1 /*
2  * Copyright (C) 2011 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.cts.verifier.nfc;
18 
19 import com.android.cts.verifier.R;
20 
21 import android.app.AlertDialog;
22 import android.content.Context;
23 import android.content.DialogInterface;
24 import android.content.Intent;
25 import android.provider.Settings;
26 
27 /** Class containing methods to create common dialogs for NFC activities. */
28 public class NfcDialogs {
29 
createNotEnabledDialog(final Context context)30     static AlertDialog createNotEnabledDialog(final Context context) {
31         return new AlertDialog.Builder(context)
32                 .setIcon(android.R.drawable.ic_dialog_alert)
33                 .setTitle(R.string.nfc_not_enabled)
34                 .setMessage(R.string.nfc_not_enabled_message)
35                 .setPositiveButton(R.string.nfc_settings, new DialogInterface.OnClickListener() {
36                     @Override
37                     public void onClick(DialogInterface dialog, int which) {
38                         Intent intent = new Intent(Settings.ACTION_NFC_SETTINGS);
39                         context.startActivity(intent);
40                     }
41                 })
42                 .create();
43     }
44 
45     static AlertDialog createNdefPushNotEnabledDialog(final Context context) {
46         return new AlertDialog.Builder(context)
47                 .setIcon(android.R.drawable.ic_dialog_alert)
48                 .setTitle(R.string.ndef_push_not_enabled)
49                 .setMessage(R.string.ndef_push_not_enabled_message)
50                 .setPositiveButton(R.string.ndef_push_settings, new DialogInterface.OnClickListener() {
51                     @Override
52                     public void onClick(DialogInterface dialog, int which) {
53                         Intent intent = new Intent(Settings.ACTION_NFCSHARING_SETTINGS);
54                         context.startActivity(intent);
55                     }
56                 })
57                 .create();
58     }
59 
60     public static AlertDialog createHceTapReaderDialog(final Context context, String message) {
61         String baseString = context.getString(R.string.nfc_hce_tap_reader_message);
62         return new AlertDialog.Builder(context)
63                 .setIcon(android.R.drawable.ic_dialog_alert)
64                 .setTitle(R.string.nfc_hce_tap_reader_title)
65                 .setMessage(message != null ? message + "\n\n" + baseString : baseString)
66                 .setPositiveButton("OK", null)
67                 .create();
68     }
69 
70     public static AlertDialog createChangeForegroundDialog(final Context context) {
71         return new AlertDialog.Builder(context)
72                 .setIcon(android.R.drawable.ic_dialog_alert)
73                 .setTitle(R.string.nfc_hce_tap_reader_title)
74                 .setMessage(context.getString(R.string.nfc_hce_change_favor_foreground))
75                 .setPositiveButton("OK", new DialogInterface.OnClickListener() {
76                     @Override
77                     public void onClick(DialogInterface dialog, int which) {
78                         Intent intent = new Intent(Settings.ACTION_NFC_PAYMENT_SETTINGS);
79                         context.startActivity(intent);
80                     }
81                 })
82                 .create();
83     }
84 
85     private NfcDialogs() {
86     }
87 }
88