Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2013 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.launcher3; |
| 18 | |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 19 | import android.animation.LayoutTransition; |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 20 | import android.annotation.TargetApi; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 21 | import android.app.ActionBar; |
| 22 | import android.app.Activity; |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 23 | import android.app.WallpaperManager; |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 24 | import android.content.ActivityNotFoundException; |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 25 | import android.content.Context; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 26 | import android.content.Intent; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 27 | import android.content.pm.ApplicationInfo; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 29 | import android.content.res.Resources; |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 30 | import android.database.Cursor; |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 31 | import android.database.DataSetObserver; |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 32 | import android.graphics.Bitmap; |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 33 | import android.graphics.BitmapFactory; |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 35 | import android.graphics.Matrix; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 36 | import android.graphics.Point; |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 37 | import android.graphics.PorterDuff; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 38 | import android.graphics.RectF; |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 39 | import android.graphics.drawable.BitmapDrawable; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 40 | import android.graphics.drawable.Drawable; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 41 | import android.net.Uri; |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 42 | import android.os.AsyncTask; |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 43 | import android.os.Build; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 44 | import android.os.Bundle; |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 45 | import android.provider.MediaStore; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 46 | import android.util.Log; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 47 | import android.util.Pair; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 48 | import android.view.ActionMode; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 49 | import android.view.LayoutInflater; |
| 50 | import android.view.Menu; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 51 | import android.view.MenuInflater; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 52 | import android.view.MenuItem; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 53 | import android.view.View; |
| 54 | import android.view.View.OnClickListener; |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 55 | import android.view.View.OnLayoutChangeListener; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 56 | import android.view.ViewGroup; |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 57 | import android.view.ViewPropertyAnimator; |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 58 | import android.view.ViewTreeObserver; |
| 59 | import android.view.ViewTreeObserver.OnGlobalLayoutListener; |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 60 | import android.view.WindowManager; |
Daniel Sandler | 24f397d | 2013-10-12 00:02:45 -0400 | [diff] [blame] | 61 | import android.view.animation.AccelerateInterpolator; |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 62 | import android.view.animation.DecelerateInterpolator; |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 63 | import android.widget.ArrayAdapter; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 64 | import android.widget.BaseAdapter; |
| 65 | import android.widget.FrameLayout; |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 66 | import android.widget.HorizontalScrollView; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 67 | import android.widget.ImageView; |
| 68 | import android.widget.LinearLayout; |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 69 | import android.widget.Toast; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 70 | |
Sunny Goyal | 06a4d3f | 2015-02-12 11:19:39 -0800 | [diff] [blame] | 71 | import com.android.gallery3d.common.BitmapCropTask; |
| 72 | import com.android.gallery3d.common.BitmapUtils; |
| 73 | import com.android.gallery3d.common.Utils; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 74 | import com.android.launcher3.util.Thunk; |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 75 | import com.android.launcher3.util.WallpaperUtils; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 76 | import com.android.photos.BitmapRegionTileSource; |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 77 | import com.android.photos.BitmapRegionTileSource.BitmapSource; |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 78 | import com.android.photos.views.TiledImageRenderer.TileSource; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 79 | |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 80 | import java.io.File; |
| 81 | import java.io.FileOutputStream; |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 82 | import java.io.IOException; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 83 | import java.util.ArrayList; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 84 | |
| 85 | public class WallpaperPickerActivity extends WallpaperCropActivity { |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 86 | static final String TAG = "Launcher.WallpaperPickerActivity"; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 87 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 88 | public static final int IMAGE_PICK = 5; |
| 89 | public static final int PICK_WALLPAPER_THIRD_PARTY_ACTIVITY = 6; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 90 | private static final String TEMP_WALLPAPER_TILES = "TEMP_WALLPAPER_TILES"; |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 91 | private static final String SELECTED_INDEX = "SELECTED_INDEX"; |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 92 | private static final int FLAG_POST_DELAY_MILLIS = 200; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 93 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 94 | @Thunk View mSelectedTile; |
| 95 | @Thunk boolean mIgnoreNextTap; |
| 96 | @Thunk OnClickListener mThumbnailOnClickListener; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 97 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 98 | @Thunk LinearLayout mWallpapersView; |
| 99 | @Thunk HorizontalScrollView mWallpaperScrollContainer; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 100 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 101 | @Thunk ActionMode.Callback mActionModeCallback; |
| 102 | @Thunk ActionMode mActionMode; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 103 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 104 | @Thunk View.OnLongClickListener mLongClickListener; |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 105 | |
| 106 | ArrayList<Uri> mTempWallpaperTiles = new ArrayList<Uri>(); |
| 107 | private SavedWallpaperImages mSavedImages; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 108 | @Thunk int mSelectedIndex = -1; |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 109 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 110 | public static abstract class WallpaperTileInfo { |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 111 | protected View mView; |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 112 | public Drawable mThumb; |
| 113 | |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 114 | public void setView(View v) { |
| 115 | mView = v; |
| 116 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 117 | public void onClick(WallpaperPickerActivity a) {} |
| 118 | public void onSave(WallpaperPickerActivity a) {} |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 119 | public void onDelete(WallpaperPickerActivity a) {} |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 120 | public boolean isSelectable() { return false; } |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 121 | public boolean isNamelessWallpaper() { return false; } |
| 122 | public void onIndexUpdated(CharSequence label) { |
| 123 | if (isNamelessWallpaper()) { |
| 124 | mView.setContentDescription(label); |
| 125 | } |
| 126 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | public static class PickImageInfo extends WallpaperTileInfo { |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 130 | @Override |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 131 | public void onClick(WallpaperPickerActivity a) { |
| 132 | Intent intent = new Intent(Intent.ACTION_GET_CONTENT); |
| 133 | intent.setType("image/*"); |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 134 | a.startActivityForResultSafely(intent, IMAGE_PICK); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | public static class UriWallpaperInfo extends WallpaperTileInfo { |
| 139 | private Uri mUri; |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 140 | private boolean mFirstClick = true; |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 141 | @Thunk BitmapRegionTileSource.UriBitmapSource mBitmapSource; |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 142 | public UriWallpaperInfo(Uri uri) { |
| 143 | mUri = uri; |
| 144 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 145 | @Override |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 146 | public void onClick(final WallpaperPickerActivity a) { |
| 147 | final Runnable onLoad; |
| 148 | if (!mFirstClick) { |
| 149 | onLoad = null; |
| 150 | } else { |
| 151 | mFirstClick = false; |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 152 | a.mSetWallpaperButton.setEnabled(false); |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 153 | onLoad = new Runnable() { |
| 154 | public void run() { |
| 155 | if (mBitmapSource != null && |
| 156 | mBitmapSource.getLoadingState() == BitmapSource.State.LOADED) { |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 157 | a.selectTile(mView); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 158 | a.mSetWallpaperButton.setEnabled(true); |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 159 | } else { |
| 160 | ViewGroup parent = (ViewGroup) mView.getParent(); |
| 161 | if (parent != null) { |
| 162 | parent.removeView(mView); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 163 | Toast.makeText(a.getContext(), R.string.image_load_fail, |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 164 | Toast.LENGTH_SHORT).show(); |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | }; |
| 169 | } |
| 170 | mBitmapSource = new BitmapRegionTileSource.UriBitmapSource( |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 171 | a.getContext(), mUri, BitmapRegionTileSource.MAX_PREVIEW_SIZE); |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 172 | a.setCropViewTileSource(mBitmapSource, true, false, null, onLoad); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 173 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 174 | @Override |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 175 | public void onSave(final WallpaperPickerActivity a) { |
| 176 | boolean finishActivityWhenDone = true; |
Sunny Goyal | 06a4d3f | 2015-02-12 11:19:39 -0800 | [diff] [blame] | 177 | BitmapCropTask.OnBitmapCroppedHandler h = new BitmapCropTask.OnBitmapCroppedHandler() { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 178 | public void onBitmapCropped(byte[] imageBytes) { |
| 179 | Point thumbSize = getDefaultThumbnailSize(a.getResources()); |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 180 | // rotation is set to 0 since imageBytes has already been correctly rotated |
| 181 | Bitmap thumb = createThumbnail( |
| 182 | thumbSize, null, null, imageBytes, null, 0, 0, true); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 183 | a.getSavedImages().writeImage(thumb, imageBytes); |
| 184 | } |
| 185 | }; |
| 186 | a.cropImageAndSetWallpaper(mUri, h, finishActivityWhenDone); |
| 187 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 188 | @Override |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 189 | public boolean isSelectable() { |
| 190 | return true; |
| 191 | } |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 192 | @Override |
| 193 | public boolean isNamelessWallpaper() { |
| 194 | return true; |
| 195 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 196 | } |
| 197 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 198 | public static class FileWallpaperInfo extends WallpaperTileInfo { |
| 199 | private File mFile; |
| 200 | |
| 201 | public FileWallpaperInfo(File target, Drawable thumb) { |
| 202 | mFile = target; |
| 203 | mThumb = thumb; |
| 204 | } |
| 205 | @Override |
| 206 | public void onClick(WallpaperPickerActivity a) { |
| 207 | BitmapRegionTileSource.UriBitmapSource bitmapSource = |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 208 | new BitmapRegionTileSource.UriBitmapSource(a.getContext(), |
| 209 | Uri.fromFile(mFile), 1024); |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 210 | a.setCropViewTileSource(bitmapSource, false, true, null, null); |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 211 | } |
| 212 | @Override |
| 213 | public void onSave(WallpaperPickerActivity a) { |
| 214 | a.setWallpaper(Uri.fromFile(mFile), true); |
| 215 | } |
| 216 | @Override |
| 217 | public boolean isSelectable() { |
| 218 | return true; |
| 219 | } |
| 220 | @Override |
| 221 | public boolean isNamelessWallpaper() { |
| 222 | return true; |
| 223 | } |
| 224 | } |
| 225 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 226 | public static class ResourceWallpaperInfo extends WallpaperTileInfo { |
| 227 | private Resources mResources; |
| 228 | private int mResId; |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 229 | |
| 230 | public ResourceWallpaperInfo(Resources res, int resId, Drawable thumb) { |
| 231 | mResources = res; |
| 232 | mResId = resId; |
| 233 | mThumb = thumb; |
| 234 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 235 | @Override |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 236 | public void onClick(final WallpaperPickerActivity a) { |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 237 | BitmapRegionTileSource.ResourceBitmapSource bitmapSource = |
Michael Jurka | 83699e5 | 2013-10-23 20:59:51 +0200 | [diff] [blame] | 238 | new BitmapRegionTileSource.ResourceBitmapSource( |
| 239 | mResources, mResId, BitmapRegionTileSource.MAX_PREVIEW_SIZE); |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 240 | a.setCropViewTileSource(bitmapSource, false, false, new CropViewScaleProvider() { |
| 241 | |
| 242 | @Override |
| 243 | public float getScale(TileSource src) { |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 244 | Point wallpaperSize = WallpaperUtils.getDefaultWallpaperSize( |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 245 | a.getResources(), a.getWindowManager()); |
| 246 | RectF crop = Utils.getMaxCropRect( |
| 247 | src.getImageWidth(), src.getImageHeight(), |
| 248 | wallpaperSize.x, wallpaperSize.y, false); |
| 249 | return wallpaperSize.x / crop.width(); |
| 250 | } |
| 251 | }, null); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 252 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 253 | @Override |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 254 | public void onSave(WallpaperPickerActivity a) { |
| 255 | boolean finishActivityWhenDone = true; |
| 256 | a.cropImageAndSetWallpaper(mResources, mResId, finishActivityWhenDone); |
| 257 | } |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 258 | @Override |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 259 | public boolean isSelectable() { |
| 260 | return true; |
| 261 | } |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 262 | @Override |
| 263 | public boolean isNamelessWallpaper() { |
| 264 | return true; |
| 265 | } |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 268 | @TargetApi(Build.VERSION_CODES.KITKAT) |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 269 | public static class DefaultWallpaperInfo extends WallpaperTileInfo { |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 270 | public DefaultWallpaperInfo(Drawable thumb) { |
| 271 | mThumb = thumb; |
| 272 | } |
| 273 | @Override |
| 274 | public void onClick(WallpaperPickerActivity a) { |
Michael Jurka | 83699e5 | 2013-10-23 20:59:51 +0200 | [diff] [blame] | 275 | CropView c = a.getCropView(); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 276 | Drawable defaultWallpaper = WallpaperManager.getInstance(a.getContext()) |
| 277 | .getBuiltInDrawable(c.getWidth(), c.getHeight(), false, 0.5f, 0.5f); |
Christoph Studer | 7084c60 | 2014-02-28 15:57:18 +0100 | [diff] [blame] | 278 | if (defaultWallpaper == null) { |
| 279 | Log.w(TAG, "Null default wallpaper encountered."); |
| 280 | c.setTileSource(null, null); |
| 281 | return; |
| 282 | } |
| 283 | |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 284 | LoadRequest req = new LoadRequest(); |
| 285 | req.moveToLeft = false; |
| 286 | req.touchEnabled = false; |
| 287 | req.scaleProvider = new CropViewScaleProvider() { |
| 288 | |
| 289 | @Override |
| 290 | public float getScale(TileSource src) { |
| 291 | return 1f; |
| 292 | } |
| 293 | }; |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 294 | req.result = new DrawableTileSource(a.getContext(), |
| 295 | defaultWallpaper, DrawableTileSource.MAX_PREVIEW_SIZE); |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 296 | a.onLoadRequestComplete(req, true); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 297 | } |
| 298 | @Override |
| 299 | public void onSave(WallpaperPickerActivity a) { |
| 300 | try { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 301 | WallpaperManager.getInstance(a.getContext()).clear(); |
| 302 | a.setResult(Activity.RESULT_OK); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 303 | } catch (IOException e) { |
| 304 | Log.w("Setting wallpaper to default threw exception", e); |
| 305 | } |
| 306 | a.finish(); |
| 307 | } |
| 308 | @Override |
| 309 | public boolean isSelectable() { |
| 310 | return true; |
| 311 | } |
| 312 | @Override |
| 313 | public boolean isNamelessWallpaper() { |
| 314 | return true; |
| 315 | } |
| 316 | } |
| 317 | |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 318 | /** |
| 319 | * shows the system wallpaper behind the window and hides the {@link |
| 320 | * #mCropView} if visible |
| 321 | * @param visible should the system wallpaper be shown |
| 322 | */ |
| 323 | protected void setSystemWallpaperVisiblity(final boolean visible) { |
| 324 | // hide our own wallpaper preview if necessary |
| 325 | if(!visible) { |
| 326 | mCropView.setVisibility(View.VISIBLE); |
| 327 | } else { |
| 328 | changeWallpaperFlags(visible); |
| 329 | } |
| 330 | // the change of the flag must be delayed in order to avoid flickering, |
| 331 | // a simple post / double post does not suffice here |
| 332 | mCropView.postDelayed(new Runnable() { |
| 333 | @Override |
| 334 | public void run() { |
| 335 | if(!visible) { |
| 336 | changeWallpaperFlags(visible); |
| 337 | } else { |
| 338 | mCropView.setVisibility(View.INVISIBLE); |
| 339 | } |
| 340 | } |
| 341 | }, FLAG_POST_DELAY_MILLIS); |
| 342 | } |
| 343 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 344 | @Thunk void changeWallpaperFlags(boolean visible) { |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 345 | int desiredWallpaperFlag = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; |
| 346 | int currentWallpaperFlag = getWindow().getAttributes().flags |
| 347 | & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; |
| 348 | if (desiredWallpaperFlag != currentWallpaperFlag) { |
| 349 | getWindow().setFlags(desiredWallpaperFlag, |
| 350 | WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); |
| 351 | } |
| 352 | } |
| 353 | |
| 354 | @Override |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 355 | protected void onLoadRequestComplete(LoadRequest req, boolean success) { |
| 356 | super.onLoadRequestComplete(req, success); |
| 357 | if (success) { |
| 358 | setSystemWallpaperVisiblity(false); |
| 359 | } |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 360 | } |
| 361 | |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 362 | // called by onCreate; this is subclassed to overwrite WallpaperCropActivity |
| 363 | protected void init() { |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 364 | setContentView(R.layout.wallpaper_picker); |
| 365 | |
| 366 | mCropView = (CropView) findViewById(R.id.cropView); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 367 | mCropView.setVisibility(View.INVISIBLE); |
| 368 | |
Sunny Goyal | 65b929d | 2015-02-12 15:34:41 -0800 | [diff] [blame] | 369 | mProgressView = findViewById(R.id.loading); |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 370 | mWallpaperScrollContainer = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container); |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 371 | mCropView.setTouchCallback(new CropView.TouchCallback() { |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 372 | ViewPropertyAnimator mAnim; |
Michael Jurka | e8115d5 | 2013-09-20 03:52:24 +0200 | [diff] [blame] | 373 | @Override |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 374 | public void onTouchDown() { |
| 375 | if (mAnim != null) { |
| 376 | mAnim.cancel(); |
| 377 | } |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 378 | if (mWallpaperScrollContainer.getAlpha() == 1f) { |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 379 | mIgnoreNextTap = true; |
| 380 | } |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 381 | mAnim = mWallpaperScrollContainer.animate(); |
Daniel Sandler | 24f397d | 2013-10-12 00:02:45 -0400 | [diff] [blame] | 382 | mAnim.alpha(0f) |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 383 | .setDuration(150) |
| 384 | .withEndAction(new Runnable() { |
| 385 | public void run() { |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 386 | mWallpaperScrollContainer.setVisibility(View.INVISIBLE); |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 387 | } |
| 388 | }); |
Daniel Sandler | 24f397d | 2013-10-12 00:02:45 -0400 | [diff] [blame] | 389 | mAnim.setInterpolator(new AccelerateInterpolator(0.75f)); |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 390 | mAnim.start(); |
| 391 | } |
Michael Jurka | e8115d5 | 2013-09-20 03:52:24 +0200 | [diff] [blame] | 392 | @Override |
| 393 | public void onTouchUp() { |
| 394 | mIgnoreNextTap = false; |
| 395 | } |
| 396 | @Override |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 397 | public void onTap() { |
| 398 | boolean ignoreTap = mIgnoreNextTap; |
| 399 | mIgnoreNextTap = false; |
| 400 | if (!ignoreTap) { |
| 401 | if (mAnim != null) { |
| 402 | mAnim.cancel(); |
| 403 | } |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 404 | mWallpaperScrollContainer.setVisibility(View.VISIBLE); |
| 405 | mAnim = mWallpaperScrollContainer.animate(); |
Daniel Sandler | 24f397d | 2013-10-12 00:02:45 -0400 | [diff] [blame] | 406 | mAnim.alpha(1f) |
| 407 | .setDuration(150) |
| 408 | .setInterpolator(new DecelerateInterpolator(0.75f)); |
Michael Jurka | 4b94060 | 2013-09-05 12:14:12 +0200 | [diff] [blame] | 409 | mAnim.start(); |
| 410 | } |
| 411 | } |
| 412 | }); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 413 | |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 414 | mThumbnailOnClickListener = new OnClickListener() { |
| 415 | public void onClick(View v) { |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 416 | if (mActionMode != null) { |
| 417 | // When CAB is up, clicking toggles the item instead |
| 418 | if (v.isLongClickable()) { |
| 419 | mLongClickListener.onLongClick(v); |
| 420 | } |
| 421 | return; |
| 422 | } |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 423 | mSetWallpaperButton.setEnabled(true); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 424 | WallpaperTileInfo info = (WallpaperTileInfo) v.getTag(); |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 425 | if (info.isSelectable() && v.getVisibility() == View.VISIBLE) { |
| 426 | selectTile(v); |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 427 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 428 | info.onClick(WallpaperPickerActivity.this); |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 429 | } |
| 430 | }; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 431 | mLongClickListener = new View.OnLongClickListener() { |
| 432 | // Called when the user long-clicks on someView |
| 433 | public boolean onLongClick(View view) { |
| 434 | CheckableFrameLayout c = (CheckableFrameLayout) view; |
| 435 | c.toggle(); |
| 436 | |
| 437 | if (mActionMode != null) { |
| 438 | mActionMode.invalidate(); |
| 439 | } else { |
| 440 | // Start the CAB using the ActionMode.Callback defined below |
| 441 | mActionMode = startActionMode(mActionModeCallback); |
| 442 | int childCount = mWallpapersView.getChildCount(); |
| 443 | for (int i = 0; i < childCount; i++) { |
| 444 | mWallpapersView.getChildAt(i).setSelected(false); |
| 445 | } |
| 446 | } |
| 447 | return true; |
| 448 | } |
| 449 | }; |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 450 | |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 451 | // Populate the built-in wallpapers |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 452 | ArrayList<WallpaperTileInfo> wallpapers = findBundledWallpapers(); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 453 | mWallpapersView = (LinearLayout) findViewById(R.id.wallpaper_list); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 454 | SimpleWallpapersAdapter ia = new SimpleWallpapersAdapter(getContext(), wallpapers); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 455 | populateWallpapersFromAdapter(mWallpapersView, ia, false); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 456 | |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 457 | // Populate the saved wallpapers |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 458 | mSavedImages = new SavedWallpaperImages(getContext()); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 459 | mSavedImages.loadThumbnailsAndImageIdList(); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 460 | populateWallpapersFromAdapter(mWallpapersView, mSavedImages, true); |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 461 | |
| 462 | // Populate the live wallpapers |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 463 | final LinearLayout liveWallpapersView = |
| 464 | (LinearLayout) findViewById(R.id.live_wallpaper_list); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 465 | final LiveWallpaperListAdapter a = new LiveWallpaperListAdapter(getContext()); |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 466 | a.registerDataSetObserver(new DataSetObserver() { |
| 467 | public void onChanged() { |
| 468 | liveWallpapersView.removeAllViews(); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 469 | populateWallpapersFromAdapter(liveWallpapersView, a, false); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 470 | initializeScrollForRtl(); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 471 | updateTileIndices(); |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 472 | } |
| 473 | }); |
| 474 | |
| 475 | // Populate the third-party wallpaper pickers |
| 476 | final LinearLayout thirdPartyWallpapersView = |
| 477 | (LinearLayout) findViewById(R.id.third_party_wallpaper_list); |
| 478 | final ThirdPartyWallpaperPickerListAdapter ta = |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 479 | new ThirdPartyWallpaperPickerListAdapter(getContext()); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 480 | populateWallpapersFromAdapter(thirdPartyWallpapersView, ta, false); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 481 | |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 482 | // Add a tile for the Gallery |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 483 | LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 484 | FrameLayout pickImageTile = (FrameLayout) getLayoutInflater(). |
Michael Jurka | 5b4b690 | 2013-10-03 18:15:08 -0700 | [diff] [blame] | 485 | inflate(R.layout.wallpaper_picker_image_picker_item, masterWallpaperList, false); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 486 | masterWallpaperList.addView(pickImageTile, 0); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 487 | |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 488 | // Make its background the last photo taken on external storage |
| 489 | Bitmap lastPhoto = getThumbnailOfLastPhoto(); |
| 490 | if (lastPhoto != null) { |
| 491 | ImageView galleryThumbnailBg = |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 492 | (ImageView) pickImageTile.findViewById(R.id.wallpaper_image); |
Sunny Goyal | 6f553b9 | 2015-02-12 09:46:41 -0800 | [diff] [blame] | 493 | galleryThumbnailBg.setImageBitmap(lastPhoto); |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 494 | int colorOverlay = getResources().getColor(R.color.wallpaper_picker_translucent_gray); |
| 495 | galleryThumbnailBg.setColorFilter(colorOverlay, PorterDuff.Mode.SRC_ATOP); |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 496 | } |
| 497 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 498 | PickImageInfo pickImageInfo = new PickImageInfo(); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 499 | pickImageTile.setTag(pickImageInfo); |
| 500 | pickImageInfo.setView(pickImageTile); |
| 501 | pickImageTile.setOnClickListener(mThumbnailOnClickListener); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 502 | |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 503 | // Select the first item; wait for a layout pass so that we initialize the dimensions of |
| 504 | // cropView or the defaultWallpaperView first |
Michael Jurka | 83699e5 | 2013-10-23 20:59:51 +0200 | [diff] [blame] | 505 | mCropView.addOnLayoutChangeListener(new OnLayoutChangeListener() { |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 506 | @Override |
| 507 | public void onLayoutChange(View v, int left, int top, int right, int bottom, |
| 508 | int oldLeft, int oldTop, int oldRight, int oldBottom) { |
| 509 | if ((right - left) > 0 && (bottom - top) > 0) { |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 510 | if (mSelectedIndex >= 0 && mSelectedIndex < mWallpapersView.getChildCount()) { |
| 511 | mThumbnailOnClickListener.onClick( |
| 512 | mWallpapersView.getChildAt(mSelectedIndex)); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 513 | setSystemWallpaperVisiblity(false); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 514 | } |
| 515 | v.removeOnLayoutChangeListener(this); |
| 516 | } |
| 517 | } |
| 518 | }); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 519 | |
| 520 | updateTileIndices(); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 521 | |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 522 | // Update the scroll for RTL |
| 523 | initializeScrollForRtl(); |
| 524 | |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 525 | // Create smooth layout transitions for when items are deleted |
| 526 | final LayoutTransition transitioner = new LayoutTransition(); |
| 527 | transitioner.setDuration(200); |
| 528 | transitioner.setStartDelay(LayoutTransition.CHANGE_DISAPPEARING, 0); |
| 529 | transitioner.setAnimator(LayoutTransition.DISAPPEARING, null); |
| 530 | mWallpapersView.setLayoutTransition(transitioner); |
| 531 | |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 532 | // Action bar |
| 533 | // Show the custom action bar view |
| 534 | final ActionBar actionBar = getActionBar(); |
| 535 | actionBar.setCustomView(R.layout.actionbar_set_wallpaper); |
| 536 | actionBar.getCustomView().setOnClickListener( |
| 537 | new View.OnClickListener() { |
| 538 | @Override |
| 539 | public void onClick(View v) { |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 540 | if (mSelectedTile != null) { |
| 541 | WallpaperTileInfo info = (WallpaperTileInfo) mSelectedTile.getTag(); |
Michael Jurka | b92f433 | 2013-09-24 12:53:49 +0100 | [diff] [blame] | 542 | info.onSave(WallpaperPickerActivity.this); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 543 | } else { |
| 544 | // no tile was selected, so we just finish the activity and go back |
| 545 | setResult(Activity.RESULT_OK); |
| 546 | finish(); |
Michael Jurka | b92f433 | 2013-09-24 12:53:49 +0100 | [diff] [blame] | 547 | } |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 548 | } |
| 549 | }); |
Michael Jurka | 849aff7 | 2014-01-16 14:58:00 +0100 | [diff] [blame] | 550 | mSetWallpaperButton = findViewById(R.id.set_wallpaper_button); |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 551 | |
| 552 | // CAB for deleting items |
| 553 | mActionModeCallback = new ActionMode.Callback() { |
| 554 | // Called when the action mode is created; startActionMode() was called |
| 555 | @Override |
| 556 | public boolean onCreateActionMode(ActionMode mode, Menu menu) { |
| 557 | // Inflate a menu resource providing context menu items |
| 558 | MenuInflater inflater = mode.getMenuInflater(); |
| 559 | inflater.inflate(R.menu.cab_delete_wallpapers, menu); |
| 560 | return true; |
| 561 | } |
| 562 | |
| 563 | private int numCheckedItems() { |
| 564 | int childCount = mWallpapersView.getChildCount(); |
| 565 | int numCheckedItems = 0; |
| 566 | for (int i = 0; i < childCount; i++) { |
| 567 | CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); |
| 568 | if (c.isChecked()) { |
| 569 | numCheckedItems++; |
| 570 | } |
| 571 | } |
| 572 | return numCheckedItems; |
| 573 | } |
| 574 | |
| 575 | // Called each time the action mode is shown. Always called after onCreateActionMode, |
| 576 | // but may be called multiple times if the mode is invalidated. |
| 577 | @Override |
| 578 | public boolean onPrepareActionMode(ActionMode mode, Menu menu) { |
| 579 | int numCheckedItems = numCheckedItems(); |
| 580 | if (numCheckedItems == 0) { |
| 581 | mode.finish(); |
| 582 | return true; |
| 583 | } else { |
| 584 | mode.setTitle(getResources().getQuantityString( |
| 585 | R.plurals.number_of_items_selected, numCheckedItems, numCheckedItems)); |
| 586 | return true; |
| 587 | } |
| 588 | } |
| 589 | |
| 590 | // Called when the user selects a contextual menu item |
| 591 | @Override |
| 592 | public boolean onActionItemClicked(ActionMode mode, MenuItem item) { |
Bjorn Bringert | c639f8c | 2013-09-13 13:39:12 +0100 | [diff] [blame] | 593 | int itemId = item.getItemId(); |
| 594 | if (itemId == R.id.menu_delete) { |
| 595 | int childCount = mWallpapersView.getChildCount(); |
| 596 | ArrayList<View> viewsToRemove = new ArrayList<View>(); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 597 | boolean selectedTileRemoved = false; |
Bjorn Bringert | c639f8c | 2013-09-13 13:39:12 +0100 | [diff] [blame] | 598 | for (int i = 0; i < childCount; i++) { |
| 599 | CheckableFrameLayout c = |
| 600 | (CheckableFrameLayout) mWallpapersView.getChildAt(i); |
| 601 | if (c.isChecked()) { |
Michael Jurka | 8a34bdb | 2013-09-25 07:57:33 -0700 | [diff] [blame] | 602 | WallpaperTileInfo info = (WallpaperTileInfo) c.getTag(); |
| 603 | info.onDelete(WallpaperPickerActivity.this); |
Bjorn Bringert | c639f8c | 2013-09-13 13:39:12 +0100 | [diff] [blame] | 604 | viewsToRemove.add(c); |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 605 | if (i == mSelectedIndex) { |
| 606 | selectedTileRemoved = true; |
| 607 | } |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 608 | } |
Bjorn Bringert | c639f8c | 2013-09-13 13:39:12 +0100 | [diff] [blame] | 609 | } |
| 610 | for (View v : viewsToRemove) { |
| 611 | mWallpapersView.removeView(v); |
| 612 | } |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 613 | if (selectedTileRemoved) { |
| 614 | mSelectedIndex = -1; |
| 615 | mSelectedTile = null; |
| 616 | setSystemWallpaperVisiblity(true); |
| 617 | } |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 618 | updateTileIndices(); |
Bjorn Bringert | c639f8c | 2013-09-13 13:39:12 +0100 | [diff] [blame] | 619 | mode.finish(); // Action picked, so close the CAB |
| 620 | return true; |
| 621 | } else { |
| 622 | return false; |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 623 | } |
| 624 | } |
| 625 | |
| 626 | // Called when the user exits the action mode |
| 627 | @Override |
| 628 | public void onDestroyActionMode(ActionMode mode) { |
| 629 | int childCount = mWallpapersView.getChildCount(); |
| 630 | for (int i = 0; i < childCount; i++) { |
| 631 | CheckableFrameLayout c = (CheckableFrameLayout) mWallpapersView.getChildAt(i); |
| 632 | c.setChecked(false); |
| 633 | } |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 634 | if (mSelectedTile != null) { |
| 635 | mSelectedTile.setSelected(true); |
| 636 | } |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 637 | mActionMode = null; |
| 638 | } |
| 639 | }; |
| 640 | } |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 641 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 642 | @Thunk void selectTile(View v) { |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 643 | if (mSelectedTile != null) { |
| 644 | mSelectedTile.setSelected(false); |
| 645 | mSelectedTile = null; |
| 646 | } |
| 647 | mSelectedTile = v; |
| 648 | v.setSelected(true); |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 649 | mSelectedIndex = mWallpapersView.indexOfChild(v); |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 650 | // TODO: Remove this once the accessibility framework and |
| 651 | // services have better support for selection state. |
| 652 | v.announceForAccessibility( |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 653 | getContext().getString(R.string.announce_selection, v.getContentDescription())); |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 654 | } |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 655 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 656 | @Thunk void initializeScrollForRtl() { |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 657 | if (mWallpaperScrollContainer.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL) { |
| 658 | final ViewTreeObserver observer = mWallpaperScrollContainer.getViewTreeObserver(); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 659 | observer.addOnGlobalLayoutListener(new OnGlobalLayoutListener() { |
| 660 | public void onGlobalLayout() { |
| 661 | LinearLayout masterWallpaperList = |
| 662 | (LinearLayout) findViewById(R.id.master_wallpaper_list); |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 663 | mWallpaperScrollContainer.scrollTo(masterWallpaperList.getWidth(), 0); |
| 664 | mWallpaperScrollContainer.getViewTreeObserver().removeOnGlobalLayoutListener(this); |
Michael Jurka | fe0ace3 | 2013-10-03 01:05:14 -0700 | [diff] [blame] | 665 | } |
| 666 | }); |
| 667 | } |
| 668 | } |
| 669 | |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 670 | protected Bitmap getThumbnailOfLastPhoto() { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 671 | Cursor cursor = MediaStore.Images.Media.query(getContext().getContentResolver(), |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 672 | MediaStore.Images.Media.EXTERNAL_CONTENT_URI, |
| 673 | new String[] { MediaStore.Images.ImageColumns._ID, |
| 674 | MediaStore.Images.ImageColumns.DATE_TAKEN}, |
| 675 | null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC LIMIT 1"); |
Adam Cohen | c8d31ff | 2014-06-12 12:29:50 -0700 | [diff] [blame] | 676 | |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 677 | Bitmap thumb = null; |
Adam Cohen | c8d31ff | 2014-06-12 12:29:50 -0700 | [diff] [blame] | 678 | if (cursor != null) { |
| 679 | if (cursor.moveToNext()) { |
| 680 | int id = cursor.getInt(0); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 681 | thumb = MediaStore.Images.Thumbnails.getThumbnail(getContext().getContentResolver(), |
Adam Cohen | c8d31ff | 2014-06-12 12:29:50 -0700 | [diff] [blame] | 682 | id, MediaStore.Images.Thumbnails.MINI_KIND, null); |
| 683 | } |
| 684 | cursor.close(); |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 685 | } |
Michael Jurka | 42a7174 | 2013-09-18 00:45:45 +0200 | [diff] [blame] | 686 | return thumb; |
| 687 | } |
Michael Jurka | 5664de2 | 2013-09-12 02:53:22 +0200 | [diff] [blame] | 688 | |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 689 | public void onStop() { |
Michael Jurka | 5664de2 | 2013-09-12 02:53:22 +0200 | [diff] [blame] | 690 | super.onStop(); |
Sunny Goyal | 9c83a0d | 2015-02-13 10:40:07 -0800 | [diff] [blame] | 691 | mWallpaperScrollContainer = (HorizontalScrollView) findViewById(R.id.wallpaper_scroll_container); |
| 692 | if (mWallpaperScrollContainer.getAlpha() < 1f) { |
| 693 | mWallpaperScrollContainer.setAlpha(1f); |
| 694 | mWallpaperScrollContainer.setVisibility(View.VISIBLE); |
Michael Jurka | 5664de2 | 2013-09-12 02:53:22 +0200 | [diff] [blame] | 695 | } |
| 696 | } |
| 697 | |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 698 | public void onSaveInstanceState(Bundle outState) { |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 699 | outState.putParcelableArrayList(TEMP_WALLPAPER_TILES, mTempWallpaperTiles); |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 700 | outState.putInt(SELECTED_INDEX, mSelectedIndex); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 701 | } |
| 702 | |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 703 | protected void onRestoreInstanceState(Bundle savedInstanceState) { |
| 704 | ArrayList<Uri> uris = savedInstanceState.getParcelableArrayList(TEMP_WALLPAPER_TILES); |
| 705 | for (Uri uri : uris) { |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 706 | addTemporaryWallpaperTile(uri, true); |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 707 | } |
Selim Cinek | ffed658 | 2014-02-28 17:18:59 +0100 | [diff] [blame] | 708 | mSelectedIndex = savedInstanceState.getInt(SELECTED_INDEX, -1); |
Michael Jurka | d6dc604 | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 709 | } |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 710 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 711 | @Thunk void populateWallpapersFromAdapter(ViewGroup parent, BaseAdapter adapter, |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 712 | boolean addLongPressHandler) { |
Michael Jurka | 998e4ff | 2013-09-18 16:04:36 +0200 | [diff] [blame] | 713 | for (int i = 0; i < adapter.getCount(); i++) { |
| 714 | FrameLayout thumbnail = (FrameLayout) adapter.getView(i, null, parent); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 715 | parent.addView(thumbnail, i); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 716 | WallpaperTileInfo info = (WallpaperTileInfo) adapter.getItem(i); |
| 717 | thumbnail.setTag(info); |
| 718 | info.setView(thumbnail); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 719 | if (addLongPressHandler) { |
| 720 | addLongPressHandler(thumbnail); |
| 721 | } |
| 722 | thumbnail.setOnClickListener(mThumbnailOnClickListener); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 726 | @Thunk void updateTileIndices() { |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 727 | LinearLayout masterWallpaperList = (LinearLayout) findViewById(R.id.master_wallpaper_list); |
| 728 | final int childCount = masterWallpaperList.getChildCount(); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 729 | final Resources res = getResources(); |
| 730 | |
| 731 | // Do two passes; the first pass gets the total number of tiles |
| 732 | int numTiles = 0; |
| 733 | for (int passNum = 0; passNum < 2; passNum++) { |
| 734 | int tileIndex = 0; |
| 735 | for (int i = 0; i < childCount; i++) { |
| 736 | View child = masterWallpaperList.getChildAt(i); |
| 737 | LinearLayout subList; |
| 738 | |
| 739 | int subListStart; |
| 740 | int subListEnd; |
| 741 | if (child.getTag() instanceof WallpaperTileInfo) { |
| 742 | subList = masterWallpaperList; |
| 743 | subListStart = i; |
| 744 | subListEnd = i + 1; |
| 745 | } else { // if (child instanceof LinearLayout) { |
| 746 | subList = (LinearLayout) child; |
| 747 | subListStart = 0; |
| 748 | subListEnd = subList.getChildCount(); |
| 749 | } |
| 750 | |
| 751 | for (int j = subListStart; j < subListEnd; j++) { |
| 752 | WallpaperTileInfo info = (WallpaperTileInfo) subList.getChildAt(j).getTag(); |
| 753 | if (info.isNamelessWallpaper()) { |
| 754 | if (passNum == 0) { |
| 755 | numTiles++; |
| 756 | } else { |
| 757 | CharSequence label = res.getString( |
| 758 | R.string.wallpaper_accessibility_name, ++tileIndex, numTiles); |
| 759 | info.onIndexUpdated(label); |
| 760 | } |
| 761 | } |
| 762 | } |
| 763 | } |
| 764 | } |
| 765 | } |
| 766 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 767 | @Thunk static Point getDefaultThumbnailSize(Resources res) { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 768 | return new Point(res.getDimensionPixelSize(R.dimen.wallpaperThumbnailWidth), |
| 769 | res.getDimensionPixelSize(R.dimen.wallpaperThumbnailHeight)); |
| 770 | |
| 771 | } |
| 772 | |
Adam Cohen | 091440a | 2015-03-18 14:16:05 -0700 | [diff] [blame] | 773 | @Thunk static Bitmap createThumbnail(Point size, Context context, Uri uri, byte[] imageBytes, |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 774 | Resources res, int resId, int rotation, boolean leftAligned) { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 775 | int width = size.x; |
| 776 | int height = size.y; |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 777 | |
| 778 | BitmapCropTask cropTask; |
| 779 | if (uri != null) { |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 780 | cropTask = new BitmapCropTask( |
| 781 | context, uri, null, rotation, width, height, false, true, null); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 782 | } else if (imageBytes != null) { |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 783 | cropTask = new BitmapCropTask( |
| 784 | imageBytes, null, rotation, width, height, false, true, null); |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 785 | } else { |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 786 | cropTask = new BitmapCropTask( |
| 787 | context, res, resId, null, rotation, width, height, false, true, null); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 788 | } |
| 789 | Point bounds = cropTask.getImageBounds(); |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 790 | if (bounds == null || bounds.x == 0 || bounds.y == 0) { |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 791 | return null; |
| 792 | } |
| 793 | |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 794 | Matrix rotateMatrix = new Matrix(); |
| 795 | rotateMatrix.setRotate(rotation); |
| 796 | float[] rotatedBounds = new float[] { bounds.x, bounds.y }; |
| 797 | rotateMatrix.mapPoints(rotatedBounds); |
| 798 | rotatedBounds[0] = Math.abs(rotatedBounds[0]); |
| 799 | rotatedBounds[1] = Math.abs(rotatedBounds[1]); |
| 800 | |
Sunny Goyal | 06a4d3f | 2015-02-12 11:19:39 -0800 | [diff] [blame] | 801 | RectF cropRect = Utils.getMaxCropRect( |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 802 | (int) rotatedBounds[0], (int) rotatedBounds[1], width, height, leftAligned); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 803 | cropTask.setCropBounds(cropRect); |
| 804 | |
| 805 | if (cropTask.cropBitmap()) { |
| 806 | return cropTask.getCroppedBitmap(); |
| 807 | } else { |
| 808 | return null; |
| 809 | } |
| 810 | } |
| 811 | |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 812 | private void addTemporaryWallpaperTile(final Uri uri, boolean fromRestore) { |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 813 | mTempWallpaperTiles.add(uri); |
| 814 | // Add a tile for the image picked from Gallery |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 815 | final FrameLayout pickedImageThumbnail = (FrameLayout) getLayoutInflater(). |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 816 | inflate(R.layout.wallpaper_picker_item, mWallpapersView, false); |
Michael Jurka | 619a180 | 2013-10-29 15:50:06 +0100 | [diff] [blame] | 817 | pickedImageThumbnail.setVisibility(View.GONE); |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 818 | mWallpapersView.addView(pickedImageThumbnail, 0); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 819 | |
| 820 | // Load the thumbnail |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 821 | final ImageView image = (ImageView) pickedImageThumbnail.findViewById(R.id.wallpaper_image); |
| 822 | final Point defaultSize = getDefaultThumbnailSize(this.getResources()); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 823 | final Context context = getContext(); |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 824 | new AsyncTask<Void, Bitmap, Bitmap>() { |
| 825 | protected Bitmap doInBackground(Void...args) { |
Adam Cohen | 8dc6e1b | 2014-07-24 10:39:57 -0700 | [diff] [blame] | 826 | try { |
Sunny Goyal | 06a4d3f | 2015-02-12 11:19:39 -0800 | [diff] [blame] | 827 | int rotation = BitmapUtils.getRotationFromExif(context, uri); |
Adam Cohen | 8dc6e1b | 2014-07-24 10:39:57 -0700 | [diff] [blame] | 828 | return createThumbnail(defaultSize, context, uri, null, null, 0, rotation, false); |
| 829 | } catch (SecurityException securityException) { |
| 830 | if (isDestroyed()) { |
| 831 | // Temporarily granted permissions are revoked when the activity |
| 832 | // finishes, potentially resulting in a SecurityException here. |
| 833 | // Even though {@link #isDestroyed} might also return true in different |
| 834 | // situations where the configuration changes, we are fine with |
| 835 | // catching these cases here as well. |
| 836 | cancel(false); |
| 837 | } else { |
| 838 | // otherwise it had a different cause and we throw it further |
| 839 | throw securityException; |
| 840 | } |
| 841 | return null; |
| 842 | } |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 843 | } |
| 844 | protected void onPostExecute(Bitmap thumb) { |
Adam Cohen | 8dc6e1b | 2014-07-24 10:39:57 -0700 | [diff] [blame] | 845 | if (!isCancelled() && thumb != null) { |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 846 | image.setImageBitmap(thumb); |
| 847 | Drawable thumbDrawable = image.getDrawable(); |
| 848 | thumbDrawable.setDither(true); |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 849 | pickedImageThumbnail.setVisibility(View.VISIBLE); |
Michael Jurka | 862f7e3 | 2013-10-16 18:23:56 -0700 | [diff] [blame] | 850 | } else { |
| 851 | Log.e(TAG, "Error loading thumbnail for uri=" + uri); |
| 852 | } |
| 853 | } |
| 854 | }.execute(); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 855 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 856 | UriWallpaperInfo info = new UriWallpaperInfo(uri); |
| 857 | pickedImageThumbnail.setTag(info); |
Michael Jurka | 6b783a0 | 2013-10-04 12:26:48 -0700 | [diff] [blame] | 858 | info.setView(pickedImageThumbnail); |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 859 | addLongPressHandler(pickedImageThumbnail); |
Michael Jurka | 7b71549 | 2013-10-09 11:22:34 -0700 | [diff] [blame] | 860 | updateTileIndices(); |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 861 | pickedImageThumbnail.setOnClickListener(mThumbnailOnClickListener); |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 862 | if (!fromRestore) { |
| 863 | mThumbnailOnClickListener.onClick(pickedImageThumbnail); |
| 864 | } |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 865 | } |
| 866 | |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 867 | public void onActivityResult(int requestCode, int resultCode, Intent data) { |
| 868 | if (requestCode == IMAGE_PICK && resultCode == Activity.RESULT_OK) { |
Michael Jurka | 2fe1530 | 2013-10-04 12:35:27 -0700 | [diff] [blame] | 869 | if (data != null && data.getData() != null) { |
| 870 | Uri uri = data.getData(); |
Jorim Jaggi | 1b921ef | 2014-01-14 16:00:17 -0800 | [diff] [blame] | 871 | addTemporaryWallpaperTile(uri, false); |
Michael Jurka | 2fe1530 | 2013-10-04 12:35:27 -0700 | [diff] [blame] | 872 | } |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 873 | } else if (requestCode == PICK_WALLPAPER_THIRD_PARTY_ACTIVITY |
| 874 | && resultCode == Activity.RESULT_OK) { |
Sunny Goyal | fddef46 | 2015-02-12 09:51:48 -0800 | [diff] [blame] | 875 | // Something was set on the third-party activity. |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 876 | setResult(Activity.RESULT_OK); |
Michael Jurka | 2d8de58 | 2013-09-04 14:42:52 +0200 | [diff] [blame] | 877 | finish(); |
| 878 | } |
| 879 | } |
| 880 | |
Michael Jurka | be2f8dd | 2013-09-10 13:39:59 +0200 | [diff] [blame] | 881 | private void addLongPressHandler(View v) { |
| 882 | v.setOnLongClickListener(mLongClickListener); |
| 883 | } |
| 884 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 885 | private ArrayList<WallpaperTileInfo> findBundledWallpapers() { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 886 | final PackageManager pm = getContext().getPackageManager(); |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 887 | final ArrayList<WallpaperTileInfo> bundled = new ArrayList<WallpaperTileInfo>(24); |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 888 | |
| 889 | Partner partner = Partner.get(pm); |
| 890 | if (partner != null) { |
| 891 | final Resources partnerRes = partner.getResources(); |
Adam Cohen | 4ae96ce | 2014-08-29 15:05:48 -0700 | [diff] [blame] | 892 | final int resId = partnerRes.getIdentifier(Partner.RES_WALLPAPERS, "array", |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 893 | partner.getPackageName()); |
| 894 | if (resId != 0) { |
| 895 | addWallpapers(bundled, partnerRes, partner.getPackageName(), resId); |
| 896 | } |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 897 | |
| 898 | // Add system wallpapers |
| 899 | File systemDir = partner.getWallpaperDirectory(); |
| 900 | if (systemDir != null && systemDir.isDirectory()) { |
| 901 | for (File file : systemDir.listFiles()) { |
| 902 | if (!file.isFile()) { |
| 903 | continue; |
| 904 | } |
| 905 | String name = file.getName(); |
| 906 | int dotPos = name.lastIndexOf('.'); |
| 907 | String extension = ""; |
| 908 | if (dotPos >= -1) { |
| 909 | extension = name.substring(dotPos); |
| 910 | name = name.substring(0, dotPos); |
| 911 | } |
| 912 | |
| 913 | if (name.endsWith("_small")) { |
| 914 | // it is a thumbnail |
| 915 | continue; |
| 916 | } |
| 917 | |
| 918 | File thumbnail = new File(systemDir, name + "_small" + extension); |
| 919 | Bitmap thumb = BitmapFactory.decodeFile(thumbnail.getAbsolutePath()); |
| 920 | if (thumb != null) { |
| 921 | bundled.add(new FileWallpaperInfo(file, new BitmapDrawable(thumb))); |
| 922 | } |
| 923 | } |
| 924 | } |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 925 | } |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 926 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 927 | Pair<ApplicationInfo, Integer> r = getWallpaperArrayResourceId(); |
| 928 | if (r != null) { |
| 929 | try { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 930 | Resources wallpaperRes = getContext().getPackageManager() |
| 931 | .getResourcesForApplication(r.first); |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 932 | addWallpapers(bundled, wallpaperRes, r.first.packageName, r.second); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 933 | } catch (PackageManager.NameNotFoundException e) { |
| 934 | } |
| 935 | } |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 936 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 937 | if (partner == null || !partner.hideDefaultWallpaper()) { |
| 938 | // Add an entry for the default wallpaper (stored in system resources) |
| 939 | WallpaperTileInfo defaultWallpaperInfo = |
| 940 | (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) |
| 941 | ? getPreKKDefaultWallpaperInfo() |
| 942 | : getDefaultWallpaper(); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 943 | if (defaultWallpaperInfo != null) { |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 944 | bundled.add(0, defaultWallpaperInfo); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 945 | } |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 946 | } |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 947 | return bundled; |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 948 | } |
| 949 | |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 950 | private boolean writeImageToFileAsJpeg(File f, Bitmap b) { |
| 951 | try { |
| 952 | f.createNewFile(); |
| 953 | FileOutputStream thumbFileStream = |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 954 | getContext().openFileOutput(f.getName(), Context.MODE_PRIVATE); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 955 | b.compress(Bitmap.CompressFormat.JPEG, 95, thumbFileStream); |
| 956 | thumbFileStream.close(); |
| 957 | return true; |
| 958 | } catch (IOException e) { |
| 959 | Log.e(TAG, "Error while writing bitmap to file " + e); |
| 960 | f.delete(); |
| 961 | } |
| 962 | return false; |
| 963 | } |
| 964 | |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 965 | private File getDefaultThumbFile() { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 966 | return new File(getContext().getFilesDir(), Build.VERSION.SDK_INT |
Helena Josol | 28db280 | 2014-10-09 17:04:09 +0100 | [diff] [blame] | 967 | + "_" + LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL); |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 968 | } |
| 969 | |
| 970 | private boolean saveDefaultWallpaperThumb(Bitmap b) { |
| 971 | // Delete old thumbnails. |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 972 | new File(getContext().getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL_OLD).delete(); |
| 973 | new File(getContext().getFilesDir(), LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete(); |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 974 | |
| 975 | for (int i = Build.VERSION_CODES.JELLY_BEAN; i < Build.VERSION.SDK_INT; i++) { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 976 | new File(getContext().getFilesDir(), i + "_" |
| 977 | + LauncherFiles.DEFAULT_WALLPAPER_THUMBNAIL).delete(); |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 978 | } |
| 979 | return writeImageToFileAsJpeg(getDefaultThumbFile(), b); |
| 980 | } |
| 981 | |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 982 | private ResourceWallpaperInfo getPreKKDefaultWallpaperInfo() { |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 983 | Resources sysRes = Resources.getSystem(); |
| 984 | int resId = sysRes.getIdentifier("default_wallpaper", "drawable", "android"); |
| 985 | |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 986 | File defaultThumbFile = getDefaultThumbFile(); |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 987 | Bitmap thumb = null; |
| 988 | boolean defaultWallpaperExists = false; |
| 989 | if (defaultThumbFile.exists()) { |
| 990 | thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath()); |
| 991 | defaultWallpaperExists = true; |
| 992 | } else { |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 993 | Resources res = getResources(); |
| 994 | Point defaultThumbSize = getDefaultThumbnailSize(res); |
Sunny Goyal | 06a4d3f | 2015-02-12 11:19:39 -0800 | [diff] [blame] | 995 | int rotation = BitmapUtils.getRotationFromExif(res, resId); |
Michael Jurka | 8713a94 | 2013-10-10 21:28:40 -0700 | [diff] [blame] | 996 | thumb = createThumbnail( |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 997 | defaultThumbSize, getContext(), null, null, sysRes, resId, rotation, false); |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 998 | if (thumb != null) { |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 999 | defaultWallpaperExists = saveDefaultWallpaperThumb(thumb); |
Michael Jurka | db84e82 | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1000 | } |
| 1001 | } |
| 1002 | if (defaultWallpaperExists) { |
| 1003 | return new ResourceWallpaperInfo(sysRes, resId, new BitmapDrawable(thumb)); |
| 1004 | } |
| 1005 | return null; |
| 1006 | } |
| 1007 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1008 | @TargetApi(Build.VERSION_CODES.KITKAT) |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 1009 | private DefaultWallpaperInfo getDefaultWallpaper() { |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 1010 | File defaultThumbFile = getDefaultThumbFile(); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 1011 | Bitmap thumb = null; |
| 1012 | boolean defaultWallpaperExists = false; |
| 1013 | if (defaultThumbFile.exists()) { |
| 1014 | thumb = BitmapFactory.decodeFile(defaultThumbFile.getAbsolutePath()); |
| 1015 | defaultWallpaperExists = true; |
| 1016 | } else { |
| 1017 | Resources res = getResources(); |
| 1018 | Point defaultThumbSize = getDefaultThumbnailSize(res); |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 1019 | Drawable wallpaperDrawable = WallpaperManager.getInstance(getContext()).getBuiltInDrawable( |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 1020 | defaultThumbSize.x, defaultThumbSize.y, true, 0.5f, 0.5f); |
| 1021 | if (wallpaperDrawable != null) { |
| 1022 | thumb = Bitmap.createBitmap( |
| 1023 | defaultThumbSize.x, defaultThumbSize.y, Bitmap.Config.ARGB_8888); |
| 1024 | Canvas c = new Canvas(thumb); |
Michael Jurka | a7d82b9 | 2013-11-08 15:45:48 +0100 | [diff] [blame] | 1025 | wallpaperDrawable.setBounds(0, 0, defaultThumbSize.x, defaultThumbSize.y); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 1026 | wallpaperDrawable.draw(c); |
| 1027 | c.setBitmap(null); |
| 1028 | } |
| 1029 | if (thumb != null) { |
Sunny Goyal | 0af0d84 | 2014-08-13 12:12:48 -0700 | [diff] [blame] | 1030 | defaultWallpaperExists = saveDefaultWallpaperThumb(thumb); |
Michael Jurka | 12ca613 | 2013-10-15 11:14:44 -0700 | [diff] [blame] | 1031 | } |
| 1032 | } |
| 1033 | if (defaultWallpaperExists) { |
| 1034 | return new DefaultWallpaperInfo(new BitmapDrawable(thumb)); |
| 1035 | } |
| 1036 | return null; |
| 1037 | } |
| 1038 | |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 1039 | public Pair<ApplicationInfo, Integer> getWallpaperArrayResourceId() { |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1040 | // Context.getPackageName() may return the "original" package name, |
| 1041 | // com.android.launcher3; Resources needs the real package name, |
| 1042 | // com.android.launcher3. So we ask Resources for what it thinks the |
| 1043 | // package name should be. |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 1044 | final String packageName = getResources().getResourcePackageName(R.array.wallpapers); |
| 1045 | try { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 1046 | ApplicationInfo info = getContext().getPackageManager().getApplicationInfo(packageName, 0); |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 1047 | return new Pair<ApplicationInfo, Integer>(info, R.array.wallpapers); |
| 1048 | } catch (PackageManager.NameNotFoundException e) { |
| 1049 | return null; |
| 1050 | } |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1051 | } |
| 1052 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1053 | private void addWallpapers(ArrayList<WallpaperTileInfo> known, Resources res, |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 1054 | String packageName, int listResId) { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1055 | final String[] extras = res.getStringArray(listResId); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1056 | for (String extra : extras) { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1057 | int resId = res.getIdentifier(extra, "drawable", packageName); |
| 1058 | if (resId != 0) { |
| 1059 | final int thumbRes = res.getIdentifier(extra + "_small", "drawable", packageName); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1060 | |
| 1061 | if (thumbRes != 0) { |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1062 | ResourceWallpaperInfo wallpaperInfo = |
| 1063 | new ResourceWallpaperInfo(res, resId, res.getDrawable(thumbRes)); |
Jeff Sharkey | 5aeef58 | 2014-04-14 13:26:42 -0700 | [diff] [blame] | 1064 | known.add(wallpaperInfo); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1065 | // Log.d(TAG, "add: [" + packageName + "]: " + extra + " (" + res + ")"); |
| 1066 | } |
Michael Jurka | 6218e5b | 2013-09-10 14:07:20 +0200 | [diff] [blame] | 1067 | } else { |
| 1068 | Log.e(TAG, "Couldn't find wallpaper " + extra); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1069 | } |
| 1070 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1071 | } |
| 1072 | |
| 1073 | public CropView getCropView() { |
| 1074 | return mCropView; |
| 1075 | } |
| 1076 | |
| 1077 | public SavedWallpaperImages getSavedImages() { |
| 1078 | return mSavedImages; |
| 1079 | } |
| 1080 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1081 | private static class SimpleWallpapersAdapter extends ArrayAdapter<WallpaperTileInfo> { |
| 1082 | private final LayoutInflater mLayoutInflater; |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1083 | |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 1084 | SimpleWallpapersAdapter(Context context, ArrayList<WallpaperTileInfo> wallpapers) { |
| 1085 | super(context, R.layout.wallpaper_picker_item, wallpapers); |
| 1086 | mLayoutInflater = LayoutInflater.from(context); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
| 1089 | public View getView(int position, View convertView, ViewGroup parent) { |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1090 | Drawable thumb = getItem(position).mThumb; |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1091 | if (thumb == null) { |
Michael Jurka | eadbfc5 | 2013-09-04 00:45:37 +0200 | [diff] [blame] | 1092 | Log.e(TAG, "Error decoding thumbnail for wallpaper #" + position); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1093 | } |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1094 | return createImageTileView(mLayoutInflater, convertView, parent, thumb); |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1095 | } |
| 1096 | } |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1097 | |
Sunny Goyal | cdc4dbd | 2014-07-16 16:04:08 -0700 | [diff] [blame] | 1098 | public static View createImageTileView(LayoutInflater layoutInflater, |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1099 | View convertView, ViewGroup parent, Drawable thumb) { |
| 1100 | View view; |
| 1101 | |
| 1102 | if (convertView == null) { |
| 1103 | view = layoutInflater.inflate(R.layout.wallpaper_picker_item, parent, false); |
| 1104 | } else { |
| 1105 | view = convertView; |
| 1106 | } |
| 1107 | |
Michael Jurka | 1e4e6dd | 2013-09-23 23:02:05 +0100 | [diff] [blame] | 1108 | ImageView image = (ImageView) view.findViewById(R.id.wallpaper_image); |
| 1109 | |
| 1110 | if (thumb != null) { |
| 1111 | image.setImageDrawable(thumb); |
| 1112 | thumb.setDither(true); |
| 1113 | } |
| 1114 | |
| 1115 | return view; |
| 1116 | } |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 1117 | |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 1118 | public void startActivityForResultSafely(Intent intent, int requestCode) { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 1119 | Utilities.startActivityForResultSafely(getActivity(), intent, requestCode); |
Sunny Goyal | 6a1e95a | 2015-03-20 17:26:30 -0700 | [diff] [blame] | 1120 | } |
| 1121 | |
| 1122 | @Override |
| 1123 | public boolean enableRotation() { |
Sunny Goyal | 1d0b093 | 2015-03-20 18:51:38 -0700 | [diff] [blame^] | 1124 | return Utilities.isRotationEnabled(getContext()); |
Michael Jurka | 7ad868b | 2013-12-12 15:04:25 +0100 | [diff] [blame] | 1125 | } |
Michael Jurka | 104c456 | 2013-07-08 18:03:46 -0700 | [diff] [blame] | 1126 | } |