diff options
author | Yuli Huang <yuli@google.com> | 2012-04-02 21:40:25 +0800 |
---|---|---|
committer | Yuli Huang <yuli@google.com> | 2012-04-02 22:58:51 +0800 |
commit | fc28f4b3866dd7f5ae841174fd3c28be3a2e672f (patch) | |
tree | 2247f6cb5f7677761c9df619e1031f2ee5c9b94d /src/com/android/gallery3d/photoeditor/actions | |
parent | 948b5ffc4c004b6e4daf18f64165fb555bc4d6b2 (diff) | |
download | android_packages_apps_Snap-fc28f4b3866dd7f5ae841174fd3c28be3a2e672f.tar.gz android_packages_apps_Snap-fc28f4b3866dd7f5ae841174fd3c28be3a2e672f.tar.bz2 android_packages_apps_Snap-fc28f4b3866dd7f5ae841174fd3c28be3a2e672f.zip |
Fix b/5974240: Sliders may not be responsive to touches.
Add padding around sliders to increase its touchable areas.
Change-Id: I034e25804811b14ce6137c72472191dabd7bdef8
Diffstat (limited to 'src/com/android/gallery3d/photoeditor/actions')
3 files changed, 36 insertions, 32 deletions
diff --git a/src/com/android/gallery3d/photoeditor/actions/AbstractSeekBar.java b/src/com/android/gallery3d/photoeditor/actions/AbstractSeekBar.java index 27a0bce0b..aaf0e5ba3 100644 --- a/src/com/android/gallery3d/photoeditor/actions/AbstractSeekBar.java +++ b/src/com/android/gallery3d/photoeditor/actions/AbstractSeekBar.java @@ -28,7 +28,7 @@ import android.widget.SeekBar; import com.android.gallery3d.R; /** - * Seek-bar base that implements a draggable thumb that fits seek-bar height. + * Seek-bar base that implements a draggable thumb that fits seek-bar's track height. */ abstract class AbstractSeekBar extends SeekBar { @@ -38,22 +38,22 @@ abstract class AbstractSeekBar extends SeekBar { @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { - super.onSizeChanged(w, h, oldw, oldh); - - // Scale the thumb to fit seek-bar height. + // Scale the thumb to fit seek-bar's track height. Resources res = getResources(); Drawable thumb = res.getDrawable(R.drawable.photoeditor_seekbar_thumb); + int height = h - getPaddingTop() - getPaddingBottom(); + int scaledWidth = thumb.getIntrinsicWidth() * height / thumb.getIntrinsicHeight(); - // Set the left/right padding to half width of the thumb drawn. - int scaledWidth = thumb.getIntrinsicWidth() * h / thumb.getIntrinsicHeight(); - int padding = (scaledWidth + 1) / 2; - setPadding(padding, 0, padding, 0); - - Bitmap bitmap = Bitmap.createBitmap(scaledWidth, h, Bitmap.Config.ARGB_8888); + Bitmap bitmap = Bitmap.createBitmap(scaledWidth, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); thumb.setBounds(0, 0, bitmap.getWidth(), bitmap.getHeight()); thumb.draw(canvas); + // The thumb should not extend out of the track per UX design. setThumb(new BitmapDrawable(res, bitmap)); + setThumbOffset(0); + + // The thumb position is updated here after the thumb is changed. + super.onSizeChanged(w, h, oldw, oldh); } } diff --git a/src/com/android/gallery3d/photoeditor/actions/ColorSeekBar.java b/src/com/android/gallery3d/photoeditor/actions/ColorSeekBar.java index 5f9809be0..41d1f2448 100644 --- a/src/com/android/gallery3d/photoeditor/actions/ColorSeekBar.java +++ b/src/com/android/gallery3d/photoeditor/actions/ColorSeekBar.java @@ -42,7 +42,7 @@ class ColorSeekBar extends AbstractSeekBar { } private final int[] colors; - private Bitmap background; + private Bitmap progressDrawable; public ColorSeekBar(Context context, AttributeSet attrs) { super(context, attrs); @@ -61,46 +61,47 @@ class ColorSeekBar extends AbstractSeekBar { protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); - if (background != null) { - background.recycle(); + if (progressDrawable != null) { + progressDrawable.recycle(); } - background = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); - Canvas canvas = new Canvas(background); + int width = w - getPaddingLeft() - getPaddingRight(); + int height = h - getPaddingTop() - getPaddingBottom(); + progressDrawable = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(progressDrawable); Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG); paint.setStyle(Paint.Style.FILL); - // Draw two half circles in the first and last colors at seek-bar left/right ends. - int radius = getThumbOffset(); + // Draw two half circles in the first and last colors at the left/right ends. + int radius = height / 2; float left = radius; - float right = w - radius; - float cy = h / 2; + float right = width - radius; canvas.save(); - canvas.clipRect(left, 0, right, h, Op.DIFFERENCE); + canvas.clipRect(left, 0, right, height, Op.DIFFERENCE); paint.setColor(colors[0]); - canvas.drawCircle(left, cy, radius, paint); + canvas.drawCircle(left, radius, radius, paint); paint.setColor(colors[colors.length - 1]); - canvas.drawCircle(right, cy, radius, paint); + canvas.drawCircle(right, radius, radius, paint); canvas.restore(); // Draw color strips that make the thumb stop at every strip's center during seeking. float strip = (right - left) / (colors.length - 1); right = left + strip / 2; paint.setColor(colors[0]); - canvas.drawRect(left, 0, right, h, paint); + canvas.drawRect(left, 0, right, height, paint); left = right; for (int i = 1; i < colors.length - 1; i++) { right = left + strip; paint.setColor(colors[i]); - canvas.drawRect(left, 0, right, h, paint); + canvas.drawRect(left, 0, right, height, paint); left = right; } right = left + strip / 2; paint.setColor(colors[colors.length - 1]); - canvas.drawRect(left, 0, right, h, paint); + canvas.drawRect(left, 0, right, height, paint); - setBackgroundDrawable(new BitmapDrawable(getResources(), background)); + setProgressDrawable(new BitmapDrawable(getResources(), progressDrawable)); } public void setOnColorChangeListener(final OnColorChangeListener listener) { diff --git a/src/com/android/gallery3d/photoeditor/actions/EffectToolKit.java b/src/com/android/gallery3d/photoeditor/actions/EffectToolKit.java index fbb54d948..285e06b64 100644 --- a/src/com/android/gallery3d/photoeditor/actions/EffectToolKit.java +++ b/src/com/android/gallery3d/photoeditor/actions/EffectToolKit.java @@ -17,6 +17,8 @@ package com.android.gallery3d.photoeditor.actions; import android.content.Context; +import android.content.res.Resources; +import android.graphics.drawable.Drawable; import android.os.SystemClock; import android.view.LayoutInflater; import android.view.MotionEvent; @@ -109,24 +111,25 @@ public class EffectToolKit { return tool; } - private int getScalePickerBackground(ScaleType type) { + private Drawable getScalePickerProgressDrawable(Resources res, ScaleType type) { switch (type) { case LIGHT: - return R.drawable.photoeditor_scale_seekbar_light; + return res.getDrawable(R.drawable.photoeditor_scale_seekbar_light); case SHADOW: - return R.drawable.photoeditor_scale_seekbar_shadow; + return res.getDrawable(R.drawable.photoeditor_scale_seekbar_shadow); case COLOR: - return R.drawable.photoeditor_scale_seekbar_color; + return res.getDrawable(R.drawable.photoeditor_scale_seekbar_color); } - return R.drawable.photoeditor_scale_seekbar_generic; + return res.getDrawable(R.drawable.photoeditor_scale_seekbar_generic); } public ScaleSeekBar addScalePicker(ScaleType type) { ScaleSeekBar scalePicker = (ScaleSeekBar) addPanelTool( R.layout.photoeditor_scale_seekbar); - scalePicker.setBackgroundResource(getScalePickerBackground(type)); + scalePicker.setProgressDrawable(getScalePickerProgressDrawable( + toolPanel.getResources(), type)); return scalePicker; } |