• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.car.settings.users;
18 
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.os.Bundle;
22 
23 import androidx.annotation.VisibleForTesting;
24 import androidx.fragment.app.DialogFragment;
25 import androidx.fragment.app.Fragment;
26 
27 import com.android.car.settings.R;
28 
29 /**
30  * Dialog to inform that user deletion failed and offers to retry.
31  */
32 public class MaxUsersLimitReachedDialog extends DialogFragment {
33     @VisibleForTesting
34     static final String DIALOG_TAG = "MaxUsersLimitReachedDialog";
35     private final int mMaxUserLimit;
36 
MaxUsersLimitReachedDialog(int maxUserLimit)37     public MaxUsersLimitReachedDialog(int maxUserLimit) {
38         super();
39         mMaxUserLimit = maxUserLimit;
40     }
41 
42     /**
43      * Shows the dialog.
44      *
45      * @param parent Fragment associated with the dialog.
46      */
show(Fragment parent)47     public void show(Fragment parent) {
48         setTargetFragment(parent, 0);
49         show(parent.getFragmentManager(), DIALOG_TAG);
50     }
51 
52     @Override
onCreateDialog(Bundle savedInstanceState)53     public Dialog onCreateDialog(Bundle savedInstanceState) {
54         return new AlertDialog.Builder(getContext())
55                 .setTitle(R.string.user_limit_reached_title)
56                 .setMessage(getResources().getQuantityString(
57                         R.plurals.user_limit_reached_message, mMaxUserLimit, mMaxUserLimit))
58                 .setPositiveButton(android.R.string.ok, null)
59                 .create();
60     }
61 }
62