1 /*
2  * Copyright (C) 2020 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.settingslib.users;
18 
19 import android.app.AlertDialog;
20 import android.content.Context;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.WindowManager;
24 import android.widget.TextView;
25 
26 import com.android.settingslib.R;
27 
28 /**
29  * Dialog to show when a user creation is in progress.
30  */
31 public class UserCreatingDialog extends AlertDialog {
32 
UserCreatingDialog(Context context)33     public UserCreatingDialog(Context context) {
34         this(context, false);
35     }
36 
UserCreatingDialog(Context context, boolean isGuest)37     public UserCreatingDialog(Context context, boolean isGuest) {
38         // hardcoding theme to be consistent with UserSwitchingDialog's theme
39         // todo replace both to adapt to the device's theme
40         super(context, com.android.internal.R.style.Theme_DeviceDefault_Light_Dialog_Alert);
41 
42         inflateContent(isGuest);
43         getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
44 
45         WindowManager.LayoutParams attrs = getWindow().getAttributes();
46         attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR
47                 | WindowManager.LayoutParams.SYSTEM_FLAG_SHOW_FOR_ALL_USERS;
48         getWindow().setAttributes(attrs);
49     }
50 
inflateContent(boolean isGuest)51     private void inflateContent(boolean isGuest) {
52         // using the same design as UserSwitchingDialog
53         setCancelable(false);
54         View view = LayoutInflater.from(getContext())
55                 .inflate(R.layout.user_creation_progress_dialog, null);
56         String message = getContext().getString(isGuest
57                 ? R.string.creating_new_guest_dialog_message
58                 : R.string.creating_new_user_dialog_message);
59         view.setAccessibilityPaneTitle(message);
60         ((TextView) view.findViewById(R.id.message)).setText(message);
61         setView(view);
62     }
63 
64 }
65