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.conversationsettings; 17 18 import android.app.AlertDialog; 19 import android.content.ClipData; 20 import android.content.ClipboardManager; 21 import android.content.Context; 22 import android.content.DialogInterface; 23 import android.view.LayoutInflater; 24 import android.view.View; 25 import android.widget.TextView; 26 27 import com.android.messaging.R; 28 import com.android.messaging.util.AccessibilityUtil; 29 30 public class CopyContactDetailDialog implements DialogInterface.OnClickListener { 31 32 private final Context mContext; 33 private final String mContactDetail; 34 CopyContactDetailDialog(final Context context, final String contactDetail)35 public CopyContactDetailDialog(final Context context, final String contactDetail) { 36 mContext = context; 37 mContactDetail = contactDetail; 38 } 39 show()40 public void show() { 41 new AlertDialog.Builder(mContext) 42 .setView(createBodyView()) 43 .setTitle(R.string.copy_to_clipboard_dialog_title) 44 .setPositiveButton(R.string.copy_to_clipboard, this) 45 .show(); 46 } 47 48 @Override onClick(final DialogInterface dialog, final int which)49 public void onClick(final DialogInterface dialog, final int which) { 50 final ClipboardManager clipboard = 51 (ClipboardManager) mContext.getSystemService(Context.CLIPBOARD_SERVICE); 52 clipboard.setPrimaryClip(ClipData.newPlainText(null /* label */, mContactDetail)); 53 } 54 createBodyView()55 private View createBodyView() { 56 LayoutInflater inflater = (LayoutInflater) mContext 57 .getSystemService(Context.LAYOUT_INFLATER_SERVICE); 58 TextView textView = (TextView) inflater.inflate(R.layout.copy_contact_dialog_view, null, 59 false); 60 textView.setText(mContactDetail); 61 final String vocalizedDisplayName = AccessibilityUtil.getVocalizedPhoneNumber( 62 mContext.getResources(), mContactDetail); 63 textView.setContentDescription(vocalizedDisplayName); 64 return textView; 65 } 66 } 67