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

Unverified Commit b8ecc1ad authored by Danesh M's avatar Danesh M Committed by Michael Bestas
Browse files

SystemUI : Clock position support + am/pm styles



Based on Dave Kessler's work from cm-12.0

Change-Id: I88e630fcfcffd8a795f1abbeecd71a258d0e8e81

SystemUI: recalculate clock position on removing empty shade views

Change-Id: I70cc2dd3e1da99d4467cd43fc81018ccf135cd77
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
(cherry picked from commit 4f965c58)

SystemUI: fix clock jumping when expanding QS from lockscreen

commit 4f965c58 fixed recalculating clock position from shade_locked but
it didn't account for other scenarios such as when the QS is expanding,
causing the clock to jump when expanding QS from lockscreen.

Change-Id: I0e4f473fbc500f7dcdfa015cbedda07761c3cdb2
Signed-off-by: default avatarRoman Birg <roman@cyngn.com>
(cherry picked from commit 6831615a)

SystemUI : Fix left/center clock visibility

Change-Id: I5bee0927ceaf93ea4cc0751bcb866aaaed64356b

SystemUI : Make clock/navigation multi-user compatible

Change-Id: Ie6a1552aeb31e138221143d548f7cd4cbb5bde7e
parent c352695e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -29,7 +29,7 @@ LOCAL_STATIC_JAVA_LIBRARIES := \
    android-support-v17-leanback \
    framework-protos \
    SystemUI-proto-tags \
    org.cyanogenmod.platform.sdk
    org.cyanogenmod.platform.internal

LOCAL_JAVA_LIBRARIES := telephony-common telephony-ext

+10 −1
Original line number Diff line number Diff line
@@ -19,6 +19,15 @@
    android:id="@+id/notification_icon_area_inner"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <com.android.systemui.statusbar.policy.Clock
        android:id="@+id/left_clock"
        android:textAppearance="@style/TextAppearance.StatusBar.Clock"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:singleLine="true"
        android:paddingEnd="6dip"
        android:gravity="center"
        android:visibility="gone"/>
    <com.android.systemui.statusbar.StatusBarIconView
        android:id="@+id/moreIcon"
        android:layout_width="@dimen/status_bar_icon_size"
+19 −0
Original line number Diff line number Diff line
@@ -92,4 +92,23 @@
        android:layout="@layout/emergency_cryptkeeper_text"
    />

    <com.android.keyguard.AlphaOptimizedLinearLayout
        android:id="@+id/center_clock_layout"
        android:gravity="center"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        >

        <com.android.systemui.statusbar.policy.Clock
            android:id="@+id/center_clock"
            android:textAppearance="@style/TextAppearance.StatusBar.Clock"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:singleLine="true"
            android:gravity="center"
            android:visibility="gone"
            />
    </com.android.keyguard.AlphaOptimizedLinearLayout>

</com.android.systemui.statusbar.phone.PhoneStatusBarView>
+140 −0
Original line number Diff line number Diff line
package com.android.systemui.statusbar.phone;

import android.content.Context;
import android.graphics.Color;
import android.graphics.Rect;
import android.os.Handler;
import android.util.Log;
import android.view.View;

import com.android.systemui.FontSizeUtils;
import com.android.systemui.R;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.tuner.TunerService;

import static com.android.systemui.statusbar.policy.Clock.AM_PM_STYLE_GONE;
import static com.android.systemui.statusbar.policy.Clock.CLOCK_SECONDS;

/**
 * To control your...clock
 */
public class ClockController implements TunerService.Tunable {

    private static final String TAG = "ClockController";

    public static final int STYLE_CLOCK_RIGHT = 1;
    public static final int STYLE_CLOCK_CENTER = 2;
    public static final int STYLE_CLOCK_LEFT = 3;

    public static final String CLOCK_POSITION = "cmsystem:status_bar_clock";
    public static final String CLOCK_STYLE = "cmsystem:status_bar_am_pm";

    private final NotificationIconAreaController mNotificationIconAreaController;
    private final Context mContext;
    private Clock mRightClock, mCenterClock, mLeftClock, mActiveClock;

    private int mAmPmStyle = AM_PM_STYLE_GONE;
    private int mClockPosition = STYLE_CLOCK_RIGHT;
    private boolean mClockVisible = true;
    private boolean mShowSeconds = false;

    private int mIconTint = Color.WHITE;

    public ClockController(View statusBar,
            NotificationIconAreaController notificationIconAreaController, Handler handler) {
        mRightClock = (Clock) statusBar.findViewById(R.id.clock);
        mCenterClock = (Clock) statusBar.findViewById(R.id.center_clock);
        mLeftClock = (Clock) statusBar.findViewById(R.id.left_clock);
        mNotificationIconAreaController = notificationIconAreaController;
        mContext = statusBar.getContext();

        mActiveClock = mRightClock;

        TunerService.get(mContext).addTunable(this, CLOCK_POSITION, CLOCK_STYLE, CLOCK_SECONDS);
    }

