Merge "Settings app: Include package icons in list of virtual keyboards"
This commit is contained in:
committed by
Android (Google) Code Review
commit
c043de9fbf
23
res/layout/preference_settings_icon_widget.xml
Normal file
23
res/layout/preference_settings_icon_widget.xml
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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
|
||||||
|
-->
|
||||||
|
|
||||||
|
<ImageView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:src="@drawable/ic_settings_24dp"
|
||||||
|
android:tint="@color/material_grey_600"
|
||||||
|
android:contentDescription="@null"/>
|
@@ -20,6 +20,9 @@ import android.app.Activity;
|
|||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.preference.PreferenceScreen;
|
import android.support.v7.preference.PreferenceScreen;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
@@ -38,6 +41,8 @@ import java.util.List;
|
|||||||
public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFragment
|
public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFragment
|
||||||
implements InputMethodPreference.OnSavePreferenceListener {
|
implements InputMethodPreference.OnSavePreferenceListener {
|
||||||
|
|
||||||
|
private static final Drawable NO_ICON = new ColorDrawable(Color.TRANSPARENT);
|
||||||
|
|
||||||
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
||||||
private InputMethodSettingValuesWrapper mInputMethodSettingValues;
|
private InputMethodSettingValuesWrapper mInputMethodSettingValues;
|
||||||
private InputMethodManager mImm;
|
private InputMethodManager mImm;
|
||||||
@@ -93,8 +98,15 @@ public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFr
|
|||||||
final InputMethodInfo imi = imis.get(i);
|
final InputMethodInfo imi = imis.get(i);
|
||||||
final boolean isAllowedByOrganization = permittedList == null
|
final boolean isAllowedByOrganization = permittedList == null
|
||||||
|| permittedList.contains(imi.getPackageName());
|
|| permittedList.contains(imi.getPackageName());
|
||||||
|
Drawable icon;
|
||||||
|
try {
|
||||||
|
icon = getActivity().getPackageManager().getApplicationIcon(imi.getPackageName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
icon = NO_ICON;
|
||||||
|
}
|
||||||
final InputMethodPreference pref = new InputMethodPreference(
|
final InputMethodPreference pref = new InputMethodPreference(
|
||||||
context, imi, true, isAllowedByOrganization, this);
|
context, imi, true, isAllowedByOrganization, this);
|
||||||
|
pref.setIcon(icon);
|
||||||
mInputMethodPreferenceList.add(pref);
|
mInputMethodPreferenceList.add(pref);
|
||||||
}
|
}
|
||||||
final Collator collator = Collator.getInstance();
|
final Collator collator = Collator.getInstance();
|
||||||
|
@@ -54,6 +54,7 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
OnPreferenceChangeListener {
|
OnPreferenceChangeListener {
|
||||||
private static final String TAG = InputMethodPreference.class.getSimpleName();
|
private static final String TAG = InputMethodPreference.class.getSimpleName();
|
||||||
private static final String EMPTY_TEXT = "";
|
private static final String EMPTY_TEXT = "";
|
||||||
|
private static final int SETTINGS_ICON_LAYOUT = R.layout.preference_settings_icon_widget;
|
||||||
|
|
||||||
interface OnSavePreferenceListener {
|
interface OnSavePreferenceListener {
|
||||||
/**
|
/**
|
||||||
@@ -97,8 +98,8 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
mIsAllowedByOrganization = isAllowedByOrganization;
|
mIsAllowedByOrganization = isAllowedByOrganization;
|
||||||
mOnSaveListener = onSaveListener;
|
mOnSaveListener = onSaveListener;
|
||||||
if (!isImeEnabler) {
|
if (!isImeEnabler) {
|
||||||
// Hide switch widget.
|
// Replace switch widget with settings icon.
|
||||||
setWidgetLayoutResource(0 /* widgetLayoutResId */);
|
setWidgetLayoutResource(SETTINGS_ICON_LAYOUT);
|
||||||
}
|
}
|
||||||
// Disable on/off switch texts.
|
// Disable on/off switch texts.
|
||||||
setSwitchTextOn(EMPTY_TEXT);
|
setSwitchTextOn(EMPTY_TEXT);
|
||||||
@@ -134,7 +135,7 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
|
|||||||
private boolean isImeEnabler() {
|
private boolean isImeEnabler() {
|
||||||
// If this {@link SwitchPreference} doesn't have a widget layout, we explicitly hide the
|
// If this {@link SwitchPreference} doesn't have a widget layout, we explicitly hide the
|
||||||
// switch widget at constructor.
|
// switch widget at constructor.
|
||||||
return getWidgetLayoutResource() != 0;
|
return getWidgetLayoutResource() != SETTINGS_ICON_LAYOUT;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@@ -19,6 +19,9 @@ package com.android.settings.inputmethod;
|
|||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.app.admin.DevicePolicyManager;
|
import android.app.admin.DevicePolicyManager;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.drawable.ColorDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.preference.Preference;
|
import android.support.v7.preference.Preference;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
@@ -38,6 +41,7 @@ import java.util.List;
|
|||||||
public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
|
public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
|
||||||
|
|
||||||
private static final String ADD_VIRTUAL_KEYBOARD_SCREEN = "add_virtual_keyboard_screen";
|
private static final String ADD_VIRTUAL_KEYBOARD_SCREEN = "add_virtual_keyboard_screen";
|
||||||
|
private static final Drawable NO_ICON = new ColorDrawable(Color.TRANSPARENT);
|
||||||
|
|
||||||
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
|
||||||
private InputMethodManager mImm;
|
private InputMethodManager mImm;
|
||||||
@@ -78,12 +82,21 @@ public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
|
|||||||
final InputMethodInfo imi = imis.get(i);
|
final InputMethodInfo imi = imis.get(i);
|
||||||
final boolean isAllowedByOrganization = permittedList == null
|
final boolean isAllowedByOrganization = permittedList == null
|
||||||
|| permittedList.contains(imi.getPackageName());
|
|| permittedList.contains(imi.getPackageName());
|
||||||
|
Drawable icon;
|
||||||
|
try {
|
||||||
|
// TODO: Consider other ways to retrieve an icon to show here.
|
||||||
|
icon = getActivity().getPackageManager().getApplicationIcon(imi.getPackageName());
|
||||||
|
} catch (Exception e) {
|
||||||
|
// TODO: Consider handling the error differently perhaps by showing default icons.
|
||||||
|
icon = NO_ICON;
|
||||||
|
}
|
||||||
final InputMethodPreference pref = new InputMethodPreference(
|
final InputMethodPreference pref = new InputMethodPreference(
|
||||||
context,
|
context,
|
||||||
imi,
|
imi,
|
||||||
false, /* isImeEnabler */
|
false, /* isImeEnabler */
|
||||||
isAllowedByOrganization,
|
isAllowedByOrganization,
|
||||||
null /* this can be null since isImeEnabler is false */);
|
null /* this can be null since isImeEnabler is false */);
|
||||||
|
pref.setIcon(icon);
|
||||||
mInputMethodPreferenceList.add(pref);
|
mInputMethodPreferenceList.add(pref);
|
||||||
}
|
}
|
||||||
final Collator collator = Collator.getInstance();
|
final Collator collator = Collator.getInstance();
|
||||||
@@ -101,6 +114,7 @@ public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
|
|||||||
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
|
InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
|
||||||
pref.updatePreferenceViews();
|
pref.updatePreferenceViews();
|
||||||
}
|
}
|
||||||
|
mAddVirtualKeyboardScreen.setIcon(R.drawable.ic_add);
|
||||||
mAddVirtualKeyboardScreen.setOrder(N);
|
mAddVirtualKeyboardScreen.setOrder(N);
|
||||||
getPreferenceScreen().addPreference(mAddVirtualKeyboardScreen);
|
getPreferenceScreen().addPreference(mAddVirtualKeyboardScreen);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user