Skip to content

Commit 0103849

Browse files
committed
Show physical keyboard control button on the input method switch dialog
Bug: 5240095 Change-Id: Ica768083f95c33dc1e494a28ba7d8b6eb989b0ef
1 parent 63c115c commit 0103849

File tree

8 files changed

+193
-10
lines changed

8 files changed

+193
-10
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
/*
4+
** Copyright 2012, The Android Open Source Project
5+
**
6+
** Licensed under the Apache License, Version 2.0 (the "License");
7+
** you may not use this file except in compliance with the License.
8+
** You may obtain a copy of the License at
9+
**
10+
** http://www.apache.org/licenses/LICENSE-2.0
11+
**
12+
** Unless required by applicable law or agreed to in writing, software
13+
** distributed under the License is distributed on an "AS IS" BASIS,
14+
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
** See the License for the specific language governing permissions and
16+
** limitations under the License.
17+
*/
18+
-->
19+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
20+
android:layout_width="match_parent"
21+
android:layout_height="wrap_content"
22+
android:orientation="vertical" >
23+
24+
<LinearLayout
25+
android:layout_width="match_parent"
26+
android:layout_height="wrap_content"
27+
android:layout_marginBottom="9dip"
28+
android:layout_marginLeft="20dip"
29+
android:layout_marginRight="10dip"
30+
android:layout_marginTop="6dip"
31+
android:gravity="center_vertical"
32+
android:orientation="vertical" >
33+
34+
<com.android.internal.widget.DialogTitle
35+
android:id="@+id/alertTitle"
36+
style="@android:style/DialogWindowTitle.Holo"
37+
android:layout_width="match_parent"
38+
android:layout_height="wrap_content"
39+
android:ellipsize="end"
40+
android:singleLine="true"
41+
android:text="@string/select_input_method" />
42+
</LinearLayout>
43+
44+
<!-- Hard keyboard switch -->
45+
46+
<LinearLayout
47+
android:id="@+id/hard_keyboard_section"
48+
android:layout_width="match_parent"
49+
android:layout_height="wrap_content"
50+
android:orientation="vertical" >
51+
52+
<View
53+
android:layout_width="match_parent"
54+
android:layout_height="2dip"
55+
android:background="@android:color/holo_blue_light" />
56+
57+
<LinearLayout
58+
android:layout_width="match_parent"
59+
android:layout_height="wrap_content"
60+
android:orientation="horizontal" >
61+
62+
<LinearLayout
63+
android:layout_width="0dip"
64+
android:layout_height="wrap_content"
65+
android:layout_weight="1"
66+
android:background="?android:attr/selectableItemBackground"
67+
android:ellipsize="marquee"
68+
android:gravity="center_vertical"
69+
android:minHeight="?android:attr/listPreferredItemHeightSmall"
70+
android:orientation="vertical"
71+
android:paddingBottom="5dip"
72+
android:paddingLeft="16dip"
73+
android:paddingRight="0dip"
74+
android:paddingTop="5dip" >
75+
76+
<TextView
77+
android:layout_width="wrap_content"
78+
android:layout_height="wrap_content"
79+
android:singleLine="true"
80+
android:text="@string/hardware"
81+
android:textAppearance="?android:attr/textAppearanceMedium"
82+
android:textColor="?android:attr/textColorAlertDialogListItem" />
83+
84+
<TextView
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:singleLine="true"
88+
android:text="@string/use_physical_keyboard"
89+
android:textAppearance="?android:attr/textAppearanceSmall"
90+
android:textColor="?android:attr/textColorAlertDialogListItem" />
91+
</LinearLayout>
92+
93+
<Switch
94+
android:id="@+id/hard_keyboard_switch"
95+
android:layout_width="wrap_content"
96+
android:layout_height="wrap_content"
97+
android:layout_gravity="center_vertical"
98+
android:layout_marginRight="12dip" />
99+
</LinearLayout>
100+
</LinearLayout>
101+
102+
<View
103+
android:id="@+id/titleDivider"
104+
android:layout_width="match_parent"
105+
android:layout_height="2dip"
106+
android:background="@android:drawable/divider_horizontal_dark" />
107+
108+
</LinearLayout>

