• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.android.settings.support;
17 
18 import android.app.Activity;
19 import android.app.AlertDialog;
20 import android.app.Dialog;
21 import android.app.DialogFragment;
22 import android.content.Intent;
23 import android.os.Bundle;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.widget.TextView;
27 
28 import com.android.internal.logging.MetricsLogger;
29 import com.android.internal.logging.MetricsProto;
30 import com.android.settings.R;
31 
32 import java.util.Locale;
33 
34 /**
35  * A dialog fragment that displays support phone numbers.
36  */
37 public final class SupportPhoneDialogFragment extends DialogFragment implements
38         View.OnClickListener {
39 
40     public static final String TAG = "SupportPhoneDialog";
41     private static final String EXTRA_PHONE = "extra_phone";
42 
newInstance(SupportPhone phone)43     public static SupportPhoneDialogFragment newInstance(SupportPhone phone) {
44         final SupportPhoneDialogFragment fragment = new SupportPhoneDialogFragment();
45         final Bundle bundle = new Bundle(2);
46         bundle.putParcelable(EXTRA_PHONE, phone);
47         fragment.setArguments(bundle);
48         return fragment;
49     }
50 
51     @Override
onCreateDialog(Bundle savedInstanceState)52     public Dialog onCreateDialog(Bundle savedInstanceState) {
53         final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
54         final AlertDialog.Builder builder = new AlertDialog.Builder(getActivity())
55                 .setTitle(R.string.support_international_phone_title);
56         final View content = LayoutInflater.from(builder.getContext())
57                 .inflate(R.layout.support_phone_dialog_content, null);
58         final View phoneNumberContainer = content.findViewById(R.id.phone_number_container);
59         final TextView phoneView = (TextView) content.findViewById(R.id.phone_number);
60         final String formattedPhoneNumber = getContext().getString(
61                 R.string.support_phone_international_format,
62                 new Locale(phone.language).getDisplayLanguage(), phone.number);
63         phoneView.setText(formattedPhoneNumber);
64         phoneNumberContainer.setOnClickListener(this);
65         return builder
66                 .setView(content)
67                 .create();
68     }
69 
70     @Override
onClick(View v)71     public void onClick(View v) {
72         final SupportPhone phone = getArguments().getParcelable(EXTRA_PHONE);
73         final Activity activity = getActivity();
74         final Intent intent = phone.getDialIntent();
75         final boolean canDial = !activity.getPackageManager()
76                 .queryIntentActivities(intent, 0)
77                 .isEmpty();
78         if (canDial) {
79             MetricsLogger.action(getActivity(),
80                     MetricsProto.MetricsEvent.ACTION_SUPPORT_DIAL_TOLLED);
81             getActivity().startActivity(intent);
82         }
83         dismiss();
84     }
85 }
86