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
This commit is contained in:
@@ -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<String, UsageStats> 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<ResolveInfo> 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<ResolveInfo> rList, int launchedFromUid,
|
||||
boolean filterLastUsed) {
|
||||
mIntent = new Intent(intent);
|
||||
public ResolveListAdapter(Context context, Intent[] initialIntents,
|
||||
List<ResolveInfo> 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();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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" />
|
||||
|
||||
@@ -25,19 +25,56 @@
|
||||
android:maxCollapsedHeightSmall="56dp"
|
||||
android:id="@id/contentPanel">
|
||||
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alwaysShow="true"
|
||||
android:minHeight="56dp"
|
||||
android:textAppearance="?attr/textAppearanceMedium"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingStart="?attr/dialogPreferredPadding"
|
||||
android:paddingEnd="?attr/dialogPreferredPadding"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp"
|
||||
android:background="@color/white"
|
||||
android:elevation="8dp" />
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alwaysShow="true"
|
||||
android:elevation="8dp"
|
||||
android:background="@color/white" >
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:minHeight="56dp"
|
||||
android:textAppearance="?attr/textAppearanceMedium"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingStart="?attr/dialogPreferredPadding"
|
||||
android:paddingEnd="?attr/dialogPreferredPadding"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="8dp" />
|
||||
<LinearLayout android:id="@+id/profile_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:focusable="true"
|
||||
android:visibility="gone"
|
||||
style="?attr/borderlessButtonStyle">
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:scaleType="fitCenter" />
|
||||
<TextView android:id="@id/text1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:textAppearance="?attr/textAppearanceButton"
|
||||
android:textColor="?attr/textColorPrimary"
|
||||
android:minLines="1"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="marquee" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<ListView
|
||||
android:layout_width="match_parent"
|
||||
|
||||
@@ -36,8 +36,7 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="64dp"
|
||||
android:orientation="horizontal"
|
||||
>
|
||||
android:orientation="horizontal" >
|
||||
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
@@ -46,8 +45,7 @@
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
android:layout_marginTop="20dp"
|
||||
android:scaleType="fitCenter"
|
||||
/>
|
||||
android:scaleType="fitCenter" />
|
||||
<TextView android:id="@+id/title"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
@@ -55,8 +53,38 @@
|
||||
android:layout_marginStart="16dp"
|
||||
android:textAppearance="?android:attr/textAppearanceMedium"
|
||||
android:gravity="start|center_vertical"
|
||||
android:paddingEnd="16dp"
|
||||
/>
|
||||
android:paddingEnd="16dp" />
|
||||
<LinearLayout android:id="@+id/profile_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="4dp"
|
||||
android:layout_marginEnd="4dp"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingEnd="8dp"
|
||||
android:paddingTop="4dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:focusable="true"
|
||||
android:visibility="gone"
|
||||
style="?attr/borderlessButtonStyle">
|
||||
<ImageView android:id="@+id/icon"
|
||||
android:layout_width="24dp"
|
||||
android:layout_height="24dp"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginEnd="?attr/listPreferredItemPaddingEnd"
|
||||
android:layout_marginTop="12dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:scaleType="fitCenter" />
|
||||
<TextView android:id="@id/text1"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="start|center_vertical"
|
||||
android:layout_marginEnd="?attr/listPreferredItemPaddingEnd"
|
||||
android:textAppearance="?attr/textAppearanceButton"
|
||||
android:textColor="?attr/textColorPrimary"
|
||||
android:minLines="1"
|
||||
android:maxLines="1"
|
||||
android:ellipsize="marquee" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
||||
@@ -2129,6 +2129,7 @@
|
||||
<java-symbol type="id" name="scrollIndicatorDown" />
|
||||
<java-symbol type="array" name="config_sms_convert_destination_number_support" />
|
||||
<java-symbol type="string" name="prohibit_manual_network_selection_in_gobal_mode" />
|
||||
<java-symbol type="id" name="profile_button" />
|
||||
|
||||
<!-- From SignalStrength -->
|
||||
<java-symbol type="integer" name="config_LTE_RSRP_threshold_type" />
|
||||
|
||||
@@ -551,6 +551,8 @@ easier.
|
||||
<item name="windowDrawsSystemBarBackgrounds">false</item>
|
||||
<item name="windowContentOverlay">@null</item>
|
||||
<item name="colorControlActivated">?attr/colorControlHighlight</item>
|
||||
<item name="listPreferredItemPaddingStart">?attr/dialogPreferredPadding</item>
|
||||
<item name="listPreferredItemPaddingEnd">?attr/dialogPreferredPadding</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user