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 */
16package com.android.messaging.ui.conversationsettings;
17
18import android.app.AlertDialog;
19import android.content.ClipData;
20import android.content.ClipboardManager;
21import android.content.Context;
22import android.content.DialogInterface;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.widget.TextView;
26
27import com.android.messaging.R;
28import com.android.messaging.util.AccessibilityUtil;
29
30public class CopyContactDetailDialog implements DialogInterface.OnClickListener {
31
32    private final Context mContext;
33    private final String mContactDetail;
34
35    public CopyContactDetailDialog(final Context context, final String contactDetail) {
36        mContext = context;
37        mContactDetail = contactDetail;
38    }
39
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
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
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