List of usage examples for android.content Intent setSourceBounds
public void setSourceBounds(@Nullable Rect r)
From source file:com.android.launcher3.Launcher.java
public boolean startActivitySafely(View v, Intent intent, ItemInfo item) { if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) { Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show(); return false; }//from www . j ava 2s. c om // Only launch using the new animation if the shortcut has not opted out (this is a // private contract between launcher and may be ignored in the future). boolean useLaunchAnimation = (v != null) && !intent.hasExtra(INTENT_EXTRA_IGNORE_LAUNCH_ANIMATION); Bundle optsBundle = useLaunchAnimation ? getActivityLaunchOptions(v) : null; UserHandleCompat user = null; if (intent.hasExtra(AppInfo.EXTRA_PROFILE)) { long serialNumber = intent.getLongExtra(AppInfo.EXTRA_PROFILE, -1); user = UserManagerCompat.getInstance(this).getUserForSerialNumber(serialNumber); } // Prepare intent intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); if (v != null) { intent.setSourceBounds(getViewBounds(v)); } try { if (Utilities.ATLEAST_MARSHMALLOW && item != null && (item.itemType == Favorites.ITEM_TYPE_SHORTCUT || item.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT) && ((ShortcutInfo) item).promisedIntent == null) { // Shortcuts need some special checks due to legacy reasons. startShortcutIntentSafely(intent, optsBundle, item); } else if (user == null || user.equals(UserHandleCompat.myUserHandle())) { // Could be launching some bookkeeping activity startActivity(intent, optsBundle); if (isAllAppsVisible()) { predictiveAppsProvider.updateComponentCount(intent.getComponent()); } } else { LauncherAppsCompat.getInstance(this).startActivityForProfile(intent.getComponent(), user, intent.getSourceBounds(), optsBundle); } return true; } catch (ActivityNotFoundException | SecurityException e) { Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show(); Log.e(TAG, "Unable to launch. tag=" + item + " intent=" + intent, e); } return false; }
From source file:com.android.soma.Launcher.java
/** * Launches the intent referred by the clicked shortcut. * * @param v The view representing the clicked shortcut. */// w w w .j av a 2 s. c o m public void onClick(View v) { // Make sure that rogue clicks don't get through while allapps is launching, or after the // view has detached (it's possible for this to happen if the view is removed mid touch). if (v.getWindowToken() == null) { return; } if (!mWorkspace.isFinishedSwitchingState()) { return; } if (v instanceof Workspace) { if (mWorkspace.isInOverviewMode()) { mWorkspace.exitOverviewMode(true); } return; } if (v instanceof CellLayout) { if (mWorkspace.isInOverviewMode()) { mWorkspace.exitOverviewMode(mWorkspace.indexOfChild(v), true); } } Object tag = v.getTag(); if (tag instanceof ShortcutInfo) { // Open shortcut final ShortcutInfo shortcut = (ShortcutInfo) tag; final Intent intent = shortcut.intent; // Check for special shortcuts if (intent.getComponent() != null) { final String shortcutClass = intent.getComponent().getClassName(); if (shortcutClass.equals(WidgetAdder.class.getName())) { showAllApps(true, AppsCustomizePagedView.ContentType.Widgets, true); return; } else if (shortcutClass.equals(MemoryDumpActivity.class.getName())) { MemoryDumpActivity.startDump(this); return; } else if (shortcutClass.equals(ToggleWeightWatcher.class.getName())) { toggleShowWeightWatcher(); return; } } // Start activities int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(intent, shortcut); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } } else if (tag instanceof FolderInfo) { if (v instanceof FolderIcon) { FolderIcon fi = (FolderIcon) v; handleFolderClick(fi); } } else if (v == mAllAppsButton) { if (isAllAppsVisible()) { showWorkspace(true); } else { onClickAllAppsButton(v); } } }
From source file:com.android.soma.Launcher.java
/** * Starts the global search activity. This code is a copied from SearchManager *//*from w w w . ja v a 2 s. c o m*/ private void startGlobalSearch(String initialQuery, boolean selectInitialQuery, Bundle appSearchData, Rect sourceBounds) { final SearchManager searchManager = (SearchManager) getSystemService(Context.SEARCH_SERVICE); ComponentName globalSearchActivity = searchManager.getGlobalSearchActivity(); if (globalSearchActivity == null) { Log.w(TAG, "No global search activity found."); return; } Intent intent = new Intent(SearchManager.INTENT_ACTION_GLOBAL_SEARCH); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.setComponent(globalSearchActivity); // Make sure that we have a Bundle to put source in if (appSearchData == null) { appSearchData = new Bundle(); } else { appSearchData = new Bundle(appSearchData); } // Set source to package name of app that starts global search, if not set already. if (!appSearchData.containsKey("source")) { appSearchData.putString("source", getPackageName()); } intent.putExtra(SearchManager.APP_DATA, appSearchData); if (!TextUtils.isEmpty(initialQuery)) { intent.putExtra(SearchManager.QUERY, initialQuery); } if (selectInitialQuery) { intent.putExtra(SearchManager.EXTRA_SELECT_QUERY, selectInitialQuery); } intent.setSourceBounds(sourceBounds); try { startActivity(intent); } catch (ActivityNotFoundException ex) { Log.e(TAG, "Global search activity not found: " + globalSearchActivity); } }
From source file:g7.bluesky.launcher3.Launcher.java
private void startAppShortcutOrInfoActivity(View v) { Object tag = v.getTag();/*from w w w .jav a 2 s. co m*/ final ShortcutInfo shortcut; final Intent intent; String prefKey; if (tag instanceof ShortcutInfo) { shortcut = (ShortcutInfo) tag; prefKey = shortcut.getTargetComponent().getClassName(); intent = shortcut.intent; int[] pos = new int[2]; v.getLocationOnScreen(pos); intent.setSourceBounds(new Rect(pos[0], pos[1], pos[0] + v.getWidth(), pos[1] + v.getHeight())); } else if (tag instanceof AppInfo) { shortcut = null; intent = ((AppInfo) tag).intent; prefKey = ((AppInfo) tag).getComponentName().getClassName(); } else { throw new IllegalArgumentException("Input must be a Shortcut or AppInfo"); } // Count app launch times LauncherUtil.increaseAppLaunchTimes(defaultSharedPref, prefKey); boolean success = startActivitySafely(v, intent, tag); mStats.recordLaunch(intent, shortcut); if (success && v instanceof BubbleTextView) { mWaitingForResume = (BubbleTextView) v; mWaitingForResume.setStayPressed(true); } }