Home | History | Annotate | Download | only in contact
      1 /*
      2  * Copyright (C) 2015 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.messaging.ui.contact;
     17 
     18 import android.app.AlertDialog;
     19 import android.content.Context;
     20 import android.content.DialogInterface;
     21 import android.content.res.Resources;
     22 import android.net.Uri;
     23 import android.view.LayoutInflater;
     24 import android.view.View;
     25 import android.widget.Button;
     26 import android.widget.TextView;
     27 
     28 import com.android.messaging.R;
     29 import com.android.messaging.ui.ContactIconView;
     30 import com.android.messaging.ui.UIIntents;
     31 import com.android.messaging.util.AccessibilityUtil;
     32 
     33 public class AddContactsConfirmationDialog implements DialogInterface.OnClickListener {
     34     private final Context mContext;
     35     private final Uri mAvatarUri;
     36     private final String mNormalizedDestination;
     37 
     38     public AddContactsConfirmationDialog(final Context context, final Uri avatarUri,
     39             final String normalizedDestination) {
     40         mContext = context;
     41         mAvatarUri = avatarUri;
     42         mNormalizedDestination = normalizedDestination;
     43     }
     44 
     45     public void show() {
     46         final int confirmAddContactStringId = R.string.add_contact_confirmation;
     47         final int cancelStringId = android.R.string.cancel;
     48         final AlertDialog alertDialog = new AlertDialog.Builder(mContext)
     49         .setTitle(R.string.add_contact_confirmation_dialog_title)
     50         .setView(createBodyView())
     51         .setPositiveButton(confirmAddContactStringId, this)
     52         .setNegativeButton(cancelStringId, null)
     53         .create();
     54         alertDialog.show();
     55         final Resources resources = mContext.getResources();
     56         final Button cancelButton = alertDialog.getButton(DialogInterface.BUTTON_NEGATIVE);
     57         if (cancelButton != null) {
     58             cancelButton.setTextColor(resources.getColor(R.color.contact_picker_button_text_color));
     59         }
     60         final Button addButton = alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
     61         if (addButton != null) {
     62             addButton.setTextColor(resources.getColor(R.color.contact_picker_button_text_color));
     63         }
     64     }
     65 
     66     @Override
     67     public void onClick(final DialogInterface dialog, final int which) {
     68         UIIntents.get().launchAddContactActivity(mContext, mNormalizedDestination);
     69     }
     70 
     71     private View createBodyView() {
     72         final View view = LayoutInflater.from(mContext).inflate(
     73                 R.layout.add_contacts_confirmation_dialog_body, null);
     74         final ContactIconView iconView = (ContactIconView) view.findViewById(R.id.contact_icon);
     75         iconView.setImageResourceUri(mAvatarUri);
     76         final TextView textView = (TextView) view.findViewById(R.id.participant_name);
     77         textView.setText(mNormalizedDestination);
     78         // Accessibility reason : in case phone numbers are mixed in the display name,
     79         // we need to vocalize it for talkback.
     80         final String vocalizedDisplayName = AccessibilityUtil.getVocalizedPhoneNumber(
     81                 mContext.getResources(), mNormalizedDestination);
     82         textView.setContentDescription(vocalizedDisplayName);
     83         return view;
     84     }
     85 }
     86