From 88831a2a6f4c7dd47d6479ba107ce1a8045d3fa5 Mon Sep 17 00:00:00 2001 From: Adam Powell Date: Thu, 20 Nov 2014 18:17:00 -0800 Subject: Make work profile apps easier to pick in ResolverActivity Pull the "Work" profile item up out of the main list and into the header of the resolver drawer, making it easier to discover and access without disrupting the sort order of the list. Bug 17935301 Change-Id: Id2d081b61828352c998e517127132f883a20b7ef --- .../com/android/internal/app/ResolverActivity.java | 100 ++++++++++++++++----- core/res/res/layout/resolve_list_item.xml | 1 - core/res/res/layout/resolver_list.xml | 63 ++++++++++--- core/res/res/layout/resolver_list_with_default.xml | 40 +++++++-- core/res/res/values/symbols.xml | 1 + core/res/res/values/themes_device_defaults.xml | 2 + 6 files changed, 167 insertions(+), 40 deletions(-) diff --git a/core/java/com/android/internal/app/ResolverActivity.java b/core/java/com/android/internal/app/ResolverActivity.java index 2db466aa7889..634d03d9fb1c 100644 --- a/core/java/com/android/internal/app/ResolverActivity.java +++ b/core/java/com/android/internal/app/ResolverActivity.java @@ -95,12 +95,14 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private ListView mListView; private Button mAlwaysButton; private Button mOnceButton; + private View mProfileView; private int mIconDpi; private int mIconSize; private int mMaxColumns; private int mLastSelected = ListView.INVALID_POSITION; private boolean mResolvingHome = false; private int mProfileSwitchMessageId = -1; + private Intent mIntent; private UsageStatsManager mUsm; private Map mStats; @@ -110,6 +112,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private final PackageMonitor mPackageMonitor = new PackageMonitor() { @Override public void onSomePackagesChanged() { mAdapter.handlePackagesChanged(); + if (mProfileView != null) { + bindProfileView(); + } } }; @@ -217,7 +222,6 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic final long sinceTime = System.currentTimeMillis() - USAGE_STATS_PERIOD; mStats = mUsm.queryAndAggregateUsageStats(sinceTime, System.currentTimeMillis()); - Log.d(TAG, "sinceTime=" + sinceTime); mMaxColumns = getResources().getInteger(R.integer.config_maxResolverActivityColumns); @@ -228,7 +232,8 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic mIconDpi = am.getLauncherLargeIconDensity(); mIconSize = am.getLauncherLargeIconSize(); - mAdapter = new ResolveListAdapter(this, intent, initialIntents, rList, + mIntent = new Intent(intent); + mAdapter = new ResolveListAdapter(this, initialIntents, rList, mLaunchedFromUid, alwaysUseOption); final int layoutId; @@ -324,6 +329,40 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic setAlwaysButtonEnabled(true, mAdapter.getFilteredPosition(), false); mOnceButton.setEnabled(true); } + + mProfileView = findViewById(R.id.profile_button); + if (mProfileView != null) { + mProfileView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final DisplayResolveInfo dri = mAdapter.getOtherProfile(); + if (dri == null) { + return; + } + + final Intent intent = intentForDisplayResolveInfo(dri); + onIntentSelected(dri.ri, intent, mAlwaysUseOption); + finish(); + } + }); + bindProfileView(); + } + } + + void bindProfileView() { + final DisplayResolveInfo dri = mAdapter.getOtherProfile(); + if (dri != null) { + mProfileView.setVisibility(View.VISIBLE); + final ImageView icon = (ImageView) mProfileView.findViewById(R.id.icon); + final TextView text = (TextView) mProfileView.findViewById(R.id.text1); + if (dri.displayIcon == null) { + new LoadIconTask().execute(dri); + } + icon.setImageDrawable(dri.displayIcon); + text.setText(dri.displayLabel); + } else { + mProfileView.setVisibility(View.GONE); + } } private void setProfileSwitchMessageId(int contentUserHint) { @@ -416,6 +455,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic mRegistered = true; } mAdapter.handlePackagesChanged(); + if (mProfileView != null) { + bindProfileView(); + } } @Override @@ -702,6 +744,17 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic startActivity(in); } + Intent intentForDisplayResolveInfo(DisplayResolveInfo dri) { + Intent intent = new Intent(dri.origIntent != null ? dri.origIntent : + getReplacementIntent(dri.ri.activityInfo, mIntent)); + intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT + |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); + ActivityInfo ai = dri.ri.activityInfo; + intent.setComponent(new ComponentName( + ai.applicationInfo.packageName, ai.name)); + return intent; + } + private final class DisplayResolveInfo { ResolveInfo ri; CharSequence displayLabel; @@ -722,7 +775,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private final Intent[] mInitialIntents; private final List mBaseResolveList; private ResolveInfo mLastChosen; - private final Intent mIntent; + private DisplayResolveInfo mOtherProfile; private final int mLaunchedFromUid; private final LayoutInflater mInflater; @@ -732,10 +785,8 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic private int mLastChosenPosition = -1; private boolean mFilterLastUsed; - public ResolveListAdapter(Context context, Intent intent, - Intent[] initialIntents, List rList, int launchedFromUid, - boolean filterLastUsed) { - mIntent = new Intent(intent); + public ResolveListAdapter(Context context, Intent[] initialIntents, + List rList, int launchedFromUid, boolean filterLastUsed) { mInitialIntents = initialIntents; mBaseResolveList = rList; mLaunchedFromUid = launchedFromUid; @@ -764,6 +815,10 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic return null; } + public DisplayResolveInfo getOtherProfile() { + return mOtherProfile; + } + public int getFilteredPosition() { if (mFilterLastUsed && mLastChosenPosition >= 0) { return mLastChosenPosition; @@ -870,7 +925,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic ri.nonLocalizedLabel = li.getNonLocalizedLabel(); ri.icon = li.getIconResource(); } - mList.add(new DisplayResolveInfo(ri, + addResolveInfo(new DisplayResolveInfo(ri, ri.loadLabel(getPackageManager()), null, ii)); } } @@ -915,7 +970,7 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic mLastChosenPosition = mList.size(); } // No duplicate labels. Use label for entry at start - mList.add(new DisplayResolveInfo(ro, roLabel, null, null)); + addResolveInfo(new DisplayResolveInfo(ro, roLabel, null, null)); } else { mShowExtended = true; boolean usePkg = false; @@ -951,32 +1006,34 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic } if (usePkg) { // Use application name for all entries from start to end-1 - mList.add(new DisplayResolveInfo(add, roLabel, + addResolveInfo(new DisplayResolveInfo(add, roLabel, add.activityInfo.packageName, null)); } else { // Use package name for all entries from start to end-1 - mList.add(new DisplayResolveInfo(add, roLabel, + addResolveInfo(new DisplayResolveInfo(add, roLabel, add.activityInfo.applicationInfo.loadLabel(mPm), null)); } } } } + private void addResolveInfo(DisplayResolveInfo dri) { + if (dri.ri.targetUserId != UserHandle.USER_CURRENT && mOtherProfile == null) { + // So far we only support a single other profile at a time. + // The first one we see gets special treatment. + mOtherProfile = dri; + } else { + mList.add(dri); + } + } + public ResolveInfo resolveInfoForPosition(int position, boolean filtered) { return (filtered ? getItem(position) : mList.get(position)).ri; } public Intent intentForPosition(int position, boolean filtered) { DisplayResolveInfo dri = filtered ? getItem(position) : mList.get(position); - - Intent intent = new Intent(dri.origIntent != null ? dri.origIntent : - getReplacementIntent(dri.ri.activityInfo, mIntent)); - intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT - |Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP); - ActivityInfo ai = dri.ri.activityInfo; - intent.setComponent(new ComponentName( - ai.applicationInfo.packageName, ai.name)); - return intent; + return intentForDisplayResolveInfo(dri); } public int getCount() { @@ -1067,6 +1124,9 @@ public class ResolverActivity extends Activity implements AdapterView.OnItemClic @Override protected void onPostExecute(DisplayResolveInfo info) { + if (mProfileView != null && mAdapter.getOtherProfile() == info) { + bindProfileView(); + } mAdapter.notifyDataSetChanged(); } } diff --git a/core/res/res/layout/resolve_list_item.xml b/core/res/res/layout/resolve_list_item.xml index 2933a6a67f06..5d5283296f4b 100644 --- a/core/res/res/layout/resolve_list_item.xml +++ b/core/res/res/layout/resolve_list_item.xml @@ -33,7 +33,6 @@ android:layout_height="24dp" android:layout_gravity="start|center_vertical" android:layout_marginStart="?attr/listPreferredItemPaddingStart" - android:layout_marginEnd="?attr/listPreferredItemPaddingEnd" android:layout_marginTop="12dp" android:layout_marginBottom="12dp" android:scaleType="fitCenter" /> diff --git a/core/res/res/layout/resolver_list.xml b/core/res/res/layout/resolver_list.xml index 9ae3aec64900..00c25e65c1b4 100644 --- a/core/res/res/layout/resolver_list.xml +++ b/core/res/res/layout/resolver_list.xml @@ -25,19 +25,56 @@ android:maxCollapsedHeightSmall="56dp" android:id="@id/contentPanel"> - + + + + + + + + android:orientation="horizontal" > + android:scaleType="fitCenter" /> + android:paddingEnd="16dp" /> + + + + + diff --git a/core/res/res/values/themes_device_defaults.xml b/core/res/res/values/themes_device_defaults.xml index 36d711658b65..def8659f7f2e 100644 --- a/core/res/res/values/themes_device_defaults.xml +++ b/core/res/res/values/themes_device_defaults.xml @@ -551,6 +551,8 @@ easier. false @null ?attr/colorControlHighlight + ?attr/dialogPreferredPadding + ?attr/dialogPreferredPadding -- cgit v1.2.3-59-g8ed1b