• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2022 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.settings.accessibility;
18 
19 import android.content.Context;
20 import android.content.res.Resources;
21 
22 import androidx.preference.PreferenceScreen;
23 
24 import com.android.settings.R;
25 import com.android.settings.accessibility.ListDialogPreference.OnValueChangedListener;
26 
27 /** Preference controller for captioning foreground opacity. */
28 public class CaptioningForegroundOpacityController extends BaseCaptioningCustomController
29         implements OnValueChangedListener {
30 
CaptioningForegroundOpacityController(Context context, String preferenceKey)31     public CaptioningForegroundOpacityController(Context context, String preferenceKey) {
32         super(context, preferenceKey);
33     }
34 
35     @Override
displayPreference(PreferenceScreen screen)36     public void displayPreference(PreferenceScreen screen) {
37         super.displayPreference(screen);
38         final ColorPreference preference = screen.findPreference(getPreferenceKey());
39         final Resources res = mContext.getResources();
40         final int[] opacityValues = res.getIntArray(R.array.captioning_opacity_selector_values);
41         final String[] opacityTitles = res.getStringArray(
42                 R.array.captioning_opacity_selector_titles);
43         preference.setTitles(opacityTitles);
44         preference.setValues(opacityValues);
45         final int foregroundColor = mCaptionHelper.getForegroundColor();
46         final int opacity = CaptionUtils.parseOpacity(foregroundColor);
47         preference.setValue(opacity);
48         preference.setOnValueChangedListener(this);
49     }
50 
51     @Override
onValueChanged(ListDialogPreference preference, int value)52     public void onValueChanged(ListDialogPreference preference, int value) {
53         final int foregroundColor = mCaptionHelper.getForegroundColor();
54         final int color = CaptionUtils.parseColor(foregroundColor);
55         final int merged = CaptionUtils.mergeColorOpacity(color, value);
56         mCaptionHelper.setForegroundColor(merged);
57         mCaptionHelper.setEnabled(true);
58     }
59 }
60