diff options
author | Selim Cinek <cinek@google.com> | 2014-02-28 17:18:59 +0100 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2014-06-06 22:54:29 -0700 |
commit | 5a8139c9079a4d9a85a14e86fc95dfddc16d5638 (patch) | |
tree | e9ca20982a8ca8f419e0c5f0f5261b7530c7f62c /WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java | |
parent | 1a835b1bcf20a6cbbf50deeb19fd205b4268efa7 (diff) | |
download | android_packages_apps_Trebuchet-5a8139c9079a4d9a85a14e86fc95dfddc16d5638.tar.gz android_packages_apps_Trebuchet-5a8139c9079a4d9a85a14e86fc95dfddc16d5638.tar.bz2 android_packages_apps_Trebuchet-5a8139c9079a4d9a85a14e86fc95dfddc16d5638.zip |
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
Diffstat (limited to 'WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java')
-rw-r--r-- | WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java | 106 |
1 files changed, 96 insertions, 10 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java index 93967ad5d..08caf3b42 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java @@ -58,6 +58,7 @@ import android.view.ViewGroup; 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; @@ -87,12 +88,14 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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 static final int MENU_WALLPAPER_SCROLL = 0; private View mSelectedTile; - private View mSetWallpaperButton; + protected View mSetWallpaperButton; + private boolean mIgnoreNextTap; private OnClickListener mThumbnailOnClickListener; @@ -107,7 +110,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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; @@ -149,13 +153,13 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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) { @@ -222,6 +226,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { wallpaperSize.x, wallpaperSize.y, false); v.setScale(wallpaperSize.x / crop.width()); v.setTouchEnabled(false); + a.setSystemWallpaperVisiblity(false); } @Override public void onSave(WallpaperPickerActivity a) { @@ -260,6 +265,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { new DrawableTileSource(a, defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE), null); c.setScale(1f); c.setTouchEnabled(false); + a.setSystemWallpaperVisiblity(false); } @Override public void onSave(WallpaperPickerActivity a) { @@ -285,11 +291,70 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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; @@ -343,7 +408,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } return; } - mSetWallpaperButton.setVisibility(View.VISIBLE); + mSetWallpaperButton.setEnabled(true); WallpaperTileInfo info = (WallpaperTileInfo) v.getTag(); if (info.isSelectable() && v.getVisibility() == View.VISIBLE) { selectTile(v); @@ -449,6 +514,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) { mThumbnailOnClickListener.onClick( mWallpapersView.getChildAt(mSelectedIndex)); + setSystemWallpaperVisiblity(false); } v.removeOnLayoutChangeListener(this); } @@ -478,6 +544,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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(); } } }); @@ -528,6 +598,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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); @@ -535,11 +606,19 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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; @@ -556,7 +635,9 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); c.setChecked(false); } - mSelectedTile.setSelected(true); + if (mSelectedTile != null) { + mSelectedTile.setSelected(true); + } mActionMode = null; } }; @@ -664,7 +745,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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, @@ -822,11 +903,15 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } 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(); @@ -986,7 +1071,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { return mSavedImages; } - public void onLiveWallpaperPickerLaunch() { + public void onLiveWallpaperPickerLaunch(WallpaperInfo info) { + mLastClickedLiveWallpaperInfo = info; mLiveWallpaperInfoOnPickerLaunch = WallpaperManager.getInstance(this).getWallpaperInfo(); } |