• 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.Dialog;
20 import android.content.DialogInterface;
21 import android.content.DialogInterface.OnClickListener;
22 import android.os.Bundle;
23 import android.support.annotation.Nullable;
24 import android.support.v4.app.DialogFragment;
25 
26 import androidx.car.app.CarAlertDialog;
27 
28 import com.android.car.settings.R;
29 
30 /**
31  * Dialog to inform that user deletion failed and offers to retry.
32  */
33 public class RemoveUserErrorDialog extends DialogFragment {
34     private DialogInterface.OnClickListener mRemoveUserRetryListener = new OnClickListener() {
35         @Override
36         public void onClick(DialogInterface dialog, int which) {
37             if (mListener != null && which == DialogInterface.BUTTON_POSITIVE) {
38                 mListener.onRetryRemoveUser();
39             }
40             dialog.dismiss();
41         }
42     };
43 
44     private RemoveUserErrorListener mListener;
45 
46     /**
47      * Sets a listener for onRetryRemoveUser that will get called if user presses positive
48      * button.
49      *
50      * @param listener Instance of {@link RemoveUserErrorListener} to call when confirmed.
51      */
setRetryListener(@ullable RemoveUserErrorListener listener)52     public void setRetryListener(@Nullable RemoveUserErrorListener listener) {
53         mListener = listener;
54     }
55 
56     @Override
onCreateDialog(Bundle savedInstanceState)57     public Dialog onCreateDialog(Bundle savedInstanceState) {
58         return new CarAlertDialog.Builder(getContext())
59                 .setTitle(R.string.remove_user_error_title)
60                 .setBody(R.string.remove_user_error_message)
61                 .setPositiveButton(R.string.remove_user_error_retry, mRemoveUserRetryListener)
62                 .setNegativeButton(R.string.remove_user_error_dismiss, null)
63                 .create();
64     }
65 
66     /**
67      * Interface for listeners that want to receive a callback when user removal fails.
68      */
69     public interface RemoveUserErrorListener {
70 
71         /**
72          * Method called only when user presses retry button.
73          */
onRetryRemoveUser()74         void onRetryRemoveUser();
75     }
76 }
77