Example usage for android.content Intent getComponent

List of usage examples for android.content Intent getComponent

Introduction

In this page you can find the example usage for android.content Intent getComponent.

Prototype

public @Nullable ComponentName getComponent() 

Source Link

Document

Retrieve the concrete component associated with the intent.

Usage

From source file:com.android.soma.Launcher.java

/**
 * Launches the intent referred by the clicked shortcut.
 *
 * @param v The view representing the clicked shortcut.
 *///from w ww  .ja  v  a2s.co  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.fairphone.fplauncher3.Workspace.java

private void updateShortcutsAndWidgetsPerUser(ArrayList<AppInfo> apps, final UserHandleCompat user) {
    // Create a map of the apps to test against
    final HashMap<ComponentName, AppInfo> appsMap = new HashMap<ComponentName, AppInfo>();
    final HashSet<String> pkgNames = new HashSet<String>();
    for (AppInfo ai : apps) {
        appsMap.put(ai.componentName, ai);
        pkgNames.add(ai.componentName.getPackageName());
    }/*from   w  w w  .  ja  va 2  s  . c  o m*/
    final HashSet<ComponentName> iconsToRemove = new HashSet<ComponentName>();

    mapOverItems(MAP_RECURSE, new ItemOperator() {
        @Override
        public boolean evaluate(ItemInfo info, View v, View parent) {
            if (info instanceof ShortcutInfo && v instanceof BubbleTextView) {
                ShortcutInfo shortcutInfo = (ShortcutInfo) info;
                ComponentName cn = shortcutInfo.getTargetComponent();
                AppInfo appInfo = appsMap.get(cn);
                if (user.equals(shortcutInfo.user) && cn != null && LauncherModel.isShortcutInfoUpdateable(info)
                        && pkgNames.contains(cn.getPackageName())) {
                    boolean promiseStateChanged = false;
                    boolean infoUpdated = false;
                    if (shortcutInfo.isPromise()) {
                        if (shortcutInfo.hasStatusFlag(ShortcutInfo.FLAG_AUTOINTALL_ICON)) {
                            // Auto install icon
                            PackageManager pm = getContext().getPackageManager();
                            ResolveInfo matched = pm
                                    .resolveActivity(
                                            new Intent(Intent.ACTION_MAIN).setComponent(cn)
                                                    .addCategory(Intent.CATEGORY_LAUNCHER),
                                            PackageManager.MATCH_DEFAULT_ONLY);
                            if (matched == null) {
                                // Try to find the best match activity.
                                Intent intent = pm.getLaunchIntentForPackage(cn.getPackageName());
                                if (intent != null) {
                                    cn = intent.getComponent();
                                    appInfo = appsMap.get(cn);
                                }

                                if ((intent == null) || (appsMap == null)) {
                                    // Could not find a default activity. Remove this item.
                                    iconsToRemove.add(shortcutInfo.getTargetComponent());

                                    // process next shortcut.
                                    return false;
                                }
                                shortcutInfo.promisedIntent = intent;
                            }
                        }

                        // Restore the shortcut.
                        shortcutInfo.intent = shortcutInfo.promisedIntent;
                        shortcutInfo.promisedIntent = null;
                        shortcutInfo.status &= ~ShortcutInfo.FLAG_RESTORED_ICON
                                & ~ShortcutInfo.FLAG_AUTOINTALL_ICON
                                & ~ShortcutInfo.FLAG_INSTALL_SESSION_ACTIVE;

                        promiseStateChanged = true;
                        infoUpdated = true;
                        shortcutInfo.updateIcon(mIconCache);
                        LauncherModel.updateItemInDatabase(getContext(), shortcutInfo);
                    }

                    if (appInfo != null) {
                        shortcutInfo.updateIcon(mIconCache);
                        shortcutInfo.title = appInfo.title.toString();
                        shortcutInfo.contentDescription = appInfo.contentDescription;
                        infoUpdated = true;
                    }

                    if (infoUpdated) {
                        BubbleTextView shortcut = (BubbleTextView) v;
                        shortcut.applyFromShortcutInfo(shortcutInfo, mIconCache, true, promiseStateChanged);

                        if (parent != null) {
                            parent.invalidate();
                        }
                    }
                }
            }
            // process all the shortcuts
            return false;
        }
    });

    if (!iconsToRemove.isEmpty()) {
        removeItemsByComponentName(iconsToRemove, user);
    }
    if (user.equals(UserHandleCompat.myUserHandle())) {
        restorePendingWidgets(pkgNames);
    }
}

