diff --git a/core/java/android/inputmethodservice/CompactExtractEditLayout.java b/core/java/android/inputmethodservice/CompactExtractEditLayout.java new file mode 100644 index 0000000000000..f994c65f69359 --- /dev/null +++ b/core/java/android/inputmethodservice/CompactExtractEditLayout.java @@ -0,0 +1,103 @@ +package android.inputmethodservice; + +import android.content.Context; +import android.content.res.Resources; +import android.annotation.FractionRes; +import android.util.AttributeSet; +import android.util.DisplayMetrics; +import android.view.Gravity; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; + +/** + * A special purpose layout for the editor extract view for tiny (sub 250dp) screens. + * The layout is based on sizes proportional to screen pixel size to provide for the + * best layout fidelity on varying pixel sizes and densities. + * + * @hide + */ +public class CompactExtractEditLayout extends LinearLayout { + private View mInputExtractEditText; + private View mInputExtractAccessories; + private View mInputExtractAction; + private boolean mPerformLayoutChanges; + + public CompactExtractEditLayout(Context context) { + super(context); + } + + public CompactExtractEditLayout(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public CompactExtractEditLayout(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + @Override + protected void onFinishInflate() { + super.onFinishInflate(); + mInputExtractEditText = findViewById(com.android.internal.R.id.inputExtractEditText); + mInputExtractAccessories = findViewById(com.android.internal.R.id.inputExtractAccessories); + mInputExtractAction = findViewById(com.android.internal.R.id.inputExtractAction); + + if (mInputExtractEditText != null && mInputExtractAccessories != null + && mInputExtractAction != null) { + mPerformLayoutChanges = true; + } + } + + private int applyFractionInt(@FractionRes int fraction, int whole) { + return Math.round(getResources().getFraction(fraction, whole, whole)); + } + + private static void setLayoutHeight(View v, int px) { + ViewGroup.LayoutParams lp = v.getLayoutParams(); + lp.height = px; + v.setLayoutParams(lp); + } + + private static void setLayoutMarginBottom(View v, int px) { + ViewGroup.MarginLayoutParams lp = (MarginLayoutParams) v.getLayoutParams(); + lp.bottomMargin = px; + v.setLayoutParams(lp); + } + + private void applyProportionalLayout(int screenWidthPx, int screenHeightPx) { + if (getResources().getConfiguration().isScreenRound()) { + setGravity(Gravity.BOTTOM); + } + setLayoutHeight(this, applyFractionInt( + com.android.internal.R.fraction.input_extract_layout_height, screenHeightPx)); + + setPadding( + applyFractionInt(com.android.internal.R.fraction.input_extract_layout_padding_left, + screenWidthPx), + 0, + applyFractionInt(com.android.internal.R.fraction.input_extract_layout_padding_right, + screenWidthPx), + 0); + + setLayoutMarginBottom(mInputExtractEditText, + applyFractionInt(com.android.internal.R.fraction.input_extract_text_margin_bottom, + screenHeightPx)); + + setLayoutMarginBottom(mInputExtractAccessories, + applyFractionInt(com.android.internal.R.fraction.input_extract_action_margin_bottom, + screenHeightPx)); + } + + @Override + protected void onAttachedToWindow() { + super.onAttachedToWindow(); + if (mPerformLayoutChanges) { + Resources res = getResources(); + DisplayMetrics dm = res.getDisplayMetrics(); + int heightPixels = dm.heightPixels; + int widthPixels = dm.widthPixels; + applyProportionalLayout(widthPixels, heightPixels); + } + } +} + diff --git a/core/java/android/inputmethodservice/InputMethodService.java b/core/java/android/inputmethodservice/InputMethodService.java index cc201bc78bb59..085b97cc0f6d4 100644 --- a/core/java/android/inputmethodservice/InputMethodService.java +++ b/core/java/android/inputmethodservice/InputMethodService.java @@ -68,9 +68,10 @@ import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputMethod; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodSubtype; -import android.widget.Button; import android.widget.FrameLayout; +import android.widget.ImageButton; import android.widget.LinearLayout; +import android.widget.TextView; import java.io.FileDescriptor; import java.io.PrintWriter; @@ -302,7 +303,7 @@ public class InputMethodService extends AbstractInputMethodService { boolean mExtractViewHidden; ExtractEditText mExtractEditText; ViewGroup mExtractAccessories; - Button mExtractAction; + View mExtractAction; ExtractedText mExtractedText; int mExtractedToken; @@ -1344,7 +1345,7 @@ public class InputMethodService extends AbstractInputMethodService { mExtractEditText = (ExtractEditText)view.findViewById( com.android.internal.R.id.inputExtractEditText); mExtractEditText.setIME(this); - mExtractAction = (Button)view.findViewById( + mExtractAction = view.findViewById( com.android.internal.R.id.inputExtractAction); if (mExtractAction != null) { mExtractAccessories = (ViewGroup)view.findViewById( @@ -2408,7 +2409,35 @@ public class InputMethodService extends AbstractInputMethodService { return getText(com.android.internal.R.string.ime_action_default); } } - + + /** + * Return a drawable resource id that can be used as a button icon for the given + * {@link EditorInfo#imeOptions EditorInfo.imeOptions}. + * + * @param imeOptions The value from @link EditorInfo#imeOptions EditorInfo.imeOptions}. + * + * @return Returns a drawable resource id to use. + */ + @DrawableRes + private int getIconForImeAction(int imeOptions) { + switch (imeOptions&EditorInfo.IME_MASK_ACTION) { + case EditorInfo.IME_ACTION_GO: + return com.android.internal.R.drawable.ic_input_extract_action_go; + case EditorInfo.IME_ACTION_SEARCH: + return com.android.internal.R.drawable.ic_input_extract_action_search; + case EditorInfo.IME_ACTION_SEND: + return com.android.internal.R.drawable.ic_input_extract_action_send; + case EditorInfo.IME_ACTION_NEXT: + return com.android.internal.R.drawable.ic_input_extract_action_next; + case EditorInfo.IME_ACTION_DONE: + return com.android.internal.R.drawable.ic_input_extract_action_done; + case EditorInfo.IME_ACTION_PREVIOUS: + return com.android.internal.R.drawable.ic_input_extract_action_previous; + default: + return com.android.internal.R.drawable.ic_input_extract_action_return; + } + } + /** * Called when the fullscreen-mode extracting editor info has changed, * to determine whether the extracting (extract text and candidates) portion @@ -2459,10 +2488,20 @@ public class InputMethodService extends AbstractInputMethodService { if (hasAction) { mExtractAccessories.setVisibility(View.VISIBLE); if (mExtractAction != null) { - if (ei.actionLabel != null) { - mExtractAction.setText(ei.actionLabel); + if (mExtractAction instanceof ImageButton) { + ((ImageButton) mExtractAction) + .setImageResource(getIconForImeAction(ei.imeOptions)); + if (ei.actionLabel != null) { + mExtractAction.setContentDescription(ei.actionLabel); + } else { + mExtractAction.setContentDescription(getTextForImeAction(ei.imeOptions)); + } } else { - mExtractAction.setText(getTextForImeAction(ei.imeOptions)); + if (ei.actionLabel != null) { + ((TextView) mExtractAction).setText(ei.actionLabel); + } else { + ((TextView) mExtractAction).setText(getTextForImeAction(ei.imeOptions)); + } } mExtractAction.setOnClickListener(mActionClickListener); } diff --git a/core/res/res/drawable/ic_input_extract_action_done.xml b/core/res/res/drawable/ic_input_extract_action_done.xml new file mode 100644 index 0000000000000..a0ebf92d14eaa --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_done.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_go.xml b/core/res/res/drawable/ic_input_extract_action_go.xml new file mode 100644 index 0000000000000..c24f5a0141cf0 --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_go.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_next.xml b/core/res/res/drawable/ic_input_extract_action_next.xml new file mode 100644 index 0000000000000..fa0b178974227 --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_next.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_previous.xml b/core/res/res/drawable/ic_input_extract_action_previous.xml new file mode 100644 index 0000000000000..5e1823c75509d --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_previous.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_return.xml b/core/res/res/drawable/ic_input_extract_action_return.xml new file mode 100644 index 0000000000000..c46a4a2082f8a --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_return.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_search.xml b/core/res/res/drawable/ic_input_extract_action_search.xml new file mode 100644 index 0000000000000..fd1dceafc7da8 --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_search.xml @@ -0,0 +1,4 @@ + + + diff --git a/core/res/res/drawable/ic_input_extract_action_send.xml b/core/res/res/drawable/ic_input_extract_action_send.xml new file mode 100644 index 0000000000000..0f3754bcf21ee --- /dev/null +++ b/core/res/res/drawable/ic_input_extract_action_send.xml @@ -0,0 +1,9 @@ + + + diff --git a/core/res/res/drawable/input_extract_action_bg_material_dark.xml b/core/res/res/drawable/input_extract_action_bg_material_dark.xml new file mode 100644 index 0000000000000..2457bb9f50541 --- /dev/null +++ b/core/res/res/drawable/input_extract_action_bg_material_dark.xml @@ -0,0 +1,6 @@ + + + + + diff --git a/core/res/res/drawable/input_extract_action_bg_normal_material_dark.xml b/core/res/res/drawable/input_extract_action_bg_normal_material_dark.xml new file mode 100644 index 0000000000000..9e3625377b27d --- /dev/null +++ b/core/res/res/drawable/input_extract_action_bg_normal_material_dark.xml @@ -0,0 +1,4 @@ + + + + diff --git a/core/res/res/drawable/input_extract_action_bg_pressed_material_dark.xml b/core/res/res/drawable/input_extract_action_bg_pressed_material_dark.xml new file mode 100644 index 0000000000000..2328ce3312ef1 --- /dev/null +++ b/core/res/res/drawable/input_extract_action_bg_pressed_material_dark.xml @@ -0,0 +1,4 @@ + + + + diff --git a/core/res/res/layout-watch/input_method_extract_view.xml b/core/res/res/layout-watch/input_method_extract_view.xml new file mode 100644 index 0000000000000..cd921f108d03b --- /dev/null +++ b/core/res/res/layout-watch/input_method_extract_view.xml @@ -0,0 +1,41 @@ + + + + + + + + + + diff --git a/core/res/res/values-round-watch/dimens.xml b/core/res/res/values-round-watch/dimens.xml new file mode 100644 index 0000000000000..f4b250cfc447b --- /dev/null +++ b/core/res/res/values-round-watch/dimens.xml @@ -0,0 +1,30 @@ + + + + + 25.2% + 7.5% + @fraction/input_extract_layout_padding_right + 21.4% + 5.5% + 2.1% + 32dp + 32dp + diff --git a/core/res/res/values-w170dp-notround-watch/dimens.xml b/core/res/res/values-w170dp-notround-watch/dimens.xml new file mode 100644 index 0000000000000..9f30ac1806df6 --- /dev/null +++ b/core/res/res/values-w170dp-notround-watch/dimens.xml @@ -0,0 +1,23 @@ + + + + + 7.5% + diff --git a/core/res/res/values-watch/dimens.xml b/core/res/res/values-watch/dimens.xml new file mode 100644 index 0000000000000..f79a0a5c0a3fc --- /dev/null +++ b/core/res/res/values-watch/dimens.xml @@ -0,0 +1,30 @@ + + + + + 17.5% + 3.6% + @fraction/input_extract_layout_padding_right + 2.5% + 0% + 0% + 24dp + 24dp + diff --git a/core/res/res/values-watch/themes.xml b/core/res/res/values-watch/themes.xml index 756a94b4185ca..6d6065f68ed4f 100644 --- a/core/res/res/values-watch/themes.xml +++ b/core/res/res/values-watch/themes.xml @@ -18,6 +18,7 @@ + +