summaryrefslogtreecommitdiffstats
path: root/core/java/com/android/internal/widget/RotarySelector.java
diff options
context:
space:
mode:
authorKarl Rosaen <krosaen@android.com>2009-09-25 11:34:50 -0700
committerKarl Rosaen <krosaen@android.com>2009-09-25 11:35:41 -0700
commitc8ad6dcb8abcf5f7296faecdcfa93a01fb4011b9 (patch)
treef44ae0570e41e6a2ed7c2364cea60e20747ffd89 /core/java/com/android/internal/widget/RotarySelector.java
parent82768db56b8f6a6d22adba36df9539550091d411 (diff)
downloadframeworks_base-c8ad6dcb8abcf5f7296faecdcfa93a01fb4011b9.zip
frameworks_base-c8ad6dcb8abcf5f7296faecdcfa93a01fb4011b9.tar.gz
frameworks_base-c8ad6dcb8abcf5f7296faecdcfa93a01fb4011b9.tar.bz2
Optimize rotary selector widget by using bitmaps instead of drawables.
In profiling setBounds was expensive. Time per onDraw from 13.3ms to 6.59ms :)
Diffstat (limited to 'core/java/com/android/internal/widget/RotarySelector.java')
-rw-r--r--core/java/com/android/internal/widget/RotarySelector.java54
1 files changed, 15 insertions, 39 deletions
diff --git a/core/java/com/android/internal/widget/RotarySelector.java b/core/java/com/android/internal/widget/RotarySelector.java
index 42cbd07..8939346 100644
--- a/core/java/com/android/internal/widget/RotarySelector.java
+++ b/core/java/com/android/internal/widget/RotarySelector.java
@@ -56,10 +56,10 @@ public class RotarySelector extends View {
// UI elements
private Bitmap mBackground;
- private Drawable mDimple;
+ private Bitmap mDimple;
- private Drawable mLeftHandleIcon;
- private Drawable mRightHandleIcon;
+ private Bitmap mLeftHandleIcon;
+ private Bitmap mRightHandleIcon;
private Bitmap mArrowShortLeftAndRight;
private Bitmap mArrowLongLeft; // Long arrow starting on the left, pointing clockwise
@@ -177,7 +177,7 @@ public class RotarySelector extends View {
// Assets (all are BitmapDrawables).
mBackground = getBitmapFor(R.drawable.jog_dial_bg);
- mDimple = r.getDrawable(R.drawable.jog_dial_dimple);
+ mDimple = getBitmapFor(R.drawable.jog_dial_dimple);
mArrowLongLeft = getBitmapFor(R.drawable.jog_dial_arrow_long_left_green);
mArrowLongRight = getBitmapFor(R.drawable.jog_dial_arrow_long_right_red);
@@ -187,7 +187,7 @@ public class RotarySelector extends View {
mEdgeTriggerThresh = (int) (mDensity * EDGE_TRIGGER_DIP);
- mDimpleWidth = mDimple.getIntrinsicWidth();
+ mDimpleWidth = mDimple.getWidth();
mBackgroundWidth = mBackground.getWidth();
mBackgroundHeight = mBackground.getHeight();
@@ -239,20 +239,9 @@ public class RotarySelector extends View {
* @param resId the resource ID.
*/
public void setLeftHandleResource(int resId) {
- Drawable d = null;
if (resId != 0) {
- d = getResources().getDrawable(resId);
+ mLeftHandleIcon = getBitmapFor(resId);
}
- setLeftHandleDrawable(d);
- }
-
- /**
- * Sets the left handle icon to a given Drawable.
- *
- * @param d the Drawable to use as the icon, or null to remove the icon.
- */
- public void setLeftHandleDrawable(Drawable d) {
- mLeftHandleIcon = d;
invalidate();
}
@@ -265,23 +254,13 @@ public class RotarySelector extends View {
* @param resId the resource ID.
*/
public void setRightHandleResource(int resId) {
- Drawable d = null;
if (resId != 0) {
- d = getResources().getDrawable(resId);
+ mRightHandleIcon = getBitmapFor(resId);
}
- setRightHandleDrawable(d);
- }
-
- /**
- * Sets the right handle icon to a given Drawable.
- *
- * @param d the Drawable to use as the icon, or null to remove the icon.
- */
- public void setRightHandleDrawable(Drawable d) {
- mRightHandleIcon = d;
invalidate();
}
+
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int length = isHoriz() ?
@@ -699,18 +678,15 @@ public class RotarySelector extends View {
}
/**
- * Sets the bounds of the specified Drawable so that it's centered
- * on the point (x,y), then draws it onto the specified canvas.
+ * Draw the bitmap so that it's centered
+ * on the point (x,y), then draws it using specified canvas.
* TODO: is there already a utility method somewhere for this?
*/
- private static void drawCentered(Drawable d, Canvas c, int x, int y) {
- int w = d.getIntrinsicWidth();
- int h = d.getIntrinsicHeight();
-
- // if (DBG) log("--> drawCentered: " + x + " , " + y + "; intrinsic " + w + " x " + h);
- d.setBounds(x - (w / 2), y - (h / 2),
- x + (w / 2), y + (h / 2));
- d.draw(c);
+ private void drawCentered(Bitmap d, Canvas c, int x, int y) {
+ int w = d.getWidth();
+ int h = d.getHeight();
+
+ c.drawBitmap(d, x - (w / 2), y - (h / 2), mPaint);
}