Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ac32c9ac authored by Beverly's avatar Beverly
Browse files

Wireless charging on aod and lockscreen

- wireless charging animation plays on aod + lockscreen
- timing changes on animation based on design spec
- charging feedback only given if phone is not just booted

Test: manual
Bug: 67598445
Change-Id: I009ff6016141bcdfe9f0392bb9a1c220ea88dfe5
parent c65eb444
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -323,4 +323,16 @@ public class BatteryManager {
    public long getLongProperty(int id) {
        return queryProperty(id);
    }

    /**
     * Return true if the plugType given is wired
     * @param plugType {@link #BATTERY_PLUGGED_AC}, {@link #BATTERY_PLUGGED_USB},
     *        or {@link #BATTERY_PLUGGED_WIRELESS}
     *
     * @return true if plugType is wired
     * @hide
     */
    public static boolean isPlugWired(int plugType) {
        return plugType == BATTERY_PLUGGED_USB || plugType == BATTERY_PLUGGED_AC;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ oneway interface IStatusBar
    void animateCollapsePanels();
    void togglePanel();

    void showChargingAnimation(int batteryLevel);
    void showWirelessChargingAnimation(int batteryLevel);

    /**
     * Notifies the status bar of a System UI visibility flag change.
+22 −7
Original line number Diff line number Diff line
@@ -902,12 +902,27 @@
    <dimen name="fingerprint_dialog_animation_translation_offset">350dp</dimen>

    <!-- Wireless Charging Animation values -->
    <!-- Starting text size of batteryLevel for wireless charging animation -->
    <dimen name="config_batteryLevelTextSizeStart" format="float">5.0</dimen>
    <!-- Ending text size of batteryLevel for wireless charging animation -->
    <dimen name="config_batteryLevelTextSizeEnd" format="float">32.0</dimen>
    <!-- Wireless Charging battery level text animation duration -->
    <integer name="config_batteryLevelTextAnimationDuration">400</integer>
    <dimen name="wireless_charging_dots_radius_start">0dp</dimen>
    <dimen name="wireless_charging_dots_radius_end">4dp</dimen>
    <dimen name="wireless_charging_circle_radius_start">28dp</dimen>
    <dimen name="wireless_charging_circle_radius_end">92dp</dimen>
    <integer name="wireless_charging_angle_offset">20</integer>
    <integer name="wireless_charging_scale_dots_duration">83</integer>
    <integer name="wireless_charging_num_dots">20</integer>
    <!-- Starting text size in dp of batteryLevel for wireless charging animation -->
    <dimen name="wireless_charging_anim_battery_level_text_size_start">0dp</dimen>
    <!-- Ending text size in dp of batteryLevel for wireless charging animation -->
    <dimen name="wireless_charging_anim_battery_level_text_size_end">14dp</dimen>
    <!-- time until battery info is at full opacity-->
    <integer name="wireless_charging_anim_opacity_offset">80</integer>
    <!-- duration batteryLevel opacity goes from 0 to 1 duration -->
    <integer name="wireless_charging_battery_level_text_opacity_duration">117</integer>
    <!-- battery text scale animation duration -->
    <integer name="wireless_charging_battery_level_text_scale_animation_duration">367</integer>
    <!--time until wireless charging animation starts to fade-->
    <integer name="wireless_charging_fade_offset">920</integer>
    <!-- duration wireless charging animation takes to full fade to 0 opacity -->
    <integer name="wireless_charging_fade_duration">200</integer>

    <!-- Wired charging on AOD, text animation duration -->
    <integer name="wired_charging_aod_text_animation_duration_down">500</integer>
+22 −19
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.systemui.charging;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.PixelFormat;
import android.os.Handler;
import android.os.Looper;
@@ -36,13 +35,18 @@ import android.view.WindowManager;
 */
public class WirelessChargingAnimation {

    public static final long DURATION = 1400;
    public static final long DURATION = 1133;
    private static final String TAG = "WirelessChargingView";
    private static final boolean LOCAL_LOGV = false;

    private final WirelessChargingView mCurrentWirelessChargingView;
    private static WirelessChargingView mPreviousWirelessChargingView;

    public interface Callback {
        void onAnimationStarting();
        void onAnimationEnded();
    }

    /**
     * Constructs an empty WirelessChargingAnimation object.  If looper is null,
     * Looper.myLooper() is used.  Must set
@@ -51,9 +55,9 @@ public class WirelessChargingAnimation {
     * @hide
     */
    public WirelessChargingAnimation(@NonNull Context context, @Nullable Looper looper, int
            batteryLevel) {
            batteryLevel, Callback callback) {
        mCurrentWirelessChargingView = new WirelessChargingView(context, looper,
                batteryLevel);
                batteryLevel, callback);
    }

    /**
@@ -61,8 +65,8 @@ public class WirelessChargingAnimation {
     * @hide
     */
    public static WirelessChargingAnimation makeWirelessChargingAnimation(@NonNull Context context,
            @Nullable Looper looper, int batteryLevel) {
        return new WirelessChargingAnimation(context, looper, batteryLevel);
            @Nullable Looper looper, int batteryLevel, Callback callback) {
        return new WirelessChargingAnimation(context, looper, batteryLevel, callback);
    }

    /**
@@ -95,8 +99,11 @@ public class WirelessChargingAnimation {
        private View mView;
        private View mNextView;
        private WindowManager mWM;
        private Callback mCallback;

        public WirelessChargingView(Context context, @Nullable Looper looper, int batteryLevel) {
        public WirelessChargingView(Context context, @Nullable Looper looper, int batteryLevel,
                Callback callback) {
            mCallback = callback;
            mNextView = new WirelessChargingLayout(context, batteryLevel);
            mGravity = Gravity.CENTER_HORIZONTAL | Gravity.CENTER;

@@ -149,6 +156,8 @@ public class WirelessChargingAnimation {
        }

        public void hide(long duration) {
            mHandler.removeMessages(HIDE);

            if (LOCAL_LOGV) Log.v(TAG, "HIDE: " + this);
            mHandler.sendMessageDelayed(Message.obtain(mHandler, HIDE), duration);
        }
@@ -169,18 +178,6 @@ public class WirelessChargingAnimation {
                    context = mView.getContext();
                }
                mWM = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
                // We can resolve the Gravity here by using the Locale for getting
                // the layout direction
                final Configuration config = mView.getContext().getResources().getConfiguration();
                final int gravity = Gravity.getAbsoluteGravity(mGravity,
                        config.getLayoutDirection());
                mParams.gravity = gravity;
                if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
                    mParams.horizontalWeight = 1.0f;
                }
                if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
                    mParams.verticalWeight = 1.0f;
                }
                mParams.packageName = packageName;
                mParams.hideTimeoutMilliseconds = DURATION;

@@ -191,6 +188,9 @@ public class WirelessChargingAnimation {
                if (LOCAL_LOGV) Log.v(TAG, "ADD! " + mView + " in " + this);

                try {
                    if (mCallback != null) {
                        mCallback.onAnimationStarting();
                    }
                    mWM.addView(mView, mParams);
                } catch (WindowManager.BadTokenException e) {
                    Slog.d(TAG, "Unable to add wireless charging view. " + e);
@@ -203,6 +203,9 @@ public class WirelessChargingAnimation {
            if (mView != null) {
                if (mView.getParent() != null) {
                    if (LOCAL_LOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
                    if (mCallback != null) {
                        mCallback.onAnimationEnded();
                    }
                    mWM.removeViewImmediate(mView);
                }

+57 −12
Original line number Diff line number Diff line
@@ -16,13 +16,16 @@

package com.android.systemui.charging;

import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.util.AttributeSet;
import android.view.animation.PathInterpolator;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.systemui.Interpolators;
import com.android.systemui.R;

import java.text.NumberFormat;
@@ -52,10 +55,9 @@ public class WirelessChargingLayout extends FrameLayout {
        init(c, attrs, -1);
    }

    private void init(Context c, AttributeSet attrs, int batteryLevel) {
    private void init(Context context, AttributeSet attrs, int batteryLevel) {
        final int mBatteryLevel = batteryLevel;

        inflate(c, R.layout.wireless_charging_layout, this);
        inflate(context, R.layout.wireless_charging_layout, this);

        // where the circle animation occurs:
        final WirelessChargingView mChargingView = findViewById(R.id.wireless_charging_view);
@@ -68,14 +70,57 @@ public class WirelessChargingLayout extends FrameLayout {

        if (batteryLevel != UNKNOWN_BATTERY_LEVEL) {
            mPercentage.setText(NumberFormat.getPercentInstance().format(mBatteryLevel / 100f));

            ValueAnimator animator = ObjectAnimator.ofFloat(mPercentage, "textSize",
                    getContext().getResources().getFloat(R.dimen.config_batteryLevelTextSizeStart),
                    getContext().getResources().getFloat(R.dimen.config_batteryLevelTextSizeEnd));

            animator.setDuration((long) getContext().getResources().getInteger(
                    R.integer.config_batteryLevelTextAnimationDuration));
            animator.start();
            mPercentage.setAlpha(0);
        }

        final long chargingAnimationFadeStartOffset = (long) context.getResources().getInteger(
                R.integer.wireless_charging_fade_offset);
        final long chargingAnimationFadeDuration = (long) context.getResources().getInteger(
                R.integer.wireless_charging_fade_duration);
        final int batteryLevelTextSizeStart = context.getResources().getDimensionPixelSize(
                R.dimen.wireless_charging_anim_battery_level_text_size_start);
        final int batteryLevelTextSizeEnd = context.getResources().getDimensionPixelSize(
                R.dimen.wireless_charging_anim_battery_level_text_size_end);

        // Animation Scale: battery percentage text scales from 0% to 100%
        ValueAnimator textSizeAnimator = ObjectAnimator.ofFloat(mPercentage, "textSize",
                batteryLevelTextSizeStart, batteryLevelTextSizeEnd);
        textSizeAnimator.setInterpolator(new PathInterpolator(0, 0, 0, 1));
        textSizeAnimator.setDuration((long) context.getResources().getInteger(
                R.integer.wireless_charging_battery_level_text_scale_animation_duration));

        // Animation Opacity: battery percentage text transitions from 0 to 1 opacity
        ValueAnimator textOpacityAnimator = ObjectAnimator.ofFloat(mPercentage, "alpha", 0, 1);
        textOpacityAnimator.setInterpolator(Interpolators.LINEAR);
        textOpacityAnimator.setDuration((long) context.getResources().getInteger(
                R.integer.wireless_charging_battery_level_text_opacity_duration));
        textOpacityAnimator.setStartDelay((long) context.getResources().getInteger(
                R.integer.wireless_charging_anim_opacity_offset));

        // Animation Opacity: battery percentage text fades from 1 to 0 opacity
        ValueAnimator textFadeAnimator = ObjectAnimator.ofFloat(mPercentage, "alpha", 1, 0);
        textFadeAnimator.setDuration(chargingAnimationFadeDuration);
        textFadeAnimator.setInterpolator(Interpolators.LINEAR);
        textFadeAnimator.setStartDelay(chargingAnimationFadeStartOffset);

        // Animation Opacity: wireless charging circle animation fades from 1 to 0 opacity
        ValueAnimator circleFadeAnimator = ObjectAnimator.ofFloat(mChargingView, "alpha",
                1, 0);
        circleFadeAnimator.setDuration(chargingAnimationFadeDuration);
        circleFadeAnimator.setInterpolator(Interpolators.LINEAR);
        circleFadeAnimator.setStartDelay(chargingAnimationFadeStartOffset);

        // Animation Opacity: secondary text animation fades from 1 to 0 opacity
        ValueAnimator secondaryTextFadeAnimator = ObjectAnimator.ofFloat(mSecondaryText, "alpha",
                1, 0);
        circleFadeAnimator.setDuration(chargingAnimationFadeDuration);
        secondaryTextFadeAnimator.setInterpolator(Interpolators.LINEAR);
        secondaryTextFadeAnimator.setStartDelay(chargingAnimationFadeStartOffset);

        // play all animations together
        AnimatorSet animatorSet = new AnimatorSet();
        animatorSet.playTogether(textSizeAnimator, textOpacityAnimator, textFadeAnimator,
                circleFadeAnimator, secondaryTextFadeAnimator);
        animatorSet.start();
    }
}
 No newline at end of file
Loading