Update Personal / work selection UI.
Implement the new-look by using AlertDialog's custom title and custom view. Using the RecyclerView so we can display profile horizontally. Bug: 174626616 Test: manual & robolectric Change-Id: I9f5a7685d9217fc62e01799ad73f9b9a3ddbf19a
This commit is contained in:
@@ -20,7 +20,6 @@ import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.DialogInterface.OnCancelListener;
|
||||
import android.content.DialogInterface.OnClickListener;
|
||||
import android.content.DialogInterface.OnDismissListener;
|
||||
import android.content.DialogInterface.OnShowListener;
|
||||
import android.content.Intent;
|
||||
@@ -28,17 +27,27 @@ import android.os.Bundle;
|
||||
import android.os.UserHandle;
|
||||
import android.os.UserManager;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.fragment.app.DialogFragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
|
||||
import com.android.internal.widget.DialogTitle;
|
||||
import com.android.internal.widget.LinearLayoutManager;
|
||||
import com.android.internal.widget.RecyclerView;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.overlay.FeatureFactory;
|
||||
import com.android.settingslib.drawer.Tile;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class ProfileSelectDialog extends DialogFragment implements OnClickListener {
|
||||
/**
|
||||
* A {@link DialogFragment} that can select one of the different profiles.
|
||||
*/
|
||||
public class ProfileSelectDialog extends DialogFragment implements UserAdapter.OnClickListener {
|
||||
|
||||
private static final String TAG = "ProfileSelectDialog";
|
||||
private static final String ARG_SELECTED_TILE = "selectedTile";
|
||||
@@ -53,12 +62,13 @@ public class ProfileSelectDialog extends DialogFragment implements OnClickListen
|
||||
|
||||
/**
|
||||
* Display the profile select dialog, adding the fragment to the given FragmentManager.
|
||||
* @param manager The FragmentManager this fragment will be added to.
|
||||
* @param tile The tile for this fragment.
|
||||
*
|
||||
* @param manager The FragmentManager this fragment will be added to.
|
||||
* @param tile The tile for this fragment.
|
||||
* @param sourceMetricCategory The source metric category.
|
||||
* @param onShowListener The listener listens to the dialog showing event.
|
||||
* @param onDismissListener The listener listens to the dialog dismissing event.
|
||||
* @param onCancelListener The listener listens to the dialog cancelling event.
|
||||
* @param onShowListener The listener listens to the dialog showing event.
|
||||
* @param onDismissListener The listener listens to the dialog dismissing event.
|
||||
* @param onCancelListener The listener listens to the dialog cancelling event.
|
||||
*/
|
||||
public static void show(FragmentManager manager, Tile tile, int sourceMetricCategory,
|
||||
OnShowListener onShowListener, OnDismissListener onDismissListener,
|
||||
@@ -77,32 +87,53 @@ public class ProfileSelectDialog extends DialogFragment implements OnClickListen
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mSelectedTile = getArguments().getParcelable(ARG_SELECTED_TILE);
|
||||
mSourceMetricCategory = getArguments().getInt(ARG_SOURCE_METRIC_CATEGORY);
|
||||
Bundle arguments = requireArguments();
|
||||
mSelectedTile = arguments.getParcelable(ARG_SELECTED_TILE, Tile.class);
|
||||
mSourceMetricCategory = arguments.getInt(ARG_SOURCE_METRIC_CATEGORY);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
||||
final Context context = getActivity();
|
||||
final AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||
final UserAdapter adapter = UserAdapter.createUserAdapter(UserManager.get(context), context,
|
||||
mSelectedTile.userHandle);
|
||||
builder.setTitle(com.android.settingslib.R.string.choose_profile)
|
||||
.setAdapter(adapter, this);
|
||||
return createDialog(getContext(), mSelectedTile.userHandle, this);
|
||||
}
|
||||
|
||||
return builder.create();
|
||||
/**
|
||||
* Creates the profile select dialog.
|
||||
*/
|
||||
public static Dialog createDialog(Context context, List<UserHandle> userProfiles,
|
||||
UserAdapter.OnClickListener onClickListener) {
|
||||
LayoutInflater layoutInflater = context.getSystemService(LayoutInflater.class);
|
||||
|
||||
DialogTitle titleView =
|
||||
(DialogTitle) layoutInflater.inflate(R.layout.user_select_title, null);
|
||||
titleView.setText(com.android.settingslib.R.string.choose_profile);
|
||||
|
||||
View contentView = layoutInflater.inflate(R.layout.user_select, null);
|
||||
|
||||
RecyclerView listView = contentView.findViewById(R.id.list);
|
||||
listView.setAdapter(
|
||||
UserAdapter.createUserRecycleViewAdapter(context, userProfiles, onClickListener));
|
||||
listView.setLayoutManager(
|
||||
new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
|
||||
|
||||
return new AlertDialog.Builder(context)
|
||||
.setCustomTitle(titleView)
|
||||
.setView(contentView)
|
||||
.create();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
final UserHandle user = mSelectedTile.userHandle.get(which);
|
||||
public void onClick(int position) {
|
||||
final UserHandle user = mSelectedTile.userHandle.get(position);
|
||||
// Show menu on top level items.
|
||||
final Intent intent = new Intent(mSelectedTile.getIntent());
|
||||
FeatureFactory.getFactory(getContext()).getMetricsFeatureProvider()
|
||||
.logStartedIntentWithProfile(intent, mSourceMetricCategory,
|
||||
which == 1 /* isWorkProfile */);
|
||||
position == 1 /* isWorkProfile */);
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
getActivity().startActivityAsUser(intent, user);
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
Reference in New Issue
Block a user