1 /** 2 * Copyright (c) 2011, Google Inc. 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.mail.compose; 18 19 import android.content.Context; 20 import android.util.AttributeSet; 21 import android.view.inputmethod.EditorInfo; 22 import android.view.inputmethod.InputConnection; 23 import android.widget.EditText; 24 25 /** 26 * Allows IME behavior for multiline text fields to be overridden so that 27 * pressing next/enter will take the user to the compose field instead of 28 * creating a newline in this field. 29 */ 30 public class EnterSubject extends EditText { EnterSubject(Context context)31 public EnterSubject(Context context) { 32 super(context); 33 } EnterSubject(Context context, AttributeSet attrs)34 public EnterSubject(Context context, AttributeSet attrs) { 35 super(context, attrs); 36 } EnterSubject(Context context, AttributeSet attrs, int defStyle)37 public EnterSubject(Context context, AttributeSet attrs, int defStyle) { 38 super(context, attrs, defStyle); 39 } 40 41 @Override onCreateInputConnection(EditorInfo outAttrs)42 public InputConnection onCreateInputConnection(EditorInfo outAttrs) { 43 InputConnection connection = super.onCreateInputConnection(outAttrs); 44 int imeActions = outAttrs.imeOptions&EditorInfo.IME_MASK_ACTION; 45 if ((imeActions&EditorInfo.IME_ACTION_NEXT) != 0) { 46 // clear the existing action 47 outAttrs.imeOptions ^= imeActions; 48 // set the DONE action 49 outAttrs.imeOptions |= EditorInfo.IME_ACTION_NEXT; 50 } 51 if ((outAttrs.imeOptions&EditorInfo.IME_FLAG_NO_ENTER_ACTION) != 0) { 52 outAttrs.imeOptions &= ~EditorInfo.IME_FLAG_NO_ENTER_ACTION; 53 } 54 return connection; 55 } 56 } 57