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

Commit 1d4d30ae authored by Daniel Sandler's avatar Daniel Sandler
Browse files

It's lights out for you, navigation bar!

Views requesting lights out mode will cause the navbar to
disappear (this is useful for viewing videos/photos/etc
using every pixel of the screen).

But there's a catch: any user activity at all will cause the
lights to come back on and the navbar to return.

Change-Id: I535ed3ba9ae7fab3282c402be256add765395b6f
parent ed742306
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,5 +34,6 @@ oneway interface IStatusBar
    void setMenuKeyVisible(boolean visible);
    void setImeWindowStatus(in IBinder token, int vis, int backDisposition);
    void setHardKeyboardStatus(boolean available, boolean enabled);
    void userActivity();
}
+1 −0
Original line number Diff line number Diff line
@@ -46,4 +46,5 @@ interface IStatusBarService
    void onNotificationClear(String pkg, String tag, int id);
    void setSystemUiVisibility(int vis);
    void setHardKeyboardEnabled(boolean enabled);
    void userActivity();
}
+90 −84
Original line number Diff line number Diff line
@@ -25,12 +25,18 @@
    android:layout_width="match_parent"
    >

    <FrameLayout
        android:id="@+id/background"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:background="#FF000000"
        >

        <LinearLayout android:id="@+id/rot0"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            android:paddingLeft="8dip"
            android:paddingRight="8dip"
        android:background="#FF000000"
            android:orientation="horizontal"
            >

@@ -61,7 +67,6 @@
        <LinearLayout android:id="@+id/rot90"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
        android:background="#FF000000"
            android:orientation="vertical"
            android:visibility="gone"
            >
@@ -93,7 +98,6 @@
        <LinearLayout android:id="@+id/rot270"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
        android:background="#FF000000"
            android:orientation="vertical"
            android:visibility="gone"
            >
@@ -121,4 +125,6 @@
                android:layout_weight="1"
                />
        </LinearLayout>
    
    </FrameLayout>
</com.android.systemui.statusbar.phone.NavigationBarView>
+31 −15
Original line number Diff line number Diff line
@@ -35,28 +35,33 @@ import com.android.internal.statusbar.StatusBarNotification;
public class CommandQueue extends IStatusBar.Stub {
    private static final String TAG = "StatusBar.CommandQueue";

    private static final int MSG_MASK = 0xffff0000;
    private static final int INDEX_MASK = 0x0000ffff;
    private static final int INDEX_MASK = 0xffff;
    private static final int MSG_SHIFT  = 16;
    private static final int MSG_MASK   = 0xffff << MSG_SHIFT;

    private static final int MSG_ICON = 0x00010000;

    private static final int MSG_ICON                   = 1 << MSG_SHIFT;
    private static final int OP_SET_ICON    = 1;
    private static final int OP_REMOVE_ICON = 2;

    private static final int MSG_ADD_NOTIFICATION = 0x00020000;
    private static final int MSG_UPDATE_NOTIFICATION = 0x00030000;
    private static final int MSG_REMOVE_NOTIFICATION = 0x00040000;
    private static final int MSG_ADD_NOTIFICATION       = 2 << MSG_SHIFT;
    private static final int MSG_UPDATE_NOTIFICATION    = 3 << MSG_SHIFT;
    private static final int MSG_REMOVE_NOTIFICATION    = 4 << MSG_SHIFT;

    private static final int MSG_DISABLE = 0x00050000;
    private static final int MSG_DISABLE                = 5 << MSG_SHIFT;

    private static final int MSG_SET_VISIBILITY = 0x00060000;
    private static final int MSG_SET_VISIBILITY         = 6 << MSG_SHIFT;
    private static final int OP_EXPAND      = 1;
    private static final int OP_COLLAPSE    = 2;

    private static final int MSG_SET_LIGHTS_ON = 0x00070000;
    private static final int MSG_SET_LIGHTS_ON          = 7 << MSG_SHIFT;

    private static final int MSG_SHOW_MENU              = 8 << MSG_SHIFT;
    private static final int MSG_SHOW_IME_BUTTON        = 9 << MSG_SHIFT;
    private static final int MSG_SET_HARD_KEYBOARD_STATUS = 10 << MSG_SHIFT;
    
