Search in sources :

Example 16 with ComponentName

use of android.content.ComponentName in project cw-omnibus by commonsguy.

the class ActivityChooserModel method chooseActivity.

/**
     * Chooses a activity to handle the current intent. This will result in
     * adding a historical record for that action and construct intent with
     * its component name set such that it can be immediately started by the
     * client.
     * <p>
     * <strong>Note:</strong> By calling this method the client guarantees
     * that the returned intent will be started. This intent is returned to
     * the client solely to let additional customization before the start.
     * </p>
     *
     * @return An {@link Intent} for launching the activity or null if the
     *         policy has consumed the intent.
     *
     * @see HistoricalRecord
     * @see OnChooseActivityListener
     */
public Intent chooseActivity(int index) {
    ActivityResolveInfo chosenActivity = mActivites.get(index);
    ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name);
    Intent choiceIntent = new Intent(mIntent);
    choiceIntent.setComponent(chosenName);
    if (mActivityChoserModelPolicy != null) {
        // Do not allow the policy to change the intent.
        Intent choiceIntentCopy = new Intent(choiceIntent);
        final boolean handled = mActivityChoserModelPolicy.onChooseActivity(this, choiceIntentCopy);
        if (handled) {
            return null;
        }
    }
    HistoricalRecord historicalRecord = new HistoricalRecord(chosenName, System.currentTimeMillis(), DEFAULT_HISTORICAL_RECORD_WEIGHT);
    addHisoricalRecord(historicalRecord);
    return choiceIntent;
}
Also used : ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 17 with ComponentName

use of android.content.ComponentName in project cw-omnibus by commonsguy.

the class FreecarTileService method onClick.

@Override
public void onClick() {
    super.onClick();
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
    String cnFlat = prefs.getString(PREF_TO_LAUNCH, null);
    if (cnFlat != null) {
        ComponentName cn = ComponentName.unflattenFromString(cnFlat);
        try {
            ActivityInfo info = getPackageManager().getActivityInfo(cn, 0);
            ActivityInfo.WindowLayout layout = info.windowLayout;
            Intent i = new Intent().setComponent(cn).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Point size = new Point();
            getSystemService(DisplayManager.class).getDisplay(Display.DEFAULT_DISPLAY).getSize(size);
            if (layout == null) {
                size.x = size.x / 2;
                size.y = size.y / 2;
            } else {
                if (layout.widthFraction > 0.0f) {
                    size.x = Math.max(layout.minWidth, (int) (size.x * layout.widthFraction));
                } else {
                    size.x = layout.width;
                }
                if (layout.heightFraction > 0.0f) {
                    size.y = Math.max(layout.minHeight, (int) (size.y * layout.heightFraction));
                } else {
                    size.y = layout.height;
                }
            }
            ActivityOptions opts = ActivityOptions.makeBasic().setLaunchBounds(new Rect(0, 0, size.x, size.y));
            startActivity(i, opts.toBundle());
        } catch (Exception e) {
            Log.e(getClass().getSimpleName(), "Exception trying to launch activity", e);
            toast(R.string.msg_sorry);
        }
    } else {
        toast(R.string.msg_choose);
    }
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) Rect(android.graphics.Rect) SharedPreferences(android.content.SharedPreferences) ComponentName(android.content.ComponentName) Intent(android.content.Intent) Point(android.graphics.Point) ActivityOptions(android.app.ActivityOptions)

Example 18 with ComponentName

use of android.content.ComponentName in project cw-omnibus by commonsguy.

the class MainActivity method onListItemClick.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    ResolveInfo launchable = adapter.getItem(position);
    ActivityInfo activity = launchable.activityInfo;
    ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
    PreferenceManager.getDefaultSharedPreferences(this).edit().putString(FreecarTileService.PREF_TO_LAUNCH, name.flattenToString()).apply();
    Toast.makeText(this, R.string.msg_saved, Toast.LENGTH_LONG).show();
    finish();
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ComponentName(android.content.ComponentName)

Example 19 with ComponentName

use of android.content.ComponentName in project cw-omnibus by commonsguy.

the class Launchalot method onListItemClick.

@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    ResolveInfo launchable = adapter.getItem(position);
    ActivityInfo activity = launchable.activityInfo;
    ComponentName name = new ComponentName(activity.applicationInfo.packageName, activity.name);
    Intent i = new Intent(Intent.ACTION_MAIN);
    i.addCategory(Intent.CATEGORY_LAUNCHER);
    i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED);
    i.setComponent(name);
    startActivity(i);
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ActivityInfo(android.content.pm.ActivityInfo) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 20 with ComponentName

use of android.content.ComponentName in project cw-advandroid by commonsguy.

the class AppWidget method onUpdate.

@Override
public void onUpdate(Context ctxt, AppWidgetManager mgr, int[] appWidgetIds) {
    ComponentName me = new ComponentName(ctxt, AppWidget.class);
    mgr.updateAppWidget(me, buildUpdate(ctxt, appWidgetIds));
}
Also used : ComponentName(android.content.ComponentName)

Aggregations

ComponentName (android.content.ComponentName)2524 Intent (android.content.Intent)941 ResolveInfo (android.content.pm.ResolveInfo)375 RemoteException (android.os.RemoteException)317 PackageManager (android.content.pm.PackageManager)266 PendingIntent (android.app.PendingIntent)248 ActivityInfo (android.content.pm.ActivityInfo)243 ArrayList (java.util.ArrayList)240 ShortcutInfo (android.content.pm.ShortcutInfo)152 Point (android.graphics.Point)145 Bundle (android.os.Bundle)137 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)130 IBinder (android.os.IBinder)128 IOException (java.io.IOException)124 ServiceConnection (android.content.ServiceConnection)96 ServiceInfo (android.content.pm.ServiceInfo)95 UserHandle (android.os.UserHandle)86 ArraySet (android.util.ArraySet)73 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)69 Uri (android.net.Uri)66