core/res/res/values/public.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@
8585
<java-symbol type="id" name="fillInIntent" />
8686
<java-symbol type="id" name="find" />
8787
<java-symbol type="id" name="fullscreenArea" />
88+
<java-symbol type="id" name="hard_keyboard_section" />
89+
<java-symbol type="id" name="hard_keyboard_switch" />
8890
<java-symbol type="id" name="headers" />
8991
<java-symbol type="id" name="hour" />
9092
<java-symbol type="id" name="icon" />
@@ -1042,6 +1044,7 @@
10421044
<java-symbol type="layout" name="icon_menu_layout" />
10431045
<java-symbol type="layout" name="input_method" />
10441046
<java-symbol type="layout" name="input_method_extract_view" />
1047+
<java-symbol type="layout" name="input_method_switch_dialog_title" />
10451048
<java-symbol type="layout" name="js_prompt" />
10461049
<java-symbol type="layout" name="list_content_simple" />
10471050
<java-symbol type="layout" name="list_menu_item_checkbox" />
@@ -1449,6 +1452,7 @@
14491452
<java-symbol type="string" name="factorytest_no_action" />
14501453
<java-symbol type="string" name="factorytest_not_system" />
14511454
<java-symbol type="string" name="factorytest_reboot" />
1455+
<java-symbol type="string" name="hardware" />
14521456
<java-symbol type="string" name="heavy_weight_notification" />
14531457
<java-symbol type="string" name="heavy_weight_notification_detail" />
14541458
<java-symbol type="string" name="input_method_binding_label" />
@@ -1471,6 +1475,7 @@
14711475
<java-symbol type="string" name="usb_cd_installer_notification_title" />
14721476
<java-symbol type="string" name="usb_mtp_notification_title" />
14731477
<java-symbol type="string" name="usb_notification_message" />
1478+
<java-symbol type="string" name="use_physical_keyboard" />
14741479
<java-symbol type="string" name="usb_ptp_notification_title" />
14751480
<java-symbol type="string" name="vpn_text" />
14761481
<java-symbol type="string" name="vpn_text_long" />

core/res/res/values/strings.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2921,6 +2921,10 @@
29212921
<string name="select_input_method">Choose input method</string>
29222922
<!-- Title of a button to open the settings for input methods [CHAR LIMIT=30] -->
29232923
<string name="configure_input_methods">Set up input methods</string>
2924+
<!-- Summary text of a toggle switch to enable/disable use of the physical keyboard in the input method selector [CHAR LIMIT=25] -->
2925+
<string name="use_physical_keyboard">Physical keyboard</string>
2926+
<!-- Title of the physical keyboard category in the input method selector [CHAR LIMIT=10] -->
2927+
<string name="hardware">Hardware</string>
29242928

29252929
<string name="fast_scroll_alphabet">\u0020ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>
29262930
<string name="fast_scroll_numeric_alphabet">\u00200123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ</string>

packages/SystemUI/res/layout-sw600dp/status_bar_input_methods_panel.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
xmlns:android="http://schemas.android.com/apk/res/android"
2222
android:layout_height="match_parent"
2323
android:layout_width="match_parent"
24-
android:paddingBottom="28dip"
24+
android:paddingBottom="7dip"
2525
android:orientation="vertical"
2626
android:visibility="gone">
2727
<View
@@ -38,7 +38,7 @@
3838
android:layout_height="wrap_content"
3939
android:layout_marginLeft="20dip"
4040
android:orientation="vertical"
41-
android:background="@*android:drawable/dialog_full_holo_dark">
41+
android:background="@drawable/notify_panel_clock_bg">
4242
<!-- Hard keyboard switch -->
4343
<LinearLayout
4444
android:id="@+id/hard_keyboard_section"
@@ -51,7 +51,7 @@
5151
android:orientation="horizontal">
5252
<TextView
5353
android:id="@+id/use_physical_keyboard_label"
54-
android:layout_width="wrap_content"
54+
android:layout_width="0dip"
5555
android:layout_height="wrap_content"
5656
android:layout_weight="1"
5757
android:minHeight="?android:attr/listPreferredItemHeight"
@@ -82,7 +82,7 @@
8282
<!-- Input method list -->
8383
<ScrollView
8484
android:layout_width="wrap_content"
85-
android:layout_height="wrap_content"
85+
android:layout_height="0dip"
8686
android:overScrollMode="ifContentScrolls"
8787
android:layout_marginTop="3dip"
8888
android:layout_weight="1"

packages/SystemUI/res/values/strings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<string name="status_bar_input_method_settings_configure_input_methods">Set up input methods</string>
126126

127127
<!-- Label of a toggle switch to disable use of the physical keyboard in favor of the IME. [CHAR LIMIT=25] -->
128-
<string name="status_bar_use_physical_keyboard">Use physical keyboard</string>
128+
<string name="status_bar_use_physical_keyboard">Physical keyboard</string>
129129

