Loading core/java/android/inputmethodservice/CompactExtractEditLayout.java 0 → 100644 +103 −0 Original line number Diff line number Diff line 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); } } } core/java/android/inputmethodservice/InputMethodService.java +46 −7 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -302,7 +303,7 @@ public class InputMethodService extends AbstractInputMethodService { boolean mExtractViewHidden; ExtractEditText mExtractEditText; ViewGroup mExtractAccessories; Button mExtractAction; View mExtractAction; ExtractedText mExtractedText; int mExtractedToken; Loading Loading @@ -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( Loading Loading @@ -2409,6 +2410,34 @@ public class InputMethodService extends AbstractInputMethodService { } } /** * 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 Loading Loading @@ -2459,10 +2488,20 @@ public class InputMethodService extends AbstractInputMethodService { if (hasAction) { mExtractAccessories.setVisibility(View.VISIBLE); if (mExtractAction != null) { if (mExtractAction instanceof ImageButton) { ((ImageButton) mExtractAction) .setImageResource(getIconForImeAction(ei.imeOptions)); if (ei.actionLabel != null) { mExtractAction.setText(ei.actionLabel); mExtractAction.setContentDescription(ei.actionLabel); } else { mExtractAction.setText(getTextForImeAction(ei.imeOptions)); mExtractAction.setContentDescription(getTextForImeAction(ei.imeOptions)); } } else { if (ei.actionLabel != null) { ((TextView) mExtractAction).setText(ei.actionLabel); } else { ((TextView) mExtractAction).setText(getTextForImeAction(ei.imeOptions)); } } mExtractAction.setOnClickListener(mActionClickListener); } Loading core/res/res/drawable/ic_input_extract_action_done.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M18,32.34L9.66,24l-2.83,2.83L18,38l24,-24 -2.83,-2.83z"/> </vector> core/res/res/drawable/ic_input_extract_action_go.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M6,22h28.34l-7.17,-7.17L30,12l12,12 -12,12 -2.83,-2.83L34.34,26H6z"/> </vector> core/res/res/drawable/ic_input_extract_action_next.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M23.17,14.83L30.34,22H2v4h28.34l-7.17,7.17L26,36l12,-12 -12,-12 -2.83,2.83zM40,12v24h4V12h-4z"/> </vector> Loading
core/java/android/inputmethodservice/CompactExtractEditLayout.java 0 → 100644 +103 −0 Original line number Diff line number Diff line 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); } } }
core/java/android/inputmethodservice/InputMethodService.java +46 −7 Original line number Diff line number Diff line Loading @@ -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; Loading Loading @@ -302,7 +303,7 @@ public class InputMethodService extends AbstractInputMethodService { boolean mExtractViewHidden; ExtractEditText mExtractEditText; ViewGroup mExtractAccessories; Button mExtractAction; View mExtractAction; ExtractedText mExtractedText; int mExtractedToken; Loading Loading @@ -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( Loading Loading @@ -2409,6 +2410,34 @@ public class InputMethodService extends AbstractInputMethodService { } } /** * 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 Loading Loading @@ -2459,10 +2488,20 @@ public class InputMethodService extends AbstractInputMethodService { if (hasAction) { mExtractAccessories.setVisibility(View.VISIBLE); if (mExtractAction != null) { if (mExtractAction instanceof ImageButton) { ((ImageButton) mExtractAction) .setImageResource(getIconForImeAction(ei.imeOptions)); if (ei.actionLabel != null) { mExtractAction.setText(ei.actionLabel); mExtractAction.setContentDescription(ei.actionLabel); } else { mExtractAction.setText(getTextForImeAction(ei.imeOptions)); mExtractAction.setContentDescription(getTextForImeAction(ei.imeOptions)); } } else { if (ei.actionLabel != null) { ((TextView) mExtractAction).setText(ei.actionLabel); } else { ((TextView) mExtractAction).setText(getTextForImeAction(ei.imeOptions)); } } mExtractAction.setOnClickListener(mActionClickListener); } Loading
core/res/res/drawable/ic_input_extract_action_done.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M18,32.34L9.66,24l-2.83,2.83L18,38l24,-24 -2.83,-2.83z"/> </vector>
core/res/res/drawable/ic_input_extract_action_go.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M6,22h28.34l-7.17,-7.17L30,12l12,12 -12,12 -2.83,-2.83L34.34,26H6z"/> </vector>
core/res/res/drawable/ic_input_extract_action_next.xml 0 → 100644 +4 −0 Original line number Diff line number Diff line <vector android:height="24dp" android:viewportHeight="48.0" android:viewportWidth="48.0" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android"> <path android:fillColor="#FFFFFF" android:pathData="M23.17,14.83L30.34,22H2v4h28.34l-7.17,7.17L26,36l12,-12 -12,-12 -2.83,2.83zM40,12v24h4V12h-4z"/> </vector>