Fields Summary |
---|
private static final String | TAG |
private static final boolean | DEBUG |
private static final int | UPDATE_TIME_TIMEOUT |
private static final int | DISPLAY_STATE_WHEN_DOZING |
private android.os.PowerManager | mPowerManager |
private PowerManager.WakeLock | mWakeLock |
private android.app.AlarmManager | mAlarmManager |
private android.app.PendingIntent | mAlarmIntent |
private android.os.Handler | mHandler |
private android.widget.TextView | mAlarmClock |
private final Date | mTime |
private DateFormat | mTimeFormat |
private boolean | mDreaming |
private long | mLastTime |
private final android.content.BroadcastReceiver | mAlarmReceiver |
Methods Summary |
---|
private void | cancelTimeUpdate()
mAlarmManager.cancel(mAlarmIntent);
|
public void | onAttachedToWindow()
super.onAttachedToWindow();
setInteractive(false);
setLowProfile(true);
setFullscreen(true);
setContentView(R.layout.dream);
setScreenBright(false);
mAlarmClock = (TextView)findViewById(R.id.alarm_clock);
mTimeFormat = DateFormat.getTimeFormat(this);
|
public void | onCreate()
super.onCreate();
mPowerManager = (PowerManager)getSystemService(Context.POWER_SERVICE);
mWakeLock = mPowerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
mAlarmManager = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent("com.android.dreams.dozetest.ACTION_ALARM");
intent.setPackage(getPackageName());
IntentFilter filter = new IntentFilter();
filter.addAction(intent.getAction());
registerReceiver(mAlarmReceiver, filter);
mAlarmIntent = PendingIntent.getBroadcast(this, 0, intent,
PendingIntent.FLAG_CANCEL_CURRENT);
setDozeScreenState(DISPLAY_STATE_WHEN_DOZING);
|
public void | onDestroy()
super.onDestroy();
unregisterReceiver(mAlarmReceiver);
mAlarmIntent.cancel();
|
public void | onDreamingStarted()
super.onDreamingStarted();
mDreaming = true;
Log.d(TAG, "Dream started: canDoze=" + canDoze());
performTimeUpdate();
startDozing();
|
public void | onDreamingStopped()
super.onDreamingStopped();
mDreaming = false;
Log.d(TAG, "Dream ended: isDozing=" + isDozing());
stopDozing();
cancelTimeUpdate();
|
private void | performTimeUpdate()
if (mDreaming) {
long now = System.currentTimeMillis();
now -= now % 60000; // back up to last minute boundary
if (mLastTime == now) {
return;
}
mLastTime = now;
mTime.setTime(now);
mAlarmClock.setText(mTimeFormat.format(mTime));
mAlarmManager.setExact(AlarmManager.RTC_WAKEUP, now + 60000, mAlarmIntent);
mWakeLock.acquire(UPDATE_TIME_TIMEOUT + 5000 /*for testing brightness*/);
// flash the screen a bit to test these functions
setDozeScreenState(DISPLAY_STATE_WHEN_DOZING);
setDozeScreenBrightness(200);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
setDozeScreenBrightness(50);
}
}, 2000);
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
setDozeScreenState(Display.STATE_OFF);
}
}, 5000);
}
|