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

Commit a22dd334 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Xiaohui Chen
Browse files

Make user deletion dialog reusable.

This change will be immediately integrated into master.

This dialog will be also used by the alternate lock screen.

Bug: 25192625
Change-Id: Idc374312fe884af104e342d58f207e0510b9754a
(cherry picked from commit b29374806c393a06c993e5c6b92c62f06d5978c7)
parent 84867864
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -897,10 +897,10 @@
    <!-- Message for add user confirmation dialog - short version. [CHAR LIMIT=none] -->
    <string name="user_add_user_message_short" msgid="1511354412249044381">When you add a new user, that person needs to set up their space.\n\nAny user can update apps for all other users. </string>

    <!-- Title of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] -->
    <!-- Title of the confirmation dialog for deleting a user [CHAR LIMIT=NONE] -->
    <string name="user_remove_user_title">Remove user?</string>

    <!-- Message of the confirmation dialog when exiting guest session [CHAR LIMIT=NONE] -->
    <!-- Message of the confirmation dialog for deleting a user [CHAR LIMIT=NONE] -->
    <string name="user_remove_user_message">All apps and data of this user will be deleted.</string>

    <!-- Label for button in confirmation dialog when exiting guest session [CHAR LIMIT=35] -->
+62 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 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.
 */

package com.android.systemui.statusbar;

import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.UserSwitcherController;
import android.content.Context;
import android.content.DialogInterface;

import com.android.systemui.R;

public class UserUtil {
    public static void deleteUserWithPrompt(Context context, int userId,
                                            UserSwitcherController userSwitcherController) {
        new RemoveUserDialog(context, userId, userSwitcherController).show();
    }

    private final static class RemoveUserDialog extends SystemUIDialog implements
            DialogInterface.OnClickListener {

        private final int mUserId;
        private final UserSwitcherController mUserSwitcherController;

        public RemoveUserDialog(Context context, int userId,
                                UserSwitcherController userSwitcherController) {
            super(context);
            setTitle(R.string.user_remove_user_title);
            setMessage(context.getString(R.string.user_remove_user_message));
            setButton(DialogInterface.BUTTON_NEGATIVE,
                    context.getString(android.R.string.cancel), this);
            setButton(DialogInterface.BUTTON_POSITIVE,
                    context.getString(R.string.user_remove_user_remove), this);
            setCanceledOnTouchOutside(false);
            mUserId = userId;
            mUserSwitcherController = userSwitcherController;
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == BUTTON_NEGATIVE) {
                cancel();
            } else {
                dismiss();
                mUserSwitcherController.removeUserId(mUserId);
            }
        }
    }
}
+3 −31
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.systemui.statusbar.car;

import android.content.Context;
import android.content.DialogInterface;
import android.os.UserHandle;
import android.util.AttributeSet;
import android.view.LayoutInflater;
@@ -29,8 +28,8 @@ import android.widget.ImageView;
import android.widget.TextView;

import com.android.systemui.R;
import com.android.systemui.statusbar.UserUtil;
import com.android.systemui.statusbar.phone.PhoneStatusBar;
import com.android.systemui.statusbar.phone.SystemUIDialog;
import com.android.systemui.statusbar.policy.UserSwitcherController;

public class UserGridView extends GridView {
@@ -88,7 +87,8 @@ public class UserGridView extends GridView {
                    return true;
                }

                new RemoveUserDialog(getContext(), record.info.id).show();
                UserUtil.deleteUserWithPrompt(getContext(), record.info.id,
                        mUserSwitcherController);
                return true;
            }
        });
@@ -159,32 +159,4 @@ public class UserGridView extends GridView {
            return convertView;
        }
    }

    private final class RemoveUserDialog extends SystemUIDialog implements
            DialogInterface.OnClickListener {

        private final int mUserId;

        public RemoveUserDialog(Context context, int userId) {
            super(context);
            setTitle(R.string.user_remove_user_title);
            setMessage(context.getString(R.string.user_remove_user_message));
            setButton(DialogInterface.BUTTON_NEGATIVE,
                    context.getString(android.R.string.cancel), this);
            setButton(DialogInterface.BUTTON_POSITIVE,
                    context.getString(R.string.user_remove_user_remove), this);
            setCanceledOnTouchOutside(false);
            mUserId = userId;
        }

        @Override
        public void onClick(DialogInterface dialog, int which) {
            if (which == BUTTON_NEGATIVE) {
                cancel();
            } else {
                dismiss();
                mUserSwitcherController.removeUserId(mUserId);
            }
        }
    }
}