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

Commit 16af2395 authored by Robert Horvath's avatar Robert Horvath Committed by Android (Google) Code Review
Browse files

Merge changes from topic "inattentive-sleep"

* changes:
  Remove inattentive sleep string translations
  Fade out inattentive sleep warning overlay
parents 80a32fe0 d2b6e5d1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -197,5 +197,5 @@ oneway interface IStatusBar
    /**
     * Dismiss the warning that the device is about to go to sleep due to user inactivity.
     */
    void dismissInattentiveSleepWarning();
    void dismissInattentiveSleepWarning(boolean animated);
}
+1 −1
Original line number Diff line number Diff line
@@ -122,5 +122,5 @@ interface IStatusBarService
    /**
     * Dismiss the warning that the device is about to go to sleep due to user inactivity.
     */
    void dismissInattentiveSleepWarning();
    void dismissInattentiveSleepWarning(boolean animated);
}
+2 −2
Original line number Diff line number Diff line
@@ -54,9 +54,9 @@ public class InattentiveSleepWarningController extends SystemUI implements Comma
    }

    @Override
    public void dismissInattentiveSleepWarning() {
    public void dismissInattentiveSleepWarning(boolean animated) {
        if (mOverlayView != null) {
            mOverlayView.dismiss();
            mOverlayView.dismiss(animated);
        }
    }
}
+50 −5
Original line number Diff line number Diff line
@@ -16,11 +16,15 @@

package com.android.systemui.power;

import android.animation.Animator;
import android.animation.AnimatorInflater;
import android.animation.AnimatorListenerAdapter;
import android.content.Context;
import android.graphics.PixelFormat;
import android.os.Binder;
import android.os.IBinder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.FrameLayout;
@@ -34,6 +38,8 @@ import com.android.systemui.R;
public class InattentiveSleepWarningView extends FrameLayout {
    private final IBinder mWindowToken = new Binder();
    private final WindowManager mWindowManager;
    private Animator mFadeOutAnimator;
    private boolean mDismissing;

    InattentiveSleepWarningView(Context context) {
        super(context);
@@ -47,23 +53,62 @@ public class InattentiveSleepWarningView extends FrameLayout {
            // overlay consumes key presses
            return true;
        });

        mFadeOutAnimator = AnimatorInflater.loadAnimator(getContext(),
                com.android.internal.R.animator.fade_out);
        mFadeOutAnimator.setTarget(this);
        mFadeOutAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                removeView();
            }

            @Override
            public void onAnimationCancel(Animator animation) {
                mDismissing = false;
                setAlpha(1f);
                setVisibility(View.VISIBLE);
            }
        });
    }

    private void removeView() {
        if (mDismissing) {
            setVisibility(View.INVISIBLE);
            mWindowManager.removeView(InattentiveSleepWarningView.this);
        }
    }

    /**
     * Show the warning.
     */
    public void show() {
        if (getParent() == null) {
            mWindowManager.addView(this, getLayoutParams(mWindowToken));
        if (getParent() != null) {
            if (mFadeOutAnimator.isStarted()) {
                mFadeOutAnimator.cancel();
            }
            return;
        }

        setAlpha(1f);
        setVisibility(View.VISIBLE);
        mWindowManager.addView(this, getLayoutParams(mWindowToken));
    }

    /**
     * Dismiss the warning.
     */
    public void dismiss() {
        if (getParent() != null) {
            mWindowManager.removeView(this);
    public void dismiss(boolean animated) {
        if (getParent() == null) {
            return;
        }

        mDismissing = true;

        if (animated) {
            postOnAnimation(mFadeOutAnimator::start);
        } else {
            removeView();
        }
    }

+4 −4
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
         * Called to notify System UI that the warning about the device going to sleep
         * due to prolonged user inactivity should be dismissed.
         */
        default void dismissInattentiveSleepWarning() { }
        default void dismissInattentiveSleepWarning(boolean animated) { }
    }

    public CommandQueue(Context context) {
@@ -816,9 +816,9 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
    }

    @Override
    public void dismissInattentiveSleepWarning() {
    public void dismissInattentiveSleepWarning(boolean animated) {
        synchronized (mLock) {
            mHandler.obtainMessage(MSG_DISMISS_INATTENTIVE_SLEEP_WARNING)
            mHandler.obtainMessage(MSG_DISMISS_INATTENTIVE_SLEEP_WARNING, animated)
                    .sendToTarget();
        }
    }
@@ -1175,7 +1175,7 @@ public class CommandQueue extends IStatusBar.Stub implements CallbackController<
                    break;
                case MSG_DISMISS_INATTENTIVE_SLEEP_WARNING:
                    for (int i = 0; i < mCallbacks.size(); i++) {
                        mCallbacks.get(i).dismissInattentiveSleepWarning();
                        mCallbacks.get(i).dismissInattentiveSleepWarning((Boolean) msg.obj);
                    }
                    break;
            }
Loading