Skip to content

Commit

Permalink
Add Center Clock-Framework Part
Browse files Browse the repository at this point in the history
Patch Set 5: Rebase
Patch Set 6: Rebase and changed copyright message
Patch Set 7: Rebase and added null check

Change-Id: I80cfef86d556a468925ec22f42dd1638f7c90565
(cherry picked from commit ea82da80e3c2d25517730fbdb1a85dad2d048cc9)
  • Loading branch information
jishnurk authored and temasek committed Oct 30, 2012
1 parent d81a494 commit 34fe601
Show file tree
Hide file tree
Showing 7 changed files with 161 additions and 33 deletions.
5 changes: 3 additions & 2 deletions core/java/android/provider/Settings.java
Expand Up @@ -2461,11 +2461,12 @@ public static void setShowGTalkServiceStatus(ContentResolver cr, boolean flag) {
* Whether to show the clock in status bar
* of the stock battery icon
* 0: don't show the clock
* 1: show the clock
* 1: Right clock
* 2: Center clock
* default: 1
* @hide
*/
public static final String STATUS_BAR_CLOCK = "status_bar_clock";
public static final String STATUS_BAR_CLOCK_STYLE = "status_bar_clock_style";

/**
* Whether to show the signal text or signal bars.
Expand Down
16 changes: 16 additions & 0 deletions packages/SystemUI/res/layout/status_bar.xml
Expand Up @@ -136,6 +136,22 @@
/>
</LinearLayout>

<LinearLayout
android:id="@+id/center_clock_layout"
android:gravity="center"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<com.android.systemui.statusbar.policy.CenterClock
android:textAppearance="@style/TextAppearance.StatusBar.Clock"
android:gravity="center"
android:id="@+id/center_clock"
android:paddingLeft="6.0dip"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:singleLine="true" />
</LinearLayout>

<LinearLayout android:id="@+id/ticker"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
11 changes: 10 additions & 1 deletion packages/SystemUI/res/layout/status_bar_expanded_header.xml
Expand Up @@ -34,6 +34,15 @@
android:clickable="true"
/>

<com.android.systemui.statusbar.policy.CenterClock
android:id="@+id/clock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:singleLine="true"
android:textAppearance="@style/TextAppearance.StatusBar.Expanded.Clock"
/>

<com.android.systemui.statusbar.policy.DateView android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
Expand Down Expand Up @@ -76,4 +85,4 @@
android:src="@drawable/ic_notify_clear"
android:contentDescription="@string/accessibility_clear_all"
/>
</LinearLayout>
</LinearLayout>
Expand Up @@ -100,6 +100,8 @@
import com.android.systemui.statusbar.RotationToggle;
import com.android.systemui.statusbar.SignalClusterView;
import com.android.systemui.statusbar.StatusBarIconView;
import com.android.systemui.statusbar.policy.CenterClock;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.statusbar.policy.DateView;
Expand Down Expand Up @@ -213,7 +215,8 @@ public class PhoneStatusBar extends BaseStatusBar {
private TextView mEmergencyCallLabel;

// clock
private boolean mShowClock;
private int mClockStyle;
LinearLayout mCenterClockLayout;

// drag bar
CloseDragHandle mCloseView;
Expand Down Expand Up @@ -498,6 +501,7 @@ public boolean onTouch(View v, MotionEvent event) {
mNotificationIcons = (IconMerger)mStatusBarView.findViewById(R.id.notificationIcons);
mNotificationIcons.setOverflowIndicator(mMoreIcon);
mIcons = (LinearLayout)mStatusBarView.findViewById(R.id.icons);
mCenterClockLayout = (LinearLayout) mStatusBarView.findViewById(R.id.center_clock_layout);
mTickerView = mStatusBarView.findViewById(R.id.ticker);

/* Destroy the old widget before recreating the expanded dialog
Expand Down Expand Up @@ -1206,8 +1210,20 @@ public void showClock(boolean show) {
ContentResolver resolver = mContext.getContentResolver();
mShowClock = (Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK, 1) == 1);
if (mClockView != null) {
mClockView.setVisibility(show ? (mShowClock ? View.VISIBLE : View.GONE) : View.GONE);
mClockStyle = (Settings.System.getInt(resolver,Settings.System.STATUS_BAR_CLOCK_STYLE, 1));
Clock clock = (Clock) mStatusBarView.findViewById(R.id.clock);
CenterClock cclock = (CenterClock) mStatusBarView.findViewById(R.id.center_clock);
if(mClockStyle != 0 && clock !=null && cclock != null){
clock.updateClockVisibility(show);
cclock.updateClockVisibility(show);
}
else{
if (clock != null) {
clock.updateClockVisibility(false);
}
if (cclock != null) {
cclock.updateClockVisibility(false);
}
}
}

Expand Down Expand Up @@ -2155,24 +2171,32 @@ private class MyTicker extends Ticker {
public void tickerStarting() {
mTicking = true;
mIcons.setVisibility(View.GONE);
mCenterClockLayout.setVisibility(View.GONE);
mTickerView.setVisibility(View.VISIBLE);
mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_up_in, null));
mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out, null));
mCenterClockLayout.startAnimation(loadAnim(com.android.internal.R.anim.push_up_out,
null));
}

@Override
public void tickerDone() {
mIcons.setVisibility(View.VISIBLE);
mCenterClockLayout.setVisibility(View.VISIBLE);
mTickerView.setVisibility(View.GONE);
mIcons.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in, null));
mCenterClockLayout.startAnimation(loadAnim(com.android.internal.R.anim.push_down_in,
null));
mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.push_down_out,
mTickingDoneListener));
}

public void tickerHalting() {
mIcons.setVisibility(View.VISIBLE);
mCenterClockLayout.setVisibility(View.VISIBLE);
mTickerView.setVisibility(View.GONE);
mIcons.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null));
mCenterClockLayout.startAnimation(loadAnim(com.android.internal.R.anim.fade_in, null));
mTickerView.startAnimation(loadAnim(com.android.internal.R.anim.fade_out,
mTickingDoneListener));
}
Expand Down
@@ -0,0 +1,62 @@
/*
* Copyright (C) 2012 The CyanogenMod Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.android.systemui.statusbar.policy;

import android.content.ContentResolver;
import android.provider.Settings;
import android.database.ContentObserver;
import android.content.Context;
import android.os.Handler;
import android.util.AttributeSet;
import android.view.View;

public class CenterClock extends Clock {

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

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

public CenterClock(Context context) {
this(context, null);
}

public CenterClock(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}

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

public void updateClockVisibility(boolean show) {
ContentResolver resolver = mContext.getContentResolver();
mClockStyle = (Settings.System.getInt(resolver,Settings.System.STATUS_BAR_CLOCK_STYLE, 1));
if (mClockStyle == CLOCK_STYLE_CENTER)
setVisibility(show ? View.VISIBLE : View.GONE);
else
setVisibility(View.GONE);

}
}
Expand Up @@ -58,23 +58,29 @@
* minutes.
*/
public class Clock extends TextView implements OnClickListener, OnLongClickListener {
private boolean mAttached;
private Calendar mCalendar;
private String mClockFormatString;
private SimpleDateFormat mClockFormat;
private int mDefaultColor;
protected boolean mAttached;
protected Calendar mCalendar;
protected String mClockFormatString;
protected SimpleDateFormat mClockFormat;

private static final int AM_PM_STYLE_NORMAL = 0;
private static final int AM_PM_STYLE_SMALL = 1;
private static final int AM_PM_STYLE_GONE = 2;
public static final int AM_PM_STYLE_NORMAL = 0;
public static final int AM_PM_STYLE_SMALL = 1;
public static final int AM_PM_STYLE_GONE = 2;

private static int AM_PM_STYLE = AM_PM_STYLE_GONE;
public int AM_PM_STYLE = AM_PM_STYLE_GONE;

private int mAmPmStyle;
private boolean mShowClock;
protected int mAmPmStyle;

public static final int CLOCK_STYLE_NOCLOCK = 0;
public static final int CLOCK_STYLE_RIGHT = 1;
public static final int CLOCK_STYLE_CENTER = 2;

protected int mClockStyle;

Handler mHandler;

class SettingsObserver extends ContentObserver {
protected class SettingsObserver extends ContentObserver {
SettingsObserver(Handler handler) {
super(handler);
}
Expand All @@ -84,7 +90,7 @@ void observe() {
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);
Settings.System.STATUS_BAR_CLOCK_STYLE), false, this);
}

@Override public void onChange(boolean selfChange) {
Expand Down Expand Up @@ -146,9 +152,10 @@ protected void onDetachedFromWindow() {
getContext().unregisterReceiver(mIntentReceiver);
mAttached = false;
}

}

private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
protected final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Expand All @@ -163,12 +170,12 @@ public void onReceive(Context context, Intent intent) {
}
};

