Customizes input extract edit view for Wear

Provides an alternate presentation of the extract edit area
of an input method window, designed for sub 250dp width screens.

An icon is used on a round material style button in place of a text
action, providing more horizontal space for the editing area.

BUG: 22512982
Change-Id: I16226ce393f2d15065d08e66a36d008eb1a0c8a1
(cherry picked from commit fd71a6a5d99bad5d3ab32edc328fb5b026b66215)
This commit is contained in:
Mark Renouf
2016-04-05 13:21:57 -04:00
committed by Mark Renouf
parent 3212a4c759
commit 880602eb64
21 changed files with 359 additions and 8 deletions

View File

@@ -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);
}
}
}

View File

@@ -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);
}

View File

@@ -0,0 +1,4 @@
<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>

View File

@@ -0,0 +1,4 @@
<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>

View File

@@ -0,0 +1,4 @@
<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>

View File

@@ -0,0 +1,4 @@
<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="M22.83,14.83L15.66,22H44v4H15.66l7.17,7.17L20,36 8,24l12,-12 2.83,2.83zM6,12v24H2V12h4z"/>
</vector>

View File

@@ -0,0 +1,4 @@
<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="M38,14v8H11.66l7.17,-7.17L16,12 4,24l12,12 2.83,-2.83L11.66,26H42V14z"/>
</vector>

View File

@@ -0,0 +1,4 @@
<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="M31,28h-1.59l-0.55,-0.55C30.82,25.18 32,22.23 32,19c0,-7.18 -5.82,-13 -13,-13S6,11.82 6,19s5.82,13 13,13c3.23,0 6.18,-1.18 8.45,-3.13l0.55,0.55L28,31l10,9.98L40.98,38 31,28zM19,28c-4.97,0 -9,-4.03 -9,-9s4.03,-9 9,-9 9,4.03 9,9 -4.03,9 -9,9z"/>
</vector>

View File

@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:viewportWidth="48.0"
android:viewportHeight="48.0">
<path
android:pathData="M4.02,42L46,24 4.02,6 4,20l30,4 -30,4z"
android:fillColor="#FFFFFF"/>
</vector>

View File

@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/input_extract_action_bg_pressed_material_dark"
android:state_pressed="true"/>
<item android:drawable="@drawable/input_extract_action_bg_normal_material_dark"/>
</selector>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/material_deep_teal_200"/>
</shape>

View File

@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="oval">
<solid android:color="@color/material_deep_teal_100"/>
</shape>

View File

@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="utf-8"?>
<android.inputmethodservice.CompactExtractEditLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical"
android:baselineAligned="false">
<android.inputmethodservice.ExtractEditText
android:id="@id/inputExtractEditText"
android:layout_width="0dp"
android:layout_height="24dp"
android:background="@null"
android:singleLine="true"
android:inputType="text"
android:layout_weight="1"
android:fontFamily="sans-serif-condensed-light"
android:textColor="@color/primary_text_default_material_dark"
android:textColorHighlight="@color/accent_material_dark"
android:textSize="18dp"
android:cursorVisible="false"
android:gravity="bottom|right"
/>
<FrameLayout
android:id="@id/inputExtractAccessories"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:visibility="visible">
<ImageButton
android:id="@id/inputExtractAction"
android:layout_width="@dimen/input_extract_action_button_width"
android:layout_height="@dimen/input_extract_action_button_width"
android:background="@drawable/input_extract_action_bg_material_dark"
android:padding="4dp"
android:scaleType="centerInside" />
</FrameLayout>
</android.inputmethodservice.CompactExtractEditLayout>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/dimens.xml
**
** Copyright 2016, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources>
<!-- each of these are relative to the display size -->
<item name="input_extract_layout_height" type="fraction">25.2%</item>
<item name="input_extract_layout_padding_left" type="fraction">7.5%</item>
<item name="input_extract_layout_padding_left_no_action" type="fraction">@fraction/input_extract_layout_padding_right</item>
<item name="input_extract_layout_padding_right" type="fraction">21.4%</item>
<item name="input_extract_text_margin_bottom" type="fraction">5.5%</item>
<item name="input_extract_action_margin_bottom" type="fraction">2.1%</item>
<item name="input_extract_action_button_width" type="dimen">32dp</item>
<item name="input_extract_action_button_height" type="dimen">32dp</item>
</resources>

View File

@@ -0,0 +1,23 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/dimens.xml
**
** Copyright 2016, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources>
<!-- each of these are relative to the display size -->
<item name="input_extract_layout_padding_right" type="fraction">7.5%</item>
</resources>

View File

@@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/* //device/apps/common/assets/res/any/dimens.xml
**
** Copyright 2016, The Android Open Source Project
**
** Licensed under the Apache License, Version 2.0 (the "License");
** you may not use this file except in compliance with the License.
** You may obtain a copy of the License at
**
** http://www.apache.org/licenses/LICENSE-2.0
**
** Unless required by applicable law or agreed to in writing, software
** distributed under the License is distributed on an "AS IS" BASIS,
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
** See the License for the specific language governing permissions and
** limitations under the License.
*/
-->
<resources>
<!-- each of these are relative to the display size -->
<item name="input_extract_layout_height" type="fraction">17.5%</item>
<item name="input_extract_layout_padding_left" type="fraction">3.6%</item>
<item name="input_extract_layout_padding_left_no_action" type="fraction">@fraction/input_extract_layout_padding_right</item>
<item name="input_extract_layout_padding_right" type="fraction">2.5%</item>
<item name="input_extract_text_margin_bottom" type="fraction">0%</item>
<item name="input_extract_action_margin_bottom" type="fraction">0%</item>
<item name="input_extract_action_button_width" type="dimen">24dp</item>
<item name="input_extract_action_button_height" type="dimen">24dp</item>
</resources>

