Launcher.java revision 86a720e4927a997e9fd98276d2dab67244138f79
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.AnimatorSet; 23import android.animation.ObjectAnimator; 24import android.animation.PropertyValuesHolder; 25import android.animation.ValueAnimator; 26import android.animation.ValueAnimator.AnimatorUpdateListener; 27import android.app.Activity; 28import android.app.ActivityManager; 29import android.app.ActivityOptions; 30import android.app.SearchManager; 31import android.appwidget.AppWidgetHostView; 32import android.appwidget.AppWidgetManager; 33import android.appwidget.AppWidgetProviderInfo; 34import android.content.ActivityNotFoundException; 35import android.content.BroadcastReceiver; 36import android.content.ComponentCallbacks2; 37import android.content.ComponentName; 38import android.content.ContentResolver; 39import android.content.Context; 40import android.content.Intent; 41import android.content.IntentFilter; 42import android.content.SharedPreferences; 43import android.content.pm.ActivityInfo; 44import android.content.pm.PackageManager; 45import android.content.pm.PackageManager.NameNotFoundException; 46import android.content.res.Configuration; 47import android.content.res.Resources; 48import android.database.ContentObserver; 49import android.graphics.Rect; 50import android.graphics.drawable.Drawable; 51import android.net.Uri; 52import android.os.AsyncTask; 53import android.os.Bundle; 54import android.os.Environment; 55import android.os.Handler; 56import android.os.Message; 57import android.os.StrictMode; 58import android.os.SystemClock; 59import android.os.SystemProperties; 60import android.provider.Settings; 61import android.speech.RecognizerIntent; 62import android.text.Selection; 63import android.text.SpannableStringBuilder; 64import android.text.method.TextKeyListener; 65import android.util.Log; 66import android.view.Display; 67import android.view.HapticFeedbackConstants; 68import android.view.KeyEvent; 69import android.view.LayoutInflater; 70import android.view.Menu; 71import android.view.MenuItem; 72import android.view.MotionEvent; 73import android.view.Surface; 74import android.view.View; 75import android.view.View.OnLongClickListener; 76import android.view.ViewGroup; 77import android.view.ViewTreeObserver; 78import android.view.ViewTreeObserver.OnGlobalLayoutListener; 79import android.view.WindowManager; 80import android.view.accessibility.AccessibilityEvent; 81import android.view.animation.AccelerateDecelerateInterpolator; 82import android.view.animation.AccelerateInterpolator; 83import android.view.animation.DecelerateInterpolator; 84import android.view.inputmethod.InputMethodManager; 85import android.widget.Advanceable; 86import android.widget.ImageView; 87import android.widget.TextView; 88import android.widget.Toast; 89 90import com.android.common.Search; 91import com.android.launcher.R; 92import com.android.launcher2.DropTarget.DragObject; 93 94import java.io.DataInputStream; 95import java.io.DataOutputStream; 96import java.io.FileDescriptor; 97import java.io.FileNotFoundException; 98import java.io.IOException; 99import java.io.PrintWriter; 100import java.util.ArrayList; 101import java.util.Collection; 102import java.util.Collections; 103import java.util.Comparator; 104import java.util.HashMap; 105import java.util.HashSet; 106import java.util.List; 107import java.util.Set; 108 109/** 110 * Default launcher application. 111 */ 112public final class Launcher extends Activity 113 implements View.OnClickListener, OnLongClickListener, LauncherModel.Callbacks, 114 AllAppsView.Watcher, View.OnTouchListener { 115 static final String TAG = "Launcher"; 116 static final boolean LOGD = false; 117 118 static final boolean PROFILE_STARTUP = false; 119 static final boolean DEBUG_WIDGETS = false; 120 static final boolean DEBUG_STRICT_MODE = false; 121 122 private static final int MENU_GROUP_WALLPAPER = 1; 123 private static final int MENU_WALLPAPER_SETTINGS = Menu.FIRST + 1; 124 private static final int MENU_MANAGE_APPS = MENU_WALLPAPER_SETTINGS + 1; 125 private static final int MENU_SYSTEM_SETTINGS = MENU_MANAGE_APPS + 1; 126 private static final int MENU_HELP = MENU_SYSTEM_SETTINGS + 1; 127 128 private static final int REQUEST_CREATE_SHORTCUT = 1; 129 private static final int REQUEST_CREATE_APPWIDGET = 5; 130 private static final int REQUEST_PICK_APPLICATION = 6; 131 private static final int REQUEST_PICK_SHORTCUT = 7; 132 private static final int REQUEST_PICK_APPWIDGET = 9; 133 private static final int REQUEST_PICK_WALLPAPER = 10; 134 135 private static final int REQUEST_BIND_APPWIDGET = 11; 136 137 static final String EXTRA_SHORTCUT_DUPLICATE = "duplicate"; 138 139 static final int SCREEN_COUNT = 5; 140 static final int DEFAULT_SCREEN = 2; 141 142 private static final String PREFERENCES = "launcher.preferences"; 143 static final String FORCE_ENABLE_ROTATION_PROPERTY = "launcher.force_enable_rotation"; 144 145 // The Intent extra that defines whether to ignore the launch animation 146 static final String INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION = 147 "com.android.launcher.intent.extra.shortcut.INGORE_LAUNCH_ANIMATION"; 148 149 // Type: int 150 private static final String RUNTIME_STATE_CURRENT_SCREEN = "launcher.current_screen"; 151 // Type: int 152 private static final String RUNTIME_STATE = "launcher.state"; 153 // Type: int 154 private static final String RUNTIME_STATE_PENDING_ADD_CONTAINER = "launcher.add_container"; 155 // Type: int 156 private static final String RUNTIME_STATE_PENDING_ADD_SCREEN = "launcher.add_screen"; 157 // Type: int 158 private static final String RUNTIME_STATE_PENDING_ADD_CELL_X = "launcher.add_cell_x"; 159 // Type: int 160 private static final String RUNTIME_STATE_PENDING_ADD_CELL_Y = "launcher.add_cell_y"; 161 // Type: boolean 162 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME = "launcher.rename_folder"; 163 // Type: long 164 private static final String RUNTIME_STATE_PENDING_FOLDER_RENAME_ID = "launcher.rename_folder_id"; 165 166 private static final String TOOLBAR_ICON_METADATA_NAME = "com.android.launcher.toolbar_icon"; 167 private static final String TOOLBAR_SEARCH_ICON_METADATA_NAME = 168 "com.android.launcher.toolbar_search_icon"; 169 private static final String TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME = 170 "com.android.launcher.toolbar_voice_search_icon"; 171 172 /** The different states that Launcher can be in. */ 173 private enum State { WORKSPACE, APPS_CUSTOMIZE, APPS_CUSTOMIZE_SPRING_LOADED }; 174 private State mState = State.WORKSPACE; 175 private AnimatorSet mStateAnimation; 176 private AnimatorSet mDividerAnimator; 177 178 static final int APPWIDGET_HOST_ID = 1024; 179 private static final int EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT = 300; 180 private static final int EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT = 600; 181 private static final int SHOW_CLING_DURATION = 550; 182 private static final int DISMISS_CLING_DURATION = 250; 183 184 private static final Object sLock = new Object(); 185 private static int sScreen = DEFAULT_SCREEN; 186 187 // How long to wait before the new-shortcut animation automatically pans the workspace 188 private static int NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS = 10; 189 190 private final BroadcastReceiver mCloseSystemDialogsReceiver 191 = new CloseSystemDialogsIntentReceiver(); 192 private final ContentObserver mWidgetObserver = new AppWidgetResetObserver(); 193 194 private LayoutInflater mInflater; 195 196 private Workspace mWorkspace; 197 private View mQsbDivider; 198 private View mDockDivider; 199 private DragLayer mDragLayer; 200 private DragController mDragController; 201 202 private AppWidgetManager mAppWidgetManager; 203 private LauncherAppWidgetHost mAppWidgetHost; 204 205 private ItemInfo mPendingAddInfo = new ItemInfo(); 206 private int[] mTmpAddItemCellCoordinates = new int[2]; 207 208 private FolderInfo mFolderInfo; 209 210 private Hotseat mHotseat; 211 private View mAllAppsButton; 212 213 private SearchDropTargetBar mSearchDropTargetBar; 214 private AppsCustomizeTabHost mAppsCustomizeTabHost; 215 private AppsCustomizePagedView mAppsCustomizeContent; 216 private boolean mAutoAdvanceRunning = false; 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 private boolean mOnResumeNeedsLoad; 228 229 private Bundle mSavedInstanceState; 230 231 private LauncherModel mModel; 232 private IconCache mIconCache; 233 private boolean mUserPresent = true; 234 private boolean mVisible = false; 235 private boolean mAttached = false; 236 237 private static LocaleConfiguration sLocaleConfiguration = null; 238 239 private static HashMap<Long, FolderInfo> sFolders = new HashMap<Long, FolderInfo>(); 240 241 private Intent mAppMarketIntent = null; 242 243 // Related to the auto-advancing of widgets 244 private final int ADVANCE_MSG = 1; 245 private final int mAdvanceInterval = 20000; 246 private final int mAdvanceStagger = 250; 247 private long mAutoAdvanceSentTime; 248 private long mAutoAdvanceTimeLeft = -1; 249 private HashMap<View, AppWidgetProviderInfo> mWidgetsToAdvance = 250 new HashMap<View, AppWidgetProviderInfo>(); 251 252 // Determines how long to wait after a rotation before restoring the screen orientation to 253 // match the sensor state. 254 private final int mRestoreScreenOrientationDelay = 500; 255 256 // External icons saved in case of resource changes, orientation, etc. 257 private static Drawable.ConstantState[] sGlobalSearchIcon = new Drawable.ConstantState[2]; 258 private static Drawable.ConstantState[] sVoiceSearchIcon = new Drawable.ConstantState[2]; 259 private static Drawable.ConstantState[] sAppMarketIcon = new Drawable.ConstantState[2]; 260 261 static final ArrayList<String> sDumpLogs = new ArrayList<String>(); 262 PendingAddWidgetInfo mWidgetBeingBoundOrConfigured = null; 263 264 // We only want to get the SharedPreferences once since it does an FS stat each time we get 265 // it from the context. 266 private SharedPreferences mSharedPrefs; 267 268 // Holds the page that we need to animate to, and the icon views that we need to animate up 269 // when we scroll to that page on resume. 270 private int mNewShortcutAnimatePage = -1; 271 private ArrayList<View> mNewShortcutAnimateViews = new ArrayList<View>(); 272 273 private BubbleTextView mWaitingForResume; 274 275 private Runnable mBuildLayersRunnable = new Runnable() { 276 public void run() { 277 if (mWorkspace != null) { 278 mWorkspace.buildPageHardwareLayers(); 279 } 280 } 281 }; 282 283 private static ArrayList<PendingAddArguments> sPendingAddList 284 = new ArrayList<PendingAddArguments>(); 285 286 private static class PendingAddArguments { 287 int requestCode; 288 Intent intent; 289 long container; 290 int screen; 291 int cellX; 292 int cellY; 293 } 294 295 @Override 296 protected void onCreate(Bundle savedInstanceState) { 297 if (DEBUG_STRICT_MODE) { 298 StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder() 299 .detectDiskReads() 300 .detectDiskWrites() 301 .detectNetwork() // or .detectAll() for all detectable problems 302 .penaltyLog() 303 .build()); 304 StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder() 305 .detectLeakedSqlLiteObjects() 306 .detectLeakedClosableObjects() 307 .penaltyLog() 308 .penaltyDeath() 309 .build()); 310 } 311 312 super.onCreate(savedInstanceState); 313 LauncherApplication app = ((LauncherApplication)getApplication()); 314 mSharedPrefs = getSharedPreferences(LauncherApplication.getSharedPreferencesKey(), 315 Context.MODE_PRIVATE); 316 mModel = app.setLauncher(this); 317 mIconCache = app.getIconCache(); 318 mDragController = new DragController(this); 319 mInflater = getLayoutInflater(); 320 321 mAppWidgetManager = AppWidgetManager.getInstance(this); 322 mAppWidgetHost = new LauncherAppWidgetHost(this, APPWIDGET_HOST_ID); 323 mAppWidgetHost.startListening(); 324 325 if (PROFILE_STARTUP) { 326 android.os.Debug.startMethodTracing( 327 Environment.getExternalStorageDirectory() + "/launcher"); 328 } 329 330 checkForLocaleChange(); 331 setContentView(R.layout.launcher); 332 setupViews(); 333 showFirstRunWorkspaceCling(); 334 335 registerContentObservers(); 336 337 lockAllApps(); 338 339 mSavedState = savedInstanceState; 340 restoreState(mSavedState); 341 342 // Update customization drawer _after_ restoring the states 343 if (mAppsCustomizeContent != null) { 344 mAppsCustomizeContent.onPackagesUpdated(); 345 } 346 347 if (PROFILE_STARTUP) { 348 android.os.Debug.stopMethodTracing(); 349 } 350 351 if (!mRestoring) { 352 mModel.startLoader(true); 353 } 354 355 if (!mModel.isAllAppsLoaded()) { 356 ViewGroup appsCustomizeContentParent = (ViewGroup) mAppsCustomizeContent.getParent(); 357 mInflater.inflate(R.layout.apps_customize_progressbar, appsCustomizeContentParent); 358 } 359 360 // For handling default keys 361 mDefaultKeySsb = new SpannableStringBuilder(); 362 Selection.setSelection(mDefaultKeySsb, 0); 363 364 IntentFilter filter = new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS); 365 registerReceiver(mCloseSystemDialogsReceiver, filter); 366 367 boolean searchVisible = false; 368 boolean voiceVisible = false; 369 // If we have a saved version of these external icons, we load them up immediately 370 int coi = getCurrentOrientationIndexForGlobalIcons(); 371 if (sGlobalSearchIcon[coi] == null || sVoiceSearchIcon[coi] == null || 372 sAppMarketIcon[coi] == null) { 373 updateAppMarketIcon(); 374 searchVisible = updateGlobalSearchIcon(); 375 voiceVisible = updateVoiceSearchIcon(searchVisible); 376 } 377 if (sGlobalSearchIcon[coi] != null) { 378 updateGlobalSearchIcon(sGlobalSearchIcon[coi]); 379 searchVisible = true; 380 } 381 if (sVoiceSearchIcon[coi] != null) { 382 updateVoiceSearchIcon(sVoiceSearchIcon[coi]); 383 voiceVisible = true; 384 } 385 if (sAppMarketIcon[coi] != null) { 386 updateAppMarketIcon(sAppMarketIcon[coi]); 387 } 388 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); 389 390 // On large interfaces, we want the screen to auto-rotate based on the current orientation 391 unlockScreenOrientation(true); 392 } 393 394 private void checkForLocaleChange() { 395 if (sLocaleConfiguration == null) { 396 new AsyncTask<Void, Void, LocaleConfiguration>() { 397 @Override 398 protected LocaleConfiguration doInBackground(Void... unused) { 399 LocaleConfiguration localeConfiguration = new LocaleConfiguration(); 400 readConfiguration(Launcher.this, localeConfiguration); 401 return localeConfiguration; 402 } 403 404 @Override 405 protected void onPostExecute(LocaleConfiguration result) { 406 sLocaleConfiguration = result; 407 checkForLocaleChange(); // recursive, but now with a locale configuration 408 } 409 }.execute(); 410 return; 411 } 412 413 final Configuration configuration = getResources().getConfiguration(); 414 415 final String previousLocale = sLocaleConfiguration.locale; 416 final String locale = configuration.locale.toString(); 417 418 final int previousMcc = sLocaleConfiguration.mcc; 419 final int mcc = configuration.mcc; 420 421 final int previousMnc = sLocaleConfiguration.mnc; 422 final int mnc = configuration.mnc; 423 424 boolean localeChanged = !locale.equals(previousLocale) || mcc != previousMcc || mnc != previousMnc; 425 426 if (localeChanged) { 427 sLocaleConfiguration.locale = locale; 428 sLocaleConfiguration.mcc = mcc; 429 sLocaleConfiguration.mnc = mnc; 430 431 mIconCache.flush(); 432 433 final LocaleConfiguration localeConfiguration = sLocaleConfiguration; 434 new Thread("WriteLocaleConfiguration") { 435 @Override 436 public void run() { 437 writeConfiguration(Launcher.this, localeConfiguration); 438 } 439 }.start(); 440 } 441 } 442 443 private static class LocaleConfiguration { 444 public String locale; 445 public int mcc = -1; 446 public int mnc = -1; 447 } 448 449 private static void readConfiguration(Context context, LocaleConfiguration configuration) { 450 DataInputStream in = null; 451 try { 452 in = new DataInputStream(context.openFileInput(PREFERENCES)); 453 configuration.locale = in.readUTF(); 454 configuration.mcc = in.readInt(); 455 configuration.mnc = in.readInt(); 456 } catch (FileNotFoundException e) { 457 // Ignore 458 } catch (IOException e) { 459 // Ignore 460 } finally { 461 if (in != null) { 462 try { 463 in.close(); 464 } catch (IOException e) { 465 // Ignore 466 } 467 } 468 } 469 } 470 471 private static void writeConfiguration(Context context, LocaleConfiguration configuration) { 472 DataOutputStream out = null; 473 try { 474 out = new DataOutputStream(context.openFileOutput(PREFERENCES, MODE_PRIVATE)); 475 out.writeUTF(configuration.locale); 476 out.writeInt(configuration.mcc); 477 out.writeInt(configuration.mnc); 478 out.flush(); 479 } catch (FileNotFoundException e) { 480 // Ignore 481 } catch (IOException e) { 482 //noinspection ResultOfMethodCallIgnored 483 context.getFileStreamPath(PREFERENCES).delete(); 484 } finally { 485 if (out != null) { 486 try { 487 out.close(); 488 } catch (IOException e) { 489 // Ignore 490 } 491 } 492 } 493 } 494 495 public DragLayer getDragLayer() { 496 return mDragLayer; 497 } 498 499 boolean isDraggingEnabled() { 500 // We prevent dragging when we are loading the workspace as it is possible to pick up a view 501 // that is subsequently removed from the workspace in startBinding(). 502 return !mModel.isLoadingWorkspace(); 503 } 504 505 static int getScreen() { 506 synchronized (sLock) { 507 return sScreen; 508 } 509 } 510 511 static void setScreen(int screen) { 512 synchronized (sLock) { 513 sScreen = screen; 514 } 515 } 516 517 /** 518 * Returns whether we should delay spring loaded mode -- for shortcuts and widgets that have 519 * a configuration step, this allows the proper animations to run after other transitions. 520 */ 521 private boolean completeAdd(PendingAddArguments args) { 522 boolean result = false; 523 switch (args.requestCode) { 524 case REQUEST_PICK_APPLICATION: 525 completeAddApplication(args.intent, args.container, args.screen, args.cellX, 526 args.cellY); 527 break; 528 case REQUEST_PICK_SHORTCUT: 529 processShortcut(args.intent); 530 break; 531 case REQUEST_CREATE_SHORTCUT: 532 completeAddShortcut(args.intent, args.container, args.screen, args.cellX, 533 args.cellY); 534 result = true; 535 break; 536 case REQUEST_PICK_APPWIDGET: 537 addAppWidgetFromPick(args.intent); 538 break; 539 case REQUEST_CREATE_APPWIDGET: 540 int appWidgetId = args.intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 541 completeAddAppWidget(appWidgetId, args.container, args.screen, null, null); 542 result = true; 543 break; 544 case REQUEST_PICK_WALLPAPER: 545 // We just wanted the activity result here so we can clear mWaitingForResult 546 break; 547 } 548 // Before adding this resetAddInfo(), after a shortcut was added to a workspace screen, 549 // if you turned the screen off and then back while in All Apps, Launcher would not 550 // return to the workspace. Clearing mAddInfo.container here fixes this issue 551 resetAddInfo(); 552 return result; 553 } 554 555 @Override 556 protected void onActivityResult( 557 final int requestCode, final int resultCode, final Intent data) { 558 if (requestCode == REQUEST_BIND_APPWIDGET) { 559 int appWidgetId = data != null ? 560 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; 561 if (resultCode == RESULT_CANCELED) { 562 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); 563 } else if (resultCode == RESULT_OK) { 564 addAppWidgetImpl(appWidgetId, mWidgetBeingBoundOrConfigured); 565 } 566 return; 567 } 568 boolean delayExitSpringLoadedMode = false; 569 boolean isWidgetDrop = (requestCode == REQUEST_PICK_APPWIDGET || 570 requestCode == REQUEST_CREATE_APPWIDGET); 571 mWaitingForResult = false; 572 573 // We have special handling for widgets 574 if (isWidgetDrop) { 575 int appWidgetId = data != null ? 576 data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1) : -1; 577 if (appWidgetId < 0) { 578 Log.e(TAG, "Error: appWidgetId (EXTRA_APPWIDGET_ID) was not returned from the \\" + 579 "widget configuration activity."); 580 completeTwoStageWidgetDrop(RESULT_CANCELED, appWidgetId); 581 } else { 582 completeTwoStageWidgetDrop(resultCode, appWidgetId); 583 } 584 return; 585 } 586 587 // The pattern used here is that a user PICKs a specific application, 588 // which, depending on the target, might need to CREATE the actual target. 589 590 // For example, the user would PICK_SHORTCUT for "Music playlist", and we 591 // launch over to the Music app to actually CREATE_SHORTCUT. 592 if (resultCode == RESULT_OK && mPendingAddInfo.container != ItemInfo.NO_ID) { 593 final PendingAddArguments args = new PendingAddArguments(); 594 args.requestCode = requestCode; 595 args.intent = data; 596 args.container = mPendingAddInfo.container; 597 args.screen = mPendingAddInfo.screen; 598 args.cellX = mPendingAddInfo.cellX; 599 args.cellY = mPendingAddInfo.cellY; 600 if (isWorkspaceLocked()) { 601 sPendingAddList.add(args); 602 } else { 603 delayExitSpringLoadedMode = completeAdd(args); 604 } 605 } 606 mDragLayer.clearAnimatedView(); 607 // Exit spring loaded mode if necessary after cancelling the configuration of a widget 608 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), delayExitSpringLoadedMode, 609 null); 610 } 611 612 private void completeTwoStageWidgetDrop(final int resultCode, final int appWidgetId) { 613 CellLayout cellLayout = 614 (CellLayout) mWorkspace.getChildAt(mWidgetBeingBoundOrConfigured.screen); 615 Runnable onCompleteRunnable = null; 616 int animationType = 0; 617 618 if (resultCode == RESULT_OK) { 619 animationType = Workspace.COMPLETE_TWO_STAGE_WIDGET_DROP_ANIMATION; 620 final AppWidgetHostView layout = mAppWidgetHost.createView(this, appWidgetId, 621 mWidgetBeingBoundOrConfigured.info); 622 mWidgetBeingBoundOrConfigured.boundWidget = layout; 623 onCompleteRunnable = new Runnable() { 624 @Override 625 public void run() { 626 completeAddAppWidget(appWidgetId, mPendingAddInfo.container, 627 mPendingAddInfo.screen, layout, null); 628 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, 629 null); 630 } 631 }; 632 } else if (resultCode == RESULT_CANCELED) { 633 animationType = Workspace.CANCEL_TWO_STAGE_WIDGET_DROP_ANIMATION; 634 onCompleteRunnable = new Runnable() { 635 @Override 636 public void run() { 637 exitSpringLoadedDragModeDelayed((resultCode != RESULT_CANCELED), false, 638 null); 639 } 640 }; 641 } 642 mWorkspace.animateWidgetDrop(mWidgetBeingBoundOrConfigured, cellLayout, 643 (DragView) mDragLayer.getAnimatedView(), onCompleteRunnable, 644 animationType, mWidgetBeingBoundOrConfigured.boundWidget, true); 645 mWidgetBeingBoundOrConfigured = null; 646 } 647 648 @Override 649 protected void onResume() { 650 super.onResume(); 651 652 // Process any items that were added while Launcher was away 653 InstallShortcutReceiver.flushInstallQueue(this); 654 655 mPaused = false; 656 if (mRestoring || mOnResumeNeedsLoad) { 657 mWorkspaceLoading = true; 658 mModel.startLoader(true); 659 mRestoring = false; 660 mOnResumeNeedsLoad = false; 661 } 662 663 // Reset the pressed state of icons that were locked in the press state while activities 664 // were launching 665 if (mWaitingForResume != null) { 666 // Resets the previous workspace icon press state 667 mWaitingForResume.setStayPressed(false); 668 } 669 if (mAppsCustomizeContent != null) { 670 // Resets the previous all apps icon press state 671 mAppsCustomizeContent.resetDrawableState(); 672 } 673 } 674 675 @Override 676 protected void onPause() { 677 // NOTE: We want all transitions from launcher to act as if the wallpaper were enabled 678 // to be consistent. So re-enable the flag here, and we will re-disable it as necessary 679 // when Launcher resumes and we are still in AllApps. 680 updateWallpaperVisibility(true); 681 682 super.onPause(); 683 mPaused = true; 684 mDragController.cancelDrag(); 685 mDragController.resetLastGestureUpTime(); 686 } 687 688 @Override 689 public Object onRetainNonConfigurationInstance() { 690 // Flag the loader to stop early before switching 691 mModel.stopLoader(); 692 if (mAppsCustomizeContent != null) { 693 mAppsCustomizeContent.surrender(); 694 } 695 return Boolean.TRUE; 696 } 697 698 // We can't hide the IME if it was forced open. So don't bother 699 /* 700 @Override 701 public void onWindowFocusChanged(boolean hasFocus) { 702 super.onWindowFocusChanged(hasFocus); 703 704 if (hasFocus) { 705 final InputMethodManager inputManager = (InputMethodManager) 706 getSystemService(Context.INPUT_METHOD_SERVICE); 707 WindowManager.LayoutParams lp = getWindow().getAttributes(); 708 inputManager.hideSoftInputFromWindow(lp.token, 0, new android.os.ResultReceiver(new 709 android.os.Handler()) { 710 protected void onReceiveResult(int resultCode, Bundle resultData) { 711 Log.d(TAG, "ResultReceiver got resultCode=" + resultCode); 712 } 713 }); 714 Log.d(TAG, "called hideSoftInputFromWindow from onWindowFocusChanged"); 715 } 716 } 717 */ 718 719 private boolean acceptFilter() { 720 final InputMethodManager inputManager = (InputMethodManager) 721 getSystemService(Context.INPUT_METHOD_SERVICE); 722 return !inputManager.isFullscreenMode(); 723 } 724 725 @Override 726 public boolean onKeyDown(int keyCode, KeyEvent event) { 727 final int uniChar = event.getUnicodeChar(); 728 final boolean handled = super.onKeyDown(keyCode, event); 729 final boolean isKeyNotWhitespace = uniChar > 0 && !Character.isWhitespace(uniChar); 730 if (!handled && acceptFilter() && isKeyNotWhitespace) { 731 boolean gotKey = TextKeyListener.getInstance().onKeyDown(mWorkspace, mDefaultKeySsb, 732 keyCode, event); 733 if (gotKey && mDefaultKeySsb != null && mDefaultKeySsb.length() > 0) { 734 // something usable has been typed - start a search 735 // the typed text will be retrieved and cleared by 736 // showSearchDialog() 737 // If there are multiple keystrokes before the search dialog takes focus, 738 // onSearchRequested() will be called for every keystroke, 739 // but it is idempotent, so it's fine. 740 return onSearchRequested(); 741 } 742 } 743 744 // Eat the long press event so the keyboard doesn't come up. 745 if (keyCode == KeyEvent.KEYCODE_MENU && event.isLongPress()) { 746 return true; 747 } 748 749 return handled; 750 } 751 752 private String getTypedText() { 753 return mDefaultKeySsb.toString(); 754 } 755 756 private void clearTypedText() { 757 mDefaultKeySsb.clear(); 758 mDefaultKeySsb.clearSpans(); 759 Selection.setSelection(mDefaultKeySsb, 0); 760 } 761 762 /** 763 * Given the integer (ordinal) value of a State enum instance, convert it to a variable of type 764 * State 765 */ 766 private static State intToState(int stateOrdinal) { 767 State state = State.WORKSPACE; 768 final State[] stateValues = State.values(); 769 for (int i = 0; i < stateValues.length; i++) { 770 if (stateValues[i].ordinal() == stateOrdinal) { 771 state = stateValues[i]; 772 break; 773 } 774 } 775 return state; 776 } 777 778 /** 779 * Restores the previous state, if it exists. 780 * 781 * @param savedState The previous state. 782 */ 783 private void restoreState(Bundle savedState) { 784 if (savedState == null) { 785 return; 786 } 787 788 State state = intToState(savedState.getInt(RUNTIME_STATE, State.WORKSPACE.ordinal())); 789 if (state == State.APPS_CUSTOMIZE) { 790 showAllApps(false); 791 } 792 793 int currentScreen = savedState.getInt(RUNTIME_STATE_CURRENT_SCREEN, -1); 794 if (currentScreen > -1) { 795 mWorkspace.setCurrentPage(currentScreen); 796 } 797 798 final long pendingAddContainer = savedState.getLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, -1); 799 final int pendingAddScreen = savedState.getInt(RUNTIME_STATE_PENDING_ADD_SCREEN, -1); 800 801 if (pendingAddContainer != ItemInfo.NO_ID && pendingAddScreen > -1) { 802 mPendingAddInfo.container = pendingAddContainer; 803 mPendingAddInfo.screen = pendingAddScreen; 804 mPendingAddInfo.cellX = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_X); 805 mPendingAddInfo.cellY = savedState.getInt(RUNTIME_STATE_PENDING_ADD_CELL_Y); 806 mRestoring = true; 807 } 808 809 boolean renameFolder = savedState.getBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, false); 810 if (renameFolder) { 811 long id = savedState.getLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID); 812 mFolderInfo = mModel.getFolderById(this, sFolders, id); 813 mRestoring = true; 814 } 815 816 817 // Restore the AppsCustomize tab 818 if (mAppsCustomizeTabHost != null) { 819 String curTab = savedState.getString("apps_customize_currentTab"); 820 if (curTab != null) { 821 // We set this directly so that there is no delay before the tab is set 822 mAppsCustomizeContent.setContentType( 823 mAppsCustomizeTabHost.getContentTypeForTabTag(curTab)); 824 mAppsCustomizeTabHost.setCurrentTabByTag(curTab); 825 mAppsCustomizeContent.loadAssociatedPages( 826 mAppsCustomizeContent.getCurrentPage()); 827 } 828 829 int currentIndex = savedState.getInt("apps_customize_currentIndex"); 830 mAppsCustomizeContent.restorePageForIndex(currentIndex); 831 } 832 } 833 834 /** 835 * Finds all the views we need and configure them properly. 836 */ 837 private void setupViews() { 838 final DragController dragController = mDragController; 839 840 mDragLayer = (DragLayer) findViewById(R.id.drag_layer); 841 mWorkspace = (Workspace) mDragLayer.findViewById(R.id.workspace); 842 mQsbDivider = (ImageView) findViewById(R.id.qsb_divider); 843 mDockDivider = (ImageView) findViewById(R.id.dock_divider); 844 845 // Setup the drag layer 846 mDragLayer.setup(this, dragController); 847 848 // Setup the hotseat 849 mHotseat = (Hotseat) findViewById(R.id.hotseat); 850 if (mHotseat != null) { 851 mHotseat.setup(this); 852 } 853 854 // Setup the workspace 855 mWorkspace.setHapticFeedbackEnabled(false); 856 mWorkspace.setOnLongClickListener(this); 857 mWorkspace.setup(dragController); 858 dragController.addDragListener(mWorkspace); 859 860 // Get the search/delete bar 861 mSearchDropTargetBar = (SearchDropTargetBar) mDragLayer.findViewById(R.id.qsb_bar); 862 863 // Setup AppsCustomize 864 mAppsCustomizeTabHost = (AppsCustomizeTabHost) 865 findViewById(R.id.apps_customize_pane); 866 mAppsCustomizeContent = (AppsCustomizePagedView) 867 mAppsCustomizeTabHost.findViewById(R.id.apps_customize_pane_content); 868 mAppsCustomizeTabHost.setup(this); 869 mAppsCustomizeContent.setup(this, dragController); 870 871 // Get the all apps button 872 mAllAppsButton = findViewById(R.id.all_apps_button); 873 if (mAllAppsButton != null) { 874 mAllAppsButton.setOnTouchListener(new View.OnTouchListener() { 875 @Override 876 public boolean onTouch(View v, MotionEvent event) { 877 if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) { 878 onTouchDownAllAppsButton(v); 879 } 880 return false; 881 } 882 }); 883 } 884 // Setup the drag controller (drop targets have to be added in reverse order in priority) 885 dragController.setDragScoller(mWorkspace); 886 dragController.setScrollView(mDragLayer); 887 dragController.setMoveTarget(mWorkspace); 888 dragController.addDropTarget(mWorkspace); 889 if (mSearchDropTargetBar != null) { 890 mSearchDropTargetBar.setup(this, dragController); 891 } 892 } 893 894 /** 895 * Creates a view representing a shortcut. 896 * 897 * @param info The data structure describing the shortcut. 898 * 899 * @return A View inflated from R.layout.application. 900 */ 901 View createShortcut(ShortcutInfo info) { 902 return createShortcut(R.layout.application, 903 (ViewGroup) mWorkspace.getChildAt(mWorkspace.getCurrentPage()), info); 904 } 905 906 /** 907 * Creates a view representing a shortcut inflated from the specified resource. 908 * 909 * @param layoutResId The id of the XML layout used to create the shortcut. 910 * @param parent The group the shortcut belongs to. 911 * @param info The data structure describing the shortcut. 912 * 913 * @return A View inflated from layoutResId. 914 */ 915 View createShortcut(int layoutResId, ViewGroup parent, ShortcutInfo info) { 916 BubbleTextView favorite = (BubbleTextView) mInflater.inflate(layoutResId, parent, false); 917 favorite.applyFromShortcutInfo(info, mIconCache); 918 favorite.setOnClickListener(this); 919 return favorite; 920 } 921 922 /** 923 * Add an application shortcut to the workspace. 924 * 925 * @param data The intent describing the application. 926 * @param cellInfo The position on screen where to create the shortcut. 927 */ 928 void completeAddApplication(Intent data, long container, int screen, int cellX, int cellY) { 929 final int[] cellXY = mTmpAddItemCellCoordinates; 930 final CellLayout layout = getCellLayout(container, screen); 931 932 // First we check if we already know the exact location where we want to add this item. 933 if (cellX >= 0 && cellY >= 0) { 934 cellXY[0] = cellX; 935 cellXY[1] = cellY; 936 } else if (!layout.findCellForSpan(cellXY, 1, 1)) { 937 showOutOfSpaceMessage(isHotseatLayout(layout)); 938 return; 939 } 940 941 final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this); 942 943 if (info != null) { 944 info.setActivity(data.getComponent(), Intent.FLAG_ACTIVITY_NEW_TASK | 945 Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 946 info.container = ItemInfo.NO_ID; 947 mWorkspace.addApplicationShortcut(info, layout, container, screen, cellXY[0], cellXY[1], 948 isWorkspaceLocked(), cellX, cellY); 949 } else { 950 Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data); 951 } 952 } 953 954 /** 955 * Add a shortcut to the workspace. 956 * 957 * @param data The intent describing the shortcut. 958 * @param cellInfo The position on screen where to create the shortcut. 959 */ 960 private void completeAddShortcut(Intent data, long container, int screen, int cellX, 961 int cellY) { 962 int[] cellXY = mTmpAddItemCellCoordinates; 963 int[] touchXY = mPendingAddInfo.dropPos; 964 CellLayout layout = getCellLayout(container, screen); 965 966 boolean foundCellSpan = false; 967 968 ShortcutInfo info = mModel.infoFromShortcutIntent(this, data, null); 969 if (info == null) { 970 return; 971 } 972 final View view = createShortcut(info); 973 974 // First we check if we already know the exact location where we want to add this item. 975 if (cellX >= 0 && cellY >= 0) { 976 cellXY[0] = cellX; 977 cellXY[1] = cellY; 978 foundCellSpan = true; 979 980 // If appropriate, either create a folder or add to an existing folder 981 if (mWorkspace.createUserFolderIfNecessary(view, container, layout, cellXY, 0, 982 true, null,null)) { 983 return; 984 } 985 DragObject dragObject = new DragObject(); 986 dragObject.dragInfo = info; 987 if (mWorkspace.addToExistingFolderIfNecessary(view, layout, cellXY, 0, dragObject, 988 true)) { 989 return; 990 } 991 } else if (touchXY != null) { 992 // when dragging and dropping, just find the closest free spot 993 int[] result = layout.findNearestVacantArea(touchXY[0], touchXY[1], 1, 1, cellXY); 994 foundCellSpan = (result != null); 995 } else { 996 foundCellSpan = layout.findCellForSpan(cellXY, 1, 1); 997 } 998 999 if (!foundCellSpan) { 1000 showOutOfSpaceMessage(isHotseatLayout(layout)); 1001 return; 1002 } 1003 1004 LauncherModel.addItemToDatabase(this, info, container, screen, cellXY[0], cellXY[1], false); 1005 1006 if (!mRestoring) { 1007 mWorkspace.addInScreen(view, container, screen, cellXY[0], cellXY[1], 1, 1, 1008 isWorkspaceLocked()); 1009 } 1010 } 1011 1012 static int[] getSpanForWidget(Context context, ComponentName component, int minWidth, 1013 int minHeight) { 1014 Rect padding = AppWidgetHostView.getDefaultPaddingForWidget(context, component, null); 1015 // We want to account for the extra amount of padding that we are adding to the widget 1016 // to ensure that it gets the full amount of space that it has requested 1017 int requiredWidth = minWidth + padding.left + padding.right; 1018 int requiredHeight = minHeight + padding.top + padding.bottom; 1019 return CellLayout.rectToCell(context.getResources(), requiredWidth, requiredHeight, null); 1020 } 1021 1022 static int[] getSpanForWidget(Context context, AppWidgetProviderInfo info) { 1023 return getSpanForWidget(context, info.provider, info.minWidth, info.minHeight); 1024 } 1025 1026 static int[] getMinSpanForWidget(Context context, AppWidgetProviderInfo info) { 1027 return getSpanForWidget(context, info.provider, info.minResizeWidth, info.minResizeHeight); 1028 } 1029 1030 static int[] getSpanForWidget(Context context, PendingAddWidgetInfo info) { 1031 return getSpanForWidget(context, info.componentName, info.minWidth, info.minHeight); 1032 } 1033 1034 static int[] getMinSpanForWidget(Context context, PendingAddWidgetInfo info) { 1035 return getSpanForWidget(context, info.componentName, info.minResizeWidth, 1036 info.minResizeHeight); 1037 } 1038 1039 /** 1040 * Add a widget to the workspace. 1041 * 1042 * @param appWidgetId The app widget id 1043 * @param cellInfo The position on screen where to create the widget. 1044 */ 1045 private void completeAddAppWidget(final int appWidgetId, long container, int screen, 1046 AppWidgetHostView hostView, AppWidgetProviderInfo appWidgetInfo) { 1047 if (appWidgetInfo == null) { 1048 appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 1049 } 1050 1051 // Calculate the grid spans needed to fit this widget 1052 CellLayout layout = getCellLayout(container, screen); 1053 1054 int[] minSpanXY = getMinSpanForWidget(this, appWidgetInfo); 1055 int[] spanXY = getSpanForWidget(this, appWidgetInfo); 1056 1057 // Try finding open space on Launcher screen 1058 // We have saved the position to which the widget was dragged-- this really only matters 1059 // if we are placing widgets on a "spring-loaded" screen 1060 int[] cellXY = mTmpAddItemCellCoordinates; 1061 int[] touchXY = mPendingAddInfo.dropPos; 1062 int[] finalSpan = new int[2]; 1063 boolean foundCellSpan = false; 1064 if (mPendingAddInfo.cellX >= 0 && mPendingAddInfo.cellY >= 0) { 1065 cellXY[0] = mPendingAddInfo.cellX; 1066 cellXY[1] = mPendingAddInfo.cellY; 1067 spanXY[0] = mPendingAddInfo.spanX; 1068 spanXY[1] = mPendingAddInfo.spanY; 1069 foundCellSpan = true; 1070 } else if (touchXY != null) { 1071 // when dragging and dropping, just find the closest free spot 1072 int[] result = layout.findNearestVacantArea( 1073 touchXY[0], touchXY[1], minSpanXY[0], minSpanXY[1], spanXY[0], 1074 spanXY[1], cellXY, finalSpan); 1075 spanXY[0] = finalSpan[0]; 1076 spanXY[1] = finalSpan[1]; 1077 foundCellSpan = (result != null); 1078 } else { 1079 foundCellSpan = layout.findCellForSpan(cellXY, minSpanXY[0], minSpanXY[1]); 1080 } 1081 1082 if (!foundCellSpan) { 1083 if (appWidgetId != -1) { 1084 // Deleting an app widget ID is a void call but writes to disk before returning 1085 // to the caller... 1086 new Thread("deleteAppWidgetId") { 1087 public void run() { 1088 mAppWidgetHost.deleteAppWidgetId(appWidgetId); 1089 } 1090 }.start(); 1091 } 1092 showOutOfSpaceMessage(isHotseatLayout(layout)); 1093 return; 1094 } 1095 1096 // Build Launcher-specific widget info and save to database 1097 LauncherAppWidgetInfo launcherInfo = new LauncherAppWidgetInfo(appWidgetId, 1098 appWidgetInfo.provider); 1099 launcherInfo.spanX = spanXY[0]; 1100 launcherInfo.spanY = spanXY[1]; 1101 launcherInfo.minSpanX = mPendingAddInfo.minSpanX; 1102 launcherInfo.minSpanY = mPendingAddInfo.minSpanY; 1103 1104 LauncherModel.addItemToDatabase(this, launcherInfo, 1105 container, screen, cellXY[0], cellXY[1], false); 1106 1107 if (!mRestoring) { 1108 if (hostView == null) { 1109 // Perform actual inflation because we're live 1110 launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); 1111 launcherInfo.hostView.setAppWidget(appWidgetId, appWidgetInfo); 1112 } else { 1113 // The AppWidgetHostView has already been inflated and instantiated 1114 launcherInfo.hostView = hostView; 1115 } 1116 1117 launcherInfo.hostView.setTag(launcherInfo); 1118 launcherInfo.hostView.setVisibility(View.VISIBLE); 1119 AppWidgetResizeFrame.updateWidgetSizeRanges(launcherInfo.hostView, 1120 this, launcherInfo.spanX, launcherInfo.spanY); 1121 mWorkspace.addInScreen(launcherInfo.hostView, container, screen, cellXY[0], cellXY[1], 1122 launcherInfo.spanX, launcherInfo.spanY, isWorkspaceLocked()); 1123 1124 addWidgetToAutoAdvanceIfNeeded(launcherInfo.hostView, appWidgetInfo); 1125 } 1126 resetAddInfo(); 1127 } 1128 1129 private final BroadcastReceiver mReceiver = new BroadcastReceiver() { 1130 @Override 1131 public void onReceive(Context context, Intent intent) { 1132 final String action = intent.getAction(); 1133 if (Intent.ACTION_SCREEN_OFF.equals(action)) { 1134 mUserPresent = false; 1135 mDragLayer.clearAllResizeFrames(); 1136 updateRunning(); 1137 1138 // Reset AllApps to its initial state only if we are not in the middle of 1139 // processing a multi-step drop 1140 if (mAppsCustomizeTabHost != null && mPendingAddInfo.container == ItemInfo.NO_ID) { 1141 mAppsCustomizeTabHost.reset(); 1142 showWorkspace(false); 1143 } 1144 } else if (Intent.ACTION_USER_PRESENT.equals(action)) { 1145 mUserPresent = true; 1146 updateRunning(); 1147 } 1148 } 1149 }; 1150 1151 @Override 1152 public void onAttachedToWindow() { 1153 super.onAttachedToWindow(); 1154 1155 // Listen for broadcasts related to user-presence 1156 final IntentFilter filter = new IntentFilter(); 1157 filter.addAction(Intent.ACTION_SCREEN_OFF); 1158 filter.addAction(Intent.ACTION_USER_PRESENT); 1159 registerReceiver(mReceiver, filter); 1160 1161 mAttached = true; 1162 mVisible = true; 1163 } 1164 1165 @Override 1166 public void onDetachedFromWindow() { 1167 super.onDetachedFromWindow(); 1168 mVisible = false; 1169 1170 if (mAttached) { 1171 unregisterReceiver(mReceiver); 1172 mAttached = false; 1173 } 1174 updateRunning(); 1175 } 1176 1177 public void onWindowVisibilityChanged(int visibility) { 1178 mVisible = visibility == View.VISIBLE; 1179 updateRunning(); 1180 // The following code used to be in onResume, but it turns out onResume is called when 1181 // you're in All Apps and click home to go to the workspace. onWindowVisibilityChanged 1182 // is a more appropriate event to handle 1183 if (mVisible) { 1184 mAppsCustomizeTabHost.onWindowVisible(); 1185 if (!mWorkspaceLoading) { 1186 final ViewTreeObserver observer = mWorkspace.getViewTreeObserver(); 1187 // We want to let Launcher draw itself at least once before we force it to build 1188 // layers on all the workspace pages, so that transitioning to Launcher from other 1189 // apps is nice and speedy. Usually the first call to preDraw doesn't correspond to 1190 // a true draw so we wait until the second preDraw call to be safe 1191 observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() { 1192 public boolean onPreDraw() { 1193 // We delay the layer building a bit in order to give 1194 // other message processing a time to run. In particular 1195 // this avoids a delay in hiding the IME if it was 1196 // currently shown, because doing that may involve 1197 // some communication back with the app. 1198 mWorkspace.postDelayed(mBuildLayersRunnable, 500); 1199 1200 // We had to enable the wallpaper visibility when launching apps from all 1201 // apps (so that the transitions would be the same as when launching from 1202 // workspace) so take this time to see if we need to re-disable the 1203 // wallpaper visibility to ensure performance. 1204 mWorkspace.post(new Runnable() { 1205 @Override 1206 public void run() { 1207 if (mState == State.APPS_CUSTOMIZE) { 1208 if (mAppsCustomizeTabHost != null && 1209 !mAppsCustomizeTabHost.isTransitioning()) { 1210 updateWallpaperVisibility(false); 1211 } 1212 } 1213 } 1214 }); 1215 1216 observer.removeOnPreDrawListener(this); 1217 return true; 1218 } 1219 }); 1220 } 1221 // When Launcher comes back to foreground, a different Activity might be responsible for 1222 // the app market intent, so refresh the icon 1223 updateAppMarketIcon(); 1224 clearTypedText(); 1225 } 1226 } 1227 1228 private void sendAdvanceMessage(long delay) { 1229 mHandler.removeMessages(ADVANCE_MSG); 1230 Message msg = mHandler.obtainMessage(ADVANCE_MSG); 1231 mHandler.sendMessageDelayed(msg, delay); 1232 mAutoAdvanceSentTime = System.currentTimeMillis(); 1233 } 1234 1235 private void updateRunning() { 1236 boolean autoAdvanceRunning = mVisible && mUserPresent && !mWidgetsToAdvance.isEmpty(); 1237 if (autoAdvanceRunning != mAutoAdvanceRunning) { 1238 mAutoAdvanceRunning = autoAdvanceRunning; 1239 if (autoAdvanceRunning) { 1240 long delay = mAutoAdvanceTimeLeft == -1 ? mAdvanceInterval : mAutoAdvanceTimeLeft; 1241 sendAdvanceMessage(delay); 1242 } else { 1243 if (!mWidgetsToAdvance.isEmpty()) { 1244 mAutoAdvanceTimeLeft = Math.max(0, mAdvanceInterval - 1245 (System.currentTimeMillis() - mAutoAdvanceSentTime)); 1246 } 1247 mHandler.removeMessages(ADVANCE_MSG); 1248 mHandler.removeMessages(0); // Remove messages sent using postDelayed() 1249 } 1250 } 1251 } 1252 1253 private final Handler mHandler = new Handler() { 1254 @Override 1255 public void handleMessage(Message msg) { 1256 if (msg.what == ADVANCE_MSG) { 1257 int i = 0; 1258 for (View key: mWidgetsToAdvance.keySet()) { 1259 final View v = key.findViewById(mWidgetsToAdvance.get(key).autoAdvanceViewId); 1260 final int delay = mAdvanceStagger * i; 1261 if (v instanceof Advanceable) { 1262 postDelayed(new Runnable() { 1263 public void run() { 1264 ((Advanceable) v).advance(); 1265 } 1266 }, delay); 1267 } 1268 i++; 1269 } 1270 sendAdvanceMessage(mAdvanceInterval); 1271 } 1272 } 1273 }; 1274 1275 void addWidgetToAutoAdvanceIfNeeded(View hostView, AppWidgetProviderInfo appWidgetInfo) { 1276 if (appWidgetInfo == null || appWidgetInfo.autoAdvanceViewId == -1) return; 1277 View v = hostView.findViewById(appWidgetInfo.autoAdvanceViewId); 1278 if (v instanceof Advanceable) { 1279 mWidgetsToAdvance.put(hostView, appWidgetInfo); 1280 ((Advanceable) v).fyiWillBeAdvancedByHostKThx(); 1281 updateRunning(); 1282 } 1283 } 1284 1285 void removeWidgetToAutoAdvance(View hostView) { 1286 if (mWidgetsToAdvance.containsKey(hostView)) { 1287 mWidgetsToAdvance.remove(hostView); 1288 updateRunning(); 1289 } 1290 } 1291 1292 public void removeAppWidget(LauncherAppWidgetInfo launcherInfo) { 1293 removeWidgetToAutoAdvance(launcherInfo.hostView); 1294 launcherInfo.hostView = null; 1295 } 1296 1297 void showOutOfSpaceMessage(boolean isHotseatLayout) { 1298 int strId = (isHotseatLayout ? R.string.hotseat_out_of_space : R.string.out_of_space); 1299 Toast.makeText(this, getString(strId), Toast.LENGTH_SHORT).show(); 1300 } 1301 1302 public LauncherAppWidgetHost getAppWidgetHost() { 1303 return mAppWidgetHost; 1304 } 1305 1306 public LauncherModel getModel() { 1307 return mModel; 1308 } 1309 1310 void closeSystemDialogs() { 1311 getWindow().closeAllPanels(); 1312 1313 // Whatever we were doing is hereby canceled. 1314 mWaitingForResult = false; 1315 } 1316 1317 @Override 1318 protected void onNewIntent(Intent intent) { 1319 super.onNewIntent(intent); 1320 1321 // Close the menu 1322 if (Intent.ACTION_MAIN.equals(intent.getAction())) { 1323 // also will cancel mWaitingForResult. 1324 closeSystemDialogs(); 1325 1326 boolean alreadyOnHome = ((intent.getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) 1327 != Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT); 1328 1329 Folder openFolder = mWorkspace.getOpenFolder(); 1330 // In all these cases, only animate if we're already on home 1331 mWorkspace.exitWidgetResizeMode(); 1332 if (alreadyOnHome && mState == State.WORKSPACE && !mWorkspace.isTouchActive() && 1333 openFolder == null) { 1334 mWorkspace.moveToDefaultScreen(true); 1335 } 1336 1337 closeFolder(); 1338 exitSpringLoadedDragMode(); 1339 showWorkspace(alreadyOnHome); 1340 1341 final View v = getWindow().peekDecorView(); 1342 if (v != null && v.getWindowToken() != null) { 1343 InputMethodManager imm = (InputMethodManager)getSystemService( 1344 INPUT_METHOD_SERVICE); 1345 imm.hideSoftInputFromWindow(v.getWindowToken(), 0); 1346 } 1347 1348 // Reset AllApps to its initial state 1349 if (!alreadyOnHome && mAppsCustomizeTabHost != null) { 1350 mAppsCustomizeTabHost.reset(); 1351 } 1352 } 1353 } 1354 1355 @Override 1356 protected void onRestoreInstanceState(Bundle savedInstanceState) { 1357 // Do not call super here 1358 mSavedInstanceState = savedInstanceState; 1359 } 1360 1361 @Override 1362 protected void onSaveInstanceState(Bundle outState) { 1363 outState.putInt(RUNTIME_STATE_CURRENT_SCREEN, mWorkspace.getCurrentPage()); 1364 super.onSaveInstanceState(outState); 1365 1366 outState.putInt(RUNTIME_STATE, mState.ordinal()); 1367 // We close any open folder since it will not be re-opened, and we need to make sure 1368 // this state is reflected. 1369 closeFolder(); 1370 1371 if (mPendingAddInfo.container != ItemInfo.NO_ID && mPendingAddInfo.screen > -1 && 1372 mWaitingForResult) { 1373 outState.putLong(RUNTIME_STATE_PENDING_ADD_CONTAINER, mPendingAddInfo.container); 1374 outState.putInt(RUNTIME_STATE_PENDING_ADD_SCREEN, mPendingAddInfo.screen); 1375 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_X, mPendingAddInfo.cellX); 1376 outState.putInt(RUNTIME_STATE_PENDING_ADD_CELL_Y, mPendingAddInfo.cellY); 1377 } 1378 1379 if (mFolderInfo != null && mWaitingForResult) { 1380 outState.putBoolean(RUNTIME_STATE_PENDING_FOLDER_RENAME, true); 1381 outState.putLong(RUNTIME_STATE_PENDING_FOLDER_RENAME_ID, mFolderInfo.id); 1382 } 1383 1384 // Save the current AppsCustomize tab 1385 if (mAppsCustomizeTabHost != null) { 1386 String currentTabTag = mAppsCustomizeTabHost.getCurrentTabTag(); 1387 if (currentTabTag != null) { 1388 outState.putString("apps_customize_currentTab", currentTabTag); 1389 } 1390 int currentIndex = mAppsCustomizeContent.getSaveInstanceStateIndex(); 1391 outState.putInt("apps_customize_currentIndex", currentIndex); 1392 } 1393 } 1394 1395 @Override 1396 public void onDestroy() { 1397 super.onDestroy(); 1398 1399 // Remove all pending runnables 1400 mHandler.removeMessages(ADVANCE_MSG); 1401 mHandler.removeMessages(0); 1402 mWorkspace.removeCallbacks(mBuildLayersRunnable); 1403 1404 // Stop callbacks from LauncherModel 1405 LauncherApplication app = ((LauncherApplication) getApplication()); 1406 mModel.stopLoader(); 1407 app.setLauncher(null); 1408 1409 try { 1410 mAppWidgetHost.stopListening(); 1411 } catch (NullPointerException ex) { 1412 Log.w(TAG, "problem while stopping AppWidgetHost during Launcher destruction", ex); 1413 } 1414 mAppWidgetHost = null; 1415 1416 mWidgetsToAdvance.clear(); 1417 1418 TextKeyListener.getInstance().release(); 1419 1420 1421 unbindWorkspaceAndHotseatItems(); 1422 1423 getContentResolver().unregisterContentObserver(mWidgetObserver); 1424 unregisterReceiver(mCloseSystemDialogsReceiver); 1425 1426 mDragLayer.clearAllResizeFrames(); 1427 ((ViewGroup) mWorkspace.getParent()).removeAllViews(); 1428 mWorkspace.removeAllViews(); 1429 mWorkspace = null; 1430 mDragController = null; 1431 1432 ValueAnimator.clearAllAnimations(); 1433 } 1434 1435 public DragController getDragController() { 1436 return mDragController; 1437 } 1438 1439 @Override 1440 public void startActivityForResult(Intent intent, int requestCode) { 1441 if (requestCode >= 0) mWaitingForResult = true; 1442 super.startActivityForResult(intent, requestCode); 1443 } 1444 1445 /** 1446 * Indicates that we want global search for this activity by setting the globalSearch 1447 * argument for {@link #startSearch} to true. 1448 */ 1449 @Override 1450 public void startSearch(String initialQuery, boolean selectInitialQuery, 1451 Bundle appSearchData, boolean globalSearch) { 1452 1453 showWorkspace(true); 1454 1455 if (initialQuery == null) { 1456 // Use any text typed in the launcher as the initial query 1457 initialQuery = getTypedText(); 1458 } 1459 if (appSearchData == null) { 1460 appSearchData = new Bundle(); 1461 appSearchData.putString(Search.SOURCE, "launcher-search"); 1462 } 1463 Rect sourceBounds = mSearchDropTargetBar.getSearchBarBounds(); 1464 1465 final SearchManager searchManager = 1466 (SearchManager) getSystemService(Context.SEARCH_SERVICE); 1467 searchManager.startSearch(initialQuery, selectInitialQuery, getComponentName(), 1468 appSearchData, globalSearch, sourceBounds); 1469 } 1470 1471 @Override 1472 public boolean onCreateOptionsMenu(Menu menu) { 1473 if (isWorkspaceLocked()) { 1474 return false; 1475 } 1476 1477 super.onCreateOptionsMenu(menu); 1478 1479 Intent manageApps = new Intent(Settings.ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS); 1480 manageApps.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1481 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1482 Intent settings = new Intent(android.provider.Settings.ACTION_SETTINGS); 1483 settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1484 | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 1485 String helpUrl = getString(R.string.help_url); 1486 Intent help = new Intent(Intent.ACTION_VIEW, Uri.parse(helpUrl)); 1487 help.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1488 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1489 1490 menu.add(MENU_GROUP_WALLPAPER, MENU_WALLPAPER_SETTINGS, 0, R.string.menu_wallpaper) 1491 .setIcon(android.R.drawable.ic_menu_gallery) 1492 .setAlphabeticShortcut('W'); 1493 menu.add(0, MENU_MANAGE_APPS, 0, R.string.menu_manage_apps) 1494 .setIcon(android.R.drawable.ic_menu_manage) 1495 .setIntent(manageApps) 1496 .setAlphabeticShortcut('M'); 1497 menu.add(0, MENU_SYSTEM_SETTINGS, 0, R.string.menu_settings) 1498 .setIcon(android.R.drawable.ic_menu_preferences) 1499 .setIntent(settings) 1500 .setAlphabeticShortcut('P'); 1501 if (!helpUrl.isEmpty()) { 1502 menu.add(0, MENU_HELP, 0, R.string.menu_help) 1503 .setIcon(android.R.drawable.ic_menu_help) 1504 .setIntent(help) 1505 .setAlphabeticShortcut('H'); 1506 } 1507 return true; 1508 } 1509 1510 @Override 1511 public boolean onPrepareOptionsMenu(Menu menu) { 1512 super.onPrepareOptionsMenu(menu); 1513 1514 if (mAppsCustomizeTabHost.isTransitioning()) { 1515 return false; 1516 } 1517 boolean allAppsVisible = (mAppsCustomizeTabHost.getVisibility() == View.VISIBLE); 1518 menu.setGroupVisible(MENU_GROUP_WALLPAPER, !allAppsVisible); 1519 1520 return true; 1521 } 1522 1523 @Override 1524 public boolean onOptionsItemSelected(MenuItem item) { 1525 switch (item.getItemId()) { 1526 case MENU_WALLPAPER_SETTINGS: 1527 startWallpaper(); 1528 return true; 1529 } 1530 1531 return super.onOptionsItemSelected(item); 1532 } 1533 1534 @Override 1535 public boolean onSearchRequested() { 1536 startSearch(null, false, null, true); 1537 // Use a custom animation for launching search 1538 overridePendingTransition(R.anim.fade_in_fast, R.anim.fade_out_fast); 1539 return true; 1540 } 1541 1542 public boolean isWorkspaceLocked() { 1543 return mWorkspaceLoading || mWaitingForResult; 1544 } 1545 1546 private void resetAddInfo() { 1547 mPendingAddInfo.container = ItemInfo.NO_ID; 1548 mPendingAddInfo.screen = -1; 1549 mPendingAddInfo.cellX = mPendingAddInfo.cellY = -1; 1550 mPendingAddInfo.spanX = mPendingAddInfo.spanY = -1; 1551 mPendingAddInfo.minSpanX = mPendingAddInfo.minSpanY = -1; 1552 mPendingAddInfo.dropPos = null; 1553 } 1554 1555 void addAppWidgetFromPick(Intent data) { 1556 // TODO: catch bad widget exception when sent 1557 int appWidgetId = data.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); 1558 // TODO: Is this log message meaningful? 1559 if (LOGD) Log.d(TAG, "dumping extras content=" + data.getExtras()); 1560 addAppWidgetImpl(appWidgetId, null); 1561 } 1562 1563 void addAppWidgetImpl(final int appWidgetId, final PendingAddWidgetInfo info) { 1564 final AppWidgetProviderInfo appWidget = info.info; 1565 if (appWidget.configure != null) { 1566 // Launch over to configure widget, if needed 1567 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE); 1568 intent.setComponent(appWidget.configure); 1569 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 1570 startActivityForResultSafely(intent, REQUEST_CREATE_APPWIDGET); 1571 mWidgetBeingBoundOrConfigured = info; 1572 } else { 1573 // Otherwise just add it 1574 completeAddAppWidget(appWidgetId, info.container, info.screen, info.boundWidget, appWidget); 1575 // Exit spring loaded mode if necessary after adding the widget 1576 exitSpringLoadedDragModeDelayed(true, false, null); 1577 } 1578 } 1579 1580 /** 1581 * Process a shortcut drop. 1582 * 1583 * @param componentName The name of the component 1584 * @param screen The screen where it should be added 1585 * @param cell The cell it should be added to, optional 1586 * @param position The location on the screen where it was dropped, optional 1587 */ 1588 void processShortcutFromDrop(ComponentName componentName, long container, int screen, 1589 int[] cell, int[] loc) { 1590 resetAddInfo(); 1591 mPendingAddInfo.container = container; 1592 mPendingAddInfo.screen = screen; 1593 mPendingAddInfo.dropPos = loc; 1594 1595 if (cell != null) { 1596 mPendingAddInfo.cellX = cell[0]; 1597 mPendingAddInfo.cellY = cell[1]; 1598 } 1599 1600 Intent createShortcutIntent = new Intent(Intent.ACTION_CREATE_SHORTCUT); 1601 createShortcutIntent.setComponent(componentName); 1602 processShortcut(createShortcutIntent); 1603 } 1604 1605 /** 1606 * Process a widget drop. 1607 * 1608 * @param info The PendingAppWidgetInfo of the widget being added. 1609 * @param screen The screen where it should be added 1610 * @param cell The cell it should be added to, optional 1611 * @param position The location on the screen where it was dropped, optional 1612 */ 1613 void addAppWidgetFromDrop(PendingAddWidgetInfo info, long container, int screen, 1614 int[] cell, int[] span, int[] loc) { 1615 resetAddInfo(); 1616 mPendingAddInfo.container = info.container = container; 1617 mPendingAddInfo.screen = info.screen = screen; 1618 mPendingAddInfo.dropPos = loc; 1619 mPendingAddInfo.minSpanX = info.minSpanX; 1620 mPendingAddInfo.minSpanY = info.minSpanY; 1621 1622 if (cell != null) { 1623 mPendingAddInfo.cellX = cell[0]; 1624 mPendingAddInfo.cellY = cell[1]; 1625 } 1626 if (span != null) { 1627 mPendingAddInfo.spanX = span[0]; 1628 mPendingAddInfo.spanY = span[1]; 1629 } 1630 1631 AppWidgetHostView hostView = info.boundWidget; 1632 int appWidgetId; 1633 if (hostView != null) { 1634 appWidgetId = hostView.getAppWidgetId(); 1635 addAppWidgetImpl(appWidgetId, info); 1636 } else { 1637 appWidgetId = getAppWidgetHost().allocateAppWidgetId(); 1638 mWidgetBeingBoundOrConfigured = info; 1639 if (mAppWidgetManager.bindAppWidgetIdIfAllowed(appWidgetId, info.componentName)) { 1640 addAppWidgetImpl(appWidgetId, info); 1641 } else { 1642 Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND); 1643 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); 1644 intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_PROVIDER, info.componentName); 1645 startActivityForResult(intent, REQUEST_BIND_APPWIDGET); 1646 } 1647 } 1648 } 1649 1650 void processShortcut(Intent intent) { 1651 // Handle case where user selected "Applications" 1652 String applicationName = getResources().getString(R.string.group_applications); 1653 String shortcutName = intent.getStringExtra(Intent.EXTRA_SHORTCUT_NAME); 1654 1655 if (applicationName != null && applicationName.equals(shortcutName)) { 1656 Intent mainIntent = new Intent(Intent.ACTION_MAIN, null); 1657 mainIntent.addCategory(Intent.CATEGORY_LAUNCHER); 1658 1659 Intent pickIntent = new Intent(Intent.ACTION_PICK_ACTIVITY); 1660 pickIntent.putExtra(Intent.EXTRA_INTENT, mainIntent); 1661 pickIntent.putExtra(Intent.EXTRA_TITLE, getText(R.string.title_select_application)); 1662 startActivityForResultSafely(pickIntent, REQUEST_PICK_APPLICATION); 1663 } else { 1664 startActivityForResultSafely(intent, REQUEST_CREATE_SHORTCUT); 1665 } 1666 } 1667 1668 void processWallpaper(Intent intent) { 1669 startActivityForResult(intent, REQUEST_PICK_WALLPAPER); 1670 } 1671 1672 FolderIcon addFolder(CellLayout layout, long container, final int screen, int cellX, 1673 int cellY) { 1674 final FolderInfo folderInfo = new FolderInfo(); 1675 folderInfo.title = getText(R.string.folder_name); 1676 1677 // Update the model 1678 LauncherModel.addItemToDatabase(Launcher.this, folderInfo, container, screen, cellX, cellY, 1679 false); 1680 sFolders.put(folderInfo.id, folderInfo); 1681 1682 // Create the view 1683 FolderIcon newFolder = 1684 FolderIcon.fromXml(R.layout.folder_icon, this, layout, folderInfo, mIconCache); 1685 mWorkspace.addInScreen(newFolder, container, screen, cellX, cellY, 1, 1, 1686 isWorkspaceLocked()); 1687 return newFolder; 1688 } 1689 1690 void removeFolder(FolderInfo folder) { 1691 sFolders.remove(folder.id); 1692 } 1693 1694 private void startWallpaper() { 1695 showWorkspace(true); 1696 final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER); 1697 Intent chooser = Intent.createChooser(pickWallpaper, 1698 getText(R.string.chooser_wallpaper)); 1699 // NOTE: Adds a configure option to the chooser if the wallpaper supports it 1700 // Removed in Eclair MR1 1701// WallpaperManager wm = (WallpaperManager) 1702// getSystemService(Context.WALLPAPER_SERVICE); 1703// WallpaperInfo wi = wm.getWallpaperInfo(); 1704// if (wi != null && wi.getSettingsActivity() != null) { 1705// LabeledIntent li = new LabeledIntent(getPackageName(), 1706// R.string.configure_wallpaper, 0); 1707// li.setClassName(wi.getPackageName(), wi.getSettingsActivity()); 1708// chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { li }); 1709// } 1710 startActivityForResult(chooser, REQUEST_PICK_WALLPAPER); 1711 } 1712 1713 /** 1714 * Registers various content observers. The current implementation registers 1715 * only a favorites observer to keep track of the favorites applications. 1716 */ 1717 private void registerContentObservers() { 1718 ContentResolver resolver = getContentResolver(); 1719 resolver.registerContentObserver(LauncherProvider.CONTENT_APPWIDGET_RESET_URI, 1720 true, mWidgetObserver); 1721 } 1722 1723 @Override 1724 public boolean dispatchKeyEvent(KeyEvent event) { 1725 if (event.getAction() == KeyEvent.ACTION_DOWN) { 1726 switch (event.getKeyCode()) { 1727 case KeyEvent.KEYCODE_HOME: 1728 return true; 1729 case KeyEvent.KEYCODE_VOLUME_DOWN: 1730 if (SystemProperties.getInt("debug.launcher2.dumpstate", 0) != 0) { 1731 dumpState(); 1732 return true; 1733 } 1734 break; 1735 } 1736 } else if (event.getAction() == KeyEvent.ACTION_UP) { 1737 switch (event.getKeyCode()) { 1738 case KeyEvent.KEYCODE_HOME: 1739 return true; 1740 } 1741 } 1742 1743 return super.dispatchKeyEvent(event); 1744 } 1745 1746 @Override 1747 public void onBackPressed() { 1748 if (mState == State.APPS_CUSTOMIZE) { 1749 showWorkspace(true); 1750 } else if (mWorkspace.getOpenFolder() != null) { 1751 Folder openFolder = mWorkspace.getOpenFolder(); 1752 if (openFolder.isEditingName()) { 1753 openFolder.dismissEditingName(); 1754 } else { 1755 closeFolder(); 1756 } 1757 } else { 1758 mWorkspace.exitWidgetResizeMode(); 1759 1760 // Back button is a no-op here, but give at least some feedback for the button press 1761 mWorkspace.showOutlinesTemporarily(); 1762 } 1763 } 1764 1765 /** 1766 * Re-listen when widgets are reset. 1767 */ 1768 private void onAppWidgetReset() { 1769 if (mAppWidgetHost != null) { 1770 mAppWidgetHost.startListening(); 1771 } 1772 } 1773 1774 /** 1775 * Go through the and disconnect any of the callbacks in the drawables and the views or we 1776 * leak the previous Home screen on orientation change. 1777 */ 1778 private void unbindWorkspaceAndHotseatItems() { 1779 if (mModel != null) { 1780 mModel.unbindWorkspaceItems(); 1781 } 1782 } 1783 1784 /** 1785 * Launches the intent referred by the clicked shortcut. 1786 * 1787 * @param v The view representing the clicked shortcut. 1788 */ 1789 public void onClick(View v) { 1790 // Make sure that rogue clicks don't get through while allapps is launching, or after the 1791 // view has detached (it's possible for this to happen if the view is removed mid touch). 1792 if (v.getWindowToken() == null) { 1793 return; 1794 } 1795 1796 if (!mWorkspace.isFinishedSwitchingState()) { 1797 return; 1798 } 1799 1800 Object tag = v.getTag(); 1801 if (tag instanceof ShortcutInfo) { 1802 // Open shortcut 1803 final Intent intent = ((ShortcutInfo) tag).intent; 1804 int[] pos = new int[2]; 1805 v.getLocationOnScreen(pos); 1806 intent.setSourceBounds(new Rect(pos[0], pos[1], 1807 pos[0] + v.getWidth(), pos[1] + v.getHeight())); 1808 1809 boolean success = startActivitySafely(v, intent, tag); 1810 1811 if (success && v instanceof BubbleTextView) { 1812 mWaitingForResume = (BubbleTextView) v; 1813 mWaitingForResume.setStayPressed(true); 1814 } 1815 } else if (tag instanceof FolderInfo) { 1816 if (v instanceof FolderIcon) { 1817 FolderIcon fi = (FolderIcon) v; 1818 handleFolderClick(fi); 1819 } 1820 } else if (v == mAllAppsButton) { 1821 if (mState == State.APPS_CUSTOMIZE) { 1822 showWorkspace(true); 1823 } else { 1824 onClickAllAppsButton(v); 1825 } 1826 } 1827 } 1828 1829 public boolean onTouch(View v, MotionEvent event) { 1830 // this is an intercepted event being forwarded from mWorkspace; 1831 // clicking anywhere on the workspace causes the customization drawer to slide down 1832 showWorkspace(true); 1833 return false; 1834 } 1835 1836 /** 1837 * Event handler for the search button 1838 * 1839 * @param v The view that was clicked. 1840 */ 1841 public void onClickSearchButton(View v) { 1842 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); 1843 1844 onSearchRequested(); 1845 } 1846 1847 /** 1848 * Event handler for the voice button 1849 * 1850 * @param v The view that was clicked. 1851 */ 1852 public void onClickVoiceButton(View v) { 1853 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); 1854 1855 try { 1856 final SearchManager searchManager = 1857 (SearchManager) getSystemService(Context.SEARCH_SERVICE); 1858 ComponentName activityName = searchManager.getGlobalSearchActivity(); 1859 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 1860 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1861 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1862 if (activityName != null) { 1863 intent.setPackage(activityName.getPackageName()); 1864 } 1865 startActivity(null, intent, "onClickVoiceButton"); 1866 } catch (ActivityNotFoundException e) { 1867 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 1868 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 1869 | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1870 startActivitySafely(null, intent, "onClickVoiceButton"); 1871 } 1872 } 1873 1874 /** 1875 * Event handler for the "grid" button that appears on the home screen, which 1876 * enters all apps mode. 1877 * 1878 * @param v The view that was clicked. 1879 */ 1880 public void onClickAllAppsButton(View v) { 1881 showAllApps(true); 1882 } 1883 1884 public void onTouchDownAllAppsButton(View v) { 1885 // Provide the same haptic feedback that the system offers for virtual keys. 1886 v.performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY); 1887 } 1888 1889 public void onClickAppMarketButton(View v) { 1890 if (mAppMarketIntent != null) { 1891 startActivitySafely(v, mAppMarketIntent, "app market"); 1892 } else { 1893 Log.e(TAG, "Invalid app market intent."); 1894 } 1895 } 1896 1897 void startApplicationDetailsActivity(ComponentName componentName) { 1898 String packageName = componentName.getPackageName(); 1899 Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS, 1900 Uri.fromParts("package", packageName, null)); 1901 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1902 startActivitySafely(null, intent, "startApplicationDetailsActivity"); 1903 } 1904 1905 void startApplicationUninstallActivity(ApplicationInfo appInfo) { 1906 if ((appInfo.flags & ApplicationInfo.DOWNLOADED_FLAG) == 0) { 1907 // System applications cannot be installed. For now, show a toast explaining that. 1908 // We may give them the option of disabling apps this way. 1909 int messageId = R.string.uninstall_system_app_text; 1910 Toast.makeText(this, messageId, Toast.LENGTH_SHORT).show(); 1911 } else { 1912 String packageName = appInfo.componentName.getPackageName(); 1913 String className = appInfo.componentName.getClassName(); 1914 Intent intent = new Intent( 1915 Intent.ACTION_DELETE, Uri.fromParts("package", packageName, className)); 1916 intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | 1917 Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS); 1918 startActivity(intent); 1919 } 1920 } 1921 1922 boolean startActivity(View v, Intent intent, Object tag) { 1923 intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 1924 1925 try { 1926 // Only launch using the new animation if the shortcut has not opted out (this is a 1927 // private contract between launcher and may be ignored in the future). 1928 boolean useLaunchAnimation = (v != null) && 1929 !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); 1930 if (useLaunchAnimation) { 1931 ActivityOptions opts = ActivityOptions.makeScaleUpAnimation(v, 0, 0, 1932 v.getMeasuredWidth(), v.getMeasuredHeight()); 1933 1934 startActivity(intent, opts.toBundle()); 1935 } else { 1936 startActivity(intent); 1937 } 1938 return true; 1939 } catch (SecurityException e) { 1940 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1941 Log.e(TAG, "Launcher does not have the permission to launch " + intent + 1942 ". Make sure to create a MAIN intent-filter for the corresponding activity " + 1943 "or use the exported attribute for this activity. " 1944 + "tag="+ tag + " intent=" + intent, e); 1945 } 1946 return false; 1947 } 1948 1949 boolean startActivitySafely(View v, Intent intent, Object tag) { 1950 boolean success = false; 1951 try { 1952 success = startActivity(v, intent, tag); 1953 } catch (ActivityNotFoundException e) { 1954 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1955 Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e); 1956 } 1957 return success; 1958 } 1959 1960 void startActivityForResultSafely(Intent intent, int requestCode) { 1961 try { 1962 startActivityForResult(intent, requestCode); 1963 } catch (ActivityNotFoundException e) { 1964 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1965 } catch (SecurityException e) { 1966 Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); 1967 Log.e(TAG, "Launcher does not have the permission to launch " + intent + 1968 ". Make sure to create a MAIN intent-filter for the corresponding activity " + 1969 "or use the exported attribute for this activity.", e); 1970 } 1971 } 1972 1973 private void handleFolderClick(FolderIcon folderIcon) { 1974 final FolderInfo info = folderIcon.mInfo; 1975 Folder openFolder = mWorkspace.getFolderForTag(info); 1976 1977 // If the folder info reports that the associated folder is open, then verify that 1978 // it is actually opened. There have been a few instances where this gets out of sync. 1979 if (info.opened && openFolder == null) { 1980 Log.d(TAG, "Folder info marked as open, but associated folder is not open. Screen: " 1981 + info.screen + " (" + info.cellX + ", " + info.cellY + ")"); 1982 info.opened = false; 1983 } 1984 1985 if (!info.opened) { 1986 // Close any open folder 1987 closeFolder(); 1988 // Open the requested folder 1989 openFolder(folderIcon); 1990 } else { 1991 // Find the open folder... 1992 int folderScreen; 1993 if (openFolder != null) { 1994 folderScreen = mWorkspace.getPageForView(openFolder); 1995 // .. and close it 1996 closeFolder(openFolder); 1997 if (folderScreen != mWorkspace.getCurrentPage()) { 1998 // Close any folder open on the current screen 1999 closeFolder(); 2000 // Pull the folder onto this screen 2001 openFolder(folderIcon); 2002 } 2003 } 2004 } 2005 } 2006 2007 private void growAndFadeOutFolderIcon(FolderIcon fi) { 2008 if (fi == null) return; 2009 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 0); 2010 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.5f); 2011 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.5f); 2012 2013 FolderInfo info = (FolderInfo) fi.getTag(); 2014 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { 2015 CellLayout cl = (CellLayout) fi.getParent().getParent(); 2016 CellLayout.LayoutParams lp = (CellLayout.LayoutParams) fi.getLayoutParams(); 2017 cl.setFolderLeaveBehindCell(lp.cellX, lp.cellY); 2018 } 2019 2020 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); 2021 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); 2022 oa.start(); 2023 } 2024 2025 private void shrinkAndFadeInFolderIcon(FolderIcon fi) { 2026 if (fi == null) return; 2027 PropertyValuesHolder alpha = PropertyValuesHolder.ofFloat("alpha", 1.0f); 2028 PropertyValuesHolder scaleX = PropertyValuesHolder.ofFloat("scaleX", 1.0f); 2029 PropertyValuesHolder scaleY = PropertyValuesHolder.ofFloat("scaleY", 1.0f); 2030 2031 FolderInfo info = (FolderInfo) fi.getTag(); 2032 CellLayout cl = null; 2033 if (info.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { 2034 cl = (CellLayout) fi.getParent().getParent(); 2035 } 2036 2037 final CellLayout layout = cl; 2038 ObjectAnimator oa = ObjectAnimator.ofPropertyValuesHolder(fi, alpha, scaleX, scaleY); 2039 oa.setDuration(getResources().getInteger(R.integer.config_folderAnimDuration)); 2040 oa.addListener(new AnimatorListenerAdapter() { 2041 @Override 2042 public void onAnimationEnd(Animator animation) { 2043 if (layout != null) { 2044 layout.clearFolderLeaveBehind(); 2045 } 2046 } 2047 }); 2048 oa.start(); 2049 } 2050 2051 /** 2052 * Opens the user folder described by the specified tag. The opening of the folder 2053 * is animated relative to the specified View. If the View is null, no animation 2054 * is played. 2055 * 2056 * @param folderInfo The FolderInfo describing the folder to open. 2057 */ 2058 public void openFolder(FolderIcon folderIcon) { 2059 Folder folder = folderIcon.mFolder; 2060 FolderInfo info = folder.mInfo; 2061 2062 growAndFadeOutFolderIcon(folderIcon); 2063 info.opened = true; 2064 2065 // Just verify that the folder hasn't already been added to the DragLayer. 2066 // There was a one-off crash where the folder had a parent already. 2067 if (folder.getParent() == null) { 2068 mDragLayer.addView(folder); 2069 mDragController.addDropTarget((DropTarget) folder); 2070 } else { 2071 Log.w(TAG, "Opening folder (" + folder + ") which already has a parent (" + 2072 folder.getParent() + ")."); 2073 } 2074 folder.animateOpen(); 2075 } 2076 2077 public void closeFolder() { 2078 Folder folder = mWorkspace.getOpenFolder(); 2079 if (folder != null) { 2080 if (folder.isEditingName()) { 2081 folder.dismissEditingName(); 2082 } 2083 closeFolder(folder); 2084 2085 // Dismiss the folder cling 2086 dismissFolderCling(null); 2087 } 2088 } 2089 2090 void closeFolder(Folder folder) { 2091 folder.getInfo().opened = false; 2092 2093 ViewGroup parent = (ViewGroup) folder.getParent().getParent(); 2094 if (parent != null) { 2095 FolderIcon fi = (FolderIcon) mWorkspace.getViewForTag(folder.mInfo); 2096 shrinkAndFadeInFolderIcon(fi); 2097 } 2098 folder.animateClosed(); 2099 } 2100 2101 public boolean onLongClick(View v) { 2102 if (!isDraggingEnabled()) return false; 2103 if (isWorkspaceLocked()) return false; 2104 if (mState != State.WORKSPACE) return false; 2105 2106 if (!(v instanceof CellLayout)) { 2107 v = (View) v.getParent().getParent(); 2108 } 2109 2110 resetAddInfo(); 2111 CellLayout.CellInfo longClickCellInfo = (CellLayout.CellInfo) v.getTag(); 2112 // This happens when long clicking an item with the dpad/trackball 2113 if (longClickCellInfo == null) { 2114 return true; 2115 } 2116 2117 // The hotseat touch handling does not go through Workspace, and we always allow long press 2118 // on hotseat items. 2119 final View itemUnderLongClick = longClickCellInfo.cell; 2120 boolean allowLongPress = isHotseatLayout(v) || mWorkspace.allowLongPress(); 2121 if (allowLongPress && !mDragController.isDragging()) { 2122 if (itemUnderLongClick == null) { 2123 // User long pressed on empty space 2124 mWorkspace.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS, 2125 HapticFeedbackConstants.FLAG_IGNORE_VIEW_SETTING); 2126 startWallpaper(); 2127 } else { 2128 if (!(itemUnderLongClick instanceof Folder)) { 2129 // User long pressed on an item 2130 mWorkspace.startDrag(longClickCellInfo); 2131 } 2132 } 2133 } 2134 return true; 2135 } 2136 2137 boolean isHotseatLayout(View layout) { 2138 return mHotseat != null && layout != null && 2139 (layout instanceof CellLayout) && (layout == mHotseat.getLayout()); 2140 } 2141 Hotseat getHotseat() { 2142 return mHotseat; 2143 } 2144 SearchDropTargetBar getSearchBar() { 2145 return mSearchDropTargetBar; 2146 } 2147 2148 /** 2149 * Returns the CellLayout of the specified container at the specified screen. 2150 */ 2151 CellLayout getCellLayout(long container, int screen) { 2152 if (container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) { 2153 if (mHotseat != null) { 2154 return mHotseat.getLayout(); 2155 } else { 2156 return null; 2157 } 2158 } else { 2159 return (CellLayout) mWorkspace.getChildAt(screen); 2160 } 2161 } 2162 2163 Workspace getWorkspace() { 2164 return mWorkspace; 2165 } 2166 2167 // Now a part of LauncherModel.Callbacks. Used to reorder loading steps. 2168 public boolean isAllAppsVisible() { 2169 return (mState == State.APPS_CUSTOMIZE); 2170 } 2171 2172 public boolean isAllAppsButtonRank(int rank) { 2173 return mHotseat.isAllAppsButtonRank(rank); 2174 } 2175 2176 // AllAppsView.Watcher 2177 public void zoomed(float zoom) { 2178 if (zoom == 1.0f) { 2179 mWorkspace.setVisibility(View.GONE); 2180 } 2181 } 2182 2183 /** 2184 * Helper method for the cameraZoomIn/cameraZoomOut animations 2185 * @param view The view being animated 2186 * @param state The state that we are moving in or out of (eg. APPS_CUSTOMIZE) 2187 * @param scaleFactor The scale factor used for the zoom 2188 */ 2189 private void setPivotsForZoom(View view, float scaleFactor) { 2190 view.setPivotX(view.getWidth() / 2.0f); 2191 view.setPivotY(view.getHeight() / 2.0f); 2192 } 2193 2194 void updateWallpaperVisibility(boolean visible) { 2195 int wpflags = visible ? WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER : 0; 2196 int curflags = getWindow().getAttributes().flags 2197 & WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER; 2198 if (wpflags != curflags) { 2199 getWindow().setFlags(wpflags, WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER); 2200 } 2201 } 2202 2203 private void dispatchOnLauncherTransitionPrepare(View v, boolean animated, boolean toWorkspace) { 2204 if (v instanceof LauncherTransitionable) { 2205 ((LauncherTransitionable) v).onLauncherTransitionPrepare(this, animated, toWorkspace); 2206 } 2207 } 2208 2209 private void dispatchOnLauncherTransitionStart(View v, boolean animated, boolean toWorkspace) { 2210 if (v instanceof LauncherTransitionable) { 2211 ((LauncherTransitionable) v).onLauncherTransitionStart(this, animated, toWorkspace); 2212 } 2213 2214 // Update the workspace transition step as well 2215 dispatchOnLauncherTransitionStep(v, 0f); 2216 } 2217 2218 private void dispatchOnLauncherTransitionStep(View v, float t) { 2219 if (v instanceof LauncherTransitionable) { 2220 ((LauncherTransitionable) v).onLauncherTransitionStep(this, t); 2221 } 2222 } 2223 2224 private void dispatchOnLauncherTransitionEnd(View v, boolean animated, boolean toWorkspace) { 2225 if (v instanceof LauncherTransitionable) { 2226 ((LauncherTransitionable) v).onLauncherTransitionEnd(this, animated, toWorkspace); 2227 } 2228 2229 // Update the workspace transition step as well 2230 dispatchOnLauncherTransitionStep(v, 1f); 2231 } 2232 2233 /** 2234 * Things to test when changing the following seven functions. 2235 * - Home from workspace 2236 * - from center screen 2237 * - from other screens 2238 * - Home from all apps 2239 * - from center screen 2240 * - from other screens 2241 * - Back from all apps 2242 * - from center screen 2243 * - from other screens 2244 * - Launch app from workspace and quit 2245 * - with back 2246 * - with home 2247 * - Launch app from all apps and quit 2248 * - with back 2249 * - with home 2250 * - Go to a screen that's not the default, then all 2251 * apps, and launch and app, and go back 2252 * - with back 2253 * -with home 2254 * - On workspace, long press power and go back 2255 * - with back 2256 * - with home 2257 * - On all apps, long press power and go back 2258 * - with back 2259 * - with home 2260 * - On workspace, power off 2261 * - On all apps, power off 2262 * - Launch an app and turn off the screen while in that app 2263 * - Go back with home key 2264 * - Go back with back key TODO: make this not go to workspace 2265 * - From all apps 2266 * - From workspace 2267 * - Enter and exit car mode (becuase it causes an extra configuration changed) 2268 * - From all apps 2269 * - From the center workspace 2270 * - From another workspace 2271 */ 2272 2273 /** 2274 * Zoom the camera out from the workspace to reveal 'toView'. 2275 * Assumes that the view to show is anchored at either the very top or very bottom 2276 * of the screen. 2277 */ 2278 private void showAppsCustomizeHelper(final boolean animated, final boolean springLoaded) { 2279 if (mStateAnimation != null) { 2280 mStateAnimation.cancel(); 2281 mStateAnimation = null; 2282 } 2283 final Resources res = getResources(); 2284 2285 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomInTime); 2286 final int fadeDuration = res.getInteger(R.integer.config_appsCustomizeFadeInTime); 2287 final float scale = (float) res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); 2288 final View fromView = mWorkspace; 2289 final AppsCustomizeTabHost toView = mAppsCustomizeTabHost; 2290 final int startDelay = 2291 res.getInteger(R.integer.config_workspaceAppsCustomizeAnimationStagger); 2292 2293 setPivotsForZoom(toView, scale); 2294 2295 // Shrink workspaces away if going to AppsCustomize from workspace 2296 Animator workspaceAnim = 2297 mWorkspace.getChangeStateAnimation(Workspace.State.SMALL, animated); 2298 2299 if (animated) { 2300 toView.setScaleX(scale); 2301 toView.setScaleY(scale); 2302 final LauncherViewPropertyAnimator scaleAnim = new LauncherViewPropertyAnimator(toView); 2303 scaleAnim. 2304 scaleX(1f).scaleY(1f). 2305 setDuration(duration). 2306 setInterpolator(new Workspace.ZoomOutInterpolator()); 2307 2308 toView.setVisibility(View.VISIBLE); 2309 toView.setAlpha(0f); 2310 final ObjectAnimator alphaAnim = ObjectAnimator 2311 .ofFloat(toView, "alpha", 0f, 1f) 2312 .setDuration(fadeDuration); 2313 alphaAnim.setInterpolator(new DecelerateInterpolator(1.5f)); 2314 alphaAnim.addUpdateListener(new AnimatorUpdateListener() { 2315 @Override 2316 public void onAnimationUpdate(ValueAnimator animation) { 2317 float t = (Float) animation.getAnimatedValue(); 2318 dispatchOnLauncherTransitionStep(fromView, t); 2319 dispatchOnLauncherTransitionStep(toView, t); 2320 } 2321 }); 2322 2323 // toView should appear right at the end of the workspace shrink 2324 // animation 2325 mStateAnimation = new AnimatorSet(); 2326 mStateAnimation.play(scaleAnim).after(startDelay); 2327 mStateAnimation.play(alphaAnim).after(startDelay); 2328 2329 mStateAnimation.addListener(new AnimatorListenerAdapter() { 2330 boolean animationCancelled = false; 2331 2332 @Override 2333 public void onAnimationStart(Animator animation) { 2334 updateWallpaperVisibility(true); 2335 // Prepare the position 2336 toView.setTranslationX(0.0f); 2337 toView.setTranslationY(0.0f); 2338 toView.setVisibility(View.VISIBLE); 2339 toView.bringToFront(); 2340 } 2341 @Override 2342 public void onAnimationEnd(Animator animation) { 2343 dispatchOnLauncherTransitionEnd(fromView, animated, false); 2344 dispatchOnLauncherTransitionEnd(toView, animated, false); 2345 2346 if (!springLoaded && !LauncherApplication.isScreenLarge()) { 2347 // Hide the workspace scrollbar 2348 mWorkspace.hideScrollingIndicator(true); 2349 hideDockDivider(); 2350 } 2351 if (!animationCancelled) { 2352 updateWallpaperVisibility(false); 2353 } 2354 } 2355 2356 @Override 2357 public void onAnimationCancel(Animator animation) { 2358 animationCancelled = true; 2359 } 2360 }); 2361 2362 if (workspaceAnim != null) { 2363 mStateAnimation.play(workspaceAnim); 2364 } 2365 2366 boolean delayAnim = false; 2367 final ViewTreeObserver observer; 2368 2369 dispatchOnLauncherTransitionPrepare(fromView, animated, false); 2370 dispatchOnLauncherTransitionPrepare(toView, animated, false); 2371 2372 // If any of the objects being animated haven't been measured/laid out 2373 // yet, delay the animation until we get a layout pass 2374 if ((((LauncherTransitionable) toView).getContent().getMeasuredWidth() == 0) || 2375 (mWorkspace.getMeasuredWidth() == 0) || 2376 (toView.getMeasuredWidth() == 0)) { 2377 observer = mWorkspace.getViewTreeObserver(); 2378 delayAnim = true; 2379 } else { 2380 observer = null; 2381 } 2382 2383 if (delayAnim) { 2384 final AnimatorSet stateAnimation = mStateAnimation; 2385 final OnGlobalLayoutListener delayedStart = new OnGlobalLayoutListener() { 2386 public void onGlobalLayout() { 2387 mWorkspace.post(new Runnable() { 2388 public void run() { 2389 // Check that mStateAnimation hasn't changed while 2390 // we waited for a layout pass 2391 if (mStateAnimation == stateAnimation) { 2392 // Need to update pivots for zoom if layout changed 2393 setPivotsForZoom(toView, scale); 2394 dispatchOnLauncherTransitionStart(fromView, animated, false); 2395 dispatchOnLauncherTransitionStart(toView, animated, false); 2396 mStateAnimation.start(); 2397 } 2398 } 2399 }); 2400 observer.removeOnGlobalLayoutListener(this); 2401 } 2402 }; 2403 observer.addOnGlobalLayoutListener(delayedStart); 2404 } else { 2405 setPivotsForZoom(toView, scale); 2406 dispatchOnLauncherTransitionStart(fromView, animated, false); 2407 dispatchOnLauncherTransitionStart(toView, animated, false); 2408 mStateAnimation.start(); 2409 } 2410 } else { 2411 toView.setTranslationX(0.0f); 2412 toView.setTranslationY(0.0f); 2413 toView.setScaleX(1.0f); 2414 toView.setScaleY(1.0f); 2415 toView.setVisibility(View.VISIBLE); 2416 toView.bringToFront(); 2417 2418 if (!springLoaded && !LauncherApplication.isScreenLarge()) { 2419 // Hide the workspace scrollbar 2420 mWorkspace.hideScrollingIndicator(true); 2421 hideDockDivider(); 2422 } 2423 dispatchOnLauncherTransitionPrepare(fromView, animated, false); 2424 dispatchOnLauncherTransitionStart(fromView, animated, false); 2425 dispatchOnLauncherTransitionEnd(fromView, animated, false); 2426 dispatchOnLauncherTransitionPrepare(toView, animated, false); 2427 dispatchOnLauncherTransitionStart(toView, animated, false); 2428 dispatchOnLauncherTransitionEnd(toView, animated, false); 2429 updateWallpaperVisibility(false); 2430 } 2431 } 2432 2433 /** 2434 * Zoom the camera back into the workspace, hiding 'fromView'. 2435 * This is the opposite of showAppsCustomizeHelper. 2436 * @param animated If true, the transition will be animated. 2437 */ 2438 private void hideAppsCustomizeHelper(State toState, final boolean animated, 2439 final boolean springLoaded, final Runnable onCompleteRunnable) { 2440 2441 if (mStateAnimation != null) { 2442 mStateAnimation.cancel(); 2443 mStateAnimation = null; 2444 } 2445 Resources res = getResources(); 2446 2447 final int duration = res.getInteger(R.integer.config_appsCustomizeZoomOutTime); 2448 final int fadeOutDuration = 2449 res.getInteger(R.integer.config_appsCustomizeFadeOutTime); 2450 final float scaleFactor = (float) 2451 res.getInteger(R.integer.config_appsCustomizeZoomScaleFactor); 2452 final View fromView = mAppsCustomizeTabHost; 2453 final View toView = mWorkspace; 2454 Animator workspaceAnim = null; 2455 2456 if (toState == State.WORKSPACE) { 2457 int stagger = res.getInteger(R.integer.config_appsCustomizeWorkspaceAnimationStagger); 2458 workspaceAnim = mWorkspace.getChangeStateAnimation( 2459 Workspace.State.NORMAL, animated, stagger); 2460 } else if (toState == State.APPS_CUSTOMIZE_SPRING_LOADED) { 2461 workspaceAnim = mWorkspace.getChangeStateAnimation( 2462 Workspace.State.SPRING_LOADED, animated); 2463 } 2464 2465 setPivotsForZoom(fromView, scaleFactor); 2466 updateWallpaperVisibility(true); 2467 showHotseat(animated); 2468 if (animated) { 2469 final LauncherViewPropertyAnimator scaleAnim = 2470 new LauncherViewPropertyAnimator(fromView); 2471 scaleAnim. 2472 scaleX(scaleFactor).scaleY(scaleFactor). 2473 setDuration(duration). 2474 setInterpolator(new Workspace.ZoomInInterpolator()); 2475 2476 final ObjectAnimator alphaAnim = ObjectAnimator 2477 .ofFloat(fromView, "alpha", 1f, 0f) 2478 .setDuration(fadeOutDuration); 2479 alphaAnim.setInterpolator(new AccelerateDecelerateInterpolator()); 2480 alphaAnim.addUpdateListener(new AnimatorUpdateListener() { 2481 @Override 2482 public void onAnimationUpdate(ValueAnimator animation) { 2483 float t = 1f - (Float) animation.getAnimatedValue(); 2484 dispatchOnLauncherTransitionStep(fromView, t); 2485 dispatchOnLauncherTransitionStep(toView, t); 2486 } 2487 }); 2488 2489 mStateAnimation = new AnimatorSet(); 2490 2491 dispatchOnLauncherTransitionPrepare(fromView, animated, true); 2492 dispatchOnLauncherTransitionPrepare(toView, animated, true); 2493 2494 mStateAnimation.addListener(new AnimatorListenerAdapter() { 2495 @Override 2496 public void onAnimationEnd(Animator animation) { 2497 updateWallpaperVisibility(true); 2498 fromView.setVisibility(View.GONE); 2499 dispatchOnLauncherTransitionEnd(fromView, animated, true); 2500 dispatchOnLauncherTransitionEnd(toView, animated, true); 2501 if (mWorkspace != null) { 2502 mWorkspace.hideScrollingIndicator(false); 2503 } 2504 if (onCompleteRunnable != null) { 2505 onCompleteRunnable.run(); 2506 } 2507 } 2508 }); 2509 2510 mStateAnimation.playTogether(scaleAnim, alphaAnim); 2511 if (workspaceAnim != null) { 2512 mStateAnimation.play(workspaceAnim); 2513 } 2514 dispatchOnLauncherTransitionStart(fromView, animated, true); 2515 dispatchOnLauncherTransitionStart(toView, animated, true); 2516 mStateAnimation.start(); 2517 } else { 2518 fromView.setVisibility(View.GONE); 2519 dispatchOnLauncherTransitionPrepare(fromView, animated, true); 2520 dispatchOnLauncherTransitionStart(fromView, animated, true); 2521 dispatchOnLauncherTransitionEnd(fromView, animated, true); 2522 dispatchOnLauncherTransitionPrepare(toView, animated, true); 2523 dispatchOnLauncherTransitionStart(toView, animated, true); 2524 dispatchOnLauncherTransitionEnd(toView, animated, true); 2525 mWorkspace.hideScrollingIndicator(false); 2526 } 2527 } 2528 2529 @Override 2530 public void onTrimMemory(int level) { 2531 super.onTrimMemory(level); 2532 if (level >= ComponentCallbacks2.TRIM_MEMORY_MODERATE) { 2533 mAppsCustomizeTabHost.onTrimMemory(); 2534 } 2535 } 2536 2537 void showWorkspace(boolean animated) { 2538 showWorkspace(animated, null); 2539 } 2540 2541 void showWorkspace(boolean animated, Runnable onCompleteRunnable) { 2542 if (mState != State.WORKSPACE) { 2543 mWorkspace.setVisibility(View.VISIBLE); 2544 hideAppsCustomizeHelper(State.WORKSPACE, animated, false, onCompleteRunnable); 2545 2546 // Show the search bar and hotseat 2547 mSearchDropTargetBar.showSearchBar(animated); 2548 // We only need to animate in the dock divider if we're going from spring loaded mode 2549 showDockDivider(animated && mState == State.APPS_CUSTOMIZE_SPRING_LOADED); 2550 2551 // Set focus to the AppsCustomize button 2552 if (mAllAppsButton != null) { 2553 mAllAppsButton.requestFocus(); 2554 } 2555 } 2556 2557 mWorkspace.flashScrollingIndicator(animated); 2558 2559 // Change the state *after* we've called all the transition code 2560 mState = State.WORKSPACE; 2561 2562 // Resume the auto-advance of widgets 2563 mUserPresent = true; 2564 updateRunning(); 2565 2566 // send an accessibility event to announce the context change 2567 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); 2568 } 2569 2570 void showAllApps(boolean animated) { 2571 if (mState != State.WORKSPACE) return; 2572 2573 showAppsCustomizeHelper(animated, false); 2574 mAppsCustomizeTabHost.requestFocus(); 2575 2576 // Hide the search bar and hotseat 2577 mSearchDropTargetBar.hideSearchBar(animated); 2578 2579 // Change the state *after* we've called all the transition code 2580 mState = State.APPS_CUSTOMIZE; 2581 2582 // Pause the auto-advance of widgets until we are out of AllApps 2583 mUserPresent = false; 2584 updateRunning(); 2585 closeFolder(); 2586 2587 // Send an accessibility event to announce the context change 2588 getWindow().getDecorView().sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); 2589 } 2590 2591 void enterSpringLoadedDragMode() { 2592 if (mState == State.APPS_CUSTOMIZE) { 2593 hideAppsCustomizeHelper(State.APPS_CUSTOMIZE_SPRING_LOADED, true, true, null); 2594 hideDockDivider(); 2595 mState = State.APPS_CUSTOMIZE_SPRING_LOADED; 2596 } 2597 } 2598 2599 void exitSpringLoadedDragModeDelayed(final boolean successfulDrop, boolean extendedDelay, 2600 final Runnable onCompleteRunnable) { 2601 if (mState != State.APPS_CUSTOMIZE_SPRING_LOADED) return; 2602 2603 mHandler.postDelayed(new Runnable() { 2604 @Override 2605 public void run() { 2606 if (successfulDrop) { 2607 // Before we show workspace, hide all apps again because 2608 // exitSpringLoadedDragMode made it visible. This is a bit hacky; we should 2609 // clean up our state transition functions 2610 mAppsCustomizeTabHost.setVisibility(View.GONE); 2611 mSearchDropTargetBar.showSearchBar(true); 2612 showWorkspace(true, onCompleteRunnable); 2613 } else { 2614 exitSpringLoadedDragMode(); 2615 } 2616 } 2617 }, (extendedDelay ? 2618 EXIT_SPRINGLOADED_MODE_LONG_TIMEOUT : 2619 EXIT_SPRINGLOADED_MODE_SHORT_TIMEOUT)); 2620 } 2621 2622 void exitSpringLoadedDragMode() { 2623 if (mState == State.APPS_CUSTOMIZE_SPRING_LOADED) { 2624 final boolean animated = true; 2625 final boolean springLoaded = true; 2626 showAppsCustomizeHelper(animated, springLoaded); 2627 mState = State.APPS_CUSTOMIZE; 2628 } 2629 // Otherwise, we are not in spring loaded mode, so don't do anything. 2630 } 2631 2632 void hideDockDivider() { 2633 if (mQsbDivider != null && mDockDivider != null) { 2634 mQsbDivider.setVisibility(View.INVISIBLE); 2635 mDockDivider.setVisibility(View.INVISIBLE); 2636 } 2637 } 2638 2639 void showDockDivider(boolean animated) { 2640 if (mQsbDivider != null && mDockDivider != null) { 2641 mQsbDivider.setVisibility(View.VISIBLE); 2642 mDockDivider.setVisibility(View.VISIBLE); 2643 if (mDividerAnimator != null) { 2644 mDividerAnimator.cancel(); 2645 mQsbDivider.setAlpha(1f); 2646 mDockDivider.setAlpha(1f); 2647 mDividerAnimator = null; 2648 } 2649 if (animated) { 2650 mDividerAnimator = new AnimatorSet(); 2651 mDividerAnimator.playTogether(ObjectAnimator.ofFloat(mQsbDivider, "alpha", 1f), 2652 ObjectAnimator.ofFloat(mDockDivider, "alpha", 1f)); 2653 mDividerAnimator.setDuration(mSearchDropTargetBar.getTransitionInDuration()); 2654 mDividerAnimator.start(); 2655 } 2656 } 2657 } 2658 2659 void lockAllApps() { 2660 // TODO 2661 } 2662 2663 void unlockAllApps() { 2664 // TODO 2665 } 2666 2667 public boolean isAllAppsCustomizeOpen() { 2668 return mState == State.APPS_CUSTOMIZE; 2669 } 2670 2671 /** 2672 * Shows the hotseat area. 2673 */ 2674 void showHotseat(boolean animated) { 2675 if (!LauncherApplication.isScreenLarge()) { 2676 if (animated) { 2677 if (mHotseat.getAlpha() != 1f) { 2678 int duration = mSearchDropTargetBar.getTransitionInDuration(); 2679 mHotseat.animate().alpha(1f).setDuration(duration); 2680 } 2681 } else { 2682 mHotseat.setAlpha(1f); 2683 } 2684 } 2685 } 2686 2687 /** 2688 * Hides the hotseat area. 2689 */ 2690 void hideHotseat(boolean animated) { 2691 if (!LauncherApplication.isScreenLarge()) { 2692 if (animated) { 2693 if (mHotseat.getAlpha() != 0f) { 2694 int duration = mSearchDropTargetBar.getTransitionOutDuration(); 2695 mHotseat.animate().alpha(0f).setDuration(duration); 2696 } 2697 } else { 2698 mHotseat.setAlpha(0f); 2699 } 2700 } 2701 } 2702 2703 /** 2704 * Add an item from all apps or customize onto the given workspace screen. 2705 * If layout is null, add to the current screen. 2706 */ 2707 void addExternalItemToScreen(ItemInfo itemInfo, final CellLayout layout) { 2708 if (!mWorkspace.addExternalItemToScreen(itemInfo, layout)) { 2709 showOutOfSpaceMessage(isHotseatLayout(layout)); 2710 } 2711 } 2712 2713 /** Maps the current orientation to an index for referencing orientation correct global icons */ 2714 private int getCurrentOrientationIndexForGlobalIcons() { 2715 // default - 0, landscape - 1 2716 switch (getResources().getConfiguration().orientation) { 2717 case Configuration.ORIENTATION_LANDSCAPE: 2718 return 1; 2719 default: 2720 return 0; 2721 } 2722 } 2723 2724 private Drawable getExternalPackageToolbarIcon(ComponentName activityName, String resourceName) { 2725 try { 2726 PackageManager packageManager = getPackageManager(); 2727 // Look for the toolbar icon specified in the activity meta-data 2728 Bundle metaData = packageManager.getActivityInfo( 2729 activityName, PackageManager.GET_META_DATA).metaData; 2730 if (metaData != null) { 2731 int iconResId = metaData.getInt(resourceName); 2732 if (iconResId != 0) { 2733 Resources res = packageManager.getResourcesForActivity(activityName); 2734 return res.getDrawable(iconResId); 2735 } 2736 } 2737 } catch (NameNotFoundException e) { 2738 // This can happen if the activity defines an invalid drawable 2739 Log.w(TAG, "Failed to load toolbar icon; " + activityName.flattenToShortString() + 2740 " not found", e); 2741 } catch (Resources.NotFoundException nfe) { 2742 // This can happen if the activity defines an invalid drawable 2743 Log.w(TAG, "Failed to load toolbar icon from " + activityName.flattenToShortString(), 2744 nfe); 2745 } 2746 return null; 2747 } 2748 2749 // if successful in getting icon, return it; otherwise, set button to use default drawable 2750 private Drawable.ConstantState updateTextButtonWithIconFromExternalActivity( 2751 int buttonId, ComponentName activityName, int fallbackDrawableId, 2752 String toolbarResourceName) { 2753 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); 2754 Resources r = getResources(); 2755 int w = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_width); 2756 int h = r.getDimensionPixelSize(R.dimen.toolbar_external_icon_height); 2757 2758 TextView button = (TextView) findViewById(buttonId); 2759 // If we were unable to find the icon via the meta-data, use a generic one 2760 if (toolbarIcon == null) { 2761 toolbarIcon = r.getDrawable(fallbackDrawableId); 2762 toolbarIcon.setBounds(0, 0, w, h); 2763 if (button != null) { 2764 button.setCompoundDrawables(toolbarIcon, null, null, null); 2765 } 2766 return null; 2767 } else { 2768 toolbarIcon.setBounds(0, 0, w, h); 2769 if (button != null) { 2770 button.setCompoundDrawables(toolbarIcon, null, null, null); 2771 } 2772 return toolbarIcon.getConstantState(); 2773 } 2774 } 2775 2776 // if successful in getting icon, return it; otherwise, set button to use default drawable 2777 private Drawable.ConstantState updateButtonWithIconFromExternalActivity( 2778 int buttonId, ComponentName activityName, int fallbackDrawableId, 2779 String toolbarResourceName) { 2780 ImageView button = (ImageView) findViewById(buttonId); 2781 Drawable toolbarIcon = getExternalPackageToolbarIcon(activityName, toolbarResourceName); 2782 2783 if (button != null) { 2784 // If we were unable to find the icon via the meta-data, use a 2785 // generic one 2786 if (toolbarIcon == null) { 2787 button.setImageResource(fallbackDrawableId); 2788 } else { 2789 button.setImageDrawable(toolbarIcon); 2790 } 2791 } 2792 2793 return toolbarIcon != null ? toolbarIcon.getConstantState() : null; 2794 2795 } 2796 2797 private void updateTextButtonWithDrawable(int buttonId, Drawable.ConstantState d) { 2798 TextView button = (TextView) findViewById(buttonId); 2799 button.setCompoundDrawables(d.newDrawable(getResources()), null, null, null); 2800 } 2801 2802 private void updateButtonWithDrawable(int buttonId, Drawable.ConstantState d) { 2803 ImageView button = (ImageView) findViewById(buttonId); 2804 button.setImageDrawable(d.newDrawable(getResources())); 2805 } 2806 2807 private void invalidatePressedFocusedStates(View container, View button) { 2808 if (container instanceof HolographicLinearLayout) { 2809 HolographicLinearLayout layout = (HolographicLinearLayout) container; 2810 layout.invalidatePressedFocusedStates(); 2811 } else if (button instanceof HolographicImageView) { 2812 HolographicImageView view = (HolographicImageView) button; 2813 view.invalidatePressedFocusedStates(); 2814 } 2815 } 2816 2817 private boolean updateGlobalSearchIcon() { 2818 final View searchButtonContainer = findViewById(R.id.search_button_container); 2819 final ImageView searchButton = (ImageView) findViewById(R.id.search_button); 2820 final View searchDivider = findViewById(R.id.search_divider); 2821 final View voiceButtonContainer = findViewById(R.id.voice_button_container); 2822 final View voiceButton = findViewById(R.id.voice_button); 2823 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); 2824 2825 final SearchManager searchManager = 2826 (SearchManager) getSystemService(Context.SEARCH_SERVICE); 2827 ComponentName activityName = searchManager.getGlobalSearchActivity(); 2828 if (activityName != null) { 2829 int coi = getCurrentOrientationIndexForGlobalIcons(); 2830 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( 2831 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, 2832 TOOLBAR_SEARCH_ICON_METADATA_NAME); 2833 if (sGlobalSearchIcon[coi] == null) { 2834 sGlobalSearchIcon[coi] = updateButtonWithIconFromExternalActivity( 2835 R.id.search_button, activityName, R.drawable.ic_home_search_normal_holo, 2836 TOOLBAR_ICON_METADATA_NAME); 2837 } 2838 2839 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE); 2840 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.VISIBLE); 2841 searchButton.setVisibility(View.VISIBLE); 2842 invalidatePressedFocusedStates(searchButtonContainer, searchButton); 2843 return true; 2844 } else { 2845 // We disable both search and voice search when there is no global search provider 2846 if (searchDivider != null) searchDivider.setVisibility(View.GONE); 2847 if (searchButtonContainer != null) searchButtonContainer.setVisibility(View.GONE); 2848 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); 2849 searchButton.setVisibility(View.GONE); 2850 voiceButton.setVisibility(View.GONE); 2851 if (voiceButtonProxy != null) { 2852 voiceButtonProxy.setVisibility(View.GONE); 2853 } 2854 return false; 2855 } 2856 } 2857 2858 private void updateGlobalSearchIcon(Drawable.ConstantState d) { 2859 final View searchButtonContainer = findViewById(R.id.search_button_container); 2860 final View searchButton = (ImageView) findViewById(R.id.search_button); 2861 updateButtonWithDrawable(R.id.search_button, d); 2862 invalidatePressedFocusedStates(searchButtonContainer, searchButton); 2863 } 2864 2865 private boolean updateVoiceSearchIcon(boolean searchVisible) { 2866 final View searchDivider = findViewById(R.id.search_divider); 2867 final View voiceButtonContainer = findViewById(R.id.voice_button_container); 2868 final View voiceButton = findViewById(R.id.voice_button); 2869 final View voiceButtonProxy = findViewById(R.id.voice_button_proxy); 2870 2871 // We only show/update the voice search icon if the search icon is enabled as well 2872 final SearchManager searchManager = 2873 (SearchManager) getSystemService(Context.SEARCH_SERVICE); 2874 ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); 2875 2876 ComponentName activityName = null; 2877 if (globalSearchActivity != null) { 2878 // Check if the global search activity handles voice search 2879 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 2880 intent.setPackage(globalSearchActivity.getPackageName()); 2881 activityName = intent.resolveActivity(getPackageManager()); 2882 } 2883 2884 if (activityName == null) { 2885 // Fallback: check if an activity other than the global search activity 2886 // resolves this 2887 Intent intent = new Intent(RecognizerIntent.ACTION_WEB_SEARCH); 2888 activityName = intent.resolveActivity(getPackageManager()); 2889 } 2890 if (searchVisible && activityName != null) { 2891 int coi = getCurrentOrientationIndexForGlobalIcons(); 2892 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( 2893 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, 2894 TOOLBAR_VOICE_SEARCH_ICON_METADATA_NAME); 2895 if (sVoiceSearchIcon[coi] == null) { 2896 sVoiceSearchIcon[coi] = updateButtonWithIconFromExternalActivity( 2897 R.id.voice_button, activityName, R.drawable.ic_home_voice_search_holo, 2898 TOOLBAR_ICON_METADATA_NAME); 2899 } 2900 if (searchDivider != null) searchDivider.setVisibility(View.VISIBLE); 2901 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.VISIBLE); 2902 voiceButton.setVisibility(View.VISIBLE); 2903 if (voiceButtonProxy != null) { 2904 voiceButtonProxy.setVisibility(View.VISIBLE); 2905 } 2906 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); 2907 return true; 2908 } else { 2909 if (searchDivider != null) searchDivider.setVisibility(View.GONE); 2910 if (voiceButtonContainer != null) voiceButtonContainer.setVisibility(View.GONE); 2911 voiceButton.setVisibility(View.GONE); 2912 if (voiceButtonProxy != null) { 2913 voiceButtonProxy.setVisibility(View.GONE); 2914 } 2915 return false; 2916 } 2917 } 2918 2919 private void updateVoiceSearchIcon(Drawable.ConstantState d) { 2920 final View voiceButtonContainer = findViewById(R.id.voice_button_container); 2921 final View voiceButton = findViewById(R.id.voice_button); 2922 updateButtonWithDrawable(R.id.voice_button, d); 2923 invalidatePressedFocusedStates(voiceButtonContainer, voiceButton); 2924 } 2925 2926 /** 2927 * Sets the app market icon 2928 */ 2929 private void updateAppMarketIcon() { 2930 final View marketButton = findViewById(R.id.market_button); 2931 Intent intent = new Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_APP_MARKET); 2932 // Find the app market activity by resolving an intent. 2933 // (If multiple app markets are installed, it will return the ResolverActivity.) 2934 ComponentName activityName = intent.resolveActivity(getPackageManager()); 2935 if (activityName != null) { 2936 int coi = getCurrentOrientationIndexForGlobalIcons(); 2937 mAppMarketIntent = intent; 2938 sAppMarketIcon[coi] = updateTextButtonWithIconFromExternalActivity( 2939 R.id.market_button, activityName, R.drawable.ic_launcher_market_holo, 2940 TOOLBAR_ICON_METADATA_NAME); 2941 marketButton.setVisibility(View.VISIBLE); 2942 } else { 2943 // We should hide and disable the view so that we don't try and restore the visibility 2944 // of it when we swap between drag & normal states from IconDropTarget subclasses. 2945 marketButton.setVisibility(View.GONE); 2946 marketButton.setEnabled(false); 2947 } 2948 } 2949 2950 private void updateAppMarketIcon(Drawable.ConstantState d) { 2951 updateTextButtonWithDrawable(R.id.market_button, d); 2952 } 2953 2954 @Override 2955 public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { 2956 boolean result = super.dispatchPopulateAccessibilityEvent(event); 2957 final List<CharSequence> text = event.getText(); 2958 text.clear(); 2959 text.add(getString(R.string.home)); 2960 return result; 2961 } 2962 2963 /** 2964 * Receives notifications when system dialogs are to be closed. 2965 */ 2966 private class CloseSystemDialogsIntentReceiver extends BroadcastReceiver { 2967 @Override 2968 public void onReceive(Context context, Intent intent) { 2969 closeSystemDialogs(); 2970 } 2971 } 2972 2973 /** 2974 * Receives notifications whenever the appwidgets are reset. 2975 */ 2976 private class AppWidgetResetObserver extends ContentObserver { 2977 public AppWidgetResetObserver() { 2978 super(new Handler()); 2979 } 2980 2981 @Override 2982 public void onChange(boolean selfChange) { 2983 onAppWidgetReset(); 2984 } 2985 } 2986 2987 /** 2988 * If the activity is currently paused, signal that we need to re-run the loader 2989 * in onResume. 2990 * 2991 * This needs to be called from incoming places where resources might have been loaded 2992 * while we are paused. That is becaues the Configuration might be wrong 2993 * when we're not running, and if it comes back to what it was when we 2994 * were paused, we are not restarted. 2995 * 2996 * Implementation of the method from LauncherModel.Callbacks. 2997 * 2998 * @return true if we are currently paused. The caller might be able to 2999 * skip some work in that case since we will come back again. 3000 */ 3001 public boolean setLoadOnResume() { 3002 if (mPaused) { 3003 Log.i(TAG, "setLoadOnResume"); 3004 mOnResumeNeedsLoad = true; 3005 return true; 3006 } else { 3007 return false; 3008 } 3009 } 3010 3011 /** 3012 * Implementation of the method from LauncherModel.Callbacks. 3013 */ 3014 public int getCurrentWorkspaceScreen() { 3015 if (mWorkspace != null) { 3016 return mWorkspace.getCurrentPage(); 3017 } else { 3018 return SCREEN_COUNT / 2; 3019 } 3020 } 3021 3022 /** 3023 * Refreshes the shortcuts shown on the workspace. 3024 * 3025 * Implementation of the method from LauncherModel.Callbacks. 3026 */ 3027 public void startBinding() { 3028 final Workspace workspace = mWorkspace; 3029 3030 mNewShortcutAnimatePage = -1; 3031 mNewShortcutAnimateViews.clear(); 3032 mWorkspace.clearDropTargets(); 3033 int count = workspace.getChildCount(); 3034 for (int i = 0; i < count; i++) { 3035 // Use removeAllViewsInLayout() to avoid an extra requestLayout() and invalidate(). 3036 final CellLayout layoutParent = (CellLayout) workspace.getChildAt(i); 3037 layoutParent.removeAllViewsInLayout(); 3038 } 3039 mWidgetsToAdvance.clear(); 3040 if (mHotseat != null) { 3041 mHotseat.resetLayout(); 3042 } 3043 } 3044 3045 /** 3046 * Bind the items start-end from the list. 3047 * 3048 * Implementation of the method from LauncherModel.Callbacks. 3049 */ 3050 public void bindItems(ArrayList<ItemInfo> shortcuts, int start, int end) { 3051 setLoadOnResume(); 3052 3053 // Get the list of added shortcuts and intersect them with the set of shortcuts here 3054 Set<String> newApps = new HashSet<String>(); 3055 newApps = mSharedPrefs.getStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, newApps); 3056 3057 Workspace workspace = mWorkspace; 3058 for (int i = start; i < end; i++) { 3059 final ItemInfo item = shortcuts.get(i); 3060 3061 // Short circuit if we are loading dock items for a configuration which has no dock 3062 if (item.container == LauncherSettings.Favorites.CONTAINER_HOTSEAT && 3063 mHotseat == null) { 3064 continue; 3065 } 3066 3067 switch (item.itemType) { 3068 case LauncherSettings.Favorites.ITEM_TYPE_APPLICATION: 3069 case LauncherSettings.Favorites.ITEM_TYPE_SHORTCUT: 3070 ShortcutInfo info = (ShortcutInfo) item; 3071 String uri = info.intent.toUri(0).toString(); 3072 View shortcut = createShortcut(info); 3073 workspace.addInScreen(shortcut, item.container, item.screen, item.cellX, 3074 item.cellY, 1, 1, false); 3075 if (newApps.contains(uri)) { 3076 newApps.remove(uri); 3077 3078 // Prepare the view to be animated up 3079 shortcut.setAlpha(0f); 3080 shortcut.setScaleX(0f); 3081 shortcut.setScaleY(0f); 3082 mNewShortcutAnimatePage = item.screen; 3083 if (!mNewShortcutAnimateViews.contains(shortcut)) { 3084 mNewShortcutAnimateViews.add(shortcut); 3085 } 3086 } 3087 break; 3088 case LauncherSettings.Favorites.ITEM_TYPE_FOLDER: 3089 FolderIcon newFolder = FolderIcon.fromXml(R.layout.folder_icon, this, 3090 (ViewGroup) workspace.getChildAt(workspace.getCurrentPage()), 3091 (FolderInfo) item, mIconCache); 3092 workspace.addInScreen(newFolder, item.container, item.screen, item.cellX, 3093 item.cellY, 1, 1, false); 3094 break; 3095 } 3096 } 3097 3098 workspace.requestLayout(); 3099 } 3100 3101 /** 3102 * Implementation of the method from LauncherModel.Callbacks. 3103 */ 3104 public void bindFolders(HashMap<Long, FolderInfo> folders) { 3105 setLoadOnResume(); 3106 sFolders.clear(); 3107 sFolders.putAll(folders); 3108 } 3109 3110 /** 3111 * Add the views for a widget to the workspace. 3112 * 3113 * Implementation of the method from LauncherModel.Callbacks. 3114 */ 3115 public void bindAppWidget(LauncherAppWidgetInfo item) { 3116 setLoadOnResume(); 3117 3118 final long start = DEBUG_WIDGETS ? SystemClock.uptimeMillis() : 0; 3119 if (DEBUG_WIDGETS) { 3120 Log.d(TAG, "bindAppWidget: " + item); 3121 } 3122 final Workspace workspace = mWorkspace; 3123 3124 final int appWidgetId = item.appWidgetId; 3125 final AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appWidgetId); 3126 if (DEBUG_WIDGETS) { 3127 Log.d(TAG, "bindAppWidget: id=" + item.appWidgetId + " belongs to component " + appWidgetInfo.provider); 3128 } 3129 3130 item.hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo); 3131 3132 item.hostView.setAppWidget(appWidgetId, appWidgetInfo); 3133 item.hostView.setTag(item); 3134 3135 workspace.addInScreen(item.hostView, item.container, item.screen, item.cellX, 3136 item.cellY, item.spanX, item.spanY, false); 3137 3138 addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo); 3139 3140 workspace.requestLayout(); 3141 3142 AppWidgetResizeFrame.updateWidgetSizeRanges(item.hostView, 3143 this, item.spanX, item.spanY); 3144 3145 if (DEBUG_WIDGETS) { 3146 Log.d(TAG, "bound widget id="+item.appWidgetId+" in " 3147 + (SystemClock.uptimeMillis()-start) + "ms"); 3148 } 3149 } 3150 3151 /** 3152 * Callback saying that there aren't any more items to bind. 3153 * 3154 * Implementation of the method from LauncherModel.Callbacks. 3155 */ 3156 public void finishBindingItems() { 3157 setLoadOnResume(); 3158 3159 if (mSavedState != null) { 3160 if (!mWorkspace.hasFocus()) { 3161 mWorkspace.getChildAt(mWorkspace.getCurrentPage()).requestFocus(); 3162 } 3163 mSavedState = null; 3164 } 3165 3166 if (mSavedInstanceState != null) { 3167 super.onRestoreInstanceState(mSavedInstanceState); 3168 mSavedInstanceState = null; 3169 } 3170 3171 // If we received the result of any pending adds while the loader was running (e.g. the 3172 // widget configuration forced an orientation change), process them now. 3173 for (int i = 0; i < sPendingAddList.size(); i++) { 3174 completeAdd(sPendingAddList.get(i)); 3175 } 3176 sPendingAddList.clear(); 3177 3178 // Update the market app icon as necessary (the other icons will be managed in response to 3179 // package changes in bindSearchablesChanged() 3180 updateAppMarketIcon(); 3181 3182 // Animate up any icons as necessary 3183 if (mVisible || mWorkspaceLoading) { 3184 Runnable newAppsRunnable = new Runnable() { 3185 @Override 3186 public void run() { 3187 runNewAppsAnimation(false); 3188 } 3189 }; 3190 3191 boolean willSnapPage = mNewShortcutAnimatePage > -1 && 3192 mNewShortcutAnimatePage != mWorkspace.getCurrentPage(); 3193 if (canRunNewAppsAnimation()) { 3194 // If the user has not interacted recently, then either snap to the new page to show 3195 // the new-apps animation or just run them if they are to appear on the current page 3196 if (willSnapPage) { 3197 mWorkspace.snapToPage(mNewShortcutAnimatePage, newAppsRunnable); 3198 } else { 3199 runNewAppsAnimation(false); 3200 } 3201 } else { 3202 // If the user has interacted recently, then just add the items in place if they 3203 // are on another page (or just normally if they are added to the current page) 3204 runNewAppsAnimation(willSnapPage); 3205 } 3206 } 3207 3208 mWorkspaceLoading = false; 3209 } 3210 3211 private boolean canRunNewAppsAnimation() { 3212 long diff = System.currentTimeMillis() - mDragController.getLastGestureUpTime(); 3213 return diff > (NEW_APPS_ANIMATION_INACTIVE_TIMEOUT_SECONDS * 1000); 3214 } 3215 3216 /** 3217 * Runs a new animation that scales up icons that were added while Launcher was in the 3218 * background. 3219 * 3220 * @param immediate whether to run the animation or show the results immediately 3221 */ 3222 private void runNewAppsAnimation(boolean immediate) { 3223 AnimatorSet anim = new AnimatorSet(); 3224 Collection<Animator> bounceAnims = new ArrayList<Animator>(); 3225 3226 // Order these new views spatially so that they animate in order 3227 Collections.sort(mNewShortcutAnimateViews, new Comparator<View>() { 3228 @Override 3229 public int compare(View a, View b) { 3230 CellLayout.LayoutParams alp = (CellLayout.LayoutParams) a.getLayoutParams(); 3231 CellLayout.LayoutParams blp = (CellLayout.LayoutParams) b.getLayoutParams(); 3232 int cellCountX = LauncherModel.getCellCountX(); 3233 return (alp.cellY * cellCountX + alp.cellX) - (blp.cellY * cellCountX + blp.cellX); 3234 } 3235 }); 3236 3237 // Animate each of the views in place (or show them immediately if requested) 3238 if (immediate) { 3239 for (View v : mNewShortcutAnimateViews) { 3240 v.setAlpha(1f); 3241 v.setScaleX(1f); 3242 v.setScaleY(1f); 3243 } 3244 } else { 3245 for (int i = 0; i < mNewShortcutAnimateViews.size(); ++i) { 3246 View v = mNewShortcutAnimateViews.get(i); 3247 ValueAnimator bounceAnim = ObjectAnimator.ofPropertyValuesHolder(v, 3248 PropertyValuesHolder.ofFloat("alpha", 1f), 3249 PropertyValuesHolder.ofFloat("scaleX", 1f), 3250 PropertyValuesHolder.ofFloat("scaleY", 1f)); 3251 bounceAnim.setDuration(InstallShortcutReceiver.NEW_SHORTCUT_BOUNCE_DURATION); 3252 bounceAnim.setStartDelay(i * InstallShortcutReceiver.NEW_SHORTCUT_STAGGER_DELAY); 3253 bounceAnim.setInterpolator(new SmoothPagedView.OvershootInterpolator()); 3254 bounceAnims.add(bounceAnim); 3255 } 3256 anim.playTogether(bounceAnims); 3257 anim.addListener(new AnimatorListenerAdapter() { 3258 @Override 3259 public void onAnimationEnd(Animator animation) { 3260 mWorkspace.postDelayed(mBuildLayersRunnable, 500); 3261 } 3262 }); 3263 anim.start(); 3264 } 3265 3266 // Clean up 3267 mNewShortcutAnimatePage = -1; 3268 mNewShortcutAnimateViews.clear(); 3269 new Thread("clearNewAppsThread") { 3270 public void run() { 3271 mSharedPrefs.edit() 3272 .putInt(InstallShortcutReceiver.NEW_APPS_PAGE_KEY, -1) 3273 .putStringSet(InstallShortcutReceiver.NEW_APPS_LIST_KEY, null) 3274 .commit(); 3275 } 3276 }.start(); 3277 } 3278 3279 @Override 3280 public void bindSearchablesChanged() { 3281 boolean searchVisible = updateGlobalSearchIcon(); 3282 boolean voiceVisible = updateVoiceSearchIcon(searchVisible); 3283 mSearchDropTargetBar.onSearchPackagesChanged(searchVisible, voiceVisible); 3284 } 3285 3286 /** 3287 * Add the icons for all apps. 3288 * 3289 * Implementation of the method from LauncherModel.Callbacks. 3290 */ 3291 public void bindAllApplications(final ArrayList<ApplicationInfo> apps) { 3292 // Remove the progress bar entirely; we could also make it GONE 3293 // but better to remove it since we know it's not going to be used 3294 View progressBar = mAppsCustomizeTabHost. 3295 findViewById(R.id.apps_customize_progress_bar); 3296 if (progressBar != null) { 3297 ((ViewGroup)progressBar.getParent()).removeView(progressBar); 3298 } 3299 // We just post the call to setApps so the user sees the progress bar 3300 // disappear-- otherwise, it just looks like the progress bar froze 3301 // which doesn't look great 3302 mAppsCustomizeTabHost.post(new Runnable() { 3303 public void run() { 3304 if (mAppsCustomizeContent != null) { 3305 mAppsCustomizeContent.setApps(apps); 3306 } 3307 } 3308 }); 3309 } 3310 3311 /** 3312 * A package was installed. 3313 * 3314 * Implementation of the method from LauncherModel.Callbacks. 3315 */ 3316 public void bindAppsAdded(ArrayList<ApplicationInfo> apps) { 3317 setLoadOnResume(); 3318 3319 if (mAppsCustomizeContent != null) { 3320 mAppsCustomizeContent.addApps(apps); 3321 } 3322 } 3323 3324 /** 3325 * A package was updated. 3326 * 3327 * Implementation of the method from LauncherModel.Callbacks. 3328 */ 3329 public void bindAppsUpdated(ArrayList<ApplicationInfo> apps) { 3330 setLoadOnResume(); 3331 if (mWorkspace != null) { 3332 mWorkspace.updateShortcuts(apps); 3333 } 3334 3335 if (mAppsCustomizeContent != null) { 3336 mAppsCustomizeContent.updateApps(apps); 3337 } 3338 } 3339 3340 /** 3341 * A package was uninstalled. 3342 * 3343 * Implementation of the method from LauncherModel.Callbacks. 3344 */ 3345 public void bindAppsRemoved(ArrayList<ApplicationInfo> apps, boolean permanent) { 3346 if (permanent) { 3347 mWorkspace.removeItems(apps); 3348 } 3349 3350 if (mAppsCustomizeContent != null) { 3351 mAppsCustomizeContent.removeApps(apps); 3352 } 3353 3354 // Notify the drag controller 3355 mDragController.onAppsRemoved(apps, this); 3356 } 3357 3358 /** 3359 * A number of packages were updated. 3360 */ 3361 public void bindPackagesUpdated() { 3362 if (mAppsCustomizeContent != null) { 3363 mAppsCustomizeContent.onPackagesUpdated(); 3364 } 3365 } 3366 3367 private int mapConfigurationOriActivityInfoOri(int configOri) { 3368 final Display d = getWindowManager().getDefaultDisplay(); 3369 int naturalOri = Configuration.ORIENTATION_LANDSCAPE; 3370 switch (d.getRotation()) { 3371 case Surface.ROTATION_0: 3372 case Surface.ROTATION_180: 3373 // We are currently in the same basic orientation as the natural orientation 3374 naturalOri = configOri; 3375 break; 3376 case Surface.ROTATION_90: 3377 case Surface.ROTATION_270: 3378 // We are currently in the other basic orientation to the natural orientation 3379 naturalOri = (configOri == Configuration.ORIENTATION_LANDSCAPE) ? 3380 Configuration.ORIENTATION_PORTRAIT : Configuration.ORIENTATION_LANDSCAPE; 3381 break; 3382 } 3383 3384 int[] oriMap = { 3385 ActivityInfo.SCREEN_ORIENTATION_PORTRAIT, 3386 ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE, 3387 ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT, 3388 ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE 3389 }; 3390 // Since the map starts at portrait, we need to offset if this device's natural orientation 3391 // is landscape. 3392 int indexOffset = 0; 3393 if (naturalOri == Configuration.ORIENTATION_LANDSCAPE) { 3394 indexOffset = 1; 3395 } 3396 return oriMap[(d.getRotation() + indexOffset) % 4]; 3397 } 3398 3399 public boolean isRotationEnabled() { 3400 boolean forceEnableRotation = "true".equalsIgnoreCase(SystemProperties.get( 3401 FORCE_ENABLE_ROTATION_PROPERTY, "false")); 3402 boolean enableRotation = forceEnableRotation || 3403 getResources().getBoolean(R.bool.allow_rotation); 3404 return enableRotation; 3405 } 3406 public void lockScreenOrientation() { 3407 if (isRotationEnabled()) { 3408 setRequestedOrientation(mapConfigurationOriActivityInfoOri(getResources() 3409 .getConfiguration().orientation)); 3410 } 3411 } 3412 public void unlockScreenOrientation(boolean immediate) { 3413 if (isRotationEnabled()) { 3414 if (immediate) { 3415 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 3416 } else { 3417 mHandler.postDelayed(new Runnable() { 3418 public void run() { 3419 setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); 3420 } 3421 }, mRestoreScreenOrientationDelay); 3422 } 3423 } 3424 } 3425 3426 /* Cling related */ 3427 private boolean isClingsEnabled() { 3428 // disable clings when running in a test harness 3429 if(ActivityManager.isRunningInTestHarness()) return false; 3430 3431 return true; 3432 } 3433 private Cling initCling(int clingId, int[] positionData, boolean animate, int delay) { 3434 Cling cling = (Cling) findViewById(clingId); 3435 if (cling != null) { 3436 cling.init(this, positionData); 3437 cling.setVisibility(View.VISIBLE); 3438 cling.setLayerType(View.LAYER_TYPE_HARDWARE, null); 3439 if (animate) { 3440 cling.buildLayer(); 3441 cling.setAlpha(0f); 3442 cling.animate() 3443 .alpha(1f) 3444 .setInterpolator(new AccelerateInterpolator()) 3445 .setDuration(SHOW_CLING_DURATION) 3446 .setStartDelay(delay) 3447 .start(); 3448 } else { 3449 cling.setAlpha(1f); 3450 } 3451 } 3452 return cling; 3453 } 3454 private void dismissCling(final Cling cling, final String flag, int duration) { 3455 if (cling != null) { 3456 ObjectAnimator anim = ObjectAnimator.ofFloat(cling, "alpha", 0f); 3457 anim.setDuration(duration); 3458 anim.addListener(new AnimatorListenerAdapter() { 3459 public void onAnimationEnd(Animator animation) { 3460 cling.setVisibility(View.GONE); 3461 cling.cleanup(); 3462 // We should update the shared preferences on a background thread 3463 new Thread("dismissClingThread") { 3464 public void run() { 3465 SharedPreferences.Editor editor = mSharedPrefs.edit(); 3466 editor.putBoolean(flag, true); 3467 editor.commit(); 3468 } 3469 }.start(); 3470 }; 3471 }); 3472 anim.start(); 3473 } 3474 } 3475 private void removeCling(int id) { 3476 final View cling = findViewById(id); 3477 if (cling != null) { 3478 final ViewGroup parent = (ViewGroup) cling.getParent(); 3479 parent.post(new Runnable() { 3480 @Override 3481 public void run() { 3482 parent.removeView(cling); 3483 } 3484 }); 3485 } 3486 } 3487 public void showFirstRunWorkspaceCling() { 3488 // Enable the clings only if they have not been dismissed before 3489 if (isClingsEnabled() && 3490 !mSharedPrefs.getBoolean(Cling.WORKSPACE_CLING_DISMISSED_KEY, false)) { 3491 initCling(R.id.workspace_cling, null, false, 0); 3492 } else { 3493 removeCling(R.id.workspace_cling); 3494 } 3495 } 3496 public void showFirstRunAllAppsCling(int[] position) { 3497 // Enable the clings only if they have not been dismissed before 3498 if (isClingsEnabled() && 3499 !mSharedPrefs.getBoolean(Cling.ALLAPPS_CLING_DISMISSED_KEY, false)) { 3500 initCling(R.id.all_apps_cling, position, true, 0); 3501 } else { 3502 removeCling(R.id.all_apps_cling); 3503 } 3504 } 3505 public Cling showFirstRunFoldersCling() { 3506 // Enable the clings only if they have not been dismissed before 3507 if (isClingsEnabled() && 3508 !mSharedPrefs.getBoolean(Cling.FOLDER_CLING_DISMISSED_KEY, false)) { 3509 return initCling(R.id.folder_cling, null, true, 0); 3510 } else { 3511 removeCling(R.id.folder_cling); 3512 return null; 3513 } 3514 } 3515 public boolean isFolderClingVisible() { 3516 Cling cling = (Cling) findViewById(R.id.folder_cling); 3517 if (cling != null) { 3518 return cling.getVisibility() == View.VISIBLE; 3519 } 3520 return false; 3521 } 3522 public void dismissWorkspaceCling(View v) { 3523 Cling cling = (Cling) findViewById(R.id.workspace_cling); 3524 dismissCling(cling, Cling.WORKSPACE_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); 3525 } 3526 public void dismissAllAppsCling(View v) { 3527 Cling cling = (Cling) findViewById(R.id.all_apps_cling); 3528 dismissCling(cling, Cling.ALLAPPS_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); 3529 } 3530 public void dismissFolderCling(View v) { 3531 Cling cling = (Cling) findViewById(R.id.folder_cling); 3532 dismissCling(cling, Cling.FOLDER_CLING_DISMISSED_KEY, DISMISS_CLING_DURATION); 3533 } 3534 3535 /** 3536 * Prints out out state for debugging. 3537 */ 3538 public void dumpState() { 3539 Log.d(TAG, "BEGIN launcher2 dump state for launcher " + this); 3540 Log.d(TAG, "mSavedState=" + mSavedState); 3541 Log.d(TAG, "mWorkspaceLoading=" + mWorkspaceLoading); 3542 Log.d(TAG, "mRestoring=" + mRestoring); 3543 Log.d(TAG, "mWaitingForResult=" + mWaitingForResult); 3544 Log.d(TAG, "mSavedInstanceState=" + mSavedInstanceState); 3545 Log.d(TAG, "sFolders.size=" + sFolders.size()); 3546 mModel.dumpState(); 3547 3548 if (mAppsCustomizeContent != null) { 3549 mAppsCustomizeContent.dumpState(); 3550 } 3551 Log.d(TAG, "END launcher2 dump state"); 3552 } 3553 3554 @Override 3555 public void dump(String prefix, FileDescriptor fd, PrintWriter writer, String[] args) { 3556 super.dump(prefix, fd, writer, args); 3557 writer.println(" "); 3558 writer.println("Debug logs: "); 3559 for (int i = 0; i < sDumpLogs.size(); i++) { 3560 writer.println(" " + sDumpLogs.get(i)); 3561 } 3562 } 3563} 3564 3565interface LauncherTransitionable { 3566 View getContent(); 3567 void onLauncherTransitionPrepare(Launcher l, boolean animated, boolean toWorkspace); 3568 void onLauncherTransitionStart(Launcher l, boolean animated, boolean toWorkspace); 3569 void onLauncherTransitionStep(Launcher l, float t); 3570 void onLauncherTransitionEnd(Launcher l, boolean animated, boolean toWorkspace); 3571} 3572