Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2011 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.launcher2; |
| 18 | |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 19 | import android.animation.AnimatorSet; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 20 | import android.animation.ObjectAnimator; |
Winson Chung | d2e87b3 | 2011-06-02 10:53:07 -0700 | [diff] [blame] | 21 | import android.animation.ValueAnimator; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 22 | import android.appwidget.AppWidgetManager; |
| 23 | import android.appwidget.AppWidgetProviderInfo; |
| 24 | import android.content.ComponentName; |
| 25 | import android.content.Context; |
| 26 | import android.content.Intent; |
Winson Chung | 46af2e8 | 2011-05-09 16:00:53 -0700 | [diff] [blame] | 27 | import android.content.pm.ActivityInfo; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 28 | import android.content.pm.PackageManager; |
| 29 | import android.content.pm.ResolveInfo; |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 30 | import android.content.res.Configuration; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 31 | import android.content.res.Resources; |
| 32 | import android.content.res.TypedArray; |
| 33 | import android.graphics.Bitmap; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 34 | import android.graphics.Canvas; |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 35 | import android.graphics.MaskFilter; |
| 36 | import android.graphics.Paint; |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 37 | import android.graphics.PorterDuff; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 38 | import android.graphics.Rect; |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 39 | import android.graphics.RectF; |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 40 | import android.graphics.Bitmap.Config; |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 41 | import android.graphics.TableMaskFilter; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 42 | import android.graphics.drawable.Drawable; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 43 | import android.os.AsyncTask; |
| 44 | import android.os.Process; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 45 | import android.util.AttributeSet; |
| 46 | import android.util.Log; |
Winson Chung | 72d8b39 | 2011-07-29 13:56:44 -0700 | [diff] [blame] | 47 | import android.view.Gravity; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 48 | import android.view.LayoutInflater; |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 49 | import android.view.MotionEvent; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 50 | import android.view.View; |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 51 | import android.view.ViewGroup; |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 52 | import android.view.animation.AccelerateInterpolator; |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 53 | import android.view.animation.DecelerateInterpolator; |
| 54 | import android.view.animation.Interpolator; |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 55 | import android.widget.GridLayout; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 56 | import android.widget.ImageView; |
Winson Chung | 55b6550 | 2011-05-26 12:03:43 -0700 | [diff] [blame] | 57 | import android.widget.Toast; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 58 | |
| 59 | import com.android.launcher.R; |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 60 | import com.android.launcher2.DropTarget.DragObject; |
| 61 | |
| 62 | import java.util.ArrayList; |
| 63 | import java.util.Collections; |
| 64 | import java.util.Iterator; |
| 65 | import java.util.List; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 66 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 67 | /** |
| 68 | * A simple callback interface which also provides the results of the task. |
| 69 | */ |
| 70 | interface AsyncTaskCallback { |
| 71 | void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data); |
| 72 | } |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 73 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 74 | /** |
| 75 | * The data needed to perform either of the custom AsyncTasks. |
| 76 | */ |
| 77 | class AsyncTaskPageData { |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 78 | enum Type { |
| 79 | LoadWidgetPreviewData, |
| 80 | LoadHolographicIconsData |
| 81 | } |
| 82 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 83 | AsyncTaskPageData(int p, ArrayList<Object> l, ArrayList<Bitmap> si, AsyncTaskCallback bgR, |
| 84 | AsyncTaskCallback postR) { |
| 85 | page = p; |
| 86 | items = l; |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 87 | sourceImages = si; |
| 88 | generatedImages = new ArrayList<Bitmap>(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 89 | cellWidth = cellHeight = -1; |
| 90 | doInBackgroundCallback = bgR; |
| 91 | postExecuteCallback = postR; |
| 92 | } |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 93 | AsyncTaskPageData(int p, ArrayList<Object> l, int cw, int ch, int ccx, AsyncTaskCallback bgR, |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 94 | AsyncTaskCallback postR) { |
| 95 | page = p; |
| 96 | items = l; |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 97 | generatedImages = new ArrayList<Bitmap>(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 98 | cellWidth = cw; |
| 99 | cellHeight = ch; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 100 | cellCountX = ccx; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 101 | doInBackgroundCallback = bgR; |
| 102 | postExecuteCallback = postR; |
| 103 | } |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 104 | void cleanup(boolean cancelled) { |
| 105 | // Clean up any references to source/generated bitmaps |
| 106 | if (sourceImages != null) { |
| 107 | if (cancelled) { |
| 108 | for (Bitmap b : sourceImages) { |
| 109 | b.recycle(); |
| 110 | } |
| 111 | } |
| 112 | sourceImages.clear(); |
| 113 | } |
| 114 | if (generatedImages != null) { |
| 115 | if (cancelled) { |
| 116 | for (Bitmap b : generatedImages) { |
| 117 | b.recycle(); |
| 118 | } |
| 119 | } |
| 120 | generatedImages.clear(); |
| 121 | } |
| 122 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 123 | int page; |
| 124 | ArrayList<Object> items; |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 125 | ArrayList<Bitmap> sourceImages; |
| 126 | ArrayList<Bitmap> generatedImages; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 127 | int cellWidth; |
| 128 | int cellHeight; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 129 | int cellCountX; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 130 | AsyncTaskCallback doInBackgroundCallback; |
| 131 | AsyncTaskCallback postExecuteCallback; |
| 132 | } |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 133 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 134 | /** |
| 135 | * A generic template for an async task used in AppsCustomize. |
| 136 | */ |
| 137 | class AppsCustomizeAsyncTask extends AsyncTask<AsyncTaskPageData, Void, AsyncTaskPageData> { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 138 | AppsCustomizeAsyncTask(int p, AsyncTaskPageData.Type ty) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 139 | page = p; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 140 | threadPriority = Process.THREAD_PRIORITY_DEFAULT; |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 141 | dataType = ty; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 142 | } |
| 143 | @Override |
| 144 | protected AsyncTaskPageData doInBackground(AsyncTaskPageData... params) { |
| 145 | if (params.length != 1) return null; |
| 146 | // Load each of the widget previews in the background |
| 147 | params[0].doInBackgroundCallback.run(this, params[0]); |
| 148 | return params[0]; |
| 149 | } |
| 150 | @Override |
| 151 | protected void onPostExecute(AsyncTaskPageData result) { |
| 152 | // All the widget previews are loaded, so we can just callback to inflate the page |
| 153 | result.postExecuteCallback.run(this, result); |
| 154 | } |
| 155 | |
| 156 | void setThreadPriority(int p) { |
| 157 | threadPriority = p; |
| 158 | } |
| 159 | void syncThreadPriority() { |
| 160 | Process.setThreadPriority(threadPriority); |
| 161 | } |
| 162 | |
| 163 | // The page that this async task is associated with |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 164 | AsyncTaskPageData.Type dataType; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 165 | int page; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 166 | int threadPriority; |
| 167 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 168 | |
| 169 | /** |
| 170 | * The Apps/Customize page that displays all the applications, widgets, and shortcuts. |
| 171 | */ |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 172 | public class AppsCustomizePagedView extends PagedViewWithDraggableItems implements |
| 173 | AllAppsView, View.OnClickListener, DragSource { |
| 174 | static final String LOG_TAG = "AppsCustomizePagedView"; |
| 175 | |
| 176 | /** |
| 177 | * The different content types that this paged view can show. |
| 178 | */ |
| 179 | public enum ContentType { |
| 180 | Applications, |
Winson Chung | 6a26e5b | 2011-05-26 14:36:06 -0700 | [diff] [blame] | 181 | Widgets |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 182 | } |
| 183 | |
| 184 | // Refs |
| 185 | private Launcher mLauncher; |
| 186 | private DragController mDragController; |
| 187 | private final LayoutInflater mLayoutInflater; |
| 188 | private final PackageManager mPackageManager; |
| 189 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 190 | // Save and Restore |
| 191 | private int mSaveInstanceStateItemIndex = -1; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 192 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 193 | // Content |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 194 | private ArrayList<ApplicationInfo> mApps; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 195 | private ArrayList<Object> mWidgets; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 196 | |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 197 | // Cling |
| 198 | private int mClingFocusedX; |
| 199 | private int mClingFocusedY; |
| 200 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 201 | // Caching |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 202 | private Canvas mCanvas; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 203 | private Drawable mDefaultWidgetBackground; |
Winson Chung | 4dbea79 | 2011-05-05 14:21:32 -0700 | [diff] [blame] | 204 | private IconCache mIconCache; |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 205 | private int mDragViewMultiplyColor; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 206 | |
| 207 | // Dimens |
| 208 | private int mContentWidth; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 209 | private int mAppIconSize; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 210 | private int mWidgetCountX, mWidgetCountY; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 211 | private int mWidgetWidthGap, mWidgetHeightGap; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 212 | private final int mWidgetPreviewIconPaddedDimension; |
| 213 | private final float sWidgetPreviewIconPaddingPercentage = 0.25f; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 214 | private PagedViewCellLayout mWidgetSpacingLayout; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 215 | private int mNumAppsPages; |
| 216 | private int mNumWidgetPages; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 217 | |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 218 | // Relating to the scroll and overscroll effects |
| 219 | Workspace.ZInterpolator mZInterpolator = new Workspace.ZInterpolator(0.5f); |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 220 | private static float CAMERA_DISTANCE = 6500; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 221 | private static float TRANSITION_SCALE_FACTOR = 0.74f; |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 222 | private static float TRANSITION_PIVOT = 0.65f; |
| 223 | private static float TRANSITION_MAX_ROTATION = 22; |
| 224 | private static final boolean PERFORM_OVERSCROLL_ROTATION = true; |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 225 | private AccelerateInterpolator mAlphaInterpolator = new AccelerateInterpolator(0.9f); |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 226 | private DecelerateInterpolator mLeftScreenAlphaInterpolator = new DecelerateInterpolator(4); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 227 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 228 | // Previews & outlines |
| 229 | ArrayList<AppsCustomizeAsyncTask> mRunningTasks; |
| 230 | private HolographicOutlineHelper mHolographicOutlineHelper; |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 231 | private static final int sPageSleepDelay = 150; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 232 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 233 | public AppsCustomizePagedView(Context context, AttributeSet attrs) { |
| 234 | super(context, attrs); |
| 235 | mLayoutInflater = LayoutInflater.from(context); |
| 236 | mPackageManager = context.getPackageManager(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 237 | mApps = new ArrayList<ApplicationInfo>(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 238 | mWidgets = new ArrayList<Object>(); |
Winson Chung | 4dbea79 | 2011-05-05 14:21:32 -0700 | [diff] [blame] | 239 | mIconCache = ((LauncherApplication) context.getApplicationContext()).getIconCache(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 240 | mHolographicOutlineHelper = new HolographicOutlineHelper(); |
| 241 | mCanvas = new Canvas(); |
| 242 | mRunningTasks = new ArrayList<AppsCustomizeAsyncTask>(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 243 | |
| 244 | // Save the default widget preview background |
| 245 | Resources resources = context.getResources(); |
Winson Chung | 967289b | 2011-06-30 18:09:30 -0700 | [diff] [blame] | 246 | mDefaultWidgetBackground = resources.getDrawable(R.drawable.default_widget_preview_holo); |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 247 | mAppIconSize = resources.getDimensionPixelSize(R.dimen.app_icon_size); |
| 248 | mDragViewMultiplyColor = resources.getColor(R.color.drag_view_multiply_color); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 249 | |
| 250 | TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, 0, 0); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 251 | // TODO-APPS_CUSTOMIZE: remove these unnecessary attrs after |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 252 | mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 6); |
| 253 | mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); |
| 254 | a.recycle(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 255 | a = context.obtainStyledAttributes(attrs, R.styleable.AppsCustomizePagedView, 0, 0); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 256 | mWidgetWidthGap = |
| 257 | a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellWidthGap, 0); |
| 258 | mWidgetHeightGap = |
| 259 | a.getDimensionPixelSize(R.styleable.AppsCustomizePagedView_widgetCellHeightGap, 0); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 260 | mWidgetCountX = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountX, 2); |
| 261 | mWidgetCountY = a.getInt(R.styleable.AppsCustomizePagedView_widgetCountY, 2); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 262 | mClingFocusedX = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedX, 0); |
| 263 | mClingFocusedY = a.getInt(R.styleable.AppsCustomizePagedView_clingFocusedY, 0); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 264 | a.recycle(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 265 | mWidgetSpacingLayout = new PagedViewCellLayout(getContext()); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 266 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 267 | // The padding on the non-matched dimension for the default widget preview icons |
| 268 | // (top + bottom) |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 269 | mWidgetPreviewIconPaddedDimension = |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 270 | (int) (mAppIconSize * (1 + (2 * sWidgetPreviewIconPaddingPercentage))); |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 271 | mFadeInAdjacentScreens = false; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 272 | } |
| 273 | |
| 274 | @Override |
| 275 | protected void init() { |
| 276 | super.init(); |
Winson Chung | 6a87740 | 2011-10-26 14:51:44 -0700 | [diff] [blame] | 277 | mCenterPagesVertically = false; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 278 | |
| 279 | Context context = getContext(); |
| 280 | Resources r = context.getResources(); |
| 281 | setDragSlopeThreshold(r.getInteger(R.integer.config_appsCustomizeDragSlopeThreshold)/100f); |
| 282 | } |
| 283 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 284 | @Override |
Michael Jurka | d771c96 | 2011-08-09 15:00:48 -0700 | [diff] [blame] | 285 | protected void onUnhandledTap(MotionEvent ev) { |
| 286 | if (LauncherApplication.isScreenLarge()) { |
Winson Chung | de1af76 | 2011-07-21 16:44:07 -0700 | [diff] [blame] | 287 | // Dismiss AppsCustomize if we tap |
| 288 | mLauncher.showWorkspace(true); |
| 289 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 292 | /** Returns the item index of the center item on this page so that we can restore to this |
| 293 | * item index when we rotate. */ |
| 294 | private int getMiddleComponentIndexOnCurrentPage() { |
| 295 | int i = -1; |
| 296 | if (getPageCount() > 0) { |
| 297 | int currentPage = getCurrentPage(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 298 | if (currentPage < mNumAppsPages) { |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 299 | PagedViewCellLayout layout = (PagedViewCellLayout) getPageAt(currentPage); |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 300 | PagedViewCellLayoutChildren childrenLayout = layout.getChildrenLayout(); |
| 301 | int numItemsPerPage = mCellCountX * mCellCountY; |
| 302 | int childCount = childrenLayout.getChildCount(); |
| 303 | if (childCount > 0) { |
| 304 | i = (currentPage * numItemsPerPage) + (childCount / 2); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 305 | } |
| 306 | } else { |
| 307 | int numApps = mApps.size(); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 308 | PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(currentPage); |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 309 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
| 310 | int childCount = layout.getChildCount(); |
| 311 | if (childCount > 0) { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 312 | i = numApps + |
| 313 | ((currentPage - mNumAppsPages) * numItemsPerPage) + (childCount / 2); |
| 314 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 315 | } |
| 316 | } |
| 317 | return i; |
| 318 | } |
| 319 | |
| 320 | /** Get the index of the item to restore to if we need to restore the current page. */ |
| 321 | int getSaveInstanceStateIndex() { |
| 322 | if (mSaveInstanceStateItemIndex == -1) { |
| 323 | mSaveInstanceStateItemIndex = getMiddleComponentIndexOnCurrentPage(); |
| 324 | } |
| 325 | return mSaveInstanceStateItemIndex; |
| 326 | } |
| 327 | |
| 328 | /** Returns the page in the current orientation which is expected to contain the specified |
| 329 | * item index. */ |
| 330 | int getPageForComponent(int index) { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 331 | if (index < 0) return 0; |
| 332 | |
| 333 | if (index < mApps.size()) { |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 334 | int numItemsPerPage = mCellCountX * mCellCountY; |
| 335 | return (index / numItemsPerPage); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 336 | } else { |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 337 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 338 | return mNumAppsPages + ((index - mApps.size()) / numItemsPerPage); |
| 339 | } |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 342 | /** |
| 343 | * This differs from isDataReady as this is the test done if isDataReady is not set. |
| 344 | */ |
| 345 | private boolean testDataReady() { |
Winson Chung | fd3385f | 2011-06-15 19:51:24 -0700 | [diff] [blame] | 346 | // We only do this test once, and we default to the Applications page, so we only really |
| 347 | // have to wait for there to be apps. |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 348 | // TODO: What if one of them is validly empty |
| 349 | return !mApps.isEmpty() && !mWidgets.isEmpty(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 350 | } |
| 351 | |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 352 | /** Restores the page for an item at the specified index */ |
| 353 | void restorePageForIndex(int index) { |
| 354 | if (index < 0) return; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 355 | mSaveInstanceStateItemIndex = index; |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 356 | } |
| 357 | |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 358 | private void updatePageCounts() { |
| 359 | mNumWidgetPages = (int) Math.ceil(mWidgets.size() / |
| 360 | (float) (mWidgetCountX * mWidgetCountY)); |
| 361 | mNumAppsPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); |
| 362 | } |
| 363 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 364 | protected void onDataReady(int width, int height) { |
| 365 | // Note that we transpose the counts in portrait so that we get a similar layout |
| 366 | boolean isLandscape = getResources().getConfiguration().orientation == |
| 367 | Configuration.ORIENTATION_LANDSCAPE; |
| 368 | int maxCellCountX = Integer.MAX_VALUE; |
| 369 | int maxCellCountY = Integer.MAX_VALUE; |
| 370 | if (LauncherApplication.isScreenLarge()) { |
| 371 | maxCellCountX = (isLandscape ? LauncherModel.getCellCountX() : |
| 372 | LauncherModel.getCellCountY()); |
| 373 | maxCellCountY = (isLandscape ? LauncherModel.getCellCountY() : |
| 374 | LauncherModel.getCellCountX()); |
| 375 | } |
| 376 | |
| 377 | // Now that the data is ready, we can calculate the content width, the number of cells to |
| 378 | // use for each page |
| 379 | mWidgetSpacingLayout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); |
| 380 | mWidgetSpacingLayout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, |
| 381 | mPageLayoutPaddingRight, mPageLayoutPaddingBottom); |
| 382 | mWidgetSpacingLayout.calculateCellCount(width, height, maxCellCountX, maxCellCountY); |
| 383 | mCellCountX = mWidgetSpacingLayout.getCellCountX(); |
| 384 | mCellCountY = mWidgetSpacingLayout.getCellCountY(); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 385 | updatePageCounts(); |
Winson Chung | 5a80835 | 2011-06-27 19:08:49 -0700 | [diff] [blame] | 386 | |
Winson Chung | db1138b | 2011-06-30 14:39:35 -0700 | [diff] [blame] | 387 | // Force a measure to update recalculate the gaps |
| 388 | int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); |
| 389 | int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST); |
| 390 | mWidgetSpacingLayout.measure(widthSpec, heightSpec); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 391 | mContentWidth = mWidgetSpacingLayout.getContentWidth(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 392 | |
| 393 | // Restore the page |
| 394 | int page = getPageForComponent(mSaveInstanceStateItemIndex); |
| 395 | invalidatePageData(Math.max(0, page)); |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 396 | |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 397 | // Calculate the position for the cling punch through |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 398 | int[] offset = new int[2]; |
| 399 | int[] pos = mWidgetSpacingLayout.estimateCellPosition(mClingFocusedX, mClingFocusedY); |
| 400 | mLauncher.getDragLayer().getLocationInDragLayer(this, offset); |
| 401 | pos[0] += (getMeasuredWidth() - mWidgetSpacingLayout.getMeasuredWidth()) / 2 + offset[0]; |
| 402 | pos[1] += (getMeasuredHeight() - mWidgetSpacingLayout.getMeasuredHeight()) / 2 + offset[1]; |
| 403 | mLauncher.showFirstRunAllAppsCling(pos); |
| 404 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 405 | } |
| 406 | |
| 407 | @Override |
| 408 | protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
| 409 | int width = MeasureSpec.getSize(widthMeasureSpec); |
| 410 | int height = MeasureSpec.getSize(heightMeasureSpec); |
| 411 | if (!isDataReady()) { |
| 412 | if (testDataReady()) { |
| 413 | setDataIsReady(); |
| 414 | setMeasuredDimension(width, height); |
| 415 | onDataReady(width, height); |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
| 420 | } |
| 421 | |
Winson Chung | 34efdaf | 2011-05-24 14:19:56 -0700 | [diff] [blame] | 422 | /** Removes and returns the ResolveInfo with the specified ComponentName */ |
| 423 | private ResolveInfo removeResolveInfoWithComponentName(List<ResolveInfo> list, |
| 424 | ComponentName cn) { |
| 425 | Iterator<ResolveInfo> iter = list.iterator(); |
| 426 | while (iter.hasNext()) { |
| 427 | ResolveInfo rinfo = iter.next(); |
| 428 | ActivityInfo info = rinfo.activityInfo; |
| 429 | ComponentName c = new ComponentName(info.packageName, info.name); |
| 430 | if (c.equals(cn)) { |
| 431 | iter.remove(); |
| 432 | return rinfo; |
| 433 | } |
| 434 | } |
| 435 | return null; |
| 436 | } |
| 437 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 438 | public void onPackagesUpdated() { |
Adam Cohen | b0fa352 | 2011-08-17 16:10:46 -0700 | [diff] [blame] | 439 | // TODO: this isn't ideal, but we actually need to delay here. This call is triggered |
| 440 | // by a broadcast receiver, and in order for it to work correctly, we need to know that |
| 441 | // the AppWidgetService has already received and processed the same broadcast. Since there |
| 442 | // is no guarantee about ordering of broadcast receipt, we just delay here. Ideally, |
| 443 | // we should have a more precise way of ensuring the AppWidgetService is up to date. |
| 444 | postDelayed(new Runnable() { |
| 445 | public void run() { |
| 446 | updatePackages(); |
| 447 | } |
| 448 | }, 500); |
| 449 | } |
| 450 | |
| 451 | public void updatePackages() { |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 452 | // Get the list of widgets and shortcuts |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 453 | boolean wasEmpty = mWidgets.isEmpty(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 454 | mWidgets.clear(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 455 | List<AppWidgetProviderInfo> widgets = |
| 456 | AppWidgetManager.getInstance(mLauncher).getInstalledProviders(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 457 | Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 458 | List<ResolveInfo> shortcuts = mPackageManager.queryIntentActivities(shortcutsIntent, 0); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 459 | mWidgets.addAll(widgets); |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 460 | mWidgets.addAll(shortcuts); |
| 461 | Collections.sort(mWidgets, |
| 462 | new LauncherModel.WidgetAndShortcutNameComparator(mPackageManager)); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 463 | updatePageCounts(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 464 | |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 465 | if (wasEmpty) { |
| 466 | // The next layout pass will trigger data-ready if both widgets and apps are set, so request |
| 467 | // a layout to do this test and invalidate the page data when ready. |
| 468 | if (testDataReady()) requestLayout(); |
| 469 | } else { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 470 | cancelAllTasks(); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 471 | invalidatePageData(); |
| 472 | } |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | @Override |
| 476 | public void onClick(View v) { |
Adam Cohen | fc53cd2 | 2011-07-20 15:45:11 -0700 | [diff] [blame] | 477 | // When we have exited all apps or are in transition, disregard clicks |
| 478 | if (!mLauncher.isAllAppsCustomizeOpen() || |
| 479 | mLauncher.getWorkspace().isSwitchingState()) return; |
| 480 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 481 | if (v instanceof PagedViewIcon) { |
| 482 | // Animate some feedback to the click |
| 483 | final ApplicationInfo appInfo = (ApplicationInfo) v.getTag(); |
| 484 | animateClickFeedback(v, new Runnable() { |
| 485 | @Override |
| 486 | public void run() { |
| 487 | mLauncher.startActivitySafely(appInfo.intent, appInfo); |
| 488 | } |
| 489 | }); |
| 490 | } else if (v instanceof PagedViewWidget) { |
Winson Chung | d2e87b3 | 2011-06-02 10:53:07 -0700 | [diff] [blame] | 491 | // Let the user know that they have to long press to add a widget |
| 492 | Toast.makeText(getContext(), R.string.long_press_widget_to_add, |
| 493 | Toast.LENGTH_SHORT).show(); |
Winson Chung | 46af2e8 | 2011-05-09 16:00:53 -0700 | [diff] [blame] | 494 | |
Winson Chung | d2e87b3 | 2011-06-02 10:53:07 -0700 | [diff] [blame] | 495 | // Create a little animation to show that the widget can move |
| 496 | float offsetY = getResources().getDimensionPixelSize(R.dimen.dragViewOffsetY); |
| 497 | final ImageView p = (ImageView) v.findViewById(R.id.widget_preview); |
| 498 | AnimatorSet bounce = new AnimatorSet(); |
| 499 | ValueAnimator tyuAnim = ObjectAnimator.ofFloat(p, "translationY", offsetY); |
| 500 | tyuAnim.setDuration(125); |
| 501 | ValueAnimator tydAnim = ObjectAnimator.ofFloat(p, "translationY", 0f); |
| 502 | tydAnim.setDuration(100); |
| 503 | bounce.play(tyuAnim).before(tydAnim); |
| 504 | bounce.setInterpolator(new AccelerateInterpolator()); |
| 505 | bounce.start(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 506 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 507 | } |
| 508 | |
| 509 | /* |
| 510 | * PagedViewWithDraggableItems implementation |
| 511 | */ |
| 512 | @Override |
| 513 | protected void determineDraggingStart(android.view.MotionEvent ev) { |
| 514 | // Disable dragging by pulling an app down for now. |
| 515 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 516 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 517 | private void beginDraggingApplication(View v) { |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 518 | mLauncher.getWorkspace().onDragStartedWithItem(v); |
| 519 | mLauncher.getWorkspace().beginDragShared(v, this); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 520 | } |
Adam Cohen | ac8c876 | 2011-07-13 11:15:27 -0700 | [diff] [blame] | 521 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 522 | private void beginDraggingWidget(View v) { |
| 523 | // Get the widget preview as the drag representation |
| 524 | ImageView image = (ImageView) v.findViewById(R.id.widget_preview); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 525 | PendingAddItemInfo createItemInfo = (PendingAddItemInfo) v.getTag(); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 526 | |
| 527 | // Compose the drag image |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 528 | Bitmap b; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 529 | Drawable preview = image.getDrawable(); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 530 | RectF mTmpScaleRect = new RectF(0f,0f,1f,1f); |
| 531 | image.getImageMatrix().mapRect(mTmpScaleRect); |
| 532 | float scale = mTmpScaleRect.right; |
| 533 | int w = (int) (preview.getIntrinsicWidth() * scale); |
| 534 | int h = (int) (preview.getIntrinsicHeight() * scale); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 535 | if (createItemInfo instanceof PendingAddWidgetInfo) { |
| 536 | PendingAddWidgetInfo createWidgetInfo = (PendingAddWidgetInfo) createItemInfo; |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 537 | int[] spanXY = mLauncher.getSpanForWidget(createWidgetInfo, null); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 538 | createItemInfo.spanX = spanXY[0]; |
| 539 | createItemInfo.spanY = spanXY[1]; |
| 540 | |
| 541 | b = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 542 | renderDrawableToBitmap(preview, b, 0, 0, w, h, scale, mDragViewMultiplyColor); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 543 | } else { |
| 544 | // Workaround for the fact that we don't keep the original ResolveInfo associated with |
| 545 | // the shortcut around. To get the icon, we just render the preview image (which has |
| 546 | // the shortcut icon) to a new drag bitmap that clips the non-icon space. |
| 547 | b = Bitmap.createBitmap(mWidgetPreviewIconPaddedDimension, |
| 548 | mWidgetPreviewIconPaddedDimension, Bitmap.Config.ARGB_8888); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 549 | mCanvas.setBitmap(b); |
| 550 | mCanvas.save(); |
| 551 | preview.draw(mCanvas); |
| 552 | mCanvas.restore(); |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 553 | mCanvas.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY); |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 554 | mCanvas.setBitmap(null); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 555 | createItemInfo.spanX = createItemInfo.spanY = 1; |
| 556 | } |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 557 | |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 558 | // We use a custom alpha clip table for the default widget previews |
| 559 | Paint alphaClipPaint = null; |
| 560 | if (createItemInfo instanceof PendingAddWidgetInfo) { |
| 561 | if (((PendingAddWidgetInfo) createItemInfo).hasDefaultPreview) { |
| 562 | MaskFilter alphaClipTable = TableMaskFilter.CreateClipTable(0, 255); |
| 563 | alphaClipPaint = new Paint(); |
| 564 | alphaClipPaint.setMaskFilter(alphaClipTable); |
| 565 | } |
| 566 | } |
| 567 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 568 | // Start the drag |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 569 | mLauncher.lockScreenOrientationOnLargeUI(); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 570 | mLauncher.getWorkspace().onDragStartedWithItemSpans(createItemInfo.spanX, |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 571 | createItemInfo.spanY, b, alphaClipPaint); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 572 | mDragController.startDrag(image, b, this, createItemInfo, |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 573 | DragController.DRAG_ACTION_COPY, null); |
| 574 | b.recycle(); |
| 575 | } |
| 576 | @Override |
| 577 | protected boolean beginDragging(View v) { |
Winson Chung | 7d7541e | 2011-09-16 20:14:36 -0700 | [diff] [blame] | 578 | // Dismiss the cling |
| 579 | mLauncher.dismissAllAppsCling(null); |
| 580 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 581 | if (!super.beginDragging(v)) return false; |
| 582 | |
Winson Chung | c07918d | 2011-07-01 15:35:26 -0700 | [diff] [blame] | 583 | // Go into spring loaded mode (must happen before we startDrag()) |
Adam Cohen | 7777d96 | 2011-08-18 18:58:38 -0700 | [diff] [blame] | 584 | mLauncher.enterSpringLoadedDragMode(); |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 585 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 586 | if (v instanceof PagedViewIcon) { |
| 587 | beginDraggingApplication(v); |
| 588 | } else if (v instanceof PagedViewWidget) { |
| 589 | beginDraggingWidget(v); |
| 590 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 591 | return true; |
| 592 | } |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 593 | private void endDragging(View target, boolean success) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 594 | mLauncher.getWorkspace().onDragStopped(success); |
Adam Cohen | d4d7aa5 | 2011-07-19 21:47:37 -0700 | [diff] [blame] | 595 | if (!success || (target != mLauncher.getWorkspace() && |
| 596 | !(target instanceof DeleteDropTarget))) { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 597 | // Exit spring loaded mode if we have not successfully dropped or have not handled the |
| 598 | // drop in Workspace |
| 599 | mLauncher.exitSpringLoadedDragMode(); |
| 600 | } |
Adam Cohen | 446e940 | 2011-09-15 18:21:21 -0700 | [diff] [blame] | 601 | mLauncher.unlockScreenOrientationOnLargeUI(); |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 602 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 603 | } |
| 604 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 605 | @Override |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 606 | public void onDropCompleted(View target, DragObject d, boolean success) { |
Winson Chung | 557d6ed | 2011-07-08 15:34:52 -0700 | [diff] [blame] | 607 | endDragging(target, success); |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 608 | |
| 609 | // Display an error message if the drag failed due to there not being enough space on the |
| 610 | // target layout we were dropping on. |
| 611 | if (!success) { |
| 612 | boolean showOutOfSpaceMessage = false; |
| 613 | if (target instanceof Workspace) { |
| 614 | int currentScreen = mLauncher.getCurrentWorkspaceScreen(); |
| 615 | Workspace workspace = (Workspace) target; |
| 616 | CellLayout layout = (CellLayout) workspace.getChildAt(currentScreen); |
Adam Cohen | c0dcf59 | 2011-06-01 15:30:43 -0700 | [diff] [blame] | 617 | ItemInfo itemInfo = (ItemInfo) d.dragInfo; |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 618 | if (layout != null) { |
| 619 | layout.calculateSpans(itemInfo); |
| 620 | showOutOfSpaceMessage = |
| 621 | !layout.findCellForSpan(null, itemInfo.spanX, itemInfo.spanY); |
| 622 | } |
| 623 | } |
Winson Chung | fc79c80 | 2011-05-02 13:35:34 -0700 | [diff] [blame] | 624 | if (showOutOfSpaceMessage) { |
| 625 | mLauncher.showOutOfSpaceMessage(); |
| 626 | } |
| 627 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 628 | } |
| 629 | |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 630 | @Override |
| 631 | protected void onDetachedFromWindow() { |
| 632 | super.onDetachedFromWindow(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 633 | cancelAllTasks(); |
| 634 | } |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 635 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 636 | private void cancelAllTasks() { |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 637 | // Clean up all the async tasks |
| 638 | Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator(); |
| 639 | while (iter.hasNext()) { |
| 640 | AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next(); |
| 641 | task.cancel(false); |
| 642 | iter.remove(); |
| 643 | } |
| 644 | } |
| 645 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 646 | public void setContentType(ContentType type) { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 647 | if (type == ContentType.Widgets) { |
| 648 | invalidatePageData(mNumAppsPages, true); |
| 649 | } else if (type == ContentType.Applications) { |
| 650 | invalidatePageData(0, true); |
| 651 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 652 | } |
| 653 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 654 | protected void snapToPage(int whichPage, int delta, int duration) { |
| 655 | super.snapToPage(whichPage, delta, duration); |
| 656 | updateCurrentTab(whichPage); |
| 657 | } |
| 658 | |
| 659 | private void updateCurrentTab(int currentPage) { |
| 660 | AppsCustomizeTabHost tabHost = getTabHost(); |
| 661 | String tag = tabHost.getCurrentTabTag(); |
Winson Chung | 6a8103c | 2011-10-21 11:08:32 -0700 | [diff] [blame] | 662 | if (tag != null) { |
| 663 | if (currentPage >= mNumAppsPages && |
| 664 | !tag.equals(tabHost.getTabTagForContentType(ContentType.Widgets))) { |
| 665 | tabHost.setCurrentTabFromContent(ContentType.Widgets); |
| 666 | } else if (currentPage < mNumAppsPages && |
| 667 | !tag.equals(tabHost.getTabTagForContentType(ContentType.Applications))) { |
| 668 | tabHost.setCurrentTabFromContent(ContentType.Applications); |
| 669 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 670 | } |
| 671 | } |
| 672 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 673 | /* |
| 674 | * Apps PagedView implementation |
| 675 | */ |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 676 | private void setVisibilityOnChildren(ViewGroup layout, int visibility) { |
| 677 | int childCount = layout.getChildCount(); |
| 678 | for (int i = 0; i < childCount; ++i) { |
| 679 | layout.getChildAt(i).setVisibility(visibility); |
| 680 | } |
| 681 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 682 | private void setupPage(PagedViewCellLayout layout) { |
| 683 | layout.setCellCount(mCellCountX, mCellCountY); |
| 684 | layout.setGap(mPageLayoutWidthGap, mPageLayoutHeightGap); |
| 685 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, |
| 686 | mPageLayoutPaddingRight, mPageLayoutPaddingBottom); |
| 687 | |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 688 | // Note: We force a measure here to get around the fact that when we do layout calculations |
| 689 | // immediately after syncing, we don't have a proper width. That said, we already know the |
| 690 | // expected page width, so we can actually optimize by hiding all the TextView-based |
| 691 | // children that are expensive to measure, and let that happen naturally later. |
| 692 | setVisibilityOnChildren(layout, View.GONE); |
Winson Chung | db1138b | 2011-06-30 14:39:35 -0700 | [diff] [blame] | 693 | int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 694 | int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST); |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 695 | layout.setMinimumWidth(getPageContentWidth()); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 696 | layout.measure(widthSpec, heightSpec); |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 697 | setVisibilityOnChildren(layout, View.VISIBLE); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 698 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 699 | |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 700 | public void syncAppsPageItems(int page, boolean immediate) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 701 | // ensure that we have the right number of items on the pages |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 702 | int numCells = mCellCountX * mCellCountY; |
| 703 | int startIndex = page * numCells; |
| 704 | int endIndex = Math.min(startIndex + numCells, mApps.size()); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 705 | PagedViewCellLayout layout = (PagedViewCellLayout) getPageAt(page); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 706 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 707 | layout.removeAllViewsOnPage(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 708 | ArrayList<Object> items = new ArrayList<Object>(); |
| 709 | ArrayList<Bitmap> images = new ArrayList<Bitmap>(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 710 | for (int i = startIndex; i < endIndex; ++i) { |
| 711 | ApplicationInfo info = mApps.get(i); |
| 712 | PagedViewIcon icon = (PagedViewIcon) mLayoutInflater.inflate( |
| 713 | R.layout.apps_customize_application, layout, false); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 714 | icon.applyFromApplicationInfo(info, true, mHolographicOutlineHelper); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 715 | icon.setOnClickListener(this); |
| 716 | icon.setOnLongClickListener(this); |
| 717 | icon.setOnTouchListener(this); |
| 718 | |
| 719 | int index = i - startIndex; |
| 720 | int x = index % mCellCountX; |
| 721 | int y = index / mCellCountX; |
Winson Chung | 6a70e9f | 2011-05-17 16:24:49 -0700 | [diff] [blame] | 722 | layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 723 | |
| 724 | items.add(info); |
| 725 | images.add(info.iconBitmap); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 726 | } |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 727 | |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 728 | layout.createHardwareLayers(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 729 | |
Winson Chung | 8ff8713 | 2011-09-30 19:40:46 -0700 | [diff] [blame] | 730 | /* TEMPORARILY DISABLE HOLOGRAPHIC ICONS |
Winson Chung | 54c725c | 2011-08-03 12:03:40 -0700 | [diff] [blame] | 731 | if (mFadeInAdjacentScreens) { |
| 732 | prepareGenerateHoloOutlinesTask(page, items, images); |
| 733 | } |
Winson Chung | 8ff8713 | 2011-09-30 19:40:46 -0700 | [diff] [blame] | 734 | */ |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 735 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 736 | |
| 737 | /** |
| 738 | * Return the appropriate thread priority for loading for a given page (we give the current |
| 739 | * page much higher priority) |
| 740 | */ |
| 741 | private int getThreadPriorityForPage(int page) { |
| 742 | // TODO-APPS_CUSTOMIZE: detect number of cores and set thread priorities accordingly below |
| 743 | int pageDiff = Math.abs(page - mCurrentPage); |
| 744 | if (pageDiff <= 0) { |
| 745 | // return Process.THREAD_PRIORITY_DEFAULT; |
| 746 | return Process.THREAD_PRIORITY_MORE_FAVORABLE; |
| 747 | } else if (pageDiff <= 1) { |
| 748 | // return Process.THREAD_PRIORITY_BACKGROUND; |
| 749 | return Process.THREAD_PRIORITY_DEFAULT; |
| 750 | } else { |
| 751 | // return Process.THREAD_PRIORITY_LOWEST; |
| 752 | return Process.THREAD_PRIORITY_DEFAULT; |
| 753 | } |
| 754 | } |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 755 | private int getSleepForPage(int page) { |
| 756 | int pageDiff = Math.abs(page - mCurrentPage) - 1; |
| 757 | return Math.max(0, pageDiff * sPageSleepDelay); |
| 758 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 759 | /** |
| 760 | * Creates and executes a new AsyncTask to load a page of widget previews. |
| 761 | */ |
| 762 | private void prepareLoadWidgetPreviewsTask(int page, ArrayList<Object> widgets, |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 763 | int cellWidth, int cellHeight, int cellCountX) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 764 | // Prune all tasks that are no longer needed |
| 765 | Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator(); |
| 766 | while (iter.hasNext()) { |
| 767 | AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next(); |
| 768 | int taskPage = task.page; |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 769 | if ((taskPage == page) || |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 770 | taskPage < getAssociatedLowerPageBound(mCurrentPage - mNumAppsPages) || |
| 771 | taskPage > getAssociatedUpperPageBound(mCurrentPage - mNumAppsPages)) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 772 | task.cancel(false); |
| 773 | iter.remove(); |
| 774 | } else { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 775 | task.setThreadPriority(getThreadPriorityForPage(taskPage + mNumAppsPages)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 776 | } |
| 777 | } |
| 778 | |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 779 | // We introduce a slight delay to order the loading of side pages so that we don't thrash |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 780 | final int sleepMs = getSleepForPage(page + mNumAppsPages); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 781 | AsyncTaskPageData pageData = new AsyncTaskPageData(page, widgets, cellWidth, cellHeight, |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 782 | cellCountX, new AsyncTaskCallback() { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 783 | @Override |
| 784 | public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) { |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 785 | try { |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 786 | try { |
| 787 | Thread.sleep(sleepMs); |
| 788 | } catch (Exception e) {} |
| 789 | loadWidgetPreviewsInBackground(task, data); |
| 790 | } finally { |
| 791 | if (task.isCancelled()) { |
| 792 | data.cleanup(true); |
| 793 | } |
| 794 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 795 | } |
| 796 | }, |
| 797 | new AsyncTaskCallback() { |
| 798 | @Override |
| 799 | public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) { |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 800 | try { |
| 801 | mRunningTasks.remove(task); |
| 802 | if (task.isCancelled()) return; |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 803 | onSyncWidgetPageItems(data); |
| 804 | } finally { |
| 805 | data.cleanup(task.isCancelled()); |
| 806 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 807 | } |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 808 | }); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 809 | |
| 810 | // Ensure that the task is appropriately prioritized and runs in parallel |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 811 | AppsCustomizeAsyncTask t = new AppsCustomizeAsyncTask(page, |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 812 | AsyncTaskPageData.Type.LoadWidgetPreviewData); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 813 | t.setThreadPriority(getThreadPriorityForPage(page)); |
| 814 | t.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, pageData); |
| 815 | mRunningTasks.add(t); |
| 816 | } |
| 817 | /** |
| 818 | * Creates and executes a new AsyncTask to load the outlines for a page of content. |
| 819 | */ |
| 820 | private void prepareGenerateHoloOutlinesTask(int page, ArrayList<Object> items, |
| 821 | ArrayList<Bitmap> images) { |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 822 | // Prune old tasks for this page |
| 823 | Iterator<AppsCustomizeAsyncTask> iter = mRunningTasks.iterator(); |
| 824 | while (iter.hasNext()) { |
| 825 | AppsCustomizeAsyncTask task = (AppsCustomizeAsyncTask) iter.next(); |
| 826 | int taskPage = task.page; |
| 827 | if ((taskPage == page) && |
| 828 | (task.dataType == AsyncTaskPageData.Type.LoadHolographicIconsData)) { |
| 829 | task.cancel(false); |
| 830 | iter.remove(); |
| 831 | } |
| 832 | } |
| 833 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 834 | AsyncTaskPageData pageData = new AsyncTaskPageData(page, items, images, |
| 835 | new AsyncTaskCallback() { |
| 836 | @Override |
| 837 | public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) { |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 838 | try { |
| 839 | // Ensure that this task starts running at the correct priority |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 840 | task.syncThreadPriority(); |
| 841 | |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 842 | ArrayList<Bitmap> images = data.generatedImages; |
| 843 | ArrayList<Bitmap> srcImages = data.sourceImages; |
| 844 | int count = srcImages.size(); |
| 845 | Canvas c = new Canvas(); |
| 846 | for (int i = 0; i < count && !task.isCancelled(); ++i) { |
| 847 | // Before work on each item, ensure that this task is running at the correct |
| 848 | // priority |
| 849 | task.syncThreadPriority(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 850 | |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 851 | Bitmap b = srcImages.get(i); |
| 852 | Bitmap outline = Bitmap.createBitmap(b.getWidth(), b.getHeight(), |
| 853 | Bitmap.Config.ARGB_8888); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 854 | |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 855 | c.setBitmap(outline); |
| 856 | c.save(); |
| 857 | c.drawBitmap(b, 0, 0, null); |
| 858 | c.restore(); |
| 859 | c.setBitmap(null); |
| 860 | |
| 861 | images.add(outline); |
| 862 | } |
| 863 | } finally { |
| 864 | if (task.isCancelled()) { |
| 865 | data.cleanup(true); |
| 866 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 867 | } |
| 868 | } |
| 869 | }, |
| 870 | new AsyncTaskCallback() { |
| 871 | @Override |
| 872 | public void run(AppsCustomizeAsyncTask task, AsyncTaskPageData data) { |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 873 | try { |
| 874 | mRunningTasks.remove(task); |
| 875 | if (task.isCancelled()) return; |
Winson Chung | 0994593 | 2011-09-20 14:22:40 -0700 | [diff] [blame] | 876 | onHolographicPageItemsLoaded(data); |
| 877 | } finally { |
| 878 | data.cleanup(task.isCancelled()); |
| 879 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 880 | } |
| 881 | }); |
| 882 | |
| 883 | // Ensure that the outline task always runs in the background, serially |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 884 | AppsCustomizeAsyncTask t = |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 885 | new AppsCustomizeAsyncTask(page, AsyncTaskPageData.Type.LoadHolographicIconsData); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 886 | t.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND); |
| 887 | t.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR, pageData); |
| 888 | mRunningTasks.add(t); |
| 889 | } |
| 890 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 891 | /* |
| 892 | * Widgets PagedView implementation |
| 893 | */ |
Winson Chung | 4e6a976 | 2011-05-09 11:56:34 -0700 | [diff] [blame] | 894 | private void setupPage(PagedViewGridLayout layout) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 895 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, |
| 896 | mPageLayoutPaddingRight, mPageLayoutPaddingBottom); |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 897 | |
| 898 | // Note: We force a measure here to get around the fact that when we do layout calculations |
Winson Chung | d52f3d8 | 2011-07-12 14:29:11 -0700 | [diff] [blame] | 899 | // immediately after syncing, we don't have a proper width. |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 900 | int widthSpec = MeasureSpec.makeMeasureSpec(getMeasuredWidth(), MeasureSpec.AT_MOST); |
| 901 | int heightSpec = MeasureSpec.makeMeasureSpec(getMeasuredHeight(), MeasureSpec.AT_MOST); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 902 | layout.setMinimumWidth(getPageContentWidth()); |
Winson Chung | 63257c1 | 2011-05-05 17:06:13 -0700 | [diff] [blame] | 903 | layout.measure(widthSpec, heightSpec); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 904 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 905 | |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 906 | private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h) { |
| 907 | renderDrawableToBitmap(d, bitmap, x, y, w, h, 1f, 0xFFFFFFFF); |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 908 | } |
| 909 | private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 910 | float scale) { |
| 911 | renderDrawableToBitmap(d, bitmap, x, y, w, h, scale, 0xFFFFFFFF); |
| 912 | } |
| 913 | private void renderDrawableToBitmap(Drawable d, Bitmap bitmap, int x, int y, int w, int h, |
| 914 | float scale, int multiplyColor) { |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 915 | if (bitmap != null) { |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 916 | Canvas c = new Canvas(bitmap); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 917 | c.scale(scale, scale); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 918 | Rect oldBounds = d.copyBounds(); |
| 919 | d.setBounds(x, y, x + w, y + h); |
| 920 | d.draw(c); |
| 921 | d.setBounds(oldBounds); // Restore the bounds |
Winson Chung | 70fc438 | 2011-08-08 15:31:33 -0700 | [diff] [blame] | 922 | if (multiplyColor != 0xFFFFFFFF) { |
| 923 | c.drawColor(mDragViewMultiplyColor, PorterDuff.Mode.MULTIPLY); |
| 924 | } |
Adam Cohen | aaf473c | 2011-08-03 12:02:47 -0700 | [diff] [blame] | 925 | c.setBitmap(null); |
Winson Chung | 201bc82 | 2011-06-20 15:41:53 -0700 | [diff] [blame] | 926 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 927 | } |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 928 | private Bitmap getShortcutPreview(ResolveInfo info, int cellWidth, int cellHeight) { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 929 | // Render the background |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 930 | int offset = 0; |
| 931 | int bitmapSize = mAppIconSize; |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 932 | Bitmap preview = Bitmap.createBitmap(bitmapSize, bitmapSize, Config.ARGB_8888); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 933 | |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 934 | // Render the icon |
Winson Chung | 4dbea79 | 2011-05-05 14:21:32 -0700 | [diff] [blame] | 935 | Drawable icon = mIconCache.getFullResIcon(info, mPackageManager); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 936 | renderDrawableToBitmap(icon, preview, offset, offset, mAppIconSize, mAppIconSize); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 937 | return preview; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 938 | } |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 939 | private Bitmap getWidgetPreview(AppWidgetProviderInfo info, |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 940 | int cellHSpan, int cellVSpan, int cellWidth, int cellHeight) { |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 941 | |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 942 | // Load the preview image if possible |
| 943 | String packageName = info.provider.getPackageName(); |
| 944 | Drawable drawable = null; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 945 | Bitmap preview = null; |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 946 | if (info.previewImage != 0) { |
| 947 | drawable = mPackageManager.getDrawable(packageName, info.previewImage, null); |
| 948 | if (drawable == null) { |
| 949 | Log.w(LOG_TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) |
| 950 | + " for provider: " + info.provider); |
| 951 | } else { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 952 | // Scale down the preview to something that is closer to the cellWidth/Height |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 953 | int imageWidth = drawable.getIntrinsicWidth(); |
| 954 | int imageHeight = drawable.getIntrinsicHeight(); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 955 | int bitmapWidth = imageWidth; |
| 956 | int bitmapHeight = imageHeight; |
| 957 | if (imageWidth > imageHeight) { |
| 958 | bitmapWidth = cellWidth; |
| 959 | bitmapHeight = (int) (imageHeight * ((float) bitmapWidth / imageWidth)); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 960 | } else { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 961 | bitmapHeight = cellHeight; |
| 962 | bitmapWidth = (int) (imageWidth * ((float) bitmapHeight / imageHeight)); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 963 | } |
| 964 | |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 965 | preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); |
| 966 | renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth, bitmapHeight); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 967 | } |
| 968 | } |
| 969 | |
| 970 | // Generate a preview image if we couldn't load one |
| 971 | if (drawable == null) { |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 972 | Resources resources = mLauncher.getResources(); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 973 | // TODO: This actually uses the apps customize cell layout params, where as we make want |
| 974 | // the Workspace params for more accuracy. |
| 975 | int targetWidth = mWidgetSpacingLayout.estimateCellWidth(cellHSpan); |
| 976 | int targetHeight = mWidgetSpacingLayout.estimateCellHeight(cellVSpan); |
| 977 | int bitmapWidth = targetWidth; |
| 978 | int bitmapHeight = targetHeight; |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 979 | int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 980 | float iconScale = 1f; |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 981 | |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 982 | // Determine the size of the bitmap we want to draw |
Winson Chung | 273c102 | 2011-07-11 13:40:52 -0700 | [diff] [blame] | 983 | if (cellHSpan == cellVSpan) { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 984 | // For square widgets, we just have a fixed size for 1x1 and larger-than-1x1 |
| 985 | if (cellHSpan <= 1) { |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 986 | bitmapWidth = bitmapHeight = mAppIconSize + 2 * minOffset; |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 987 | } else { |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 988 | bitmapWidth = bitmapHeight = mAppIconSize + 4 * minOffset; |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 989 | } |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 990 | } else { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 991 | // Otherwise, ensure that we are properly sized within the cellWidth/Height |
| 992 | if (targetWidth > targetHeight) { |
| 993 | bitmapWidth = Math.min(targetWidth, cellWidth); |
| 994 | bitmapHeight = (int) (targetHeight * ((float) bitmapWidth / targetWidth)); |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 995 | iconScale = Math.min((float) bitmapHeight / (mAppIconSize + 2 * minOffset), 1f); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 996 | } else { |
| 997 | bitmapHeight = Math.min(targetHeight, cellHeight); |
| 998 | bitmapWidth = (int) (targetWidth * ((float) bitmapHeight / targetHeight)); |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 999 | iconScale = Math.min((float) bitmapWidth / (mAppIconSize + 2 * minOffset), 1f); |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 1000 | } |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 1001 | } |
Winson Chung | 273c102 | 2011-07-11 13:40:52 -0700 | [diff] [blame] | 1002 | preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888); |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 1003 | if (cellHSpan != 1 || cellVSpan != 1) { |
| 1004 | renderDrawableToBitmap(mDefaultWidgetBackground, preview, 0, 0, bitmapWidth, |
| 1005 | bitmapHeight); |
| 1006 | } |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 1007 | |
| 1008 | // Draw the icon in the top left corner |
| 1009 | try { |
| 1010 | Drawable icon = null; |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 1011 | int hoffset = (int) (bitmapWidth / 2 - mAppIconSize * iconScale / 2); |
| 1012 | int yoffset = (int) (bitmapHeight / 2 - mAppIconSize * iconScale / 2); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 1013 | if (info.icon > 0) icon = mPackageManager.getDrawable(packageName, info.icon, null); |
| 1014 | if (icon == null) icon = resources.getDrawable(R.drawable.ic_launcher_application); |
| 1015 | |
Peter Ng | 8db7000 | 2011-10-25 15:40:08 -0700 | [diff] [blame] | 1016 | renderDrawableToBitmap(icon, preview, hoffset, yoffset, |
| 1017 | (int) (mAppIconSize * iconScale), |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 1018 | (int) (mAppIconSize * iconScale)); |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 1019 | } catch (Resources.NotFoundException e) {} |
Winson Chung | 4b576be | 2011-04-27 17:40:20 -0700 | [diff] [blame] | 1020 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1021 | return preview; |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1022 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1023 | |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1024 | public void syncWidgetPageItems(int page, boolean immediate) { |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 1025 | int numItemsPerPage = mWidgetCountX * mWidgetCountY; |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1026 | int contentWidth = mWidgetSpacingLayout.getContentWidth(); |
| 1027 | int contentHeight = mWidgetSpacingLayout.getContentHeight(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1028 | |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1029 | // Calculate the dimensions of each cell we are giving to each widget |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1030 | ArrayList<Object> items = new ArrayList<Object>(); |
| 1031 | int cellWidth = ((contentWidth - mPageLayoutPaddingLeft - mPageLayoutPaddingRight |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 1032 | - ((mWidgetCountX - 1) * mWidgetWidthGap)) / mWidgetCountX); |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1033 | int cellHeight = ((contentHeight - mPageLayoutPaddingTop - mPageLayoutPaddingBottom |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 1034 | - ((mWidgetCountY - 1) * mWidgetHeightGap)) / mWidgetCountY); |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1035 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 1036 | // Prepare the set of widgets to load previews for in the background |
Winson Chung | 6a3fd3f | 2011-08-02 14:03:26 -0700 | [diff] [blame] | 1037 | int offset = page * numItemsPerPage; |
| 1038 | for (int i = offset; i < Math.min(offset + numItemsPerPage, mWidgets.size()); ++i) { |
| 1039 | items.add(mWidgets.get(i)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1040 | } |
| 1041 | |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 1042 | // Prepopulate the pages with the other widget info, and fill in the previews later |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1043 | PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page + mNumAppsPages); |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 1044 | layout.setColumnCount(layout.getCellCountX()); |
| 1045 | for (int i = 0; i < items.size(); ++i) { |
| 1046 | Object rawInfo = items.get(i); |
| 1047 | PendingAddItemInfo createItemInfo = null; |
| 1048 | PagedViewWidget widget = (PagedViewWidget) mLayoutInflater.inflate( |
| 1049 | R.layout.apps_customize_widget, layout, false); |
| 1050 | if (rawInfo instanceof AppWidgetProviderInfo) { |
| 1051 | // Fill in the widget information |
| 1052 | AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; |
| 1053 | createItemInfo = new PendingAddWidgetInfo(info, null, null); |
| 1054 | int[] cellSpans = mLauncher.getSpanForWidget(info, null); |
| 1055 | widget.applyFromAppWidgetProviderInfo(info, -1, cellSpans, |
| 1056 | mHolographicOutlineHelper); |
| 1057 | widget.setTag(createItemInfo); |
| 1058 | } else if (rawInfo instanceof ResolveInfo) { |
| 1059 | // Fill in the shortcuts information |
| 1060 | ResolveInfo info = (ResolveInfo) rawInfo; |
| 1061 | createItemInfo = new PendingAddItemInfo(); |
| 1062 | createItemInfo.itemType = LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT; |
| 1063 | createItemInfo.componentName = new ComponentName(info.activityInfo.packageName, |
| 1064 | info.activityInfo.name); |
| 1065 | widget.applyFromResolveInfo(mPackageManager, info, mHolographicOutlineHelper); |
| 1066 | widget.setTag(createItemInfo); |
| 1067 | } |
| 1068 | widget.setOnClickListener(this); |
| 1069 | widget.setOnLongClickListener(this); |
| 1070 | widget.setOnTouchListener(this); |
| 1071 | |
| 1072 | // Layout each widget |
| 1073 | int ix = i % mWidgetCountX; |
| 1074 | int iy = i / mWidgetCountX; |
| 1075 | GridLayout.LayoutParams lp = new GridLayout.LayoutParams( |
| 1076 | GridLayout.spec(iy, GridLayout.LEFT), |
| 1077 | GridLayout.spec(ix, GridLayout.TOP)); |
| 1078 | lp.width = cellWidth; |
| 1079 | lp.height = cellHeight; |
| 1080 | lp.setGravity(Gravity.TOP | Gravity.LEFT); |
| 1081 | if (ix > 0) lp.leftMargin = mWidgetWidthGap; |
| 1082 | if (iy > 0) lp.topMargin = mWidgetHeightGap; |
| 1083 | layout.addView(widget, lp); |
| 1084 | } |
| 1085 | |
| 1086 | // Load the widget previews |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1087 | if (immediate) { |
| 1088 | AsyncTaskPageData data = new AsyncTaskPageData(page, items, cellWidth, cellHeight, |
| 1089 | mWidgetCountX, null, null); |
| 1090 | loadWidgetPreviewsInBackground(null, data); |
| 1091 | onSyncWidgetPageItems(data); |
| 1092 | } else { |
| 1093 | prepareLoadWidgetPreviewsTask(page, items, cellWidth, cellHeight, mWidgetCountX); |
| 1094 | } |
| 1095 | } |
| 1096 | private void loadWidgetPreviewsInBackground(AppsCustomizeAsyncTask task, |
| 1097 | AsyncTaskPageData data) { |
| 1098 | if (task != null) { |
| 1099 | // Ensure that this task starts running at the correct priority |
| 1100 | task.syncThreadPriority(); |
| 1101 | } |
| 1102 | |
| 1103 | // Load each of the widget/shortcut previews |
| 1104 | ArrayList<Object> items = data.items; |
| 1105 | ArrayList<Bitmap> images = data.generatedImages; |
| 1106 | int count = items.size(); |
| 1107 | int cellWidth = data.cellWidth; |
| 1108 | int cellHeight = data.cellHeight; |
| 1109 | for (int i = 0; i < count; ++i) { |
| 1110 | if (task != null) { |
| 1111 | // Ensure we haven't been cancelled yet |
| 1112 | if (task.isCancelled()) break; |
| 1113 | // Before work on each item, ensure that this task is running at the correct |
| 1114 | // priority |
| 1115 | task.syncThreadPriority(); |
| 1116 | } |
| 1117 | |
| 1118 | Object rawInfo = items.get(i); |
| 1119 | if (rawInfo instanceof AppWidgetProviderInfo) { |
| 1120 | AppWidgetProviderInfo info = (AppWidgetProviderInfo) rawInfo; |
Adam Cohen | f814aa0 | 2011-09-01 13:48:05 -0700 | [diff] [blame] | 1121 | int[] cellSpans = mLauncher.getSpanForWidget(info, null); |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1122 | images.add(getWidgetPreview(info, cellSpans[0],cellSpans[1], |
| 1123 | cellWidth, cellHeight)); |
| 1124 | } else if (rawInfo instanceof ResolveInfo) { |
| 1125 | // Fill in the shortcuts information |
| 1126 | ResolveInfo info = (ResolveInfo) rawInfo; |
| 1127 | images.add(getShortcutPreview(info, cellWidth, cellHeight)); |
| 1128 | } |
| 1129 | } |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1130 | } |
| 1131 | private void onSyncWidgetPageItems(AsyncTaskPageData data) { |
| 1132 | int page = data.page; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1133 | PagedViewGridLayout layout = (PagedViewGridLayout) getPageAt(page + mNumAppsPages); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1134 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1135 | ArrayList<Object> items = data.items; |
| 1136 | int count = items.size(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1137 | for (int i = 0; i < count; ++i) { |
Winson Chung | e4a647f | 2011-09-30 14:41:25 -0700 | [diff] [blame] | 1138 | PagedViewWidget widget = (PagedViewWidget) layout.getChildAt(i); |
| 1139 | if (widget != null) { |
Winson Chung | 5fc72b3 | 2011-10-11 17:53:58 -0700 | [diff] [blame] | 1140 | Bitmap preview = data.generatedImages.get(i); |
| 1141 | boolean scale = |
| 1142 | (preview.getWidth() >= data.cellWidth || |
| 1143 | preview.getHeight() >= data.cellHeight); |
| 1144 | |
| 1145 | widget.applyPreview(new FastBitmapDrawable(preview), i, scale); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 1146 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1147 | } |
Winson Chung | 7f0acdd | 2011-09-19 18:34:19 -0700 | [diff] [blame] | 1148 | layout.createHardwareLayer(); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1149 | |
| 1150 | invalidate(); |
| 1151 | forceUpdateAdjacentPagesAlpha(); |
Winson Chung | 54c725c | 2011-08-03 12:03:40 -0700 | [diff] [blame] | 1152 | |
Winson Chung | 8ff8713 | 2011-09-30 19:40:46 -0700 | [diff] [blame] | 1153 | /* TEMPORARILY DISABLE HOLOGRAPHIC ICONS |
Winson Chung | 54c725c | 2011-08-03 12:03:40 -0700 | [diff] [blame] | 1154 | if (mFadeInAdjacentScreens) { |
| 1155 | prepareGenerateHoloOutlinesTask(data.page, data.items, data.generatedImages); |
| 1156 | } |
Winson Chung | 8ff8713 | 2011-09-30 19:40:46 -0700 | [diff] [blame] | 1157 | */ |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1158 | } |
| 1159 | private void onHolographicPageItemsLoaded(AsyncTaskPageData data) { |
| 1160 | // Invalidate early to short-circuit children invalidates |
| 1161 | invalidate(); |
| 1162 | |
| 1163 | int page = data.page; |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1164 | ViewGroup layout = (ViewGroup) getPageAt(page); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1165 | if (layout instanceof PagedViewCellLayout) { |
| 1166 | PagedViewCellLayout cl = (PagedViewCellLayout) layout; |
| 1167 | int count = cl.getPageChildCount(); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 1168 | if (count != data.generatedImages.size()) return; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1169 | for (int i = 0; i < count; ++i) { |
| 1170 | PagedViewIcon icon = (PagedViewIcon) cl.getChildOnPageAt(i); |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 1171 | icon.setHolographicOutline(data.generatedImages.get(i)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1172 | } |
| 1173 | } else { |
| 1174 | int count = layout.getChildCount(); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 1175 | if (count != data.generatedImages.size()) return; |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1176 | for (int i = 0; i < count; ++i) { |
| 1177 | View v = layout.getChildAt(i); |
Winson Chung | 4e07654 | 2011-06-23 13:04:10 -0700 | [diff] [blame] | 1178 | ((PagedViewWidget) v).setHolographicOutline(data.generatedImages.get(i)); |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1179 | } |
| 1180 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1181 | } |
Winson Chung | 46af2e8 | 2011-05-09 16:00:53 -0700 | [diff] [blame] | 1182 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1183 | @Override |
| 1184 | public void syncPages() { |
| 1185 | removeAllViews(); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1186 | cancelAllTasks(); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 1187 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1188 | Context context = getContext(); |
| 1189 | for (int j = 0; j < mNumWidgetPages; ++j) { |
| 1190 | PagedViewGridLayout layout = new PagedViewGridLayout(context, mWidgetCountX, |
| 1191 | mWidgetCountY); |
| 1192 | setupPage(layout); |
| 1193 | addView(layout, new PagedViewGridLayout.LayoutParams(LayoutParams.MATCH_PARENT, |
| 1194 | LayoutParams.MATCH_PARENT)); |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 1195 | } |
| 1196 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1197 | for (int i = 0; i < mNumAppsPages; ++i) { |
| 1198 | PagedViewCellLayout layout = new PagedViewCellLayout(context); |
| 1199 | setupPage(layout); |
| 1200 | addView(layout); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1201 | } |
| 1202 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1203 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1204 | @Override |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1205 | public void syncPageItems(int page, boolean immediate) { |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1206 | if (page < mNumAppsPages) { |
Winson Chung | f314b0e | 2011-08-16 11:54:27 -0700 | [diff] [blame] | 1207 | syncAppsPageItems(page, immediate); |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1208 | } else { |
| 1209 | syncWidgetPageItems(page - mNumAppsPages, immediate); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1210 | } |
| 1211 | } |
| 1212 | |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1213 | // We want our pages to be z-ordered such that the further a page is to the left, the higher |
| 1214 | // it is in the z-order. This is important to insure touch events are handled correctly. |
| 1215 | View getPageAt(int index) { |
| 1216 | return getChildAt(getChildCount() - index - 1); |
| 1217 | } |
| 1218 | |
Adam Cohen | ae4f155 | 2011-10-20 00:15:42 -0700 | [diff] [blame] | 1219 | @Override |
| 1220 | protected int indexToPage(int index) { |
| 1221 | return getChildCount() - index - 1; |
| 1222 | } |
| 1223 | |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1224 | // In apps customize, we have a scrolling effect which emulates pulling cards off of a stack. |
| 1225 | @Override |
| 1226 | protected void screenScrolled(int screenCenter) { |
| 1227 | super.screenScrolled(screenCenter); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1228 | |
| 1229 | for (int i = 0; i < getChildCount(); i++) { |
| 1230 | View v = getPageAt(i); |
| 1231 | if (v != null) { |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1232 | float scrollProgress = getScrollProgress(screenCenter, v, i); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1233 | |
| 1234 | float interpolatedProgress = |
| 1235 | mZInterpolator.getInterpolation(Math.abs(Math.min(scrollProgress, 0))); |
| 1236 | float scale = (1 - interpolatedProgress) + |
| 1237 | interpolatedProgress * TRANSITION_SCALE_FACTOR; |
| 1238 | float translationX = Math.min(0, scrollProgress) * v.getMeasuredWidth(); |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1239 | |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 1240 | float alpha; |
| 1241 | |
| 1242 | if (!LauncherApplication.isScreenLarge() || scrollProgress < 0) { |
| 1243 | alpha = scrollProgress < 0 ? mAlphaInterpolator.getInterpolation( |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1244 | 1 - Math.abs(scrollProgress)) : 1.0f; |
Adam Cohen | 2591f6a | 2011-10-25 14:36:40 -0700 | [diff] [blame] | 1245 | } else { |
| 1246 | // On large screens we need to fade the page as it nears its leftmost position |
| 1247 | alpha = mLeftScreenAlphaInterpolator.getInterpolation(1 - scrollProgress); |
| 1248 | } |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1249 | |
| 1250 | v.setCameraDistance(mDensity * CAMERA_DISTANCE); |
| 1251 | int pageWidth = v.getMeasuredWidth(); |
| 1252 | int pageHeight = v.getMeasuredHeight(); |
Adam Cohen | b5ba097 | 2011-09-07 18:02:31 -0700 | [diff] [blame] | 1253 | |
| 1254 | if (PERFORM_OVERSCROLL_ROTATION) { |
| 1255 | if (i == 0 && scrollProgress < 0) { |
| 1256 | // Overscroll to the left |
| 1257 | v.setPivotX(TRANSITION_PIVOT * pageWidth); |
| 1258 | v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress); |
| 1259 | scale = 1.0f; |
| 1260 | alpha = 1.0f; |
| 1261 | // On the first page, we don't want the page to have any lateral motion |
| 1262 | translationX = getScrollX(); |
| 1263 | } else if (i == getChildCount() - 1 && scrollProgress > 0) { |
| 1264 | // Overscroll to the right |
| 1265 | v.setPivotX((1 - TRANSITION_PIVOT) * pageWidth); |
| 1266 | v.setRotationY(-TRANSITION_MAX_ROTATION * scrollProgress); |
| 1267 | scale = 1.0f; |
| 1268 | alpha = 1.0f; |
| 1269 | // On the last page, we don't want the page to have any lateral motion. |
| 1270 | translationX = getScrollX() - mMaxScrollX; |
| 1271 | } else { |
| 1272 | v.setPivotY(pageHeight / 2.0f); |
| 1273 | v.setPivotX(pageWidth / 2.0f); |
| 1274 | v.setRotationY(0f); |
| 1275 | } |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1276 | } |
| 1277 | |
| 1278 | v.setTranslationX(translationX); |
| 1279 | v.setScaleX(scale); |
| 1280 | v.setScaleY(scale); |
| 1281 | v.setAlpha(alpha); |
| 1282 | } |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | protected void overScroll(float amount) { |
Adam Cohen | cff6af8 | 2011-09-13 14:51:53 -0700 | [diff] [blame] | 1287 | acceleratedOverScroll(amount); |
Adam Cohen | 22f823d | 2011-09-01 17:22:18 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1290 | /** |
| 1291 | * Used by the parent to get the content width to set the tab bar to |
| 1292 | * @return |
| 1293 | */ |
| 1294 | public int getPageContentWidth() { |
| 1295 | return mContentWidth; |
| 1296 | } |
| 1297 | |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 1298 | @Override |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 1299 | protected void onPageEndMoving() { |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 1300 | super.onPageEndMoving(); |
Winson Chung | 5afbf7b | 2011-07-25 11:53:08 -0700 | [diff] [blame] | 1301 | |
| 1302 | // We reset the save index when we change pages so that it will be recalculated on next |
| 1303 | // rotation |
| 1304 | mSaveInstanceStateItemIndex = -1; |
Winson Chung | b26f3d6 | 2011-06-02 10:49:29 -0700 | [diff] [blame] | 1305 | } |
| 1306 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1307 | /* |
| 1308 | * AllAppsView implementation |
| 1309 | */ |
| 1310 | @Override |
| 1311 | public void setup(Launcher launcher, DragController dragController) { |
| 1312 | mLauncher = launcher; |
| 1313 | mDragController = dragController; |
| 1314 | } |
| 1315 | @Override |
| 1316 | public void zoom(float zoom, boolean animate) { |
| 1317 | // TODO-APPS_CUSTOMIZE: Call back to mLauncher.zoomed() |
| 1318 | } |
| 1319 | @Override |
| 1320 | public boolean isVisible() { |
| 1321 | return (getVisibility() == VISIBLE); |
| 1322 | } |
| 1323 | @Override |
| 1324 | public boolean isAnimating() { |
| 1325 | return false; |
| 1326 | } |
| 1327 | @Override |
| 1328 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 1329 | mApps = list; |
| 1330 | Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1331 | updatePageCounts(); |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1332 | |
Winson Chung | 875de7e | 2011-06-28 14:25:17 -0700 | [diff] [blame] | 1333 | // The next layout pass will trigger data-ready if both widgets and apps are set, so |
| 1334 | // request a layout to do this test and invalidate the page data when ready. |
Winson Chung | f0ea4d3 | 2011-06-06 14:27:16 -0700 | [diff] [blame] | 1335 | if (testDataReady()) requestLayout(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1336 | } |
| 1337 | private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 1338 | // We add it in place, in alphabetical order |
| 1339 | int count = list.size(); |
| 1340 | for (int i = 0; i < count; ++i) { |
| 1341 | ApplicationInfo info = list.get(i); |
| 1342 | int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); |
| 1343 | if (index < 0) { |
| 1344 | mApps.add(-(index + 1), info); |
| 1345 | } |
| 1346 | } |
| 1347 | } |
| 1348 | @Override |
| 1349 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 1350 | addAppsWithoutInvalidate(list); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1351 | updatePageCounts(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1352 | invalidatePageData(); |
| 1353 | } |
| 1354 | private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { |
| 1355 | ComponentName removeComponent = item.intent.getComponent(); |
| 1356 | int length = list.size(); |
| 1357 | for (int i = 0; i < length; ++i) { |
| 1358 | ApplicationInfo info = list.get(i); |
| 1359 | if (info.intent.getComponent().equals(removeComponent)) { |
| 1360 | return i; |
| 1361 | } |
| 1362 | } |
| 1363 | return -1; |
| 1364 | } |
| 1365 | private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 1366 | // loop through all the apps and remove apps that have the same component |
| 1367 | int length = list.size(); |
| 1368 | for (int i = 0; i < length; ++i) { |
| 1369 | ApplicationInfo info = list.get(i); |
| 1370 | int removeIndex = findAppByComponent(mApps, info); |
| 1371 | if (removeIndex > -1) { |
| 1372 | mApps.remove(removeIndex); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1373 | } |
| 1374 | } |
| 1375 | } |
| 1376 | @Override |
| 1377 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 1378 | removeAppsWithoutInvalidate(list); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1379 | updatePageCounts(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1380 | invalidatePageData(); |
| 1381 | } |
| 1382 | @Override |
| 1383 | public void updateApps(ArrayList<ApplicationInfo> list) { |
| 1384 | // We remove and re-add the updated applications list because it's properties may have |
| 1385 | // changed (ie. the title), and this will ensure that the items will be in their proper |
| 1386 | // place in the list. |
| 1387 | removeAppsWithoutInvalidate(list); |
| 1388 | addAppsWithoutInvalidate(list); |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1389 | updatePageCounts(); |
| 1390 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1391 | invalidatePageData(); |
| 1392 | } |
Michael Jurka | 35aa14d | 2011-07-07 17:01:08 -0700 | [diff] [blame] | 1393 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1394 | @Override |
| 1395 | public void reset() { |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 1396 | AppsCustomizeTabHost tabHost = getTabHost(); |
| 1397 | String tag = tabHost.getCurrentTabTag(); |
Winson Chung | 6a8103c | 2011-10-21 11:08:32 -0700 | [diff] [blame] | 1398 | if (tag != null) { |
| 1399 | if (!tag.equals(tabHost.getTabTagForContentType(ContentType.Applications))) { |
| 1400 | tabHost.setCurrentTabFromContent(ContentType.Applications); |
| 1401 | } |
Adam Cohen | b64d36e | 2011-10-17 21:48:02 -0700 | [diff] [blame] | 1402 | } |
| 1403 | if (mCurrentPage != 0) { |
| 1404 | invalidatePageData(0); |
| 1405 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1406 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1407 | |
| 1408 | private AppsCustomizeTabHost getTabHost() { |
| 1409 | return (AppsCustomizeTabHost) mLauncher.findViewById(R.id.apps_customize_pane); |
| 1410 | } |
| 1411 | |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1412 | @Override |
| 1413 | public void dumpState() { |
| 1414 | // TODO: Dump information related to current list of Applications, Widgets, etc. |
| 1415 | ApplicationInfo.dumpApplicationInfoList(LOG_TAG, "mApps", mApps); |
| 1416 | dumpAppWidgetProviderInfoList(LOG_TAG, "mWidgets", mWidgets); |
| 1417 | } |
| 1418 | private void dumpAppWidgetProviderInfoList(String tag, String label, |
Winson Chung | d294526 | 2011-06-24 15:22:14 -0700 | [diff] [blame] | 1419 | ArrayList<Object> list) { |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1420 | Log.d(tag, label + " size=" + list.size()); |
Winson Chung | 1ed747a | 2011-05-03 16:18:34 -0700 | [diff] [blame] | 1421 | for (Object i: list) { |
| 1422 | if (i instanceof AppWidgetProviderInfo) { |
| 1423 | AppWidgetProviderInfo info = (AppWidgetProviderInfo) i; |
| 1424 | Log.d(tag, " label=\"" + info.label + "\" previewImage=" + info.previewImage |
| 1425 | + " resizeMode=" + info.resizeMode + " configure=" + info.configure |
| 1426 | + " initialLayout=" + info.initialLayout |
| 1427 | + " minWidth=" + info.minWidth + " minHeight=" + info.minHeight); |
| 1428 | } else if (i instanceof ResolveInfo) { |
| 1429 | ResolveInfo info = (ResolveInfo) i; |
| 1430 | Log.d(tag, " label=\"" + info.loadLabel(mPackageManager) + "\" icon=" |
| 1431 | + info.icon); |
| 1432 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1433 | } |
| 1434 | } |
| 1435 | @Override |
| 1436 | public void surrender() { |
| 1437 | // TODO: If we are in the middle of any process (ie. for holographic outlines, etc) we |
| 1438 | // should stop this now. |
Winson Chung | 4b0ed8c | 2011-10-19 15:24:49 -0700 | [diff] [blame] | 1439 | |
| 1440 | // Stop all background tasks |
| 1441 | cancelAllTasks(); |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1442 | } |
Winson Chung | 007c698 | 2011-06-14 13:27:53 -0700 | [diff] [blame] | 1443 | |
Winson Chung | b44b524 | 2011-06-13 11:32:14 -0700 | [diff] [blame] | 1444 | /* |
| 1445 | * We load an extra page on each side to prevent flashes from scrolling and loading of the |
| 1446 | * widget previews in the background with the AsyncTasks. |
| 1447 | */ |
| 1448 | protected int getAssociatedLowerPageBound(int page) { |
| 1449 | return Math.max(0, page - 2); |
| 1450 | } |
| 1451 | protected int getAssociatedUpperPageBound(int page) { |
| 1452 | final int count = getChildCount(); |
| 1453 | return Math.min(page + 2, count - 1); |
| 1454 | } |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1455 | |
| 1456 | @Override |
| 1457 | protected String getCurrentPageDescription() { |
| 1458 | int page = (mNextPage != INVALID_PAGE) ? mNextPage : mCurrentPage; |
| 1459 | int stringId = R.string.default_scroll_format; |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1460 | int count = 0; |
| 1461 | |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1462 | if (page < mNumAppsPages) { |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1463 | stringId = R.string.apps_customize_apps_scroll_format; |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1464 | count = mNumAppsPages; |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1465 | } else { |
| 1466 | page -= mNumAppsPages; |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1467 | stringId = R.string.apps_customize_widgets_scroll_format; |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1468 | count = mNumWidgetPages; |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1469 | } |
Adam Cohen | 0cd3b64 | 2011-10-14 14:58:00 -0700 | [diff] [blame] | 1470 | |
Adam Cohen | d3357b1 | 2011-10-18 14:58:11 -0700 | [diff] [blame] | 1471 | return String.format(mContext.getString(stringId), page + 1, count); |
Winson Chung | 6a0f57d | 2011-06-29 20:10:49 -0700 | [diff] [blame] | 1472 | } |
Winson Chung | 785d2eb | 2011-04-14 16:08:02 -0700 | [diff] [blame] | 1473 | } |