From bacd1788f3e966bf78c5fb34e481b25797e2ad42 Mon Sep 17 00:00:00 2001 From: nicolasroard Date: Tue, 2 Jul 2013 17:54:05 -0700 Subject: Improves portrait categories buttons - use only CategoryView, no FilterIconButton - add xml values for the font size/margins - for now reuse the same Action bitmap - add accessibility contentDescription Change-Id: Ic1ae8015abba27bea0b3c4a2bccbd1a7c9ff4731 --- .../gallery3d/filtershow/FilterShowActivity.java | 3 - .../gallery3d/filtershow/category/Action.java | 5 +- .../filtershow/category/CategoryAdapter.java | 27 ------- .../filtershow/category/CategoryPanel.java | 1 - .../filtershow/category/CategoryView.java | 83 ++++++++++++++++------ 5 files changed, 63 insertions(+), 56 deletions(-) (limited to 'src') diff --git a/src/com/android/gallery3d/filtershow/FilterShowActivity.java b/src/com/android/gallery3d/filtershow/FilterShowActivity.java index 3fa6d1bb8..8d581888c 100644 --- a/src/com/android/gallery3d/filtershow/FilterShowActivity.java +++ b/src/com/android/gallery3d/filtershow/FilterShowActivity.java @@ -351,9 +351,6 @@ public class FilterShowActivity extends FragmentActivity implements OnItemClickL Resources res = getResources(); FiltersManager.setResources(res); - CategoryView.setMargin((int) getPixelsFromDip(8)); - CategoryView.setTextSize((int) getPixelsFromDip(16)); - // TODO: get those values from XML. FramedTextButton.setTextSize((int) getPixelsFromDip(14)); FramedTextButton.setTrianglePadding((int) getPixelsFromDip(4)); diff --git a/src/com/android/gallery3d/filtershow/category/Action.java b/src/com/android/gallery3d/filtershow/category/Action.java index 62bd99bc7..71d6415b8 100644 --- a/src/com/android/gallery3d/filtershow/category/Action.java +++ b/src/com/android/gallery3d/filtershow/category/Action.java @@ -72,7 +72,7 @@ public class Action implements RenderingRequestCaller { mName = name; } - public void setImageFrame(Rect imageFrame) { + public void setImageFrame(Rect imageFrame, int orientation) { if (mImageFrame != null && mImageFrame.equals(imageFrame)) { return; } @@ -81,7 +81,8 @@ public class Action implements RenderingRequestCaller { mImageFrame = imageFrame; int w = mImageFrame.width(); int h = mImageFrame.height(); - if (mType == CROP_VIEW) { + if (orientation == CategoryView.VERTICAL + && mType == CROP_VIEW) { w /= 2; } Bitmap bitmapCrop = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); diff --git a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java index 5baaeaf0f..027fa5d8e 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryAdapter.java @@ -35,7 +35,6 @@ public class CategoryAdapter extends ArrayAdapter { private int mItemHeight; private View mContainer; private int mItemWidth = ListView.LayoutParams.MATCH_PARENT; - private boolean mUseFilterIconButton = false; private int mSelectedPosition; int mCategory; private int mOrientation; @@ -76,24 +75,6 @@ public class CategoryAdapter extends ArrayAdapter { @Override public View getView(int position, View convertView, ViewGroup parent) { - if (mUseFilterIconButton) { - if (convertView == null) { - LayoutInflater inflater = - (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); - convertView = inflater.inflate(R.layout.filtericonbutton, parent, false); - } - FilterIconButton view = (FilterIconButton) convertView; - Action action = getItem(position); - view.setAction(action); - view.setup(action.getName(), null, this); - view.setLayoutParams( - new ListView.LayoutParams(mItemWidth, mItemHeight)); - view.setTag(position); - if (mCategory == MainPanel.LOOKS || mCategory == MainPanel.BORDERS) { - view.setBackgroundResource(0); - } - return view; - } if (convertView == null) { convertView = new CategoryView(getContext()); } @@ -142,14 +123,6 @@ public class CategoryAdapter extends ArrayAdapter { notifyDataSetChanged(); } - public void setUseFilterIconButton(boolean useFilterIconButton) { - mUseFilterIconButton = useFilterIconButton; - } - - public boolean isUseFilterIconButton() { - return mUseFilterIconButton; - } - public FilterRepresentation getTinyPlanet() { for (int i = 0; i < getCount(); i++) { Action action = getItem(i); diff --git a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java index e78722187..477e00f5f 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryPanel.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryPanel.java @@ -93,7 +93,6 @@ public class CategoryPanel extends Fragment { if (panelView instanceof CategoryTrack) { CategoryTrack panel = (CategoryTrack) panelView; mAdapter.setOrientation(CategoryView.HORIZONTAL); - mAdapter.setUseFilterIconButton(true); panel.setAdapter(mAdapter); mAdapter.setContainer(panel); } else { diff --git a/src/com/android/gallery3d/filtershow/category/CategoryView.java b/src/com/android/gallery3d/filtershow/category/CategoryView.java index e045cf452..c456dc207 100644 --- a/src/com/android/gallery3d/filtershow/category/CategoryView.java +++ b/src/com/android/gallery3d/filtershow/category/CategoryView.java @@ -24,7 +24,6 @@ import android.graphics.Color; import android.graphics.Paint; import android.graphics.Rect; import android.graphics.Typeface; -import android.util.Log; import android.view.View; import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; @@ -39,8 +38,8 @@ public class CategoryView extends View implements View.OnClickListener { private Paint mPaint = new Paint(); private Action mAction; private Rect mTextBounds = new Rect(); - private static int sMargin = 16; - private static int sTextSize = 32; + private int mMargin = 16; + private int mTextSize = 32; private int mTextColor; private int mBackgroundColor; private Paint mSelectPaint; @@ -50,14 +49,6 @@ public class CategoryView extends View implements View.OnClickListener { private int mBorderStroke; private int mOrientation = VERTICAL; - public static void setTextSize(int size) { - sTextSize = size; - } - - public static void setMargin(int margin) { - sMargin = margin; - } - public CategoryView(Context context) { super(context); setOnClickListener(this); @@ -65,6 +56,8 @@ public class CategoryView extends View implements View.OnClickListener { mBackgroundColor = res.getColor(R.color.filtershow_categoryview_background); mTextColor = res.getColor(R.color.filtershow_categoryview_text); mSelectionStroke = res.getDimensionPixelSize(R.dimen.thumbnail_margin); + mTextSize = res.getDimensionPixelSize(R.dimen.category_panel_text_size); + mMargin = res.getDimensionPixelOffset(R.dimen.category_panel_margin); mSelectPaint = new Paint(); mSelectPaint.setStyle(Paint.Style.FILL); mSelectPaint.setColor(res.getColor(R.color.filtershow_category_selection)); @@ -73,36 +66,80 @@ public class CategoryView extends View implements View.OnClickListener { mBorderStroke = mSelectionStroke / 3; } + private void computeTextPosition(String text) { + if (text == null) { + return; + } + mPaint.setTextSize(mTextSize); + if (mOrientation == VERTICAL) { + text = text.toUpperCase(); + // TODO: set this in xml + mPaint.setTypeface(Typeface.DEFAULT_BOLD); + } + mPaint.getTextBounds(text, 0, text.length(), mTextBounds); + } + public void drawText(Canvas canvas, String text) { if (text == null) { return; } - text = text.toUpperCase(); - mPaint.setTextSize(sTextSize); - mPaint.setTypeface(Typeface.DEFAULT_BOLD); float textWidth = mPaint.measureText(text); - mPaint.getTextBounds(text, 0, text.length(), mTextBounds); - int x = (int) (canvas.getWidth() - textWidth - sMargin); - int y = canvas.getHeight() - sMargin; + int x = (int) (canvas.getWidth() - textWidth - mMargin); + if (mOrientation == HORIZONTAL) { + x = (int) ((canvas.getWidth() - textWidth) / 2.0f); + } + if (x < 0) { + // If the text takes more than the view width, + // justify to the left. + x = mMargin; + } + int y = canvas.getHeight() - mMargin; canvas.drawText(text, x, y, mPaint); } + @Override + public CharSequence getContentDescription () { + if (mAction != null) { + return mAction.getName(); + } + return null; + } + @Override public void onDraw(Canvas canvas) { canvas.drawColor(mBackgroundColor); if (mAction != null) { mPaint.reset(); mPaint.setAntiAlias(true); + computeTextPosition(mAction.getName()); if (mAction.getImage() == null) { - mAction.setImageFrame(new Rect(0, 0, canvas.getWidth(), canvas.getHeight())); + mAction.setImageFrame(new Rect(0, 0, getWidth(), getHeight()), mOrientation); } else { Bitmap bitmap = mAction.getImage(); - canvas.drawBitmap(bitmap, 0, 0, mPaint); + canvas.save(); + Rect clipRect = new Rect(mSelectionStroke, mSelectionStroke, + getWidth() - mSelectionStroke, + getHeight() - 2* mMargin - mTextSize); + int offsetx = 0; + int offsety = 0; + if (mOrientation == HORIZONTAL) { + canvas.clipRect(clipRect); + offsetx = - (bitmap.getWidth() - clipRect.width()) / 2; + offsety = - (bitmap.getHeight() - clipRect.height()) / 2; + } + canvas.drawBitmap(bitmap, offsetx, offsety, mPaint); + canvas.restore(); if (mAdapter.isSelected(this)) { - SelectionRenderer.drawSelection(canvas, 0, 0, - Math.min(bitmap.getWidth(), getWidth()), - Math.min(bitmap.getHeight(), getHeight()), - mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint); + if (mOrientation == HORIZONTAL) { + SelectionRenderer.drawSelection(canvas, 0, 0, + getWidth(), getHeight() - mMargin - mTextSize, + mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint); + } else { + SelectionRenderer.drawSelection(canvas, 0, 0, + Math.min(bitmap.getWidth(), getWidth()), + Math.min(bitmap.getHeight(), getHeight()), + mSelectionStroke, mSelectPaint, mBorderStroke, mBorderPaint); + } } } mPaint.setColor(mBackgroundColor); -- cgit v1.2.3