summaryrefslogtreecommitdiffstats
path: root/src/com/android/gallery3d
diff options
context:
space:
mode:
authornicolasroard <nicolasroard@google.com>2013-07-03 01:25:06 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2013-07-03 01:25:07 +0000
commitd77e55a4bf326b4bfc1f3880f24d068cb79af1ce (patch)
treec3ace2373ad00c9d1ae99d327a4b8a9ab44bb104 /src/com/android/gallery3d
parent67bf67eafefeda59bb0d2db8e048a5b989076850 (diff)
parentbacd1788f3e966bf78c5fb34e481b25797e2ad42 (diff)
downloadandroid_packages_apps_Snap-d77e55a4bf326b4bfc1f3880f24d068cb79af1ce.tar.gz
android_packages_apps_Snap-d77e55a4bf326b4bfc1f3880f24d068cb79af1ce.tar.bz2
android_packages_apps_Snap-d77e55a4bf326b4bfc1f3880f24d068cb79af1ce.zip
Merge "Improves portrait categories buttons" into gb-ub-photos-carlsbad
Diffstat (limited to 'src/com/android/gallery3d')
-rw-r--r--src/com/android/gallery3d/filtershow/FilterShowActivity.java3
-rw-r--r--src/com/android/gallery3d/filtershow/category/Action.java5
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryAdapter.java27
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryPanel.java1
-rw-r--r--src/com/android/gallery3d/filtershow/category/CategoryView.java83
5 files changed, 63 insertions, 56 deletions
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<Action> {
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<Action> {
@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<Action> {
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);