Merge "Show physical keyboard control button on the input method switch dialog"

This commit is contained in:
satok
2012-04-11 00:12:59 -07:00
committed by Android (Google) Code Review
8 changed files with 193 additions and 10 deletions

View File

@ -0,0 +1,108 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
/*
** Copyright 2012, 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.
*/
-->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="9dip"
android:layout_marginLeft="20dip"
android:layout_marginRight="10dip"
android:layout_marginTop="6dip"
android:gravity="center_vertical"
android:orientation="vertical" >
<com.android.internal.widget.DialogTitle
android:id="@+id/alertTitle"
style="@android:style/DialogWindowTitle.Holo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:singleLine="true"
android:text="@string/select_input_method" />
</LinearLayout>
<!-- Hard keyboard switch -->
<LinearLayout
android:id="@+id/hard_keyboard_section"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<View
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="@android:color/holo_blue_light" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="?android:attr/selectableItemBackground"
android:ellipsize="marquee"
android:gravity="center_vertical"
android:minHeight="?android:attr/listPreferredItemHeightSmall"
android:orientation="vertical"
android:paddingBottom="5dip"
android:paddingLeft="16dip"
android:paddingRight="0dip"
android:paddingTop="5dip" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/hardware"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="?android:attr/textColorAlertDialogListItem" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="true"
android:text="@string/use_physical_keyboard"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="?android:attr/textColorAlertDialogListItem" />
</LinearLayout>
<Switch
android:id="@+id/hard_keyboard_switch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="12dip" />
</LinearLayout>
</LinearLayout>
<View
android:id="@+id/titleDivider"
android:layout_width="match_parent"
android:layout_height="2dip"
android:background="@android:drawable/divider_horizontal_dark" />
</LinearLayout>

View File

@ -85,6 +85,8 @@
<java-symbol type="id" name="fillInIntent" />
<java-symbol type="id" name="find" />
<java-symbol type="id" name="fullscreenArea" />
<java-symbol type="id" name="hard_keyboard_section" />
<java-symbol type="id" name="hard_keyboard_switch" />
<java-symbol type="id" name="headers" />
<java-symbol type="id" name="hour" />
<java-symbol type="id" name="icon" />
@ -1042,6 +1044,7 @@
<java-symbol type="layout" name="icon_menu_layout" />
<java-symbol type="layout" name="input_method" />
<java-symbol type="layout" name="input_method_extract_view" />
<java-symbol type="layout" name="input_method_switch_dialog_title" />
<java-symbol type="layout" name="js_prompt" />
<java-symbol type="layout" name="list_content_simple" />
<java-symbol type="layout" name="list_menu_item_checkbox" />
@ -1449,6 +1452,7 @@
<java-symbol type="string" name="factorytest_no_action" />
<java-symbol type="string" name="factorytest_not_system" />
<java-symbol type="string" name="factorytest_reboot" />
<java-symbol type="string" name="hardware" />
<java-symbol type="string" name="heavy_weight_notification" />
<java-symbol type="string" name="heavy_weight_notification_detail" />
<java-symbol type="string" name="input_method_binding_label" />
@ -1471,6 +1475,7 @@
<java-symbol type="string" name="usb_cd_installer_notification_title" />
<java-symbol type="string" name="usb_mtp_notification_title" />
<java-symbol type="string" name="usb_notification_message" />
<java-symbol type="string" name="use_physical_keyboard" />
<java-symbol type="string" name="usb_ptp_notification_title" />
<java-symbol type="string" name="vpn_text" />
<java-symbol type="string" name="vpn_text_long" />

View File

