Bug 785246: Make custom button inherit ShapedButton. [r=mfinkle]
authorSriram Ramasubramanian <sriram@mozilla.com>
Wed, 05 Sep 2012 14:53:54 -0700
changeset 104344 d89a71a8f5aead66d115b573aab0c8a47129ff12
parent 104343 013743bb609ef214d6bad4e64bd46863a5b0450f
child 104345 ad0a615541cf1a48de25dc7994b605402e651e11
push id14465
push usersramasubramanian@mozilla.com
push dateWed, 05 Sep 2012 21:55:31 +0000
treeherdermozilla-inbound@d89a71a8f5ae [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmfinkle
bugs785246
milestone18.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 785246: Make custom button inherit ShapedButton. [r=mfinkle]
mobile/android/base/Makefile.in
mobile/android/base/MenuButton.java
mobile/android/base/ShapedButton.java
mobile/android/base/TabsButton.java
mobile/android/base/TabsPanelButton.java
--- a/mobile/android/base/Makefile.in
+++ b/mobile/android/base/Makefile.in
@@ -102,16 +102,17 @@ FENNEC_JAVA_FILES = \
   PromptService.java \
   sqlite/ByteBufferInputStream.java \
   sqlite/MatrixBlobCursor.java \
   sqlite/SQLiteBridge.java \
   sqlite/SQLiteBridgeException.java \
   RemoteTabs.java \
   RobocopAPI.java \
   SetupScreen.java \
+  ShapedButton.java \
   SiteIdentityPopup.java \
   SuggestClient.java \
   SurfaceBits.java \
   Tab.java \
   Tabs.java \
   TabsButton.java \
   TabsPanel.java \
   TabsPanelButton.java \
--- a/mobile/android/base/MenuButton.java
+++ b/mobile/android/base/MenuButton.java
@@ -1,44 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.Context;
-import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.Path;
 import android.graphics.PorterDuff.Mode;
 import android.util.AttributeSet;
-import android.widget.ImageButton;
 
-public class MenuButton extends ImageButton
-                        implements CanvasDelegate.DrawManager { 
-    Path mPath;
-    CurveTowards mSide;
-    CanvasDelegate mCanvasDelegate;
-
-    private enum CurveTowards { NONE, LEFT, RIGHT };
+public class MenuButton extends ShapedButton {
 
     public MenuButton(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbarCurve);
-        int curveTowards = a.getInt(R.styleable.BrowserToolbarCurve_curveTowards, 0x02);
-        a.recycle();
-
-        if (curveTowards == 0x00)
-            mSide = CurveTowards.NONE;
-        else if (curveTowards == 0x01)
-            mSide = CurveTowards.LEFT;
-        else
-            mSide = CurveTowards.RIGHT;
-
         // Path is clipped.
         mPath = new Path();
         mCanvasDelegate = new CanvasDelegate(this, Mode.DST_OUT);
     }
 
     @Override
     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -61,19 +42,9 @@ public class MenuButton extends ImageBut
             mPath.moveTo(width, 0);
             mPath.cubicTo((width - (curve * 0.75f)), 0,
                           (width - (curve * 0.25f)), height,
                           (width - curve), height);
             mPath.lineTo(width, height);
             mPath.lineTo(width, 0);
         }
     }
-
-    @Override
-    public void draw(Canvas canvas) {
-        mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
-    }
-
-    @Override
-    public void defaultDraw(Canvas canvas) {
-        super.draw(canvas);
-    }
 }
new file mode 100644
--- /dev/null
+++ b/mobile/android/base/ShapedButton.java
@@ -0,0 +1,46 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+package org.mozilla.gecko;
+
+import android.content.Context;
+import android.content.res.TypedArray;
+import android.graphics.Canvas;
+import android.graphics.Path;
+import android.util.AttributeSet;
+import android.widget.ImageButton;
+
+public class ShapedButton extends ImageButton
+                          implements CanvasDelegate.DrawManager { 
+    protected Path mPath;
+    protected CurveTowards mSide;
+    protected CanvasDelegate mCanvasDelegate;
+
+    protected enum CurveTowards { NONE, LEFT, RIGHT };
+
+    public ShapedButton(Context context, AttributeSet attrs) {
+        super(context, attrs);
+
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbarCurve);
+        int curveTowards = a.getInt(R.styleable.BrowserToolbarCurve_curveTowards, 0x02);
+        a.recycle();
+
+        if (curveTowards == 0x00)
+            mSide = CurveTowards.NONE;
+        else if (curveTowards == 0x01)
+            mSide = CurveTowards.LEFT;
+        else
+            mSide = CurveTowards.RIGHT;
+    }
+
+    @Override
+    public void draw(Canvas canvas) {
+        mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
+    }
+
+    @Override
+    public void defaultDraw(Canvas canvas) {
+        super.draw(canvas);
+    }
+}
--- a/mobile/android/base/TabsButton.java
+++ b/mobile/android/base/TabsButton.java
@@ -9,52 +9,34 @@ import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.drawable.Drawable;
 import android.graphics.drawable.ColorDrawable;
 import android.graphics.Paint;
 import android.graphics.Path;
 import android.graphics.PorterDuffXfermode;
 import android.graphics.PorterDuff.Mode;
 import android.util.AttributeSet;
