Files
packages_apps_Settings/src/com/android/settings/accessibility/AccessibilityUtil.java
jasonwshsu 3d94a57d97 Accessibility shortcut secondary action - divide different fragment for different fragment type
Different accessibility service fragment type have different UI.
- AccessibilityServiceFragmentType.LEGACY will use LegacyAccessibilityServicePreferenceFragment
- AccessibilityServiceFragmentType.INVISIBLE will use InvisibleToggleAccessibilityServicePreferenceFragment
- AccessibilityServiceFragmentType.INTUITIVE will use ToggleAccessibilityServicePreferenceFragment

Bug: 142530063
Test: Manual
Change-Id: Ib32a4f97514450e5c0d29e99c22935efecf8b6df
2019-12-26 11:40:11 +08:00

90 lines
3.4 KiB
Java

/*
* Copyright (C) 2019 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.settings.accessibility;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.content.Context;
import android.os.Build;
import android.provider.Settings;
import androidx.annotation.IntDef;
import com.android.settings.R;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
/** Provides utility methods to accessibility settings only. */
final class AccessibilityUtil {
private AccessibilityUtil(){}
/**
* Annotation for different accessibilityService fragment UI type.
*
* {@code LEGACY} for displaying appearance aligned with sdk version Q accessibility service
* page, but only hardware shortcut allowed.
* {@code INVISIBLE} for displaying appearance without switch bar.
* {@code INTUITIVE} for displaying appearance with new design.
*/
@Retention(RetentionPolicy.SOURCE)
@IntDef({
AccessibilityServiceFragmentType.LEGACY,
AccessibilityServiceFragmentType.INVISIBLE,
AccessibilityServiceFragmentType.INTUITIVE,
})
public @interface AccessibilityServiceFragmentType {
int LEGACY = 0;
int INVISIBLE = 1;
int INTUITIVE = 2;
}
/**
* Return On/Off string according to the setting which specifies the integer value 1 or 0. This
* setting is defined in the secure system settings {@link android.provider.Settings.Secure}.
*/
static CharSequence getSummary(Context context, String settingsSecureKey) {
final boolean enabled = Settings.Secure.getInt(context.getContentResolver(),
settingsSecureKey, 0) == 1;
final int resId = enabled ? R.string.accessibility_feature_state_on
: R.string.accessibility_feature_state_off;
return context.getResources().getText(resId);
}
/**
* Gets the corresponding fragment type of a given accessibility service
*
* @param accessibilityServiceInfo The accessibilityService's info
* @return int from {@link AccessibilityServiceFragmentType}
*/
static @AccessibilityServiceFragmentType int getAccessibilityServiceFragmentType(
AccessibilityServiceInfo accessibilityServiceInfo) {
final int targetSdk = accessibilityServiceInfo.getResolveInfo()
.serviceInfo.applicationInfo.targetSdkVersion;
final boolean requestA11yButton = (accessibilityServiceInfo.flags
& AccessibilityServiceInfo.FLAG_REQUEST_ACCESSIBILITY_BUTTON) != 0;
if (targetSdk <= Build.VERSION_CODES.Q) {
return AccessibilityServiceFragmentType.LEGACY;
}
return requestA11yButton
? AccessibilityServiceFragmentType.INVISIBLE
: AccessibilityServiceFragmentType.INTUITIVE;
}
}