Merge "Add battery to AOD"

This commit is contained in:
Lucas Dupin
2018-01-17 03:36:26 +00:00
committed by Android (Google) Code Review
10 changed files with 75 additions and 165 deletions

View File

@@ -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" />
<com.android.systemui.ChargingView
android:id="@+id/battery_doze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@id/clock_view"
android:layout_alignBottom="@id/clock_view"
android:layout_toEndOf="@id/clock_view"
android:visibility="invisible"
android:src="@drawable/ic_aod_charging_24dp"
android:contentDescription="@string/accessibility_ambient_display_charging" />
<View
android:id="@+id/clock_separator"
android:layout_width="16dp"

View File

@@ -40,6 +40,7 @@
android:gravity="center_horizontal"
android:textStyle="italic"
android:textColor="?attr/wallpaperTextColorSecondary"
android:textSize="16sp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:visibility="gone" />
@@ -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" />

View File

@@ -579,6 +579,7 @@
<dimen name="keyguard_affordance_icon_width">24dp</dimen>
<dimen name="keyguard_indication_margin_bottom">65dp</dimen>
<dimen name="keyguard_indication_margin_bottom_ambient">30dp</dimen>
<!-- The text size for battery level -->
<dimen name="battery_level_text_size">12sp</dimen>

View File

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

View File

@@ -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;

View File

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

View File

@@ -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) {

View File

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

View File

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

View File

@@ -4645,7 +4645,7 @@ public class StatusBar extends SystemUI implements DemoMode,
@Override
public void dozeTimeTick() {
mNotificationPanel.refreshTime();
mNotificationPanel.dozeTimeTick();
}
@Override