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

Commit b8bf55c8 authored by Peter_Liang's avatar Peter_Liang
Browse files

Rollback chooser menu to version Q behavior for accessibility button (1/n).

1. Replace ACCESSIBILITY_BUTTON_TARGET_COMPONENT key with
ACCESSIBILITY_BUTTON_TARGETS key.
2. Rollback to version Q widgets.

Bug: 151294664
Test: manual test
Change-Id: Ibaa3b058418476e58291bfb95a1935dbf5c70e25
parent 3a507cbf
Loading
Loading
Loading
Loading
+102 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility.dialog;

import static android.view.WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;

import static com.android.internal.accessibility.dialog.AccessibilityTargetHelper.getTargets;
import static com.android.internal.util.Preconditions.checkArgument;

import android.annotation.Nullable;
import android.app.Activity;
import android.os.Bundle;
import android.provider.Settings;
import android.text.TextUtils;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.widget.GridView;
import android.widget.TextView;

import com.android.internal.R;
import com.android.internal.widget.ResolverDrawerLayout;

import java.util.ArrayList;
import java.util.List;

/**
 * Activity used to display and persist a service or feature target for the Accessibility button.
 */
public class AccessibilityButtonChooserActivity extends Activity {
    private final List<AccessibilityTarget> mTargets = new ArrayList<>();

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.accessibility_button_chooser);

        final int shortcutType = getIntent().getIntExtra(AccessibilityManager.EXTRA_SHORTCUT_TYPE,
                /* unexpectedShortcutType */ -1);
        final boolean existInShortcutType = (shortcutType == ACCESSIBILITY_BUTTON)
                || (shortcutType == ACCESSIBILITY_SHORTCUT_KEY);
        checkArgument(existInShortcutType, "Unexpected shortcut type: " + shortcutType);

        final ResolverDrawerLayout rdl = findViewById(R.id.contentPanel);
        if (rdl != null) {
            rdl.setOnDismissedListener(this::finish);
        }

        final String component = Settings.Secure.getString(getContentResolver(),
                Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT);

        final AccessibilityManager accessibilityManager =
                getSystemService(AccessibilityManager.class);
        final boolean isTouchExploreOn =
                accessibilityManager.isTouchExplorationEnabled();
        final boolean isGestureNavigateEnabled =
                NAV_BAR_MODE_GESTURAL == getResources().getInteger(
                        com.android.internal.R.integer.config_navBarInteractionMode);

        if (isGestureNavigateEnabled) {
            final TextView promptPrologue = findViewById(R.id.accessibility_button_prompt_prologue);
            promptPrologue.setText(isTouchExploreOn
                    ? R.string.accessibility_gesture_3finger_prompt_text
                    : R.string.accessibility_gesture_prompt_text);
        }

        if (TextUtils.isEmpty(component)) {
            final TextView prompt = findViewById(R.id.accessibility_button_prompt);
            if (isGestureNavigateEnabled) {
                prompt.setText(isTouchExploreOn
                        ? R.string.accessibility_gesture_3finger_instructional_text
                        : R.string.accessibility_gesture_instructional_text);
            }
            prompt.setVisibility(View.VISIBLE);
        }

        mTargets.addAll(getTargets(this, shortcutType));

        final GridView gridview = findViewById(R.id.accessibility_button_chooser_grid);
        gridview.setAdapter(new ButtonTargetAdapter(mTargets));
        gridview.setOnItemClickListener((parent, view, position, id) -> {
            final String key = Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
            Settings.Secure.putString(getContentResolver(), key, mTargets.get(position).getId());
            finish();
        });
    }
}
+2 −2
Original line number Diff line number Diff line
@@ -149,10 +149,10 @@ public class AccessibilityShortcutChooserActivity extends Activity {

    private void updateDialogListeners() {
        final boolean isEditMenuMode =
                (mTargetAdapter.getShortcutMenuMode() == ShortcutMenuMode.EDIT);
                mTargetAdapter.getShortcutMenuMode() == ShortcutMenuMode.EDIT;
        final int selectDialogTitleId = R.string.accessibility_select_shortcut_menu_title;
        final int editDialogTitleId =
                (mShortcutType == ACCESSIBILITY_BUTTON)
                mShortcutType == ACCESSIBILITY_BUTTON
                        ? R.string.accessibility_edit_shortcut_menu_button_title
                        : R.string.accessibility_edit_shortcut_menu_volume_title;

+68 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.accessibility.dialog;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.internal.R;

import java.util.List;

/**
 * Extension for {@link TargetAdapter} and used for AccessibilityButtonChooserActivity.
 */
class ButtonTargetAdapter extends TargetAdapter {
    private List<AccessibilityTarget> mTargets;

    ButtonTargetAdapter(List<AccessibilityTarget> targets) {
        mTargets = targets;
    }

    @Override
    public int getCount() {
        return mTargets.size();
    }

    @Override
    public Object getItem(int position) {
        return mTargets.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final Context context = parent.getContext();
        final View root = LayoutInflater.from(context).inflate(
                R.layout.accessibility_button_chooser_item, parent, /* attachToRoot= */
                false);
        final AccessibilityTarget target = mTargets.get(position);
        final ImageView iconView = root.findViewById(R.id.accessibility_button_target_icon);
        final TextView labelView = root.findViewById(R.id.accessibility_button_target_label);
        iconView.setImageDrawable(target.getIcon());
        labelView.setText(target.getLabel());
        return root;
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -151,7 +151,7 @@ public final class ShortcutUtils {
    public static String convertToKey(@UserShortcutType int type) {
        switch (type) {
            case UserShortcutType.SOFTWARE:
                return Settings.Secure.ACCESSIBILITY_BUTTON_TARGET_COMPONENT;
                return Settings.Secure.ACCESSIBILITY_BUTTON_TARGETS;
            case UserShortcutType.HARDWARE:
                return Settings.Secure.ACCESSIBILITY_SHORTCUT_TARGET_SERVICE;
            case UserShortcutType.TRIPLETAP:
+14 −0
Original line number Diff line number Diff line
@@ -5072,6 +5072,20 @@
                  android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden"
                  android:process=":ui"
                  android:visibleToInstantApps="true">
            <intent-filter>
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
        <activity android:name="com.android.internal.accessibility.dialog.AccessibilityButtonChooserActivity"
                  android:exported="false"
                  android:theme="@style/Theme.DeviceDefault.Resolver"
                  android:finishOnCloseSystemDialogs="true"
                  android:excludeFromRecents="true"
                  android:documentLaunchMode="never"
                  android:relinquishTaskIdentity="true"
                  android:configChanges="screenSize|smallestScreenSize|screenLayout|orientation|keyboard|keyboardHidden"
                  android:process=":ui"
                  android:visibleToInstantApps="true">
            <intent-filter>
                <action android:name="com.android.internal.intent.action.CHOOSE_ACCESSIBILITY_BUTTON" />
                <category android:name="android.intent.category.DEFAULT" />
Loading