summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAmin Shaikh <ashaikh@google.com>2019-05-03 15:09:55 -0400
committerAmin Shaikh <ashaikh@google.com>2019-05-03 15:09:55 -0400
commit729db179a8efa81d1e85515e7f9cb4c499e87a7c (patch)
treeab8f2ef8e8dddfee388e5a022e94b4737f8f40cf /src
parent883d80f1180e289b5c2692b8b9d723e22ba54c67 (diff)
parent0b5a0a19f9aa933c82051b77b7f2281318a2e322 (diff)
downloadandroid_packages_apps_WallpaperPicker2-729db179a8efa81d1e85515e7f9cb4c499e87a7c.tar.gz
android_packages_apps_WallpaperPicker2-729db179a8efa81d1e85515e7f9cb4c499e87a7c.tar.bz2
android_packages_apps_WallpaperPicker2-729db179a8efa81d1e85515e7f9cb4c499e87a7c.zip
Merging ub-launcher3-qt-dev, build 5530094
Test: Manual Bug:117099627 Bug:117559479 Bug:125903559 Bug:130734277 Change-Id: Ibb92fd5cde01d3aab0e36cd3eedde0c95e279284
Diffstat (limited to 'src')
-rw-r--r--src/com/android/wallpaper/module/WallpaperSetter.java57
-rwxr-xr-xsrc/com/android/wallpaper/picker/PreviewFragment.java5
-rwxr-xr-xsrc/com/android/wallpaper/picker/SetWallpaperDialogFragment.java9
-rwxr-xr-xsrc/com/android/wallpaper/util/ScreenSizeCalculator.java4
4 files changed, 68 insertions, 7 deletions
diff --git a/src/com/android/wallpaper/module/WallpaperSetter.java b/src/com/android/wallpaper/module/WallpaperSetter.java
index bb71aa6..2fb00a8 100644
--- a/src/com/android/wallpaper/module/WallpaperSetter.java
+++ b/src/com/android/wallpaper/module/WallpaperSetter.java
@@ -2,6 +2,7 @@ package com.android.wallpaper.module;
import android.app.Activity;
import android.app.ProgressDialog;
+import android.app.WallpaperManager;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.graphics.Rect;
@@ -25,6 +26,8 @@ import com.android.wallpaper.util.ThrowableAnalyzer;
import com.bumptech.glide.Glide;
+import java.io.IOException;
+
/**
* Helper class used to set the current wallpaper. It handles showing the destination request dialog
* and actually setting the wallpaper on a given destination.
@@ -71,6 +74,11 @@ public class WallpaperSetter {
public void setCurrentWallpaper(Activity containerActivity, WallpaperInfo wallpaper,
Asset wallpaperAsset, @Destination final int destination, float wallpaperScale,
@Nullable Rect cropRect, @Nullable SetWallpaperCallback callback) {
+ if (wallpaper instanceof LiveWallpaperInfo) {
+ setCurrentLiveWallpaper(containerActivity, (LiveWallpaperInfo) wallpaper, destination,
+ callback);
+ return;
+ }
mPreferences.setPendingWallpaperSetStatus(
WallpaperPreferences.WALLPAPER_SET_PENDING);
@@ -117,6 +125,40 @@ public class WallpaperSetter {
});
}
+ public void setCurrentLiveWallpaper(Activity activity, LiveWallpaperInfo wallpaper,
+ @Destination final int destination, @Nullable SetWallpaperCallback callback) {
+ try {
+ // Save current screen rotation so we can temporarily disable rotation while setting the
+ // wallpaper and restore after setting the wallpaper finishes.
+ saveAndLockScreenOrientation(activity);
+
+ if (destination == WallpaperPersister.DEST_LOCK_SCREEN) {
+ throw new IllegalArgumentException(
+ "Live wallpaper cannot be applied on lock screen only");
+ }
+ WallpaperManager wallpaperManager = WallpaperManager.getInstance(activity);
+ wallpaperManager.setWallpaperComponent(
+ wallpaper.getWallpaperComponent().getComponent());
+ wallpaperManager.setWallpaperOffsetSteps(0.5f /* xStep */, 0.0f /* yStep */);
+ wallpaperManager.setWallpaperOffsets(
+ activity.getWindow().getDecorView().getRootView().getWindowToken(),
+ 0.5f /* xOffset */, 0.0f /* yOffset */);
+ if (destination == WallpaperPersister.DEST_BOTH) {
+ wallpaperManager.clear(WallpaperManager.FLAG_LOCK);
+ }
+ onWallpaperApplied(wallpaper, activity);
+ if (callback != null) {
+ callback.onSuccess();
+ }
+ } catch (RuntimeException | IOException e) {
+ onWallpaperApplyError(e, activity);
+ if (callback != null) {
+ callback.onError(e);
+ }
+ }
+
+ }
+
private void onWallpaperApplied(WallpaperInfo wallpaper, Activity containerActivity) {
mUserEventLogger.logWallpaperSet(
wallpaper.getCollectionId(containerActivity),
@@ -162,9 +204,9 @@ public class WallpaperSetter {
* @see Destination
*/
public void requestDestination(Context context, FragmentManager fragmentManager,
- Listener listener) {
+ WallpaperInfo wallpaper, Listener listener) {
requestDestination(context, fragmentManager, R.string.set_wallpaper_dialog_message,
- listener);
+ wallpaper, listener);
}
/**
@@ -175,7 +217,7 @@ public class WallpaperSetter {
* @see Destination
*/
public void requestDestination(Context context, FragmentManager fragmentManager,
- @StringRes int titleResId, Listener listener) {
+ @StringRes int titleResId, WallpaperInfo wallpaper, Listener listener) {
CurrentWallpaperInfoFactory factory = InjectorProvider.getInjector()
.getCurrentWallpaperFactory(context);
@@ -184,9 +226,18 @@ public class WallpaperSetter {
setWallpaperDialog.setTitleResId(titleResId);
setWallpaperDialog.setListener(listener);
if (homeWallpaper instanceof LiveWallpaperInfo && lockWallpaper == null) {
+ if (wallpaper instanceof LiveWallpaperInfo) {
+ // 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();
+ return;
+ }
// if the lock wallpaper is a live wallpaper, we cannot set a home-only static one
setWallpaperDialog.setHomeOptionAvailable(false);
}
+ if (wallpaper instanceof LiveWallpaperInfo) {
+ setWallpaperDialog.setLockOptionAvailable(false);
+ }
setWallpaperDialog.show(fragmentManager, TAG_SET_WALLPAPER_DIALOG_FRAGMENT);
}, true); // Force refresh as the wallpaper may have been set while this fragment was paused
}
diff --git a/src/com/android/wallpaper/picker/PreviewFragment.java b/src/com/android/wallpaper/picker/PreviewFragment.java
index 82fd195..0ba9412 100755
--- a/src/com/android/wallpaper/picker/PreviewFragment.java
+++ b/src/com/android/wallpaper/picker/PreviewFragment.java
@@ -408,7 +408,8 @@ public class PreviewFragment extends Fragment implements
int id = item.getItemId();
if (id == R.id.set_wallpaper) {
if (BuildCompat.isAtLeastN()) {
- mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), this);
+ mWallpaperSetter.requestDestination(getContext(), getFragmentManager(), mWallpaper,
+ this);
} else {
setCurrentWallpaper(WallpaperPersister.DEST_HOME_SCREEN);
}
@@ -756,7 +757,7 @@ public class PreviewFragment extends Fragment implements
centerPosition.offset( - (screenToCropSurfacePosition.x + cropSurfaceToWallpaperPosition.x),
- (screenToCropSurfacePosition.y + cropSurfaceToWallpaperPosition.y));
- mFullResImageView.setScaleAndCenter(defaultWallpaperZoom, centerPosition);
+ mFullResImageView.setScaleAndCenter(minWallpaperZoom, centerPosition);
}
protected Rect calculateCropRect() {
diff --git a/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java b/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
index cf69d9a..cc9e348 100755
--- a/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
+++ b/src/com/android/wallpaper/picker/SetWallpaperDialogFragment.java
@@ -40,6 +40,7 @@ public class SetWallpaperDialogFragment extends DialogFragment {
private Button mSetBothWallpaperButton;
private boolean mHomeAvailable = true;
+ private boolean mLockAvailable = true;
private Listener mListener;
private int mTitleResId;
@@ -98,6 +99,11 @@ public class SetWallpaperDialogFragment extends DialogFragment {
updateButtonsVisibility();
}
+ public void setLockOptionAvailable(boolean lockAvailable) {
+ mLockAvailable = lockAvailable;
+ updateButtonsVisibility();
+ }
+
public void setTitleResId(@StringRes int titleResId) {
mTitleResId = titleResId;
}
@@ -110,6 +116,9 @@ public class SetWallpaperDialogFragment extends DialogFragment {
if (mSetHomeWallpaperButton != null) {
mSetHomeWallpaperButton.setVisibility(mHomeAvailable ? View.VISIBLE : View.GONE);
}
+ if (mSetLockWallpaperButton != null) {
+ mSetLockWallpaperButton.setVisibility(mLockAvailable ? View.VISIBLE : View.GONE);
+ }
}
/**
diff --git a/src/com/android/wallpaper/util/ScreenSizeCalculator.java b/src/com/android/wallpaper/util/ScreenSizeCalculator.java
index 49148c3..d55cf99 100755
--- a/src/com/android/wallpaper/util/ScreenSizeCalculator.java
+++ b/src/com/android/wallpaper/util/ScreenSizeCalculator.java
@@ -73,16 +73,16 @@ public class ScreenSizeCalculator {
private Point getPortraitScreenSize(Display display) {
if (mPortraitScreenSize == null) {
mPortraitScreenSize = new Point();
- writeDisplaySizeToPoint(display, mPortraitScreenSize);
}
+ writeDisplaySizeToPoint(display, mPortraitScreenSize);
return mPortraitScreenSize;
}
private Point getLandscapeScreenSize(Display display) {
if (mLandscapeScreenSize == null) {
mLandscapeScreenSize = new Point();
- writeDisplaySizeToPoint(display, mLandscapeScreenSize);
}
+ writeDisplaySizeToPoint(display, mLandscapeScreenSize);
return mLandscapeScreenSize;
}