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

Commit 79a45c6f authored by Amith Yamasani's avatar Amith Yamasani Committed by Android (Google) Code Review
Browse files

Merge "Improve Intent disambig dialog behavior" into klp-dev

parents 6b115980 e9ecc8b4
Loading
Loading
Loading
Loading
+7 −1
Original line number Diff line number Diff line
@@ -216,6 +216,12 @@ interface IPackageManager {

    void resetPreferredActivities(int userId);

    ResolveInfo getLastChosenActivity(in Intent intent,
            String resolvedType, int flags);

    void setLastChosenActivity(in Intent intent, String resolvedType, int flags,
            in IntentFilter filter, int match, in ComponentName activity);

    void addPreferredActivity(in IntentFilter filter, int match,
            in ComponentName[] set, in ComponentName activity, int userId);

+130 −98
Original line number Diff line number Diff line
@@ -22,11 +22,13 @@ import com.android.internal.content.PackageMonitor;

import android.app.ActivityManager;
import android.app.ActivityManagerNative;
import android.app.AppGlobals;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.ActivityInfo;
import android.content.pm.IPackageManager;
import android.content.pm.LabeledIntent;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
@@ -45,7 +47,6 @@ import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
@@ -71,13 +72,13 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
    private PackageManager mPm;
    private boolean mAlwaysUseOption;
    private boolean mShowExtended;
    private GridView mGrid;
    private ListView mListView;
    private Button mAlwaysButton;
    private Button mOnceButton;
    private int mIconDpi;
    private int mIconSize;
    private int mMaxColumns;
    private int mLastSelected = GridView.INVALID_POSITION;
    private int mLastSelected = ListView.INVALID_POSITION;

    private boolean mRegistered;
    private final PackageMonitor mPackageMonitor = new PackageMonitor() {
@@ -139,17 +140,15 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
            finish();
            return;
        } else if (count > 1) {
            ap.mView = getLayoutInflater().inflate(R.layout.resolver_grid, null);
            mGrid = (GridView) ap.mView.findViewById(R.id.resolver_grid);
            mGrid.setAdapter(mAdapter);
            mGrid.setOnItemClickListener(this);
            mGrid.setOnItemLongClickListener(new ItemLongClickListener());
            ap.mView = getLayoutInflater().inflate(R.layout.resolver_list, null);
            mListView = (ListView) ap.mView.findViewById(R.id.resolver_list);
            mListView.setAdapter(mAdapter);
            mListView.setOnItemClickListener(this);
            mListView.setOnItemLongClickListener(new ItemLongClickListener());

            if (alwaysUseOption) {
                mGrid.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
                mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
            }

            resizeGrid();
        } else if (count == 1) {
            startActivity(mAdapter.intentForPosition(0));
            mPackageMonitor.unregister();
@@ -172,11 +171,11 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
                mAlwaysUseOption = false;
            }
        }
        final int initialHighlight = mAdapter.getInitialHighlight();
        if (initialHighlight >= 0) {
            mListView.setItemChecked(initialHighlight, true);
            onItemClick(null, null, initialHighlight, 0); // Other entries are not used
        }

    void resizeGrid() {
        final int itemCount = mAdapter.getCount();
        mGrid.setNumColumns(Math.min(itemCount, mMaxColumns));
    }

    Drawable getIcon(Resources res, int resId) {
@@ -247,26 +246,26 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
    protected void onRestoreInstanceState(Bundle savedInstanceState) {
        super.onRestoreInstanceState(savedInstanceState);
        if (mAlwaysUseOption) {
            final int checkedPos = mGrid.getCheckedItemPosition();
            final boolean enabled = checkedPos != GridView.INVALID_POSITION;
            final int checkedPos = mListView.getCheckedItemPosition();
            final boolean enabled = checkedPos != ListView.INVALID_POSITION;
            mLastSelected = checkedPos;
            mAlwaysButton.setEnabled(enabled);
            mOnceButton.setEnabled(enabled);
            if (enabled) {
                mGrid.setSelection(checkedPos);
                mListView.setSelection(checkedPos);
            }
        }
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        final int checkedPos = mGrid.getCheckedItemPosition();
        final boolean hasValidSelection = checkedPos != GridView.INVALID_POSITION;
        final int checkedPos = mListView.getCheckedItemPosition();
        final boolean hasValidSelection = checkedPos != ListView.INVALID_POSITION;
        if (mAlwaysUseOption && (!hasValidSelection || mLastSelected != checkedPos)) {
            mAlwaysButton.setEnabled(hasValidSelection);
            mOnceButton.setEnabled(hasValidSelection);
            if (hasValidSelection) {
                mGrid.smoothScrollToPosition(checkedPos);
                mListView.smoothScrollToPosition(checkedPos);
            }
            mLastSelected = checkedPos;
        } else {
@@ -276,7 +275,7 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte

    public void onButtonClick(View v) {
        final int id = v.getId();
        startSelected(mGrid.getCheckedItemPosition(), id == R.id.button_always);
        startSelected(mListView.getCheckedItemPosition(), id == R.id.button_always);
        dismiss();
    }

@@ -288,7 +287,6 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
    }

    protected void onIntentSelected(ResolveInfo ri, Intent intent, boolean alwaysCheck) {
        if (alwaysCheck) {
        // Build a reasonable intent filter, based on what matched.
        IntentFilter filter = new IntentFilter();

@@ -374,8 +372,18 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
                        r.activityInfo.name);
                if (r.match > bestMatch) bestMatch = r.match;
            }
            if (alwaysCheck) {
                getPackageManager().addPreferredActivity(filter, bestMatch, set,
                        intent.getComponent());
            } else {
                try {
                    AppGlobals.getPackageManager().setLastChosenActivity(intent,
                            intent.resolveTypeIfNeeded(getContentResolver()),
                            PackageManager.MATCH_DEFAULT_ONLY,
                            filter, bestMatch, intent.getComponent());
                } catch (RemoteException re) {
                    Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
                }
            }
        }

@@ -410,11 +418,13 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
    private final class ResolveListAdapter extends BaseAdapter {
        private final Intent[] mInitialIntents;
        private final List<ResolveInfo> mBaseResolveList;
        private ResolveInfo mLastChosen;
        private final Intent mIntent;
        private final int mLaunchedFromUid;
        private final LayoutInflater mInflater;

        private List<DisplayResolveInfo> mList;
        private int mInitialHighlight = -1;

        public ResolveListAdapter(Context context, Intent intent,
                Intent[] initialIntents, List<ResolveInfo> rList, int launchedFromUid) {
@@ -436,14 +446,24 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
            if (newItemCount == 0) {
                // We no longer have any items...  just finish the activity.
                finish();
            } else if (newItemCount != oldItemCount) {
                resizeGrid();
            }
        }

        public int getInitialHighlight() {
            return mInitialHighlight;
        }

        private void rebuildList() {
            List<ResolveInfo> currentResolveList;

            try {
                mLastChosen = AppGlobals.getPackageManager().getLastChosenActivity(
                        mIntent, mIntent.resolveTypeIfNeeded(getContentResolver()),
                        PackageManager.MATCH_DEFAULT_ONLY);
            } catch (RemoteException re) {
                Log.d(TAG, "Error calling setLastChosenActivity\n" + re);
            }

            mList.clear();
            if (mBaseResolveList != null) {
                currentResolveList = mBaseResolveList;
@@ -556,6 +576,12 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
            // Process labels from start to i
            int num = end - start+1;
            if (num == 1) {
                if (mLastChosen != null
                        && mLastChosen.activityInfo.packageName.equals(
                                ro.activityInfo.packageName)
                        && mLastChosen.activityInfo.name.equals(ro.activityInfo.name)) {
                    mInitialHighlight = mList.size();
                }
                // No duplicate labels. Use label for entry at start
                mList.add(new DisplayResolveInfo(ro, roLabel, null, null));
            } else {
@@ -585,6 +611,12 @@ public class ResolverActivity extends AlertActivity implements AdapterView.OnIte
                }
                for (int k = start; k <= end; k++) {
                    ResolveInfo add = rList.get(k);
                    if (mLastChosen != null
                            && mLastChosen.activityInfo.packageName.equals(
                                    add.activityInfo.packageName)
                            && mLastChosen.activityInfo.name.equals(add.activityInfo.name)) {
                        mInitialHighlight = mList.size();
                    }
                    if (usePkg) {
                        // Use application name for all entries from start to end-1
                        mList.add(new DisplayResolveInfo(add, roLabel,
+24 −24
Original line number Diff line number Diff line
@@ -18,40 +18,40 @@
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:gravity="center"
              android:orientation="vertical"
              android:orientation="horizontal"
              android:layout_height="wrap_content"
              android:layout_width="match_parent"
              android:background="@android:drawable/activity_picker_bg"
              android:padding="16dp">

    <!-- Extended activity info to distinguish between duplicate activity names -->
    <TextView android:id="@android:id/text2"
              android:textAppearance="?android:attr/textAppearance"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:gravity="center"
              android:minLines="2"
              android:maxLines="2"
              android:paddingStart="4dip"
              android:paddingEnd="4dip" />
              android:background="@android:drawable/activity_picker_bg">

    <!-- Activity icon when presenting dialog
         Size will be filled in by ResolverActivity -->
    <ImageView android:id="@+id/icon"
               android:layout_width="0dp"
               android:layout_height="0dp"
               android:layout_marginStart="12dp"
               android:padding="4dp"
               android:scaleType="fitCenter" />

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:gravity="start|center_vertical"
              android:orientation="vertical"
              android:layout_height="wrap_content"
              android:layout_width="wrap_content"
              android:layout_gravity="start|center_vertical"
              android:layout_marginStart="12dp">
        <!-- Activity name -->
        <TextView android:id="@android:id/text1"
                  android:textAppearance="?android:attr/textAppearanceMedium"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:maxLines="2" />
        <!-- Extended activity info to distinguish between duplicate activity names -->
        <TextView android:id="@android:id/text2"
                  android:textAppearance="?android:attr/textAppearanceSmall"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
              android:gravity="center"
              android:minLines="2"
                  android:maxLines="2"
              android:paddingStart="4dip"
              android:paddingEnd="4dip" />
                  android:paddingTop="4dip" />
    </LinearLayout>
</LinearLayout>
+7 −9
Original line number Diff line number Diff line
@@ -23,20 +23,18 @@
              android:divider="?android:attr/dividerHorizontal"
              android:showDividers="middle"
              android:dividerPadding="0dip">

    <FrameLayout android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1">
        <GridView
            android:layout_gravity="center"
            android:layout_width="wrap_content"

        <ListView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/resolver_grid"
            android:numColumns="4"
            android:columnWidth="128dp"
            android:padding="16dp"
            android:clipToPadding="false"
            android:scrollbarStyle="outsideOverlay" />
            android:id="@+id/resolver_list" />

    </FrameLayout>

    <LinearLayout
        android:id="@+id/button_bar"
        android:visibility="gone"
+2 −2
Original line number Diff line number Diff line
@@ -1526,8 +1526,8 @@
  <java-symbol type="string" name="enable_explore_by_touch_warning_title" />
  <java-symbol type="string" name="enable_explore_by_touch_warning_message" />

  <java-symbol type="layout" name="resolver_grid" />
  <java-symbol type="id" name="resolver_grid" />
  <java-symbol type="layout" name="resolver_list" />
  <java-symbol type="id" name="resolver_list" />
  <java-symbol type="id" name="button_once" />
  <java-symbol type="id" name="button_always" />
  <java-symbol type="integer" name="config_maxResolverActivityColumns" />
Loading