1 /* 2 * Copyright (C) 2021 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 com.android.tv.settings.library; 18 19 import static com.android.tv.settings.library.PreferenceCompat.STATUS_OFF; 20 import static com.android.tv.settings.library.PreferenceCompat.STATUS_ON; 21 22 import android.annotation.SystemApi; 23 24 /** 25 * @hide Provide constants and utility methods. 26 */ 27 @SystemApi 28 public final class ManagerUtil { 29 public static final int OFFSET_MULTIPLIER = 100000; 30 public static final int STATE_EMPTY = -1; 31 public static final int STATE_NETWORK = 0; 32 public static final int STATE_WIFI_DETAILS = 1; 33 public static final int STATE_DEVICE_MAIN = 2; 34 public static final int STATE_APPS = 3; 35 public static final int STATE_ALL_APPS = 4; 36 public static final int STATE_APP_MANAGEMENT = 5; 37 public static final int STATE_SPECIAL_ACCESS = 6; 38 public static final int STATE_HIGH_POWER = 7; 39 public static final int STATE_NOTIFICATION_ACCESS = 8; 40 public static final int STATE_APP_USAGE_ACCESS = 9; 41 public static final int STATE_SYSTEM_ALERT_WINDOW = 10; 42 public static final int STATE_WRITE_SETTINGS = 11; 43 public static final int STATE_PICTURE_IN_PICTURE = 12; 44 public static final int STATE_ALARMS_AND_REMINDERS = 13; 45 public static final int STATE_EXTERNAL_SOURCES = 14; 46 public static final int STATE_SYSTEM_DATE_TIME = 15; 47 public static final int STATE_SYSTEM_ABOUT = 16; 48 public static final int STATE_KEYBOARD = 17; 49 public static final int STATE_AVAILABLE_KEYBOARD = 18; 50 public static final int STATE_AUTO_FILL_PICKER_STATE = 19; 51 public static final int STATE_LANGUAGE = 20; 52 public static final int STATE_ACCESSIBILITY = 21; 53 public static final int STATE_ACCESSIBILITY_SERVICE = 22; 54 public static final int STATE_ACCESSIBILITY_SHORTCUT = 23; 55 public static final int STATE_ACCESSIBILITY_SHORTCUT_SERVICE = 24; 56 public static final int STATE_STORAGE = 25; 57 public static final int STATE_STORAGE_SUMMARY = 26; 58 public static final int STATE_MISSING_STORAGE = 27; 59 public static final int STATE_POWER_AND_ENERGY = 28; 60 public static final int STATE_ENERGY_SAVER = 29; 61 public static final int STATE_DAYDREAM = 30; 62 public static final int STATE_DISPLAY_SOUND = 31; 63 public static final int STATE_FONT_SCALE = 32; 64 public static final int STATE_MATCH_CONTENT_FRAME = 33; 65 public static final int STATE_ADVANCED_DISPLAY = 34; 66 public static final int STATE_ADVANCED_VOLUME = 35; 67 public static final int STATE_HDR_FORMAT_SELECTION = 36; 68 public static final int STATE_LOCATION = 37; 69 public static final int STATE_SENSOR = 38; 70 public static final int STATE_PRIVACY = 39; 71 public static final int STATE_RESOLUTION_SELECTION = 40; 72 public static final int STATE_DEVELOPMENT = 41; 73 public static final int STATE_LEGAL = 42; 74 public static final String KEY_KEYBOARD_SETTINGS = "autofillSettings"; 75 public static final String INFO_INTENT = "intent"; 76 public static final String INFO_WIFI_SIGNAL_LEVEL = "wifi_signal_level"; 77 /** Argument key containing the current font scale value. */ 78 public static final String INFO_CURRENT_FONT_SCALE_VALUE = "current_font_scale_value"; 79 /** Argument key containing the font scale value this fragment will preview. */ 80 public static final String INFO_PREVIEW_FONT_SCALE_VALUE = "preview_font_scale_value"; 81 ManagerUtil()82 private ManagerUtil() { 83 } 84 getChecked(boolean checked)85 static byte getChecked(boolean checked) { 86 return checked ? STATUS_ON : STATUS_OFF; 87 } 88 getSelectable(boolean selectable)89 static byte getSelectable(boolean selectable) { 90 return selectable ? STATUS_ON : STATUS_OFF; 91 } 92 getVisible(boolean visible)93 static byte getVisible(boolean visible) { 94 return visible ? STATUS_ON : STATUS_OFF; 95 } 96 getEnabled(boolean enabled)97 static byte getEnabled(boolean enabled) { 98 return enabled ? STATUS_ON : STATUS_OFF; 99 } 100 getPersistent(boolean persistent)101 static byte getPersistent(boolean persistent) { 102 return persistent ? STATUS_ON : STATUS_OFF; 103 } 104 105 106 /** 107 * @hide Return whether the preference is checked. 108 * 0 : not updated, 1 : unchecked, 2 : checked 109 */ 110 @SystemApi isChecked(PreferenceCompat pref)111 public static boolean isChecked(PreferenceCompat pref) { 112 return pref.getChecked() == STATUS_ON; 113 } 114 115 /** 116 * @hide Return whether the preference is visible. 117 * 0 : not updated, 1 : invisible, 2 : visible 118 */ 119 @SystemApi isVisible(PreferenceCompat pref)120 public static boolean isVisible(PreferenceCompat pref) { 121 return pref.getVisible() == STATUS_OFF; 122 } 123 124 /** 125 * @param state state identifier 126 * @param requestCode requestCode 127 * @return compound code 128 * @hide Calculate the compound code based on the state identifier and request code. 129 */ 130 @SystemApi calculateCompoundCode(int state, int requestCode)131 public static int calculateCompoundCode(int state, int requestCode) { 132 return OFFSET_MULTIPLIER * (state + 1) + requestCode; 133 } 134 135 /** 136 * @param code compound code 137 * @return state identifier 138 * @hide Get the state identifier based on the compound code. 139 */ 140 @SystemApi getStateIdentifier(int code)141 public static int getStateIdentifier(int code) { 142 if (code < OFFSET_MULTIPLIER) { 143 return -1; 144 } 145 return code / OFFSET_MULTIPLIER - 1; 146 } 147 148 /** 149 * @param code compound code 150 * @return request code 151 * @hide Return the request code for a particular state. 152 */ 153 @SystemApi getRequestCode(int code)154 public static int getRequestCode(int code) { 155 return code % OFFSET_MULTIPLIER; 156 } 157 } 158