Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit c043de9f authored by Abodunrinwa Toki's avatar Abodunrinwa Toki Committed by Android (Google) Code Review
Browse files

Merge "Settings app: Include package icons in list of virtual keyboards"

parents 2e634f87 567ebd68
Loading
Loading
Loading
Loading
+23 −0
Original line number Diff line number Diff line
<?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"/>
+12 −0
Original line number Diff line number Diff line
@@ -20,6 +20,9 @@ import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
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.support.v7.preference.PreferenceScreen;
import android.view.inputmethod.InputMethodInfo;
@@ -38,6 +41,8 @@ import java.util.List;
public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFragment
        implements InputMethodPreference.OnSavePreferenceListener {

    private static final Drawable NO_ICON = new ColorDrawable(Color.TRANSPARENT);

    private final ArrayList<InputMethodPreference> mInputMethodPreferenceList = new ArrayList<>();
    private InputMethodSettingValuesWrapper mInputMethodSettingValues;
    private InputMethodManager mImm;
@@ -93,8 +98,15 @@ public final class AvailableVirtualKeyboardFragment extends SettingsPreferenceFr
            final InputMethodInfo imi = imis.get(i);
            final boolean isAllowedByOrganization = permittedList == null
                    || permittedList.contains(imi.getPackageName());
            Drawable icon;
            try {
                icon = getActivity().getPackageManager().getApplicationIcon(imi.getPackageName());
            } catch (Exception e) {
                icon = NO_ICON;
            }
            final InputMethodPreference pref = new InputMethodPreference(
                    context, imi, true, isAllowedByOrganization, this);
            pref.setIcon(icon);
            mInputMethodPreferenceList.add(pref);
        }
        final Collator collator = Collator.getInstance();
+4 −3
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
        OnPreferenceChangeListener {
    private static final String TAG = InputMethodPreference.class.getSimpleName();
    private static final String EMPTY_TEXT = "";
    private static final int SETTINGS_ICON_LAYOUT = R.layout.preference_settings_icon_widget;

    interface OnSavePreferenceListener {
        /**
@@ -97,8 +98,8 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
        mIsAllowedByOrganization = isAllowedByOrganization;
        mOnSaveListener = onSaveListener;
        if (!isImeEnabler) {
            // Hide switch widget.
            setWidgetLayoutResource(0 /* widgetLayoutResId */);
            // Replace switch widget with settings icon.
            setWidgetLayoutResource(SETTINGS_ICON_LAYOUT);
        }
        // Disable on/off switch texts.
        setSwitchTextOn(EMPTY_TEXT);
@@ -134,7 +135,7 @@ class InputMethodPreference extends RestrictedSwitchPreference implements OnPref
    private boolean isImeEnabler() {
        // If this {@link SwitchPreference} doesn't have a widget layout, we explicitly hide the
        // switch widget at constructor.
        return getWidgetLayoutResource() != 0;
        return getWidgetLayoutResource() != SETTINGS_ICON_LAYOUT;
    }

    @Override
+14 −0
Original line number Diff line number Diff line
@@ -19,6 +19,9 @@ package com.android.settings.inputmethod;
import android.app.Activity;
import android.app.admin.DevicePolicyManager;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.v7.preference.Preference;
import android.view.inputmethod.InputMethodInfo;
@@ -38,6 +41,7 @@ import java.util.List;
public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {

    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 InputMethodManager mImm;
@@ -78,12 +82,21 @@ public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
            final InputMethodInfo imi = imis.get(i);
            final boolean isAllowedByOrganization = permittedList == null
                    || 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(
                    context,
                    imi,
                    false,  /* isImeEnabler */
                    isAllowedByOrganization,
                    null  /* this can be null since isImeEnabler is false */);
            pref.setIcon(icon);
            mInputMethodPreferenceList.add(pref);
        }
        final Collator collator = Collator.getInstance();
@@ -101,6 +114,7 @@ public final class VirtualKeyboardFragment extends SettingsPreferenceFragment {
            InputMethodAndSubtypeUtil.removeUnnecessaryNonPersistentPreference(pref);
            pref.updatePreferenceViews();
        }
        mAddVirtualKeyboardScreen.setIcon(R.drawable.ic_add);
        mAddVirtualKeyboardScreen.setOrder(N);
        getPreferenceScreen().addPreference(mAddVirtualKeyboardScreen);
    }