Merge "Fix 5021968: Add input method switcher button to lock screen."

This commit is contained in:
Jim Miller
2011-08-19 16:30:13 -07:00
committed by Android (Google) Code Review
6 changed files with 112 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 202 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 157 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 217 B

View File

@@ -133,13 +133,14 @@
<!-- Column 2 - password entry field and PIN keyboard -->
<LinearLayout
android:orientation="vertical"
android:orientation="horizontal"
android:layout_width="270dip"
android:layout_gravity="center_vertical">
<EditText android:id="@+id/passwordEntry"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:layout_width="0dip"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:textStyle="normal"
@@ -153,6 +154,17 @@
android:suggestionsEnabled="false"
/>
<ImageView android:id="@+id/switch_ime_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_lockscreen_ime"
android:clickable="true"
android:padding="8dip"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackground"
android:visibility="gone"
/>
</LinearLayout>
<!-- Numeric keyboard -->

View File

@@ -95,22 +95,39 @@
/>
<!-- Password entry field -->
<EditText android:id="@+id/passwordEntry"
android:layout_height="wrap_content"
android:layout_width="match_parent"
<LinearLayout
android:layout_gravity="center_vertical|fill_horizontal"
android:gravity="center_horizontal"
android:singleLine="true"
android:textStyle="normal"
android:inputType="textPassword"
android:textSize="36sp"
android:orientation="horizontal"
android:layout_marginLeft="16dip"
android:layout_marginRight="16dip"
android:background="@drawable/lockscreen_password_field_dark"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffffff"
android:imeOptions="actionDone"
android:suggestionsEnabled="false"/>
android:layout_marginRight="16dip">
<EditText android:id="@+id/passwordEntry"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal"
android:singleLine="true"
android:textStyle="normal"
android:inputType="textPassword"
android:textSize="36sp"
android:background="@drawable/lockscreen_password_field_dark"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffffff"
android:imeOptions="actionDone"
android:suggestionsEnabled="false"/>
<ImageView android:id="@+id/switch_ime_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_lockscreen_ime"
android:clickable="true"
android:padding="8dip"
android:layout_gravity="center"
android:background="?android:attr/selectableItemBackground"
android:visibility="gone"
/>
</LinearLayout>
<!-- Numeric keyboard -->
<com.android.internal.widget.PasswordEntryKeyboardView android:id="@+id/keyboard"

View File

@@ -16,6 +16,8 @@
package com.android.internal.policy.impl;
import java.util.List;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.content.res.Configuration;
@@ -27,18 +29,18 @@ import com.android.internal.widget.PasswordEntryKeyboardView;
import android.os.CountDownTimer;
import android.os.SystemClock;
import android.security.KeyStore;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.text.method.DigitsKeyListener;
import android.text.method.TextKeyListener;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
@@ -159,6 +161,68 @@ public class PasswordUnlockScreen extends LinearLayout implements KeyguardScreen
}
}
});
// If there's more than one IME, enable the IME switcher button
View switchImeButton = findViewById(R.id.switch_ime_button);
final InputMethodManager imm = (InputMethodManager) getContext().getSystemService(
Context.INPUT_METHOD_SERVICE);
if (switchImeButton != null && hasMultipleEnabledIMEsOrSubtypes(imm, false)) {
switchImeButton.setVisibility(View.VISIBLE);
switchImeButton.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
mCallback.pokeWakelock(); // Leave the screen on a bit longer
imm.showInputMethodPicker();
}
});
}
}
/**
* Method adapted from com.android.inputmethod.latin.Utils
*
* @param imm The input method manager
* @param shouldIncludeAuxiliarySubtypes
* @return true if we have multiple IMEs to choose from
*/
private boolean hasMultipleEnabledIMEsOrSubtypes(InputMethodManager imm,
final boolean shouldIncludeAuxiliarySubtypes) {
final List<InputMethodInfo> enabledImis = imm.getEnabledInputMethodList();
// Number of the filtered IMEs
int filteredImisCount = 0;
for (InputMethodInfo imi : enabledImis) {
// We can return true immediately after we find two or more filtered IMEs.
if (filteredImisCount > 1) return true;
final List<InputMethodSubtype> subtypes =
imm.getEnabledInputMethodSubtypeList(imi, true);
// IMEs that have no subtypes should be counted.
if (subtypes.isEmpty()) {
++filteredImisCount;
continue;
}
int auxCount = 0;
for (InputMethodSubtype subtype : subtypes) {
if (subtype.isAuxiliary()) {
++auxCount;
}
}
final int nonAuxCount = subtypes.size() - auxCount;
// IMEs that have one or more non-auxiliary subtypes should be counted.
// If shouldIncludeAuxiliarySubtypes is true, IMEs that have two or more auxiliary
// subtypes should be counted as well.
if (nonAuxCount > 0 || (shouldIncludeAuxiliarySubtypes && auxCount > 1)) {
++filteredImisCount;
continue;
}
}
return filteredImisCount > 1
// imm.getEnabledInputMethodSubtypeList(null, false) will return the current IME's enabled
// input method subtype (The current IME should be LatinIME.)
|| imm.getEnabledInputMethodSubtypeList(null, false).size() > 1;
}
@Override