diff --git a/packages/Keyguard/res/drawable/ic_backspace_24dp.xml b/packages/Keyguard/res/drawable/ic_backspace_24dp.xml index 47c8d14330c05..1e4022ea402b6 100644 --- a/packages/Keyguard/res/drawable/ic_backspace_24dp.xml +++ b/packages/Keyguard/res/drawable/ic_backspace_24dp.xml @@ -15,6 +15,7 @@ Copyright (C) 2014 The Android Open Source Project --> diff --git a/packages/Keyguard/res/values/attrs.xml b/packages/Keyguard/res/values/attrs.xml index 96a5bcc5fcbcd..7cfe6316084f4 100644 --- a/packages/Keyguard/res/values/attrs.xml +++ b/packages/Keyguard/res/values/attrs.xml @@ -32,6 +32,9 @@ + + + diff --git a/packages/Keyguard/src/com/android/keyguard/NumPadKey.java b/packages/Keyguard/src/com/android/keyguard/NumPadKey.java index ef8bb0be0d144..2ff7e121721a5 100644 --- a/packages/Keyguard/src/com/android/keyguard/NumPadKey.java +++ b/packages/Keyguard/src/com/android/keyguard/NumPadKey.java @@ -71,6 +71,10 @@ public class NumPadKey extends ViewGroup { } public NumPadKey(Context context, AttributeSet attrs, int defStyle) { + this(context, attrs, defStyle, R.layout.keyguard_num_pad_key); + } + + protected NumPadKey(Context context, AttributeSet attrs, int defStyle, int contentResource) { super(context, attrs, defStyle); setFocusable(true); @@ -92,7 +96,7 @@ public class NumPadKey extends ViewGroup { mPM = (PowerManager) mContext.getSystemService(Context.POWER_SERVICE); LayoutInflater inflater = (LayoutInflater) getContext().getSystemService( Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.keyguard_num_pad_key, this, true); + inflater.inflate(contentResource, this, true); mDigitText = (TextView) findViewById(R.id.digit_text); mDigitText.setText(Integer.toString(mDigit)); @@ -113,7 +117,11 @@ public class NumPadKey extends ViewGroup { } } - setBackground(mContext.getDrawable(R.drawable.ripple_drawable)); + a = context.obtainStyledAttributes(attrs, android.R.styleable.View); + if (!a.hasValueOrEmpty(android.R.styleable.View_background)) { + setBackground(mContext.getDrawable(R.drawable.ripple_drawable)); + } + a.recycle(); setContentDescription(mDigitText.getText().toString()); } diff --git a/packages/Keyguard/src/com/android/keyguard/PasswordTextView.java b/packages/Keyguard/src/com/android/keyguard/PasswordTextView.java index 50e7ecb92ffc2..6eea81bf4014d 100644 --- a/packages/Keyguard/src/com/android/keyguard/PasswordTextView.java +++ b/packages/Keyguard/src/com/android/keyguard/PasswordTextView.java @@ -33,6 +33,7 @@ import android.provider.Settings; import android.text.InputType; import android.text.TextUtils; import android.util.AttributeSet; +import android.view.Gravity; import android.view.View; import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; @@ -81,6 +82,7 @@ public class PasswordTextView extends View { * The raw text size, will be multiplied by the scaled density when drawn */ private final int mTextHeightRaw; + private final int mGravity; private ArrayList mTextChars = new ArrayList<>(); private String mText = ""; private Stack mCharPool = new Stack<>(); @@ -118,6 +120,12 @@ public class PasswordTextView extends View { TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PasswordTextView); try { mTextHeightRaw = a.getInt(R.styleable.PasswordTextView_scaledTextSize, 0); + mGravity = a.getInt(R.styleable.PasswordTextView_android_gravity, Gravity.CENTER); + mDotSize = a.getDimensionPixelSize(R.styleable.PasswordTextView_dotSize, + getContext().getResources().getDimensionPixelSize(R.dimen.password_dot_size)); + mCharPadding = a.getDimensionPixelSize(R.styleable.PasswordTextView_charPadding, + getContext().getResources().getDimensionPixelSize( + R.dimen.password_char_padding)); } finally { a.recycle(); } @@ -125,9 +133,6 @@ public class PasswordTextView extends View { mDrawPaint.setTextAlign(Paint.Align.CENTER); mDrawPaint.setColor(0xffffffff); mDrawPaint.setTypeface(Typeface.create("sans-serif-light", 0)); - mDotSize = getContext().getResources().getDimensionPixelSize(R.dimen.password_dot_size); - mCharPadding = getContext().getResources().getDimensionPixelSize(R.dimen - .password_char_padding); mShowPassword = Settings.System.getInt(mContext.getContentResolver(), Settings.System.TEXT_SHOW_PASSWORD, 1) == 1; mAppearInterpolator = AnimationUtils.loadInterpolator(mContext, @@ -142,11 +147,23 @@ public class PasswordTextView extends View { @Override protected void onDraw(Canvas canvas) { float totalDrawingWidth = getDrawingWidth(); - float currentDrawPosition = getWidth() / 2 - totalDrawingWidth / 2; + float currentDrawPosition; + if ((mGravity & Gravity.START) != 0) { + if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) { + currentDrawPosition = getWidth() - getPaddingRight() - totalDrawingWidth; + } else { + currentDrawPosition = getPaddingLeft(); + } + } else { + currentDrawPosition = getWidth() / 2 - totalDrawingWidth / 2; + } int length = mTextChars.size(); Rect bounds = getCharBounds(); int charHeight = (bounds.bottom - bounds.top); - float yPosition = getHeight() / 2; + float yPosition = + (getHeight() - getPaddingBottom() - getPaddingTop()) / 2 + getPaddingTop(); + canvas.clipRect(getPaddingLeft(), getPaddingTop(), + getWidth()-getPaddingRight(), getHeight()-getPaddingBottom()); float charLength = bounds.right - bounds.left; for (int i = 0; i < length; i++) { CharState charState = mTextChars.get(i);