summaryrefslogtreecommitdiffstats
path: root/WallpaperPicker/src/com
diff options
context:
space:
mode:
Diffstat (limited to 'WallpaperPicker/src/com')
-rw-r--r--WallpaperPicker/src/com/android/launcher3/AlphaDisableableButton.java50
-rw-r--r--WallpaperPicker/src/com/android/launcher3/LiveWallpaperListAdapter.java2
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperCropActivity.java6
-rw-r--r--WallpaperPicker/src/com/android/launcher3/WallpaperPickerActivity.java106
-rw-r--r--WallpaperPicker/src/com/android/photos/views/TiledImageView.java12
5 files changed, 162 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 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 @@ 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 23fbe73..561c4bb 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 93967ad..08caf3b 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();
}
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 @@ 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;