diff options
author | Michael Jurka <mikejurka@google.com> | 2013-09-12 22:15:02 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2013-09-12 22:15:03 +0000 |
commit | 80521d95f96f6eb630c269f899ecc28b809fb5ba (patch) | |
tree | 9d27d0a45761d52036346a52936e42ead85a3a67 /src/com | |
parent | e763ad1d1427977cfac494fc62cc637a69b91755 (diff) | |
parent | d6dc6043ad29c84511b7cd1c60a4bb72279fb50a (diff) | |
download | android_packages_apps_Trebuchet-80521d95f96f6eb630c269f899ecc28b809fb5ba.tar.gz android_packages_apps_Trebuchet-80521d95f96f6eb630c269f899ecc28b809fb5ba.tar.bz2 android_packages_apps_Trebuchet-80521d95f96f6eb630c269f899ecc28b809fb5ba.zip |
Merge "Adding ability to delete previously saved wallpapers" into jb-ub-now-indigo-rose
Diffstat (limited to 'src/com')
-rw-r--r-- | src/com/android/launcher3/CheckableFrameLayout.java | 63 | ||||
-rw-r--r-- | src/com/android/launcher3/WallpaperPickerActivity.java | 126 |
2 files changed, 188 insertions, 1 deletions
diff --git a/src/com/android/launcher3/CheckableFrameLayout.java b/src/com/android/launcher3/CheckableFrameLayout.java new file mode 100644 index 000000000..5b7d82425 --- /dev/null +++ b/src/com/android/launcher3/CheckableFrameLayout.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2013 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.Checkable; +import android.widget.FrameLayout; + +public class CheckableFrameLayout extends FrameLayout implements Checkable { + private static final int[] CHECKED_STATE_SET = { android.R.attr.state_checked }; + boolean mChecked; + + public CheckableFrameLayout(Context context) { + super(context); + } + + public CheckableFrameLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CheckableFrameLayout(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + } + + public boolean isChecked() { + return mChecked; + } + + public void setChecked(boolean checked) { + if (checked != mChecked) { + mChecked = checked; + refreshDrawableState(); + } + } + + public void toggle() { + setChecked(!mChecked); + } + + @Override + protected int[] onCreateDrawableState(int extraSpace) { + final int[] drawableState = super.onCreateDrawableState(extraSpace + 1); + if (isChecked()) { + mergeDrawableStates(drawableState, CHECKED_STATE_SET); + } + return drawableState; + } +} diff --git a/src/com/android/launcher3/WallpaperPickerActivity.java b/src/com/android/launcher3/WallpaperPickerActivity.java index 59318d9c6..a0b9e6e7d 100644 --- a/src/com/android/launcher3/WallpaperPickerActivity.java +++ b/src/com/android/launcher3/WallpaperPickerActivity.java @@ -33,10 +33,13 @@ import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.graphics.drawable.LevelListDrawable; import android.net.Uri; +import android.os.Bundle; import android.util.Log; import android.util.Pair; +import android.view.ActionMode; import android.view.LayoutInflater; import android.view.Menu; +import android.view.MenuInflater; import android.view.MenuItem; import android.view.SubMenu; import android.view.View; @@ -62,6 +65,7 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private static final int IMAGE_PICK = 5; private static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6; + private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES"; private ArrayList<Drawable> mBundledWallpaperThumbs; private ArrayList<Integer> mBundledWallpaperResIds; @@ -72,6 +76,10 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { private OnClickListener mThumbnailOnClickListener; private LinearLayout mWallpapersView; + + private ActionMode.Callback mActionModeCallback; + private ActionMode mActionMode; + private View.OnLongClickListener mLongClickListener; ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>(); @@ -120,6 +128,13 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { mThumbnailOnClickListener = new OnClickListener() { public void onClick(View v) { + if (mActionMode != null) { + // When CAB is up, clicking toggles the item instead + if (v.isLongClickable()) { + mLongClickListener.onLongClick(v); + } + return; + } if (mSelectedThumb != null) { mSelectedThumb.setSelected(false); } @@ -161,6 +176,25 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } }; + mLongClickListener = new View.OnLongClickListener() { + // Called when the user long-clicks on someView + public boolean onLongClick(View view) { + CheckableFrameLayout c = (CheckableFrameLayout) view; + c.toggle(); + + if (mActionMode != null) { + mActionMode.invalidate(); + } else { + // Start the CAB using the ActionMode.Callback defined below + mActionMode = startActionMode(mActionModeCallback); + int childCount = mWallpapersView.getChildCount(); + for (int i = 0; i < childCount; i++) { + mWallpapersView.getChildAt(i).setSelected(false); + } + } + return true; + } + }; // Populate the built-in wallpapers findBundledWallpapers(); @@ -191,6 +225,13 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { galleryThumbnail.setTag(meta); galleryThumbnail.setOnClickListener(mThumbnailOnClickListener); + // Create smooth layout transitions for when items are deleted + final LayoutTransition transitioner = new LayoutTransition(); + transitioner.setDuration(200); + transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); + transitioner.setAnimator(LayoutTransition.DISAPPEARING, null); + mWallpapersView.setLayoutTransition(transitioner); + // Action bar // Show the custom action bar view final ActionBar actionBar = getActionBar(); @@ -223,12 +264,95 @@ public class WallpaperPickerActivity extends WallpaperCropActivity { } } }); - } + // CAB for deleting items + mActionModeCallback = new ActionMode.Callback() { + // Called when the action mode is created; startActionMode() was called + @Override + public boolean onCreateActionMode(ActionMode mode, Menu menu) { + // Inflate a menu resource providing context menu items + MenuInflater inflater = mode.getMenuInflater(); + inflater.inflate(R.menu.cab_delete_wallpapers, menu); + return true; + } + private int numCheckedItems() { + int childCount = mWallpapersView.getChildCount(); + int numCheckedItems = 0; + for (int i = 0; i < childCount; i++) { + CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); + if (c.isChecked()) { + numCheckedItems++; + } + } + return numCheckedItems; + } + // Called each time the action mode is shown. Always called after onCreateActionMode, + // but may be called multiple times if the mode is invalidated. + @Override + public boolean onPrepareActionMode(ActionMode mode, Menu menu) { + int numCheckedItems = numCheckedItems(); + if (numCheckedItems == 0) { + mode.finish(); + return true; + } else { + mode.setTitle(getResources().getQuantityString( + R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems)); + return true; + } + } + // Called when the user selects a contextual menu item + @Override + public boolean onActionItemClicked(ActionMode mode, MenuItem item) { + switch (item.getItemId()) { + case R.id.menu_delete: + int childCount = mWallpapersView.getChildCount(); + ArrayList<View> viewsToRemove = new ArrayList<View>(); + for (int i = 0; i < childCount; i++) { + CheckableFrameLayout c = + (CheckableFrameLayout) mWallpapersView.getChildAt(i); + if (c.isChecked()) { + ThumbnailMetaData meta = (ThumbnailMetaData) c.getTag(); + mSavedImages.deleteImage(meta.mSavedWallpaperDbId); + viewsToRemove.add(c); + } + } + for (View v : viewsToRemove) { + mWallpapersView.removeView(v); + } + ///xxxxx DESTROYING + mode.finish(); // Action picked, so close the CAB + return true; + default: + return false; + } + } + + // Called when the user exits the action mode + @Override + public void onDestroyActionMode(ActionMode mode) { + int childCount = mWallpapersView.getChildCount(); + for (int i = 0; i < childCount; i++) { + CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); + c.setChecked(false); + } + mSelectedThumb.setSelected(true); + mActionMode = null; + } + }; + } + protected void onSaveInstanceState(Bundle outState) { + outState.putParcelableArrayList(TEMP_WALLPAPER_TILES, mTempWallpaperTiles); + } + protected void onRestoreInstanceState(Bundle savedInstanceState) { + ArrayList<Uri> uris = savedInstanceState.getParcelableArrayList(TEMP_WALLPAPER_TILES); + for (Uri uri : uris) { + addTemporaryWallpaperTile(uri); + } + } private void populateWallpapersFromAdapter(ViewGroup parent, ImageAdapter ia, ArrayList<Integer> imageIds, boolean imagesAreResources, boolean addLongPressHandler) { |