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

Commit 898d0bc3 authored by Cédric Bellegarde's avatar Cédric Bellegarde Committed by Bruno Martins
Browse files

frameworks: Add support for clock auto-hiding

Hide statusbar clock when launcher is visible. Useful when you already have a clock as widget.

Change-Id: I03dfc81bc055f2f865ac704e3bf9d9d104fac272
parent 5ce459e0
Loading
Loading
Loading
Loading
+55 −2
Original line number Original line Diff line number Diff line
@@ -16,7 +16,9 @@


package com.android.systemui.statusbar.policy;
package com.android.systemui.statusbar.policy;


import android.app.ActivityManager;
import android.app.StatusBarManager;
import android.app.StatusBarManager;
import android.app.WindowConfiguration;
import android.content.BroadcastReceiver;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Context;
import android.content.Intent;
import android.content.Intent;
@@ -50,6 +52,9 @@ import com.android.systemui.demomode.DemoModeCommandReceiver;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.plugins.DarkIconDispatcher.DarkReceiver;
import com.android.systemui.settings.CurrentUserTracker;
import com.android.systemui.settings.CurrentUserTracker;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.TaskStackChangeListener;
import com.android.systemui.shared.system.TaskStackChangeListeners;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.CommandQueue;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.statusbar.policy.ConfigurationController.ConfigurationListener;
import com.android.systemui.tuner.TunerService;
import com.android.systemui.tuner.TunerService;
@@ -72,6 +77,8 @@ public class Clock extends TextView implements
        CommandQueue.Callbacks,
        CommandQueue.Callbacks,
        DarkReceiver, ConfigurationListener {
        DarkReceiver, ConfigurationListener {


    private static final String CLOCK_AUTO_HIDE =
            "lineagesystem:" + LineageSettings.System.STATUS_BAR_CLOCK_AUTO_HIDE;
    public static final String CLOCK_SECONDS = "clock_seconds";
    public static final String CLOCK_SECONDS = "clock_seconds";
    private static final String CLOCK_STYLE =
    private static final String CLOCK_STYLE =
            "lineagesystem:" + LineageSettings.System.STATUS_BAR_AM_PM;
            "lineagesystem:" + LineageSettings.System.STATUS_BAR_AM_PM;
@@ -86,11 +93,13 @@ public class Clock extends TextView implements
    private final CommandQueue mCommandQueue;
    private final CommandQueue mCommandQueue;
    private int mCurrentUserId;
    private int mCurrentUserId;


    private boolean mClockAutoHide = false;
    private boolean mClockVisibleByPolicy = true;
    private boolean mClockVisibleByPolicy = true;
    private boolean mClockVisibleByUser = getVisibility() == View.VISIBLE;
    private boolean mClockVisibleByUser = getVisibility() == View.VISIBLE;


    private boolean mAttached;
    private boolean mAttached;
    private boolean mScreenReceiverRegistered;
    private boolean mScreenReceiverRegistered;
    private boolean mTaskStackListenerRegistered;
    private Calendar mCalendar;
    private Calendar mCalendar;
    private String mContentDescriptionFormatString;
    private String mContentDescriptionFormatString;
    private SimpleDateFormat mClockFormat;
    private SimpleDateFormat mClockFormat;
@@ -196,7 +205,8 @@ public class Clock extends TextView implements
            // The receiver will return immediately if the view does not have a Handler yet.
            // The receiver will return immediately if the view does not have a Handler yet.
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
            mBroadcastDispatcher.registerReceiverWithHandler(mIntentReceiver, filter,
                    Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
                    Dependency.get(Dependency.TIME_TICK_HANDLER), UserHandle.ALL);
            Dependency.get(TunerService.class).addTunable(this, CLOCK_SECONDS, CLOCK_STYLE);
            Dependency.get(TunerService.class).addTunable(this,
                    CLOCK_AUTO_HIDE, CLOCK_SECONDS, CLOCK_STYLE);
            mCommandQueue.addCallback(this);
            mCommandQueue.addCallback(this);
            mCurrentUserTracker.startTracking();
            mCurrentUserTracker.startTracking();
            mCurrentUserId = mCurrentUserTracker.getCurrentUserId();
            mCurrentUserId = mCurrentUserTracker.getCurrentUserId();
@@ -230,6 +240,17 @@ public class Clock extends TextView implements
            Dependency.get(TunerService.class).removeTunable(this);
            Dependency.get(TunerService.class).removeTunable(this);
            mCommandQueue.removeCallback(this);
            mCommandQueue.removeCallback(this);
            mCurrentUserTracker.stopTracking();
            mCurrentUserTracker.stopTracking();
            handleTaskStackListener(false);
        }
    }

    private void handleTaskStackListener(boolean register) {
        if (register && !mTaskStackListenerRegistered) {
            TaskStackChangeListeners.getInstance().registerTaskStackListener(mTaskStackListener);
            mTaskStackListenerRegistered = true;
        } else if (!register && mTaskStackListenerRegistered) {
            TaskStackChangeListeners.getInstance().unregisterTaskStackListener(mTaskStackListener);
            mTaskStackListenerRegistered = false;
        }
        }
    }
    }


@@ -286,7 +307,7 @@ public class Clock extends TextView implements
    }
    }


    public boolean shouldBeVisible() {
    public boolean shouldBeVisible() {
        return mClockVisibleByPolicy && mClockVisibleByUser;
        return !mClockAutoHide && mClockVisibleByPolicy && mClockVisibleByUser;
    }
    }


    private void updateClockVisibility() {
    private void updateClockVisibility() {
@@ -349,6 +370,8 @@ public class Clock extends TextView implements
            mContentDescriptionFormatString = "";
            mContentDescriptionFormatString = "";
            mDateTimePatternGenerator = null;
            mDateTimePatternGenerator = null;
            updateClock(true);
            updateClock(true);
        } else if (CLOCK_AUTO_HIDE.equals(key)) {
            handleTaskStackListener(TunerService.parseIntegerSwitch(newValue, false));
        }
        }
    }
    }


@@ -413,6 +436,19 @@ public class Clock extends TextView implements
        }
        }
    }
    }


    private void updateShowClock() {
        ActivityManager.RunningTaskInfo runningTask =
                ActivityManagerWrapper.getInstance().getRunningTask();
        final int activityType = runningTask != null
                ? runningTask.configuration.windowConfiguration.getActivityType()
                : WindowConfiguration.ACTIVITY_TYPE_UNDEFINED;
        final boolean clockAutoHide = activityType == WindowConfiguration.ACTIVITY_TYPE_HOME;
        if (mClockAutoHide != clockAutoHide) {
            mClockAutoHide = clockAutoHide;
            updateClockVisibility();
        }
    }

    private final CharSequence getSmallTime() {
    private final CharSequence getSmallTime() {
        Context context = getContext();
        Context context = getContext();
        boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId);
        boolean is24 = DateFormat.is24HourFormat(context, mCurrentUserId);
@@ -552,5 +588,22 @@ public class Clock extends TextView implements
            mSecondsHandler.postAtTime(this, SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
            mSecondsHandler.postAtTime(this, SystemClock.uptimeMillis() / 1000 * 1000 + 1000);
        }
        }
    };
    };

    private final TaskStackChangeListener mTaskStackListener = new TaskStackChangeListener() {
        @Override
        public void onTaskStackChanged() {
            updateShowClock();
        }

        @Override
        public void onTaskRemoved(int taskId) {
            updateShowClock();
        }

        @Override
        public void onTaskMovedToFront(int taskId) {
            updateShowClock();
        }
    };
}
}