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;
}
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);
}
}
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();
}
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);
}
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));
}
Aggregations