• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.accessibility;
18 
19 import android.content.ContentResolver;
20 import android.os.Bundle;
21 import android.provider.Settings;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.TextView;
26 
27 import androidx.annotation.Keep;
28 import androidx.lifecycle.ViewModelProvider;
29 import com.android.tv.settings.accessibility.viewmodel.BounceKeyViewModel;
30 import com.android.tv.twopanelsettings.R;
31 import com.android.tv.twopanelsettings.slices.InfoFragment;
32 
33 @Keep
34 public class AccessibilityBounceKeyDetailedFragment extends InfoFragment {
35 
36     private BounceKeyViewModel viewModel;
37 
38     @Override
onCreate(Bundle savedInstanceState)39     public void onCreate(Bundle savedInstanceState) {
40         super.onCreate(savedInstanceState);
41         viewModel = new ViewModelProvider(requireActivity()).get(BounceKeyViewModel.class);
42     }
43 
44     @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)45     public View onCreateView(
46             LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
47         View view = super.onCreateView(inflater, container, savedInstanceState);
48 
49         // Get the initial Bounce Key Time
50         int initialBounceKeyTime = getCurrentBounceKeyTime();
51 
52         // Setting up Bounce Keys Title
53         TextView bounceKeyInfoTitle = view.requireViewById(R.id.info_title);
54         bounceKeyInfoTitle.setVisibility(View.VISIBLE);
55 
56         // Setting up Bounce Keys Description
57         TextView bounceKeyInfoSummary = view.requireViewById(R.id.info_summary);
58         bounceKeyInfoSummary.setVisibility(View.VISIBLE);
59 
60         // Setting initial bounce key title and description
61         setBounceKeyText(bounceKeyInfoTitle, bounceKeyInfoSummary, initialBounceKeyTime);
62 
63         // Observe the ViewModel's Bounce Key Title
64         viewModel
65                 .getBounceKeyValue()
66                 .observe(
67                         getViewLifecycleOwner(),
68                         bounceKeyValue -> {
69                             // Update your UI elements based on the bounceKey Selected
70                             setBounceKeyText(bounceKeyInfoTitle,
71                                     bounceKeyInfoSummary, bounceKeyValue);
72                         });
73 
74         return view;
75     }
76 
77     /* Set Bounce Keys detailed  */
setBounceKeyText( TextView bounceKeyInfoTitle, TextView bounceKeyInfoSummary, int bounceKeyTime)78     private void setBounceKeyText(
79             TextView bounceKeyInfoTitle, TextView bounceKeyInfoSummary, int bounceKeyTime) {
80         switch (bounceKeyTime) {
81             case 500:
82                 bounceKeyInfoTitle.setText(R.string.bounce_key_timing_half_second_title);
83                 bounceKeyInfoSummary.setText(R.string.bounce_key_timing_half_second_description);
84                 break;
85             case 1000:
86                 bounceKeyInfoTitle.setText(R.string.bounce_key_timing_one_second_title);
87                 bounceKeyInfoSummary.setText(R.string.bounce_key_timing_one_second_description);
88                 break;
89             case 2000:
90                 bounceKeyInfoTitle.setText(R.string.bounce_key_timing_two_second_title);
91                 bounceKeyInfoSummary.setText(R.string.bounce_key_timing_two_second_description);
92                 break;
93             default:
94                 bounceKeyInfoTitle.setText(R.string.bounce_key_timing_default_title);
95                 bounceKeyInfoSummary.setText(R.string.bounce_key_timing_default_description);
96                 break;
97         }
98     }
99 
100     /**
101      * Get current bounce keys time
102      *
103      * @return current bounce key value
104      */
getCurrentBounceKeyTime()105     private int getCurrentBounceKeyTime() {
106         final ContentResolver resolver = getContext().getContentResolver();
107         return Settings.Secure.getInt(resolver, Settings.Secure.ACCESSIBILITY_BOUNCE_KEYS, 0);
108     }
109 }
110