public void setShareIntent(Intent shareIntent) { if (shareIntent != null) { final String action = shareIntent.getAction(); if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } } ActivityChooserModel dataModel = ActivityChooserModel.get(mContext, mShareHistoryFileName); dataModel.setIntent(shareIntent); }
public void setShareIntent(Intent[] shareIntents) { // for (Intent intent : shareIntents) { // if (intent != null) { final String action = intent.getAction(); if (Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) { intent.addFlags(Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK); } } } CustomActivityChooserModel dataModel = CustomActivityChooserModel.get(mContext, mShareHistoryFileName); // ActivityChooserModel , dataModel.setIntent(shareIntents); // dataModel }
public static CustomActivityChooserModel get(Context context, String historyFileName) { synchronized (sRegistryLock) { CustomActivityChooserModel dataModel = sDataModelRegistry.get(historyFileName); if (dataModel == null) { dataModel = new CustomActivityChooserModel(context, historyFileName); sDataModelRegistry.put(historyFileName, dataModel); } return dataModel; } }
public void setIntent(Intent[] intents) { // synchronized (mInstanceLock) { if (mIntents == intents) { // intent mIntent Intent[] mIntents return; } mIntents = intents; mReloadActivities = true; ensureConsistentState(); } } // mIntent mIntents // : getIntent(), chooseActivity(), sortActivitiesIfNeeded(), loadActivitiesIfNeeded() // getIntent() , // chooseActivity() . , mIntent mIntents
private final List<ActivityResolveInfo> mActivities = new ArrayList<ActivityResolveInfo>(); /* ... */ // - private boolean loadActivitiesIfNeeded() { if (mReloadActivities && mIntent != null) { mReloadActivities = false; mActivities.clear(); List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivities(mIntent, 0); final int resolveInfoCount = resolveInfos.size(); for (int i = 0; i < resolveInfoCount; i++) { ResolveInfo resolveInfo = resolveInfos.get(i); mActivities.add(new ActivityResolveInfo(resolveInfo)); } return true; } return false; }
private final LinkedHashMap<Intent, ArrayList<ActivityResolveInfo>> mActivities = new LinkedHashMap<Intent, ArrayList<ActivityResolveInfo>>(); // -, , mActivities , , ( . , -) /* ... */ private boolean loadActivitiesIfNeeded() { if (mReloadActivities && mIntents != null) { mReloadActivities = false; mActivities.clear(); for (Intent intent : mIntents) { // List<ResolveInfo> resolveInfos = mContext.getPackageManager().queryIntentActivities(intent, 0); ArrayList<ActivityResolveInfo> activityResolveInfos = new ArrayList<>(); // ArrayList final int resolveInfoCount = resolveInfos.size(); for (int i = 0; i < resolveInfoCount; i++) { ResolveInfo resolveInfo = resolveInfos.get(i); activityResolveInfos.add(new ActivityResolveInfo(resolveInfo)); } mActivities.put(intent, activityResolveInfos); // , - . , } return true; } return false; }
private boolean sortActivitiesIfNeeded() { if (mActivitySorter != null && mIntents != null && !mActivities.isEmpty() && !mHistoricalRecords.isEmpty()) { for (Intent intent : mIntents) { // - mActivitySorter.sort(intent, mActivities.get(intent), Collections.unmodifiableList(mHistoricalRecords)); } // ⸮ . ⸮ return true; } return false; }
/** * Gets an activity resolve info at a given index. * * @return The activity resolve info. * @see ActivityResolveInfo * @see #setIntent(Intent[]) */ private ActivityResolveInfo getActivityResolveInfo(int index) { synchronized (mInstanceLock) { ensureConsistentState(); Collection<ArrayList<ActivityResolveInfo>> activitiesValues = mActivities.values(); ArrayList<ActivityResolveInfo> activitiesList = new ArrayList<>(); for (ArrayList<ActivityResolveInfo> list : activitiesValues) { activitiesList.addAll(list); } return activitiesList.get(index); } }
public ResolveInfo getActivity(int index) { synchronized (mInstanceLock) { ensureConsistentState(); return mActivities.get(index).resolveInfo; } }
public ResolveInfo getActivity(int index) { return getActivityResolveInfo(index).resolveInfo; }
public void setDefaultActivity(int index) { // // // ActivityResolveInfo newDefaultActivity = mActivities.get(index); // ActivityResolveInfo oldDefaultActivity = mActivities.get(0); // ActivityResolveInfo newDefaultActivity = mActivities.get(mIntents[0]).get(index); ActivityResolveInfo oldDefaultActivity = mActivities.get(mIntents[0]).get(0); //
public ResolveInfo getDefaultActivity() { synchronized (mInstanceLock) { ensureConsistentState(); if (!mActivities.isEmpty()) { return mActivities.get(0).resolveInfo; } } return null; }
public ResolveInfo getDefaultActivity() { synchronized (mInstanceLock) { ensureConsistentState(); if (!mActivities.isEmpty()) { for (ArrayList<ActivityResolveInfo> arrayList : mActivities.values()) { // if (!arrayList.isEmpty()) { return arrayList.get(0).resolveInfo; // - ResolveInfo } } } } return null; // null }
List<ActivityResolveInfo> activities = mActivities; final int activityCount = activities.size();
HashMap<Intent, ArrayList<ActivityResolveInfo>> activities = mActivities; Collection<ArrayList<ActivityResolveInfo>> activitiesValues = activities.values(); ArrayList<ActivityResolveInfo> activitiesList = new ArrayList<>(); for (ArrayList<ActivityResolveInfo> list : activitiesValues) { activitiesList.addAll(list); // ArrayList } final int activityCount = activitiesList.size();
public Intent chooseActivity(int index) { synchronized (mInstanceLock) { if (mIntent == null) { return null; } ensureConsistentState(); ActivityResolveInfo chosenActivity = mActivities.get(index); ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name); Intent choiceIntent = new Intent(mIntent); // } }
public Intent chooseActivity(int index) { synchronized (mInstanceLock) { if (mIntents == null) { return null; } ensureConsistentState(); ActivityResolveInfo chosenActivity = getActivityResolveInfo(index); // ComponentName chosenName = new ComponentName(chosenActivity.resolveInfo.activityInfo.packageName, chosenActivity.resolveInfo.activityInfo.name); Iterator iterator = mActivities.keySet().iterator(); // Intent tmpIntent = (Intent) iterator.next(); while (mActivities.get(tmpIntent).size() <= index) { // - index -= mActivities.get(tmpIntent).size(); // tmpIntent = (Intent) iterator.next(); // , } Intent choiceIntent = new Intent(tmpIntent); // , - // } }
private Intent[] getDefaultIntents() { DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", Locale.US); Calendar startCalendar = Calendar.getInstance(); Calendar endCalendar = Calendar.getInstance(); try { startCalendar.setTime(dateFormat.parse("2015-01-06 00:00:00")); endCalendar.setTime(dateFormat.parse("2015-05-06 00:00:00")); } catch (ParseException e) { e.printStackTrace(); } Intent calendarIntent = new Intent(Intent.ACTION_INSERT).setData(CalendarContract.Events.CONTENT_URI) .putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, startCalendar.getTimeInMillis()) .putExtra(CalendarContract.EXTRA_EVENT_END_TIME, endCalendar.getTimeInMillis()) .putExtra(CalendarContract.Events.TITLE, "My calendar event") .putExtra(CalendarContract.Events.DESCRIPTION, "Group class") .putExtra(CalendarContract.Events.EVENT_LOCATION, "Imaginary street 16, Imaginaryland"); Intent messageIntent = new Intent(Intent.ACTION_SEND); messageIntent.putExtra(Intent.EXTRA_TEXT, " "); messageIntent.putExtra(Intent.EXTRA_SUBJECT, " "); messageIntent.setType("text/plain"); return new Intent[] {calendarIntent, messageIntent}; }
Source: https://habr.com/ru/post/255133/
All Articles