Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3b56b0d7 authored by Svetoslav Ganov's avatar Svetoslav Ganov Committed by Android (Google) Code Review
Browse files

Merge "Polish of the ActivityChooserView and ShareActionProvider."

parents 0d4fc334 76559a65
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -26082,7 +26082,7 @@ package android.widget {
    ctor public ShareActionProvider(android.content.Context);
    method public android.view.View onCreateActionView();
    method public void setShareHistoryFileName(java.lang.String);
    method public void setShareIntent(android.view.View, android.content.Intent);
    method public void setShareIntent(android.content.Intent);
    field public static final java.lang.String DEFAULT_SHARE_HISTORY_FILE_NAME = "share_history.xml";
  }
+3 −1
Original line number Diff line number Diff line
@@ -28,7 +28,9 @@ import android.content.Context;
 * {@link android.app.ActionBar} as a substitute for the menu item when the item is
 * displayed as an action item. Also the provider is responsible for performing a
 * default action if a menu item placed on the overflow menu of the ActionBar is
 * selected and none of the menu item callbacks has handled the selection.
 * selected and none of the menu item callbacks has handled the selection. For this
 * case the provider can also optionally provide a sub-menu for accomplishing the
 * task at hand.
 * </p>
 * <p>
 * There are two ways for using an action provider for creating and handling of action views:
