From ca2156890ae6b37bb2137581e0420f488d5c3cd8 Mon Sep 17 00:00:00 2001 From: Jason Monk Date: Thu, 9 Feb 2017 14:32:54 -0800 Subject: [PATCH] Fix tinting and sizing of tuner lock screen shortcuts Test: visual Change-Id: I13f0281d38cd4d73322e9752d9bca36be2412917 --- .../plugins/IntentButtonProvider.java | 1 + .../res/layout/keyguard_bottom_area.xml | 2 -- .../statusbar/KeyguardAffordanceView.java | 9 +++++++++ .../phone/KeyguardBottomAreaView.java | 4 ++-- .../systemui/tuner/LockscreenFragment.java | 19 +++++++++++++++++-- 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java b/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java index 1b8efa79ad739..9c173bd169673 100644 --- a/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java +++ b/packages/SystemUI/plugin/src/com/android/systemui/plugins/IntentButtonProvider.java @@ -32,6 +32,7 @@ public interface IntentButtonProvider extends Plugin { public boolean isVisible = true; public CharSequence contentDescription = null; public Drawable drawable; + public boolean tint = true; } public IconState getIcon(); diff --git a/packages/SystemUI/res/layout/keyguard_bottom_area.xml b/packages/SystemUI/res/layout/keyguard_bottom_area.xml index 078f9d73ffecc..fc1271cf74b6f 100644 --- a/packages/SystemUI/res/layout/keyguard_bottom_area.xml +++ b/packages/SystemUI/res/layout/keyguard_bottom_area.xml @@ -66,7 +66,6 @@ android:layout_height="@dimen/keyguard_affordance_height" android:layout_width="@dimen/keyguard_affordance_width" android:layout_gravity="bottom|end" - android:tint="#ffffffff" android:src="@drawable/ic_camera_alt_24dp" android:scaleType="center" android:contentDescription="@string/accessibility_camera_button" /> @@ -76,7 +75,6 @@ android:layout_height="@dimen/keyguard_affordance_height" android:layout_width="@dimen/keyguard_affordance_width" android:layout_gravity="bottom|start" - android:tint="#ffffffff" android:src="@drawable/ic_phone_24dp" android:scaleType="center" android:contentDescription="@string/accessibility_phone_button" /> diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java index 8b4225a8ab0b9..b15f0900a72b5 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardAffordanceView.java @@ -21,6 +21,7 @@ import android.animation.AnimatorListenerAdapter; import android.animation.ArgbEvaluator; import android.animation.PropertyValuesHolder; import android.animation.ValueAnimator; +import android.annotation.Nullable; import android.content.Context; import android.graphics.Canvas; import android.graphics.CanvasProperty; @@ -78,6 +79,7 @@ public class KeyguardAffordanceView extends ImageView { private boolean mSupportHardware; private boolean mFinishing; private boolean mLaunchingAffordance; + private boolean mShouldTint = true; private CanvasProperty mHwCircleRadius; private CanvasProperty mHwCenterX; @@ -137,6 +139,12 @@ public class KeyguardAffordanceView extends ImageView { mFlingAnimationUtils = new FlingAnimationUtils(mContext, 0.3f); } + public void setImageDrawable(@Nullable Drawable drawable, boolean tint) { + super.setImageDrawable(drawable); + mShouldTint = tint; + updateIconColor(); + } + @Override protected void onLayout(boolean changed, int left, int top, int right, int bottom) { super.onLayout(changed, left, top, right, bottom); @@ -165,6 +173,7 @@ public class KeyguardAffordanceView extends ImageView { } private void updateIconColor() { + if (!mShouldTint) return; Drawable drawable = getDrawable().mutate(); float alpha = mCircleRadius / mMinBackgroundRadius; alpha = Math.min(1.0f, alpha); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java index 14f991997e354..2836f41b04f59 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -324,7 +324,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL private void updateRightAffordanceIcon() { IconState state = mRightButton.getIcon(); mRightAffordanceView.setVisibility(state.isVisible ? View.VISIBLE : View.GONE); - mRightAffordanceView.setImageDrawable(state.drawable); + mRightAffordanceView.setImageDrawable(state.drawable, state.tint); mRightAffordanceView.setContentDescription(state.contentDescription); } @@ -376,7 +376,7 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL private void updateLeftAffordanceIcon() { IconState state = mLeftButton.getIcon(); mLeftAffordanceView.setVisibility(state.isVisible ? View.VISIBLE : View.GONE); - mLeftAffordanceView.setImageDrawable(state.drawable); + mLeftAffordanceView.setImageDrawable(state.drawable, state.tint); mLeftAffordanceView.setContentDescription(state.contentDescription); } diff --git a/packages/SystemUI/src/com/android/systemui/tuner/LockscreenFragment.java b/packages/SystemUI/src/com/android/systemui/tuner/LockscreenFragment.java index 9d579f561ea89..6f4a3a4969fa9 100644 --- a/packages/SystemUI/src/com/android/systemui/tuner/LockscreenFragment.java +++ b/packages/SystemUI/src/com/android/systemui/tuner/LockscreenFragment.java @@ -26,6 +26,7 @@ import android.content.pm.LauncherApps.ShortcutQuery; import android.content.pm.PackageManager.NameNotFoundException; import android.content.pm.ShortcutInfo; import android.graphics.drawable.Drawable; +import android.graphics.drawable.ScaleDrawable; import android.os.Bundle; import android.os.Handler; import android.os.Process; @@ -37,6 +38,9 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.RecyclerView.ViewHolder; import android.text.TextUtils; +import android.util.Log; +import android.util.TypedValue; +import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -46,6 +50,7 @@ import android.widget.TextView; import com.android.systemui.Dependency; import com.android.systemui.R; import com.android.systemui.plugins.IntentButtonProvider.IntentButton; +import com.android.systemui.statusbar.ScalingDrawableWrapper; import com.android.systemui.statusbar.phone.ExpandableIndicator; import com.android.systemui.tuner.ShortcutParser.Shortcut; import com.android.systemui.tuner.TunerService.Tunable; @@ -365,8 +370,13 @@ public class LockscreenFragment extends PreferenceFragment { mShortcut = shortcut; mIconState = new IconState(); mIconState.isVisible = true; - mIconState.drawable = shortcut.icon.loadDrawable(context); + mIconState.drawable = shortcut.icon.loadDrawable(context).mutate(); mIconState.contentDescription = mShortcut.label; + int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, + context.getResources().getDisplayMetrics()); + mIconState.drawable = new ScalingDrawableWrapper(mIconState.drawable, + size / (float) mIconState.drawable.getIntrinsicWidth()); + mIconState.tint = false; } @Override @@ -388,8 +398,13 @@ public class LockscreenFragment extends PreferenceFragment { mIntent = new Intent().setComponent(new ComponentName(info.packageName, info.name)); mIconState = new IconState(); mIconState.isVisible = true; - mIconState.drawable = info.loadIcon(context.getPackageManager()); + mIconState.drawable = info.loadIcon(context.getPackageManager()).mutate(); mIconState.contentDescription = info.loadLabel(context.getPackageManager()); + int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 32, + context.getResources().getDisplayMetrics()); + mIconState.drawable = new ScalingDrawableWrapper(mIconState.drawable, + size / (float) mIconState.drawable.getIntrinsicWidth()); + mIconState.tint = false; } @Override