diff options
author | Daniel Sandler <dsandler@google.com> | 2010-11-18 11:01:13 -0800 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2010-11-18 11:01:13 -0800 |
commit | 0c400f0a68d4b48516fbe0dbae05e500598317f1 (patch) | |
tree | 1981c74283b917e1febbb6c4ae97ef162273fab4 | |
parent | ab2aeeeb13f10df37bf3846771016b6ef4e69c14 (diff) | |
parent | 051dccf6fc7f88cfb4bb462cfc4e8b28b5a4142b (diff) | |
download | frameworks_base-0c400f0a68d4b48516fbe0dbae05e500598317f1.zip frameworks_base-0c400f0a68d4b48516fbe0dbae05e500598317f1.tar.gz frameworks_base-0c400f0a68d4b48516fbe0dbae05e500598317f1.tar.bz2 |
Merge "Hello, HoloClock."
-rw-r--r-- | packages/SystemUI/assets/fonts/AndroidClock.ttf | bin | 0 -> 2336 bytes | |||
-rw-r--r-- | packages/SystemUI/assets/fonts/AndroidClock2.ttf | bin | 0 -> 2212 bytes | |||
-rw-r--r-- | packages/SystemUI/res/layout-xlarge/status_bar.xml | 29 | ||||
-rw-r--r-- | packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml | 24 | ||||
-rw-r--r-- | packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java | 169 |
5 files changed, 205 insertions, 17 deletions
diff --git a/packages/SystemUI/assets/fonts/AndroidClock.ttf b/packages/SystemUI/assets/fonts/AndroidClock.ttf Binary files differnew file mode 100644 index 0000000..3945183 --- /dev/null +++ b/packages/SystemUI/assets/fonts/AndroidClock.ttf diff --git a/packages/SystemUI/assets/fonts/AndroidClock2.ttf b/packages/SystemUI/assets/fonts/AndroidClock2.ttf Binary files differnew file mode 100644 index 0000000..fa0221e --- /dev/null +++ b/packages/SystemUI/assets/fonts/AndroidClock2.ttf diff --git a/packages/SystemUI/res/layout-xlarge/status_bar.xml b/packages/SystemUI/res/layout-xlarge/status_bar.xml index b8b8bdd..d4a6136 100644 --- a/packages/SystemUI/res/layout-xlarge/status_bar.xml +++ b/packages/SystemUI/res/layout-xlarge/status_bar.xml @@ -57,20 +57,25 @@ android:layout_width="wrap_content" android:layout_height="match_parent" > - <!-- paddingLeft: 24 dips = 32dp (total space to icon) - 8dp in the icon. - TODO: Make sure the font has a small enough leading that we don't need this - negative margin business. --> - <com.android.systemui.statusbar.policy.Clock - style="@*android:style/TextAppearance.StatusBar.Icon" + <com.android.systemui.statusbar.tablet.HoloClock android:id="@+id/clock" android:layout_width="wrap_content" - android:layout_height="65dp" - android:layout_marginTop="-17dp" - android:singleLine="true" - android:textSize="60sp" - android:paddingLeft="24dip" - android:textColor="#2e2e2e" - /> + android:layout_height="match_parent" + > + <TextView android:id="@+id/time_bg" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:singleLine="true" + android:textSize="72dip" + android:textColor="#1f1f1f" /> + <TextView android:id="@+id/time_fg" + android:layout_width="wrap_content" + android:layout_height="match_parent" + android:singleLine="true" + android:textSize="72dip" + android:textColor="#2e2e2e" /> + </com.android.systemui.statusbar.tablet.HoloClock> + <LinearLayout android:layout_width="48dip" android:layout_height="match_parent" diff --git a/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml b/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml index 186aa64..b23cc7b 100644 --- a/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml +++ b/packages/SystemUI/res/layout-xlarge/sysbar_panel_notifications.xml @@ -40,15 +40,29 @@ android:layout_alignParentRight="true" > - <com.android.systemui.statusbar.policy.Clock + <com.android.systemui.statusbar.tablet.HoloClock android:id="@+id/clock" android:layout_height="wrap_content" android:layout_width="match_parent" android:layout_alignParentTop="true" - android:layout_marginRight="48dp" - android:textSize="70sp" - android:gravity="right" - /> + android:layout_marginRight="40dip" + android:layout_marginBottom="4dip" + > + <TextView android:id="@+id/time_bg" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="right" + android:singleLine="true" + android:textSize="90dip" + android:textColor="#999999" /> + <TextView android:id="@+id/time_fg" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:gravity="right" + android:singleLine="true" + android:textSize="90dip" + android:textColor="#666666" /> + </com.android.systemui.statusbar.tablet.HoloClock> <com.android.systemui.statusbar.policy.DateView android:id="@+id/date" diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java new file mode 100644 index 0000000..3b76434 --- /dev/null +++ b/packages/SystemUI/src/com/android/systemui/statusbar/tablet/HoloClock.java @@ -0,0 +1,169 @@ +/* + * Copyright (C) 2006 The Android Open Source 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.tablet; + +import android.content.BroadcastReceiver; +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.graphics.Canvas; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +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; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.TextView; + +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.TimeZone; + +import com.android.systemui.R; + +public class HoloClock extends FrameLayout { + private boolean mAttached; + private Calendar mCalendar; + private String mClockFormatString; + private SimpleDateFormat mClockFormat; + + private static Typeface sBackgroundType, sForegroundType; + private TextView mBgText, mFgText; + + public HoloClock(Context context) { + this(context, null); + } + + public HoloClock(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + public HoloClock(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + + if (sBackgroundType == null) { + AssetManager assets = getContext().getAssets(); + + sBackgroundType = Typeface.createFromAsset(assets, + "fonts/AndroidClock.ttf"); + sForegroundType = Typeface.createFromAsset(assets, + "fonts/AndroidClock2.ttf"); + } + mBgText = (TextView) findViewById(R.id.time_bg); + if (mBgText != null) { + mBgText.setTypeface(sBackgroundType); + } + mFgText = (TextView) findViewById(R.id.time_fg); + if (mFgText != null) { + mFgText.setTypeface(sForegroundType); + } + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + + if (!mAttached) { + mAttached = true; + IntentFilter filter = new IntentFilter(); + + filter.addAction(Intent.ACTION_TIME_TICK); + filter.addAction(Intent.ACTION_TIME_CHANGED); + filter.addAction(Intent.ACTION_TIMEZONE_CHANGED); + filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED); + + getContext().registerReceiver(mIntentReceiver, filter, null, getHandler()); + } + + // NOTE: It's safe to do these after registering the receiver since the receiver always runs + // in the main thread, therefore the receiver can't run before this method returns. + + // The time zone may have changed while the receiver wasn't registered, so update the Time + mCalendar = Calendar.getInstance(TimeZone.getDefault()); + + // Make sure we update to the current time + updateClock(); + } + + @Override + protected void onDetachedFromWindow() { + super.onDetachedFromWindow(); + if (mAttached) { + getContext().unregisterReceiver(mIntentReceiver); + mAttached = false; + } + } + + private final BroadcastReceiver mIntentReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (action.equals(Intent.ACTION_TIMEZONE_CHANGED)) { + String tz = intent.getStringExtra("time-zone"); + mCalendar = Calendar.getInstance(TimeZone.getTimeZone(tz)); + if (mClockFormat != null) { + mClockFormat.setTimeZone(mCalendar.getTimeZone()); + } + } + updateClock(); + } + }; + + final void updateClock() { + mCalendar.setTimeInMillis(System.currentTimeMillis()); + CharSequence txt = getTimeText(); + mBgText.setText(txt); + mFgText.setText(txt); + } + + private final CharSequence getTimeText() { + Context context = getContext(); + int res = DateFormat.is24HourFormat(context) + ? com.android.internal.R.string.twenty_four_hour_time_format + : com.android.internal.R.string.twelve_hour_time_format; + + 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 + format = format.replaceAll("a", "").trim(); + mClockFormat = sdf = new SimpleDateFormat(format); + mClockFormatString = format; + } else { + sdf = mClockFormat; + } + String result = sdf.format(mCalendar.getTime()); + return result; + } +} + |