From 4272f44f3fcd6e4c984d66a6239252abd65cbbf6 Mon Sep 17 00:00:00 2001 From: Lucas Dupin Date: Sat, 13 Jan 2018 22:00:35 -0800 Subject: [PATCH] Add battery to AOD Showing battery percentage in AOD in the keyguard indication area when also randomizing the text field position to avoid burn-in. Removed charging indication from KeyguardStatusView since now it's always visible in the indication area. Bug: 64155983 Test: flash taimen, look at AOD Test: flash walleye, look at AOD Test: unplug device, look at message Test: wait for change in battery level in AOD Change-Id: I6110d47d155e95e838cb901ab0928f0512454ab5 --- .../layout/keyguard_status_view.xml | 10 -- .../res/layout/keyguard_bottom_area.xml | 2 + packages/SystemUI/res/values/dimens.xml | 1 + .../android/keyguard/KeyguardStatusView.java | 14 +- .../keyguard/KeyguardUpdateMonitor.java | 10 +- .../com/android/systemui/ChargingView.java | 126 ------------------ .../KeyguardIndicationController.java | 14 +- .../phone/KeyguardBottomAreaView.java | 54 ++++++-- .../phone/NotificationPanelView.java | 7 +- .../systemui/statusbar/phone/StatusBar.java | 2 +- 10 files changed, 75 insertions(+), 165 deletions(-) delete mode 100644 packages/SystemUI/src/com/android/systemui/ChargingView.java diff --git a/packages/SystemUI/res-keyguard/layout/keyguard_status_view.xml b/packages/SystemUI/res-keyguard/layout/keyguard_status_view.xml index 347cf1cb09218..9adb5501345db 100644 --- a/packages/SystemUI/res-keyguard/layout/keyguard_status_view.xml +++ b/packages/SystemUI/res-keyguard/layout/keyguard_status_view.xml @@ -50,16 +50,6 @@ android:format12Hour="@string/keyguard_widget_12_hours_format" android:format24Hour="@string/keyguard_widget_24_hours_format" android:layout_marginBottom="@dimen/bottom_text_spacing_digital" /> - @@ -50,6 +51,7 @@ android:gravity="center_horizontal" android:textStyle="italic" android:textColor="?attr/wallpaperTextColorSecondary" + android:textSize="16sp" android:textAppearance="?android:attr/textAppearanceSmall" android:accessibilityLiveRegion="polite" /> diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 47a8574ae235f..39ed08eae55a6 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -579,6 +579,7 @@ 24dp 65dp + 30dp 12sp diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java index 4b9a8744900d6..2873afbca8e95 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardStatusView.java @@ -16,7 +16,6 @@ package com.android.keyguard; -import android.app.ActivityManager; import android.app.AlarmManager; import android.content.Context; import android.content.res.Configuration; @@ -40,7 +39,6 @@ import android.widget.TextClock; import android.widget.TextView; import com.android.internal.widget.LockPatternUtils; -import com.android.systemui.ChargingView; import com.google.android.collect.Sets; @@ -60,7 +58,6 @@ public class KeyguardStatusView extends GridLayout { private View mClockSeparator; private TextView mOwnerInfo; private ViewGroup mClockContainer; - private ChargingView mBatteryDoze; private KeyguardSliceView mKeyguardSlice; private Runnable mPendingMarqueeStart; private Handler mHandler; @@ -155,11 +152,9 @@ public class KeyguardStatusView extends GridLayout { mClockView.setAccessibilityDelegate(new KeyguardClockAccessibilityDelegate(mContext)); } mOwnerInfo = findViewById(R.id.owner_info); - mBatteryDoze = findViewById(R.id.battery_doze); mKeyguardSlice = findViewById(R.id.keyguard_status_area); mClockSeparator = findViewById(R.id.clock_separator); - mVisibleInDoze = Sets.newArraySet(mBatteryDoze, mClockView, mKeyguardSlice, - mClockSeparator); + mVisibleInDoze = Sets.newArraySet(mClockView, mKeyguardSlice, mClockSeparator); mTextColor = mClockView.getCurrentTextColor(); mKeyguardSlice.setListener(this::onSliceContentChanged); @@ -184,10 +179,6 @@ public class KeyguardStatusView extends GridLayout { mClockView.setTranslationY(translation); mClockView.setScaleX(clockScale); mClockView.setScaleY(clockScale); - final float batteryTranslation = - -(mClockView.getWidth() - (mClockView.getWidth() * clockScale)) / 2; - mBatteryDoze.setTranslationX(batteryTranslation); - mBatteryDoze.setTranslationY(translation); mClockSeparator.setVisibility(hasHeader ? VISIBLE : GONE); } @@ -310,7 +301,7 @@ public class KeyguardStatusView extends GridLayout { } } - public void setDark(float darkAmount) { + public void setDarkAmount(float darkAmount) { if (mDarkAmount == darkAmount) { return; } @@ -331,7 +322,6 @@ public class KeyguardStatusView extends GridLayout { final int blendedTextColor = ColorUtils.blendARGB(mTextColor, Color.WHITE, darkAmount); updateDozeVisibleViews(); - mBatteryDoze.setDark(dark); mKeyguardSlice.setDark(darkAmount); mClockView.setTextColor(blendedTextColor); mClockSeparator.setBackgroundColor(blendedTextColor); diff --git a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java index ab2bce8cc094c..e58ad0589c8ad 100644 --- a/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java +++ b/packages/SystemUI/src/com/android/keyguard/KeyguardUpdateMonitor.java @@ -1613,11 +1613,10 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { } } - private static boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { + private boolean isBatteryUpdateInteresting(BatteryStatus old, BatteryStatus current) { final boolean nowPluggedIn = current.isPluggedIn(); final boolean wasPluggedIn = old.isPluggedIn(); - final boolean stateChangedWhilePluggedIn = - wasPluggedIn == true && nowPluggedIn == true + final boolean stateChangedWhilePluggedIn = wasPluggedIn && nowPluggedIn && (old.status != current.status); // change in plug state is always interesting @@ -1630,6 +1629,11 @@ public class KeyguardUpdateMonitor implements TrustManager.TrustListener { return true; } + // change in battery level while keyguard visible + if (mKeyguardIsVisible && old.level != current.level) { + return true; + } + // change where battery needs charging if (!nowPluggedIn && current.isBatteryLow() && current.level != old.level) { return true; diff --git a/packages/SystemUI/src/com/android/systemui/ChargingView.java b/packages/SystemUI/src/com/android/systemui/ChargingView.java deleted file mode 100644 index 33f8b069b7515..0000000000000 --- a/packages/SystemUI/src/com/android/systemui/ChargingView.java +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Copyright (C) 2017 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.systemui; - -import android.annotation.Nullable; -import android.content.Context; -import android.content.res.TypedArray; -import android.os.UserHandle; -import android.util.AttributeSet; -import android.widget.ImageView; - -import com.android.internal.hardware.AmbientDisplayConfiguration; -import com.android.systemui.statusbar.policy.BatteryController; -import com.android.systemui.statusbar.policy.ConfigurationController; - -/** - * A view that only shows its drawable while the phone is charging. - * - * Also reloads its drawable upon density changes. - */ -public class ChargingView extends ImageView implements - BatteryController.BatteryStateChangeCallback, - ConfigurationController.ConfigurationListener { - - private static final long CHARGING_INDICATION_DELAY_MS = 1000; - - private final AmbientDisplayConfiguration mConfig; - private final Runnable mClearSuppressCharging = this::clearSuppressCharging; - private BatteryController mBatteryController; - private int mImageResource; - private boolean mCharging; - private boolean mDark; - private boolean mSuppressCharging; - - - private void clearSuppressCharging() { - mSuppressCharging = false; - removeCallbacks(mClearSuppressCharging); - updateVisibility(); - } - - public ChargingView(Context context, @Nullable AttributeSet attrs) { - super(context, attrs); - - mConfig = new AmbientDisplayConfiguration(context); - - TypedArray a = context.obtainStyledAttributes(attrs, new int[]{android.R.attr.src}); - int srcResId = a.getResourceId(0, 0); - - if (srcResId != 0) { - mImageResource = srcResId; - } - - a.recycle(); - - updateVisibility(); - } - - @Override - public void onAttachedToWindow() { - super.onAttachedToWindow(); - mBatteryController = Dependency.get(BatteryController.class); - mBatteryController.addCallback(this); - Dependency.get(ConfigurationController.class).addCallback(this); - } - - @Override - public void onDetachedFromWindow() { - super.onDetachedFromWindow(); - mBatteryController.removeCallback(this); - Dependency.get(ConfigurationController.class).removeCallback(this); - removeCallbacks(mClearSuppressCharging); - } - - @Override - public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) { - boolean startCharging = charging && !mCharging; - if (startCharging && deviceWillWakeUpWhenPluggedIn() && mDark) { - // We're about to wake up, and thus don't want to show the indicator just for it to be - // hidden again. - clearSuppressCharging(); - mSuppressCharging = true; - postDelayed(mClearSuppressCharging, CHARGING_INDICATION_DELAY_MS); - } - mCharging = charging; - updateVisibility(); - } - - private boolean deviceWillWakeUpWhenPluggedIn() { - boolean plugTurnsOnScreen = getResources().getBoolean( - com.android.internal.R.bool.config_unplugTurnsOnScreen); - boolean aod = mConfig.alwaysOnEnabled(UserHandle.USER_CURRENT); - return !aod && plugTurnsOnScreen; - } - - @Override - public void onDensityOrFontScaleChanged() { - setImageResource(mImageResource); - } - - public void setDark(boolean dark) { - mDark = dark; - if (!dark) { - clearSuppressCharging(); - } - updateVisibility(); - } - - private void updateVisibility() { - setVisibility(mCharging && !mSuppressCharging && mDark ? VISIBLE : INVISIBLE); - } -} diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 85400a15dfc53..43047ed6a5c56 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -52,6 +52,8 @@ import com.android.systemui.statusbar.policy.UserInfoController; import com.android.systemui.util.wakelock.SettableWakeLock; import com.android.systemui.util.wakelock.WakeLock; +import java.text.NumberFormat; + /** * Controls the indications and error messages shown on the Keyguard */ @@ -87,6 +89,7 @@ public class KeyguardIndicationController { private boolean mPowerCharged; private int mChargingSpeed; private int mChargingWattage; + private int mBatteryLevel; private String mMessageToShowOnScreenOn; private KeyguardUpdateMonitorCallback mUpdateMonitorCallback; @@ -285,14 +288,18 @@ public class KeyguardIndicationController { // Walk down a precedence-ordered list of what indication // should be shown based on user or device state if (mDozing) { - // If we're dozing, never show a persistent indication. + mTextView.setTextColor(Color.WHITE); if (!TextUtils.isEmpty(mTransientIndication)) { // When dozing we ignore any text color and use white instead, because // colors can be hard to read in low brightness. - mTextView.setTextColor(Color.WHITE); mTextView.switchIndication(mTransientIndication); + } else if (mPowerPluggedIn) { + String indication = computePowerIndication(); + mTextView.switchIndication(indication); } else { - mTextView.switchIndication(null); + String percentage = NumberFormat.getPercentInstance() + .format(mBatteryLevel / 100f); + mTextView.switchIndication(percentage); } return; } @@ -422,6 +429,7 @@ public class KeyguardIndicationController { mPowerCharged = status.isCharged(); mChargingWattage = status.maxChargingWattage; mChargingSpeed = status.getChargingSpeed(mSlowThreshold, mFastThreshold); + mBatteryLevel = status.level; updateIndication(); if (mDozing) { if (!wasPluggedIn && mPowerPluggedIn) { 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 01b3b442f2b69..ca66e987933c4 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/KeyguardBottomAreaView.java @@ -51,6 +51,7 @@ import android.telecom.TelecomManager; import android.text.TextUtils; import android.util.AttributeSet; import android.util.Log; +import android.util.MathUtils; import android.util.TypedValue; import android.view.View; import android.view.ViewGroup; @@ -166,6 +167,10 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL private String mLeftButtonStr; private LockscreenGestureLogger mLockscreenGestureLogger = new LockscreenGestureLogger(); private boolean mDozing; + private int mIndicationBottomMargin; + private int mIndicationBottomMarginAmbient; + private float mDarkAmount; + private int mBurnInXOffset; public KeyguardBottomAreaView(Context context) { this(context, null); @@ -235,6 +240,10 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL mEnterpriseDisclosure = findViewById( R.id.keyguard_indication_enterprise_disclosure); mIndicationText = findViewById(R.id.keyguard_indication_text); + mIndicationBottomMargin = getResources().getDimensionPixelSize( + R.dimen.keyguard_indication_margin_bottom); + mIndicationBottomMarginAmbient = getResources().getDimensionPixelSize( + R.dimen.keyguard_indication_margin_bottom_ambient); updateCameraVisibility(); mUnlockMethodCache = UnlockMethodCache.getInstance(getContext()); mUnlockMethodCache.addListener(this); @@ -303,11 +312,13 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - int indicationBottomMargin = getResources().getDimensionPixelSize( + mIndicationBottomMargin = getResources().getDimensionPixelSize( R.dimen.keyguard_indication_margin_bottom); + mIndicationBottomMarginAmbient = getResources().getDimensionPixelSize( + R.dimen.keyguard_indication_margin_bottom_ambient); MarginLayoutParams mlp = (MarginLayoutParams) mIndicationArea.getLayoutParams(); - if (mlp.bottomMargin != indicationBottomMargin) { - mlp.bottomMargin = indicationBottomMargin; + if (mlp.bottomMargin != mIndicationBottomMargin) { + mlp.bottomMargin = mIndicationBottomMargin; mIndicationArea.setLayoutParams(mlp); } @@ -543,6 +554,22 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL } } + public void setDarkAmount(float darkAmount) { + if (darkAmount == mDarkAmount) { + return; + } + mDarkAmount = darkAmount; + // Let's randomize the bottom margin every time we wake up to avoid burn-in. + if (darkAmount == 0) { + mIndicationBottomMarginAmbient = getResources().getDimensionPixelSize( + R.dimen.keyguard_indication_margin_bottom_ambient) + + (int) (Math.random() * mIndicationText.getTextSize()); + } + mIndicationArea.setAlpha(MathUtils.lerp(1f, 0.7f, darkAmount)); + mIndicationArea.setTranslationY(MathUtils.lerp(0, + mIndicationBottomMargin - mIndicationBottomMarginAmbient, darkAmount)); + } + private static boolean isSuccessfulLaunch(int result) { return result == ActivityManager.START_SUCCESS || result == ActivityManager.START_DELIVERED_TO_TOP @@ -687,11 +714,6 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL if (mRightAffordanceView.getVisibility() == View.VISIBLE) { startFinishDozeAnimationElement(mRightAffordanceView, delay); } - mIndicationArea.setAlpha(0f); - mIndicationArea.animate() - .alpha(1f) - .setInterpolator(Interpolators.LINEAR_OUT_SLOW_IN) - .setDuration(NotificationPanelView.DOZE_ANIMATION_DURATION); } private void startFinishDozeAnimationElement(View element, long delay) { @@ -815,6 +837,22 @@ public class KeyguardBottomAreaView extends FrameLayout implements View.OnClickL } } + public void dozeTimeTick() { + if (mDarkAmount == 1) { + // Move indication every minute to avoid burn-in + final int dozeTranslation = mIndicationBottomMargin - mIndicationBottomMarginAmbient; + mIndicationArea.setTranslationY(dozeTranslation + (float) Math.random() * 5); + } + } + + public void setBurnInXOffset(int burnInXOffset) { + if (mBurnInXOffset == burnInXOffset) { + return; + } + mBurnInXOffset = burnInXOffset; + mIndicationArea.setTranslationX(burnInXOffset); + } + private class DefaultLeftButton implements IntentButton { private IconState mIconState = new IconState(); diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java index 32675d3b2aacc..0cc7f5dfbae15 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/NotificationPanelView.java @@ -478,6 +478,7 @@ public class NotificationPanelView extends PanelView implements } mNotificationStackScroller.setIntrinsicPadding(stackScrollerPadding); mNotificationStackScroller.setDarkShelfOffsetX(mClockPositionResult.clockX); + mKeyguardBottomArea.setBurnInXOffset(mClockPositionResult.clockX); requestScrollerTopPaddingUpdate(animate); } @@ -2608,7 +2609,8 @@ public class NotificationPanelView extends PanelView implements private void setDarkAmount(float amount) { mDarkAmount = amount; - mKeyguardStatusView.setDark(mDarkAmount); + mKeyguardStatusView.setDarkAmount(mDarkAmount); + mKeyguardBottomArea.setDarkAmount(mDarkAmount); positionClockAndNotifications(); } @@ -2630,8 +2632,9 @@ public class NotificationPanelView extends PanelView implements } } - public void refreshTime() { + public void dozeTimeTick() { mKeyguardStatusView.refreshTime(); + mKeyguardBottomArea.dozeTimeTick(); if (mDarkAmount > 0) { positionClockAndNotifications(); } diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java index bc5440d116151..af65a86676e8f 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/StatusBar.java @@ -4645,7 +4645,7 @@ public class StatusBar extends SystemUI implements DemoMode, @Override public void dozeTimeTick() { - mNotificationPanel.refreshTime(); + mNotificationPanel.dozeTimeTick(); } @Override