通过keyguardstatusview.java中可以看到,代码所采用的日期格式固定
观察者定义如下:
private static class FormatChangeObserver extends ContentObserver {
private WeakReference<ClockView> mClock;
private Context mContext;
public FormatChangeObserver(ClockView clock) {
super(new Handler());
mClock = new WeakReference<ClockView>(clock);
mContext = clock.getContext();
}
@Override
public void onChange(boolean selfChange) {
ClockView digitalClock = mClock.get();
if (digitalClock != null) {
digitalClock.setDateFormat();
digitalClock.updateTime();
} else {
try {
mContext.getContentResolver().unregisterContentObserver(this);
} catch (RuntimeException e) {
// Shouldn‘t happen
}
}
}
}
时间: 2024-11-03 22:04:57