View File

@@ -18,6 +18,7 @@
<style name="Theme.Dialog.AppError" parent="Theme.Micro.Dialog.AppError" />
<style name="Theme.Holo.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
<style name="Theme.Holo.Light.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
<style name="Theme.InputMethod" parent="Theme.Micro.InputMethod" />
<style name="Theme.Material.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
<style name="Theme.Material.Light.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
</resources>

View File

@@ -19,14 +19,16 @@
<style name="Theme.DeviceDefault.Dialog" parent="Theme.Micro.Dialog" />
<style name="Theme.DeviceDefault.DialogWhenLarge" parent="Theme.Micro.Dialog" />
<style name="Theme.DeviceDefault.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
<style name="Theme.DeviceDefault.InputMethod" parent="Theme.Micro.InputMethod" />
<style name="Theme.DeviceDefault.Panel" parent="Theme.Micro.Panel" />
<style name="Theme.DeviceDefault.Light" parent="Theme.Micro.Light" />
<style name="Theme.DeviceDefault.Light.NoActionBar" parent="Theme.Micro.Light" />
<style name="Theme.DeviceDefault.Light.DarkActionBar" parent="Theme.Micro.Light" />
<style name="Theme.DeviceDefault.Light.Dialog" parent="Theme.Micro.Dialog" />
<style name="Theme.DeviceDefault.Light.DialogWhenLarge" parent="Theme.Micro.Dialog" />
<style name="Theme.DeviceDefault.Light.Dialog.Alert" parent="Theme.Micro.Dialog.Alert" />
<style name="Theme.DeviceDefault.Light.Panel" parent="Theme.Micro.Light.Panel" />
<style name="Theme.DeviceDefault.Settings" parent="Theme.Micro" />
<style name="Theme.DeviceDefault.Wallpaper" parent="Theme.Micro" />
</resources>

View File

@@ -75,7 +75,9 @@
<color name="material_grey_100">#fff5f5f5</color>
<color name="material_grey_50">#fffafafa</color>
<color name="material_deep_teal_100">#ffb2dfdb</color>
<color name="material_deep_teal_200">#ff80cbc4</color>
<color name="material_deep_teal_300">#ff4db6ac</color>
<color name="material_deep_teal_500">#ff009688</color>
<color name="material_blue_grey_800">#ff37474f</color>

View File

@@ -2542,4 +2542,23 @@
<java-symbol type="id" name="titleDividerNoCustom" />
<java-symbol type="bool" name="config_sustainedPerformanceModeSupported" />
<!-- Wearable input extract edit view -->
<java-symbol type="drawable" name="ic_input_extract_action_go" />
<java-symbol type="drawable" name="ic_input_extract_action_search" />
<java-symbol type="drawable" name="ic_input_extract_action_send" />
<java-symbol type="drawable" name="ic_input_extract_action_next" />
<java-symbol type="drawable" name="ic_input_extract_action_done" />
<java-symbol type="drawable" name="ic_input_extract_action_previous" />
<java-symbol type="drawable" name="ic_input_extract_action_return" />
<java-symbol type="fraction" name="input_extract_layout_height" />
<java-symbol type="fraction" name="input_extract_layout_padding_left" />
<java-symbol type="fraction" name="input_extract_layout_padding_left_no_action" />
<java-symbol type="fraction" name="input_extract_layout_padding_right" />
<java-symbol type="fraction" name="input_extract_text_margin_bottom" />
<java-symbol type="fraction" name="input_extract_action_margin_bottom" />
<java-symbol type="dimen" name="input_extract_action_button_width" />
<java-symbol type="dimen" name="input_extract_action_button_height" />
</resources>

View File

@@ -83,4 +83,18 @@
<item name="fontFamily">sans-serif-condensed-light</item>
<item name="textColor">@color/micro_text_light</item>
</style>
<style name="Theme.Micro.Panel" parent="Theme.Material.Panel" />
<style name="Theme.Micro.Light.Panel" parent="Theme.Material.Light.Panel" />
<!-- Default theme for material style input methods, which is used by the
{@link android.inputmethodservice.InputMethodService} class.
This inherits from Theme.Panel, but sets up IME appropriate animations
and a few custom attributes. -->
<style name="Theme.Micro.InputMethod" parent="Theme.Micro.Panel">
<item name="windowAnimationStyle">@style/Animation.InputMethod</item>
<item name="imeFullscreenBackground">#1e282c</item>
<item name="imeExtractEnterAnimation">@anim/input_method_extract_enter</item>
<item name="imeExtractExitAnimation">@anim/input_method_extract_exit</item>
</style>
</resources>