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

Commit 7682deac authored by PETER LIANG's avatar PETER LIANG Committed by Android (Google) Code Review
Browse files

Merge changes from topic "redesign shortcut chooser" into rvc-dev

* changes:
  Redesign for AccessibilityShortcutChooserActivity (3/n).
  Redesign for AccessibilityShortcutChooserActivity (2/n).
  Redesign for AccessibilityShortcutChooserActivity (1/n).
parents 96f705db fbd4bf7b
Loading
Loading
Loading
Loading
+0 −41
Original line number Diff line number Diff line
@@ -78,21 +78,6 @@ public final class ShortcutConstants {
        int LAUNCH_ACTIVITY = 3;
    }

    /**
     * Annotation for different shortcut target.
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            TargetType.ACCESSIBILITY_SERVICE,
            TargetType.ACCESSIBILITY_ACTIVITY,
            TargetType.WHITE_LISTING,
    })
    public @interface TargetType {
        int ACCESSIBILITY_SERVICE = 0;
        int ACCESSIBILITY_ACTIVITY = 1;
        int WHITE_LISTING = 2;
    }

    /**
     * Annotation for different shortcut menu mode.
     *
@@ -108,30 +93,4 @@ public final class ShortcutConstants {
        int LAUNCH = 0;
        int EDIT = 1;
    }

    /**
     * Annotation for align the element index of white listing feature
     * {@code WHITE_LISTING_FEATURES}.
     *
     * {@code COMPONENT_ID} is to get the service component name.
     * {@code LABEL_ID} is to get the service label text.
     * {@code ICON_ID} is to get the service icon.
     * {@code FRAGMENT_TYPE} is to get the service fragment type.
     * {@code SETTINGS_KEY} is to get the service settings key.
     */
    @Retention(RetentionPolicy.SOURCE)
    @IntDef({
            WhiteListingFeatureElementIndex.COMPONENT_ID,
            WhiteListingFeatureElementIndex.LABEL_ID,
            WhiteListingFeatureElementIndex.ICON_ID,
            WhiteListingFeatureElementIndex.FRAGMENT_TYPE,
            WhiteListingFeatureElementIndex.SETTINGS_KEY,
    })
    public @interface WhiteListingFeatureElementIndex {
        int COMPONENT_ID = 0;
        int LABEL_ID = 1;
        int ICON_ID = 2;
        int FRAGMENT_TYPE = 3;
        int SETTINGS_KEY = 4;
    }
}
+47 −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 com.android.internal.accessibility.util.ShortcutUtils.convertToKey;
import static com.android.internal.accessibility.util.ShortcutUtils.convertToUserType;
import static com.android.internal.accessibility.util.ShortcutUtils.isShortcutContained;

import android.accessibilityservice.AccessibilityShortcutInfo;
import android.annotation.NonNull;
import android.content.Context;
import android.view.accessibility.AccessibilityManager.ShortcutType;

import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType;

/**
 * Base class for creating accessibility activity target.
 */
class AccessibilityActivityTarget extends AccessibilityTarget {

    AccessibilityActivityTarget(Context context, @ShortcutType int shortcutType,
            @NonNull AccessibilityShortcutInfo shortcutInfo) {
        super(context,
                shortcutType,
                AccessibilityFragmentType.LAUNCH_ACTIVITY,
                isShortcutContained(context, shortcutType,
                        shortcutInfo.getComponentName().flattenToString()),
                shortcutInfo.getComponentName().flattenToString(),
                shortcutInfo.getActivityInfo().loadLabel(context.getPackageManager()),
                shortcutInfo.getActivityInfo().loadIcon(context.getPackageManager()),
                convertToKey(convertToUserType(shortcutType)));
    }
}
+49 −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 com.android.internal.accessibility.util.ShortcutUtils.convertToKey;
import static com.android.internal.accessibility.util.ShortcutUtils.convertToUserType;
import static com.android.internal.accessibility.util.ShortcutUtils.isShortcutContained;

import android.accessibilityservice.AccessibilityServiceInfo;
import android.annotation.NonNull;
import android.content.Context;
import android.view.accessibility.AccessibilityManager.ShortcutType;

import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType;

/**
 * Base class for creating accessibility service target with various fragment types related to
 * legacy type, invisible type and intuitive type.
 */
class AccessibilityServiceTarget extends AccessibilityTarget {