@ -2927,6 +2927,10 @@
<string name="select_input_method">Choose input method</string>
<!-- Title of a button to open the settings for input methods [CHAR LIMIT=30] -->
<string name="configure_input_methods">Set up input methods</string>
<!-- Summary text of a toggle switch to enable/disable use of the physical keyboard in the input method selector [CHAR LIMIT=25] -->
<string name="use_physical_keyboard">Physical keyboard</string>
<!-- Title of the physical keyboard category in the input method selector [CHAR LIMIT=10] -->
<string name="hardware">Hardware</string>
<string name="fast_scroll_alphabet">\u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>
<string name="fast_scroll_numeric_alphabet">\u00200123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>

View File

@ -21,7 +21,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:paddingBottom="28dip"
android:paddingBottom="7dip"
android:orientation="vertical"
android:visibility="gone">
<View
@ -38,7 +38,7 @@
android:layout_height="wrap_content"
android:layout_marginLeft="20dip"
android:orientation="vertical"
android:background="@*android:drawable/dialog_full_holo_dark">
android:background="@drawable/notify_panel_clock_bg">
<!-- Hard keyboard switch -->
<LinearLayout
android:id="@+id/hard_keyboard_section"
@ -51,7 +51,7 @@
android:orientation="horizontal">
<TextView
android:id="@+id/use_physical_keyboard_label"
android:layout_width="wrap_content"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minHeight="?android:attr/listPreferredItemHeight"
@ -82,7 +82,7 @@
<!-- Input method list -->
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_height="0dip"
android:overScrollMode="ifContentScrolls"
android:layout_marginTop="3dip"
android:layout_weight="1"

View File

@ -125,7 +125,7 @@
<string name="status_bar_input_method_settings_configure_input_methods">Set up input methods</string>
<!-- Label of a toggle switch to disable use of the physical keyboard in favor of the IME. [CHAR LIMIT=25] -->
<string name="status_bar_use_physical_keyboard">Use physical keyboard</string>
<string name="status_bar_use_physical_keyboard">Physical keyboard</string>
<!-- Prompt for the USB device permission dialog [CHAR LIMIT=80] -->
<string name="usb_device_permission_prompt">Allow the app <xliff:g id="application">%1$s</xliff:g> to access the USB device?</string>

View File

