diff options
-rw-r--r-- | res/drawable/ic_delete_white_24dp.xml | 27 | ||||
-rw-r--r-- | res/menu/menu_preview.xml | 6 | ||||
-rw-r--r-- | res/values/strings.xml | 2 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperChange.java | 31 | ||||
-rw-r--r-- | src/com/android/wallpaper/livepicker/LiveWallpaperPreview.java | 25 |
5 files changed, 87 insertions, 4 deletions
diff --git a/res/drawable/ic_delete_white_24dp.xml b/res/drawable/ic_delete_white_24dp.xml new file mode 100644 index 0000000..ca3b43f --- /dev/null +++ b/res/drawable/ic_delete_white_24dp.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2018 The Android Open Source Project + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +--> +<vector xmlns:android="http://schemas.android.com/apk/res/android" + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0" + android:tint="?attr/colorControlNormal"> + + <path + android:fillColor="@android:color/white" + android:pathData="M15,4L15,3L9,3v1L4,4v2h1v13c0,1.1 0.9,2 2,2h10c1.1,0 2,-0.9 2,-2L19,6h1L20,4h-5zM17,19L7,19L7,6h10v13zM9,8h2v9L9,17zM13,8h2v9h-2z"/> + +</vector>
\ No newline at end of file diff --git a/res/menu/menu_preview.xml b/res/menu/menu_preview.xml index 471e506..87d17c9 100644 --- a/res/menu/menu_preview.xml +++ b/res/menu/menu_preview.xml @@ -28,4 +28,10 @@ android:showAsAction="always|withText" android:actionLayout="@layout/set_wallpaper_action"/> + <item + android:id="@+id/delete_wallpaper" + android:icon="@drawable/ic_delete_white_24dp" + android:showAsAction="ifRoom" + android:title="@string/delete_live_wallpaper"/> + </menu> diff --git a/res/values/strings.xml b/res/values/strings.xml index 99e48e6..0206a43 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -31,6 +31,8 @@ <string name="live_wallpaper_preview_title">Live wallpaper preview</string> <!-- List item for configuring the current wallpaper --> <string name="configure_wallpaper">Settingsā¦</string> + <!-- List item for deleting the current wallpaper --> + <string name="delete_live_wallpaper">Delete</string> <!-- Button label on Wallpaper Gallery screen; user selects this button to set a specific wallpaper --> <string name="wallpaper_instructions">Set wallpaper</string> <!-- Warning message, no live wallpapers available. --> 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; |