    AccessibilityServiceTarget(Context context, @ShortcutType int shortcutType,
            @AccessibilityFragmentType int fragmentType,
            @NonNull AccessibilityServiceInfo serviceInfo) {
        super(context,
                shortcutType,
                fragmentType,
                isShortcutContained(context, shortcutType,
                        serviceInfo.getComponentName().flattenToString()),
                serviceInfo.getComponentName().flattenToString(),
                serviceInfo.getResolveInfo().loadLabel(context.getPackageManager()),
                serviceInfo.getResolveInfo().loadIcon(context.getPackageManager()),
                convertToKey(convertToUserType(shortcutType)));
    }
}
+43 −680

File changed.

Preview size limit exceeded, changes collapsed.

+141 −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.accessibility.AccessibilityManager.ACCESSIBILITY_BUTTON;
import static android.view.accessibility.AccessibilityManager.ACCESSIBILITY_SHORTCUT_KEY;

import static com.android.internal.accessibility.util.ShortcutUtils.convertToUserType;
import static com.android.internal.accessibility.util.ShortcutUtils.optInValueToSettings;
import static com.android.internal.accessibility.util.ShortcutUtils.optOutValueFromSettings;

import android.annotation.NonNull;
import android.content.Context;
import android.graphics.drawable.Drawable;
import android.view.View;
import android.view.accessibility.AccessibilityManager;
import android.view.accessibility.AccessibilityManager.ShortcutType;

import com.android.internal.accessibility.common.ShortcutConstants;
import com.android.internal.accessibility.common.ShortcutConstants.AccessibilityFragmentType;
import com.android.internal.accessibility.dialog.TargetAdapter.ViewHolder;

/**
 * Abstract base class for creating various target related to accessibility service,
 * accessibility activity, and white listing feature.
 */
abstract class AccessibilityTarget implements TargetOperations, OnTargetSelectedListener,
        OnTargetCheckedChangeListener {
    private Context mContext;
    @ShortcutType
    private int mShortcutType;
    @AccessibilityFragmentType
    private int mFragmentType;
    private boolean mShortcutEnabled;
    private String mId;
    private CharSequence mLabel;
    private Drawable mIcon;
    private String mKey;

    AccessibilityTarget(Context context, @ShortcutType int shortcutType,
            @AccessibilityFragmentType int fragmentType, boolean isShortcutSwitched, String id,
            CharSequence label, Drawable icon, String key) {
        mContext = context;
        mShortcutType = shortcutType;
        mFragmentType = fragmentType;
        mShortcutEnabled = isShortcutSwitched;
        mId = id;
        mLabel = label;
        mIcon = icon;
        mKey = key;
    }

    @Override
    public void updateActionItem(@NonNull ViewHolder holder,
            @ShortcutConstants.ShortcutMenuMode int shortcutMenuMode) {
        final boolean isEditMenuMode =
                shortcutMenuMode == ShortcutConstants.ShortcutMenuMode.EDIT;

        holder.mCheckBoxView.setChecked(isEditMenuMode && isShortcutEnabled());
        holder.mCheckBoxView.setVisibility(isEditMenuMode ? View.VISIBLE : View.GONE);
        holder.mIconView.setImageDrawable(getIcon());
        holder.mLabelView.setText(getLabel());
        holder.mSwitchItem.setVisibility(View.GONE);
    }

    @Override
    public void onSelected() {
        final AccessibilityManager am =
                getContext().getSystemService(AccessibilityManager.class);
        switch (getShortcutType()) {
            case ACCESSIBILITY_BUTTON:
                am.notifyAccessibilityButtonClicked(getContext().getDisplayId(), getId());
                return;
            case ACCESSIBILITY_SHORTCUT_KEY:
                am.performAccessibilityShortcut(getId());
                return;
            default:
                throw new IllegalStateException("Unexpected shortcut type");
        }
    }

    @Override
    public void onCheckedChanged(boolean isChecked) {
        setShortcutEnabled(isChecked);
        if (isChecked) {
            optInValueToSettings(getContext(), convertToUserType(getShortcutType()), getId());
        } else {
            optOutValueFromSettings(getContext(), convertToUserType(getShortcutType()), getId());
        }
    }

    public void setShortcutEnabled(boolean enabled) {
        mShortcutEnabled = enabled;
    }

    public Context getContext() {
        return mContext;
    }

    public @ShortcutType int getShortcutType() {
        return mShortcutType;
    }

    public @AccessibilityFragmentType int getFragmentType() {
        return mFragmentType;
    }

    public boolean isShortcutEnabled() {
        return mShortcutEnabled;
    }

    public String getId() {
        return mId;
    }

    public CharSequence getLabel() {
        return mLabel;
    }

    public Drawable getIcon() {
        return mIcon;
    }

    public String getKey() {
        return mKey;
    }
}
Loading