private void chooseActivity(int index) { if (mOnTargetListener != null) mOnTargetListener.onTargetSelected(); ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); Intent launchIntent = dataModel.chooseActivity(index); if (launchIntent != null) { launchIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); mContext.startActivity(launchIntent); } }
@Override public View onCreateActionView() { // Create the view and set its data model. ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); MenuItemActionView view = new MenuItemActionView(mContext, null); view.setActionButtonClickListener(mCallbacks); if (dataModel.getHistorySize() > 0) { PackageManager packageManager = mContext.getPackageManager(); ResolveInfo defaultActivity = dataModel.getDefaultActivity(); view.setActionButton( defaultActivity == null ? null : defaultActivity.loadIcon(packageManager)); } return view; }
@Override public void onPrepareSubMenu(SubMenu subMenu) { // Clear since the order of items may change. subMenu.clear(); ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); PackageManager packageManager = mContext.getPackageManager(); // Populate the sub-menu with a sub set of the activities. final int count = dataModel.getActivityCount(); for (int i = 0; i < count; i++) { ResolveInfo activity = dataModel.getActivity(i); subMenu .add(0, i, i, activity.loadLabel(packageManager)) .setIcon(activity.loadIcon(packageManager)) .setOnMenuItemClickListener(mCallbacks); } }
public Intent getIntent() { ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); return dataModel.getIntent(); }
@Override public void onClick(View view) { ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); chooseActivity(dataModel.getActivityIndex(dataModel.getDefaultActivity())); }
public void setIntent(Intent intent) { ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mHistoryFileName); dataModel.setIntent(intent); }