Changed behaviour of the wallpaper picker.
When opening the picker, the currently chosen wallpaper is
shown in the background.
In this change also the nullpointer was fixed when deleting
the currently selected wallpaper and setting it, because we
revert to the old wallpaper in that case.
When going into the same live wallpaper than the currently
selected we are going back to home if the user sets it or
goes back now, in order for the user not to loose state.
The real fix for this will be done later when the following
bug will be fixed: b/13241760
Bug: 12063773
Bug: 13219612
Change-Id: I7c6abb25755eca99c3255278e0884d1ff4749b55
diff --git a/AndroidManifest.xml b/AndroidManifest.xml
index be3a28b..d4cd6a2 100644
--- a/AndroidManifest.xml
+++ b/AndroidManifest.xml
@@ -106,7 +106,7 @@
<activity
android:name="com.android.launcher3.LauncherWallpaperPickerActivity"
- android:theme="@style/Theme.WallpaperCropper"
+ android:theme="@style/Theme.WallpaperPicker"
android:label="@string/pick_wallpaper"
android:icon="@mipmap/ic_launcher_wallpaper"
android:finishOnCloseSystemDialogs="true"
diff --git a/WallpaperPicker/res/layout/actionbar_set_wallpaper.xml b/WallpaperPicker/res/layout/actionbar_set_wallpaper.xml
index 2a0188a..8e349b7 100644
--- a/WallpaperPicker/res/layout/actionbar_set_wallpaper.xml
+++ b/WallpaperPicker/res/layout/actionbar_set_wallpaper.xml
@@ -18,18 +18,15 @@
*/
-->
-<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
- style="?android:actionButtonStyle"
+<com.android.launcher3.AlphaDisableableButton
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ style="@style/ActionBarSetWallpaperStyle"
android:id="@+id/set_wallpaper_button"
android:layout_width="match_parent"
- android:layout_height="match_parent" >
- <TextView style="?android:actionBarTabTextStyle"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_gravity="start|center_vertical"
- android:paddingRight="20dp"
- android:drawableLeft="@drawable/ic_actionbar_accept"
- android:drawablePadding="8dp"
- android:gravity="center_vertical"
- android:text="@string/wallpaper_instructions" />
-</FrameLayout>
+ android:layout_height="match_parent"
+ android:paddingRight="20dp"
+ android:drawableLeft="@drawable/ic_actionbar_accept"
+ android:drawablePadding="8dp"
+ android:gravity="start|center_vertical"
+ android:text="@string/wallpaper_instructions">
+</com.android.launcher3.AlphaDisableableButton>
diff --git a/WallpaperPicker/res/values/styles.xml b/WallpaperPicker/res/values/styles.xml
index 6d600bc..16b11f2 100644
--- a/WallpaperPicker/res/values/styles.xml
+++ b/WallpaperPicker/res/values/styles.xml
@@ -24,6 +24,12 @@
<item name="android:windowActionBarOverlay">true</item>
</style>
+ <style name="Theme.WallpaperPicker" parent="Theme.WallpaperCropper">
+ <item name="android:windowBackground">@android:color/transparent</item>
+ <item name="android:colorBackgroundCacheHint">@null</item>
+ <item name="android:windowShowWallpaper">true</item>
+ </style>
+
<style name="WallpaperCropperActionBar" parent="android:style/Widget.Holo.ActionBar">
<item name="android:displayOptions">showCustom</item>
<item name="android:background">#88000000</item>
@@ -31,4 +37,8 @@
<style name="Theme" parent="@android:style/Theme.Holo.Wallpaper.NoTitleBar">
</style>
+
+ <style name="ActionBarSetWallpaperStyle" parent="@android:style/Widget.Holo.ActionButton">
+ <item name="android:textColor">#ffffffff</item>
+ </style>
</resources>
diff --git a/WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java b/WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java
new file mode 100644
index 0000000..f0796c3
--- /dev/null
+++ b/WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2014 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
+ */
+
+package com.android.launcher3;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.Button;
+
+/**
+ * A Button which becomes translucent when it is disabled
+ */
+public class AlphaDisableableButton extends Button {
+ public static float DISABLED_ALPHA_VALUE = 0.4f;
+ public AlphaDisableableButton(Context context) {
+ this(context, null);
+ }
+
+ public AlphaDisableableButton(Context context, AttributeSet attrs) {
+ this(context, attrs, 0);
+ }
+
+ public AlphaDisableableButton(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ setLayerType(LAYER_TYPE_HARDWARE, null);
+ }
+
+ @Override
+ public void setEnabled(boolean enabled) {
+ super.setEnabled(enabled);
+ if(enabled) {
+ setAlpha(1.0f);
+ } else {
+ setAlpha(DISABLED_ALPHA_VALUE);
+ }
+ }
+}
diff --git a/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java b/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
index 60b2537..88f4461 100644
--- a/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
+++ b/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java
@@ -122,7 +122,7 @@
Intent preview = new Intent(WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
preview.putExtra(WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
mInfo.getComponent());
- a.onLiveWallpaperPickerLaunch();
+ a.onLiveWallpaperPickerLaunch(mInfo);
a.startActivityForResultSafely(preview, WallpaperPickerActivity.PICK_LIVE_WALLPAPER);
}
}
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
index 23fbe73..561c4bb 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java
@@ -75,7 +75,7 @@
protected CropView mCropView;
protected Uri mUri;
- private View mSetWallpaperButton;
+ protected View mSetWallpaperButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -117,7 +117,7 @@
// Load image in background
final BitmapRegionTileSource.UriBitmapSource bitmapSource =
new BitmapRegionTileSource.UriBitmapSource(this, imageUri, 1024);
- mSetWallpaperButton.setVisibility(View.INVISIBLE);
+ mSetWallpaperButton.setEnabled(false);
Runnable onLoad = new Runnable() {
public void run() {
if (bitmapSource.getLoadingState() != BitmapSource.State.LOADED) {
@@ -126,7 +126,7 @@
Toast.LENGTH_LONG).show();
finish();
} else {
- mSetWallpaperButton.setVisibility(View.VISIBLE);
+ mSetWallpaperButton.setEnabled(true);
}
}
};
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
index 80c649a..a83e75e 100644
--- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
+++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java
@@ -16,7 +16,6 @@
package com.android.launcher3;
-import android.animation.Animator;
import android.animation.LayoutTransition;
import android.app.ActionBar;
import android.app.Activity;
@@ -33,7 +32,6 @@
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Matrix;
-import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.Rect;
@@ -60,6 +58,7 @@
import android.view.ViewPropertyAnimator;
import android.view.ViewTreeObserver;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
+import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.widget.BaseAdapter;
@@ -88,9 +87,9 @@
private static final String SELECTED_INDEX = "SELECTED_INDEX";
private static final String OLD_DEFAULT_WALLPAPER_THUMBNAIL_FILENAME = "default_thumb.jpg";
private static final String DEFAULT_WALLPAPER_THUMBNAIL_FILENAME = "default_thumb2.jpg";
+ private static final int FLAG_POST_DELAY_MILLIS = 200;
private View mSelectedTile;
- private View mSetWallpaperButton;
private boolean mIgnoreNextTap;
private OnClickListener mThumbnailOnClickListener;
@@ -105,7 +104,8 @@
ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>();
private SavedWallpaperImages mSavedImages;
private WallpaperInfo mLiveWallpaperInfoOnPickerLaunch;
- private int mSelectedIndex;
+ private int mSelectedIndex = -1;
+ private WallpaperInfo mLastClickedLiveWallpaperInfo;
public static abstract class WallpaperTileInfo {
protected View mView;
@@ -147,13 +147,13 @@
onLoad = null;
} else {
mFirstClick = false;
- a.mSetWallpaperButton.setVisibility(View.INVISIBLE);
+ a.mSetWallpaperButton.setEnabled(false);
onLoad = new Runnable() {
public void run() {
if (mBitmapSource != null &&
mBitmapSource.getLoadingState() == BitmapSource.State.LOADED) {
a.selectTile(mView);
- a.mSetWallpaperButton.setVisibility(View.VISIBLE);
+ a.mSetWallpaperButton.setEnabled(true);
} else {
ViewGroup parent = (ViewGroup) mView.getParent();
if (parent != null) {
@@ -220,6 +220,7 @@
wallpaperSize.x, wallpaperSize.y, false);
v.setScale(wallpaperSize.x / crop.width());
v.setTouchEnabled(false);
+ a.setSystemWallpaperVisiblity(false);
}
@Override
public void onSave(WallpaperPickerActivity a) {
@@ -252,6 +253,7 @@
new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null);
c.setScale(1f);
c.setTouchEnabled(false);
+ a.setSystemWallpaperVisiblity(false);
}
@Override
public void onSave(WallpaperPickerActivity a) {
@@ -276,11 +278,70 @@
mWallpaperStrip.setPadding(0, 0, 0, (int) offset);
}
+ /**
+ * shows the system wallpaper behind the window and hides the {@link
+ * #mCropView} if visible
+ * @param visible should the system wallpaper be shown
+ */
+ protected void setSystemWallpaperVisiblity(final boolean visible) {
+ // hide our own wallpaper preview if necessary
+ if(!visible) {
+ mCropView.setVisibility(View.VISIBLE);
+ } else {
+ changeWallpaperFlags(visible);
+ }
+ // the change of the flag must be delayed in order to avoid flickering,
+ // a simple post / double post does not suffice here
+ mCropView.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ if(!visible) {
+ changeWallpaperFlags(visible);
+ } else {
+ mCropView.setVisibility(View.INVISIBLE);
+ }
+ }
+ }, FLAG_POST_DELAY_MILLIS);
+ }
+
+ private void changeWallpaperFlags(boolean visible) {
+ int desiredWallpaperFlag = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0;
+ int currentWallpaperFlag = getWindow().getAttributes().flags
+ & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER;
+ if (desiredWallpaperFlag != currentWallpaperFlag) {
+ getWindow().setFlags(desiredWallpaperFlag,
+ WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
+ }
+ }
+
+ @Override
+ public void setCropViewTileSource(BitmapSource bitmapSource,
+ boolean touchEnabled,
+ boolean moveToLeft,
+ final Runnable postExecute) {
+ // we also want to show our own wallpaper instead of the one in the background
+ Runnable showPostExecuteRunnable = new Runnable() {
+ @Override
+ public void run() {
+ if(postExecute != null) {
+ postExecute.run();
+ }
+ setSystemWallpaperVisiblity(false);
+ }
+ };
+ super.setCropViewTileSource(bitmapSource,
+ touchEnabled,
+ moveToLeft,
+ showPostExecuteRunnable);
+ }
+
// called by onCreate; this is subclassed to overwrite WallpaperCropActivity
protected void init() {
setContentView(R.layout.wallpaper_picker);
mCropView = (CropView) findViewById(R.id.cropView);
+ mCropView.setVisibility(View.INVISIBLE);
+
mWallpaperStrip = findViewById(R.id.wallpaper_strip);
mCropView.setTouchCallback(new CropView.TouchCallback() {
ViewPropertyAnimator mAnim;
@@ -334,7 +395,7 @@
}
return;
}
- mSetWallpaperButton.setVisibility(View.VISIBLE);
+ mSetWallpaperButton.setEnabled(true);
WallpaperTileInfo info = (WallpaperTileInfo) v.getTag();
if (info.isSelectable() && v.getVisibility() == View.VISIBLE) {
selectTile(v);
@@ -438,6 +499,7 @@
if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) {
mThumbnailOnClickListener.onClick(
mWallpapersView.getChildAt(mSelectedIndex));
+ setSystemWallpaperVisiblity(false);
}
v.removeOnLayoutChangeListener(this);
}
@@ -467,6 +529,10 @@
if (mSelectedTile != null) {
WallpaperTileInfo info = (WallpaperTileInfo) mSelectedTile.getTag();
info.onSave(WallpaperPickerActivity.this);
+ } else {
+ // no tile was selected, so we just finish the activity and go back
+ setResult(Activity.RESULT_OK);
+ finish();
}
}
});
@@ -517,6 +583,7 @@
if (itemId == R.id.menu_delete) {
int childCount = mWallpapersView.getChildCount();
ArrayList<View> viewsToRemove = new ArrayList<View>();
+ boolean selectedTileRemoved = false;
for (int i = 0; i < childCount; i++) {
CheckableFrameLayout c =
(CheckableFrameLayout) mWallpapersView.getChildAt(i);
@@ -524,11 +591,19 @@
WallpaperTileInfo info = (WallpaperTileInfo) c.getTag();
info.onDelete(WallpaperPickerActivity.this);
viewsToRemove.add(c);
+ if (i == mSelectedIndex) {
+ selectedTileRemoved = true;
+ }
}
}
for (View v : viewsToRemove) {
mWallpapersView.removeView(v);
}
+ if (selectedTileRemoved) {
+ mSelectedIndex = -1;
+ mSelectedTile = null;
+ setSystemWallpaperVisiblity(true);
+ }
updateTileIndices();
mode.finish(); // Action picked, so close the CAB
return true;
@@ -545,7 +620,9 @@
CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i);
c.setChecked(false);
}
- mSelectedTile.setSelected(true);
+ if (mSelectedTile != null) {
+ mSelectedTile.setSelected(true);
+ }
mActionMode = null;
}
};
@@ -617,7 +694,7 @@
for (Uri uri : uris) {
addTemporaryWallpaperTile(uri, true);
}
- mSelectedIndex = savedInstanceState.getInt(SELECTED_INDEX, 0);
+ mSelectedIndex = savedInstanceState.getInt(SELECTED_INDEX, -1);
}
private void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter,
@@ -775,11 +852,15 @@
} else if (requestCode == PICK_LIVE_WALLPAPER) {
WallpaperManager wm = WallpaperManager.getInstance(this);
final WallpaperInfo oldLiveWallpaper = mLiveWallpaperInfoOnPickerLaunch;
+ final WallpaperInfo clickedWallpaper = mLastClickedLiveWallpaperInfo;
WallpaperInfo newLiveWallpaper = wm.getWallpaperInfo();
// Try to figure out if a live wallpaper was set;
if (newLiveWallpaper != null &&
- (oldLiveWallpaper == null ||
- !oldLiveWallpaper.getComponent().equals(newLiveWallpaper.getComponent()))) {
+ (oldLiveWallpaper == null
+ || !oldLiveWallpaper.getComponent()
+ .equals(newLiveWallpaper.getComponent())
+ || clickedWallpaper.getComponent()
+ .equals(oldLiveWallpaper.getComponent()))) {
// Return if a live wallpaper was set
setResult(RESULT_OK);
finish();
@@ -939,7 +1020,8 @@
return mSavedImages;
}
- public void onLiveWallpaperPickerLaunch() {
+ public void onLiveWallpaperPickerLaunch(WallpaperInfo info) {
+ mLastClickedLiveWallpaperInfo = info;
mLiveWallpaperInfoOnPickerLaunch = WallpaperManager.getInstance(this).getWallpaperInfo();
}
diff --git a/WallpaperPicker/src/com/android/photos/views/TiledImageView.java b/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
index af4199c..94063b0 100644
--- a/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
+++ b/WallpaperPicker/src/com/android/photos/views/TiledImageView.java
@@ -112,6 +112,18 @@
//setTileSource(new ColoredTiles());
}
+ @Override
+ public void setVisibility(int visibility) {
+ super.setVisibility(visibility);
+ // need to update inner view's visibility because it seems like we're causing it to draw
+ // from {@link #dispatchDraw} or {@link #invalidate} even if we are invisible.
+ if (USE_TEXTURE_VIEW) {
+ mTextureView.setVisibility(visibility);
+ } else {
+ mGLSurfaceView.setVisibility(visibility);
+ }
+ }
+
public void destroy() {
if (!IS_SUPPORTED) {
return;