130130
<!-- Prompt for the USB device permission dialog [CHAR LIMIT=80] -->
131131
<string name="usb_device_permission_prompt">Allow the app <xliff:g id="application">%1$s</xliff:g> to access the USB device?</string>

packages/SystemUI/src/com/android/systemui/statusbar/tablet/InputMethodsPanel.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,6 @@ public void closePanel(boolean closeKeyboard) {
201201
if (closeKeyboard) {
202202
mImm.hideSoftInputFromWindow(getWindowToken(), 0);
203203
}
204-
updateHardKeyboardEnabled();
205204
}
206205

207206
private void startActivity(Intent intent) {
@@ -329,6 +328,7 @@ private void updateHardKeyboardSection() {
329328
mHardKeyboardSection.setVisibility(View.VISIBLE);
330329
if (mHardKeyboardSwitch.isChecked() != mHardKeyboardEnabled) {
331330
mHardKeyboardSwitch.setChecked(mHardKeyboardEnabled);
331+
updateHardKeyboardEnabled();
332332
}
333333
} else {
334334
mHardKeyboardSection.setVisibility(View.GONE);

services/java/com/android/server/InputMethodManagerService.java

Lines changed: 69 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import com.android.internal.view.IInputMethodSession;
2828
import com.android.internal.view.InputBindResult;
2929
import com.android.server.EventLogTags;
30+
import com.android.server.wm.WindowManagerService;
3031

3132
import org.xmlpull.v1.XmlPullParser;
3233
import org.xmlpull.v1.XmlPullParserException;
@@ -91,7 +92,10 @@
9192
import android.view.inputmethod.InputMethodManager;
9293
import android.view.inputmethod.InputMethodSubtype;
9394
import android.widget.ArrayAdapter;
95+
import android.widget.CompoundButton;
96+
import android.widget.CompoundButton.OnCheckedChangeListener;
9497
import android.widget.RadioButton;
98+
import android.widget.Switch;
9599
import android.widget.TextView;
96100

97101
import java.io.File;
@@ -134,6 +138,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
134138
static final int MSG_UNBIND_METHOD = 3000;
135139
static final int MSG_BIND_METHOD = 3010;
136140

141+
static final int MSG_HARD_KEYBOARD_SWITCH_CHANGED = 4000;
142+
137143
static final long TIME_TO_RECONNECT = 10*1000;
138144

139145
static final int SECURE_SUGGESTION_SPANS_MAX_SIZE = 20;
@@ -156,6 +162,8 @@ public class InputMethodManagerService extends IInputMethodManager.Stub
156162
final HandlerCaller mCaller;
157163
private final InputMethodFileManager mFileManager;
158164
private final InputMethodAndSubtypeListManager mImListManager;
165+
private final HardKeyboardListener mHardKeyboardListener;
166+
private final WindowManagerService mWindowManagerService;
159167

160168
final InputBindResult mNoBinding = new InputBindResult(null, null, -1);
161169

@@ -360,6 +368,7 @@ public String toString() {
360368

361369
private AlertDialog.Builder mDialogBuilder;
362370
private AlertDialog mSwitchingDialog;
371+
private View mSwitchingDialogTitleView;
363372
private InputMethodInfo[] mIms;
364373
private int[] mSubtypeIds;
365374

@@ -528,7 +537,31 @@ public void sessionCreated(IInputMethodSession session) throws RemoteException {
528537
}
529538
}
530539

531-
public InputMethodManagerService(Context context) {
540+
private class HardKeyboardListener
541+
implements WindowManagerService.OnHardKeyboardStatusChangeListener {
542+
@Override
543+
public void onHardKeyboardStatusChange(boolean available, boolean enabled) {
544+
mHandler.sendMessage(mHandler.obtainMessage(
545+
MSG_HARD_KEYBOARD_SWITCH_CHANGED, available ? 1 : 0, enabled ? 1 : 0));
546+
}
547+
548+
public void handleHardKeyboardStatusChange(boolean available, boolean enabled) {
549+
if (DEBUG) {
550+
Slog.w(TAG, "HardKeyboardStatusChanged: available = " + available + ", enabled = "
551+
+ enabled);
552+
}
553+
synchronized(mMethodMap) {
554+
if (mSwitchingDialog != null && mSwitchingDialogTitleView != null
555+
&& mSwitchingDialog.isShowing()) {
556+
mSwitchingDialogTitleView.findViewById(
557+
com.android.internal.R.id.hard_keyboard_section).setVisibility(
558+
available ? View.VISIBLE : View.GONE);
559+
}
560+
}
561+
}
562+
}
563+
564+
public InputMethodManagerService(Context context, WindowManagerService windowManager) {
532565
mContext = context;
533566
mRes = context.getResources();
534567
mHandler = new Handler(this);
@@ -540,6 +573,8 @@ public void executeMessage(Message msg) {
540573
handleMessage(msg);
541574
}
542575
});
576+
mWindowManagerService = windowManager;
577+
mHardKeyboardListener = new HardKeyboardListener();
543578

544579
mImeSwitcherNotification = new Notification();
545580
mImeSwitcherNotification.icon = com.android.internal.R.drawable.ic_notification_ime_default;
@@ -633,6 +668,10 @@ public void systemReady(StatusBarManagerService statusBar) {
633668
updateImeWindowStatusLocked();
634669
mShowOngoingImeSwitcherForPhones = mRes.getBoolean(
635670
com.android.internal.R.bool.show_ongoing_ime_switcher);
671+
if (mShowOngoingImeSwitcherForPhones) {
672+
mWindowManagerService.setOnHardKeyboardStatusChangeListener(
673+
mHardKeyboardListener);
674+
}
636675
try {
637676
startInputInnerLocked();
638677
} catch (RuntimeException e) {
@@ -1994,6 +2033,12 @@ public boolean handleMessage(Message msg) {
19942033
Slog.w(TAG, "Client died receiving input method " + args.arg2);
19952034
}
19962035
return true;
2036+
2037+
// --------------------------------------------------------------
2038+
case MSG_HARD_KEYBOARD_SWITCH_CHANGED:
2039+
mHardKeyboardListener.handleHardKeyboardStatusChange(
2040+
msg.arg1 == 1, msg.arg2 == 1);
2041+
return true;
19972042
}
19982043
return false;
19992044
}
@@ -2204,12 +2249,10 @@ private void showInputMethodMenuInternal(boolean showSubtypes) {
22042249
}
22052250
}
22062251
}
2207-
22082252
final TypedArray a = context.obtainStyledAttributes(null,
22092253
com.android.internal.R.styleable.DialogPreference,
22102254
com.android.internal.R.attr.alertDialogStyle, 0);
22112255
mDialogBuilder = new AlertDialog.Builder(context)
2212-
.setTitle(com.android.internal.R.string.select_input_method)
22132256
.setOnCancelListener(new OnCancelListener() {
22142257
@Override
22152258
public void onCancel(DialogInterface dialog) {
@@ -2219,6 +2262,29 @@ public void onCancel(DialogInterface dialog) {
22192262
.setIcon(a.getDrawable(
22202263
com.android.internal.R.styleable.DialogPreference_dialogTitle));
22212264
a.recycle();
2265+
final LayoutInflater inflater =
2266+
(LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
2267+
final View tv = inflater.inflate(
2268+
com.android.internal.R.layout.input_method_switch_dialog_title, null);
2269+
mDialogBuilder.setCustomTitle(tv);
2270+
2271+
// Setup layout for a toggle switch of the hardware keyboard
2272+
mSwitchingDialogTitleView = tv;
2273+
mSwitchingDialogTitleView.findViewById(
2274+
com.android.internal.R.id.hard_keyboard_section).setVisibility(
2275+
mWindowManagerService.isHardKeyboardAvailable() ?
2276+
View.VISIBLE : View.GONE);
2277+
final Switch hardKeySwitch = ((Switch)mSwitchingDialogTitleView.findViewById(
2278+
com.android.internal.R.id.hard_keyboard_switch));
2279+
hardKeySwitch.setChecked(mWindowManagerService.isHardKeyboardEnabled());
2280+
hardKeySwitch.setOnCheckedChangeListener(
2281+
new OnCheckedChangeListener() {
2282+
@Override
2283+
public void onCheckedChanged(
2284+
CompoundButton buttonView, boolean isChecked) {
2285+
mWindowManagerService.setHardKeyboardEnabled(isChecked);
2286+
}
2287+
});
22222288

22232289
final ImeSubtypeListAdapter adapter = new ImeSubtypeListAdapter(context,
22242290
com.android.internal.R.layout.simple_list_item_2_single_choice, imList,

services/java/com/android/server/SystemServer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ public void run() {
274274
if (factoryTest != SystemServer.FACTORY_TEST_LOW_LEVEL) {
275275
try {
276276
Slog.i(TAG, "Input Method Service");
277-
imm = new InputMethodManagerService(context);
277+
imm = new InputMethodManagerService(context, wm);
278278
ServiceManager.addService(Context.INPUT_METHOD_SERVICE, imm);
279279
} catch (Throwable e) {
280280
reportWtf("starting Input Manager Service", e);

0 commit comments

Comments
 (0)