Merge "Activate Dreams (screen saver) when desk-docked." into ics-mr1

This commit is contained in:
Daniel Sandler
2011-11-16 22:33:55 -08:00
committed by Android (Google) Code Review
2 changed files with 40 additions and 6 deletions

View File

@@ -46,17 +46,26 @@
</intent-filter> </intent-filter>
</receiver> </receiver>
<!-- handle dock insertion, launch screensaver instead --> <!-- should you need to launch the screensaver, this is a good way to do it -->
<activity android:name=".DreamsDockLauncher" <activity android:name=".DreamsDockLauncher"
android:theme="@android:style/Theme.Dialog" android:theme="@android:style/Theme.Dialog"
android:label="@string/dreams_dock_launcher"> android:label="@string/dreams_dock_launcher">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.DESK_DOCK" />
</intent-filter> </intent-filter>
</activity> </activity>
<!-- launch screensaver on (desk) dock event -->
<receiver android:name=".DreamsDockLauncher$DockEventReceiver"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.DOCK_EVENT" />
</intent-filter>
</receiver>
<activity android:name=".usb.UsbStorageActivity" <activity android:name=".usb.UsbStorageActivity"
android:excludeFromRecents="true"> android:excludeFromRecents="true">
</activity> </activity>

View File

@@ -12,14 +12,22 @@ import android.util.Slog;
public class DreamsDockLauncher extends Activity { public class DreamsDockLauncher extends Activity {
private static final String TAG = "DreamsDockLauncher"; private static final String TAG = "DreamsDockLauncher";
// Launch the screen saver if started as an activity.
@Override @Override
protected void onCreate (Bundle icicle) { protected void onCreate (Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
launchDream(this);
finish();
}
private static void launchDream(Context context) {
try { try {
String component = Settings.Secure.getString( String component = Settings.Secure.getString(
getContentResolver(), Settings.Secure.DREAM_COMPONENT); context.getContentResolver(), Settings.Secure.DREAM_COMPONENT);
if (component == null) { if (component == null) {
component = getResources().getString(com.android.internal.R.string.config_defaultDreamComponent); component = context.getResources().getString(
com.android.internal.R.string.config_defaultDreamComponent);
} }
if (component != null) { if (component != null) {
ComponentName cn = ComponentName.unflattenFromString(component); ComponentName cn = ComponentName.unflattenFromString(component);
@@ -29,7 +37,8 @@ public class DreamsDockLauncher extends Activity {
| Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
| Intent.FLAG_ACTIVITY_NO_USER_ACTION | Intent.FLAG_ACTIVITY_NO_USER_ACTION
); );
startActivity(zzz); Slog.v(TAG, "Starting screen saver on dock event: " + component);
context.startActivity(zzz);
} else { } else {
Slog.e(TAG, "Couldn't start screen saver: none selected"); Slog.e(TAG, "Couldn't start screen saver: none selected");
} }
@@ -37,6 +46,22 @@ public class DreamsDockLauncher extends Activity {
// no screensaver? give up // no screensaver? give up
Slog.e(TAG, "Couldn't start screen saver: none installed"); Slog.e(TAG, "Couldn't start screen saver: none installed");
} }
finish(); }
// Trap low-level dock events and launch the screensaver.
public static class DockEventReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if (Intent.ACTION_DOCK_EVENT.equals(intent.getAction())) {
Bundle extras = intent.getExtras();
int state = extras
.getInt(Intent.EXTRA_DOCK_STATE, Intent.EXTRA_DOCK_STATE_UNDOCKED);
if (state == Intent.EXTRA_DOCK_STATE_DESK
|| state == Intent.EXTRA_DOCK_STATE_LE_DESK
|| state == Intent.EXTRA_DOCK_STATE_HE_DESK) {
launchDream(context);
}
}
}
} }
} }