From source file:com.klinker.android.launcher.launcher3.Launcher.java

@Thunk
boolean startActivitySafely(View v, Intent intent, Object tag) {
    boolean success = false;
    if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }/*w  ww . j a  v  a  2  s . c  o  m*/
    try {
        success = startActivity(v, intent, tag);

        if (isAllAppsVisible()) { // only add to the prediction if they open from the drawer
            predictiveAppsProvider.updateComponentCount(intent.getComponent());
        }
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
    }

    return success;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

private void updateCounters(View view, String packageName, int counter, int color, int updateCounterFor) {
    Object tag = view.getTag();//w  w w  .  j a  va  2 s  .co  m
    //PersonaLog.d("personalauncher","------- view is ---- "+ view.toString());
    if (tag != null)
        //PersonaLog.d("personalauncher","------- tag is ---- "+ tag.toString());

        if (tag instanceof PersonaApplicationInfo) {
            PersonaApplicationInfo info = (PersonaApplicationInfo) tag;
            // We need to check for ACTION_MAIN otherwise getComponent() might
            // return null for some shortcuts (for instance, for shortcuts to
            // web pages.)
            final Intent intent = info.intent;
            final ComponentName name = intent.getComponent();
            //   PersonaLog.d("Personalauncher","name " + name.flattenToString());

            //Badge
            switch (updateCounterFor) {
            case UPDATE_COUNTERS_FOR_DIALER:
                if (name.flattenToString().contains("DialerParentActivity")) {
                    //BADGE - below lines from if loop below added since that if loop fails
                    if (view instanceof PersonaCounterImageView)
                        ((PersonaCounterImageView) view).setCounter(counter, color);
                    // else if
                    view.invalidate();
                    sModel.updateCounterDesktopItem(info, counter, color);

                    //BADGE ends
                }
                break;
            case UPDATE_COUNTERS_FOR_MESSENGER:
                if (name.flattenToString().contains("SmsListdisplay")) {
                    //BADGE - below lines from if loop below added since that if loop fails
                    if (view instanceof PersonaCounterImageView)
                        ((PersonaCounterImageView) view).setCounter(counter, color);
                    // else if
                    view.invalidate();
                    sModel.updateCounterDesktopItem(info, counter, color);

                    //BADGE ends
                }
                break;
            }
            if ((info.itemType == PersonaLauncherSettings.Favorites.ITEM_TYPE_APPLICATION
                    || info.itemType == PersonaLauncherSettings.Favorites.ITEM_TYPE_SHORTCUT)
                    && Intent.ACTION_MAIN.equals(intent.getAction()) && name != null
                    && packageName.equals(name.getPackageName())) {
                if (view instanceof PersonaCounterImageView)
                    ((PersonaCounterImageView) view).setCounter(counter, color);
                // else if
                view.invalidate();
                sModel.updateCounterDesktopItem(info, counter, color);
            }
        } else {
            //PersonaLog.d("personalauncher","------ tag is not an instance of personaApplicationInfo-----");
            //if(tag != null)
            //   PersonaLog.d("personalauncher","------- tag not an instance of personaapplicationinfo ---- "+ tag.toString());
        }
}

From source file:xyz.klinker.blur.launcher3.Launcher.java

