summaryrefslogtreecommitdiff
path: root/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
diff options
context:
space:
mode:
Diffstat (limited to 'packages/SystemUI/src/com/android/keyguard/NumPadButton.java')
-rw-r--r--packages/SystemUI/src/com/android/keyguard/NumPadButton.java52
1 files changed, 42 insertions, 10 deletions
diff --git a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
index 372810677649..8cb1bc4878a5 100644
--- a/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
+++ b/packages/SystemUI/src/com/android/keyguard/NumPadButton.java
@@ -16,45 +16,60 @@
package com.android.keyguard;
import android.content.Context;
-import android.graphics.drawable.GradientDrawable;
+import android.content.res.ColorStateList;
+import android.graphics.drawable.LayerDrawable;
+import android.graphics.drawable.VectorDrawable;
import android.util.AttributeSet;
+import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.view.ViewGroup;
+import com.android.settingslib.Utils;
+import com.android.systemui.R;
+
/**
* Similar to the {@link NumPadKey}, but displays an image.
*/
public class NumPadButton extends AlphaOptimizedImageButton {
- private final NumPadAnimator mAnimator;
+ private NumPadAnimator mAnimator;
public NumPadButton(Context context, AttributeSet attrs) {
super(context, attrs);
- mAnimator = new NumPadAnimator(context, (GradientDrawable) getBackground(),
+ mAnimator = new NumPadAnimator(context, (LayerDrawable) getBackground(),
attrs.getStyleAttribute());
}
@Override
- protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
- mAnimator.updateMargin((ViewGroup.MarginLayoutParams) getLayoutParams());
+ public void setLayoutParams(ViewGroup.LayoutParams params) {
+ if (mAnimator != null) mAnimator.updateMargin((ViewGroup.MarginLayoutParams) params);
+ super.setLayoutParams(params);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
- // Set width/height to the same value to ensure a smooth circle for the bg
- setMeasuredDimension(getMeasuredWidth(), getMeasuredWidth());
+ // Set width/height to the same value to ensure a smooth circle for the bg, but shrink
+ // the height to match the old pin bouncer
+ int width = getMeasuredWidth();
+ int height = mAnimator == null ? (int) (width * .75f) : width;
+
+ setMeasuredDimension(getMeasuredWidth(), height);
}
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
super.onLayout(changed, l, t, r, b);
- mAnimator.onLayout(b - t);
+ if (mAnimator != null) mAnimator.onLayout(b - t);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
- mAnimator.start();
+ if (mAnimator != null) mAnimator.start();
return super.onTouchEvent(event);
}
@@ -62,6 +77,23 @@ public class NumPadButton extends AlphaOptimizedImageButton {
* Reload colors from resources.
**/
public void reloadColors() {
- mAnimator.reloadColors(getContext());
+ if (mAnimator != null) {
+ mAnimator.reloadColors(getContext());
+ } else {
+ // Needed for old style pin
+ int textColor = Utils.getColorAttr(getContext(), android.R.attr.textColorPrimary)
+ .getDefaultColor();
+ ((VectorDrawable) getDrawable()).setTintList(ColorStateList.valueOf(textColor));
+ }
+ }
+
+ /**
+ * By default, the new layout will be enabled. Invoking will revert to the old style
+ */
+ public void disableNewLayout() {
+ mAnimator = null;
+ ContextThemeWrapper ctw = new ContextThemeWrapper(getContext(), R.style.NumPadKey);
+ setBackground(getContext().getResources().getDrawable(
+ R.drawable.ripple_drawable_pin, ctw.getTheme()));
}
}