The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2007-2008 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); you may not |
| 5 | * use this file except in compliance with the License. You may obtain a copy of |
| 6 | * 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, WITHOUT |
| 12 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the |
| 13 | * License for the specific language governing permissions and limitations under |
| 14 | * the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.internal.widget; |
| 18 | |
| 19 | import android.os.Bundle; |
satok | adb4358 | 2011-03-09 10:08:47 +0900 | [diff] [blame] | 20 | import android.os.IBinder; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 21 | import android.text.Editable; |
| 22 | import android.text.method.KeyListener; |
| 23 | import android.util.Log; |
| 24 | import android.view.inputmethod.BaseInputConnection; |
| 25 | import android.view.inputmethod.CompletionInfo; |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 26 | import android.view.inputmethod.CorrectionInfo; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 27 | import android.view.inputmethod.ExtractedText; |
| 28 | import android.view.inputmethod.ExtractedTextRequest; |
| 29 | import android.widget.TextView; |
| 30 | |
| 31 | public class EditableInputConnection extends BaseInputConnection { |
| 32 | private static final boolean DEBUG = false; |
| 33 | private static final String TAG = "EditableInputConnection"; |
| 34 | |
| 35 | private final TextView mTextView; |
| 36 | |
| 37 | public EditableInputConnection(TextView textview) { |
Dianne Hackborn | 51bf077 | 2009-03-24 19:11:41 -0700 | [diff] [blame] | 38 | super(textview, true); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 39 | mTextView = textview; |
| 40 | } |
| 41 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 42 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 43 | public Editable getEditable() { |
| 44 | TextView tv = mTextView; |
| 45 | if (tv != null) { |
| 46 | return tv.getEditableText(); |
| 47 | } |
| 48 | return null; |
| 49 | } |
| 50 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 51 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 52 | public boolean beginBatchEdit() { |
| 53 | mTextView.beginBatchEdit(); |
| 54 | return true; |
| 55 | } |
| 56 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 57 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 58 | public boolean endBatchEdit() { |
| 59 | mTextView.endBatchEdit(); |
| 60 | return true; |
| 61 | } |
| 62 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 63 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 64 | public boolean clearMetaKeyStates(int states) { |
| 65 | final Editable content = getEditable(); |
| 66 | if (content == null) return false; |
| 67 | KeyListener kl = mTextView.getKeyListener(); |
| 68 | if (kl != null) { |
| 69 | try { |
| 70 | kl.clearMetaKeyState(mTextView, content, states); |
| 71 | } catch (AbstractMethodError e) { |
| 72 | // This is an old listener that doesn't implement the |
| 73 | // new method. |
| 74 | } |
| 75 | } |
| 76 | return true; |
| 77 | } |
| 78 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 79 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 80 | public boolean commitCompletion(CompletionInfo text) { |
| 81 | if (DEBUG) Log.v(TAG, "commitCompletion " + text); |
| 82 | mTextView.beginBatchEdit(); |
| 83 | mTextView.onCommitCompletion(text); |
| 84 | mTextView.endBatchEdit(); |
| 85 | return true; |
| 86 | } |
| 87 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 88 | /** |
| 89 | * Calls the {@link TextView#onCommitCorrection} method of the associated TextView. |
| 90 | */ |
| 91 | @Override |
| 92 | public boolean commitCorrection(CorrectionInfo correctionInfo) { |
| 93 | if (DEBUG) Log.v(TAG, "commitCorrection" + correctionInfo); |
| 94 | mTextView.beginBatchEdit(); |
| 95 | mTextView.onCommitCorrection(correctionInfo); |
| 96 | mTextView.endBatchEdit(); |
| 97 | return true; |
| 98 | } |
| 99 | |
| 100 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 101 | public boolean performEditorAction(int actionCode) { |
| 102 | if (DEBUG) Log.v(TAG, "performEditorAction " + actionCode); |
| 103 | mTextView.onEditorAction(actionCode); |
| 104 | return true; |
| 105 | } |
| 106 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 107 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 108 | public boolean performContextMenuAction(int id) { |
| 109 | if (DEBUG) Log.v(TAG, "performContextMenuAction " + id); |
| 110 | mTextView.beginBatchEdit(); |
| 111 | mTextView.onTextContextMenuItem(id); |
| 112 | mTextView.endBatchEdit(); |
| 113 | return true; |
| 114 | } |
| 115 | |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 116 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 117 | public ExtractedText getExtractedText(ExtractedTextRequest request, int flags) { |
| 118 | if (mTextView != null) { |
| 119 | ExtractedText et = new ExtractedText(); |
| 120 | if (mTextView.extractText(request, et)) { |
| 121 | if ((flags&GET_EXTRACTED_TEXT_MONITOR) != 0) { |
| 122 | mTextView.setExtracting(request); |
| 123 | } |
| 124 | return et; |
| 125 | } |
| 126 | } |
| 127 | return null; |
| 128 | } |
Gilles Debunne | cf9cf2f | 2010-12-08 17:43:58 -0800 | [diff] [blame] | 129 | |
| 130 | @Override |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 131 | public boolean performPrivateCommand(String action, Bundle data) { |
| 132 | mTextView.onPrivateIMECommand(action, data); |
| 133 | return true; |
| 134 | } |
| 135 | |
| 136 | @Override |
| 137 | public boolean commitText(CharSequence text, int newCursorPosition) { |
| 138 | if (mTextView == null) { |
| 139 | return super.commitText(text, newCursorPosition); |
| 140 | } |
| 141 | |
Gilles Debunne | b7fc63f | 2011-01-27 15:55:29 -0800 | [diff] [blame] | 142 | mTextView.resetErrorChangedFlag(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 143 | boolean success = super.commitText(text, newCursorPosition); |
Gilles Debunne | b7fc63f | 2011-01-27 15:55:29 -0800 | [diff] [blame] | 144 | mTextView.hideErrorIfUnchanged(); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 145 | |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 146 | return success; |
| 147 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 148 | } |