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

Commit 98ddd3ed authored by Robert Burns's avatar Robert Burns Committed by Steve Kondik
Browse files

Interface settings: clock display

Change-Id: I99abcd92320a083a2e3be79fec5cfc3e0bb80b47
parent 03c641e0
Loading
Loading
Loading
Loading
+8 −1
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -120,6 +121,8 @@ public class PhoneStatusBar extends StatusBar {

    private static final boolean CLOSE_PANEL_WHEN_EMPTIED = true;

    private boolean mShowClock;

    // fling gesture tuning parameters, scaled to display density
    private float mSelfExpandVelocityPx; // classic value: 2000px/s
    private float mSelfCollapseVelocityPx; // classic value: 2000px/s (will be negated to collapse "up")
@@ -1059,9 +1062,13 @@ public class PhoneStatusBar extends StatusBar {
    }

    public void showClock(boolean show) {
        ContentResolver resolver = mContext.getContentResolver();

        View clock = mStatusBarView.findViewById(R.id.clock);
        mShowClock = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_CLOCK, 1) == 1);
        if (clock != null) {
            clock.setVisibility(show ? View.VISIBLE : View.GONE);
            clock.setVisibility(show ? (mShowClock ? View.VISIBLE : View.GONE) : View.GONE);
        }
    }

+58 −1
Original line number Diff line number Diff line
@@ -17,14 +17,18 @@
package com.android.systemui.statusbar.policy;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.provider.Settings;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.format.DateFormat;
@@ -57,7 +61,30 @@ public class Clock extends TextView {
    private static final int AM_PM_STYLE_SMALL   = 1;
    private static final int AM_PM_STYLE_GONE    = 2;

    private static final int AM_PM_STYLE = AM_PM_STYLE_GONE;
    private static int AM_PM_STYLE = AM_PM_STYLE_GONE;

    private int mAmPmStyle;
    private boolean mShowClock;

    Handler mHandler;

    class SettingsObserver extends ContentObserver {
        SettingsObserver(Handler handler) {
            super(handler);
        }

        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.STATUS_BAR_AM_PM), false, this);
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.STATUS_BAR_CLOCK), false, this);
        }

        @Override public void onChange(boolean selfChange) {
            updateSettings();
        }
    }

    public Clock(Context context) {
        this(context, null);
@@ -69,6 +96,12 @@ public class Clock extends TextView {

    public Clock(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        mHandler = new Handler();
        SettingsObserver settingsObserver = new SettingsObserver(mHandler);
        settingsObserver.observe();

        updateSettings();
    }

    @Override
@@ -204,5 +237,29 @@ public class Clock extends TextView {
        return result;

    }

    private void updateSettings(){
        ContentResolver resolver = mContext.getContentResolver();

        mAmPmStyle = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_AM_PM, 2));

        if (mAmPmStyle != AM_PM_STYLE) {
            AM_PM_STYLE = mAmPmStyle;
            mClockFormatString = "";

            if (mAttached) {
                updateClock();
            }
        }

        mShowClock = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_CLOCK, 1) == 1);

        if(mShowClock)
            setVisibility(View.VISIBLE);
        else
            setVisibility(View.GONE);
    }
}
+9 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import android.app.Notification;
import android.app.PendingIntent;
import android.app.StatusBarManager;
import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
@@ -48,6 +49,7 @@ import android.os.IBinder;
import android.os.Message;
import android.os.RemoteException;
import android.os.ServiceManager;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Slog;
import android.view.accessibility.AccessibilityEvent;
@@ -123,6 +125,8 @@ public class TabletStatusBar extends StatusBar implements
    int mIconHPadding = -1;
    private int mMaxNotificationIcons = 5;

    private boolean mShowClock;

    H mHandler = new H();

    IWindowManager mWindowManager;
@@ -934,10 +938,14 @@ public class TabletStatusBar extends StatusBar implements
    }

    public void showClock(boolean show) {
        ContentResolver resolver = mContext.getContentResolver();

        View clock = mBarContents.findViewById(R.id.clock);
        View network_text = mBarContents.findViewById(R.id.network_text);
        mShowClock = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_CLOCK, 1) == 1);
        if (clock != null) {
            clock.setVisibility(show ? View.VISIBLE : View.GONE);
            clock.setVisibility(show ? (mShowClock ? View.VISIBLE : View.GONE) : View.GONE);
        }
        if (network_text != null) {
            network_text.setVisibility((!show) ? View.VISIBLE : View.GONE);