diff options
author | Kunhung Li <kunhungli@google.com> | 2019-01-07 15:12:27 +0800 |
---|---|---|
committer | Kunhung Li <kunhungli@google.com> | 2019-01-15 17:19:55 +0800 |
commit | 9f295e7a7ef9ca17d42abf500a6d24fe37aa3990 (patch) | |
tree | cd0896f3b57c4d854ad98767e570dbdb78b5b383 /src | |
parent | ea70a99ad5618f34b5b7721f0809e4662a87131b (diff) | |
download | android_packages_wallpapers_LivePicker-9f295e7a7ef9ca17d42abf500a6d24fe37aa3990.tar.gz android_packages_wallpapers_LivePicker-9f295e7a7ef9ca17d42abf500a6d24fe37aa3990.tar.bz2 android_packages_wallpapers_LivePicker-9f295e7a7ef9ca17d42abf500a6d24fe37aa3990.zip |
Delete feature for LivePicker
Provide a delete function in menu item that can notify delete info to
wallpaper package then finish back to the requesting activity.
Bug: 122094510
Test: Manual
Change-Id: I9e7303ee9cbbae0a7987b4b8848a1aa3293c72b3
Diffstat (limited to 'src')
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperChange.java | 31 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 25 |
2 files changed, 52 insertions, 4 deletions
diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperChange.java b/src/com/android/wallpaper/livepicker/LiveWallpaperChange.java index efaf563..724e791 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperChange.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperChange.java @@ -20,12 +20,18 @@ import android.app.WallpaperInfo; import android.app.WallpaperManager; import android.content.ComponentName; import android.content.Intent; +import android.content.pm.ApplicationInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.content.pm.ServiceInfo; +import android.os.Bundle; import android.os.Parcelable; import android.service.wallpaper.WallpaperService; import android.util.Log; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + import org.xmlpull.v1.XmlPullParserException; import java.io.IOException; @@ -33,6 +39,7 @@ import java.util.List; public class LiveWallpaperChange extends LiveWallpaperPreview { private static final String TAG = "CHANGE_LIVE_WALLPAPER"; + private static final String KEY_ACTION_DELETE_LIVE_WALLPAPER = "action_delete_live_wallpaper"; @Override protected void init() { @@ -65,8 +72,7 @@ public class LiveWallpaperChange extends LiveWallpaperPreview { finish(); return; } - - initUI(info); + initUI(info, getDeleteAction(ri.serviceInfo)); return; } } @@ -75,4 +81,25 @@ public class LiveWallpaperChange extends LiveWallpaperPreview { Log.w(TAG, "Not a live wallpaper: " + comp); finish(); } + + @Nullable + private String getDeleteAction(@NonNull ServiceInfo serviceInfo) { + if (!isPackagePreInstalled(serviceInfo.applicationInfo)) { + Log.d(TAG, "This wallpaper is not pre-installed."); + return null; + } + + final Bundle metaData = serviceInfo.metaData; + if (metaData != null) { + return metaData.getString(KEY_ACTION_DELETE_LIVE_WALLPAPER); + } + return null; + } + + private boolean isPackagePreInstalled(ApplicationInfo info) { + if (info != null && (info.flags & ApplicationInfo.FLAG_SYSTEM) != 0) { + return true; + } + return false; + } } diff --git a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java index 6494434..6056859 100644 --- a/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java +++ b/src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java @@ -60,6 +60,8 @@ import android.widget.ImageButton; import android.widget.TextView; import android.widget.Toolbar; +import androidx.annotation.Nullable; + import java.io.IOException; public class LiveWallpaperPreview extends Activity { @@ -75,6 +77,7 @@ public class LiveWallpaperPreview extends Activity { private String mPackageName; private Intent mWallpaperIntent; private Intent mSettingsIntent; + private Intent mDeleteIntent; private TextView mAttributionTitle; private TextView mAttributionSubtitle1; @@ -98,10 +101,10 @@ public class LiveWallpaperPreview extends Activity { setResult(RESULT_CANCELED); finish(); } - initUI(info); + initUI(info, null /* deleteAction */); } - protected void initUI(WallpaperInfo info) { + protected void initUI(WallpaperInfo info, @Nullable String deleteAction) { getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION); @@ -146,6 +149,12 @@ public class LiveWallpaperPreview extends Activity { mWallpaperConnection = new WallpaperConnection(mWallpaperIntent); populateAttributionPane(info); + + if (!TextUtils.isEmpty(deleteAction)) { + mDeleteIntent = new Intent(deleteAction); + mDeleteIntent.setPackage(info.getPackageName()); + mDeleteIntent.putExtra(EXTRA_LIVE_WALLPAPER_INFO, info); + } } private void populateAttributionPane(WallpaperInfo info) { @@ -269,6 +278,7 @@ public class LiveWallpaperPreview extends Activity { menu.findItem(R.id.configure).setVisible(mSettingsIntent != null); menu.findItem(R.id.set_wallpaper).getActionView().setOnClickListener( this::setLiveWallpaper); + menu.findItem(R.id.delete_wallpaper).setVisible(mDeleteIntent != null); return super.onCreateOptionsMenu(menu); } @@ -317,6 +327,13 @@ public class LiveWallpaperPreview extends Activity { mWallpaperManager.setWallpaperOffsets(windowToken, 0.5f, 0.0f); } + private void deleteLiveWallpaper() { + if (mDeleteIntent != null) { + startService(mDeleteIntent); + finish(); + } + } + @Override public boolean onOptionsItemSelected(MenuItem item) { int id = item.getItemId(); @@ -326,6 +343,10 @@ public class LiveWallpaperPreview extends Activity { } else if (id == R.id.set_wallpaper) { setLiveWallpaper(getWindow().getDecorView()); return true; + } else if (id == R.id.delete_wallpaper) { + // TODO(b/122505782): Need delete confirm dialog. + deleteLiveWallpaper(); + return true; } else if (id == android.R.id.home) { onBackPressed(); return true; |