+31 −32
Original line number Diff line number Diff line
@@ -126,7 +126,7 @@ public class ActivityChooserModel extends DataSetObservable {
         */
        // This cannot be done by a simple comparator since an Activity weight
        // is computed from history. Note that Activity implements Comparable.
        public void sort(Intent intent, List<Activity> activities,
        public void sort(Intent intent, List<ActivityResolveInfo> activities,
                List<HistoricalRecord> historicalRecords);
    }

@@ -215,7 +215,7 @@ public class ActivityChooserModel extends DataSetObservable {
    /**
     * List of activities that can handle the current intent.
     */
    private final List<Activity> mActivitys = new ArrayList<Activity>();
    private final List<ActivityResolveInfo> mActivites = new ArrayList<ActivityResolveInfo>();

    /**
     * List with historical choice records.
@@ -311,9 +311,6 @@ public class ActivityChooserModel extends DataSetObservable {
     * @return The model.
     */
    public static ActivityChooserModel get(Context context, String historyFileName) {
        if (historyFileName == null) {
            return new ActivityChooserModel(context, historyFileName);
        }
        synchronized (sRegistryLock) {
            ActivityChooserModel dataModel = sDataModelRegistry.get(historyFileName);
            if (dataModel == null) {
@@ -380,7 +377,7 @@ public class ActivityChooserModel extends DataSetObservable {
     */
    public int getActivityCount() {
        synchronized (mInstanceLock) {
            return mActivitys.size();
            return mActivites.size();
        }
    }

@@ -389,12 +386,12 @@ public class ActivityChooserModel extends DataSetObservable {
     *
     * @return The activity.
     *
     * @see Activity
     * @see ActivityResolveInfo
     * @see #setIntent(Intent)
     */
    public ResolveInfo getActivity(int index) {
        synchronized (mInstanceLock) {
            return mActivitys.get(index).resolveInfo;
            return mActivites.get(index).resolveInfo;
        }
    }

@@ -406,10 +403,10 @@ public class ActivityChooserModel extends DataSetObservable {
     * @return The index if found, -1 otherwise.
     */
    public int getActivityIndex(ResolveInfo activity) {
        List<Activity> activities = mActivitys;
        List<ActivityResolveInfo> activities = mActivites;
        final int activityCount = activities.size();
        for (int i = 0; i < activityCount; i++) {
            Activity currentActivity = activities.get(i);
            ActivityResolveInfo currentActivity = activities.get(i);
            if (currentActivity.resolveInfo == activity) {
                return i;
            }
@@ -433,8 +430,8 @@ public class ActivityChooserModel extends DataSetObservable {
     * @see HistoricalRecord
     */
    public Intent chooseActivity(int index) {
        Activity chosenActivity = mActivitys.get(index);
        Activity defaultActivity = mActivitys.get(0);
        ActivityResolveInfo chosenActivity = mActivites.get(index);
        ActivityResolveInfo defaultActivity = mActivites.get(0);

        ComponentName chosenName = new ComponentName(
                chosenActivity.resolveInfo.activityInfo.packageName,
@@ -460,8 +457,8 @@ public class ActivityChooserModel extends DataSetObservable {
     */
    public ResolveInfo getDefaultActivity() {
        synchronized (mInstanceLock) {
            if (!mActivitys.isEmpty()) {
                return mActivitys.get(0).resolveInfo;
            if (!mActivites.isEmpty()) {
                return mActivites.get(0).resolveInfo;
            }
        }
        return null;
@@ -478,8 +475,8 @@ public class ActivityChooserModel extends DataSetObservable {
     * @param index The index of the activity to set as default.
     */
    public void setDefaultActivity(int index) {
        Activity newDefaultActivity = mActivitys.get(index);
        Activity oldDefaultActivity = mActivitys.get(0);
        ActivityResolveInfo newDefaultActivity = mActivites.get(index);
        ActivityResolveInfo oldDefaultActivity = mActivites.get(0);

        final float weight;
        if (oldDefaultActivity != null) {
@@ -572,8 +569,8 @@ public class ActivityChooserModel extends DataSetObservable {
     */
    private void sortActivities() {
        synchronized (mInstanceLock) {
            if (mActivitySorter != null && !mActivitys.isEmpty()) {
                mActivitySorter.sort(mIntent, mActivitys,
            if (mActivitySorter != null && !mActivites.isEmpty()) {
                mActivitySorter.sort(mIntent, mActivites,
                        Collections.unmodifiableList(mHistoricalRecords));
                notifyChanged();
            }
@@ -661,14 +658,14 @@ public class ActivityChooserModel extends DataSetObservable {
     * Loads the activities.
     */
    private void loadActivitiesLocked() {
        mActivitys.clear();
        mActivites.clear();
        if (mIntent != null) {
            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);
                mActivitys.add(new Activity(resolveInfo));
                mActivites.add(new ActivityResolveInfo(resolveInfo));
            }
            sortActivities();
        } else {
@@ -797,7 +794,7 @@ public class ActivityChooserModel extends DataSetObservable {
    /**
     * Represents an activity.
     */
    public final class Activity implements Comparable<Activity> {
    public final class ActivityResolveInfo implements Comparable<ActivityResolveInfo> {

        /**
         * The {@link ResolveInfo} of the activity.
@@ -814,7 +811,7 @@ public class ActivityChooserModel extends DataSetObservable {
         *
         * @param resolveInfo activity {@link ResolveInfo}.
         */
        public Activity(ResolveInfo resolveInfo) {
        public ActivityResolveInfo(ResolveInfo resolveInfo) {
            this.resolveInfo = resolveInfo;
        }

@@ -834,14 +831,14 @@ public class ActivityChooserModel extends DataSetObservable {
            if (getClass() != obj.getClass()) {
                return false;
            }
            Activity other = (Activity) obj;
            ActivityResolveInfo other = (ActivityResolveInfo) obj;
            if (Float.floatToIntBits(weight) != Float.floatToIntBits(other.weight)) {
                return false;
            }
            return true;
        }

        public int compareTo(Activity another) {
        public int compareTo(ActivityResolveInfo another) {
             return  Float.floatToIntBits(another.weight) - Float.floatToIntBits(weight);
        }

@@ -862,18 +859,18 @@ public class ActivityChooserModel extends DataSetObservable {
    private final class DefaultSorter implements ActivitySorter {
        private static final float WEIGHT_DECAY_COEFFICIENT = 0.95f;

        private final Map<String, Activity> mPackageNameToActivityMap =
            new HashMap<String, Activity>();
        private final Map<String, ActivityResolveInfo> mPackageNameToActivityMap =
            new HashMap<String, ActivityResolveInfo>();

        public void sort(Intent intent, List<Activity> activities,
        public void sort(Intent intent, List<ActivityResolveInfo> activities,
                List<HistoricalRecord> historicalRecords) {
            Map<String, Activity> packageNameToActivityMap =
            Map<String, ActivityResolveInfo> packageNameToActivityMap =
                mPackageNameToActivityMap;
            packageNameToActivityMap.clear();

            final int activityCount = activities.size();
            for (int i = 0; i < activityCount; i++) {
                Activity activity = activities.get(i);
                ActivityResolveInfo activity = activities.get(i);
                activity.weight = 0.0f;
                String packageName = activity.resolveInfo.activityInfo.packageName;
                packageNameToActivityMap.put(packageName, activity);
@@ -884,10 +881,12 @@ public class ActivityChooserModel extends DataSetObservable {
            for (int i = lastShareIndex; i >= 0; i--) {
                HistoricalRecord historicalRecord = historicalRecords.get(i);
                String packageName = historicalRecord.activity.getPackageName();
                Activity activity = packageNameToActivityMap.get(packageName);
                ActivityResolveInfo activity = packageNameToActivityMap.get(packageName);
                if (activity != null) {
                    activity.weight += historicalRecord.weight * nextRecordWeight;
                    nextRecordWeight = nextRecordWeight * WEIGHT_DECAY_COEFFICIENT;
                }
            }

            Collections.sort(activities);

+100 −211

File changed.

Preview size limit exceeded, changes collapsed.

+1 −0
Original line number Diff line number Diff line
@@ -375,6 +375,7 @@ public class CalendarView extends FrameLayout {
                com.android.internal.R.styleable.TextAppearance);
        mDateTextSize = dateTextAppearance.getDimensionPixelSize(
                R.styleable.TextAppearance_textSize, DEFAULT_DATE_TEXT_SIZE);
        dateTextAppearance.recycle();

        int weekDayTextAppearanceResId = attributesArray.getResourceId(
                R.styleable.CalendarView_weekDayTextAppearance,
Loading