Misc changes needed for micropaper integration.
am: 11ab2075fe
Change-Id: Idf2c392e3e5d643d4bc0f03397f3c546f65a3100
diff --git a/res/values/styles.xml b/res/values/styles.xml
index 20e9995..45b6d02 100755
--- a/res/values/styles.xml
+++ b/res/values/styles.xml
@@ -41,6 +41,10 @@
</style>
<style name="WallpaperTheme.Preview" parent="@style/Theme.AppCompat.NoActionBar">
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:windowContentOverlay">@null</item>
+ <item name="android:windowDisablePreview">true</item>
+
<!-- Set no title and no action bar because we use a toolbar instead. -->
<item name="windowActionBar">false</item>
<item name="windowNoTitle">true</item>
diff --git a/src/com/android/wallpaper/module/Injector.java b/src/com/android/wallpaper/module/Injector.java
index 520e79b..746917e 100755
--- a/src/com/android/wallpaper/module/Injector.java
+++ b/src/com/android/wallpaper/module/Injector.java
@@ -73,6 +73,7 @@
WallpaperRotationRefresher getWallpaperRotationRefresher();
Fragment getPreviewFragment(
+ Context context,
WallpaperInfo wallpaperInfo,
@PreviewMode int mode,
boolean testingModeEnabled);
diff --git a/src/com/android/wallpaper/module/WallpaperSetter.java b/src/com/android/wallpaper/module/WallpaperSetter.java
index 2fb00a8..830d914 100644
--- a/src/com/android/wallpaper/module/WallpaperSetter.java
+++ b/src/com/android/wallpaper/module/WallpaperSetter.java
@@ -200,24 +200,26 @@
/**
* Show a dialog asking the user for the Wallpaper's destination
* (eg, "Home screen", "Lock Screen")
+ * @param isLiveWallpaper whether the wallpaper that we want to set is a live wallpaper.
* @param listener {@link SetWallpaperDialogFragment.Listener} that will receive the response.
* @see Destination
*/
public void requestDestination(Context context, FragmentManager fragmentManager,
- WallpaperInfo wallpaper, Listener listener) {
+ Listener listener, boolean isLiveWallpaper) {
requestDestination(context, fragmentManager, R.string.set_wallpaper_dialog_message,
- wallpaper, listener);
+ listener, isLiveWallpaper);
}
/**
* Show a dialog asking the user for the Wallpaper's destination
* (eg, "Home screen", "Lock Screen")
+ * @param isLiveWallpaper whether the wallpaper that we want to set is a live wallpaper.
* @param listener {@link SetWallpaperDialogFragment.Listener} that will receive the response.
* @param titleResId title for the dialog
* @see Destination
*/
public void requestDestination(Context context, FragmentManager fragmentManager,
- @StringRes int titleResId, WallpaperInfo wallpaper, Listener listener) {
+ @StringRes int titleResId, Listener listener, boolean isLiveWallpaper) {
CurrentWallpaperInfoFactory factory = InjectorProvider.getInjector()
.getCurrentWallpaperFactory(context);
@@ -226,16 +228,16 @@
setWallpaperDialog.setTitleResId(titleResId);
setWallpaperDialog.setListener(listener);
if (homeWallpaper instanceof LiveWallpaperInfo && lockWallpaper == null) {
- if (wallpaper instanceof LiveWallpaperInfo) {
+ if (isLiveWallpaper) {
// If lock wallpaper is live and we're setting a live wallpaper, we can only
// set it to both, so bypass the dialog.
- listener.onSetBoth();
+ listener.onSet(WallpaperPersister.DEST_BOTH);
return;
}
// if the lock wallpaper is a live wallpaper, we cannot set a home-only static one
setWallpaperDialog.setHomeOptionAvailable(false);
}
- if (wallpaper instanceof LiveWallpaperInfo) {
+ if (isLiveWallpaper) {
setWallpaperDialog.setLockOptionAvailable(false);
}
setWallpaperDialog.show(fragmentManager, TAG_SET_WALLPAPER_DIALOG_FRAGMENT);
diff --git a/src/com/android/wallpaper/picker/PreviewActivity.java b/src/com/android/wallpaper/picker/PreviewActivity.java
index bbedb7f..457de69 100755
--- a/src/com/android/wallpaper/picker/PreviewActivity.java
+++ b/src/com/android/wallpaper/picker/PreviewActivity.java
@@ -46,6 +46,11 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
@@ -55,7 +60,10 @@
WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO);
boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
fragment = InjectorProvider.getInjector().getPreviewFragment(
- wallpaper, PreviewFragment.MODE_CROP_AND_SET_WALLPAPER, testingModeEnabled);
+ /* context */ this,
+ wallpaper,
+ PreviewFragment.MODE_CROP_AND_SET_WALLPAPER,
+ testingModeEnabled);
fm.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index eba645c..c698c8c 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -70,6 +70,7 @@
import com.android.wallpaper.asset.Asset.BitmapReceiver;
import com.android.wallpaper.asset.Asset.DimensionsReceiver;
import com.android.wallpaper.compat.BuildCompat;
+import com.android.wallpaper.model.LiveWallpaperInfo;
import com.android.wallpaper.model.WallpaperInfo;
import com.android.wallpaper.module.ExploreIntentChecker;
import com.android.wallpaper.module.Injector;
@@ -122,9 +123,9 @@
public @interface PreviewMode {
}
- protected static final String ARG_WALLPAPER = "wallpaper";
- protected static final String ARG_PREVIEW_MODE = "preview_mode";
- protected static final String ARG_TESTING_MODE_ENABLED = "testing_mode_enabled";
+ public static final String ARG_WALLPAPER = "wallpaper";
+ public static final String ARG_PREVIEW_MODE = "preview_mode";
+ public static final String ARG_TESTING_MODE_ENABLED = "testing_mode_enabled";
private static final String TAG_LOAD_WALLPAPER_ERROR_DIALOG_FRAGMENT =
"load_wallpaper_error_dialog";
private static final String TAG_SET_WALLPAPER_ERROR_DIALOG_FRAGMENT =
@@ -148,7 +149,7 @@
protected SubsamplingScaleImageView mFullResImageView;
protected WallpaperInfo mWallpaper;
private Asset mWallpaperAsset;
- private WallpaperSetter mWallpaperSetter;;
+ private WallpaperSetter mWallpaperSetter;
private UserEventLogger mUserEventLogger;
private LinearLayout mBottomSheet;
private TextView mAttributionTitle;
@@ -461,18 +462,8 @@
}
@Override
- public void onSetHomeScreen() {
- setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
- }
-
- @Override
- public void onSetLockScreen() {
- setCurrentWallpaper(WallpaperPersister.DEST_LOCK_SCREEN);
- }
-
- @Override
- public void onSetBoth() {
- setCurrentWallpaper(WallpaperPersister.DEST_BOTH);
+ public void onSet(int destination) {
+ setCurrentWallpaper(destination);
}
@Override
@@ -508,8 +499,8 @@
private void onSetWallpaperClicked(View button) {
if (BuildCompat.isAtLeastN()) {
- mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), mWallpaper,
- this);
+ mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), this,
+ mWallpaper instanceof LiveWallpaperInfo);
} else {
setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
}
diff --git a/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java b/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
index 391c29a..6b2cb3f 100755
--- a/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
+++ b/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
@@ -28,6 +28,7 @@
import com.android.wallpaper.R;
import com.android.wallpaper.compat.ButtonDrawableSetterCompat;
+import com.android.wallpaper.module.WallpaperPersister;
/**
* Dialog fragment which shows the "Set wallpaper" destination dialog for N+ devices. Lets user
@@ -68,7 +69,7 @@
mSetHomeWallpaperButton = layout.findViewById(R.id.set_home_wallpaper_button);
mSetHomeWallpaperButton.setOnClickListener(v -> {
- mListener.onSetHomeScreen();
+ mListener.onSet(WallpaperPersister.DEST_HOME_SCREEN);
dismiss();
});
ButtonDrawableSetterCompat.setDrawableToButtonStart(
@@ -77,7 +78,7 @@
mSetLockWallpaperButton = layout.findViewById(R.id.set_lock_wallpaper_button);
mSetLockWallpaperButton.setOnClickListener(v -> {
- mListener.onSetLockScreen();
+ mListener.onSet(WallpaperPersister.DEST_LOCK_SCREEN);
dismiss();
});
ButtonDrawableSetterCompat.setDrawableToButtonStart(
@@ -86,7 +87,7 @@
mSetBothWallpaperButton = layout.findViewById(R.id.set_both_wallpaper_button);
mSetBothWallpaperButton.setOnClickListener(v -> {
- mListener.onSetBoth();
+ mListener.onSet(WallpaperPersister.DEST_BOTH);
dismiss();
});
ButtonDrawableSetterCompat.setDrawableToButtonStart(
@@ -130,10 +131,6 @@
* on the dialog's clickable elements.
*/
public interface Listener {
- void onSetHomeScreen();
-
- void onSetLockScreen();
-
- void onSetBoth();
+ void onSet(int destination);
}
}
diff --git a/src/com/android/wallpaper/picker/StandalonePreviewActivity.java b/src/com/android/wallpaper/picker/StandalonePreviewActivity.java
index 9eb07fc..5d87df8 100755
--- a/src/com/android/wallpaper/picker/StandalonePreviewActivity.java
+++ b/src/com/android/wallpaper/picker/StandalonePreviewActivity.java
@@ -52,9 +52,6 @@
mUserEventLogger = InjectorProvider.getInjector().getUserEventLogger(getApplicationContext());
mUserEventLogger.logStandalonePreviewLaunched();
- FragmentManager fragmentManager = getSupportFragmentManager();
- Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
-
Intent cropAndSetWallpaperIntent = getIntent();
Uri imageUri = cropAndSetWallpaperIntent.getData();
@@ -77,8 +74,15 @@
requestPermissions(
new String[]{permission.READ_EXTERNAL_STORAGE},
READ_EXTERNAL_STORAGE_PERMISSION_REQUEST_CODE);
- return;
}
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
+
+ FragmentManager fragmentManager = getSupportFragmentManager();
+ Fragment fragment = fragmentManager.findFragmentById(R.id.fragment_container);
if (fragment == null) {
loadPreviewFragment();
@@ -116,7 +120,10 @@
boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
WallpaperInfo wallpaper = new ImageWallpaperInfo(intent.getData());
Fragment fragment = InjectorProvider.getInjector().getPreviewFragment(
- wallpaper, PreviewFragment.MODE_CROP_AND_SET_WALLPAPER, testingModeEnabled);
+ /* context */ this,
+ wallpaper,
+ PreviewFragment.MODE_CROP_AND_SET_WALLPAPER,
+ testingModeEnabled);
getSupportFragmentManager().beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
diff --git a/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java b/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
index 2a22046..f10cc51 100755
--- a/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
+++ b/src/com/android/wallpaper/picker/ViewOnlyPreviewActivity.java
@@ -44,6 +44,11 @@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_preview);
+ }
+
+ @Override
+ public void onAttachedToWindow() {
+ super.onAttachedToWindow();
FragmentManager fm = getSupportFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.fragment_container);
@@ -53,7 +58,10 @@
WallpaperInfo wallpaper = intent.getParcelableExtra(EXTRA_WALLPAPER_INFO);
boolean testingModeEnabled = intent.getBooleanExtra(EXTRA_TESTING_MODE_ENABLED, false);
fragment = InjectorProvider.getInjector().getPreviewFragment(
- wallpaper, PreviewFragment.MODE_VIEW_ONLY, testingModeEnabled);
+ /* context */ this,
+ wallpaper,
+ PreviewFragment.MODE_VIEW_ONLY,
+ testingModeEnabled);
fm.beginTransaction()
.add(R.id.fragment_container, fragment)
.commit();
diff --git a/src_override/com/android/wallpaper/module/WallpapersInjector.java b/src_override/com/android/wallpaper/module/WallpapersInjector.java
index 7a426ce..8e3b3e9 100755
--- a/src_override/com/android/wallpaper/module/WallpapersInjector.java
+++ b/src_override/com/android/wallpaper/module/WallpapersInjector.java
@@ -65,6 +65,7 @@
@Override
public Fragment getPreviewFragment(
+ Context context,
WallpaperInfo wallpaperInfo,
int mode,
boolean testingModeEnabled) {