Launcher.java revision b1254a6bdb11024042fb6c27e179210c1bbd6e1c
1 2/* 3 * Copyright (C) 2008 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18package com.android.launcher2; 19 20import android.animation.Animator; 21import android.animation.AnimatorListenerAdapter; 22import android.animation.ValueAnimator; 23import com.android.common.Search; 24import com.android.launcher.R; 25 26import android.animation.ObjectAnimator; 27import android.animation.PropertyValuesHolder; 28import android.animation.AnimatorSet; 29import android.app.Activity; 30import android.app.AlertDialog; 31import android.app.Dialog; 32import android.app.SearchManager; 33import android.app.StatusBarManager; 34import android.app.WallpaperManager; 35import android.appwidget.AppWidgetManager; 36import android.appwidget.AppWidgetProviderInfo; 37import android.content.ActivityNotFoundException; 38import android.content.BroadcastReceiver; 39import android.content.ComponentName; 40import android.content.ContentResolver; 41import android.content.Context; 42import android.content.DialogInterface; 43import android.content.Intent; 44import android.content.Intent.ShortcutIconResource; 45import android.content.IntentFilter; 46import android.content.pm.ActivityInfo; 47import android.content.pm.PackageManager; 48import android.content.pm.PackageManager.NameNotFoundException; 49import android.content.pm.ResolveInfo; 50import android.content.res.Configuration; 51import android.content.res.Resources; 52import android.content.res.TypedArray; 53import android.database.ContentObserver; 54import android.graphics.Bitmap; 55import android.graphics.Canvas; 56import android.graphics.Color; 57import android.graphics.Rect; 58import android.graphics.drawable.ColorDrawable; 59import android.graphics.drawable.Drawable; 60import android.net.Uri; 61import android.os.AsyncTask; 62import android.os.Bundle; 63import android.os.Handler; 64import android.os.Parcelable; 65import android.os.SystemClock; 66import android.os.SystemProperties; 67import android.provider.LiveFolders; 68import android.provider.Settings; 69import android.text.Selection; 70import android.text.SpannableStringBuilder; 71import android.text.TextUtils; 72import android.text.method.TextKeyListener; 73import android.util.Log; 74import android.view.Display; 75import android.view.HapticFeedbackConstants; 76import android.view.KeyEvent; 77import android.view.LayoutInflater; 78import android.view.Menu; 79import android.view.MenuItem; 80import android.view.MotionEvent; 81import android.view.View; 82import android.view.View.OnLongClickListener; 83import android.view.ViewGroup; 84import android.view.WindowManager; 85import android.view.animation.AccelerateInterpolator; 86import android.view.animation.DecelerateInterpolator; 87import android.view.inputmethod.InputMethodManager; 88import android.widget.EditText; 89import android.widget.ImageView; 90import android.widget.LinearLayout; 91import android.widget.PopupWindow; 92import android.widget.RelativeLayout; 93import android.widget.TabHost; 94import android.widget.TabHost.OnTabChangeListener; 95import android.widget.TabHost.TabContentFactory; 96import android.widget.TabWidget; 97import android.widget.TextView; 98import android.widget.Toast; 99 100import java.io.DataInputStream; 101import java.io.DataOutputStream; 102import java.io.FileNotFoundException; 103import java.io.IOException; 104import java.util.ArrayList; 105import java.util.HashMap; 106import java.util.List; 107 108/** 109 * Default launcher application. 110 */ 111public final class Launcher extends Activity 112 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, 113 AllAppsView.Watcher, View.OnTouchListener { 114 static final String TAG = "Launcher"; 115 static final boolean LOGD = false; 116 117 static final boolean PROFILE_STARTUP = false; 118 static final boolean DEBUG_WIDGETS = false; 119 static final boolean DEBUG_USER_INTERFACE = false; 120 121 private static final int WALLPAPER_SCREENS_SPAN = 2; 122 123 private static final int MENU_GROUP_ADD = 1; 124 private static final int MENU_GROUP_WALLPAPER = MENU_GROUP_ADD + 1; 125 126 private static final int MENU_ADD = Menu.FIRST + 1; 127 private static final int MENU_WALLPAPER_SETTINGS = MENU_ADD + 1; 128 private static final int MENU_SEARCH = MENU_WALLPAPER_SETTINGS + 1; 129 private static final int MENU_NOTIFICATIONS = MENU_SEARCH + 1; 130 private static final int MENU_SETTINGS = MENU_NOTIFICATIONS + 1; 131 132 private static final int REQUEST_CREATE_SHORTCUT = 1; 133 private static final int REQUEST_CREATE_LIVE_FOLDER = 4; 134 private static final int REQUEST_CREATE_APPWIDGET = 5; 135 private static final int REQUEST_PICK_APPLICATION = 6; 136 private static final int REQUEST_PICK_SHORTCUT = 7; 137 private static final int REQUEST_PICK_LIVE_FOLDER = 8; 138 private static final int REQUEST_PICK_APPWIDGET = 9; 139 private static final int REQUEST_PICK_WALLPAPER = 10; 140 141 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; 142 143 static final int SCREEN_COUNT = 5; 144 static final int DEFAULT_SCREEN = 2; 145 146 static final int DIALOG_CREATE_SHORTCUT = 1; 147 static final int DIALOG_RENAME_FOLDER = 2; 148 149 private static final String PREFERENCES = "launcher.preferences"; 150 151 // Type: int 152 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; 153 // Type: boolean 154 private static final String RUNTIME_STATE_ALL_APPS_FOLDER = "launcher.all_apps_folder"; 155 // Type: long 156 private static final String RUNTIME_STATE_USER_FOLDERS = "launcher.user_folder"; 157 // Type: int 158 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; 159 // Type: int 160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cellX"; 161 // Type: int 162 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cellY"; 163 // Type: int 164 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_X = "launcher.add_spanX"; 165 // Type: int 166 private static final String RUNTIME_STATE_PENDING_ADD_SPAN_Y = "launcher.add_spanY"; 167 // Type: int 168 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_X = "launcher.add_countX"; 169 // Type: int 170 private static final String RUNTIME_STATE_PENDING_ADD_COUNT_Y = "launcher.add_countY"; 171 // Type: int[] 172 private static final String RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS = "launcher.add_occupied_cells"; 173 // Type: boolean 174 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; 175 // Type: long 176 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; 177 178 // tags for the customization tabs 179 private static final String WIDGETS_TAG = "widgets"; 180 private static final String FOLDERS_TAG = "folders"; 181 private static final String SHORTCUTS_TAG = "shortcuts"; 182 private static final String WALLPAPERS_TAG = "wallpapers"; 183 184 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; 185 186 /** The different states that Launcher can be in. */ 187 private enum State { WORKSPACE, ALL_APPS, CUSTOMIZE, OVERVIEW }; 188 189 static final int APPWIDGET_HOST_ID = 1024; 190 191 private static final Object sLock = new Object(); 192 private static int sScreen = DEFAULT_SCREEN; 193 194 private final BroadcastReceiver mCloseSystemDialogsReceiver 195 = new CloseSystemDialogsIntentReceiver(); 196 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); 197 198 private LayoutInflater mInflater; 199 200 private DragController mDragController; 201 private Workspace mWorkspace; 202 203 private AppWidgetManager mAppWidgetManager; 204 private LauncherAppWidgetHost mAppWidgetHost; 205 206 private CellLayout.CellInfo mAddItemCellInfo; 207 private int[] mAddItemCoordinates; 208 private CellLayout.CellInfo mMenuAddInfo; 209 private final int[] mCellCoordinates = new int[2]; 210 private FolderInfo mFolderInfo; 211 212 private DeleteZone mDeleteZone; 213 private HandleView mHandleView; 214 private AllAppsView mAllAppsGrid; 215 private TabHost mHomeCustomizationDrawer; 216 private CustomizePagedView mCustomizePagedView; 217 218 private Bundle mSavedState; 219 220 private SpannableStringBuilder mDefaultKeySsb = null; 221 222 private boolean mWorkspaceLoading = true; 223 224 private boolean mPaused = true; 225 private boolean mRestoring; 226 private boolean mWaitingForResult; 227 228 private Bundle mSavedInstanceState; 229 230 private LauncherModel mModel; 231 private IconCache mIconCache; 232 233 private static LocaleConfiguration sLocaleConfiguration = null; 234 235 private ArrayList<ItemInfo> mDesktopItems = new ArrayList<ItemInfo>(); 236 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); 237 238 private ImageView mPreviousView; 239 private ImageView mNextView; 240 241 // Hotseats (quick-launch icons next to AllApps) 242 private String[] mHotseatConfig = null; 243 private Intent[] mHotseats = null; 244 private Drawable[] mHotseatIcons = null; 245 private CharSequence[] mHotseatLabels = null; 246 247 private Intent mAppMarketIntent = null; 248 249 @Override 250 protected void onCreate(Bundle savedInstanceState) { 251 super.onCreate(savedInstanceState); 252 253 if (LauncherApplication.isInPlaceRotationEnabled()) { 254 // hide the status bar (temporary until we get the status bar design figured out) 255 getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); 256 this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR); 257 } 258 259 LauncherApplication app = ((LauncherApplication)getApplication()); 260 mModel = app.setLauncher(this); 261 mIconCache = app.getIconCache(); 262 mDragController = new DragController(this); 263 mInflater = getLayoutInflater(); 264 265 mAppWidgetManager = AppWidgetManager.getInstance(this); 266 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); 267 mAppWidgetHost.startListening(); 268 269 if (PROFILE_STARTUP) { 270 android.os.Debug.startMethodTracing("/sdcard/launcher"); 271 } 272 273 loadHotseats(); 274 checkForLocaleChange(); 275 setWallpaperDimension(); 276 setContentView(R.layout.launcher); 277 mHomeCustomizationDrawer = (TabHost) findViewById(com.android.internal.R.id.tabhost); 278 if (mHomeCustomizationDrawer != null) { 279 mHomeCustomizationDrawer.setup(); 280 281 // share the same customization workspace across all the tabs 282 mCustomizePagedView = new CustomizePagedView(this); 283 TabContentFactory contentFactory = new TabContentFactory() { 284 public View createTabContent(String tag) { 285 return mCustomizePagedView; 286 } 287 }; 288 289 String widgetsLabel = getString(R.string.widgets_tab_label); 290 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WIDGETS_TAG) 291 .setIndicator(widgetsLabel).setContent(contentFactory)); 292 String foldersLabel = getString(R.string.folders_tab_label); 293 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(FOLDERS_TAG) 294 .setIndicator(foldersLabel).setContent(contentFactory)); 295 String shortcutsLabel = getString(R.string.shortcuts_tab_label); 296 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(SHORTCUTS_TAG) 297 .setIndicator(shortcutsLabel).setContent(contentFactory)); 298 String wallpapersLabel = getString(R.string.wallpapers_tab_label); 299 mHomeCustomizationDrawer.addTab(mHomeCustomizationDrawer.newTabSpec(WALLPAPERS_TAG) 300 .setIndicator(wallpapersLabel).setContent(contentFactory)); 301 302 // TEMP: just styling the tab widget to be a bit nicer until we get the actual 303 // new assets 304 TabWidget tabWidget = mHomeCustomizationDrawer.getTabWidget(); 305 for (int i = 0; i < tabWidget.getChildCount(); ++i) { 306 RelativeLayout tab = (RelativeLayout) tabWidget.getChildTabViewAt(i); 307 TextView text = (TextView) tab.getChildAt(1); 308 text.setTextSize(20.0f); 309 text.setPadding(20, 0, 20, 0); 310 text.setShadowLayer(1.0f, 0.0f, 1.0f, Color.BLACK); 311 tab.setBackgroundDrawable(null); 312 } 313 314 mHomeCustomizationDrawer.setOnTabChangedListener(new OnTabChangeListener() { 315 public void onTabChanged(String tabId) { 316 // animate the changing of the tab content by fading pages in and out 317 final int duration = 150; 318 final float alpha = mCustomizePagedView.getAlpha(); 319 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView, 320 "alpha", alpha, 0.0f); 321 alphaAnim.addListener(new AnimatorListenerAdapter() { 322 public void onAnimationEnd(Animator animation) { 323 String tag = mHomeCustomizationDrawer.getCurrentTabTag(); 324 if (tag == WIDGETS_TAG) { 325 mCustomizePagedView.setCustomizationFilter( 326 CustomizePagedView.CustomizationType.WidgetCustomization); 327 } else if (tag == FOLDERS_TAG) { 328 mCustomizePagedView.setCustomizationFilter( 329 CustomizePagedView.CustomizationType.FolderCustomization); 330 } else if (tag == SHORTCUTS_TAG) { 331 mCustomizePagedView.setCustomizationFilter( 332 CustomizePagedView.CustomizationType.ShortcutCustomization); 333 } else if (tag == WALLPAPERS_TAG) { 334 mCustomizePagedView.setCustomizationFilter( 335 CustomizePagedView.CustomizationType.WallpaperCustomization); 336 } 337 338 final float alpha = mCustomizePagedView.getAlpha(); 339 ValueAnimator alphaAnim = new ObjectAnimator(duration, mCustomizePagedView, 340 "alpha", alpha, 1.0f); 341 alphaAnim.start(); 342 } 343 }); 344 alphaAnim.start(); 345 } 346 }); 347 348 mHomeCustomizationDrawer.setCurrentTab(0); 349 } 350 setupViews(); 351 352 registerContentObservers(); 353 354 lockAllApps(); 355 356 mSavedState = savedInstanceState; 357 restoreState(mSavedState); 358 359 if (PROFILE_STARTUP) { 360 android.os.Debug.stopMethodTracing(); 361 } 362 363 if (!mRestoring) { 364 mModel.startLoader(this, true); 365 } 366 367 // For handling default keys 368 mDefaultKeySsb = new SpannableStringBuilder(); 369 Selection.setSelection(mDefaultKeySsb, 0); 370 371 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 372 registerReceiver(mCloseSystemDialogsReceiver, filter); 373 } 374 375 @Override 376 public void onConfigurationChanged(Configuration newConfig) { 377 // TODO Auto-generated method stub 378 super.onConfigurationChanged(newConfig); 379 } 380 381 private void checkForLocaleChange() { 382 if (sLocaleConfiguration == null) { 383 new AsyncTask<Void, Void, LocaleConfiguration>() { 384 @Override 385 protected LocaleConfiguration doInBackground(Void... unused) { 386 LocaleConfiguration localeConfiguration = new LocaleConfiguration(); 387 readConfiguration(Launcher.this, localeConfiguration); 388 return localeConfiguration; 389 } 390 391 @Override 392 protected void onPostExecute(LocaleConfiguration result) { 393 sLocaleConfiguration = result; 394 checkForLocaleChange(); // recursive, but now with a locale configuration 395 } 396 }.execute(); 397 return; 398 } 399 400 final Configuration configuration = getResources().getConfiguration(); 401 402 final String previousLocale = sLocaleConfiguration.locale; 403 final String locale = configuration.locale.toString(); 404 405 final int previousMcc = sLocaleConfiguration.mcc; 406 final int mcc = configuration.mcc; 407 408 final int previousMnc = sLocaleConfiguration.mnc; 409 final int mnc = configuration.mnc; 410 411 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; 412 413 if (localeChanged) { 414 sLocaleConfiguration.locale = locale; 415 sLocaleConfiguration.mcc = mcc; 416 sLocaleConfiguration.mnc = mnc; 417 418 mIconCache.flush(); 419 loadHotseats(); 420 421 final LocaleConfiguration localeConfiguration = sLocaleConfiguration; 422 new Thread("WriteLocaleConfiguration") { 423 public void run() { 424 writeConfiguration(Launcher.this, localeConfiguration); 425 } 426 }.start(); 427 } 428 } 429 430 private static class LocaleConfiguration { 431 public String locale; 432 public int mcc = -1; 433 public int mnc = -1; 434 } 435 436 private static void readConfiguration(Context context, LocaleConfiguration configuration) { 437 DataInputStream in = null; 438 try { 439 in = new DataInputStream(context.openFileInput(PREFERENCES)); 440 configuration.locale = in.readUTF(); 441 configuration.mcc = in.readInt(); 442 configuration.mnc = in.readInt(); 443 } catch (FileNotFoundException e) { 444 // Ignore 445 } catch (IOException e) { 446 // Ignore 447 } finally { 448 if (in != null) { 449 try { 450 in.close(); 451 } catch (IOException e) { 452 // Ignore 453 } 454 } 455 } 456 } 457 458 private static void writeConfiguration(Context context, LocaleConfiguration configuration) { 459 DataOutputStream out = null; 460 try { 461 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); 462 out.writeUTF(configuration.locale); 463 out.writeInt(configuration.mcc); 464 out.writeInt(configuration.mnc); 465 out.flush(); 466 } catch (FileNotFoundException e) { 467 // Ignore 468 } catch (IOException e) { 469 //noinspection ResultOfMethodCallIgnored 470 context.getFileStreamPath(PREFERENCES).delete(); 471 } finally { 472 if (out != null) { 473 try { 474 out.close(); 475 } catch (IOException e) { 476 // Ignore 477 } 478 } 479 } 480 } 481 482 static int getScreen() { 483 synchronized (sLock) { 484 return sScreen; 485 } 486 } 487 488 static void setScreen(int screen) { 489 synchronized (sLock) { 490 sScreen = screen; 491 } 492 } 493 494 private void setWallpaperDimension() { 495 WallpaperManager wpm = (WallpaperManager)getSystemService(WALLPAPER_SERVICE); 496 497 Display display = getWindowManager().getDefaultDisplay(); 498 // TODO: Put back when we decide about scrolling the wallpaper 499 // boolean isPortrait = display.getWidth() < display.getHeight(); 500 // final int width = isPortrait ? display.getWidth() : display.getHeight(); 501 // final int height = isPortrait ? display.getHeight() : display.getWidth(); 502 wpm.suggestDesiredDimensions(Math.max(display.getWidth(), display.getHeight()), 503 Math.max(display.getWidth(), display.getHeight())); 504 } 505 506 // Note: This doesn't do all the client-id magic that BrowserProvider does 507 // in Browser. (http://b/2425179) 508 private Uri getDefaultBrowserUri() { 509 String url = getString(R.string.default_browser_url); 510 if (url.indexOf("{CID}") != -1) { 511 url = url.replace("{CID}", "android-google"); 512 } 513 return Uri.parse(url); 514 } 515 516 // Load the Intent templates from arrays.xml to populate the hotseats. For 517 // each Intent, if it resolves to a single app, use that as the launch 518 // intent & use that app's label as the contentDescription. Otherwise, 519 // retain the ResolveActivity so the user can pick an app. 520 private void loadHotseats() { 521 if (mHotseatConfig == null) { 522 mHotseatConfig = getResources().getStringArray(R.array.hotseats); 523 if (mHotseatConfig.length > 0) { 524 mHotseats = new Intent[mHotseatConfig.length]; 525 mHotseatLabels = new CharSequence[mHotseatConfig.length]; 526 mHotseatIcons = new Drawable[mHotseatConfig.length]; 527 } else { 528 mHotseats = null; 529 mHotseatIcons = null; 530 mHotseatLabels = null; 531 } 532 533 TypedArray hotseatIconDrawables = getResources().obtainTypedArray(R.array.hotseat_icons); 534 for (int i=0; i<mHotseatConfig.length; i++) { 535 // load icon for this slot; currently unrelated to the actual activity 536 try { 537 mHotseatIcons[i] = hotseatIconDrawables.getDrawable(i); 538 } catch (ArrayIndexOutOfBoundsException ex) { 539 Log.w(TAG, "Missing hotseat_icons array item #" + i); 540 mHotseatIcons[i] = null; 541 } 542 } 543 hotseatIconDrawables.recycle(); 544 } 545 546 PackageManager pm = getPackageManager(); 547 for (int i=0; i<mHotseatConfig.length; i++) { 548 Intent intent = null; 549 if (mHotseatConfig[i].equals("*BROWSER*")) { 550 // magic value meaning "launch user's default web browser" 551 // replace it with a generic web request so we can see if there is indeed a default 552 String defaultUri = getString(R.string.default_browser_url); 553 intent = new Intent( 554 Intent.ACTION_VIEW, 555 ((defaultUri != null) 556 ? Uri.parse(defaultUri) 557 : getDefaultBrowserUri()) 558 ).addCategory(Intent.CATEGORY_BROWSABLE); 559 // note: if the user launches this without a default set, she 560 // will always be taken to the default URL above; this is 561 // unavoidable as we must specify a valid URL in order for the 562 // chooser to appear, and once the user selects something, that 563 // URL is unavoidably sent to the chosen app. 564 } else { 565 try { 566 intent = Intent.parseUri(mHotseatConfig[i], 0); 567 } catch (java.net.URISyntaxException ex) { 568 Log.w(TAG, "Invalid hotseat intent: " + mHotseatConfig[i]); 569 // bogus; leave intent=null 570 } 571 } 572 573 if (intent == null) { 574 mHotseats[i] = null; 575 mHotseatLabels[i] = getText(R.string.activity_not_found); 576 continue; 577 } 578 579 if (LOGD) { 580 Log.d(TAG, "loadHotseats: hotseat " + i 581 + " initial intent=[" 582 + intent.toUri(Intent.URI_INTENT_SCHEME) 583 + "]"); 584 } 585 586 ResolveInfo bestMatch = pm.resolveActivity(intent, PackageManager.MATCH_DEFAULT_ONLY); 587 List<ResolveInfo> allMatches = pm.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 588 if (LOGD) { 589 Log.d(TAG, "Best match for intent: " + bestMatch); 590 Log.d(TAG, "All matches: "); 591 for (ResolveInfo ri : allMatches) { 592 Log.d(TAG, " --> " + ri); 593 } 594 } 595 // did this resolve to a single app, or the resolver? 596 if (allMatches.size() == 0 || bestMatch == null) { 597 // can't find any activity to handle this. let's leave the 598 // intent as-is and let Launcher show a toast when it fails 599 // to launch. 600 mHotseats[i] = intent; 601 602 // set accessibility text to "Not installed" 603 mHotseatLabels[i] = getText(R.string.activity_not_found); 604 } else { 605 boolean found = false; 606 for (ResolveInfo ri : allMatches) { 607 if (bestMatch.activityInfo.name.equals(ri.activityInfo.name) 608 && bestMatch.activityInfo.applicationInfo.packageName 609 .equals(ri.activityInfo.applicationInfo.packageName)) { 610 found = true; 611 break; 612 } 613 } 614 615 if (!found) { 616 if (LOGD) Log.d(TAG, "Multiple options, no default yet"); 617 // the bestMatch is probably the ResolveActivity, meaning the 618 // user has not yet selected a default 619 // so: we'll keep the original intent for now 620 mHotseats[i] = intent; 621 622 // set the accessibility text to "Select shortcut" 623 mHotseatLabels[i] = getText(R.string.title_select_shortcut); 624 } else { 625 // we have an app! 626 // now reconstruct the intent to launch it through the front 627 // door 628 ComponentName com = new ComponentName( 629 bestMatch.activityInfo.applicationInfo.packageName, 630 bestMatch.activityInfo.name); 631 mHotseats[i] = new Intent(Intent.ACTION_MAIN).setComponent(com); 632 633 // load the app label for accessibility 634 mHotseatLabels[i] = bestMatch.activityInfo.loadLabel(pm); 635 } 636 } 637 638 if (LOGD) { 639 Log.d(TAG, "loadHotseats: hotseat " + i 640 + " final intent=[" 641 + ((mHotseats[i] == null) 642 ? "null" 643 : mHotseats[i].toUri(Intent.URI_INTENT_SCHEME)) 644 + "] label=[" + mHotseatLabels[i] 645 + "]" 646 ); 647 } 648 } 649 } 650 651 @Override 652 protected void onActivityResult(int requestCode, int resultCode, Intent data) { 653 mWaitingForResult = false; 654 655 // The pattern used here is that a user PICKs a specific application, 656 // which, depending on the target, might need to CREATE the actual target. 657 658 // For example, the user would PICK_SHORTCUT for "Music playlist", and we 659 // launch over to the Music app to actually CREATE_SHORTCUT. 660 661 if (resultCode == RESULT_OK && mAddItemCellInfo != null) { 662 switch (requestCode) { 663 case REQUEST_PICK_APPLICATION: 664 completeAddApplication(this, data, mAddItemCellInfo); 665 break; 666 case REQUEST_PICK_SHORTCUT: 667 processShortcut(data); 668 break; 669 case REQUEST_CREATE_SHORTCUT: 670 completeAddShortcut(data, mAddItemCellInfo); 671 break; 672 case REQUEST_PICK_LIVE_FOLDER: 673 addLiveFolder(data); 674 break; 675 case REQUEST_CREATE_LIVE_FOLDER: 676 completeAddLiveFolder(data, mAddItemCellInfo); 677 break; 678 case REQUEST_PICK_APPWIDGET: 679 addAppWidgetFromPick(data); 680 break; 681 case REQUEST_CREATE_APPWIDGET: 682 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 683 completeAddAppWidget(appWidgetId, mAddItemCellInfo); 684 break; 685 case REQUEST_PICK_WALLPAPER: 686 // We just wanted the activity result here so we can clear mWaitingForResult 687 break; 688 } 689 } else if ((requestCode == REQUEST_PICK_APPWIDGET || 690 requestCode == REQUEST_CREATE_APPWIDGET) && resultCode == RESULT_CANCELED && 691 data != null) { 692 // Clean up the appWidgetId if we canceled 693 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 694 if (appWidgetId != -1) { 695 mAppWidgetHost.deleteAppWidgetId(appWidgetId); 696 } 697 } 698 } 699 700 @Override 701 protected void onResume() { 702 super.onResume(); 703 704 mPaused = false; 705 706 if (mRestoring) { 707 mWorkspaceLoading = true; 708 mModel.startLoader(this, true); 709 mRestoring = false; 710 } 711 // When we resume Launcher, a different Activity might be responsible for the app 712 // market intent, so refresh the icon 713 updateAppMarketIcon(); 714 } 715 716 @Override 717 protected void onPause() { 718 super.onPause(); 719 // Some launcher layouts don't have a previous and next view 720 if (mPreviousView != null) { 721 dismissPreview(mPreviousView); 722 } 723 if (mNextView != null) { 724 dismissPreview(mNextView); 725 } 726 mDragController.cancelDrag(); 727 } 728 729 @Override 730 public Object onRetainNonConfigurationInstance() { 731 // Flag the loader to stop early before switching 732 mModel.stopLoader(); 733 mAllAppsGrid.surrender(); 734 return Boolean.TRUE; 735 } 736 737 // We can't hide the IME if it was forced open. So don't bother 738 /* 739 @Override 740 public void onWindowFocusChanged(boolean hasFocus) { 741 super.onWindowFocusChanged(hasFocus); 742 743 if (hasFocus) { 744 final InputMethodManager inputManager = (InputMethodManager) 745 getSystemService(Context.INPUT_METHOD_SERVICE); 746 WindowManager.LayoutParams lp = getWindow().getAttributes(); 747 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new 748 android.os.Handler()) { 749 protected void onReceiveResult(int resultCode, Bundle resultData) { 750 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); 751 } 752 }); 753 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); 754 } 755 } 756 */ 757 758 private boolean acceptFilter() { 759 final InputMethodManager inputManager = (InputMethodManager) 760 getSystemService(Context.INPUT_METHOD_SERVICE); 761 return !inputManager.isFullscreenMode(); 762 } 763 764 @Override 765 public boolean onKeyDown(int keyCode, KeyEvent event) { 766 boolean handled = super.onKeyDown(keyCode, event); 767 if (!handled && acceptFilter() && keyCode != KeyEvent.KEYCODE_ENTER) { 768 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, 769 keyCode, event); 770 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { 771 // something usable has been typed - start a search 772 // the typed text will be retrieved and cleared by 773 // showSearchDialog() 774 // If there are multiple keystrokes before the search dialog takes focus, 775 // onSearchRequested() will be called for every keystroke, 776 // but it is idempotent, so it's fine. 777 return onSearchRequested(); 778 } 779 } 780 781 // Eat the long press event so the keyboard doesn't come up. 782 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { 783 return true; 784 } 785 786 return handled; 787 } 788 789 private String getTypedText() { 790 return mDefaultKeySsb.toString(); 791 } 792 793 private void clearTypedText() { 794 mDefaultKeySsb.clear(); 795 mDefaultKeySsb.clearSpans(); 796 Selection.setSelection(mDefaultKeySsb, 0); 797 } 798 799 /** 800 * Restores the previous state, if it exists. 801 * 802 * @param savedState The previous state. 803 */ 804 private void restoreState(Bundle savedState) { 805 if (savedState == null) { 806 return; 807 } 808 809 final boolean allApps = savedState.getBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, false); 810 if (allApps) { 811 showAllApps(false); 812 } 813 814 final int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); 815 if (currentScreen > -1) { 816 mWorkspace.setCurrentPage(currentScreen); 817 } 818 819 final int addScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); 820 if (addScreen > -1) { 821 mAddItemCoordinates = null; 822 mAddItemCellInfo = new CellLayout.CellInfo(); 823 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; 824 addItemCellInfo.valid = true; 825 addItemCellInfo.screen = addScreen; 826 addItemCellInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); 827 addItemCellInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); 828 addItemCellInfo.spanX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_X); 829 addItemCellInfo.spanY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y); 830 addItemCellInfo.updateOccupiedCells( 831 savedState.getBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS), 832 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_X), 833 savedState.getInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y)); 834 mRestoring = true; 835 } 836 837 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); 838 if (renameFolder) { 839 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); 840 mFolderInfo = mModel.getFolderById(this, sFolders, id); 841 mRestoring = true; 842 } 843 } 844 845 /** 846 * Finds all the views we need and configure them properly. 847 */ 848 private void setupViews() { 849 final DragController dragController = mDragController; 850 851 DragLayer dragLayer = (DragLayer) findViewById(R.id.drag_layer); 852 dragLayer.setDragController(dragController); 853 854 mAllAppsGrid = (AllAppsView)dragLayer.findViewById(R.id.all_apps_view); 855 mAllAppsGrid.setLauncher(this); 856 mAllAppsGrid.setDragController(dragController); 857 ((View) mAllAppsGrid).setWillNotDraw(false); // We don't want a hole punched in our window. 858 // Manage focusability manually since this thing is always visible (in non-xlarge) 859 ((View) mAllAppsGrid).setFocusable(false); 860 861 if (LauncherApplication.isScreenXLarge()) { 862 // They need to be INVISIBLE initially so that they will be measured in the layout. 863 // Otherwise the animations are messed up when we show them for the first time. 864 ((View) mAllAppsGrid).setVisibility(View.INVISIBLE); 865 mHomeCustomizationDrawer.setVisibility(View.INVISIBLE); 866 } 867 868 mWorkspace = (Workspace) dragLayer.findViewById(R.id.workspace); 869 final Workspace workspace = mWorkspace; 870 workspace.setHapticFeedbackEnabled(false); 871 872 DeleteZone deleteZone = (DeleteZone) dragLayer.findViewById(R.id.delete_zone); 873 mDeleteZone = deleteZone; 874 875 View handleView = findViewById(R.id.all_apps_button); 876 if (handleView != null && handleView instanceof HandleView) { 877 // we don't use handle view in xlarge mode 878 mHandleView = (HandleView)handleView; 879 mHandleView.setLauncher(this); 880 mHandleView.setOnClickListener(this); 881 mHandleView.setOnLongClickListener(this); 882 } 883 884 if (mCustomizePagedView != null) { 885 mCustomizePagedView.setLauncher(this); 886 mCustomizePagedView.setDragController(dragController); 887 mCustomizePagedView.update(); 888 } else { 889 ImageView hotseatLeft = (ImageView) findViewById(R.id.hotseat_left); 890 hotseatLeft.setContentDescription(mHotseatLabels[0]); 891 hotseatLeft.setImageDrawable(mHotseatIcons[0]); 892 ImageView hotseatRight = (ImageView) findViewById(R.id.hotseat_right); 893 hotseatRight.setContentDescription(mHotseatLabels[1]); 894 hotseatRight.setImageDrawable(mHotseatIcons[1]); 895 896 mPreviousView = (ImageView) dragLayer.findViewById(R.id.previous_screen); 897 mNextView = (ImageView) dragLayer.findViewById(R.id.next_screen); 898 899 Drawable previous = mPreviousView.getDrawable(); 900 Drawable next = mNextView.getDrawable(); 901 mWorkspace.setIndicators(previous, next); 902 903 mPreviousView.setHapticFeedbackEnabled(false); 904 mPreviousView.setOnLongClickListener(this); 905 mNextView.setHapticFeedbackEnabled(false); 906 mNextView.setOnLongClickListener(this); 907 } 908 909 workspace.setOnLongClickListener(this); 910 workspace.setDragController(dragController); 911 workspace.setLauncher(this); 912 913 deleteZone.setLauncher(this); 914 deleteZone.setDragController(dragController); 915 int deleteZoneHandleId; 916 if (LauncherApplication.isScreenXLarge()) { 917 deleteZoneHandleId = R.id.all_apps_button; 918 } else { 919 deleteZoneHandleId = R.id.all_apps_button_cluster; 920 } 921 deleteZone.setHandle(findViewById(deleteZoneHandleId)); 922 dragController.addDragListener(deleteZone); 923 924 ApplicationInfoDropTarget infoButton = (ApplicationInfoDropTarget)findViewById(R.id.info_button); 925 if (infoButton != null) { 926 infoButton.setLauncher(this); 927 infoButton.setHandle(findViewById(R.id.configure_button)); 928 infoButton.setDragColor(getResources().getColor(R.color.app_info_filter)); 929 dragController.addDragListener(infoButton); 930 } 931 932 dragController.setDragScoller(workspace); 933 dragController.setScrollView(dragLayer); 934 dragController.setMoveTarget(workspace); 935 936 // The order here is bottom to top. 937 dragController.addDropTarget(workspace); 938 dragController.addDropTarget(deleteZone); 939 if (infoButton != null) { 940 dragController.addDropTarget(infoButton); 941 } 942 } 943 944 @SuppressWarnings({"UnusedDeclaration"}) 945 public void previousScreen(View v) { 946 if (!isAllAppsVisible()) { 947 mWorkspace.scrollLeft(); 948 } 949 } 950 951 @SuppressWarnings({"UnusedDeclaration"}) 952 public void nextScreen(View v) { 953 if (!isAllAppsVisible()) { 954 mWorkspace.scrollRight(); 955 } 956 } 957 958 @SuppressWarnings({"UnusedDeclaration"}) 959 public void launchHotSeat(View v) { 960 if (isAllAppsVisible()) return; 961 962 int index = -1; 963 if (v.getId() == R.id.hotseat_left) { 964 index = 0; 965 } else if (v.getId() == R.id.hotseat_right) { 966 index = 1; 967 } 968 969 // reload these every tap; you never know when they might change 970 loadHotseats(); 971 if (index >= 0 && index < mHotseats.length && mHotseats[index] != null) { 972 Intent intent = mHotseats[index]; 973 startActivitySafely( 974 mHotseats[index], 975 "hotseat" 976 ); 977 } 978 } 979 980 /** 981 * Creates a view representing a shortcut. 982 * 983 * @param info The data structure describing the shortcut. 984 * 985 * @return A View inflated from R.layout.application. 986 */ 987 View createShortcut(ShortcutInfo info) { 988 return createShortcut(R.layout.application, 989 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); 990 } 991 992 /** 993 * Creates a view representing a shortcut inflated from the specified resource. 994 * 995 * @param layoutResId The id of the XML layout used to create the shortcut. 996 * @param parent The group the shortcut belongs to. 997 * @param info The data structure describing the shortcut. 998 * 999 * @return A View inflated from layoutResId. 1000 */ 1001 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { 1002 TextView favorite = (TextView) mInflater.inflate(layoutResId, parent, false); 1003 1004 favorite.setCompoundDrawablesWithIntrinsicBounds(null, 1005 new FastBitmapDrawable(info.getIcon(mIconCache)), 1006 null, null); 1007 favorite.setText(info.title); 1008 favorite.setTag(info); 1009 favorite.setOnClickListener(this); 1010 1011 return favorite; 1012 } 1013 1014 /** 1015 * Add an application shortcut to the workspace. 1016 * 1017 * @param data The intent describing the application. 1018 * @param cellInfo The position on screen where to create the shortcut. 1019 */ 1020 void completeAddApplication(Context context, Intent data, CellLayout.CellInfo cellInfo) { 1021 cellInfo.screen = mWorkspace.getCurrentPage(); 1022 if (!findSingleSlot(cellInfo)) return; 1023 1024 final ShortcutInfo info = mModel.getShortcutInfo(context.getPackageManager(), 1025 data, context); 1026 1027 if (info != null) { 1028 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | 1029 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1030 info.container = ItemInfo.NO_ID; 1031 mWorkspace.addApplicationShortcut(info, cellInfo, isWorkspaceLocked()); 1032 } else { 1033 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data); 1034 } 1035 } 1036 1037 /** 1038 * Add a shortcut to the workspace. 1039 * 1040 * @param data The intent describing the shortcut. 1041 * @param cellInfo The position on screen where to create the shortcut. 1042 */ 1043 private void completeAddShortcut(Intent data, CellLayout.CellInfo cellInfo) { 1044 cellInfo.screen = mWorkspace.getCurrentPage(); 1045 if (!findSingleSlot(cellInfo)) return; 1046 1047 final ShortcutInfo info = mModel.addShortcut(this, data, cellInfo, false); 1048 1049 if (!mRestoring) { 1050 final View view = createShortcut(info); 1051 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, 1052 isWorkspaceLocked()); 1053 } 1054 } 1055 1056 1057 /** 1058 * Add a widget to the workspace. 1059 * 1060 * @param appWidgetId The app widget id 1061 * @param cellInfo The position on screen where to create the widget. 1062 */ 1063 private void completeAddAppWidget(int appWidgetId, CellLayout.CellInfo cellInfo) { 1064 AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 1065 1066 // Calculate the grid spans needed to fit this widget 1067 CellLayout layout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); 1068 int[] spans = layout.rectToCell(appWidgetInfo.minWidth, appWidgetInfo.minHeight, null); 1069 1070 // Try finding open space on Launcher screen 1071 // We have saved the position to which the widget was dragged-- this really only matters 1072 // if we are placing widgets on a "spring-loaded" screen 1073 final int[] xy = mCellCoordinates; 1074 1075 // For now, we don't save the coordinate where we dropped the icon because we're not 1076 // supporting spring-loaded mini-screens; however, leaving the ability to directly place 1077 // a widget on the home screen in case we want to add it in the future 1078 final int[] xyTouch = null; 1079 //final int[] xyTouch = mAddItemCoordinates; 1080 boolean findNearestVacantAreaFailed = false; 1081 if (xyTouch != null) { 1082 CellLayout screen = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); 1083 int[] result = screen.findNearestVacantArea( 1084 mAddItemCoordinates[0], mAddItemCoordinates[1], 1085 spans[0], spans[1], cellInfo, xy); 1086 findNearestVacantAreaFailed = (result == null); 1087 } 1088 1089 if (findNearestVacantAreaFailed || 1090 (xyTouch == null && !findSlot(cellInfo, xy, spans[0], spans[1]))) { 1091 if (appWidgetId != -1) mAppWidgetHost.deleteAppWidgetId(appWidgetId); 1092 return; 1093 } 1094 1095 // Build Launcher-specific widget info and save to database 1096 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId); 1097 launcherInfo.spanX = spans[0]; 1098 launcherInfo.spanY = spans[1]; 1099 1100 LauncherModel.addItemToDatabase(this, launcherInfo, 1101 LauncherSettings.Favorites.CONTAINER_DESKTOP, 1102 cellInfo.screen, xy[0], xy[1], false); 1103 1104 if (!mRestoring) { 1105 mDesktopItems.add(launcherInfo); 1106 1107 // Perform actual inflation because we're live 1108 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); 1109 1110 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); 1111 launcherInfo.hostView.setTag(launcherInfo); 1112 1113 mWorkspace.addInScreen(launcherInfo.hostView, cellInfo.screen, xy[0], xy[1], 1114 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); 1115 } 1116 } 1117 1118 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { 1119 mDesktopItems.remove(launcherInfo); 1120 launcherInfo.hostView = null; 1121 } 1122 1123 public LauncherAppWidgetHost getAppWidgetHost() { 1124 return mAppWidgetHost; 1125 } 1126 1127 void closeSystemDialogs() { 1128 getWindow().closeAllPanels(); 1129 1130 try { 1131 dismissDialog(DIALOG_CREATE_SHORTCUT); 1132 // Unlock the workspace if the dialog was showing 1133 } catch (Exception e) { 1134 // An exception is thrown if the dialog is not visible, which is fine 1135 } 1136 1137 try { 1138 dismissDialog(DIALOG_RENAME_FOLDER); 1139 // Unlock the workspace if the dialog was showing 1140 } catch (Exception e) { 1141 // An exception is thrown if the dialog is not visible, which is fine 1142 } 1143 1144 // Whatever we were doing is hereby canceled. 1145 mWaitingForResult = false; 1146 } 1147 1148 @Override 1149 protected void onNewIntent(Intent intent) { 1150 super.onNewIntent(intent); 1151 1152 // Close the menu 1153 if (Intent.ACTION_MAIN.equals(intent.getAction())) { 1154 // also will cancel mWaitingForResult. 1155 closeSystemDialogs(); 1156 1157 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) 1158 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 1159 boolean allAppsVisible = isAllAppsVisible(); 1160 boolean customizationDrawerVisible = isCustomizationDrawerVisible(); 1161 1162 // in all these cases, only animate if we're already on home 1163 if (LauncherApplication.isScreenXLarge()) { 1164 if (alreadyOnHome && !mWorkspace.isSmall() && 1165 !allAppsVisible && !customizationDrawerVisible) { 1166 mWorkspace.shrinkToMiddle(); 1167 } else { 1168 mWorkspace.unshrink(alreadyOnHome); 1169 } 1170 } else if (!mWorkspace.isDefaultPageShowing()) { 1171 // on the phone, we don't animate the change to the workspace if all apps is visible 1172 mWorkspace.moveToDefaultScreen(alreadyOnHome && !allAppsVisible); 1173 } 1174 closeAllApps(alreadyOnHome && allAppsVisible); 1175 hideCustomizationDrawer(alreadyOnHome); 1176 1177 final View v = getWindow().peekDecorView(); 1178 if (v != null && v.getWindowToken() != null) { 1179 InputMethodManager imm = (InputMethodManager)getSystemService( 1180 INPUT_METHOD_SERVICE); 1181 imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 1182 } 1183 } 1184 } 1185 1186 @Override 1187 protected void onRestoreInstanceState(Bundle savedInstanceState) { 1188 // Do not call super here 1189 mSavedInstanceState = savedInstanceState; 1190 1191 if (mHomeCustomizationDrawer != null) { 1192 String cur = savedInstanceState.getString("currentTab"); 1193 if (cur != null) { 1194 mHomeCustomizationDrawer.setCurrentTabByTag(cur); 1195 } 1196 } 1197 } 1198 1199 @Override 1200 protected void onSaveInstanceState(Bundle outState) { 1201 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); 1202 1203 final ArrayList<Folder> folders = mWorkspace.getOpenFolders(); 1204 if (folders.size() > 0) { 1205 final int count = folders.size(); 1206 long[] ids = new long[count]; 1207 for (int i = 0; i < count; i++) { 1208 final FolderInfo info = folders.get(i).getInfo(); 1209 ids[i] = info.id; 1210 } 1211 outState.putLongArray(RUNTIME_STATE_USER_FOLDERS, ids); 1212 } else { 1213 super.onSaveInstanceState(outState); 1214 } 1215 1216 // TODO should not do this if the drawer is currently closing. 1217 if (isAllAppsVisible()) { 1218 outState.putBoolean(RUNTIME_STATE_ALL_APPS_FOLDER, true); 1219 } 1220 1221 if (mAddItemCellInfo != null && mAddItemCellInfo.valid && mWaitingForResult) { 1222 final CellLayout.CellInfo addItemCellInfo = mAddItemCellInfo; 1223 final CellLayout layout = (CellLayout) mWorkspace.getChildAt(addItemCellInfo.screen); 1224 1225 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, addItemCellInfo.screen); 1226 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, addItemCellInfo.cellX); 1227 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, addItemCellInfo.cellY); 1228 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_X, addItemCellInfo.spanX); 1229 outState.putInt(RUNTIME_STATE_PENDING_ADD_SPAN_Y, addItemCellInfo.spanY); 1230 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_X, layout.getCountX()); 1231 outState.putInt(RUNTIME_STATE_PENDING_ADD_COUNT_Y, layout.getCountY()); 1232 outState.putBooleanArray(RUNTIME_STATE_PENDING_ADD_OCCUPIED_CELLS, 1233 layout.getOccupiedCellsFlattened()); 1234 } 1235 1236 if (mFolderInfo != null && mWaitingForResult) { 1237 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); 1238 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); 1239 } 1240 1241 if (mHomeCustomizationDrawer != null) { 1242 String currentTabTag = mHomeCustomizationDrawer.getCurrentTabTag(); 1243 if (currentTabTag != null) { 1244 outState.putString("currentTab", currentTabTag); 1245 } 1246 } 1247 } 1248 1249 @Override 1250 public void onDestroy() { 1251 super.onDestroy(); 1252 1253 try { 1254 mAppWidgetHost.stopListening(); 1255 } catch (NullPointerException ex) { 1256 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); 1257 } 1258 1259 TextKeyListener.getInstance().release(); 1260 1261 mModel.stopLoader(); 1262 1263 unbindDesktopItems(); 1264 1265 getContentResolver().unregisterContentObserver(mWidgetObserver); 1266 1267 // Some launcher layouts don't have a previous and next view 1268 if (mPreviousView != null) { 1269 dismissPreview(mPreviousView); 1270 } 1271 if (mNextView != null) { 1272 dismissPreview(mNextView); 1273 } 1274 1275 unregisterReceiver(mCloseSystemDialogsReceiver); 1276 } 1277 1278 @Override 1279 public void startActivityForResult(Intent intent, int requestCode) { 1280 if (requestCode >= 0) mWaitingForResult = true; 1281 super.startActivityForResult(intent, requestCode); 1282 } 1283 1284 @Override 1285 public void startSearch(String initialQuery, boolean selectInitialQuery, 1286 Bundle appSearchData, boolean globalSearch) { 1287 1288 closeAllApps(true); 1289 1290 if (initialQuery == null) { 1291 // Use any text typed in the launcher as the initial query 1292 initialQuery = getTypedText(); 1293 clearTypedText(); 1294 } 1295 if (appSearchData == null) { 1296 appSearchData = new Bundle(); 1297 appSearchData.putString(Search.SOURCE, "launcher-search"); 1298 } 1299 1300 final SearchManager searchManager = 1301 (SearchManager) getSystemService(Context.SEARCH_SERVICE); 1302 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), 1303 appSearchData, globalSearch); 1304 } 1305 1306 @Override 1307 public boolean onCreateOptionsMenu(Menu menu) { 1308 if (isWorkspaceLocked() || LauncherApplication.isScreenXLarge()) { 1309 return false; 1310 } 1311 1312 super.onCreateOptionsMenu(menu); 1313 1314 menu.add(MENU_GROUP_ADD, MENU_ADD, 0, R.string.menu_add) 1315 .setIcon(android.R.drawable.ic_menu_add) 1316 .setAlphabeticShortcut('A'); 1317 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) 1318 .setIcon(android.R.drawable.ic_menu_gallery) 1319 .setAlphabeticShortcut('W'); 1320 menu.add(0, MENU_SEARCH, 0, R.string.menu_search) 1321 .setIcon(android.R.drawable.ic_search_category_default) 1322 .setAlphabeticShortcut(SearchManager.MENU_KEY); 1323 menu.add(0, MENU_NOTIFICATIONS, 0, R.string.menu_notifications) 1324 .setIcon(com.android.internal.R.drawable.ic_menu_notifications) 1325 .setAlphabeticShortcut('N'); 1326 1327 final Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); 1328 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 1329 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1330 1331 menu.add(0, MENU_SETTINGS, 0, R.string.menu_settings) 1332 .setIcon(android.R.drawable.ic_menu_preferences).setAlphabeticShortcut('P') 1333 .setIntent(settings); 1334 1335 return true; 1336 } 1337 1338 @Override 1339 public boolean onPrepareOptionsMenu(Menu menu) { 1340 super.onPrepareOptionsMenu(menu); 1341 1342 // If all apps is animating, don't show the menu, because we don't know 1343 // which one to show. 1344 if (mAllAppsGrid.isAnimating()) { 1345 return false; 1346 } 1347 1348 // Only show the add and wallpaper options when we're not in all apps. 1349 boolean visible = !mAllAppsGrid.isVisible(); 1350 menu.setGroupVisible(MENU_GROUP_ADD, visible); 1351 menu.setGroupVisible(MENU_GROUP_WALLPAPER, visible); 1352 1353 // Disable add if the workspace is full. 1354 if (visible) { 1355 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null); 1356 menu.setGroupEnabled(MENU_GROUP_ADD, mMenuAddInfo != null && mMenuAddInfo.valid); 1357 } 1358 1359 return true; 1360 } 1361 1362 // we need to initialize mAddItemCellInfo before adding something to the homescreen -- when 1363 // using the settings menu to add an item, something similar happens in showAddDialog 1364 public void prepareAddItemFromHomeCustomizationDrawer() { 1365 mMenuAddInfo = mWorkspace.updateOccupiedCellsForCurrentScreen(null); 1366 mAddItemCellInfo = mMenuAddInfo; 1367 } 1368 1369 @Override 1370 public boolean onOptionsItemSelected(MenuItem item) { 1371 switch (item.getItemId()) { 1372 case MENU_ADD: 1373 addItems(); 1374 return true; 1375 case MENU_WALLPAPER_SETTINGS: 1376 startWallpaper(); 1377 return true; 1378 case MENU_SEARCH: 1379 onSearchRequested(); 1380 return true; 1381 case MENU_NOTIFICATIONS: 1382 showNotifications(); 1383 return true; 1384 } 1385 1386 return super.onOptionsItemSelected(item); 1387 } 1388 1389 /** 1390 * Indicates that we want global search for this activity by setting the globalSearch 1391 * argument for {@link #startSearch} to true. 1392 */ 1393 1394 @Override 1395 public boolean onSearchRequested() { 1396 startSearch(null, false, null, true); 1397 return true; 1398 } 1399 1400 public boolean isWorkspaceLocked() { 1401 return mWorkspaceLoading || mWaitingForResult; 1402 } 1403 1404 private void addItems() { 1405 if (LauncherApplication.isScreenXLarge()) { 1406 // Animate the widget chooser up from the bottom of the screen 1407 if (!isCustomizationDrawerVisible()) { 1408 showCustomizationDrawer(true); 1409 } 1410 } else { 1411 closeAllApps(true); 1412 showAddDialog(mMenuAddInfo); 1413 } 1414 } 1415 1416 void addAppWidgetFromDrop(ComponentName appWidgetProvider, CellLayout.CellInfo cellInfo, 1417 int[] position) { 1418 mAddItemCellInfo = cellInfo; 1419 1420 // only set mAddItemCoordinates if we dropped on home screen in "spring-loaded" manner 1421 mAddItemCoordinates = position; 1422 int appWidgetId = getAppWidgetHost().allocateAppWidgetId(); 1423 AppWidgetManager.getInstance(this).bindAppWidgetId(appWidgetId, appWidgetProvider); 1424 addAppWidgetImpl(appWidgetId); 1425 } 1426 1427 void addAppWidgetFromPick(Intent data) { 1428 // TODO: catch bad widget exception when sent 1429 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 1430 // TODO: Is this log message meaningful? 1431 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); 1432 addAppWidgetImpl(appWidgetId); 1433 } 1434 1435 void addAppWidgetImpl(int appWidgetId) { 1436 AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 1437 1438 if (appWidget.configure != null) { 1439 // Launch over to configure widget, if needed 1440 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); 1441 intent.setComponent(appWidget.configure); 1442 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 1443 1444 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); 1445 } else { 1446 // Otherwise just add it 1447 completeAddAppWidget(appWidgetId, mAddItemCellInfo); 1448 } 1449 } 1450 1451 void processShortcut(Intent intent) { 1452 // Handle case where user selected "Applications" 1453 String applicationName = getResources().getString(R.string.group_applications); 1454 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); 1455 1456 if (applicationName != null && applicationName.equals(shortcutName)) { 1457 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 1458 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 1459 1460 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); 1461 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); 1462 startActivityForResult(pickIntent, REQUEST_PICK_APPLICATION); 1463 } else { 1464 startActivityForResult(intent, REQUEST_CREATE_SHORTCUT); 1465 } 1466 } 1467 1468 void addLiveFolder(Intent intent) { 1469 // Handle case where user selected "Folder" 1470 String folderName = getResources().getString(R.string.group_folder); 1471 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); 1472 1473 if (folderName != null && folderName.equals(shortcutName)) { 1474 addFolder(); 1475 } else { 1476 startActivityForResult(intent, REQUEST_CREATE_LIVE_FOLDER); 1477 } 1478 } 1479 1480 void addFolder() { 1481 UserFolderInfo folderInfo = new UserFolderInfo(); 1482 folderInfo.title = getText(R.string.folder_name); 1483 1484 CellLayout.CellInfo cellInfo = mAddItemCellInfo; 1485 cellInfo.screen = mWorkspace.getCurrentPage(); 1486 if (!findSingleSlot(cellInfo)) return; 1487 1488 // Update the model 1489 LauncherModel.addItemToDatabase(this, folderInfo, 1490 LauncherSettings.Favorites.CONTAINER_DESKTOP, 1491 mWorkspace.getCurrentPage(), cellInfo.cellX, cellInfo.cellY, false); 1492 sFolders.put(folderInfo.id, folderInfo); 1493 1494 // Create the view 1495 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, 1496 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), folderInfo); 1497 mWorkspace.addInCurrentScreen(newFolder, 1498 cellInfo.cellX, cellInfo.cellY, 1, 1, isWorkspaceLocked()); 1499 } 1500 1501 void removeFolder(FolderInfo folder) { 1502 sFolders.remove(folder.id); 1503 } 1504 1505 private void completeAddLiveFolder(Intent data, CellLayout.CellInfo cellInfo) { 1506 cellInfo.screen = mWorkspace.getCurrentPage(); 1507 if (!findSingleSlot(cellInfo)) return; 1508 1509 final LiveFolderInfo info = addLiveFolder(this, data, cellInfo, false); 1510 1511 if (!mRestoring) { 1512 final View view = LiveFolderIcon.fromXml(R.layout.live_folder_icon, this, 1513 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); 1514 mWorkspace.addInCurrentScreen(view, cellInfo.cellX, cellInfo.cellY, 1, 1, 1515 isWorkspaceLocked()); 1516 } 1517 } 1518 1519 static LiveFolderInfo addLiveFolder(Context context, Intent data, 1520 CellLayout.CellInfo cellInfo, boolean notify) { 1521 1522 Intent baseIntent = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_BASE_INTENT); 1523 String name = data.getStringExtra(LiveFolders.EXTRA_LIVE_FOLDER_NAME); 1524 1525 Drawable icon = null; 1526 Intent.ShortcutIconResource iconResource = null; 1527 1528 Parcelable extra = data.getParcelableExtra(LiveFolders.EXTRA_LIVE_FOLDER_ICON); 1529 if (extra != null && extra instanceof Intent.ShortcutIconResource) { 1530 try { 1531 iconResource = (Intent.ShortcutIconResource) extra; 1532 final PackageManager packageManager = context.getPackageManager(); 1533 Resources resources = packageManager.getResourcesForApplication( 1534 iconResource.packageName); 1535 final int id = resources.getIdentifier(iconResource.resourceName, null, null); 1536 icon = resources.getDrawable(id); 1537 } catch (Exception e) { 1538 Log.w(TAG, "Could not load live folder icon: " + extra); 1539 } 1540 } 1541 1542 if (icon == null) { 1543 icon = context.getResources().getDrawable(R.drawable.ic_launcher_folder); 1544 } 1545 1546 final LiveFolderInfo info = new LiveFolderInfo(); 1547 info.icon = Utilities.createIconBitmap(icon, context); 1548 info.title = name; 1549 info.iconResource = iconResource; 1550 info.uri = data.getData(); 1551 info.baseIntent = baseIntent; 1552 info.displayMode = data.getIntExtra(LiveFolders.EXTRA_LIVE_FOLDER_DISPLAY_MODE, 1553 LiveFolders.DISPLAY_MODE_GRID); 1554 1555 LauncherModel.addItemToDatabase(context, info, LauncherSettings.Favorites.CONTAINER_DESKTOP, 1556 cellInfo.screen, cellInfo.cellX, cellInfo.cellY, notify); 1557 sFolders.put(info.id, info); 1558 1559 return info; 1560 } 1561 1562 private boolean findSingleSlot(CellLayout.CellInfo cellInfo) { 1563 final int[] xy = new int[2]; 1564 if (findSlot(cellInfo, xy, 1, 1)) { 1565 cellInfo.cellX = xy[0]; 1566 cellInfo.cellY = xy[1]; 1567 return true; 1568 } 1569 return false; 1570 } 1571 1572 private boolean findSlot(CellLayout.CellInfo cellInfo, int[] xy, int spanX, int spanY) { 1573 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { 1574 CellLayout targetLayout = (CellLayout) mWorkspace.getChildAt(cellInfo.screen); 1575 cellInfo = targetLayout.updateOccupiedCells(null, null); 1576 if (!cellInfo.findCellForSpan(xy, spanX, spanY)) { 1577 Toast.makeText(this, getString(R.string.out_of_space), Toast.LENGTH_SHORT).show(); 1578 return false; 1579 } 1580 } 1581 return true; 1582 } 1583 1584 private void showNotifications() { 1585 final StatusBarManager statusBar = (StatusBarManager) getSystemService(STATUS_BAR_SERVICE); 1586 if (statusBar != null) { 1587 statusBar.expand(); 1588 } 1589 } 1590 1591 private void startWallpaper() { 1592 closeAllApps(true); 1593 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); 1594 Intent chooser = Intent.createChooser(pickWallpaper, 1595 getText(R.string.chooser_wallpaper)); 1596 // NOTE: Adds a configure option to the chooser if the wallpaper supports it 1597 // Removed in Eclair MR1 1598// WallpaperManager wm = (WallpaperManager) 1599// getSystemService(Context.WALLPAPER_SERVICE); 1600// WallpaperInfo wi = wm.getWallpaperInfo(); 1601// if (wi != null && wi.getSettingsActivity() != null) { 1602// LabeledIntent li = new LabeledIntent(getPackageName(), 1603// R.string.configure_wallpaper, 0); 1604// li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); 1605// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); 1606// } 1607 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); 1608 } 1609 1610 /** 1611 * Registers various content observers. The current implementation registers 1612 * only a favorites observer to keep track of the favorites applications. 1613 */ 1614 private void registerContentObservers() { 1615 ContentResolver resolver = getContentResolver(); 1616 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, 1617 true, mWidgetObserver); 1618 } 1619 1620 @Override 1621 public boolean dispatchKeyEvent(KeyEvent event) { 1622 if (event.getAction() == KeyEvent.ACTION_DOWN) { 1623 switch (event.getKeyCode()) { 1624 case KeyEvent.KEYCODE_HOME: 1625 return true; 1626 case KeyEvent.KEYCODE_VOLUME_DOWN: 1627 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { 1628 dumpState(); 1629 return true; 1630 } 1631 break; 1632 } 1633 } else if (event.getAction() == KeyEvent.ACTION_UP) { 1634 switch (event.getKeyCode()) { 1635 case KeyEvent.KEYCODE_HOME: 1636 return true; 1637 } 1638 } 1639 1640 return super.dispatchKeyEvent(event); 1641 } 1642 1643 @Override 1644 public void onBackPressed() { 1645 if (isAllAppsVisible()) { 1646 closeAllApps(true); 1647 } else if (isCustomizationDrawerVisible()) { 1648 hideCustomizationDrawer(true); 1649 } else { 1650 closeFolder(); 1651 } 1652 // Some launcher layouts don't have a previous and next view 1653 if (mPreviousView != null) { 1654 dismissPreview(mPreviousView); 1655 dismissPreview(mNextView); 1656 } 1657 } 1658 1659 private void closeFolder() { 1660 Folder folder = mWorkspace.getOpenFolder(); 1661 if (folder != null) { 1662 closeFolder(folder); 1663 } 1664 } 1665 1666 void closeFolder(Folder folder) { 1667 folder.getInfo().opened = false; 1668 ViewGroup parent = (ViewGroup) folder.getParent(); 1669 if (parent != null) { 1670 parent.removeView(folder); 1671 if (folder instanceof DropTarget) { 1672 // Live folders aren't DropTargets. 1673 mDragController.removeDropTarget((DropTarget)folder); 1674 } 1675 } 1676 folder.onClose(); 1677 } 1678 1679 /** 1680 * Re-listen when widgets are reset. 1681 */ 1682 private void onAppWidgetReset() { 1683 mAppWidgetHost.startListening(); 1684 } 1685 1686 /** 1687 * Go through the and disconnect any of the callbacks in the drawables and the views or we 1688 * leak the previous Home screen on orientation change. 1689 */ 1690 private void unbindDesktopItems() { 1691 for (ItemInfo item: mDesktopItems) { 1692 item.unbind(); 1693 } 1694 } 1695 1696 /** 1697 * Launches the intent referred by the clicked shortcut. 1698 * 1699 * @param v The view representing the clicked shortcut. 1700 */ 1701 public void onClick(View v) { 1702 Object tag = v.getTag(); 1703 if (tag instanceof ShortcutInfo) { 1704 // Open shortcut 1705 final Intent intent = ((ShortcutInfo) tag).intent; 1706 int[] pos = new int[2]; 1707 v.getLocationOnScreen(pos); 1708 intent.setSourceBounds(new Rect(pos[0], pos[1], 1709 pos[0] + v.getWidth(), pos[1] + v.getHeight())); 1710 startActivitySafely(intent, tag); 1711 } else if (tag instanceof FolderInfo) { 1712 handleFolderClick((FolderInfo) tag); 1713 } else if (v == mHandleView) { 1714 if (isAllAppsVisible()) { 1715 closeAllApps(true); 1716 } else { 1717 showAllApps(true); 1718 } 1719 } 1720 } 1721 1722 public boolean onTouch(View v, MotionEvent event) { 1723 // this is an intercepted event being forwarded from mWorkspace; 1724 // clicking anywhere on the workspace causes the drawer to slide down 1725 hideCustomizationDrawer(true); 1726 return false; 1727 } 1728 1729 /** 1730 * Event handler for the search button 1731 * 1732 * @param v The view that was clicked. 1733 */ 1734 public void onClickSearchButton(View v) { 1735 Intent i = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); 1736 View button = findViewById(R.id.search_button); 1737 i.setSourceBounds( 1738 new Rect(button.getLeft(), button.getTop(), button.getRight(), button.getBottom())); 1739 startActivity(i); 1740 } 1741 1742 /** 1743 * Event handler for the "gear" button that appears on the home screen, which 1744 * enters home screen customization mode. 1745 * 1746 * @param v The view that was clicked. 1747 */ 1748 public void onClickConfigureButton(View v) { 1749 addItems(); 1750 } 1751 1752 /** 1753 * Event handler for the "grid" button that appears on the home screen, which 1754 * enters all apps mode. 1755 * 1756 * @param v The view that was clicked. 1757 */ 1758 public void onClickAllAppsButton(View v) { 1759 showAllApps(true); 1760 } 1761 1762 public void onClickAppMarketButton(View v) { 1763 if (mAppMarketIntent != null) { 1764 startActivitySafely(mAppMarketIntent, "app market"); 1765 } 1766 } 1767 1768 void startApplicationDetailsActivity(ComponentName componentName) { 1769 String packageName = componentName.getPackageName(); 1770 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 1771 Uri.fromParts("package", packageName, null)); 1772 startActivity(intent); 1773 } 1774 1775 void startApplicationUninstallActivity(ApplicationInfo appInfo) { 1776 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { 1777 // System applications cannot be installed. For now, show a toast explaining that. 1778 // We may give them the option of disabling apps this way. 1779 int messageId = R.string.uninstall_system_app_text; 1780 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); 1781 } else { 1782 String packageName = appInfo.componentName.getPackageName(); 1783 String className = appInfo.componentName.getClassName(); 1784 Intent intent = new Intent( 1785 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); 1786 startActivity(intent); 1787 } 1788 } 1789 1790 void startActivitySafely(Intent intent, Object tag) { 1791 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 1792 try { 1793 startActivity(intent); 1794 } catch (ActivityNotFoundException e) { 1795 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1796 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); 1797 } catch (SecurityException e) { 1798 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1799 Log.e(TAG, "Launcher does not have the permission to launch " + intent + 1800 ". Make sure to create a MAIN intent-filter for the corresponding activity " + 1801 "or use the exported attribute for this activity. " 1802 + "tag="+ tag + " intent=" + intent, e); 1803 } 1804 } 1805 1806 void startActivityForResultSafely(Intent intent, int requestCode) { 1807 try { 1808 startActivityForResult(intent, requestCode); 1809 } catch (ActivityNotFoundException e) { 1810 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1811 } catch (SecurityException e) { 1812 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1813 Log.e(TAG, "Launcher does not have the permission to launch " + intent + 1814 ". Make sure to create a MAIN intent-filter for the corresponding activity " + 1815 "or use the exported attribute for this activity.", e); 1816 } 1817 } 1818 1819 private void handleFolderClick(FolderInfo folderInfo) { 1820 if (!folderInfo.opened) { 1821 // Close any open folder 1822 closeFolder(); 1823 // Open the requested folder 1824 openFolder(folderInfo); 1825 } else { 1826 // Find the open folder... 1827 Folder openFolder = mWorkspace.getFolderForTag(folderInfo); 1828 int folderScreen; 1829 if (openFolder != null) { 1830 folderScreen = mWorkspace.getPageForView(openFolder); 1831 // .. and close it 1832 closeFolder(openFolder); 1833 if (folderScreen != mWorkspace.getCurrentPage()) { 1834 // Close any folder open on the current screen 1835 closeFolder(); 1836 // Pull the folder onto this screen 1837 openFolder(folderInfo); 1838 } 1839 } 1840 } 1841 } 1842 1843 /** 1844 * Opens the user fodler described by the specified tag. The opening of the folder 1845 * is animated relative to the specified View. If the View is null, no animation 1846 * is played. 1847 * 1848 * @param folderInfo The FolderInfo describing the folder to open. 1849 */ 1850 public void openFolder(FolderInfo folderInfo) { 1851 Folder openFolder; 1852 1853 if (folderInfo instanceof UserFolderInfo) { 1854 openFolder = UserFolder.fromXml(this); 1855 } else if (folderInfo instanceof LiveFolderInfo) { 1856 openFolder = com.android.launcher2.LiveFolder.fromXml(this, folderInfo); 1857 } else { 1858 return; 1859 } 1860 1861 openFolder.setDragController(mDragController); 1862 openFolder.setLauncher(this); 1863 1864 openFolder.bind(folderInfo); 1865 folderInfo.opened = true; 1866 1867 mWorkspace.addInFullScreen(openFolder, folderInfo.screen); 1868 1869 openFolder.onOpen(); 1870 } 1871 1872 public boolean onLongClick(View v) { 1873 switch (v.getId()) { 1874 case R.id.previous_screen: 1875 if (!isAllAppsVisible()) { 1876 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 1877 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 1878 showPreviews(v); 1879 } 1880 return true; 1881 case R.id.next_screen: 1882 if (!isAllAppsVisible()) { 1883 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 1884 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 1885 showPreviews(v); 1886 } 1887 return true; 1888 case R.id.all_apps_button: 1889 if (!isAllAppsVisible()) { 1890 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 1891 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 1892 showPreviews(v); 1893 } 1894 return true; 1895 } 1896 1897 if (isWorkspaceLocked()) { 1898 return false; 1899 } 1900 1901 if (!(v instanceof CellLayout)) { 1902 v = (View) v.getParent(); 1903 } 1904 1905 CellLayout.CellInfo cellInfo = (CellLayout.CellInfo) v.getTag(); 1906 1907 // This happens when long clicking an item with the dpad/trackball 1908 if (cellInfo == null) { 1909 return true; 1910 } 1911 1912 if (mWorkspace.allowLongPress()) { 1913 if (cellInfo.cell == null) { 1914 if (cellInfo.valid) { 1915 // User long pressed on empty space 1916 mWorkspace.setAllowLongPress(false); 1917 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 1918 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 1919 showAddDialog(cellInfo); 1920 } 1921 } else { 1922 if (!(cellInfo.cell instanceof Folder)) { 1923 // User long pressed on an item 1924 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 1925 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 1926 mWorkspace.startDrag(cellInfo); 1927 } 1928 } 1929 } 1930 return true; 1931 } 1932 1933 @SuppressWarnings({"unchecked"}) 1934 private void dismissPreview(final View v) { 1935 final PopupWindow window = (PopupWindow) v.getTag(); 1936 if (window != null) { 1937 window.setOnDismissListener(new PopupWindow.OnDismissListener() { 1938 public void onDismiss() { 1939 ViewGroup group = (ViewGroup) v.getTag(R.id.workspace); 1940 int count = group.getChildCount(); 1941 for (int i = 0; i < count; i++) { 1942 ((ImageView) group.getChildAt(i)).setImageDrawable(null); 1943 } 1944 ArrayList<Bitmap> bitmaps = (ArrayList<Bitmap>) v.getTag(R.id.icon); 1945 for (Bitmap bitmap : bitmaps) bitmap.recycle(); 1946 1947 v.setTag(R.id.workspace, null); 1948 v.setTag(R.id.icon, null); 1949 window.setOnDismissListener(null); 1950 } 1951 }); 1952 window.dismiss(); 1953 } 1954 v.setTag(null); 1955 } 1956 1957 private void showPreviews(View anchor) { 1958 showPreviews(anchor, 0, mWorkspace.getChildCount()); 1959 } 1960 1961 private void showPreviews(final View anchor, int start, int end) { 1962 final Resources resources = getResources(); 1963 final Workspace workspace = mWorkspace; 1964 1965 CellLayout cell = ((CellLayout) workspace.getChildAt(start)); 1966 1967 float max = workspace.getChildCount(); 1968 1969 final Rect r = new Rect(); 1970 resources.getDrawable(R.drawable.preview_background).getPadding(r); 1971 int extraW = (int) ((r.left + r.right) * max); 1972 int extraH = r.top + r.bottom; 1973 1974 int aW = cell.getWidth() - extraW; 1975 float w = aW / max; 1976 1977 int width = cell.getWidth(); 1978 int height = cell.getHeight(); 1979 int x = cell.getLeftPadding(); 1980 int y = cell.getTopPadding(); 1981 width -= (x + cell.getRightPadding()); 1982 height -= (y + cell.getBottomPadding()); 1983 1984 float scale = w / width; 1985 1986 int count = end - start; 1987 1988 final float sWidth = width * scale; 1989 float sHeight = height * scale; 1990 1991 LinearLayout preview = new LinearLayout(this); 1992 1993 PreviewTouchHandler handler = new PreviewTouchHandler(anchor); 1994 ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(count); 1995 1996 for (int i = start; i < end; i++) { 1997 ImageView image = new ImageView(this); 1998 cell = (CellLayout) workspace.getChildAt(i); 1999 2000 final Bitmap bitmap = Bitmap.createBitmap((int) sWidth, (int) sHeight, 2001 Bitmap.Config.ARGB_8888); 2002 2003 final Canvas c = new Canvas(bitmap); 2004 c.scale(scale, scale); 2005 c.translate(-cell.getLeftPadding(), -cell.getTopPadding()); 2006 cell.dispatchDraw(c); 2007 2008 image.setBackgroundDrawable(resources.getDrawable(R.drawable.preview_background)); 2009 image.setImageBitmap(bitmap); 2010 image.setTag(i); 2011 image.setOnClickListener(handler); 2012 image.setOnFocusChangeListener(handler); 2013 image.setFocusable(true); 2014 if (i == mWorkspace.getCurrentPage()) image.requestFocus(); 2015 2016 preview.addView(image, 2017 LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); 2018 2019 bitmaps.add(bitmap); 2020 } 2021 2022 final PopupWindow p = new PopupWindow(this); 2023 p.setContentView(preview); 2024 p.setWidth((int) (sWidth * count + extraW)); 2025 p.setHeight((int) (sHeight + extraH)); 2026 p.setAnimationStyle(R.style.AnimationPreview); 2027 p.setOutsideTouchable(true); 2028 p.setFocusable(true); 2029 p.setBackgroundDrawable(new ColorDrawable(0)); 2030 p.showAsDropDown(anchor, 0, 0); 2031 2032 p.setOnDismissListener(new PopupWindow.OnDismissListener() { 2033 public void onDismiss() { 2034 dismissPreview(anchor); 2035 } 2036 }); 2037 2038 anchor.setTag(p); 2039 anchor.setTag(R.id.workspace, preview); 2040 anchor.setTag(R.id.icon, bitmaps); 2041 } 2042 2043 class PreviewTouchHandler implements View.OnClickListener, Runnable, View.OnFocusChangeListener { 2044 private final View mAnchor; 2045 2046 public PreviewTouchHandler(View anchor) { 2047 mAnchor = anchor; 2048 } 2049 2050 public void onClick(View v) { 2051 mWorkspace.snapToPage((Integer) v.getTag()); 2052 v.post(this); 2053 } 2054 2055 public void run() { 2056 dismissPreview(mAnchor); 2057 } 2058 2059 public void onFocusChange(View v, boolean hasFocus) { 2060 if (hasFocus) { 2061 mWorkspace.snapToPage((Integer) v.getTag()); 2062 } 2063 } 2064 } 2065 2066 Workspace getWorkspace() { 2067 return mWorkspace; 2068 } 2069 2070 @Override 2071 protected Dialog onCreateDialog(int id) { 2072 switch (id) { 2073 case DIALOG_CREATE_SHORTCUT: 2074 return new CreateShortcut().createDialog(); 2075 case DIALOG_RENAME_FOLDER: 2076 return new RenameFolder().createDialog(); 2077 } 2078 2079 return super.onCreateDialog(id); 2080 } 2081 2082 @Override 2083 protected void onPrepareDialog(int id, Dialog dialog) { 2084 switch (id) { 2085 case DIALOG_CREATE_SHORTCUT: 2086 break; 2087 case DIALOG_RENAME_FOLDER: 2088 if (mFolderInfo != null) { 2089 EditText input = (EditText) dialog.findViewById(R.id.folder_name); 2090 final CharSequence text = mFolderInfo.title; 2091 input.setText(text); 2092 input.setSelection(0, text.length()); 2093 } 2094 break; 2095 } 2096 } 2097 2098 void showRenameDialog(FolderInfo info) { 2099 mFolderInfo = info; 2100 mWaitingForResult = true; 2101 showDialog(DIALOG_RENAME_FOLDER); 2102 } 2103 2104 private void showAddDialog(CellLayout.CellInfo cellInfo) { 2105 mAddItemCellInfo = cellInfo; 2106 mAddItemCoordinates = null; 2107 mWaitingForResult = true; 2108 showDialog(DIALOG_CREATE_SHORTCUT); 2109 } 2110 2111 private void pickShortcut() { 2112 // Insert extra item to handle picking application 2113 Bundle bundle = new Bundle(); 2114 2115 ArrayList<String> shortcutNames = new ArrayList<String>(); 2116 shortcutNames.add(getString(R.string.group_applications)); 2117 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); 2118 2119 ArrayList<ShortcutIconResource> shortcutIcons = new ArrayList<ShortcutIconResource>(); 2120 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, 2121 R.drawable.ic_launcher_application)); 2122 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); 2123 2124 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); 2125 pickIntent.putExtra(Intent.EXTRA_INTENT, new Intent(Intent.ACTION_CREATE_SHORTCUT)); 2126 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_shortcut)); 2127 pickIntent.putExtras(bundle); 2128 2129 startActivityForResult(pickIntent, REQUEST_PICK_SHORTCUT); 2130 } 2131 2132 private class RenameFolder { 2133 private EditText mInput; 2134 2135 Dialog createDialog() { 2136 final View layout = View.inflate(Launcher.this, R.layout.rename_folder, null); 2137 mInput = (EditText) layout.findViewById(R.id.folder_name); 2138 2139 AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); 2140 builder.setIcon(0); 2141 builder.setTitle(getString(R.string.rename_folder_title)); 2142 builder.setCancelable(true); 2143 builder.setOnCancelListener(new Dialog.OnCancelListener() { 2144 public void onCancel(DialogInterface dialog) { 2145 cleanup(); 2146 } 2147 }); 2148 builder.setNegativeButton(getString(R.string.cancel_action), 2149 new Dialog.OnClickListener() { 2150 public void onClick(DialogInterface dialog, int which) { 2151 cleanup(); 2152 } 2153 } 2154 ); 2155 builder.setPositiveButton(getString(R.string.rename_action), 2156 new Dialog.OnClickListener() { 2157 public void onClick(DialogInterface dialog, int which) { 2158 changeFolderName(); 2159 } 2160 } 2161 ); 2162 builder.setView(layout); 2163 2164 final AlertDialog dialog = builder.create(); 2165 dialog.setOnShowListener(new DialogInterface.OnShowListener() { 2166 public void onShow(DialogInterface dialog) { 2167 mWaitingForResult = true; 2168 mInput.requestFocus(); 2169 InputMethodManager inputManager = (InputMethodManager) 2170 getSystemService(Context.INPUT_METHOD_SERVICE); 2171 inputManager.showSoftInput(mInput, 0); 2172 } 2173 }); 2174 2175 return dialog; 2176 } 2177 2178 private void changeFolderName() { 2179 final String name = mInput.getText().toString(); 2180 if (!TextUtils.isEmpty(name)) { 2181 // Make sure we have the right folder info 2182 mFolderInfo = sFolders.get(mFolderInfo.id); 2183 mFolderInfo.title = name; 2184 LauncherModel.updateItemInDatabase(Launcher.this, mFolderInfo); 2185 2186 if (mWorkspaceLoading) { 2187 lockAllApps(); 2188 mModel.startLoader(Launcher.this, false); 2189 } else { 2190 final FolderIcon folderIcon = (FolderIcon) 2191 mWorkspace.getViewForTag(mFolderInfo); 2192 if (folderIcon != null) { 2193 folderIcon.setText(name); 2194 getWorkspace().requestLayout(); 2195 } else { 2196 lockAllApps(); 2197 mWorkspaceLoading = true; 2198 mModel.startLoader(Launcher.this, false); 2199 } 2200 } 2201 } 2202 cleanup(); 2203 } 2204 2205 private void cleanup() { 2206 dismissDialog(DIALOG_RENAME_FOLDER); 2207 mWaitingForResult = false; 2208 mFolderInfo = null; 2209 } 2210 } 2211 2212 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. 2213 public boolean isAllAppsVisible() { 2214 return mAllAppsGrid != null && mAllAppsGrid.isVisible(); 2215 } 2216 2217 // AllAppsView.Watcher 2218 public void zoomed(float zoom) { 2219 // In XLarge view, we zoom down the workspace below all apps so it's still visible 2220 if (zoom == 1.0f && !LauncherApplication.isScreenXLarge()) { 2221 mWorkspace.setVisibility(View.GONE); 2222 } 2223 } 2224 2225 private void showToolbarButton(View button) { 2226 button.setAlpha(1.0f); 2227 button.setVisibility(View.VISIBLE); 2228 button.setFocusable(true); 2229 button.setClickable(true); 2230 } 2231 2232 private void hideToolbarButton(View button) { 2233 button.setAlpha(0.0f); 2234 // We can't set it to GONE, otherwise the RelativeLayout gets screwed up 2235 button.setVisibility(View.INVISIBLE); 2236 button.setFocusable(false); 2237 button.setClickable(false); 2238 } 2239 2240 /** 2241 * Helper function for showing or hiding a toolbar button, possibly animated. 2242 * 2243 * @param show If true, create an animation to the show the item. Otherwise, hide it. 2244 * @param view The toolbar button to be animated 2245 * @param seq A AnimatorSet that will be used to animate the transition. If null, the 2246 * transition will not be animated. 2247 */ 2248 private void hideOrShowToolbarButton(boolean show, final View view, AnimatorSet seq) { 2249 final boolean showing = show; 2250 final boolean hiding = !show; 2251 2252 final int duration = show ? 2253 getResources().getInteger(R.integer.config_toolbarButtonFadeInTime) : 2254 getResources().getInteger(R.integer.config_toolbarButtonFadeOutTime); 2255 2256 if (seq != null) { 2257 Animator anim = new ObjectAnimator<Float>(duration, view, "alpha", show ? 1.0f : 0.0f); 2258 anim.addListener(new AnimatorListenerAdapter() { 2259 public void onAnimationStart(Animator animation) { 2260 if (showing) showToolbarButton(view); 2261 } 2262 public void onAnimationEnd(Animator animation) { 2263 if (hiding) hideToolbarButton(view); 2264 } 2265 }); 2266 seq.play(anim); 2267 } else { 2268 if (showing) { 2269 showToolbarButton(view); 2270 } else { 2271 hideToolbarButton(view); 2272 } 2273 } 2274 } 2275 2276 /** 2277 * Show/hide the appropriate toolbar buttons for newState. 2278 * If showSeq or hideSeq is null, the transition will be done immediately (not animated). 2279 * 2280 * @param newState The state that is being switched to 2281 * @param showSeq AnimatorSet in which to put "show" animations, or null. 2282 * @param hideSeq AnimatorSet in which to put "hide" animations, or null. 2283 */ 2284 private void hideAndShowToolbarButtons(State newState, AnimatorSet showSeq, AnimatorSet hideSeq) { 2285 final View searchButton = findViewById(R.id.search_button); 2286 final View allAppsButton = findViewById(R.id.all_apps_button); 2287 final View marketButton = findViewById(R.id.market_button); 2288 final View configureButton = findViewById(R.id.configure_button); 2289 2290 switch (newState) { 2291 case WORKSPACE: 2292 hideOrShowToolbarButton(true, searchButton, showSeq); 2293 hideOrShowToolbarButton(true, allAppsButton, showSeq); 2294 hideOrShowToolbarButton(true, configureButton, showSeq); 2295 hideOrShowToolbarButton(false, marketButton, hideSeq); 2296 mDeleteZone.setHandle(allAppsButton); 2297 break; 2298 case ALL_APPS: 2299 hideOrShowToolbarButton(true, configureButton, showSeq); 2300 hideOrShowToolbarButton(true, marketButton, showSeq); 2301 hideOrShowToolbarButton(false, searchButton, hideSeq); 2302 hideOrShowToolbarButton(false, allAppsButton, hideSeq); 2303 mDeleteZone.setHandle(marketButton); 2304 break; 2305 case CUSTOMIZE: 2306 hideOrShowToolbarButton(true, allAppsButton, showSeq); 2307 hideOrShowToolbarButton(false, searchButton, hideSeq); 2308 hideOrShowToolbarButton(false, marketButton, hideSeq); 2309 hideOrShowToolbarButton(false, configureButton, hideSeq); 2310 mDeleteZone.setHandle(allAppsButton); 2311 break; 2312 } 2313 } 2314 2315 /** 2316 * Helper method for the cameraZoomIn/cameraZoomOut animations 2317 * @param view The view being animated 2318 * @param state The state that we are moving in or out of -- either ALL_APPS or CUSTOMIZE 2319 * @param scaleFactor The scale factor used for the zoom 2320 */ 2321 private void setPivotsForZoom(View view, State state, float scaleFactor) { 2322 final int height = view.getHeight(); 2323 view.setPivotX(view.getWidth() / 2.0f); 2324 // Set pivotY so that at the starting zoom factor, the view is off-screen by a small margin 2325 // Assumes that the view is normally anchored to either the top or bottom of the screen 2326 final int margin = getResources().getInteger(R.integer.config_allAppsVerticalOffset); 2327 if (state == State.ALL_APPS) { 2328 view.setPivotY(height + ((view.getTop() + height) / scaleFactor) + margin); 2329 } else { 2330 view.setPivotY(0.0f - (view.getTop() / scaleFactor) - margin); 2331 } 2332 } 2333 2334 /** 2335 * Zoom the camera out from the workspace to reveal 'toView'. 2336 * Assumes that the view to show is anchored at either the very top or very bottom 2337 * of the screen. 2338 * @param toState The state to zoom out to. Must be ALL_APPS or CUSTOMIZE. 2339 */ 2340 private void cameraZoomOut(State toState, boolean animated) { 2341 final Resources res = getResources(); 2342 final int duration = res.getInteger(R.integer.config_allAppsZoomInTime); 2343 final float scale = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); 2344 final boolean toAllApps = (toState == State.ALL_APPS); 2345 final View toView = toAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; 2346 2347 setPivotsForZoom(toView, toState, scale); 2348 2349 if (toState == State.ALL_APPS) { 2350 mWorkspace.shrinkToBottom(animated); 2351 } else { 2352 mWorkspace.shrinkToTop(animated); 2353 } 2354 2355 if (animated) { 2356 ValueAnimator scaleAnim = new ObjectAnimator(duration, toView, 2357 new PropertyValuesHolder<Float>("scaleX", scale, 1.0f), 2358 new PropertyValuesHolder<Float>("scaleY", scale, 1.0f)); 2359 scaleAnim.setInterpolator(new DecelerateInterpolator()); 2360 scaleAnim.addListener(new AnimatorListenerAdapter() { 2361 public void onAnimationStart(Animator animation) { 2362 // Prepare the position 2363 toView.setTranslationX(0.0f); 2364 toView.setTranslationY(0.0f); 2365 toView.setVisibility(View.VISIBLE); 2366 } 2367 }); 2368 2369 AnimatorSet toolbarHideAnim = new AnimatorSet(); 2370 AnimatorSet toolbarShowAnim = new AnimatorSet(); 2371 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); 2372 2373 // toView should appear right at the end of the workspace shrink animation 2374 final int startDelay = res.getInteger(R.integer.config_workspaceShrinkTime) - duration; 2375 2376 AnimatorSet s = new AnimatorSet(); 2377 s.playTogether(scaleAnim, toolbarHideAnim); 2378 s.play(scaleAnim).after(startDelay); 2379 2380 // Show the new toolbar buttons just as the main animation is ending 2381 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); 2382 s.play(toolbarShowAnim).after(duration + startDelay - fadeInTime); 2383 s.start(); 2384 } else { 2385 toView.setTranslationX(0.0f); 2386 toView.setTranslationY(0.0f); 2387 toView.setScaleX(1.0f); 2388 toView.setScaleY(1.0f); 2389 toView.setVisibility(View.VISIBLE); 2390 hideAndShowToolbarButtons(toState, null, null); 2391 } 2392 } 2393 2394 /** 2395 * Zoom the camera back into the workspace, hiding 'fromView'. 2396 * This is the opposite of cameraZoomOut. 2397 * @param fromState The current state (must be ALL_APPS or CUSTOMIZE). 2398 * @param animated If true, the transition will be animated. 2399 */ 2400 private void cameraZoomIn(State fromState, boolean animated) { 2401 Resources res = getResources(); 2402 int duration = res.getInteger(R.integer.config_allAppsZoomOutTime); 2403 float scaleFactor = (float) res.getInteger(R.integer.config_allAppsZoomScaleFactor); 2404 final View fromView = 2405 (fromState == State.ALL_APPS) ? (View) mAllAppsGrid : mHomeCustomizationDrawer; 2406 2407 setPivotsForZoom(fromView, fromState, scaleFactor); 2408 2409 mWorkspace.unshrink(animated); 2410 2411 if (animated) { 2412 AnimatorSet s = new AnimatorSet(); 2413 ValueAnimator scaleAnim = new ObjectAnimator(duration, fromView, 2414 new PropertyValuesHolder<Float>("scaleX", scaleFactor), 2415 new PropertyValuesHolder<Float>("scaleY", scaleFactor)); 2416 scaleAnim.setInterpolator(new AccelerateInterpolator()); 2417 s.addListener(new AnimatorListenerAdapter() { 2418 public void onAnimationEnd(Animator animation) { 2419 fromView.setVisibility(View.GONE); 2420 fromView.setScaleX(1.0f); 2421 fromView.setScaleY(1.0f); 2422 } 2423 }); 2424 2425 AnimatorSet toolbarHideAnim = new AnimatorSet(); 2426 AnimatorSet toolbarShowAnim = new AnimatorSet(); 2427 hideAndShowToolbarButtons(State.WORKSPACE, toolbarShowAnim, toolbarHideAnim); 2428 2429 s.playTogether(scaleAnim, toolbarHideAnim); 2430 2431 // Show the new toolbar buttons at the very end of the whole animation 2432 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); 2433 final int unshrinkTime = res.getInteger(R.integer.config_workspaceUnshrinkTime); 2434 s.play(toolbarShowAnim).after(unshrinkTime - fadeInTime); 2435 s.start(); 2436 } else { 2437 fromView.setVisibility(View.GONE); 2438 hideAndShowToolbarButtons(State.WORKSPACE, null, null); 2439 } 2440 } 2441 2442 /** 2443 * Pan the camera in the vertical plane between 'fromView' and 'toView'. 2444 * This is the transition used on xlarge screens to go between all apps and 2445 * the home customization drawer. 2446 * @param fromState The view to pan away from. Must be ALL_APPS or CUSTOMIZE. 2447 * @param toState The view to pan into the frame. Must be ALL_APPS or CUSTOMIZE. 2448 * @param animated If true, the transition will be animated. 2449 */ 2450 private void cameraPan(State fromState, State toState, boolean animated) { 2451 final Resources res = getResources(); 2452 final int duration = res.getInteger(R.integer.config_allAppsCameraPanTime); 2453 final int workspaceHeight = mWorkspace.getHeight(); 2454 2455 final boolean fromAllApps = (fromState == State.ALL_APPS); 2456 final View fromView = fromAllApps ? (View) mAllAppsGrid : mHomeCustomizationDrawer; 2457 final View toView = fromAllApps ? mHomeCustomizationDrawer : (View) mAllAppsGrid; 2458 2459 final float fromViewStartY = fromAllApps ? 0.0f : fromView.getY(); 2460 final float fromViewEndY = fromAllApps ? -fromView.getHeight() * 2 : workspaceHeight * 2; 2461 final float toViewStartY = fromAllApps ? workspaceHeight * 2 : -toView.getHeight() * 2; 2462 final float toViewEndY = fromAllApps ? workspaceHeight - toView.getHeight() : 0.0f; 2463 2464 if (toState == State.ALL_APPS) { 2465 mWorkspace.shrinkToBottom(animated); 2466 } else { 2467 mWorkspace.shrinkToTop(animated); 2468 } 2469 2470 if (animated) { 2471 AnimatorSet s = new AnimatorSet(); 2472 s.addListener(new AnimatorListenerAdapter() { 2473 public void onAnimationStart(Animator animation) { 2474 toView.setVisibility(View.VISIBLE); 2475 toView.setY(toViewStartY); 2476 } 2477 public void onAnimationEnd(Animator animation) { 2478 fromView.setVisibility(View.GONE); 2479 } 2480 }); 2481 2482 AnimatorSet toolbarHideAnim = new AnimatorSet(); 2483 AnimatorSet toolbarShowAnim = new AnimatorSet(); 2484 hideAndShowToolbarButtons(toState, toolbarShowAnim, toolbarHideAnim); 2485 2486 s.playTogether( 2487 toolbarHideAnim, 2488 new ObjectAnimator(duration, fromView, "y", fromViewStartY, fromViewEndY), 2489 new ObjectAnimator(duration, toView, "y", toViewStartY, toViewEndY)); 2490 2491 // Show the new toolbar buttons just as the main animation is ending 2492 final int fadeInTime = res.getInteger(R.integer.config_toolbarButtonFadeInTime); 2493 s.play(toolbarShowAnim).after(duration - fadeInTime); 2494 s.start(); 2495 } else { 2496 fromView.setY(fromViewEndY); 2497 fromView.setVisibility(View.GONE); 2498 toView.setY(toViewEndY); 2499 toView.setVisibility(View.VISIBLE); 2500 hideAndShowToolbarButtons(toState, null, null); 2501 } 2502 } 2503 2504 void showAllApps(boolean animated) { 2505 if (mAllAppsGrid.isVisible()) 2506 return; 2507 2508 if (LauncherApplication.isScreenXLarge()) { 2509 if (isCustomizationDrawerVisible()) { 2510 cameraPan(State.CUSTOMIZE, State.ALL_APPS, animated); 2511 } else { 2512 cameraZoomOut(State.ALL_APPS, animated); 2513 } 2514 } else { 2515 mAllAppsGrid.zoom(1.0f, animated); 2516 } 2517 2518 ((View) mAllAppsGrid).setFocusable(true); 2519 ((View) mAllAppsGrid).requestFocus(); 2520 2521 // TODO: fade these two too 2522 mDeleteZone.setVisibility(View.GONE); 2523 } 2524 2525 /** 2526 * Things to test when changing this code. 2527 * - Home from workspace 2528 * - from center screen 2529 * - from other screens 2530 * - Home from all apps 2531 * - from center screen 2532 * - from other screens 2533 * - Back from all apps 2534 * - from center screen 2535 * - from other screens 2536 * - Launch app from workspace and quit 2537 * - with back 2538 * - with home 2539 * - Launch app from all apps and quit 2540 * - with back 2541 * - with home 2542 * - Go to a screen that's not the default, then all 2543 * apps, and launch and app, and go back 2544 * - with back 2545 * -with home 2546 * - On workspace, long press power and go back 2547 * - with back 2548 * - with home 2549 * - On all apps, long press power and go back 2550 * - with back 2551 * - with home 2552 * - On workspace, power off 2553 * - On all apps, power off 2554 * - Launch an app and turn off the screen while in that app 2555 * - Go back with home key 2556 * - Go back with back key TODO: make this not go to workspace 2557 * - From all apps 2558 * - From workspace 2559 * - Enter and exit car mode (becuase it causes an extra configuration changed) 2560 * - From all apps 2561 * - From the center workspace 2562 * - From another workspace 2563 */ 2564 void closeAllApps(boolean animated) { 2565 if (mAllAppsGrid.isVisible()) { 2566 mWorkspace.setVisibility(View.VISIBLE); 2567 if (LauncherApplication.isScreenXLarge()) { 2568 cameraZoomIn(State.ALL_APPS, animated); 2569 } else { 2570 mAllAppsGrid.zoom(0.0f, animated); 2571 } 2572 ((View)mAllAppsGrid).setFocusable(false); 2573 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); 2574 } 2575 } 2576 2577 void lockAllApps() { 2578 // TODO 2579 } 2580 2581 void unlockAllApps() { 2582 // TODO 2583 } 2584 2585 private boolean isCustomizationDrawerVisible() { 2586 return mHomeCustomizationDrawer != null && 2587 mHomeCustomizationDrawer.getVisibility() == View.VISIBLE; 2588 } 2589 2590 // Show the customization drawer (only exists in x-large configuration) 2591 private void showCustomizationDrawer(boolean animated) { 2592 if (isAllAppsVisible()) { 2593 cameraPan(State.ALL_APPS, State.CUSTOMIZE, animated); 2594 } else { 2595 cameraZoomOut(State.CUSTOMIZE, animated); 2596 } 2597 } 2598 2599 // Hide the customization drawer (only exists in x-large configuration) 2600 void hideCustomizationDrawer(boolean animated) { 2601 if (isCustomizationDrawerVisible()) { 2602 cameraZoomIn(State.CUSTOMIZE, animated); 2603 } 2604 } 2605 2606 void onWorkspaceUnshrink() { 2607 final boolean animated = true; 2608 if (isAllAppsVisible()) { 2609 closeAllApps(animated); 2610 } 2611 if (isCustomizationDrawerVisible()) { 2612 hideCustomizationDrawer(animated); 2613 } 2614 } 2615 2616 /** 2617 * Sets the app market icon (shown when all apps is visible on x-large screens) 2618 */ 2619 private void updateAppMarketIcon() { 2620 if (LauncherApplication.isScreenXLarge()) { 2621 // Find the app market activity by resolving an intent. 2622 // (If multiple app markets are installed, it will return the ResolverActivity.) 2623 PackageManager packageManager = getPackageManager(); 2624 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); 2625 ComponentName activityName = intent.resolveActivity(getPackageManager()); 2626 if (activityName != null) { 2627 mAppMarketIntent = intent; 2628 ImageView marketButton = (ImageView) findViewById(R.id.market_button); 2629 Drawable toolbarIcon = null; 2630 try { 2631 // Look for the toolbar icon specified in the activity meta-data 2632 Bundle metaData = packageManager.getActivityInfo( 2633 activityName, PackageManager.GET_META_DATA).metaData; 2634 if (metaData != null) { 2635 int iconResId = metaData.getInt(TOOLBAR_ICON_METADATA_NAME); 2636 if (iconResId != 0) { 2637 Resources res = packageManager.getResourcesForActivity(activityName); 2638 toolbarIcon = res.getDrawable(iconResId); 2639 } 2640 } 2641 } catch (NameNotFoundException e) { 2642 // Do nothing 2643 } 2644 // If we were unable to find the icon via the meta-data, use a generic one 2645 if (toolbarIcon == null) { 2646 marketButton.setImageResource(R.drawable.app_market_generic); 2647 } else { 2648 marketButton.setImageDrawable(toolbarIcon); 2649 } 2650 } else { 2651 mAppMarketIntent = null; 2652 } 2653 } 2654 } 2655 2656 /** 2657 * Displays the shortcut creation dialog and launches, if necessary, the 2658 * appropriate activity. 2659 */ 2660 private class CreateShortcut implements DialogInterface.OnClickListener, 2661 DialogInterface.OnCancelListener, DialogInterface.OnDismissListener, 2662 DialogInterface.OnShowListener { 2663 2664 private AddAdapter mAdapter; 2665 2666 Dialog createDialog() { 2667 mAdapter = new AddAdapter(Launcher.this); 2668 2669 final AlertDialog.Builder builder = new AlertDialog.Builder(Launcher.this); 2670 builder.setTitle(getString(R.string.menu_item_add_item)); 2671 builder.setAdapter(mAdapter, this); 2672 2673 builder.setInverseBackgroundForced(true); 2674 2675 AlertDialog dialog = builder.create(); 2676 dialog.setOnCancelListener(this); 2677 dialog.setOnDismissListener(this); 2678 dialog.setOnShowListener(this); 2679 2680 return dialog; 2681 } 2682 2683 public void onCancel(DialogInterface dialog) { 2684 mWaitingForResult = false; 2685 cleanup(); 2686 } 2687 2688 public void onDismiss(DialogInterface dialog) { 2689 } 2690 2691 private void cleanup() { 2692 try { 2693 dismissDialog(DIALOG_CREATE_SHORTCUT); 2694 } catch (Exception e) { 2695 // An exception is thrown if the dialog is not visible, which is fine 2696 } 2697 } 2698 2699 /** 2700 * Handle the action clicked in the "Add to home" dialog. 2701 */ 2702 public void onClick(DialogInterface dialog, int which) { 2703 Resources res = getResources(); 2704 cleanup(); 2705 2706 switch (which) { 2707 case AddAdapter.ITEM_SHORTCUT: { 2708 pickShortcut(); 2709 break; 2710 } 2711 2712 case AddAdapter.ITEM_APPWIDGET: { 2713 int appWidgetId = Launcher.this.mAppWidgetHost.allocateAppWidgetId(); 2714 2715 Intent pickIntent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK); 2716 pickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 2717 // start the pick activity 2718 startActivityForResult(pickIntent, REQUEST_PICK_APPWIDGET); 2719 break; 2720 } 2721 2722 case AddAdapter.ITEM_LIVE_FOLDER: { 2723 // Insert extra item to handle inserting folder 2724 Bundle bundle = new Bundle(); 2725 2726 ArrayList<String> shortcutNames = new ArrayList<String>(); 2727 shortcutNames.add(res.getString(R.string.group_folder)); 2728 bundle.putStringArrayList(Intent.EXTRA_SHORTCUT_NAME, shortcutNames); 2729 2730 ArrayList<ShortcutIconResource> shortcutIcons = 2731 new ArrayList<ShortcutIconResource>(); 2732 shortcutIcons.add(ShortcutIconResource.fromContext(Launcher.this, 2733 R.drawable.ic_launcher_folder)); 2734 bundle.putParcelableArrayList(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, shortcutIcons); 2735 2736 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); 2737 pickIntent.putExtra(Intent.EXTRA_INTENT, 2738 new Intent(LiveFolders.ACTION_CREATE_LIVE_FOLDER)); 2739 pickIntent.putExtra(Intent.EXTRA_TITLE, 2740 getText(R.string.title_select_live_folder)); 2741 pickIntent.putExtras(bundle); 2742 2743 startActivityForResult(pickIntent, REQUEST_PICK_LIVE_FOLDER); 2744 break; 2745 } 2746 2747 case AddAdapter.ITEM_WALLPAPER: { 2748 startWallpaper(); 2749 break; 2750 } 2751 } 2752 } 2753 2754 public void onShow(DialogInterface dialog) { 2755 mWaitingForResult = true; 2756 } 2757 } 2758 2759 /** 2760 * Receives notifications when applications are added/removed. 2761 */ 2762 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { 2763 @Override 2764 public void onReceive(Context context, Intent intent) { 2765 closeSystemDialogs(); 2766 String reason = intent.getStringExtra("reason"); 2767 if (!"homekey".equals(reason)) { 2768 boolean animate = true; 2769 if (mPaused || "lock".equals(reason)) { 2770 animate = false; 2771 } 2772 closeAllApps(animate); 2773 hideCustomizationDrawer(animate); 2774 } 2775 } 2776 } 2777 2778 /** 2779 * Receives notifications whenever the appwidgets are reset. 2780 */ 2781 private class AppWidgetResetObserver extends ContentObserver { 2782 public AppWidgetResetObserver() { 2783 super(new Handler()); 2784 } 2785 2786 @Override 2787 public void onChange(boolean selfChange) { 2788 onAppWidgetReset(); 2789 } 2790 } 2791 2792 /** 2793 * Implementation of the method from LauncherModel.Callbacks. 2794 */ 2795 public int getCurrentWorkspaceScreen() { 2796 if (mWorkspace != null) { 2797 return mWorkspace.getCurrentPage(); 2798 } else { 2799 return SCREEN_COUNT / 2; 2800 } 2801 } 2802 2803 /** 2804 * Refreshes the shortcuts shown on the workspace. 2805 * 2806 * Implementation of the method from LauncherModel.Callbacks. 2807 */ 2808 public void startBinding() { 2809 final Workspace workspace = mWorkspace; 2810 int count = workspace.getChildCount(); 2811 for (int i = 0; i < count; i++) { 2812 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). 2813 ((ViewGroup) workspace.getChildAt(i)).removeAllViewsInLayout(); 2814 } 2815 2816 if (DEBUG_USER_INTERFACE) { 2817 android.widget.Button finishButton = new android.widget.Button(this); 2818 finishButton.setText("Finish"); 2819 workspace.addInScreen(finishButton, 1, 0, 0, 1, 1); 2820 2821 finishButton.setOnClickListener(new android.widget.Button.OnClickListener() { 2822 public void onClick(View v) { 2823 finish(); 2824 } 2825 }); 2826 } 2827 } 2828 2829 /** 2830 * Bind the items start-end from the list. 2831 * 2832 * Implementation of the method from LauncherModel.Callbacks. 2833 */ 2834 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { 2835 2836 final Workspace workspace = mWorkspace; 2837 2838 for (int i=start; i<end; i++) { 2839 final ItemInfo item = shortcuts.get(i); 2840 mDesktopItems.add(item); 2841 switch (item.itemType) { 2842 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: 2843 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: 2844 final View shortcut = createShortcut((ShortcutInfo)item); 2845 workspace.addInScreen(shortcut, item.screen, item.cellX, item.cellY, 1, 1, 2846 false); 2847 break; 2848 case LauncherSettings.Favorites.ITEM_TYPE_USER_FOLDER: 2849 final FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, 2850 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), 2851 (UserFolderInfo) item); 2852 workspace.addInScreen(newFolder, item.screen, item.cellX, item.cellY, 1, 1, 2853 false); 2854 break; 2855 case LauncherSettings.Favorites.ITEM_TYPE_LIVE_FOLDER: 2856 final FolderIcon newLiveFolder = LiveFolderIcon.fromXml( 2857 R.layout.live_folder_icon, this, 2858 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), 2859 (LiveFolderInfo) item); 2860 workspace.addInScreen(newLiveFolder, item.screen, item.cellX, item.cellY, 1, 1, 2861 false); 2862 break; 2863 } 2864 } 2865 2866 workspace.requestLayout(); 2867 } 2868 2869 /** 2870 * Implementation of the method from LauncherModel.Callbacks. 2871 */ 2872 public void bindFolders(HashMap<Long, FolderInfo> folders) { 2873 sFolders.clear(); 2874 sFolders.putAll(folders); 2875 } 2876 2877 /** 2878 * Add the views for a widget to the workspace. 2879 * 2880 * Implementation of the method from LauncherModel.Callbacks. 2881 */ 2882 public void bindAppWidget(LauncherAppWidgetInfo item) { 2883 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; 2884 if (DEBUG_WIDGETS) { 2885 Log.d(TAG, "bindAppWidget: " + item); 2886 } 2887 final Workspace workspace = mWorkspace; 2888 2889 final int appWidgetId = item.appWidgetId; 2890 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 2891 if (DEBUG_WIDGETS) { 2892 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); 2893 } 2894 2895 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); 2896 2897 item.hostView.setAppWidget(appWidgetId, appWidgetInfo); 2898 item.hostView.setTag(item); 2899 2900 workspace.addInScreen(item.hostView, item.screen, item.cellX, 2901 item.cellY, item.spanX, item.spanY, false); 2902 2903 workspace.requestLayout(); 2904 2905 mDesktopItems.add(item); 2906 2907 if (DEBUG_WIDGETS) { 2908 Log.d(TAG, "bound widget id="+item.appWidgetId+" in " 2909 + (SystemClock.uptimeMillis()-start) + "ms"); 2910 } 2911 } 2912 2913 /** 2914 * Callback saying that there aren't any more items to bind. 2915 * 2916 * Implementation of the method from LauncherModel.Callbacks. 2917 */ 2918 public void finishBindingItems() { 2919 if (mSavedState != null) { 2920 if (!mWorkspace.hasFocus()) { 2921 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); 2922 } 2923 2924 final long[] userFolders = mSavedState.getLongArray(RUNTIME_STATE_USER_FOLDERS); 2925 if (userFolders != null) { 2926 for (long folderId : userFolders) { 2927 final FolderInfo info = sFolders.get(folderId); 2928 if (info != null) { 2929 openFolder(info); 2930 } 2931 } 2932 final Folder openFolder = mWorkspace.getOpenFolder(); 2933 if (openFolder != null) { 2934 openFolder.requestFocus(); 2935 } 2936 } 2937 2938 mSavedState = null; 2939 } 2940 2941 if (mSavedInstanceState != null) { 2942 super.onRestoreInstanceState(mSavedInstanceState); 2943 mSavedInstanceState = null; 2944 } 2945 2946 mWorkspaceLoading = false; 2947 } 2948 2949 /** 2950 * Add the icons for all apps. 2951 * 2952 * Implementation of the method from LauncherModel.Callbacks. 2953 */ 2954 public void bindAllApplications(ArrayList<ApplicationInfo> apps) { 2955 mAllAppsGrid.setApps(apps); 2956 updateAppMarketIcon(); 2957 } 2958 2959 /** 2960 * A package was installed. 2961 * 2962 * Implementation of the method from LauncherModel.Callbacks. 2963 */ 2964 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { 2965 removeDialog(DIALOG_CREATE_SHORTCUT); 2966 mAllAppsGrid.addApps(apps); 2967 updateAppMarketIcon(); 2968 } 2969 2970 /** 2971 * A package was updated. 2972 * 2973 * Implementation of the method from LauncherModel.Callbacks. 2974 */ 2975 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { 2976 removeDialog(DIALOG_CREATE_SHORTCUT); 2977 mWorkspace.updateShortcuts(apps); 2978 mAllAppsGrid.updateApps(apps); 2979 updateAppMarketIcon(); 2980 } 2981 2982 /** 2983 * A package was uninstalled. 2984 * 2985 * Implementation of the method from LauncherModel.Callbacks. 2986 */ 2987 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { 2988 removeDialog(DIALOG_CREATE_SHORTCUT); 2989 if (permanent) { 2990 mWorkspace.removeItems(apps); 2991 } 2992 mAllAppsGrid.removeApps(apps); 2993 updateAppMarketIcon(); 2994 } 2995 2996 /** 2997 * A number of packages were updated. 2998 */ 2999 public void bindPackagesUpdated() { 3000 // update the customization drawer contents 3001 if (mCustomizePagedView != null) 3002 mCustomizePagedView.update(); 3003 } 3004 3005 /** 3006 * Prints out out state for debugging. 3007 */ 3008 public void dumpState() { 3009 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); 3010 Log.d(TAG, "mSavedState=" + mSavedState); 3011 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); 3012 Log.d(TAG, "mRestoring=" + mRestoring); 3013 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); 3014 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); 3015 Log.d(TAG, "mDesktopItems.size=" + mDesktopItems.size()); 3016 Log.d(TAG, "sFolders.size=" + sFolders.size()); 3017 mModel.dumpState(); 3018 mAllAppsGrid.dumpState(); 3019 Log.d(TAG, "END launcher2 dump state"); 3020 } 3021} 3022