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