public boolean startActivitySafely(View v, Intent intent, Object tag) {
    boolean success = false;
    if (mIsSafeModeEnabled && !Utilities.isSystemApp(this, intent)) {
        Toast.makeText(this, R.string.safemode_shortcut_error, Toast.LENGTH_SHORT).show();
        return false;
    }//from  w  ww .ja v a  2s .c  om
    try {
        success = startActivity(v, intent, tag);

        if (isAllAppsVisible()) { // only add to the prediction if they open from the drawer
            predictiveAppsProvider.updateComponentCount(intent.getComponent());
        }
    } catch (ActivityNotFoundException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        Log.e(TAG, "Unable to launch. tag=" + tag + " intent=" + intent, e);
    }

    return success;
}

From source file:com.cognizant.trumobi.PersonaLauncher.java

@Override
public void startActivity(Intent intent) {
    // TODO Auto-generated method stub
    PersonaLog.d("PersonaLauncher", " -- startActivity ----");
    final ComponentName name = intent.getComponent();
    if (name != null) {
        PersonaLog.d("personalauncher", "updateCountersForPackage called from startactivity");
        updateCountersForPackage(name.getPackageName(), 0, 0, 0);
    }//  www  .j  a  v a 2 s .  c  o  m
    PersonaLog.d("personalauncher", "parameter passed is " + name.getPackageName());
    PersonaLog.d("personalauncher", "--------inside startactivity----- intent is " + intent.toString());
    try {
        super.startActivity(intent);
    } catch (ActivityNotFoundException e) {
        e.printStackTrace();
        Toast.makeText(this, getString(R.string.activity_not_found) + "123", Toast.LENGTH_SHORT).show();
    } catch (SecurityException e) {
        Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
        PersonaLog.e(LOG_TAG,
                "PersonaLauncher does not have the permission to launch " + intent
                        + ". Make sure to create a MAIN intent-filter for the corresponding activity "
                        + "or use the exported attribute for this activity.",
                e);
    }
}

From source file:com.android.soma.Launcher.java

/**
 * Add an application shortcut to the workspace.
 *
 * @param data The intent describing the application.
 * @param cellInfo The position on screen where to create the shortcut.
 *//*from w  ww  . j a  v  a 2  s.co  m*/
