1 /*
2  * Copyright (C) 2016 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 package com.google.android.car.kitchensink.alertdialog;
17 
18 import android.annotation.Nullable;
19 import android.app.AlertDialog;
20 import android.content.DialogInterface;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.Button;
26 
27 import androidx.fragment.app.Fragment;
28 
29 import com.google.android.car.kitchensink.R;
30 
31 /**
32  * Shows alert dialogs
33  */
34 public class AlertDialogTestFragment extends Fragment {
35 
36     private static final String TAG = "CAR.ALERT";
37 
38     private Button alertMessageBtn;
39     private Button alertBtPinConfirmBtn;
40     private Button alertBtPinEnterBtn;
41 
42 
43     @Nullable
44     @Override
onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState)45     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
46             @Nullable Bundle savedInstanceState) {
47         View view = inflater.inflate(R.layout.alert_dialog_test, container, false);
48 
49         alertMessageBtn = view.findViewById(R.id.alert_message_btn);
50         alertBtPinEnterBtn = view.findViewById(R.id.alert_bluetooth_pin_enter_view_btn);
51         alertBtPinConfirmBtn = view.findViewById(R.id.alert_bluetooth_pin_confirm_view_btn);
52 
53         alertMessageBtn.setOnClickListener(new View.OnClickListener() {
54             @Override
55             public void onClick(View v) {
56                 AlertDialog.Builder builder;
57                 builder = new AlertDialog.Builder(getContext());
58                 builder.setTitle("Alert Title")
59                         .setMessage("Message for Alert dialog window, this part is text only")
60                         .setPositiveButton(
61                                 android.R.string.yes, new DialogInterface.OnClickListener() {
62                             public void onClick(DialogInterface dialog, int which) {
63                                 // do nothing
64                             }
65                         })
66                         .setNegativeButton(
67                                 android.R.string.no, new DialogInterface.OnClickListener() {
68                             public void onClick(DialogInterface dialog, int which) {
69                                 // do nothing
70                             }
71                         })
72                         .setIcon(android.R.drawable.ic_dialog_alert)
73                         .show();
74             }
75         });
76 
77         alertBtPinEnterBtn.setOnClickListener(new View.OnClickListener() {
78             @Override
79             public void onClick(View v) {
80                 AlertDialog.Builder builder;
81                 builder = new AlertDialog.Builder(getContext());
82                 builder.setTitle("Alert Title")
83                         .setView(R.layout.alert_dialog_bluetooth_pin_entry)
84                         .setPositiveButton(
85                                 android.R.string.yes, new DialogInterface.OnClickListener() {
86                                     public void onClick(DialogInterface dialog, int which) {
87                                         // do nothing
88                                     }
89                                 })
90                         .setNegativeButton(
91                                 android.R.string.no, new DialogInterface.OnClickListener() {
92                                     public void onClick(DialogInterface dialog, int which) {
93                                         // do nothing
94                                     }
95                                 })
96                         .setIcon(android.R.drawable.ic_dialog_alert)
97                         .show();
98             }
99         });
100 
101         alertBtPinConfirmBtn.setOnClickListener(new View.OnClickListener() {
102             @Override
103             public void onClick(View v) {
104                 AlertDialog.Builder builder;
105                 builder = new AlertDialog.Builder(getContext());
106                 builder.setTitle("Alert Title")
107                         .setView(R.layout.alert_dialog_bluetooth_pin_confirm)
108                         .setPositiveButton(
109                                 android.R.string.yes, new DialogInterface.OnClickListener() {
110                                     public void onClick(DialogInterface dialog, int which) {
111                                         // do nothing
112                                     }
113                                 })
114                         .setNegativeButton(
115                                 android.R.string.no, new DialogInterface.OnClickListener() {
116                                     public void onClick(DialogInterface dialog, int which) {
117                                         // do nothing
118                                     }
119                                 })
120                         .setIcon(android.R.drawable.ic_dialog_alert)
121                         .show();
122             }
123         });
124         return view;
125     }
126 }
127