Dmitri Plotnikov | de3eec2 | 2011-01-17 18:23:37 -0800 | [diff] [blame^] | 1 | /* |
| 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 | |
| 17 | package com.android.calculator2; |
| 18 | |
| 19 | import android.content.ClipData; |
| 20 | import android.content.ClipboardManager; |
| 21 | import android.content.Context; |
| 22 | import android.text.Editable; |
| 23 | import android.text.TextUtils; |
| 24 | import android.util.AttributeSet; |
| 25 | import android.widget.EditText; |
| 26 | import android.widget.Toast; |
| 27 | |
| 28 | public 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 | } |