@ -201,7 +201,6 @@ public class InputMethodsPanel extends LinearLayout implements StatusBarPanel,
if (closeKeyboard) {
mImm.hideSoftInputFromWindow(getWindowToken(), 0);
}
updateHardKeyboardEnabled();
}
private void startActivity(Intent intent) {
@ -329,6 +328,7 @@ public class InputMethodsPanel extends LinearLayout implements StatusBarPanel,
mHardKeyboardSection.setVisibility(View.VISIBLE);
if (mHardKeyboardSwitch.isChecked() != mHardKeyboardEnabled) {
mHardKeyboardSwitch.setChecked(mHardKeyboardEnabled);
updateHardKeyboardEnabled();
}
} else {
mHardKeyboardSection.setVisibility(View.GONE);

View File

@ -27,6 +27,7 @@ import com.android.internal.view.IInputMethodManager;
import com.android.internal.view.IInputMethodSession;
import com.android.internal.view.InputBindResult;
import com.android.server.EventLogTags;
import com.android.server.wm.WindowManagerService;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
@ -91,7 +92,10 @@ import android.view.inputmethod.InputMethodInfo;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodSubtype;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.RadioButton;
import android.widget.Switch;
import android.widget.TextView;
import java.io.File;
@ -134,6 +138,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
static final int MSG_UNBIND_METHOD = 3000;
static final int MSG_BIND_METHOD = 3010;
static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
static final long TIME_TO_RECONNECT = 10*1000;
static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
@ -156,6 +162,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
final HandlerCaller mCaller;
private final InputMethodFileManager mFileManager;
private final InputMethodAndSubtypeListManager mImListManager;
private final HardKeyboardListener mHardKeyboardListener;
private final WindowManagerService mWindowManagerService;
final InputBindResult mNoBinding = new InputBindResult(null, null, -1);
@ -360,6 +368,7 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
private AlertDialog.Builder mDialogBuilder;
private AlertDialog mSwitchingDialog;
private View mSwitchingDialogTitleView;
private InputMethodInfo[] mIms;
private int[] mSubtypeIds;
@ -528,7 +537,31 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}
}
public InputMethodManagerService(Context context) {
private class HardKeyboardListener
implements WindowManagerService.OnHardKeyboardStatusChangeListener {
@Override
public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
mHandler.sendMessage(mHandler.obtainMessage(
MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
}
public void handleHardKeyboardStatusChange(boolean available, boolean enabled) {
if (DEBUG) {
Slog.w(TAG, "HardKeyboardStatusChanged: available = " + available + ", enabled = "
+ enabled);
}
synchronized(mMethodMap) {
if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
&& mSwitchingDialog.isShowing()) {
mSwitchingDialogTitleView.findViewById(
com.android.internal.R.id.hard_keyboard_section).setVisibility(
available ? View.VISIBLE : View.GONE);
}
}
}
}
public InputMethodManagerService(Context context, WindowManagerService windowManager) {
mContext = context;
mRes = context.getResources();
mHandler = new Handler(this);
@ -540,6 +573,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
handleMessage(msg);
}
});
mWindowManagerService = windowManager;
mHardKeyboardListener = new HardKeyboardListener();
mImeSwitcherNotification = new Notification();
mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default;
@ -633,6 +668,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
updateImeWindowStatusLocked();
mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
com.android.internal.R.bool.show_ongoing_ime_switcher);
if (mShowOngoingImeSwitcherForPhones) {
mWindowManagerService.setOnHardKeyboardStatusChangeListener(
mHardKeyboardListener);
}
try {
startInputInnerLocked();
} catch (RuntimeException e) {
@ -1994,6 +2033,12 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
Slog.w(TAG, "Client died receiving input method " + args.arg2);
}
return true;
// --------------------------------------------------------------
case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
mHardKeyboardListener.handleHardKeyboardStatusChange(
msg.arg1 == 1, msg.arg2 == 1);
return true;
}
return false;
}
@ -2204,12 +2249,10 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
}
}
}
final TypedArray a = context.obtainStyledAttributes(null,
com.android.internal.R.styleable.DialogPreference,
com.android.internal.R.attr.alertDialogStyle, 0);
mDialogBuilder = new AlertDialog.Builder(context)
.setTitle(com.android.internal.R.string.select_input_method)
.setOnCancelListener(new OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
@ -2219,6 +2262,29 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
.setIcon(a.getDrawable(
com.android.internal.R.styleable.DialogPreference_dialogTitle));
a.recycle();
final LayoutInflater inflater =
(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View tv = inflater.inflate(
com.android.internal.R.layout.input_method_switch_dialog_title, null);
mDialogBuilder.setCustomTitle(tv);
// Setup layout for a toggle switch of the hardware keyboard
mSwitchingDialogTitleView = tv;
mSwitchingDialogTitleView.findViewById(
com.android.internal.R.id.hard_keyboard_section).setVisibility(
mWindowManagerService.isHardKeyboardAvailable() ?
View.VISIBLE : View.GONE);
final Switch hardKeySwitch = ((Switch)mSwitchingDialogTitleView.findViewById(
com.android.internal.R.id.hard_keyboard_switch));
hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
hardKeySwitch.setOnCheckedChangeListener(
new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(
CompoundButton buttonView, boolean isChecked) {
mWindowManagerService.setHardKeyboardEnabled(isChecked);
}
});
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context,
com.android.internal.R.layout.simple_list_item_2_single_choice, imList,

View File

@ -276,7 +276,7 @@ class ServerThread extends Thread {
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
try {
Slog.i(TAG, "Input Method Service");
imm = new InputMethodManagerService(context);
imm = new InputMethodManagerService(context, wm);
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
} catch (Throwable e) {
reportWtf("starting Input Manager Service", e);