Merge "Remove old PK settings pages that are unused" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
c3fecca761
@@ -1,38 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 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">
|
|
||||||
|
|
||||||
<ImageView android:id="@+id/titleDivider"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="1dip"
|
|
||||||
android:scaleType="fitXY"
|
|
||||||
android:gravity="fill_horizontal"
|
|
||||||
android:src="@android:drawable/divider_horizontal_dark"
|
|
||||||
android:contentDescription="@null" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="@string/keyboard_layout_dialog_switch_hint"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textColor="?android:attr/textColorAlertDialogListItem"
|
|
||||||
android:minHeight="48dp"
|
|
||||||
android:gravity="center" />
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
@@ -1,23 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<!-- Copyright (C) 2018 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
xmlns:settings="http://schemas.android.com/apk/res-auto"
|
|
||||||
android:key="keyboard_layout_picker"
|
|
||||||
android:title="@string/keyboard_layout_picker_title"
|
|
||||||
settings:controller="com.android.settings.inputmethod.KeyboardLayoutPickerController">
|
|
||||||
|
|
||||||
</PreferenceScreen>
|
|
@@ -130,7 +130,6 @@ import com.android.settings.gestures.PowerMenuSettings;
|
|||||||
import com.android.settings.gestures.SwipeToNotificationSettings;
|
import com.android.settings.gestures.SwipeToNotificationSettings;
|
||||||
import com.android.settings.gestures.SystemNavigationGestureSettings;
|
import com.android.settings.gestures.SystemNavigationGestureSettings;
|
||||||
import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
import com.android.settings.inputmethod.AvailableVirtualKeyboardFragment;
|
||||||
import com.android.settings.inputmethod.KeyboardLayoutPickerFragment;
|
|
||||||
import com.android.settings.inputmethod.KeyboardSettings;
|
import com.android.settings.inputmethod.KeyboardSettings;
|
||||||
import com.android.settings.inputmethod.ModifierKeysSettings;
|
import com.android.settings.inputmethod.ModifierKeysSettings;
|
||||||
import com.android.settings.inputmethod.NewKeyboardLayoutEnabledLocalesFragment;
|
import com.android.settings.inputmethod.NewKeyboardLayoutEnabledLocalesFragment;
|
||||||
@@ -310,7 +309,6 @@ public class SettingsGateway {
|
|||||||
PrintJobSettingsFragment.class.getName(),
|
PrintJobSettingsFragment.class.getName(),
|
||||||
TrustedCredentialsSettings.class.getName(),
|
TrustedCredentialsSettings.class.getName(),
|
||||||
PaymentSettings.class.getName(),
|
PaymentSettings.class.getName(),
|
||||||
KeyboardLayoutPickerFragment.class.getName(),
|
|
||||||
PhysicalKeyboardFragment.class.getName(),
|
PhysicalKeyboardFragment.class.getName(),
|
||||||
ZenModeSettings.class.getName(),
|
ZenModeSettings.class.getName(),
|
||||||
SoundSettings.class.getName(),
|
SoundSettings.class.getName(),
|
||||||
|
@@ -1,368 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.inputmethod;
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.app.Dialog;
|
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.DialogInterface;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
|
||||||
import android.hardware.input.InputManager;
|
|
||||||
import android.hardware.input.InputManager.InputDeviceListener;
|
|
||||||
import android.hardware.input.KeyboardLayout;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.InputDevice;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.ArrayAdapter;
|
|
||||||
import android.widget.CheckedTextView;
|
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.appcompat.app.AlertDialog;
|
|
||||||
import androidx.loader.app.LoaderManager.LoaderCallbacks;
|
|
||||||
import androidx.loader.content.AsyncTaskLoader;
|
|
||||||
import androidx.loader.content.Loader;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.core.instrumentation.InstrumentedDialogFragment;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
public class KeyboardLayoutDialogFragment extends InstrumentedDialogFragment
|
|
||||||
implements InputDeviceListener, LoaderCallbacks<KeyboardLayoutDialogFragment.Keyboards> {
|
|
||||||
private static final String KEY_INPUT_DEVICE_IDENTIFIER = "inputDeviceIdentifier";
|
|
||||||
|
|
||||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
|
||||||
private int mInputDeviceId = -1;
|
|
||||||
private InputManager mIm;
|
|
||||||
private KeyboardLayoutAdapter mAdapter;
|
|
||||||
|
|
||||||
public KeyboardLayoutDialogFragment() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public KeyboardLayoutDialogFragment(InputDeviceIdentifier inputDeviceIdentifier) {
|
|
||||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return SettingsEnums.DIALOG_KEYBOARD_LAYOUT;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Activity activity) {
|
|
||||||
super.onAttach(activity);
|
|
||||||
|
|
||||||
Context context = activity.getBaseContext();
|
|
||||||
mIm = (InputManager)context.getSystemService(Context.INPUT_SERVICE);
|
|
||||||
mAdapter = new KeyboardLayoutAdapter(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
if (savedInstanceState != null) {
|
|
||||||
mInputDeviceIdentifier = savedInstanceState.getParcelable(KEY_INPUT_DEVICE_IDENTIFIER);
|
|
||||||
}
|
|
||||||
|
|
||||||
getLoaderManager().initLoader(0, null, this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSaveInstanceState(Bundle outState) {
|
|
||||||
super.onSaveInstanceState(outState);
|
|
||||||
outState.putParcelable(KEY_INPUT_DEVICE_IDENTIFIER, mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Dialog onCreateDialog(Bundle savedInstanceState) {
|
|
||||||
Context context = getActivity();
|
|
||||||
LayoutInflater inflater = LayoutInflater.from(context);
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context)
|
|
||||||
.setTitle(R.string.keyboard_layout_dialog_title)
|
|
||||||
.setPositiveButton(R.string.keyboard_layout_dialog_setup_button,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
onSetupLayoutsButtonClicked();
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setSingleChoiceItems(mAdapter, -1,
|
|
||||||
new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
onKeyboardLayoutClicked(which);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setView(inflater.inflate(R.layout.keyboard_layout_dialog_switch_hint, null));
|
|
||||||
updateSwitchHintVisibility();
|
|
||||||
return builder.create();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResume() {
|
|
||||||
super.onResume();
|
|
||||||
|
|
||||||
mIm.registerInputDeviceListener(this, null);
|
|
||||||
|
|
||||||
InputDevice inputDevice =
|
|
||||||
mIm.getInputDeviceByDescriptor(mInputDeviceIdentifier.getDescriptor());
|
|
||||||
if (inputDevice == null) {
|
|
||||||
dismiss();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mInputDeviceId = inputDevice.getId();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onPause() {
|
|
||||||
mIm.unregisterInputDeviceListener(this);
|
|
||||||
mInputDeviceId = -1;
|
|
||||||
|
|
||||||
super.onPause();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCancel(DialogInterface dialog) {
|
|
||||||
super.onCancel(dialog);
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onSetupLayoutsButtonClicked() {
|
|
||||||
((OnSetupKeyboardLayoutsListener)getTargetFragment()).onSetupKeyboardLayouts(
|
|
||||||
mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
show(getActivity().getSupportFragmentManager(), "layout");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void onKeyboardLayoutClicked(int which) {
|
|
||||||
if (which >= 0 && which < mAdapter.getCount()) {
|
|
||||||
KeyboardLayout keyboardLayout = mAdapter.getItem(which);
|
|
||||||
if (keyboardLayout != null) {
|
|
||||||
mIm.setCurrentKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
|
||||||
keyboardLayout.getDescriptor());
|
|
||||||
}
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Loader<Keyboards> onCreateLoader(int id, Bundle args) {
|
|
||||||
return new KeyboardLayoutLoader(getActivity().getBaseContext(), mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadFinished(Loader<Keyboards> loader, Keyboards data) {
|
|
||||||
mAdapter.clear();
|
|
||||||
mAdapter.addAll(data.keyboardLayouts);
|
|
||||||
mAdapter.setCheckedItem(data.current);
|
|
||||||
AlertDialog dialog = (AlertDialog)getDialog();
|
|
||||||
if (dialog != null) {
|
|
||||||
dialog.getListView().setItemChecked(data.current, true);
|
|
||||||
}
|
|
||||||
updateSwitchHintVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoaderReset(Loader<Keyboards> loader) {
|
|
||||||
mAdapter.clear();
|
|
||||||
updateSwitchHintVisibility();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceAdded(int deviceId) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
|
||||||
getLoaderManager().restartLoader(0, null, this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceRemoved(int deviceId) {
|
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
|
||||||
dismiss();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateSwitchHintVisibility() {
|
|
||||||
AlertDialog dialog = (AlertDialog)getDialog();
|
|
||||||
if (dialog != null) {
|
|
||||||
View customPanel = dialog.findViewById(com.google.android.material.R.id.customPanel);
|
|
||||||
customPanel.setVisibility(mAdapter.getCount() > 1 ? View.VISIBLE : View.GONE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class KeyboardLayoutAdapter extends ArrayAdapter<KeyboardLayout> {
|
|
||||||
private final LayoutInflater mInflater;
|
|
||||||
private int mCheckedItem = -1;
|
|
||||||
|
|
||||||
public KeyboardLayoutAdapter(Context context) {
|
|
||||||
super(context, com.android.internal.R.layout.simple_list_item_2_single_choice);
|
|
||||||
mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCheckedItem(int position) {
|
|
||||||
mCheckedItem = position;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View getView(int position, View convertView, ViewGroup parent) {
|
|
||||||
KeyboardLayout item = getItem(position);
|
|
||||||
String label, collection;
|
|
||||||
if (item != null) {
|
|
||||||
label = item.getLabel();
|
|
||||||
collection = item.getCollection();
|
|
||||||
} else {
|
|
||||||
label = getContext().getString(R.string.keyboard_layout_default_label);
|
|
||||||
collection = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
boolean checked = (position == mCheckedItem);
|
|
||||||
if (collection.isEmpty()) {
|
|
||||||
return inflateOneLine(convertView, parent, label, checked);
|
|
||||||
} else {
|
|
||||||
return inflateTwoLine(convertView, parent, label, collection, checked);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private View inflateOneLine(View convertView, ViewGroup parent,
|
|
||||||
String label, boolean checked) {
|
|
||||||
View view = convertView;
|
|
||||||
if (view == null || isTwoLine(view)) {
|
|
||||||
view = mInflater.inflate(
|
|
||||||
com.android.internal.R.layout.simple_list_item_single_choice,
|
|
||||||
parent, false);
|
|
||||||
setTwoLine(view, false);
|
|
||||||
}
|
|
||||||
CheckedTextView headline = (CheckedTextView) view.findViewById(android.R.id.text1);
|
|
||||||
headline.setText(label);
|
|
||||||
headline.setChecked(checked);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
private View inflateTwoLine(View convertView, ViewGroup parent,
|
|
||||||
String label, String collection, boolean checked) {
|
|
||||||
View view = convertView;
|
|
||||||
if (view == null || !isTwoLine(view)) {
|
|
||||||
view = mInflater.inflate(
|
|
||||||
com.android.internal.R.layout.simple_list_item_2_single_choice,
|
|
||||||
parent, false);
|
|
||||||
setTwoLine(view, true);
|
|
||||||
}
|
|
||||||
TextView headline = (TextView) view.findViewById(android.R.id.text1);
|
|
||||||
TextView subText = (TextView) view.findViewById(android.R.id.text2);
|
|
||||||
RadioButton radioButton =
|
|
||||||
(RadioButton)view.findViewById(com.android.internal.R.id.radio);
|
|
||||||
headline.setText(label);
|
|
||||||
subText.setText(collection);
|
|
||||||
radioButton.setChecked(checked);
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isTwoLine(View view) {
|
|
||||||
return view.getTag() == Boolean.TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void setTwoLine(View view, boolean twoLine) {
|
|
||||||
view.setTag(Boolean.valueOf(twoLine));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static final class KeyboardLayoutLoader extends AsyncTaskLoader<Keyboards> {
|
|
||||||
private final InputDeviceIdentifier mInputDeviceIdentifier;
|
|
||||||
|
|
||||||
public KeyboardLayoutLoader(Context context, InputDeviceIdentifier inputDeviceIdentifier) {
|
|
||||||
super(context);
|
|
||||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Keyboards loadInBackground() {
|
|
||||||
Keyboards keyboards = new Keyboards();
|
|
||||||
InputManager im = (InputManager)getContext().getSystemService(Context.INPUT_SERVICE);
|
|
||||||
if (mInputDeviceIdentifier == null || InputPeripheralsSettingsUtils.getInputDevice(
|
|
||||||
im, mInputDeviceIdentifier) == null) {
|
|
||||||
keyboards.keyboardLayouts.add(null); // default layout
|
|
||||||
keyboards.current = 0;
|
|
||||||
return keyboards;
|
|
||||||
}
|
|
||||||
String[] keyboardLayoutDescriptors = im.getEnabledKeyboardLayoutsForInputDevice(
|
|
||||||
mInputDeviceIdentifier);
|
|
||||||
for (String keyboardLayoutDescriptor : keyboardLayoutDescriptors) {
|
|
||||||
KeyboardLayout keyboardLayout = im.getKeyboardLayout(keyboardLayoutDescriptor);
|
|
||||||
if (keyboardLayout != null) {
|
|
||||||
keyboards.keyboardLayouts.add(keyboardLayout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(keyboards.keyboardLayouts);
|
|
||||||
|
|
||||||
String currentKeyboardLayoutDescriptor =
|
|
||||||
im.getCurrentKeyboardLayoutForInputDevice(mInputDeviceIdentifier);
|
|
||||||
if (currentKeyboardLayoutDescriptor != null) {
|
|
||||||
final int numKeyboardLayouts = keyboards.keyboardLayouts.size();
|
|
||||||
for (int i = 0; i < numKeyboardLayouts; i++) {
|
|
||||||
if (keyboards.keyboardLayouts.get(i).getDescriptor().equals(
|
|
||||||
currentKeyboardLayoutDescriptor)) {
|
|
||||||
keyboards.current = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (keyboards.keyboardLayouts.isEmpty()) {
|
|
||||||
keyboards.keyboardLayouts.add(null); // default layout
|
|
||||||
keyboards.current = 0;
|
|
||||||
}
|
|
||||||
return keyboards;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStartLoading() {
|
|
||||||
super.onStartLoading();
|
|
||||||
forceLoad();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStopLoading() {
|
|
||||||
super.onStopLoading();
|
|
||||||
cancelLoad();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final class Keyboards {
|
|
||||||
public final ArrayList<KeyboardLayout> keyboardLayouts = new ArrayList<KeyboardLayout>();
|
|
||||||
public int current = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnSetupKeyboardLayoutsListener {
|
|
||||||
public void onSetupKeyboardLayouts(InputDeviceIdentifier mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -1,164 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.inputmethod;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
|
||||||
import android.hardware.input.InputManager;
|
|
||||||
import android.hardware.input.KeyboardLayout;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.preference.Preference;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
import androidx.preference.SwitchPreferenceCompat;
|
|
||||||
import androidx.preference.TwoStatePreference;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
import com.android.settingslib.core.lifecycle.LifecycleObserver;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStart;
|
|
||||||
import com.android.settingslib.core.lifecycle.events.OnStop;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class KeyboardLayoutPickerController extends BasePreferenceController implements
|
|
||||||
InputManager.InputDeviceListener, LifecycleObserver, OnStart, OnStop {
|
|
||||||
|
|
||||||
private final InputManager mIm;
|
|
||||||
private final Map<TwoStatePreference, KeyboardLayout> mPreferenceMap;
|
|
||||||
|
|
||||||
private Fragment mParent;
|
|
||||||
private int mInputDeviceId;
|
|
||||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
|
||||||
private KeyboardLayout[] mKeyboardLayouts;
|
|
||||||
private PreferenceScreen mScreen;
|
|
||||||
|
|
||||||
|
|
||||||
public KeyboardLayoutPickerController(Context context, String key) {
|
|
||||||
super(context, key);
|
|
||||||
mIm = (InputManager) context.getSystemService(Context.INPUT_SERVICE);
|
|
||||||
mInputDeviceId = -1;
|
|
||||||
mPreferenceMap = new HashMap<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initialize(Fragment parent, InputDeviceIdentifier inputDeviceIdentifier) {
|
|
||||||
mParent = parent;
|
|
||||||
mInputDeviceIdentifier = inputDeviceIdentifier;
|
|
||||||
mKeyboardLayouts = mIm.getKeyboardLayoutsForInputDevice(mInputDeviceIdentifier);
|
|
||||||
Arrays.sort(mKeyboardLayouts);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStart() {
|
|
||||||
mIm.registerInputDeviceListener(this, null);
|
|
||||||
if (mInputDeviceIdentifier == null
|
|
||||||
|| InputPeripheralsSettingsUtils.getInputDevice(mIm, mInputDeviceIdentifier)
|
|
||||||
== null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mInputDeviceId =
|
|
||||||
InputPeripheralsSettingsUtils.getInputDevice(mIm,
|
|
||||||
mInputDeviceIdentifier).getId();
|
|
||||||
updateCheckedState();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onStop() {
|
|
||||||
mIm.unregisterInputDeviceListener(this);
|
|
||||||
mInputDeviceId = -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void displayPreference(PreferenceScreen screen) {
|
|
||||||
super.displayPreference(screen);
|
|
||||||
mScreen = screen;
|
|
||||||
createPreferenceHierarchy();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getAvailabilityStatus() {
|
|
||||||
return AVAILABLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean handlePreferenceTreeClick(Preference preference) {
|
|
||||||
if (!(preference instanceof TwoStatePreference switchPref)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
final KeyboardLayout layout = mPreferenceMap.get(switchPref);
|
|
||||||
if (layout != null) {
|
|
||||||
final boolean checked = switchPref.isChecked();
|
|
||||||
if (checked) {
|
|
||||||
mIm.addKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
|
||||||
layout.getDescriptor());
|
|
||||||
} else {
|
|
||||||
mIm.removeKeyboardLayoutForInputDevice(mInputDeviceIdentifier,
|
|
||||||
layout.getDescriptor());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceAdded(int deviceId) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceRemoved(int deviceId) {
|
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
|
||||||
mParent.getActivity().finish();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onInputDeviceChanged(int deviceId) {
|
|
||||||
if (mInputDeviceId >= 0 && deviceId == mInputDeviceId) {
|
|
||||||
updateCheckedState();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateCheckedState() {
|
|
||||||
final String[] enabledKeyboardLayouts = mIm.getEnabledKeyboardLayoutsForInputDevice(
|
|
||||||
mInputDeviceIdentifier);
|
|
||||||
Arrays.sort(enabledKeyboardLayouts);
|
|
||||||
|
|
||||||
for (Map.Entry<TwoStatePreference, KeyboardLayout> entry : mPreferenceMap.entrySet()) {
|
|
||||||
entry.getKey().setChecked(Arrays.binarySearch(enabledKeyboardLayouts,
|
|
||||||
entry.getValue().getDescriptor()) >= 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void createPreferenceHierarchy() {
|
|
||||||
if (mKeyboardLayouts == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (KeyboardLayout layout : mKeyboardLayouts) {
|
|
||||||
final TwoStatePreference pref = new SwitchPreferenceCompat(mScreen.getContext());
|
|
||||||
pref.setTitle(layout.getLabel());
|
|
||||||
pref.setSummary(layout.getCollection());
|
|
||||||
// TODO: Waiting for new API to use a prefix with special number to setKey
|
|
||||||
pref.setKey(layout.getDescriptor());
|
|
||||||
mScreen.addPreference(pref);
|
|
||||||
mPreferenceMap.put(pref, layout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@@ -1,64 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.inputmethod;
|
|
||||||
|
|
||||||
import android.app.settings.SettingsEnums;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
|
||||||
import android.hardware.input.InputManager;
|
|
||||||
|
|
||||||
import com.android.settings.R;
|
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
|
||||||
|
|
||||||
public class KeyboardLayoutPickerFragment extends DashboardFragment {
|
|
||||||
|
|
||||||
private static final String TAG = "KeyboardLayoutPicker";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Intent extra: The input device descriptor of the keyboard whose keyboard
|
|
||||||
* layout is to be changed.
|
|
||||||
*/
|
|
||||||
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getMetricsCategory() {
|
|
||||||
return SettingsEnums.INPUTMETHOD_KEYBOARD;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
|
|
||||||
final InputDeviceIdentifier inputDeviceIdentifier = getActivity().getIntent().
|
|
||||||
getParcelableExtra(EXTRA_INPUT_DEVICE_IDENTIFIER);
|
|
||||||
final InputManager im = context.getSystemService(InputManager.class);
|
|
||||||
if (InputPeripheralsSettingsUtils.getInputDevice(im, inputDeviceIdentifier) == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
use(KeyboardLayoutPickerController.class).initialize(this /*parent*/,
|
|
||||||
inputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getLogTag() {
|
|
||||||
return TAG;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected int getPreferenceScreenResId() {
|
|
||||||
return R.xml.keyboard_layout_picker_fragment;
|
|
||||||
}
|
|
||||||
}
|
|
@@ -20,12 +20,10 @@ import android.app.Activity;
|
|||||||
import android.app.settings.SettingsEnums;
|
import android.app.settings.SettingsEnums;
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
import android.hardware.input.InputDeviceIdentifier;
|
||||||
import android.hardware.input.InputManager;
|
import android.hardware.input.InputManager;
|
||||||
import android.hardware.input.InputSettings;
|
import android.hardware.input.InputSettings;
|
||||||
import android.hardware.input.KeyboardLayout;
|
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
@@ -47,7 +45,6 @@ import androidx.preference.TwoStatePreference;
|
|||||||
|
|
||||||
import com.android.internal.util.Preconditions;
|
import com.android.internal.util.Preconditions;
|
||||||
import com.android.settings.R;
|
import com.android.settings.R;
|
||||||
import com.android.settings.Settings;
|
|
||||||
import com.android.settings.core.SubSettingLauncher;
|
import com.android.settings.core.SubSettingLauncher;
|
||||||
import com.android.settings.dashboard.DashboardFragment;
|
import com.android.settings.dashboard.DashboardFragment;
|
||||||
import com.android.settings.keyboard.Flags;
|
import com.android.settings.keyboard.Flags;
|
||||||
@@ -66,8 +63,7 @@ import java.util.Objects;
|
|||||||
// controllers between here and A11y Setting page.
|
// controllers between here and A11y Setting page.
|
||||||
@SearchIndexable
|
@SearchIndexable
|
||||||
public final class PhysicalKeyboardFragment extends DashboardFragment
|
public final class PhysicalKeyboardFragment extends DashboardFragment
|
||||||
implements InputManager.InputDeviceListener,
|
implements InputManager.InputDeviceListener {
|
||||||
KeyboardLayoutDialogFragment.OnSetupKeyboardLayoutsListener {
|
|
||||||
|
|
||||||
private static final String KEYBOARD_OPTIONS_CATEGORY = "keyboard_options_category";
|
private static final String KEYBOARD_OPTIONS_CATEGORY = "keyboard_options_category";
|
||||||
private static final String KEYBOARD_A11Y_CATEGORY = "keyboard_a11y_category";
|
private static final String KEYBOARD_A11Y_CATEGORY = "keyboard_a11y_category";
|
||||||
@@ -79,6 +75,7 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper";
|
private static final String KEYBOARD_SHORTCUTS_HELPER = "keyboard_shortcuts_helper";
|
||||||
private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings";
|
private static final String MODIFIER_KEYS_SETTINGS = "modifier_keys_settings";
|
||||||
private static final String EXTRA_AUTO_SELECTION = "auto_selection";
|
private static final String EXTRA_AUTO_SELECTION = "auto_selection";
|
||||||
|
public static final String EXTRA_INPUT_DEVICE_IDENTIFIER = "input_device_identifier";
|
||||||
private static final String TAG = "KeyboardAndTouchA11yFragment";
|
private static final String TAG = "KeyboardAndTouchA11yFragment";
|
||||||
private static final Uri sVirtualKeyboardSettingsUri = Secure.getUriFor(
|
private static final Uri sVirtualKeyboardSettingsUri = Secure.getUriFor(
|
||||||
Secure.SHOW_IME_WITH_HARD_KEYBOARD);
|
Secure.SHOW_IME_WITH_HARD_KEYBOARD);
|
||||||
@@ -112,13 +109,8 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
private TwoStatePreference mAccessibilityStickyKeys = null;
|
private TwoStatePreference mAccessibilityStickyKeys = null;
|
||||||
@Nullable
|
@Nullable
|
||||||
private TwoStatePreference mAccessibilityMouseKeys = null;
|
private TwoStatePreference mAccessibilityMouseKeys = null;
|
||||||
|
|
||||||
private Intent mIntentWaitingForResult;
|
|
||||||
private boolean mSupportsFirmwareUpdate;
|
private boolean mSupportsFirmwareUpdate;
|
||||||
|
|
||||||
static final String EXTRA_BT_ADDRESS = "extra_bt_address";
|
|
||||||
private String mBluetoothAddress;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getLogTag() {
|
protected String getLogTag() {
|
||||||
return TAG;
|
return TAG;
|
||||||
@@ -197,8 +189,7 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
mKeyboardA11yCategory.setVisible(false);
|
mKeyboardA11yCategory.setVisible(false);
|
||||||
}
|
}
|
||||||
InputDeviceIdentifier inputDeviceIdentifier = activity.getIntent().getParcelableExtra(
|
InputDeviceIdentifier inputDeviceIdentifier = activity.getIntent().getParcelableExtra(
|
||||||
KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
EXTRA_INPUT_DEVICE_IDENTIFIER, InputDeviceIdentifier.class);
|
||||||
InputDeviceIdentifier.class);
|
|
||||||
int intentFromWhere =
|
int intentFromWhere =
|
||||||
activity.getIntent().getIntExtra(android.provider.Settings.EXTRA_ENTRYPOINT, -1);
|
activity.getIntent().getIntExtra(android.provider.Settings.EXTRA_ENTRYPOINT, -1);
|
||||||
if (intentFromWhere != -1) {
|
if (intentFromWhere != -1) {
|
||||||
@@ -360,13 +351,6 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showKeyboardLayoutDialog(InputDeviceIdentifier inputDeviceIdentifier) {
|
|
||||||
KeyboardLayoutDialogFragment fragment = new KeyboardLayoutDialogFragment(
|
|
||||||
inputDeviceIdentifier);
|
|
||||||
fragment.setTargetFragment(this, 0);
|
|
||||||
fragment.show(getActivity().getSupportFragmentManager(), "keyboardLayout");
|
|
||||||
}
|
|
||||||
|
|
||||||
private void showEnabledLocalesKeyboardLayoutList(InputDeviceIdentifier inputDeviceIdentifier) {
|
private void showEnabledLocalesKeyboardLayoutList(InputDeviceIdentifier inputDeviceIdentifier) {
|
||||||
Bundle arguments = new Bundle();
|
Bundle arguments = new Bundle();
|
||||||
arguments.putParcelable(InputPeripheralsSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
arguments.putParcelable(InputPeripheralsSettingsUtils.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
||||||
@@ -505,45 +489,6 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onSetupKeyboardLayouts(InputDeviceIdentifier inputDeviceIdentifier) {
|
|
||||||
final Intent intent = new Intent(Intent.ACTION_MAIN);
|
|
||||||
intent.setClass(getActivity(), Settings.KeyboardLayoutPickerActivity.class);
|
|
||||||
intent.putExtra(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
|
||||||
inputDeviceIdentifier);
|
|
||||||
mIntentWaitingForResult = intent;
|
|
||||||
startActivityForResult(intent, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
|
||||||
|
|
||||||
if (mIntentWaitingForResult != null) {
|
|
||||||
InputDeviceIdentifier inputDeviceIdentifier = mIntentWaitingForResult
|
|
||||||
.getParcelableExtra(KeyboardLayoutPickerFragment.EXTRA_INPUT_DEVICE_IDENTIFIER,
|
|
||||||
InputDeviceIdentifier.class);
|
|
||||||
mIntentWaitingForResult = null;
|
|
||||||
showKeyboardLayoutDialog(inputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static String getLayoutLabel(@NonNull InputDevice device,
|
|
||||||
@NonNull Context context, @NonNull InputManager im) {
|
|
||||||
final String currentLayoutDesc =
|
|
||||||
im.getCurrentKeyboardLayoutForInputDevice(device.getIdentifier());
|
|
||||||
if (currentLayoutDesc == null) {
|
|
||||||
return context.getString(R.string.keyboard_layout_default_label);
|
|
||||||
}
|
|
||||||
final KeyboardLayout currentLayout = im.getKeyboardLayout(currentLayoutDesc);
|
|
||||||
if (currentLayout == null) {
|
|
||||||
return context.getString(R.string.keyboard_layout_default_label);
|
|
||||||
}
|
|
||||||
// If current layout is specified but the layout is null, just return an empty string
|
|
||||||
// instead of falling back to R.string.keyboard_layout_default_label.
|
|
||||||
return TextUtils.emptyIfNull(currentLayout.getLabel());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
static List<HardKeyboardDeviceInfo> getHardKeyboards(@NonNull Context context) {
|
static List<HardKeyboardDeviceInfo> getHardKeyboards(@NonNull Context context) {
|
||||||
final List<HardKeyboardDeviceInfo> keyboards = new ArrayList<>();
|
final List<HardKeyboardDeviceInfo> keyboards = new ArrayList<>();
|
||||||
@@ -559,7 +504,6 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
keyboards.add(new HardKeyboardDeviceInfo(
|
keyboards.add(new HardKeyboardDeviceInfo(
|
||||||
device.getName(),
|
device.getName(),
|
||||||
device.getIdentifier(),
|
device.getIdentifier(),
|
||||||
getLayoutLabel(device, context, im),
|
|
||||||
device.getBluetoothAddress(),
|
device.getBluetoothAddress(),
|
||||||
device.getVendorId(),
|
device.getVendorId(),
|
||||||
device.getProductId()));
|
device.getProductId()));
|
||||||
@@ -572,12 +516,8 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
if (result != 0) {
|
if (result != 0) {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
result = a.mDeviceIdentifier.getDescriptor().compareTo(
|
return a.mDeviceIdentifier.getDescriptor().compareTo(
|
||||||
b.mDeviceIdentifier.getDescriptor());
|
b.mDeviceIdentifier.getDescriptor());
|
||||||
if (result != 0) {
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
return collator.compare(a.mLayoutLabel, b.mLayoutLabel);
|
|
||||||
});
|
});
|
||||||
return keyboards;
|
return keyboards;
|
||||||
}
|
}
|
||||||
@@ -587,8 +527,6 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
public final String mDeviceName;
|
public final String mDeviceName;
|
||||||
@NonNull
|
@NonNull
|
||||||
public final InputDeviceIdentifier mDeviceIdentifier;
|
public final InputDeviceIdentifier mDeviceIdentifier;
|
||||||
@NonNull
|
|
||||||
public final String mLayoutLabel;
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public final String mBluetoothAddress;
|
public final String mBluetoothAddress;
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -599,13 +537,11 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
public HardKeyboardDeviceInfo(
|
public HardKeyboardDeviceInfo(
|
||||||
@Nullable String deviceName,
|
@Nullable String deviceName,
|
||||||
@NonNull InputDeviceIdentifier deviceIdentifier,
|
@NonNull InputDeviceIdentifier deviceIdentifier,
|
||||||
@NonNull String layoutLabel,
|
|
||||||
@Nullable String bluetoothAddress,
|
@Nullable String bluetoothAddress,
|
||||||
@NonNull int vendorId,
|
@NonNull int vendorId,
|
||||||
@NonNull int productId) {
|
@NonNull int productId) {
|
||||||
mDeviceName = TextUtils.emptyIfNull(deviceName);
|
mDeviceName = TextUtils.emptyIfNull(deviceName);
|
||||||
mDeviceIdentifier = deviceIdentifier;
|
mDeviceIdentifier = deviceIdentifier;
|
||||||
mLayoutLabel = layoutLabel;
|
|
||||||
mBluetoothAddress = bluetoothAddress;
|
mBluetoothAddress = bluetoothAddress;
|
||||||
mVendorId = vendorId;
|
mVendorId = vendorId;
|
||||||
mProductId = productId;
|
mProductId = productId;
|
||||||
@@ -625,9 +561,6 @@ public final class PhysicalKeyboardFragment extends DashboardFragment
|
|||||||
if (!Objects.equals(mDeviceIdentifier, that.mDeviceIdentifier)) {
|
if (!Objects.equals(mDeviceIdentifier, that.mDeviceIdentifier)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!TextUtils.equals(mLayoutLabel, that.mLayoutLabel)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!TextUtils.equals(mBluetoothAddress, that.mBluetoothAddress)) {
|
if (!TextUtils.equals(mBluetoothAddress, that.mBluetoothAddress)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -48,7 +48,6 @@ com.android.settings.fuelgauge.InactiveApps
|
|||||||
com.android.settings.fuelgauge.RestrictedAppDetails
|
com.android.settings.fuelgauge.RestrictedAppDetails
|
||||||
com.android.settings.IccLockSettings
|
com.android.settings.IccLockSettings
|
||||||
com.android.settings.inputmethod.InputMethodAndSubtypeEnabler
|
com.android.settings.inputmethod.InputMethodAndSubtypeEnabler
|
||||||
com.android.settings.inputmethod.KeyboardLayoutPickerFragment
|
|
||||||
com.android.settings.inputmethod.SpellCheckersSettings
|
com.android.settings.inputmethod.SpellCheckersSettings
|
||||||
com.android.settings.location.LocationPersonalSettings
|
com.android.settings.location.LocationPersonalSettings
|
||||||
com.android.settings.location.LocationWorkProfileSettings
|
com.android.settings.location.LocationWorkProfileSettings
|
||||||
|
@@ -1,196 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (C) 2018 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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package com.android.settings.inputmethod;
|
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
|
||||||
|
|
||||||
import static org.mockito.ArgumentMatchers.any;
|
|
||||||
import static org.mockito.ArgumentMatchers.anyString;
|
|
||||||
import static org.mockito.Mockito.never;
|
|
||||||
import static org.mockito.Mockito.verify;
|
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.hardware.input.InputDeviceIdentifier;
|
|
||||||
import android.hardware.input.InputManager;
|
|
||||||
import android.hardware.input.KeyboardLayout;
|
|
||||||
import android.view.InputDevice;
|
|
||||||
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.fragment.app.FragmentActivity;
|
|
||||||
import androidx.preference.PreferenceManager;
|
|
||||||
import androidx.preference.PreferenceScreen;
|
|
||||||
|
|
||||||
import com.android.settings.core.BasePreferenceController;
|
|
||||||
import com.android.settings.testutils.shadow.ShadowInputDevice;
|
|
||||||
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
|
||||||
import org.junit.runner.RunWith;
|
|
||||||
import org.mockito.Mock;
|
|
||||||
import org.mockito.MockitoAnnotations;
|
|
||||||
import org.robolectric.Robolectric;
|
|
||||||
import org.robolectric.RobolectricTestRunner;
|
|
||||||
import org.robolectric.RuntimeEnvironment;
|
|
||||||
import org.robolectric.annotation.Config;
|
|
||||||
import org.robolectric.shadows.ShadowApplication;
|
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
|
||||||
@Config(shadows = {
|
|
||||||
com.android.settings.testutils.shadow.ShadowFragment.class,
|
|
||||||
})
|
|
||||||
public class KeyboardLayoutPickerControllerTest {
|
|
||||||
|
|
||||||
@Mock
|
|
||||||
private Fragment mFragment;
|
|
||||||
@Mock
|
|
||||||
private InputManager mInputManager;
|
|
||||||
|
|
||||||
private Context mContext;
|
|
||||||
private InputDeviceIdentifier mInputDeviceIdentifier;
|
|
||||||
private KeyboardLayoutPickerController mController;
|
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() {
|
|
||||||
MockitoAnnotations.initMocks(this);
|
|
||||||
final ShadowApplication shadowContext = ShadowApplication.getInstance();
|
|
||||||
shadowContext.setSystemService(Context.INPUT_SERVICE, mInputManager);
|
|
||||||
|
|
||||||
mContext = RuntimeEnvironment.application;
|
|
||||||
mInputDeviceIdentifier = new InputDeviceIdentifier("descriptor", 1, 1);
|
|
||||||
mController = new KeyboardLayoutPickerController(mContext, "pref_key");
|
|
||||||
|
|
||||||
initializeOneLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void isAlwaysAvailable() {
|
|
||||||
assertThat(mController.getAvailabilityStatus())
|
|
||||||
.isEqualTo(BasePreferenceController.AVAILABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLifecycle_onStart_shouldRegisterInputManager() {
|
|
||||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
|
||||||
when(mFragment.getActivity()).thenReturn(activity);
|
|
||||||
|
|
||||||
mController.onStart();
|
|
||||||
|
|
||||||
// Register is called, but unregister should not be called.
|
|
||||||
verify(mInputManager).registerInputDeviceListener(mController, null);
|
|
||||||
verify(mInputManager, never()).unregisterInputDeviceListener(mController);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLifecycle_onStart_NoInputDevice_shouldReturn() {
|
|
||||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
|
||||||
when(mInputManager.getInputDeviceByDescriptor(anyString())).thenReturn(null);
|
|
||||||
when(mFragment.getActivity()).thenReturn(activity);
|
|
||||||
|
|
||||||
mController.onStart();
|
|
||||||
verify(mInputManager, never()).getEnabledKeyboardLayoutsForInputDevice(any());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLifecycle_onStop_shouldCancelRegisterInputManager() {
|
|
||||||
mController.onStop();
|
|
||||||
|
|
||||||
// Unregister is called, but register should not be called.
|
|
||||||
verify(mInputManager).unregisterInputDeviceListener(mController);
|
|
||||||
verify(mInputManager, never()).registerInputDeviceListener(mController, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_createPreferenceHierarchy_shouldAddOnePreference() {
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
|
|
||||||
// We create a keyboard layouts in initializeOneLayout()
|
|
||||||
assertThat(screen.getPreferenceCount()).isEqualTo(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void test_createPreferenceHierarchy_shouldAddTwoPreference() {
|
|
||||||
initializeTwoLayouts();
|
|
||||||
final PreferenceManager preferenceManager = new PreferenceManager(mContext);
|
|
||||||
final PreferenceScreen screen = preferenceManager.createPreferenceScreen(mContext);
|
|
||||||
|
|
||||||
mController.displayPreference(screen);
|
|
||||||
|
|
||||||
// We create two keyboard layouts in initializeOneLayout()
|
|
||||||
assertThat(screen.getPreferenceCount()).isEqualTo(2);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(shadows = ShadowInputDevice.class)
|
|
||||||
public void testOnDeviceRemove_getSameDevice_shouldFinish() {
|
|
||||||
final int TARGET_DEVICE_ID = 1;
|
|
||||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
|
||||||
final String[] enableKeyboardLayouts = {"layout1"};
|
|
||||||
final InputDevice device = ShadowInputDevice.makeInputDevicebyId(TARGET_DEVICE_ID);
|
|
||||||
|
|
||||||
when(mFragment.getActivity()).thenReturn(activity);
|
|
||||||
when(mInputManager.getInputDeviceByDescriptor(anyString())).thenReturn(device);
|
|
||||||
when(mInputManager.getEnabledKeyboardLayoutsForInputDevice(
|
|
||||||
any(InputDeviceIdentifier.class))).thenReturn(enableKeyboardLayouts);
|
|
||||||
|
|
||||||
mController.onStart();
|
|
||||||
mController.onInputDeviceRemoved(TARGET_DEVICE_ID);
|
|
||||||
|
|
||||||
assertThat(activity.isFinishing()).isTrue();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Config(shadows = ShadowInputDevice.class)
|
|
||||||
public void testOnDeviceRemove_getDifferentDevice_shouldNotFinish() {
|
|
||||||
final int TARGET_DEVICE_ID = 1;
|
|
||||||
final int ANOTHER_DEVICE_ID = 2;
|
|
||||||
final FragmentActivity activity = Robolectric.setupActivity(FragmentActivity.class);
|
|
||||||
final String[] enableKeyboardLayouts = {"layout1"};
|
|
||||||
final InputDevice device = ShadowInputDevice.makeInputDevicebyId(TARGET_DEVICE_ID);
|
|
||||||
|
|
||||||
when(mFragment.getActivity()).thenReturn(activity);
|
|
||||||
when(mInputManager.getInputDeviceByDescriptor(anyString())).thenReturn(device);
|
|
||||||
when(mInputManager.getEnabledKeyboardLayoutsForInputDevice(
|
|
||||||
any(InputDeviceIdentifier.class))).thenReturn(enableKeyboardLayouts);
|
|
||||||
|
|
||||||
mController.onStart();
|
|
||||||
mController.onInputDeviceRemoved(ANOTHER_DEVICE_ID);
|
|
||||||
|
|
||||||
assertThat(activity.isFinishing()).isFalse();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeOneLayout() {
|
|
||||||
final KeyboardLayout[] keyboardLayouts = {new KeyboardLayout("", "", "", 1, null, 0, 1, 1)};
|
|
||||||
when(mInputManager.getKeyboardLayoutsForInputDevice(
|
|
||||||
any(InputDeviceIdentifier.class))).thenReturn(
|
|
||||||
keyboardLayouts);
|
|
||||||
|
|
||||||
mController.initialize(mFragment, mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initializeTwoLayouts() {
|
|
||||||
final KeyboardLayout[] keyboardLayouts = {new KeyboardLayout("", "", "", 1, null, 0, 1, 1),
|
|
||||||
new KeyboardLayout("", "", "", 2, null, 0, 2, 2)};
|
|
||||||
when(mInputManager.getKeyboardLayoutsForInputDevice(any(InputDeviceIdentifier.class))).
|
|
||||||
thenReturn(keyboardLayouts);
|
|
||||||
|
|
||||||
mController.initialize(mFragment, mInputDeviceIdentifier);
|
|
||||||
}
|
|
||||||
}
|
|
@@ -90,7 +90,6 @@ public class KeyboardSettingsPreferenceControllerTest {
|
|||||||
new HardKeyboardDeviceInfo(
|
new HardKeyboardDeviceInfo(
|
||||||
"TEST_DEVICE",
|
"TEST_DEVICE",
|
||||||
mInputDeviceIdentifier,
|
mInputDeviceIdentifier,
|
||||||
"TEST_DEVICE_LABEL",
|
|
||||||
address,
|
address,
|
||||||
VENDOR_ID,
|
VENDOR_ID,
|
||||||
PRODUCT_ID);
|
PRODUCT_ID);
|
||||||
|
@@ -50,7 +50,6 @@ import java.util.List;
|
|||||||
public class PhysicalKeyboardPreferenceControllerTest {
|
public class PhysicalKeyboardPreferenceControllerTest {
|
||||||
|
|
||||||
private static final String DEVICE_NAME = "deviceName";
|
private static final String DEVICE_NAME = "deviceName";
|
||||||
private static final String LAYOUT_LABEL = "deviceLayutLabel";
|
|
||||||
private static final String BLUETOOTHADDRESS = "deviceBluetoothAddress";
|
private static final String BLUETOOTHADDRESS = "deviceBluetoothAddress";
|
||||||
private static final int VENDOR_ID = 123;
|
private static final int VENDOR_ID = 123;
|
||||||
private static final int PRODUCT_ID = 456;
|
private static final int PRODUCT_ID = 456;
|
||||||
@@ -85,7 +84,6 @@ public class PhysicalKeyboardPreferenceControllerTest {
|
|||||||
keyboards.add(new HardKeyboardDeviceInfo(
|
keyboards.add(new HardKeyboardDeviceInfo(
|
||||||
DEVICE_NAME,
|
DEVICE_NAME,
|
||||||
mIdentifier,
|
mIdentifier,
|
||||||
LAYOUT_LABEL,
|
|
||||||
BLUETOOTHADDRESS,
|
BLUETOOTHADDRESS,
|
||||||
VENDOR_ID,
|
VENDOR_ID,
|
||||||
PRODUCT_ID));
|
PRODUCT_ID));
|
||||||
|
Reference in New Issue
Block a user