final void updateClock() {
protected final void updateClock() {
mCalendar.setTimeInMillis(System.currentTimeMillis());
setText(getSmallTime());
}

private final CharSequence getSmallTime() {
protected final CharSequence getSmallTime() {
Context context = getContext();
boolean b24 = DateFormat.is24HourFormat(context);
int res;
Expand Down Expand Up @@ -247,7 +254,7 @@ private final CharSequence getSmallTime() {

}

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

mAmPmStyle = (Settings.System.getInt(resolver,
Expand All @@ -261,12 +268,13 @@ private void updateSettings(){
updateClock();
}
}
mClockStyle = (Settings.System.getInt(resolver,Settings.System.STATUS_BAR_CLOCK_STYLE, 1));
updateClockVisibility(true);
}

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

if(mShowClock)
setVisibility(View.VISIBLE);
public void updateClockVisibility(boolean show) {
if (mClockStyle == CLOCK_STYLE_RIGHT)
setVisibility(show ? View.VISIBLE : View.GONE);
else
setVisibility(View.GONE);
}
Expand Down
Expand Up @@ -78,6 +78,8 @@
import com.android.systemui.statusbar.SignalClusterView;
import com.android.systemui.statusbar.StatusBarIconView;
import com.android.systemui.statusbar.NotificationData.Entry;
import com.android.systemui.statusbar.policy.CenterClock;
import com.android.systemui.statusbar.policy.Clock;
import com.android.systemui.statusbar.policy.BatteryController;
import com.android.systemui.statusbar.policy.DockBatteryController;
import com.android.systemui.statusbar.policy.BluetoothController;
Expand Down Expand Up @@ -193,7 +195,7 @@ public class TabletStatusBar extends BaseStatusBar implements
private CompatModePanel mCompatModePanel;

// clock
private boolean mShowClock;
private int mClockStyle;

private int mSystemUiVisibility = 0;

Expand Down Expand Up @@ -988,12 +990,18 @@ public void removeNotification(IBinder key) {

public void showClock(boolean show) {
ContentResolver resolver = mContext.getContentResolver();
View clock = mBarContents.findViewById(R.id.clock);
Clock clock = (Clock) mBarContents.findViewById(R.id.clock);
CenterClock cclock = (CenterClock) mBarContents.findViewById(R.id.center_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 ? (mShowClock ? View.VISIBLE : View.GONE) : View.GONE);
mClockStyle = Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK_STYLE, 1);
if (mClockStyle != 0 && clock != null && cclock != null) {
clock.updateClockVisibility(show);
cclock.updateClockVisibility(show);
}
else{
clock.updateClockVisibility(false);
cclock.updateClockVisibility(false);
}
if (network_text != null) {
network_text.setVisibility((!show) ? View.VISIBLE : View.GONE);
Expand Down

0 comments on commit 34fe601

Please sign in to comment.