-import android.widget.ImageButton;
 
-public class TabsButton extends ImageButton 
-                        implements CanvasDelegate.DrawManager { 
-    Paint mPaint;
+public class TabsButton extends ShapedButton {
+    private Paint mPaint;
 
-    Path mPath;
-    Path mBackgroundPath;
-    Path mLeftCurve;
-    Path mRightCurve;
+    private Path mBackgroundPath;
+    private Path mLeftCurve;
+    private Path mRightCurve;
 
-    boolean mCropped;
-    int mFullWidth;
-    CurveTowards mSide;
-    CanvasDelegate mCanvasDelegate;
-
-    private enum CurveTowards { NONE, LEFT, RIGHT };
+    private boolean mCropped;
+    private int mFullWidth;
 
     public TabsButton(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbarCurve);
-        int curveTowards = a.getInt(R.styleable.BrowserToolbarCurve_curveTowards, 0x02);
-        a.recycle();
-
-        a = context.obtainStyledAttributes(attrs, R.styleable.TabsButton);
+        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TabsButton);
         mCropped = a.getBoolean(R.styleable.TabsButton_cropped, false);
         a.recycle();
 
-        if (curveTowards == 0x00)
-            mSide = CurveTowards.NONE;
-        else if (curveTowards == 0x01)
-            mSide = CurveTowards.LEFT;
-        else
-            mSide = CurveTowards.RIGHT;
-
         // Paint to draw the background.
         mPaint = new Paint();
         mPaint.setAntiAlias(true);
         mPaint.setColor(0xFF000000);
 
         // Path is masked.
         mPath = new Path();
         mBackgroundPath = new Path();
@@ -164,14 +146,9 @@ public class TabsButton extends ImageBut
         Drawable background = getBackground();
         if (background.getCurrent() instanceof ColorDrawable)
             return;
 
         // Additionally draw a black curve for cropped button's default level.
         if (mCropped && background.getLevel() != 2)
             canvas.drawPath(mBackgroundPath, mPaint);
     }
-
-    @Override
-    public void defaultDraw(Canvas canvas) {
-        super.draw(canvas);
-    }
 }
--- a/mobile/android/base/TabsPanelButton.java
+++ b/mobile/android/base/TabsPanelButton.java
@@ -1,44 +1,25 @@
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 package org.mozilla.gecko;
 
 import android.content.Context;
-import android.content.res.TypedArray;
 import android.graphics.Canvas;
 import android.graphics.Path;
 import android.graphics.PorterDuff.Mode;
 import android.util.AttributeSet;
-import android.widget.ImageButton;
 
-public class TabsPanelButton extends ImageButton
-                             implements CanvasDelegate.DrawManager { 
-    Path mPath;
-    CurveTowards mSide;
-    CanvasDelegate mCanvasDelegate;
-
-    private enum CurveTowards { NONE, LEFT, RIGHT };
+public class TabsPanelButton extends ShapedButton {
 
     public TabsPanelButton(Context context, AttributeSet attrs) {
         super(context, attrs);
 
-        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BrowserToolbarCurve);
-        int curveTowards = a.getInt(R.styleable.BrowserToolbarCurve_curveTowards, 0x02);
-        a.recycle();
-
-        if (curveTowards == 0x00)
-            mSide = CurveTowards.NONE;
-        else if (curveTowards == 0x01)
-            mSide = CurveTowards.LEFT;
-        else
-            mSide = CurveTowards.RIGHT;
-
         // Path is clipped.
         mPath = new Path();
         mCanvasDelegate = new CanvasDelegate(this, Mode.DST_OUT);
     }
 
     @Override
     public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
         super.onMeasure(widthMeasureSpec, heightMeasureSpec);
@@ -61,19 +42,9 @@ public class TabsPanelButton extends Ima
             mPath.moveTo(width, height);
             mPath.cubicTo((width - (curve * 0.75f)), height,
                           (width - (curve * 0.25f)), 0,
                           (width - curve), 0);
             mPath.lineTo(width, 0);
             mPath.lineTo(width, height);
         }
     }
-
-    @Override
-    public void draw(Canvas canvas) {
-        mCanvasDelegate.draw(canvas, mPath, getWidth(), getHeight());
-    }
-
-    @Override
-    public void defaultDraw(Canvas canvas) {
-        super.draw(canvas);
-    }
 }