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

Commit 1a39660d authored by Chaohui Wang's avatar Chaohui Wang Committed by Android (Google) Code Review
Browse files

Merge "Update Personal / work selection UI." into tm-dev

parents 81ee2037 f2504937
Loading
Loading
Loading
Loading
+32 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<ripple
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:androidprv="http://schemas.android.com/apk/prv/res/android"
    android:color="@color/settingslib_ripple_color">
    <item android:id="@android:id/mask">
        <shape android:shape="rectangle">
            <solid android:color="?androidprv:attr/colorSurface"/>
            <corners android:radius="20dp"/>
        </shape>
    </item>
    <item android:id="@android:id/background">
        <shape android:shape="rectangle">
            <stroke android:color="?androidprv:attr/colorAccentPrimaryVariant" android:width="1dp"/>
            <corners android:radius="20dp"/>
        </shape>
    </item>
</ripple>
+29 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:paddingTop="40dp"
    android:paddingBottom="40dp">

    <com.android.internal.widget.RecyclerView
        android:id="@+id/list"
        android:overScrollMode="never"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"/>
</FrameLayout>
+47 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@android:id/widget_frame"
    android:layout_width="120dp"
    android:layout_height="112dp">

    <FrameLayout
        android:id="@+id/button"
        android:layout_width="82dp"
        android:layout_height="82dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/user_select_background">

        <ImageView
            android:id="@android:id/icon"
            android:layout_width="32dp"
            android:layout_height="32dp"
            android:layout_gravity="center"
            android:scaleType="fitCenter"/>
    </FrameLayout>

    <TextView
        android:id="@android:id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:labelFor="@android:id/icon"
        android:textSize="14sp"
        style="@style/TextAppearance.PreferenceTitle.SettingsLib"/>
</RelativeLayout>
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2022 The Android Open Source Project

     Licensed under the Apache License, Version 2.0 (the "License");
     you may not use this file except in compliance with the License.
     You may obtain a copy of the License at

          http://www.apache.org/licenses/LICENSE-2.0

     Unless required by applicable law or agreed to in writing, software
     distributed under the License is distributed on an "AS IS" BASIS,
     WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     See the License for the specific language governing permissions and
     limitations under the License.
-->
<com.android.internal.widget.DialogTitle
    xmlns:android="http://schemas.android.com/apk/res/android"
    style="?android:attr/windowTitleStyle"
    android:id="@android:id/title"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_gravity="center"
    android:paddingTop="24dp"
    android:ellipsize="end"
    android:singleLine="true"
    android:textAlignment="center"
    android:textSize="24sp"/>
+51 −20
Original line number Diff line number Diff line
@@ -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,6 +62,7 @@ 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 sourceMetricCategory The source metric category.
@@ -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);
    }

    /**
     * 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 builder.create();
        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
Loading