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

Commit 559aa077 authored by Cosmin Băieș's avatar Cosmin Băieș
Browse files

Revamp IME switcher menu

This revamps the UI of the IME switcher menu, to make it more modern,
and provide a seamless IME and subtype switching experience from the
system, regardless of the selected IME.

This also reworks the internals of the InputMethodMenuController to
decouple it from the InputMethodManagerService, and simplify it where
possible.

Test: atest
  InputMethodManagerTest#testShowInputMethodPicker
  InputMethodManagerTest#testInputMethodPickerSwitchIme
  InputMethodPickerTest#testInputMethodPicker_hidesUntrustedOverlays
  InputMethodPickerTest#testShowInputMethodPicker_noDismissWhenOverlayPopup
  InputMethodPickerTest#testShowImePickerOnExternalDisplay
  ImeInsetsVisibilityTest#testEditTextPositionAndPersistWhenAboveImeWindowShown
  InputMethodServiceLifecycleTest#testImeSwitchingWithoutWindowFocusAfterDisplayOffOnFull
  InputMethodServiceLifecycleTest#testImeSwitchingWithoutWindowFocusAfterDisplayOffOnInstant
Bug: 311791923
Flag: android.view.inputmethod.ime_switcher_revamp
Change-Id: I1005cb6b10682f3e91a7ed847c290fcc206b5faa
parent 7da46d3d
Loading
Loading
Loading
Loading
+5 −1
Original line number Diff line number Diff line
@@ -216,7 +216,11 @@ public final class NavigationBarView extends FrameLayout {
                oldConfig.getLayoutDirection() != mConfiguration.getLayoutDirection();

        if (densityChange || dirChange) {
            mImeSwitcherIcon = getDrawable(com.android.internal.R.drawable.ic_ime_switcher);
            final int switcherResId = Flags.imeSwitcherRevamp()
                    ? com.android.internal.R.drawable.ic_ime_switcher_new
                    : com.android.internal.R.drawable.ic_ime_switcher;

            mImeSwitcherIcon = getDrawable(switcherResId);
        }
        if (orientationChange || densityChange || dirChange) {
            mBackIcon = getBackDrawable();
+4 −3
Original line number Diff line number Diff line
@@ -891,12 +891,13 @@ public final class InputMethodInfo implements Parcelable {
    @FlaggedApi(android.view.inputmethod.Flags.FLAG_IME_SWITCHER_REVAMP_API)
    @Nullable
    public Intent createImeLanguageSettingsActivityIntent() {
        if (TextUtils.isEmpty(mLanguageSettingsActivityName)) {
        final var activityName = !TextUtils.isEmpty(mLanguageSettingsActivityName)
                ? mLanguageSettingsActivityName : mSettingsActivityName;
        if (TextUtils.isEmpty(activityName)) {
            return null;
        }
        return new Intent(ACTION_IME_LANGUAGE_SETTINGS).setComponent(
                new ComponentName(getServiceInfo().packageName,
                        mLanguageSettingsActivityName)
                new ComponentName(getServiceInfo().packageName, activityName)
        );
    }

+98 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.internal.widget;

import android.annotation.AttrRes;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.Px;
import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.FrameLayout;

import com.android.internal.R;

/**
 * This custom subclass of FrameLayout enforces that its calculated height be no larger than the
 * given maximum height (if any).
 *
 * @hide
 */
public class MaxHeightFrameLayout extends FrameLayout {

    private int mMaxHeight = Integer.MAX_VALUE;

    public MaxHeightFrameLayout(@NonNull Context context) {
        this(context, null);
    }

    public MaxHeightFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MaxHeightFrameLayout(@NonNull Context context, @Nullable AttributeSet attrs,
            @AttrRes int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public MaxHeightFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        final TypedArray a = context.obtainStyledAttributes(
                attrs, R.styleable.MaxHeightFrameLayout, defStyleAttr, defStyleRes);
        saveAttributeDataForStyleable(context, R.styleable.MaxHeightFrameLayout,
                attrs, a, defStyleAttr, defStyleRes);

        setMaxHeight(a.getDimensionPixelSize(R.styleable.MaxHeightFrameLayout_maxHeight,
                Integer.MAX_VALUE));
    }

    /**
     * Gets the maximum height of this view, in pixels.
     *
     * @see #setMaxHeight(int)
     *
     * @attr ref android.R.styleable#MaxHeightFrameLayout_maxHeight
     */
    @Px
    public int getMaxHeight() {
        return mMaxHeight;
    }

    /**
     * Sets the maximum height this view can have.
     *
     * @param maxHeight the maximum height, in pixels
     *
     * @see #getMaxHeight()
     *
     * @attr ref android.R.styleable#MaxHeightFrameLayout_maxHeight
     */
    public void setMaxHeight(@Px int maxHeight) {
        mMaxHeight = maxHeight;
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        if (MeasureSpec.getSize(heightMeasureSpec) > mMaxHeight) {
            final int mode = MeasureSpec.getMode(heightMeasureSpec);
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(mMaxHeight, mode);
        }
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }
}
+26 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2024 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.
-->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="20dp"
        android:height="20dp"
        android:viewportWidth="24"
        android:viewportHeight="24">
    <path
        android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM18.92,8h-2.95c-0.32,-1.25 -0.78,-2.45 -1.38,-3.56 1.84,0.63 3.37,1.91 4.33,3.56zM12,4.04c0.83,1.2 1.48,2.53 1.91,3.96h-3.82c0.43,-1.43 1.08,-2.76 1.91,-3.96zM4.26,14C4.1,13.36 4,12.69 4,12s0.1,-1.36 0.26,-2h3.38c-0.08,0.66 -0.14,1.32 -0.14,2 0,0.68 0.06,1.34 0.14,2L4.26,14zM5.08,16h2.95c0.32,1.25 0.78,2.45 1.38,3.56 -1.84,-0.63 -3.37,-1.9 -4.33,-3.56zM8.03,8L5.08,8c0.96,-1.66 2.49,-2.93 4.33,-3.56C8.81,5.55 8.35,6.75 8.03,8zM12,19.96c-0.83,-1.2 -1.48,-2.53 -1.91,-3.96h3.82c-0.43,1.43 -1.08,2.76 -1.91,3.96zM14.34,14L9.66,14c-0.09,-0.66 -0.16,-1.32 -0.16,-2 0,-0.68 0.07,-1.35 0.16,-2h4.68c0.09,0.65 0.16,1.32 0.16,2 0,0.68 -0.07,1.34 -0.16,2zM14.59,19.56c0.6,-1.11 1.06,-2.31 1.38,-3.56h2.95c-0.96,1.65 -2.49,2.93 -4.33,3.56zM16.36,14c0.08,-0.66 0.14,-1.32 0.14,-2 0,-0.68 -0.06,-1.34 -0.14,-2h3.38c0.16,0.64 0.26,1.31 0.26,2s-0.1,1.36 -0.26,2h-3.38z"
        android:fillColor="#FFFFFFFF"/>
</vector>
+42 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  Copyright (C) 2024 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.
-->

<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetTop="6dp"
    android:insetBottom="6dp">
    <ripple android:color="?android:attr/colorControlHighlight">
        <item android:id="@android:id/mask">
            <shape android:shape="rectangle">
                <corners android:radius="28dp"/>
                <solid android:color="@color/white"/>
            </shape>
        </item>

        <item>
            <shape android:shape="rectangle">
                <corners android:radius="28dp"/>
                <solid android:color="@color/transparent"/>
                <stroke android:color="?attr/materialColorPrimary"
                    android:width="1dp"/>
                <padding android:left="16dp"
                    android:top="8dp"
                    android:right="16dp"
                    android:bottom="8dp"/>
            </shape>
        </item>
    </ripple>
</inset>
Loading