summaryrefslogtreecommitdiffstats
path: root/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java')
-rw-r--r--src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java71
1 files changed, 40 insertions, 31 deletions
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
index 72ba27a..2f32e36 100644
--- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
+++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java
@@ -16,6 +16,7 @@
package com.android.wallpaper.livepicker;
+import android.app.ActionBar;
import android.app.Activity;
import android.app.WallpaperManager;
import android.app.WallpaperInfo;
@@ -33,6 +34,9 @@ import android.os.RemoteException;
import android.os.IBinder;
import android.os.ParcelFileDescriptor;
import android.os.Bundle;
+import android.service.wallpaper.WallpaperService;
+import android.view.Menu;
+import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
@@ -43,9 +47,7 @@ import android.util.Log;
import android.widget.TextView;
public class LiveWallpaperPreview extends Activity {
- static final String EXTRA_LIVE_WALLPAPER_INTENT = "android.live_wallpaper.intent";
- static final String EXTRA_LIVE_WALLPAPER_SETTINGS = "android.live_wallpaper.settings";
- static final String EXTRA_LIVE_WALLPAPER_PACKAGE = "android.live_wallpaper.package";
+ static final String EXTRA_LIVE_WALLPAPER_INFO = "android.live_wallpaper.info";
private static final String LOG_TAG = "LiveWallpaperPreview";
@@ -55,46 +57,49 @@ public class LiveWallpaperPreview extends Activity {
private String mSettings;
private String mPackageName;
private Intent mWallpaperIntent;
+
private View mView;
private Dialog mDialog;
- static void showPreview(Activity activity, int code, Intent intent, WallpaperInfo info) {
- if (info == null) {
- Log.w(LOG_TAG, "Failure showing preview", new Throwable());
- return;
- }
- Intent preview = new Intent(activity, LiveWallpaperPreview.class);
- preview.putExtra(EXTRA_LIVE_WALLPAPER_INTENT, intent);
- preview.putExtra(EXTRA_LIVE_WALLPAPER_SETTINGS, info.getSettingsActivity());
- preview.putExtra(EXTRA_LIVE_WALLPAPER_PACKAGE, info.getPackageName());
- activity.startActivityForResult(preview, code);
- }
-
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ init();
+ }
+ protected void init() {
Bundle extras = getIntent().getExtras();
- mWallpaperIntent = (Intent) extras.get(EXTRA_LIVE_WALLPAPER_INTENT);
- if (mWallpaperIntent == null) {
+ WallpaperInfo info = extras.getParcelable(EXTRA_LIVE_WALLPAPER_INFO);
+ if (info == null) {
setResult(RESULT_CANCELED);
finish();
}
- setContentView(R.layout.live_wallpaper_preview);
- mView = findViewById(R.id.configure);
+ initUI(info);
+ }
- mSettings = extras.getString(EXTRA_LIVE_WALLPAPER_SETTINGS);
- mPackageName = extras.getString(EXTRA_LIVE_WALLPAPER_PACKAGE);
- if (mSettings == null) {
- mView.setVisibility(View.GONE);
- }
+ protected void initUI(WallpaperInfo info) {
+ mSettings = info.getSettingsActivity();
+ mPackageName = info.getPackageName();
+ mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE)
+ .setClassName(info.getPackageName(), info.getServiceName());
- mWallpaperManager = WallpaperManager.getInstance(this);
+ final ActionBar actionBar = getActionBar();
+ actionBar.setCustomView(R.layout.live_wallpaper_preview);
+ mView = actionBar.getCustomView();
+ mWallpaperManager = WallpaperManager.getInstance(this);
mWallpaperConnection = new WallpaperConnection(mWallpaperIntent);
}
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ if (mSettings != null) {
+ getMenuInflater().inflate(R.menu.menu_preview, menu);
+ }
+ return super.onCreateOptionsMenu(menu);
+ }
+
public void setLiveWallpaper(View v) {
try {
mWallpaperManager.getIWallpaperManager().setWallpaperComponent(
@@ -110,12 +115,16 @@ public class LiveWallpaperPreview extends Activity {
finish();
}
- @SuppressWarnings({"UnusedDeclaration"})
- public void configureLiveWallpaper(View v) {
- Intent intent = new Intent();
- intent.setComponent(new ComponentName(mPackageName, mSettings));
- intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
- startActivity(intent);
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ if (item.getItemId() == R.id.configure) {
+ Intent intent = new Intent();
+ intent.setComponent(new ComponentName(mPackageName, mSettings));
+ intent.putExtra(WallpaperSettingsActivity.EXTRA_PREVIEW_MODE, true);
+ startActivity(intent);
+ return true;
+ }
+ return super.onOptionsItemSelected(item);
}
@Override