This commit is contained in:
Joe Onorato
2010-05-14 11:54:53 -07:00
parent 66d7d01ed9
commit 263700df7b
4 changed files with 204 additions and 126 deletions

View File

@@ -183,9 +183,6 @@ public class StatusBarManagerService extends IStatusBarService.Stub
}
}
public void setIcon(String slot, CharSequence text) {
}
public void setIcon(String slot, String iconPackage, int iconId, int iconLevel) {
enforceStatusBar();

View File

@@ -72,10 +72,6 @@ import com.android.internal.telephony.cdma.EriInfo;
import com.android.internal.telephony.cdma.TtyIntent;
import com.android.server.am.BatteryStatsService;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.TimeZone;
/**
* This class contains all of the policy about which icons are installed in the status
* bar at boot time. In reality, it should go into the android.policy package, but
@@ -100,11 +96,6 @@ public class StatusBarPolicy {
private final Handler mHandler = new StatusBarHandler();
private final IBatteryStats mBatteryStats;
// clock
private Calendar mCalendar;
private String mClockFormatString;
private SimpleDateFormat mClockFormat;
// storage
private StorageManager mStorageManager;
@@ -321,26 +312,9 @@ public class StatusBarPolicy {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action.equals(Intent.ACTION_TIME_TICK)) {
updateClock();
}
else if (action.equals(Intent.ACTION_TIME_CHANGED)) {
updateClock();
}
else if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
if (action.equals(Intent.ACTION_BATTERY_CHANGED)) {
updateBattery(intent);
}
else if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)) {
updateClock();
}
else 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();
}
else if (action.equals(Intent.ACTION_ALARM_CHANGED)) {
updateAlarm(intent);
}
@@ -388,11 +362,6 @@ public class StatusBarPolicy {
mSignalStrength = new SignalStrength();
mBatteryStats = BatteryStatsService.getService();
// clock
mCalendar = Calendar.getInstance(TimeZone.getDefault());
service.setIcon("clock", "");
updateClock();
// storage
mStorageManager = (StorageManager) context.getSystemService(Context.STORAGE_SERVICE);
mStorageManager.registerListener(
@@ -472,14 +441,10 @@ public class StatusBarPolicy {
IntentFilter filter = new IntentFilter();
// Register for Intent broadcasts for...
filter.addAction(Intent.ACTION_TIME_TICK);
filter.addAction(Intent.ACTION_TIME_CHANGED);
filter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
filter.addAction(Intent.ACTION_BATTERY_CHANGED);
filter.addAction(Intent.ACTION_BATTERY_LOW);
filter.addAction(Intent.ACTION_BATTERY_OKAY);
filter.addAction(Intent.ACTION_POWER_CONNECTED);
filter.addAction(Intent.ACTION_TIMEZONE_CHANGED);
filter.addAction(Intent.ACTION_ALARM_CHANGED);
filter.addAction(Intent.ACTION_SYNC_STATE_CHANGED);
filter.addAction(AudioManager.RINGER_MODE_CHANGED_ACTION);
@@ -511,93 +476,6 @@ public class StatusBarPolicy {
sInstance = new StatusBarPolicy(context, service);
}
private final CharSequence getSmallTime() {
boolean b24 = DateFormat.is24HourFormat(mContext);
int res;
if (b24) {
res = R.string.twenty_four_hour_time_format;
} else {
res = R.string.twelve_hour_time_format;
}
final char MAGIC1 = '\uEF00';
final char MAGIC2 = '\uEF01';
SimpleDateFormat sdf;
String format = mContext.getString(res);
if (!format.equals(mClockFormatString)) {
/*
* 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 the 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);
}
}
mClockFormat = sdf = new SimpleDateFormat(format);
mClockFormatString = format;
} else {
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 final void updateClock() {
mCalendar.setTimeInMillis(System.currentTimeMillis());
mService.setIcon("clock", getSmallTime());
}
private final void updateAlarm(Intent intent) {
boolean alarmSet = intent.getBooleanExtra("alarmSet", false);
mService.setIconVisibility("alarm_clock", alarmSet);