void completeAddApplication(Intent data, long container, long screenId, int cellX, int cellY) {
    final int[] cellXY = mTmpAddItemCellCoordinates;
    final CellLayout layout = getCellLayout(container, screenId);

    // First we check if we already know the exact location where we want to add this item.
    if (cellX >= 0 && cellY >= 0) {
        cellXY[0] = cellX;
        cellXY[1] = cellY;
    } else if (!layout.findCellForSpan(cellXY, 1, 1)) {
        showOutOfSpaceMessage(isHotseatLayout(layout));
        return;
    }

    final ShortcutInfo info = mModel.getShortcutInfo(getPackageManager(), data, this);

    if (info != null) {
        info.setActivity(this, data.getComponent(),
                Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
        info.container = ItemInfo.NO_ID;
        mWorkspace.addApplicationShortcut(info, layout, container, screenId, cellXY[0], cellXY[1],
                isWorkspaceLocked(), cellX, cellY);
    } else {
        Log.e(TAG, "Couldn't find ActivityInfo for selected application: " + data);
    }
}

From source file:android.app.Activity.java

/**
 * Navigate from this activity to the activity specified by upIntent, finishing this activity
 * in the process. If the activity indicated by upIntent already exists in the task's history,
 * this activity and all others before the indicated activity in the history stack will be
 * finished./*from  w w w .  j  a  v a  2  s. co  m*/
 *
 * <p>If the indicated activity does not appear in the history stack, this will finish
 * each activity in this task until the root activity of the task is reached, resulting in
 * an "in-app home" behavior. This can be useful in apps with a complex navigation hierarchy
 * when an activity may be reached by a path not passing through a canonical parent
 * activity.</p>
 *
 * <p>This method should be used when performing up navigation from within the same task
 * as the destination. If up navigation should cross tasks in some cases, see
 * {@link #shouldUpRecreateTask(Intent)}.</p>
 *
 * @param upIntent An intent representing the target destination for up navigation
 *
 * @return true if up navigation successfully reached the activity indicated by upIntent and
 *         upIntent was delivered to it. false if an instance of the indicated activity could
 *         not be found and this activity was simply finished normally.
 */
public boolean navigateUpTo(Intent upIntent) {
    if (mParent == null) {
        ComponentName destInfo = upIntent.getComponent();
        if (destInfo == null) {
            destInfo = upIntent.resolveActivity(getPackageManager());
            if (destInfo == null) {
                return false;
            }
            upIntent = new Intent(upIntent);
            upIntent.setComponent(destInfo);
        }
        int resultCode;
        Intent resultData;
        synchronized (this) {
            resultCode = mResultCode;
            resultData = mResultData;
        }
        if (resultData != null) {
            resultData.prepareToLeaveProcess();
        }
        try {
            upIntent.prepareToLeaveProcess();
            return ActivityManagerNative.getDefault().navigateUpTo(mToken, upIntent, resultCode, resultData);
        } catch (RemoteException e) {
            return false;
        }
    } else {
        return mParent.navigateUpToFromChild(this, upIntent);
    }
}

From source file:android.app.Activity.java

/**
 * Returns true if the app should recreate the task when navigating 'up' from this activity
 * by using targetIntent.//w w w . ja va  2  s . c o m
 *
 * <p>If this method returns false the app can trivially call
 * {@link #navigateUpTo(Intent)} using the same parameters to correctly perform
 * up navigation. If this method returns false, the app should synthesize a new task stack
 * by using {@link TaskStackBuilder} or another similar mechanism to perform up navigation.</p>
 *
 * @param targetIntent An intent representing the target destination for up navigation
 * @return true if navigating up should recreate a new task stack, false if the same task
 *         should be used for the destination
 */
public boolean shouldUpRecreateTask(Intent targetIntent) {
    try {
        PackageManager pm = getPackageManager();
        ComponentName cn = targetIntent.getComponent();
        if (cn == null) {
            cn = targetIntent.resolveActivity(pm);
        }
        ActivityInfo info = pm.getActivityInfo(cn, 0);
        if (info.taskAffinity == null) {
            return false;
        }
        return !ActivityManagerNative.getDefault().targetTaskAffinityMatchesActivity(mToken, info.taskAffinity);
    } catch (RemoteException e) {
        return false;
    } catch (NameNotFoundException e) {
        return false;
    }
}

From source file:com.android.launcher3.Launcher.java

private void startShortcutIntentSafely(Intent intent, Bundle optsBundle, ItemInfo info) {
    try {/*  w ww.  j  av  a  2 s.  c o m*/
        StrictMode.VmPolicy oldPolicy = StrictMode.getVmPolicy();
        try {
            // Temporarily disable deathPenalty on all default checks. For eg, shortcuts
            // containing file Uri's would cause a crash as penaltyDeathOnFileUriExposure
            // is enabled by default on NYC.
            StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder().detectAll().penaltyLog().build());

            if (info.itemType == LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT) {
                String id = ((ShortcutInfo) info).getDeepShortcutId();
                String packageName = intent.getPackage();
                LauncherAppState.getInstance().getShortcutManager().startShortcut(packageName, id,
                        intent.getSourceBounds(), optsBundle, info.user);
            } else {
                // Could be launching some bookkeeping activity
                startActivity(intent, optsBundle);
            }
        } finally {
            StrictMode.setVmPolicy(oldPolicy);
        }
    } catch (SecurityException e) {
        // Due to legacy reasons, direct call shortcuts require Launchers to have the
        // corresponding permission. Show the appropriate permission prompt if that
        // is the case.
        if (intent.getComponent() == null && Intent.ACTION_CALL.equals(intent.getAction())
                && checkSelfPermission(Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

            setWaitingForResult(PendingRequestArgs.forIntent(REQUEST_PERMISSION_CALL_PHONE, intent, info));
            requestPermissions(new String[] { Manifest.permission.CALL_PHONE }, REQUEST_PERMISSION_CALL_PHONE);
        } else {
            // No idea why this was thrown.
            throw e;
        }
    }
}