Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 19 | import java.util.ArrayList; |
| 20 | import java.util.Collections; |
| 21 | import java.util.Comparator; |
| 22 | import java.util.List; |
| 23 | |
| 24 | import android.appwidget.AppWidgetManager; |
| 25 | import android.appwidget.AppWidgetProviderInfo; |
| 26 | import android.content.ComponentName; |
| 27 | import android.content.Context; |
| 28 | import android.content.Intent; |
| 29 | import android.content.pm.PackageManager; |
| 30 | import android.content.pm.ResolveInfo; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 31 | import android.content.res.Configuration; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 32 | import android.content.res.Resources; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 33 | import android.content.res.TypedArray; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 34 | import android.graphics.Bitmap; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 35 | import android.graphics.Bitmap.Config; |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 36 | import android.graphics.Canvas; |
| 37 | import android.graphics.Rect; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 38 | import android.graphics.Region.Op; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 39 | import android.graphics.drawable.Drawable; |
| 40 | import android.provider.LiveFolders; |
| 41 | import android.util.AttributeSet; |
| 42 | import android.util.Log; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 43 | import android.view.Gravity; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 44 | import android.view.LayoutInflater; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 45 | import android.view.MotionEvent; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 46 | import android.view.View; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 47 | import android.view.ViewGroup; |
| 48 | import android.widget.ImageView; |
| 49 | import android.widget.LinearLayout; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 50 | import android.widget.TextView; |
| 51 | |
| 52 | import com.android.launcher.R; |
| 53 | |
| 54 | public class CustomizePagedView extends PagedView |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 55 | implements View.OnLongClickListener, View.OnClickListener, |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 56 | DragSource { |
| 57 | |
| 58 | public enum CustomizationType { |
| 59 | WidgetCustomization, |
| 60 | FolderCustomization, |
| 61 | ShortcutCustomization, |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 62 | WallpaperCustomization, |
| 63 | ApplicationCustomization |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 64 | } |
| 65 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 66 | /** |
| 67 | * The linear layout used strictly for the widget tab of the customization tray |
| 68 | */ |
| 69 | private class WidgetLayout extends LinearLayout { |
| 70 | public WidgetLayout(Context context) { |
| 71 | super(context); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public boolean onTouchEvent(MotionEvent event) { |
| 76 | // We eat up the touch events here, since the PagedView (which uses the same swiping |
| 77 | // touch code as Workspace previously) uses onInterceptTouchEvent() to determine when |
| 78 | // the user is scrolling between pages. This means that if the pages themselves don't |
| 79 | // handle touch events, it gets forwarded up to PagedView itself, and it's own |
| 80 | // onTouchEvent() handling will prevent further intercept touch events from being called |
| 81 | // (it's the same view in that case). This is not ideal, but to prevent more changes, |
| 82 | // we just always mark the touch event as handled. |
| 83 | return super.onTouchEvent(event) || true; |
| 84 | } |
| 85 | } |
| 86 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 87 | private static final String TAG = "CustomizeWorkspace"; |
| 88 | private static final boolean DEBUG = false; |
| 89 | |
| 90 | private Launcher mLauncher; |
| 91 | private DragController mDragController; |
| 92 | private PackageManager mPackageManager; |
| 93 | |
| 94 | private CustomizationType mCustomizationType; |
| 95 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 96 | // The layout used to emulate the workspace in resolve the cell dimensions of a widget |
| 97 | private PagedViewCellLayout mWorkspaceWidgetLayout; |
| 98 | |
| 99 | // The mapping between the pages and the widgets that will be laid out on them |
| 100 | private ArrayList<ArrayList<AppWidgetProviderInfo>> mWidgetPages; |
| 101 | |
| 102 | // The max dimensions for the ImageView we use for displaying the widget |
| 103 | private int mMaxWidgetWidth; |
| 104 | |
| 105 | // The max number of widget cells to take a "page" of widget |
| 106 | private int mMaxWidgetsCellHSpan; |
| 107 | |
| 108 | // The raw sources of data for each of the different tabs of the customization page |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 109 | private List<AppWidgetProviderInfo> mWidgetList; |
| 110 | private List<ResolveInfo> mFolderList; |
| 111 | private List<ResolveInfo> mShortcutList; |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 112 | private List<ResolveInfo> mWallpaperList; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 113 | private List<ApplicationInfo> mApps; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 114 | |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 115 | private int mCellCountX; |
| 116 | private int mCellCountY; |
| 117 | private int mPageLayoutPaddingTop; |
| 118 | private int mPageLayoutPaddingBottom; |
| 119 | private int mPageLayoutPaddingLeft; |
| 120 | private int mPageLayoutPaddingRight; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 121 | private static final int sMinWidgetCellHSpan = 2; |
| 122 | private static final int sMaxWidgetCellHSpan = 4; |
| 123 | |
| 124 | // The scale factor for widget previews inside the widget drawer |
| 125 | private static final float sScaleFactor = 0.75f; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 126 | |
| 127 | private final Canvas mCanvas = new Canvas(); |
| 128 | private final LayoutInflater mInflater; |
| 129 | |
| 130 | public CustomizePagedView(Context context) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 131 | this(context, null, 0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | public CustomizePagedView(Context context, AttributeSet attrs) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 135 | this(context, attrs, 0); |
| 136 | } |
| 137 | |
| 138 | public CustomizePagedView(Context context, AttributeSet attrs, int defStyle) { |
| 139 | super(context, attrs, defStyle); |
| 140 | |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 141 | TypedArray a; |
| 142 | a = context.obtainStyledAttributes(attrs, R.styleable.CustomizePagedView, |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 143 | defStyle, 0); |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 144 | mMaxWidgetsCellHSpan = a.getInt(R.styleable.CustomizePagedView_widgetCellCountX, 8); |
| 145 | a.recycle(); |
| 146 | a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0); |
| 147 | mCellCountX = a.getInt(R.styleable.PagedView_cellCountX, 7); |
| 148 | mCellCountY = a.getInt(R.styleable.PagedView_cellCountY, 4); |
| 149 | mPageLayoutPaddingTop = a.getDimensionPixelSize( |
| 150 | R.styleable.PagedView_pageLayoutPaddingTop, 10); |
| 151 | mPageLayoutPaddingBottom = a.getDimensionPixelSize( |
| 152 | R.styleable.PagedView_pageLayoutPaddingBottom, 10); |
| 153 | mPageLayoutPaddingLeft = a.getDimensionPixelSize( |
| 154 | R.styleable.PagedView_pageLayoutPaddingLeft, 10); |
| 155 | mPageLayoutPaddingRight = a.getDimensionPixelSize( |
| 156 | R.styleable.PagedView_pageLayoutPaddingRight, 10); |
| 157 | a.recycle(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 158 | mCustomizationType = CustomizationType.WidgetCustomization; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 159 | mWidgetPages = new ArrayList<ArrayList<AppWidgetProviderInfo>>(); |
| 160 | mWorkspaceWidgetLayout = new PagedViewCellLayout(context); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 161 | mInflater = LayoutInflater.from(context); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 162 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 163 | setVisibility(View.GONE); |
| 164 | setSoundEffectsEnabled(false); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 165 | setupWorkspaceLayout(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | public void setLauncher(Launcher launcher) { |
| 169 | Context context = getContext(); |
| 170 | mLauncher = launcher; |
| 171 | mPackageManager = context.getPackageManager(); |
| 172 | } |
| 173 | |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 174 | /** |
| 175 | * Sets the list of applications that launcher has loaded. |
| 176 | */ |
| 177 | public void setApps(ArrayList<ApplicationInfo> list) { |
| 178 | mApps = list; |
| 179 | Collections.sort(mApps, LauncherModel.APP_NAME_COMPARATOR); |
| 180 | mPageViewIconCache.clear(); |
| 181 | invalidatePageData(); |
| 182 | } |
| 183 | |
| 184 | /** |
| 185 | * Convenience function to add new items to the set of applications that were previously loaded. |
| 186 | * Called by both updateApps() and setApps(). |
| 187 | */ |
| 188 | private void addAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 189 | // we add it in place, in alphabetical order |
| 190 | final int count = list.size(); |
| 191 | for (int i = 0; i < count; ++i) { |
| 192 | final ApplicationInfo info = list.get(i); |
| 193 | final int index = Collections.binarySearch(mApps, info, LauncherModel.APP_NAME_COMPARATOR); |
| 194 | if (index < 0) { |
| 195 | mApps.add(-(index + 1), info); |
| 196 | } |
| 197 | } |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * Adds new applications to the loaded list, and notifies the paged view to update itself. |
| 202 | */ |
| 203 | public void addApps(ArrayList<ApplicationInfo> list) { |
| 204 | addAppsWithoutInvalidate(list); |
| 205 | invalidatePageData(); |
| 206 | } |
| 207 | |
| 208 | /** |
| 209 | * Convenience function to remove items to the set of applications that were previously loaded. |
| 210 | * Called by both updateApps() and removeApps(). |
| 211 | */ |
| 212 | private void removeAppsWithoutInvalidate(ArrayList<ApplicationInfo> list) { |
| 213 | // loop through all the apps and remove apps that have the same component |
| 214 | final int length = list.size(); |
| 215 | for (int i = 0; i < length; ++i) { |
| 216 | final ApplicationInfo info = list.get(i); |
| 217 | int removeIndex = findAppByComponent(mApps, info); |
| 218 | if (removeIndex > -1) { |
| 219 | mApps.remove(removeIndex); |
| 220 | mPageViewIconCache.removeOutline(info); |
| 221 | } |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | /** |
| 226 | * Removes applications from the loaded list, and notifies the paged view to update itself. |
| 227 | */ |
| 228 | public void removeApps(ArrayList<ApplicationInfo> list) { |
| 229 | removeAppsWithoutInvalidate(list); |
| 230 | invalidatePageData(); |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Updates a set of applications from the loaded list, and notifies the paged view to update |
| 235 | * itself. |
| 236 | */ |
| 237 | public void updateApps(ArrayList<ApplicationInfo> list) { |
| 238 | // We remove and re-add the updated applications list because it's properties may have |
| 239 | // changed (ie. the title), and this will ensure that the items will be in their proper |
| 240 | // place in the list. |
| 241 | removeAppsWithoutInvalidate(list); |
| 242 | addAppsWithoutInvalidate(list); |
| 243 | invalidatePageData(); |
| 244 | } |
| 245 | |
| 246 | /** |
| 247 | * Convenience function to find matching ApplicationInfos for removal. |
| 248 | */ |
| 249 | private int findAppByComponent(List<ApplicationInfo> list, ApplicationInfo item) { |
| 250 | ComponentName removeComponent = item.intent.getComponent(); |
| 251 | final int length = list.size(); |
| 252 | for (int i = 0; i < length; ++i) { |
| 253 | ApplicationInfo info = list.get(i); |
| 254 | if (info.intent.getComponent().equals(removeComponent)) { |
| 255 | return i; |
| 256 | } |
| 257 | } |
| 258 | return -1; |
| 259 | } |
| 260 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 261 | public void update() { |
| 262 | Context context = getContext(); |
| 263 | |
| 264 | // get the list of widgets |
| 265 | mWidgetList = AppWidgetManager.getInstance(mLauncher).getInstalledProviders(); |
| 266 | Collections.sort(mWidgetList, new Comparator<AppWidgetProviderInfo>() { |
| 267 | @Override |
| 268 | public int compare(AppWidgetProviderInfo object1, AppWidgetProviderInfo object2) { |
| 269 | return object1.label.compareTo(object2.label); |
| 270 | } |
| 271 | }); |
| 272 | |
| 273 | Comparator<ResolveInfo> resolveInfoComparator = new Comparator<ResolveInfo>() { |
| 274 | @Override |
| 275 | public int compare(ResolveInfo object1, ResolveInfo object2) { |
| 276 | return object1.loadLabel(mPackageManager).toString().compareTo( |
| 277 | object2.loadLabel(mPackageManager).toString()); |
| 278 | } |
| 279 | }; |
| 280 | |
| 281 | // get the list of live folder intents |
| 282 | Intent liveFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER); |
| 283 | mFolderList = mPackageManager.queryIntentActivities(liveFolderIntent, 0); |
| 284 | |
| 285 | // manually create a separate entry for creating a folder in Launcher |
| 286 | ResolveInfo folder = new ResolveInfo(); |
| 287 | folder.icon = R.drawable.ic_launcher_folder; |
| 288 | folder.labelRes = R.string.group_folder; |
| 289 | folder.resolvePackageName = context.getPackageName(); |
| 290 | mFolderList.add(0, folder); |
| 291 | Collections.sort(mFolderList, resolveInfoComparator); |
| 292 | |
| 293 | // get the list of shortcuts |
| 294 | Intent shortcutsIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 295 | mShortcutList = mPackageManager.queryIntentActivities(shortcutsIntent, 0); |
| 296 | Collections.sort(mShortcutList, resolveInfoComparator); |
| 297 | |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 298 | // get the list of wallpapers |
| 299 | Intent wallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 300 | mWallpaperList = mPackageManager.queryIntentActivities(wallpapersIntent, 0); |
| 301 | Collections.sort(mWallpaperList, resolveInfoComparator); |
| 302 | |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 303 | // reset the icon cache |
| 304 | mPageViewIconCache.clear(); |
| 305 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 306 | // Refresh all the tabs |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 307 | invalidatePageData(); |
| 308 | } |
| 309 | |
| 310 | public void setDragController(DragController dragger) { |
| 311 | mDragController = dragger; |
| 312 | } |
| 313 | |
| 314 | public void setCustomizationFilter(CustomizationType filterType) { |
| 315 | mCustomizationType = filterType; |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 316 | setCurrentPage(0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 317 | invalidatePageData(); |
| 318 | } |
| 319 | |
| 320 | @Override |
| 321 | public void onDropCompleted(View target, boolean success) { |
| 322 | // do nothing |
| 323 | } |
| 324 | |
| 325 | @Override |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 326 | public void onClick(View v) { |
| 327 | if (!v.isInTouchMode()) { |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | final View animView = v; |
| 332 | switch (mCustomizationType) { |
| 333 | case WallpaperCustomization: |
| 334 | // animate some feedback to the long press |
| 335 | animateClickFeedback(v, new Runnable() { |
| 336 | @Override |
| 337 | public void run() { |
| 338 | // add the shortcut |
| 339 | ResolveInfo info = (ResolveInfo) animView.getTag(); |
Winson Chung | 24ab2f1 | 2010-09-16 14:10:47 -0700 | [diff] [blame] | 340 | Intent createWallpapersIntent = new Intent(Intent.ACTION_SET_WALLPAPER); |
| 341 | ComponentName name = new ComponentName(info.activityInfo.packageName, |
| 342 | info.activityInfo.name); |
| 343 | createWallpapersIntent.setComponent(name); |
| 344 | mLauncher.processWallpaper(createWallpapersIntent); |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 345 | } |
| 346 | }); |
| 347 | } |
| 348 | } |
| 349 | |
| 350 | @Override |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 351 | public boolean onLongClick(View v) { |
| 352 | if (!v.isInTouchMode()) { |
| 353 | return false; |
| 354 | } |
| 355 | |
| 356 | final View animView = v; |
| 357 | switch (mCustomizationType) { |
| 358 | case WidgetCustomization: |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 359 | // Get the icon as the drag representation |
| 360 | final LinearLayout l = (LinearLayout) animView; |
| 361 | final Drawable icon = ((ImageView) l.findViewById(R.id.icon)).getDrawable(); |
| 362 | Bitmap b = Bitmap.createBitmap(icon.getIntrinsicWidth(), icon.getIntrinsicHeight(), |
| 363 | Bitmap.Config.ARGB_8888); |
| 364 | Canvas c = new Canvas(b); |
| 365 | icon.draw(c); |
Michael Jurka | a63c452 | 2010-08-19 13:52:27 -0700 | [diff] [blame] | 366 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 367 | AppWidgetProviderInfo appWidgetInfo = (AppWidgetProviderInfo) v.getTag(); |
| 368 | LauncherAppWidgetInfo dragInfo = new LauncherAppWidgetInfo(appWidgetInfo.provider); |
| 369 | dragInfo.minWidth = appWidgetInfo.minWidth; |
| 370 | dragInfo.minHeight = appWidgetInfo.minHeight; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 371 | mDragController.startDrag(v, b, this, dragInfo, DragController.DRAG_ACTION_COPY, null); |
| 372 | |
| 373 | // Cleanup the icon |
| 374 | b.recycle(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 375 | return true; |
| 376 | case FolderCustomization: |
| 377 | // animate some feedback to the long press |
| 378 | animateClickFeedback(v, new Runnable() { |
| 379 | @Override |
| 380 | public void run() { |
| 381 | // add the folder |
| 382 | ResolveInfo resolveInfo = (ResolveInfo) animView.getTag(); |
| 383 | Intent createFolderIntent = new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER); |
| 384 | if (resolveInfo.labelRes == R.string.group_folder) { |
| 385 | // Create app shortcuts is a special built-in case of shortcuts |
| 386 | createFolderIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, |
| 387 | getContext().getString(R.string.group_folder)); |
| 388 | } else { |
| 389 | ComponentName name = new ComponentName(resolveInfo.activityInfo.packageName, |
| 390 | resolveInfo.activityInfo.name); |
| 391 | createFolderIntent.setComponent(name); |
| 392 | } |
| 393 | mLauncher.prepareAddItemFromHomeCustomizationDrawer(); |
| 394 | mLauncher.addLiveFolder(createFolderIntent); |
| 395 | } |
| 396 | }); |
| 397 | return true; |
| 398 | case ShortcutCustomization: |
| 399 | // animate some feedback to the long press |
| 400 | animateClickFeedback(v, new Runnable() { |
| 401 | @Override |
| 402 | public void run() { |
| 403 | // add the shortcut |
| 404 | ResolveInfo info = (ResolveInfo) animView.getTag(); |
| 405 | Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); |
| 406 | if (info.labelRes == R.string.group_applications) { |
| 407 | // Create app shortcuts is a special built-in case of shortcuts |
| 408 | createShortcutIntent.putExtra( |
| 409 | Intent.EXTRA_SHORTCUT_NAME,getContext().getString( |
| 410 | R.string.group_applications)); |
| 411 | } else { |
| 412 | ComponentName name = new ComponentName(info.activityInfo.packageName, |
| 413 | info.activityInfo.name); |
| 414 | createShortcutIntent.setComponent(name); |
| 415 | } |
| 416 | mLauncher.prepareAddItemFromHomeCustomizationDrawer(); |
| 417 | mLauncher.processShortcut(createShortcutIntent); |
| 418 | } |
| 419 | }); |
| 420 | return true; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 421 | case ApplicationCustomization: |
| 422 | // Pick up the application for dropping |
| 423 | ApplicationInfo app = (ApplicationInfo) v.getTag(); |
| 424 | app = new ApplicationInfo(app); |
| 425 | |
| 426 | mDragController.startDrag(v, this, app, DragController.DRAG_ACTION_COPY); |
| 427 | return true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 428 | } |
| 429 | return false; |
| 430 | } |
| 431 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 432 | /** |
| 433 | * Pre-processes the layout of the different widget pages. |
| 434 | * @return the number of pages of widgets that we have |
| 435 | */ |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 436 | private int relayoutWidgets() { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 437 | if (mWidgetList.isEmpty()) return 0; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 438 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 439 | // create a new page for the first set of widgets |
| 440 | ArrayList<AppWidgetProviderInfo> newPage = new ArrayList<AppWidgetProviderInfo>(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 441 | mWidgetPages.clear(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 442 | mWidgetPages.add(newPage); |
| 443 | |
| 444 | // do this until we have no more widgets to lay out |
| 445 | final int maxNumCellsPerRow = mMaxWidgetsCellHSpan; |
| 446 | final int widgetCount = mWidgetList.size(); |
| 447 | int numCellsInRow = 0; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 448 | for (int i = 0; i < widgetCount; ++i) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 449 | final AppWidgetProviderInfo info = mWidgetList.get(i); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 450 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 451 | // determine the size of the current widget |
| 452 | int cellSpanX = Math.max(sMinWidgetCellHSpan, Math.min(sMaxWidgetCellHSpan, |
| 453 | mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth))); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 454 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 455 | // create a new page if necessary |
| 456 | if ((numCellsInRow + cellSpanX) > maxNumCellsPerRow) { |
| 457 | numCellsInRow = 0; |
| 458 | newPage = new ArrayList<AppWidgetProviderInfo>(); |
| 459 | mWidgetPages.add(newPage); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 460 | } |
| 461 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 462 | // add the item to the current page |
| 463 | newPage.add(info); |
| 464 | numCellsInRow += cellSpanX; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 465 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 466 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 467 | return mWidgetPages.size(); |
| 468 | } |
| 469 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 470 | /** |
| 471 | * This method will extract the preview image specified by the widget developer (if it exists), |
| 472 | * otherwise, it will try to generate a default image preview with the widget's package icon. |
| 473 | * @return the drawable will be used and sized in the ImageView to represent the widget |
| 474 | */ |
| 475 | private Drawable getWidgetIcon(AppWidgetProviderInfo info) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 476 | PackageManager packageManager = mLauncher.getPackageManager(); |
| 477 | String packageName = info.provider.getPackageName(); |
| 478 | Drawable drawable = null; |
| 479 | if (info.previewImage != 0) { |
| 480 | drawable = packageManager.getDrawable(packageName, info.previewImage, null); |
| 481 | if (drawable == null) { |
| 482 | Log.w(TAG, "Can't load icon drawable 0x" + Integer.toHexString(info.icon) |
| 483 | + " for provider: " + info.provider); |
| 484 | } else { |
| 485 | return drawable; |
| 486 | } |
| 487 | } |
| 488 | |
| 489 | // If we don't have a preview image, create a default one |
| 490 | if (drawable == null) { |
| 491 | Resources resources = mLauncher.getResources(); |
| 492 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 493 | // Create a new bitmap to hold the widget preview |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 494 | final int minDim = mWorkspaceWidgetLayout.estimateCellWidth(1); |
| 495 | final int maxDim = mWorkspaceWidgetLayout.estimateCellWidth(3); |
| 496 | int width = (int) (Math.max(minDim, Math.min(maxDim, info.minWidth)) * sScaleFactor); |
| 497 | int height = (int) (Math.max(minDim, Math.min(maxDim, info.minHeight)) * sScaleFactor); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 498 | Bitmap bitmap = Bitmap.createBitmap(width, height, Config.ARGB_8888); |
| 499 | mCanvas.setBitmap(bitmap); |
| 500 | // For some reason, we must re-set the clip rect here, otherwise it will be wrong |
| 501 | mCanvas.clipRect(0, 0, width, height, Op.REPLACE); |
| 502 | |
| 503 | Drawable background = resources.getDrawable(R.drawable.default_widget_preview); |
| 504 | background.setBounds(0, 0, width, height); |
| 505 | background.draw(mCanvas); |
| 506 | |
| 507 | // Draw the icon vertically centered, flush left |
| 508 | try { |
| 509 | Rect tmpRect = new Rect(); |
| 510 | Drawable icon = null; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 511 | if (info.icon > 0) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 512 | icon = packageManager.getDrawable(packageName, info.icon, null); |
| 513 | } else { |
| 514 | icon = resources.getDrawable(R.drawable.ic_launcher_application); |
| 515 | } |
| 516 | background.getPadding(tmpRect); |
| 517 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 518 | final int iconSize = minDim / 2; |
| 519 | final int offset = iconSize / 4; |
| 520 | icon.setBounds(new Rect(offset, offset, offset + iconSize, offset + iconSize)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 521 | icon.draw(mCanvas); |
| 522 | } catch (Resources.NotFoundException e) { |
| 523 | // if we can't find the icon, then just don't draw it |
| 524 | } |
| 525 | |
Winson Chung | b3347bb | 2010-08-19 14:51:28 -0700 | [diff] [blame] | 526 | drawable = new FastBitmapDrawable(bitmap); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 527 | } |
| 528 | drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight()); |
| 529 | return drawable; |
| 530 | } |
| 531 | |
| 532 | private void setupPage(PagedViewCellLayout layout) { |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 533 | layout.setCellCount(mCellCountX, mCellCountY); |
| 534 | layout.setPadding(mPageLayoutPaddingLeft, mPageLayoutPaddingTop, mPageLayoutPaddingRight, |
| 535 | mPageLayoutPaddingBottom); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 536 | } |
| 537 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 538 | private void setupWorkspaceLayout() { |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 539 | mWorkspaceWidgetLayout.setCellCount(mCellCountX, mCellCountY); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 540 | mWorkspaceWidgetLayout.setPadding(20, 10, 20, 0); |
| 541 | |
| 542 | mMaxWidgetWidth = mWorkspaceWidgetLayout.estimateCellWidth(sMaxWidgetCellHSpan); |
| 543 | } |
| 544 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 545 | private void syncWidgetPages() { |
| 546 | if (mWidgetList == null) return; |
| 547 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 548 | // we need to repopulate with the LinearLayout layout for the widget pages |
| 549 | removeAllViews(); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 550 | int numPages = relayoutWidgets(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 551 | for (int i = 0; i < numPages; ++i) { |
| 552 | LinearLayout layout = new WidgetLayout(getContext()); |
| 553 | layout.setGravity(Gravity.CENTER_HORIZONTAL); |
| 554 | |
| 555 | // Temporary change to prevent the last page from being too small (and items bleeding |
| 556 | // onto it). We can remove this once we properly fix the fading algorithm |
| 557 | if (i < numPages - 1) { |
| 558 | addView(layout, new LinearLayout.LayoutParams( |
| 559 | LinearLayout.LayoutParams.WRAP_CONTENT, |
| 560 | LinearLayout.LayoutParams.MATCH_PARENT)); |
| 561 | } else { |
| 562 | addView(layout, new LinearLayout.LayoutParams( |
| 563 | LinearLayout.LayoutParams.MATCH_PARENT, |
| 564 | LinearLayout.LayoutParams.MATCH_PARENT)); |
| 565 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 566 | } |
| 567 | } |
| 568 | |
| 569 | private void syncWidgetPageItems(int page) { |
| 570 | // ensure that we have the right number of items on the pages |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 571 | LinearLayout layout = (LinearLayout) getChildAt(page); |
| 572 | final ArrayList<AppWidgetProviderInfo> list = mWidgetPages.get(page); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 573 | final int count = list.size(); |
| 574 | layout.removeAllViews(); |
| 575 | for (int i = 0; i < count; ++i) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 576 | AppWidgetProviderInfo info = (AppWidgetProviderInfo) list.get(i); |
| 577 | LinearLayout l = (LinearLayout) mInflater.inflate( |
| 578 | R.layout.customize_paged_view_widget, layout, false); |
| 579 | l.setTag(info); |
| 580 | l.setOnLongClickListener(this); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 581 | |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 582 | final Drawable icon = getWidgetIcon(info); |
| 583 | final int hSpan = mWorkspaceWidgetLayout.estimateCellHSpan(info.minWidth); |
| 584 | final int vSpan = mWorkspaceWidgetLayout.estimateCellHSpan(info.minHeight); |
| 585 | |
| 586 | ImageView image = (ImageView) l.findViewById(R.id.icon); |
| 587 | image.setMaxWidth(mMaxWidgetWidth); |
| 588 | image.setImageDrawable(icon); |
| 589 | TextView name = (TextView) l.findViewById(R.id.name); |
| 590 | name.setText(info.label); |
| 591 | TextView dims = (TextView) l.findViewById(R.id.dims); |
Winson Chung | 3a47678 | 2010-09-15 15:21:55 -0700 | [diff] [blame] | 592 | dims.setText(mContext.getString(R.string.widget_dims_format, hSpan, vSpan)); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 593 | |
| 594 | layout.addView(l); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 595 | } |
| 596 | } |
| 597 | |
| 598 | private void syncListPages(List<ResolveInfo> list) { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 599 | // we need to repopulate with PagedViewCellLayouts |
| 600 | removeAllViews(); |
| 601 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 602 | // ensure that we have the right number of pages |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 603 | int numPages = (int) Math.ceil((float) list.size() / (mCellCountX * mCellCountY)); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 604 | for (int i = 0; i < numPages; ++i) { |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 605 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 606 | setupPage(layout); |
| 607 | addView(layout); |
| 608 | } |
| 609 | } |
| 610 | |
| 611 | private void syncListPageItems(int page, List<ResolveInfo> list) { |
| 612 | // ensure that we have the right number of items on the pages |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 613 | int numCells = mCellCountX * mCellCountY; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 614 | int startIndex = page * numCells; |
| 615 | int endIndex = Math.min(startIndex + numCells, list.size()); |
| 616 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
| 617 | // TODO: we can optimize by just re-applying to existing views |
| 618 | layout.removeAllViews(); |
| 619 | for (int i = startIndex; i < endIndex; ++i) { |
| 620 | ResolveInfo info = list.get(i); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 621 | PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( |
| 622 | R.layout.customize_paged_view_item, layout, false); |
| 623 | icon.applyFromResolveInfo(info, mPackageManager, mPageViewIconCache); |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 624 | if (mCustomizationType == CustomizationType.WallpaperCustomization) { |
| 625 | icon.setOnClickListener(this); |
| 626 | } else { |
| 627 | icon.setOnLongClickListener(this); |
| 628 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 629 | |
| 630 | final int index = i - startIndex; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 631 | final int x = index % mCellCountX; |
| 632 | final int y = index / mCellCountX; |
| 633 | setupPage(layout); |
| 634 | layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); |
| 635 | } |
| 636 | } |
| 637 | |
| 638 | private void syncAppPages() { |
| 639 | if (mApps == null) return; |
| 640 | |
| 641 | // We need to repopulate with PagedViewCellLayouts |
| 642 | removeAllViews(); |
| 643 | |
| 644 | // Ensure that we have the right number of pages |
| 645 | int numPages = (int) Math.ceil((float) mApps.size() / (mCellCountX * mCellCountY)); |
| 646 | for (int i = 0; i < numPages; ++i) { |
| 647 | PagedViewCellLayout layout = new PagedViewCellLayout(getContext()); |
| 648 | setupPage(layout); |
| 649 | addView(layout); |
| 650 | } |
| 651 | } |
| 652 | |
| 653 | private void syncAppPageItems(int page) { |
| 654 | if (mApps == null) return; |
| 655 | |
| 656 | // ensure that we have the right number of items on the pages |
| 657 | int numCells = mCellCountX * mCellCountY; |
| 658 | int startIndex = page * numCells; |
| 659 | int endIndex = Math.min(startIndex + numCells, mApps.size()); |
| 660 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(page); |
| 661 | // TODO: we can optimize by just re-applying to existing views |
| 662 | layout.removeAllViews(); |
| 663 | for (int i = startIndex; i < endIndex; ++i) { |
| 664 | final ApplicationInfo info = mApps.get(i); |
| 665 | PagedViewIcon icon = (PagedViewIcon) mInflater.inflate( |
| 666 | R.layout.all_apps_paged_view_application, layout, false); |
| 667 | icon.applyFromApplicationInfo(info, mPageViewIconCache); |
| 668 | icon.setOnLongClickListener(this); |
| 669 | |
| 670 | final int index = i - startIndex; |
| 671 | final int x = index % mCellCountX; |
| 672 | final int y = index / mCellCountX; |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 673 | setupPage(layout); |
Winson Chung | 241c3b4 | 2010-08-25 16:53:03 -0700 | [diff] [blame] | 674 | layout.addViewToCellLayout(icon, -1, i, new PagedViewCellLayout.LayoutParams(x,y, 1,1)); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 675 | } |
| 676 | } |
| 677 | |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 678 | @Override |
| 679 | public void syncPages() { |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 680 | boolean centerPagedViewCellLayouts = false; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 681 | switch (mCustomizationType) { |
| 682 | case WidgetCustomization: |
| 683 | syncWidgetPages(); |
| 684 | break; |
| 685 | case FolderCustomization: |
| 686 | syncListPages(mFolderList); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 687 | centerPagedViewCellLayouts = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 688 | break; |
| 689 | case ShortcutCustomization: |
| 690 | syncListPages(mShortcutList); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 691 | centerPagedViewCellLayouts = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 692 | break; |
| 693 | case WallpaperCustomization: |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 694 | syncListPages(mWallpaperList); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 695 | centerPagedViewCellLayouts = true; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 696 | break; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 697 | case ApplicationCustomization: |
| 698 | syncAppPages(); |
| 699 | centerPagedViewCellLayouts = false; |
| 700 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 701 | default: |
| 702 | removeAllViews(); |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 703 | setCurrentPage(0); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 704 | break; |
| 705 | } |
| 706 | |
| 707 | // only try and center the page if there is one page |
| 708 | final int childCount = getChildCount(); |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 709 | if (centerPagedViewCellLayouts) { |
| 710 | if (childCount == 1) { |
| 711 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(0); |
| 712 | layout.enableCenteredContent(true); |
| 713 | } else { |
| 714 | for (int i = 0; i < childCount; ++i) { |
| 715 | PagedViewCellLayout layout = (PagedViewCellLayout) getChildAt(i); |
| 716 | layout.enableCenteredContent(false); |
| 717 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 718 | } |
| 719 | } |
| 720 | |
| 721 | // bound the current page |
Winson Chung | 86f7753 | 2010-08-24 11:08:22 -0700 | [diff] [blame] | 722 | setCurrentPage(Math.max(0, Math.min(childCount - 1, getCurrentPage()))); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 723 | } |
| 724 | |
| 725 | @Override |
| 726 | public void syncPageItems(int page) { |
| 727 | switch (mCustomizationType) { |
| 728 | case WidgetCustomization: |
| 729 | syncWidgetPageItems(page); |
| 730 | break; |
| 731 | case FolderCustomization: |
| 732 | syncListPageItems(page, mFolderList); |
| 733 | break; |
| 734 | case ShortcutCustomization: |
| 735 | syncListPageItems(page, mShortcutList); |
| 736 | break; |
| 737 | case WallpaperCustomization: |
Winson Chung | e8878e3 | 2010-09-15 20:37:09 -0700 | [diff] [blame] | 738 | syncListPageItems(page, mWallpaperList); |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 739 | break; |
Winson Chung | 5ffd8ea | 2010-09-23 18:40:29 -0700 | [diff] [blame^] | 740 | case ApplicationCustomization: |
| 741 | syncAppPageItems(page); |
| 742 | break; |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 743 | } |
| 744 | } |
Winson Chung | e3193b9 | 2010-09-10 11:44:42 -0700 | [diff] [blame] | 745 | |
| 746 | protected int getAssociatedLowerPageBound(int page) { |
| 747 | return 0; |
| 748 | } |
| 749 | protected int getAssociatedUpperPageBound(int page) { |
| 750 | return getChildCount(); |
| 751 | } |
Winson Chung | 80baf5a | 2010-08-09 16:03:15 -0700 | [diff] [blame] | 752 | } |