blob: 8a29f7225a2379e3e0dcfdb16b722c5b363726b4 [file] [log] [blame]
Dmitri Plotnikovde3eec22011-01-17 18:23:37 -08001/*
2 * Copyright (C) 2010 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
17package com.android.calculator2;
18
19import android.content.ClipData;
20import android.content.ClipboardManager;
21import android.content.Context;
22import android.text.Editable;
23import android.text.TextUtils;
24import android.util.AttributeSet;
25import android.widget.EditText;
26import android.widget.Toast;
27
28public class CalculatorEditText extends EditText {
29
30 public CalculatorEditText(Context context, AttributeSet attrs) {
31 super(context, attrs);
32 }
33
34 @Override
35 public boolean performLongClick() {
36 Editable text = getText();
37 if (TextUtils.isEmpty(text)) {
38 return false;
39 }
40
41 setSelection(0, text.length());
42 ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(
43 Context.CLIPBOARD_SERVICE);
44 clipboard.setPrimaryClip(ClipData.newPlainText(null, null, getText()));
45 Toast.makeText(getContext(), R.string.text_copied_toast, Toast.LENGTH_SHORT).show();
46 return true;
47 }
48}