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

Commit ea2d4bf1 authored by Jason Hsu's avatar Jason Hsu Committed by Android (Google) Code Review
Browse files

Merge changes from topic "rhedjao_a11y_button_rollback" into rvc-dev

* changes:
  Rollback chooser menu to version Q behavior for accessibility button (2/n).
  Rollback chooser menu to version Q behavior for accessibility button (1/n).
parents f6e6cb11 0589ab0a
Loading
Loading
Loading
Loading
+3 −12
Original line number Diff line number Diff line
@@ -124,7 +124,7 @@ public final class AccessibilityManager {
     * Activity action: Launch UI to manage which accessibility service or feature is assigned
     * to the navigation bar Accessibility button.
     * <p>
     * Input: {@link #EXTRA_SHORTCUT_TYPE} is the shortcut type.
     * Input: Nothing.
     * </p>
     * <p>
     * Output: Nothing.
@@ -137,16 +137,7 @@ public final class AccessibilityManager {
            "com.android.internal.intent.action.CHOOSE_ACCESSIBILITY_BUTTON";

    /**
     * Used as an int extra field in {@link #ACTION_CHOOSE_ACCESSIBILITY_BUTTON} intent to specify
     * the shortcut type.
     *
     * @hide
     */
    public static final String EXTRA_SHORTCUT_TYPE =
            "com.android.internal.intent.extra.SHORTCUT_TYPE";

    /**
     * Used as an int value for {@link #EXTRA_SHORTCUT_TYPE} to represent the accessibility button
     * Used as an int value for accessibility chooser activity to represent the accessibility button
     * shortcut type.
     *
     * @hide
@@ -154,7 +145,7 @@ public final class AccessibilityManager {
    public static final int ACCESSIBILITY_BUTTON = 0;

    /**
     * Used as an int value for {@link #EXTRA_SHORTCUT_TYPE} to represent hardware key shortcut,
     * Used as an int value for accessibility chooser activity to represent hardware key shortcut,
     * such as volume key button.
     *
     * @hide
+5 −0
Original line number Diff line number Diff line
@@ -27,6 +27,11 @@ import java.lang.annotation.RetentionPolicy;
public final class ShortcutConstants {
    private ShortcutConstants() {}

    /**
     * Package name of the accessibility chooser and used for {@link android.content.Intent}.
     */
    public static final String CHOOSER_PACKAGE_NAME = "android";

    public static final char SERVICES_SEPARATOR = ':';

    /**
+94 −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 com.android.internal.accessibility.dialog.AccessibilityTargetHelper.getTargets;

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 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, ACCESSIBILITY_BUTTON));

        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();
        });
    }
}
+3 −11
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import static com.android.internal.accessibility.common.ShortcutConstants.Shortc
import static com.android.internal.accessibility.dialog.AccessibilityTargetHelper.createEnableDialogContentView;
import static com.android.internal.accessibility.dialog.AccessibilityTargetHelper.getInstalledTargets;
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;
@@ -33,7 +32,6 @@ import android.content.res.TypedArray;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.view.accessibility.AccessibilityManager;
import android.widget.AdapterView;

import com.android.internal.R;
@@ -47,7 +45,7 @@ import java.util.List;
 */
public class AccessibilityShortcutChooserActivity extends Activity {
    @ShortcutType
    private int mShortcutType;
    private final int mShortcutType = ACCESSIBILITY_SHORTCUT_KEY;
    private final List<AccessibilityTarget> mTargets = new ArrayList<>();
    private AlertDialog mMenuDialog;
    private AlertDialog mPermissionDialog;
@@ -62,12 +60,6 @@ public class AccessibilityShortcutChooserActivity extends Activity {
            requestWindowFeature(Window.FEATURE_NO_TITLE);
        }

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

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

        final String selectDialogTitle =
@@ -149,10 +141,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;
    }
}
Loading