1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.text; 18 19 import android.annotation.NonNull; 20 import android.app.AppGlobals; 21 22 import com.android.text.flags.Flags; 23 24 /** 25 * Flags in the "text" namespace. 26 * 27 * @hide 28 */ 29 public final class TextFlags { 30 31 /** 32 * The name space of the "text" feature. 33 * 34 * This needs to move to DeviceConfig constant. 35 */ 36 public static final String NAMESPACE = "text"; 37 38 /** 39 * Whether we use the new design of context menu. 40 */ 41 public static final String ENABLE_NEW_CONTEXT_MENU = 42 "TextEditing__enable_new_context_menu"; 43 44 /** 45 * The key name used in app core settings for {@link #ENABLE_NEW_CONTEXT_MENU}. 46 */ 47 public static final String KEY_ENABLE_NEW_CONTEXT_MENU = "text__enable_new_context_menu"; 48 49 /** 50 * Default value for the flag {@link #ENABLE_NEW_CONTEXT_MENU}. 51 */ 52 public static final boolean ENABLE_NEW_CONTEXT_MENU_DEFAULT = true; 53 54 /** 55 * List of text flags to be transferred to the application process. 56 */ 57 public static final String[] TEXT_ACONFIGS_FLAGS = { 58 Flags.FLAG_NO_BREAK_NO_HYPHENATION_SPAN, 59 Flags.FLAG_PHRASE_STRICT_FALLBACK, 60 Flags.FLAG_USE_BOUNDS_FOR_WIDTH, 61 Flags.FLAG_FIX_LINE_HEIGHT_FOR_LOCALE, 62 Flags.FLAG_ICU_BIDI_MIGRATION, 63 Flags.FLAG_FIX_MISALIGNED_CONTEXT_MENU, 64 }; 65 66 /** 67 * List of the default values of the text flags. 68 * 69 * The order must be the same to the TEXT_ACONFIG_FLAGS. 70 */ 71 public static final boolean[] TEXT_ACONFIG_DEFAULT_VALUE = { 72 Flags.noBreakNoHyphenationSpan(), 73 Flags.phraseStrictFallback(), 74 Flags.useBoundsForWidth(), 75 Flags.fixLineHeightForLocale(), 76 Flags.icuBidiMigration(), 77 Flags.fixMisalignedContextMenu(), 78 }; 79 80 /** 81 * Get a key for the feature flag. 82 */ getKeyForFlag(@onNull String flag)83 public static String getKeyForFlag(@NonNull String flag) { 84 return "text__" + flag; 85 } 86 87 /** 88 * Return true if the feature flag is enabled. 89 */ isFeatureEnabled(@onNull String flag)90 public static boolean isFeatureEnabled(@NonNull String flag) { 91 return AppGlobals.getIntCoreSetting( 92 getKeyForFlag(flag), 0 /* aconfig is false by default */) != 0; 93 } 94 } 95