Merge "Added padding and gravity support to PIN entry" into nyc-dev

This commit is contained in:
Evan Rosky
2016-04-06 20:03:51 +00:00
committed by Android (Google) Code Review
4 changed files with 36 additions and 7 deletions

View File

@@ -15,6 +15,7 @@ Copyright (C) 2014 The Android Open Source Project
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:autoMirrored="true"
android:height="24dp"
android:viewportWidth="48.0"
android:viewportHeight="48.0">

View File

@@ -32,6 +32,9 @@
<declare-styleable name="PasswordTextView">
<attr name="scaledTextSize" format="integer" />
<attr name="android:gravity" />
<attr name="dotSize" format="dimension" />
<attr name="charPadding" format="dimension" />
</declare-styleable>
<declare-styleable name="CarrierText">

View File

@@ -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());
}

View File

@@ -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<CharState> mTextChars = new ArrayList<>();
private String mText = "";
private Stack<CharState> 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);