summaryrefslogtreecommitdiffstats
path: root/packages/SystemUI/src/com/android
diff options
context:
space:
mode:
authorRobert Burns <burnsra@gmail.com>2012-02-10 19:54:13 -0500
committerRobert Burns <burnsra@gmail.com>2012-02-10 19:57:00 -0500
commit302de991085826a43467ddfd6f1ddec68e93c4e5 (patch)
tree53363bbff8e9b402e0fe216c9f734d8d2e8f8ddd /packages/SystemUI/src/com/android
parent028000afe8987f9ff6a9813e638a52537d4a78af (diff)
downloadframeworks_base-302de991085826a43467ddfd6f1ddec68e93c4e5.zip
frameworks_base-302de991085826a43467ddfd6f1ddec68e93c4e5.tar.gz
frameworks_base-302de991085826a43467ddfd6f1ddec68e93c4e5.tar.bz2
Interface settings: clock display on tablet
Change-Id: If2cab2a3ee6e971dedda669397d7a79ff9d55ed8
Diffstat (limited to 'packages/SystemUI/src/com/android')
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java120
1 files changed, 118 insertions, 2 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java
index f98caa2..2e143ae 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java
@@ -17,22 +17,25 @@
package com.android.systemui.statusbar.tablet;
import android.content.BroadcastReceiver;
+import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.AssetManager;
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;
import android.text.style.CharacterStyle;
import android.text.style.ForegroundColorSpan;
import android.text.style.RelativeSizeSpan;
-import android.text.style.RelativeSizeSpan;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.view.View;
@@ -52,6 +55,12 @@ public class HoloClock extends FrameLayout {
private String mClockFormatString;
private 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;
+
+ private static int AM_PM_STYLE = AM_PM_STYLE_GONE;
+
private static final String FONT_DIR = "/system/fonts/";
private static final String CLOCK_FONT = FONT_DIR + "AndroidClock_Solid.ttf";
private static final String CLOCK_FG_FONT = FONT_DIR + "AndroidClock.ttf";
@@ -60,6 +69,29 @@ public class HoloClock extends FrameLayout {
private static Typeface sBackgroundType, sForegroundType, sSolidType;
private TextView mSolidText, mBgText, mFgText;
+ 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 HoloClock(Context context) {
this(context, null);
}
@@ -70,6 +102,12 @@ public class HoloClock extends FrameLayout {
public HoloClock(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
+
+ mHandler = new Handler();
+ SettingsObserver settingsObserver = new SettingsObserver(mHandler);
+ settingsObserver.observe();
+
+ updateSettings();
}
@Override
@@ -161,10 +199,43 @@ public class HoloClock extends FrameLayout {
? com.android.internal.R.string.twenty_four_hour_time_format
: com.android.internal.R.string.twelve_hour_time_format;
+ final char MAGIC1 = '\uEF00';
+ final char MAGIC2 = '\uEF01';
+
SimpleDateFormat sdf;
String format = context.getString(res);
if (!format.equals(mClockFormatString)) {
- // we don't want AM/PM showing up in our statusbar, even in 12h mode
+ /*
+ * Search for an unquoted "a" in the format string, so we can
+ * add dummy characters around it to let us find it again after
+ * formatting and change its size.
+ */
+ if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
+ int a = -1;
+ boolean quoted = false;
+ for (int i = 0; i < format.length(); i++) {
+ char c = format.charAt(i);
+
+ if (c == '\'') {
+ quoted = !quoted;
+ }
+ if (!quoted && c == 'a') {
+ a = i;
+ break;
+ }
+ }
+
+ if (a >= 0) {
+ // Move a back so any whitespace before AM/PM is also in the alternate size.
+ final int b = a;
+ while (a > 0 && Character.isWhitespace(format.charAt(a-1))) {
+ a--;
+ }
+ format = format.substring(0, a) + MAGIC1 + format.substring(a, b)
+ + "a" + MAGIC2 + format.substring(b + 1);
+ }
+ }
+
format = format.replaceAll("a", "").trim();
mClockFormat = sdf = new SimpleDateFormat(format);
mClockFormatString = format;
@@ -172,7 +243,52 @@ public class HoloClock extends FrameLayout {
sdf = mClockFormat;
}
String result = sdf.format(mCalendar.getTime());
+
+ if (AM_PM_STYLE != AM_PM_STYLE_NORMAL) {
+ int magic1 = result.indexOf(MAGIC1);
+ int magic2 = result.indexOf(MAGIC2);
+ if (magic1 >= 0 && magic2 > magic1) {
+ SpannableStringBuilder formatted = new SpannableStringBuilder(result);
+ if (AM_PM_STYLE == AM_PM_STYLE_GONE) {
+ formatted.delete(magic1, magic2+1);
+ } else {
+ if (AM_PM_STYLE == AM_PM_STYLE_SMALL) {
+ CharacterStyle style = new RelativeSizeSpan(0.7f);
+ formatted.setSpan(style, magic1, magic2,
+ Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
+ }
+ formatted.delete(magic2, magic2 + 1);
+ formatted.delete(magic1, magic1 + 1);
+ }
+ return formatted;
+ }
+ }
+
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);
+ }
}