From 67df126291a3b104c6149c6e695e7c616259e551 Mon Sep 17 00:00:00 2001 From: Maurice Lam Date: Wed, 19 Oct 2016 15:16:36 -0700 Subject: [PATCH] [Fingerprint] Make enroll progress bar scalable Make the fingerprint enroll progress bar scalable by moving it to a single FingerprintProgressBar view and make it fill the remaining space. - The background fingerprint icon was changed to include the padding internally so it can be added as the background directly onto the progress bar view. - The icon in landscape mode is also fixed to use the fingerprint icon rather than the lock icon. Test: cd tests/robotests && mm Bug: 32123370 Change-Id: Ia5cf37d92f0af7c1cf39287f5070c44f51d44878 --- res/color/white_disabled.xml | 20 ++++++ .../enrollment_fingerprint_isolated.xml | 10 +-- res/drawable/fp_illustration.xml | 28 ++++++++ res/drawable/fp_illustration_enrollment.xml | 38 +++++----- ...nt_progress_ring.xml => ring_progress.xml} | 32 +++++---- .../fingerprint_enroll_enrolling.xml | 6 +- .../fingerprint_enroll_find_sensor.xml | 2 +- .../fingerprint_enroll_enrolling_base.xml | 5 +- .../fingerprint_enroll_enrolling_content.xml | 31 ++------ res/values-sw400dp/dimens.xml | 6 -- res/values/colors.xml | 2 - res/values/dimens.xml | 9 +-- res/values/styles.xml | 7 ++ res/values/themes.xml | 8 --- .../FingerprintEnrollEnrolling.java | 25 +++---- .../settings/widget/RingProgressBar.java | 57 +++++++++++++++ .../settings/widget/RingProgressBarTest.java | 70 +++++++++++++++++++ 17 files changed, 254 insertions(+), 102 deletions(-) create mode 100644 res/color/white_disabled.xml create mode 100644 res/drawable/fp_illustration.xml rename res/drawable/{fingerprint_progress_ring.xml => ring_progress.xml} (55%) create mode 100644 src/com/android/settings/widget/RingProgressBar.java create mode 100644 tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java diff --git a/res/color/white_disabled.xml b/res/color/white_disabled.xml new file mode 100644 index 00000000000..17008a87ea2 --- /dev/null +++ b/res/color/white_disabled.xml @@ -0,0 +1,20 @@ + + + + + + diff --git a/res/drawable/enrollment_fingerprint_isolated.xml b/res/drawable/enrollment_fingerprint_isolated.xml index fc31ff87372..de3965e1fde 100644 --- a/res/drawable/enrollment_fingerprint_isolated.xml +++ b/res/drawable/enrollment_fingerprint_isolated.xml @@ -17,14 +17,14 @@ + android:viewportWidth="176" + android:viewportHeight="176" > + android:translateX="88" + android:translateY="87.66685" > + + + + + + + + + diff --git a/res/drawable/fp_illustration_enrollment.xml b/res/drawable/fp_illustration_enrollment.xml index f9b7ed471ef..630c6bde3e7 100644 --- a/res/drawable/fp_illustration_enrollment.xml +++ b/res/drawable/fp_illustration_enrollment.xml @@ -16,21 +16,25 @@ Copyright (C) 2015 The Android Open Source Project - - - - - + android:viewportWidth="176.0" + android:viewportHeight="176.0"> + + + + + + + diff --git a/res/drawable/fingerprint_progress_ring.xml b/res/drawable/ring_progress.xml similarity index 55% rename from res/drawable/fingerprint_progress_ring.xml rename to res/drawable/ring_progress.xml index 44a69e9fb4a..02fcd5bf30c 100644 --- a/res/drawable/fingerprint_progress_ring.xml +++ b/res/drawable/ring_progress.xml @@ -17,23 +17,27 @@ - + android:thickness="@dimen/ring_progress_bar_thickness" + android:useLevel="false" + android:tint="?android:colorControlNormal"> + - - - + + + + + diff --git a/res/layout-land/fingerprint_enroll_enrolling.xml b/res/layout-land/fingerprint_enroll_enrolling.xml index ba0f803b047..27af681aaaa 100644 --- a/res/layout-land/fingerprint_enroll_enrolling.xml +++ b/res/layout-land/fingerprint_enroll_enrolling.xml @@ -49,7 +49,7 @@ android:layout_height="wrap_content" android:layout_marginStart="0dp" android:layout_marginEnd="0dp" - android:src="@drawable/ic_lock" /> + android:src="@drawable/ic_fingerprint_header" /> + android:src="@drawable/ic_fingerprint_header" /> diff --git a/res/layout/fingerprint_enroll_enrolling_content.xml b/res/layout/fingerprint_enroll_enrolling_content.xml index 42769d16c62..1622f3ff3bd 100644 --- a/res/layout/fingerprint_enroll_enrolling_content.xml +++ b/res/layout/fingerprint_enroll_enrolling_content.xml @@ -15,32 +15,11 @@ ~ limitations under the License --> - - - - - - - + android:background="@drawable/fp_illustration" + android:minHeight="@dimen/fingerprint_progress_bar_min_size" + android:progress="0" /> diff --git a/res/values-sw400dp/dimens.xml b/res/values-sw400dp/dimens.xml index da58a9ce03a..7ae40612aa2 100755 --- a/res/values-sw400dp/dimens.xml +++ b/res/values-sw400dp/dimens.xml @@ -16,16 +16,10 @@ --> - 106dp - 100dp - 220dp 56dp 176dp 240dp - 92dp - 192dp - 56dp 56dp diff --git a/res/values/colors.xml b/res/values/colors.xml index 9f3dd5b41d6..3be40383a41 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -53,8 +53,6 @@ ?android:attr/colorAccent #ffffffff #de000000 - ?android:attr/colorAccent - #20000000 #12000000 #ff384248 diff --git a/res/values/dimens.xml b/res/values/dimens.xml index b266f9c55f8..40f3f71ae52 100755 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -67,6 +67,7 @@ 200dp + 4dp 0dip @@ -221,8 +222,6 @@ 8dp - 92dip - 4dip 8dp 50dp 50% @@ -233,15 +232,13 @@ 16dp -8dp 88dp - 192dp + 220dp + 120dp 36dp 124dp 124dp 264dp - 80dip - 168dp - 48dp @dimen/match_parent 0dp diff --git a/res/values/styles.xml b/res/values/styles.xml index fc37bb0ebf9..0f957a8b1a7 100644 --- a/res/values/styles.xml +++ b/res/values/styles.xml @@ -445,4 +445,11 @@ 1.2 + + diff --git a/res/values/themes.xml b/res/values/themes.xml index 35d05fb9fce..a5ff54ae7d7 100644 --- a/res/values/themes.xml +++ b/res/values/themes.xml @@ -16,8 +16,6 @@ - - @@ -38,8 +36,6 @@ ?android:attr/colorBackground @*android:style/PreferencePanel.Dialog @style/FingerprintLayoutTheme - @dimen/setup_fingerprint_progress_bar_size - @dimen/setup_fingerprint_ring_radius @*android:drawable/ic_menu_moreoverflow_material @drawable/ic_wps_dark @color/setup_divider_color_dark @@ -62,8 +58,6 @@ ?android:attr/colorBackground @*android:style/PreferencePanel.Dialog @style/FingerprintLayoutTheme - @dimen/setup_fingerprint_progress_bar_size - @dimen/setup_fingerprint_ring_radius @*android:drawable/ic_menu_moreoverflow_material @drawable/ic_wps_light @color/setup_divider_color_light @@ -141,8 +135,6 @@ @dimen/settings_side_margin @style/FingerprintLayoutTheme - @dimen/fingerprint_progress_bar_size - @dimen/fingerprint_ring_radius @*android:drawable/ic_menu_moreoverflow_holo_dark @drawable/ic_wps_light @drawable/wifi_signal diff --git a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java index cd564588c92..fa108bb302f 100644 --- a/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java +++ b/src/com/android/settings/fingerprint/FingerprintEnrollEnrolling.java @@ -23,13 +23,12 @@ import android.animation.ValueAnimator; import android.app.Activity; import android.app.AlertDialog; import android.app.Dialog; -import android.app.DialogFragment; import android.content.DialogInterface; import android.content.Intent; -import android.content.res.ColorStateList; import android.graphics.drawable.Animatable2; import android.graphics.drawable.AnimatedVectorDrawable; import android.graphics.drawable.Drawable; +import android.graphics.drawable.LayerDrawable; import android.hardware.fingerprint.FingerprintManager; import android.os.Bundle; import android.os.UserHandle; @@ -37,7 +36,6 @@ import android.view.MotionEvent; import android.view.View; import android.view.animation.AnimationUtils; import android.view.animation.Interpolator; -import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.TextView; @@ -75,7 +73,6 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase private static final int ICON_TOUCH_COUNT_SHOW_UNTIL_DIALOG_SHOWN = 3; private ProgressBar mProgressBar; - private ImageView mFingerprintAnimator; private ObjectAnimator mProgressAnim; private TextView mStartMessage; private TextView mRepeatMessage; @@ -87,6 +84,7 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase private FingerprintEnrollSidecar mSidecar; private boolean mAnimationCancelled; private AnimatedVectorDrawable mIconAnimationDrawable; + private Drawable mIconBackgroundDrawable; private int mIndicatorBackgroundRestingColor; private int mIndicatorBackgroundActivatedColor; private boolean mRestoring; @@ -100,8 +98,11 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase mRepeatMessage = (TextView) findViewById(R.id.repeat_message); mErrorText = (TextView) findViewById(R.id.error_text); mProgressBar = (ProgressBar) findViewById(R.id.fingerprint_progress_bar); - mFingerprintAnimator = (ImageView) findViewById(R.id.fingerprint_animator); - mIconAnimationDrawable = (AnimatedVectorDrawable) mFingerprintAnimator.getDrawable(); + final LayerDrawable fingerprintDrawable = (LayerDrawable) mProgressBar.getBackground(); + mIconAnimationDrawable = (AnimatedVectorDrawable) + fingerprintDrawable.findDrawableByLayerId(R.id.fingerprint_animation); + mIconBackgroundDrawable = + fingerprintDrawable.findDrawableByLayerId(R.id.fingerprint_background); mIconAnimationDrawable.registerAnimationCallback(mIconAnimationCallback); mFastOutSlowInInterpolator = AnimationUtils.loadInterpolator( this, android.R.interpolator.fast_out_slow_in); @@ -109,7 +110,7 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase this, android.R.interpolator.linear_out_slow_in); mFastOutLinearInInterpolator = AnimationUtils.loadInterpolator( this, android.R.interpolator.fast_out_linear_in); - mFingerprintAnimator.setOnTouchListener(new View.OnTouchListener() { + mProgressBar.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getActionMasked() == MotionEvent.ACTION_DOWN) { @@ -117,12 +118,12 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase if (mIconTouchCount == ICON_TOUCH_COUNT_SHOW_UNTIL_DIALOG_SHOWN) { showIconTouchDialog(); } else { - mFingerprintAnimator.postDelayed(mShowDialogRunnable, + mProgressBar.postDelayed(mShowDialogRunnable, ICON_TOUCH_DURATION_UNTIL_DIALOG_SHOWN); } } else if (event.getActionMasked() == MotionEvent.ACTION_CANCEL || event.getActionMasked() == MotionEvent.ACTION_UP) { - mFingerprintAnimator.removeCallbacks(mShowDialogRunnable); + mProgressBar.removeCallbacks(mShowDialogRunnable); } return true; } @@ -131,6 +132,7 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase = getColor(R.color.fingerprint_indicator_background_resting); mIndicatorBackgroundActivatedColor = getColor(R.color.fingerprint_indicator_background_activated); + mIconBackgroundDrawable.setTint(mIndicatorBackgroundRestingColor); mRestoring = savedInstanceState != null; } @@ -213,8 +215,7 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { - mFingerprintAnimator.setBackgroundTintList(ColorStateList.valueOf( - (Integer) animation.getAnimatedValue())); + mIconBackgroundDrawable.setTint((Integer) animation.getAnimatedValue()); } }; anim.addUpdateListener(listener); @@ -400,7 +401,7 @@ public class FingerprintEnrollEnrolling extends FingerprintEnrollBase } // Start animation after it has ended. - mFingerprintAnimator.post(new Runnable() { + mProgressBar.post(new Runnable() { @Override public void run() { startIconAnimation(); diff --git a/src/com/android/settings/widget/RingProgressBar.java b/src/com/android/settings/widget/RingProgressBar.java new file mode 100644 index 00000000000..605e4e91c93 --- /dev/null +++ b/src/com/android/settings/widget/RingProgressBar.java @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.widget; + +import android.content.Context; +import android.util.AttributeSet; +import android.widget.ProgressBar; + +import com.android.settings.R; + +/** + * A (determinate) progress bar in the form of a ring. The progress bar goes clockwise starting + * from the 12 o'clock position. This view maintain equal width and height using a strategy similar + * to "centerInside" for ImageView. + */ +public class RingProgressBar extends ProgressBar { + + public RingProgressBar(Context context) { + this(context, null); + } + + public RingProgressBar(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public RingProgressBar(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, R.style.RingProgressBarStyle); + } + + public RingProgressBar(Context context, AttributeSet attrs, int defStyleAttr, + int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + + @Override + protected synchronized void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + final int measuredHeight = getMeasuredHeight(); + final int measuredWidth = getMeasuredWidth(); + final int shortSide = Math.min(measuredHeight, measuredWidth); + setMeasuredDimension(shortSide, shortSide); + } +} diff --git a/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java b/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java new file mode 100644 index 00000000000..b7a5fd987ed --- /dev/null +++ b/tests/robotests/src/com/android/settings/widget/RingProgressBarTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (C) 2016 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.settings.widget; + +import static junit.framework.Assert.assertEquals; + +import android.content.Context; +import android.view.View.MeasureSpec; + +import com.android.settings.TestConfig; + +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.robolectric.RobolectricTestRunner; +import org.robolectric.RuntimeEnvironment; +import org.robolectric.annotation.Config; + +@RunWith(RobolectricTestRunner.class) +@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION) +public class RingProgressBarTest { + + private Context mContext = RuntimeEnvironment.application; + + private RingProgressBar mProgressBar; + + @Before + public void setUp() { + mProgressBar = new RingProgressBar(mContext); + } + + @Test + public void testMeasurePortrait() { + mProgressBar.measure( + MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(200, MeasureSpec.EXACTLY)); + assertEquals(100, mProgressBar.getMeasuredHeight()); + assertEquals(100, mProgressBar.getMeasuredWidth()); + } + + @Test + public void testMeasureLandscape() { + mProgressBar.measure( + MeasureSpec.makeMeasureSpec(200, MeasureSpec.EXACTLY), + MeasureSpec.makeMeasureSpec(100, MeasureSpec.EXACTLY)); + assertEquals(100, mProgressBar.getMeasuredHeight()); + assertEquals(100, mProgressBar.getMeasuredWidth()); + } + + @Test + public void testDefaultAttributes() { + assertEquals(false, mProgressBar.isIndeterminate()); + assertEquals(0, mProgressBar.getProgress()); + assertEquals(10000, mProgressBar.getMax()); + } +}