diff options
Diffstat (limited to 'src/com/android/gallery3d/filtershow/ui')
-rw-r--r-- | src/com/android/gallery3d/filtershow/ui/FilterIconButton.java | 33 | ||||
-rw-r--r-- | src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java | 32 |
2 files changed, 64 insertions, 1 deletions
diff --git a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java index c3c87694a..96126c55c 100644 --- a/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java +++ b/src/com/android/gallery3d/filtershow/ui/FilterIconButton.java @@ -17,18 +17,25 @@ package com.android.gallery3d.filtershow.ui; import android.content.Context; +import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Rect; import android.graphics.RectF; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.View; import android.widget.LinearLayout; +import com.android.gallery3d.R; import com.android.gallery3d.filtershow.FilterShowActivity; import com.android.gallery3d.filtershow.cache.RenderingRequest; import com.android.gallery3d.filtershow.cache.RenderingRequestCaller; import com.android.gallery3d.filtershow.category.Action; +import com.android.gallery3d.filtershow.category.CategoryAdapter; import com.android.gallery3d.filtershow.filters.FilterRepresentation; import com.android.gallery3d.filtershow.imageshow.GeometryListener; import com.android.gallery3d.filtershow.imageshow.GeometryMetadata; @@ -45,6 +52,9 @@ public class FilterIconButton extends IconButton implements View.OnClickListener private FilterRepresentation mFilterRepresentation = null; private Bitmap mIconBitmap = null; private Action mAction; + private Paint mSelectPaint; + private int mSelectStroke; + private CategoryAdapter mAdapter; public FilterIconButton(Context context) { super(context); } @@ -57,11 +67,17 @@ public class FilterIconButton extends IconButton implements View.OnClickListener super(context, attrs, defStyle); } - public void setup(String text, LinearLayout parent) { + public void setup(String text, LinearLayout parent, CategoryAdapter adapter) { + mAdapter = adapter; setText(text); setContentDescription(text); super.setOnClickListener(this); + Resources res = getContext().getResources(); MasterImage.getImage().addGeometryListener(this); + mSelectStroke = res.getDimensionPixelSize(R.dimen.thumbnail_margin); + mSelectPaint = new Paint(); + mSelectPaint.setStyle(Paint.Style.FILL); + mSelectPaint.setColor(res.getColor(R.color.filtershow_category_selection)); invalidate(); } @@ -69,6 +85,7 @@ public class FilterIconButton extends IconButton implements View.OnClickListener public void onClick(View v) { FilterShowActivity activity = (FilterShowActivity) getContext(); activity.showRepresentation(mFilterRepresentation); + mAdapter.setSelected(v); } public FilterRepresentation getFilterRepresentation() { @@ -113,6 +130,20 @@ public class FilterIconButton extends IconButton implements View.OnClickListener } else { super.onDraw(canvas); } + if (mAdapter.isSelected(this)) { + Drawable iconDrawable = getCompoundDrawables()[1]; + if (iconDrawable != null) { + canvas.save(); + int padding = getCompoundDrawablePadding(); + canvas.translate(getScrollX() + padding + getPaddingLeft() - mSelectStroke - 1, + getScrollY() + padding + getPaddingTop() - mSelectStroke - 1); + Rect r = iconDrawable.getBounds(); + SelectionRenderer.drawSelection(canvas, r.left, r.top, + r.right + 2 * mSelectStroke + 2, r.bottom + 2 * mSelectStroke + 2, + mSelectStroke, mSelectPaint); + canvas.restore(); + } + } } @Override diff --git a/src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java b/src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java new file mode 100644 index 000000000..1b108bd5d --- /dev/null +++ b/src/com/android/gallery3d/filtershow/ui/SelectionRenderer.java @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2013 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.gallery3d.filtershow.ui; + +import android.graphics.Canvas; +import android.graphics.Paint; + +public class SelectionRenderer { + + public static void drawSelection(Canvas canvas, int left, int top, int right, int bottom, + int stroke, Paint paint) { + canvas.drawRect(left, top, right, top + stroke, paint); + canvas.drawRect(left, bottom - stroke, right, bottom, paint); + canvas.drawRect(left, top, left + stroke, bottom, paint); + canvas.drawRect(right - stroke, top, right, bottom, paint); + } + +} |