diff options
author | Selim Cinek <cinek@google.com> | 2014-03-04 09:48:31 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2014-03-04 09:48:32 +0000 |
commit | 0c255a946788499d7f169429890d5a423426593b (patch) | |
tree | 979a8fafd7e6cd474a458ef14ee93a703f231956 /WallpaperPicker/src/com | |
parent | 7da05a506cdc651a77df918ec20d6aa881ca51b2 (diff) | |
parent | ffed65886ecd83f52dc1c052897511c95a5f371a (diff) | |
download | android_packages_apps_Trebuchet-0c255a946788499d7f169429890d5a423426593b.tar.gz android_packages_apps_Trebuchet-0c255a946788499d7f169429890d5a423426593b.tar.bz2 android_packages_apps_Trebuchet-0c255a946788499d7f169429890d5a423426593b.zip |
Merge "Changed behaviour of the wallpaper picker." into ub-now-lunchbox
Diffstat (limited to 'WallpaperPicker/src/com')
5 files changed, 160 insertions, 14 deletions
diff --git a/WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java b/WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java new file mode 100644 index 000000000..f0796c36f --- /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 60b253711..88f4461bf 100644 --- a/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java +++ b/WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java @@ -122,7 +122,7 @@ public class LiveWallpaperListAdapter extends BaseAdapter implements ListAdapter 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 23fbe73a3..561c4bb6a 100644 --- a/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java +++ b/WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java @@ -75,7 +75,7 @@ public class WallpaperCropActivity extends Activity { protected CropView mCropView; protected Uri mUri; - private View mSetWallpaperButton; + protected View mSetWallpaperButton; @Override protected void onCreate(Bundle savedInstanceState) { @@ -117,7 +117,7 @@ public class WallpaperCropActivity extends Activity { // 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 @@ public class WallpaperCropActivity extends Activity { 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 ab25fa939..013606a50 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; @@ -86,9 +87,9 @@ 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 View mSelectedTile; - private View mSetWallpaperButton; private boolean mIgnoreNextTap; private OnClickListener mThumbnailOnClickListener; @@ -103,7 +104,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; @@ -145,13 +147,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) { @@ -218,6 +220,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) { @@ -256,6 +259,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) { @@ -281,11 +285,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; @@ -339,7 +402,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); @@ -445,6 +508,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) { mThumbnailOnClickListener.onClick( mWallpapersView.getChildAt(mSelectedIndex)); + setSystemWallpaperVisiblity(false); } v.removeOnLayoutChangeListener(this); } @@ -474,6 +538,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(); } } }); @@ -524,6 +592,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); @@ -531,11 +600,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; @@ -552,7 +629,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; } }; @@ -624,7 +703,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, @@ -782,11 +861,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(); @@ -946,7 +1029,8 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { 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 af4199c91..94063b027 100644 --- a/WallpaperPicker/src/com/android/photos/views/TiledImageView.java +++ b/WallpaperPicker/src/com/android/photos/views/TiledImageView.java @@ -112,6 +112,18 @@ public class TiledImageView extends FrameLayout { //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; |