    private static final int MSG_USER_ACTIVITY          = 11 << MSG_SHIFT;

    private static final int MSG_SHOW_MENU = 0x00080000;
    private static final int MSG_SHOW_IME_BUTTON = 0x00090000;
    private static final int MSG_SET_HARD_KEYBOARD_STATUS = 0x000a0000;

    private StatusBarIconList mList;
    private Callbacks mCallbacks;
@@ -85,6 +90,7 @@ public class CommandQueue extends IStatusBar.Stub {
        public void setMenuKeyVisible(boolean visible);
        public void setImeWindowStatus(IBinder token, int vis, int backDisposition);
        public void setHardKeyboardStatus(boolean available, boolean enabled);
        public void userActivity();
    }

    public CommandQueue(Callbacks callbacks, StatusBarIconList list) {
@@ -183,6 +189,13 @@ public class CommandQueue extends IStatusBar.Stub {
        }
    }

    public void userActivity() {
        synchronized (mList) {
            mHandler.removeMessages(MSG_USER_ACTIVITY);
            mHandler.obtainMessage(MSG_USER_ACTIVITY, 0, 0, null).sendToTarget();
        }
    }

    private final class H extends Handler {
        public void handleMessage(Message msg) {
            final int what = msg.what & MSG_MASK;
@@ -249,6 +262,9 @@ public class CommandQueue extends IStatusBar.Stub {
                case MSG_SET_HARD_KEYBOARD_STATUS:
                    mCallbacks.setHardKeyboardStatus(msg.arg1 != 0, msg.arg2 != 0);
                    break;
                case MSG_USER_ACTIVITY:
                    mCallbacks.userActivity();
                    break;
            }
        }
    }
+51 −0
Original line number Diff line number Diff line
@@ -16,29 +16,73 @@

package com.android.systemui.statusbar.phone;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.ServiceManager;
import android.util.AttributeSet;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.view.View;
import android.view.Surface;
import android.view.WindowManager;
import android.widget.LinearLayout;
import android.content.res.Configuration;

import com.android.internal.statusbar.IStatusBarService;

import com.android.systemui.R;

public class NavigationBarView extends LinearLayout {
    protected IStatusBarService mBarService;
    final Display mDisplay;
    View[] mRotatedViews = new View[4];
    View mBackground;
    Animator mLastAnimator = null;

    public NavigationBarView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mDisplay = ((WindowManager)context.getSystemService(
                Context.WINDOW_SERVICE)).getDefaultDisplay();
        mBarService = IStatusBarService.Stub.asInterface(
                ServiceManager.getService(Context.STATUS_BAR_SERVICE));

        //setLayerType(View.LAYER_TYPE_HARDWARE, null);

        setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                boolean on = (visibility == View.STATUS_BAR_VISIBLE);
                android.util.Log.d("NavigationBarView", "LIGHTS " 
                    + (on ? "ON" : "OUT"));
                setLights(on);
            }
        });
    }

    private void setLights(final boolean on) {
        float oldAlpha = mBackground.getAlpha();
        android.util.Log.d("NavigationBarView", "animating alpha: " + oldAlpha + " -> "
            + (on ? 1f : 0f));

        if (mLastAnimator != null && mLastAnimator.isRunning()) mLastAnimator.cancel();

        mLastAnimator = ObjectAnimator.ofFloat(mBackground, "alpha", oldAlpha, on ? 1f : 0f)
            .setDuration(on ? 250 : 1500);
        mLastAnimator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator _a) {
                mLastAnimator = null;
            }
        });
        mLastAnimator.start();
    }

    public void onFinishInflate() {
        mBackground = findViewById(R.id.background);

        mRotatedViews[Surface.ROTATION_0] = 
        mRotatedViews[Surface.ROTATION_180] = findViewById(R.id.rot0);

@@ -47,6 +91,13 @@ public class NavigationBarView extends LinearLayout {
        mRotatedViews[Surface.ROTATION_270] = findViewById(R.id.rot270);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // immediately bring up the lights
        setLights(true);
        return false; // pass it on
    }

    public void reorient() {
        final int rot = mDisplay.getRotation();
        for (int i=0; i<4; i++) {
Loading