1 /* 2 * Copyright (C) 2019 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.twopanelsettings.slices; 18 19 import static com.android.tv.twopanelsettings.slices.HasCustomContentDescription.CONTENT_DESCRIPTION_SEPARATOR; 20 21 import android.content.Context; 22 23 import com.android.tv.twopanelsettings.R; 24 25 /** 26 * Generate fallback content descriptions for when custom content descriptions are not specified. 27 */ 28 public final class CustomContentDescriptionUtil { 29 30 /** 31 * Generate fallback content description for Switch Preferences 32 * @param context 33 * @param contentDescription to generate first portion of full content description 34 * @param isChecked is the toggle state of SwitchPreference 35 * @return the full content description for switch preferences 36 */ getFullSwitchContentDescription( Context context, String contentDescription, Boolean isChecked)37 public static String getFullSwitchContentDescription( 38 Context context, String contentDescription, Boolean isChecked) { 39 StringBuilder switchContentDescription = new StringBuilder(); 40 switchContentDescription.append(contentDescription); 41 switchContentDescription.append(CONTENT_DESCRIPTION_SEPARATOR); 42 if (isChecked) { 43 switchContentDescription.append(context.getString(R.string.switch_on)); 44 switchContentDescription.append(CONTENT_DESCRIPTION_SEPARATOR); 45 } else { 46 switchContentDescription.append(context.getString(R.string.switch_off)); 47 switchContentDescription.append(CONTENT_DESCRIPTION_SEPARATOR); 48 } 49 switchContentDescription 50 .append(context.getString(R.string.switch_talkback_identifier)); 51 return switchContentDescription.toString(); 52 } 53 } 54