    private Clock getClockForCurrentLocation() {
        Clock clockForAlignment;
        switch (mClockPosition) {
            case STYLE_CLOCK_CENTER:
                clockForAlignment = mCenterClock;
                break;
            case STYLE_CLOCK_LEFT:
                clockForAlignment = mLeftClock;
                break;
            case STYLE_CLOCK_RIGHT:
            default:
                clockForAlignment = mRightClock;
                break;
        }
        return clockForAlignment;
    }

    private void updateActiveClock() {
        mActiveClock.setVisibility(View.GONE);
        if (!mClockVisible) {
            return;
        }

        mActiveClock = getClockForCurrentLocation();
        mActiveClock.setVisibility(View.VISIBLE);
        mActiveClock.setAmPmStyle(mAmPmStyle);
        mActiveClock.setShowSeconds(mShowSeconds);

        setClockAndDateStatus();
        setTextColor(mIconTint);
        updateFontSize();
    }

    @Override
    public void onTuningChanged(String key, String newValue) {
        Log.d(TAG, "onTuningChanged key=" + key + " value=" + newValue);

        if (CLOCK_POSITION.equals(key)) {
            mClockPosition = newValue == null ? STYLE_CLOCK_RIGHT : Integer.valueOf(newValue);
        } else if (CLOCK_STYLE.equals(key)) {
            mAmPmStyle = newValue == null ? AM_PM_STYLE_GONE : Integer.valueOf(newValue);
        } else if (CLOCK_SECONDS.equals(mShowSeconds)) {
            mShowSeconds = newValue == null ? false : Boolean.valueOf(newValue);
        }
        updateActiveClock();
    }

    private void setClockAndDateStatus() {
        if (mNotificationIconAreaController != null) {
            mNotificationIconAreaController.setClockAndDateStatus(mClockPosition);
        }
    }

    public void setVisibility(boolean visible) {
        if (mActiveClock != null) {
            mActiveClock.setVisibility(visible ? View.VISIBLE : View.GONE);
        }
        mClockVisible = visible;
    }

    public void setTextColor(int iconTint) {
        mIconTint = iconTint;
        if (mActiveClock != null) {
            mActiveClock.setTextColor(iconTint);
        }
    }

    public void setTextColor(Rect tintArea, int iconTint) {
        if (mActiveClock != null) {
            setTextColor(StatusBarIconController.getTint(tintArea, mActiveClock, iconTint));
        }
    }

    public void updateFontSize() {
        if (mActiveClock != null) {
            FontSizeUtils.updateFontSize(mActiveClock, R.dimen.status_bar_clock_size);
        }
    }

    public void setPaddingRelative(int start, int top, int end, int bottom) {
        if (mActiveClock != null) {
            mActiveClock.setPaddingRelative(start, top, end, bottom);
        }
    }
}
+19 −1
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import android.view.View;
import android.widget.LinearLayout;

import com.android.systemui.R;
import com.android.systemui.statusbar.policy.Clock;

public class IconMerger extends LinearLayout {
    private static final String TAG = "IconMerger";
@@ -32,6 +33,7 @@ public class IconMerger extends LinearLayout {
    private int mIconSize;
    private int mIconHPadding;

    private int mClockLocation;
    private View mMoreView;

    public IconMerger(Context context, AttributeSet attrs) {
@@ -67,6 +69,10 @@ public class IconMerger extends LinearLayout {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        // we need to constrain this to an integral multiple of our children
        int width = getMeasuredWidth();
        if (mClockLocation == ClockController.STYLE_CLOCK_CENTER) {
            int totalWidth = getResources().getDisplayMetrics().widthPixels;
            width = totalWidth / 2 - getFullIconWidth() * 2;
        }
        setMeasuredDimension(width - (width % getFullIconWidth()), getMeasuredHeight());
    }

@@ -86,7 +92,14 @@ public class IconMerger extends LinearLayout {
        }
        final boolean overflowShown = (mMoreView.getVisibility() == View.VISIBLE);
        // let's assume we have one more slot if the more icon is already showing
        if (overflowShown) visibleChildren --;
        if (overflowShown) {
            int totalWidth = getResources().getDisplayMetrics().widthPixels;
            if ((mClockLocation != ClockController.STYLE_CLOCK_CENTER &&
                    mClockLocation != ClockController.STYLE_CLOCK_LEFT) ||
                    (visibleChildren > (totalWidth / getFullIconWidth() / 2 + 1))) {
                visibleChildren--;
            }
        }
        final boolean moreRequired = visibleChildren * getFullIconWidth() > width;
        if (moreRequired != overflowShown) {
            post(new Runnable() {
@@ -97,4 +110,9 @@ public class IconMerger extends LinearLayout {
            });
        }
    }

    public void setClockAndDateStatus(int mode) {
        mClockLocation = mode;

    }
}
Loading