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