• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14 package com.android.tv.quicksettings;
15 
16 import android.app.Activity;
17 import android.app.Fragment;
18 import android.os.Bundle;
19 
20 import androidx.leanback.preference.LeanbackPreferenceFragment;
21 import androidx.leanback.preference.LeanbackSettingsFragment;
22 import androidx.preference.Preference;
23 import androidx.preference.PreferenceFragment;
24 import androidx.preference.PreferenceScreen;
25 
26 public class QuickSettings extends Activity {
27 
28     private static final String TAG = "QuickSettings";
29 
30     @Override
onCreate(Bundle savedInstanceState)31     protected void onCreate(Bundle savedInstanceState) {
32         super.onCreate(savedInstanceState);
33 
34         if (savedInstanceState == null) {
35             final Fragment f = new QuickSettingsFragment();
36             getFragmentManager().beginTransaction().add(android.R.id.content, f).commit();
37             getFragmentManager().executePendingTransactions();
38         }
39     }
40 
41     public static class QuickSettingsFragment extends LeanbackSettingsFragment {
42 
43         @Override
onPreferenceStartInitialScreen()44         public void onPreferenceStartInitialScreen() {
45             final Fragment f = new QuickSettingsPreferenceFragment();
46             startPreferenceFragment(f);
47         }
48 
49         @Override
onPreferenceStartFragment(PreferenceFragment caller, Preference pref)50         public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) {
51             return false;
52         }
53 
54         @Override
onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref)55         public boolean onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref) {
56             final Fragment f = new SubSettingsFragment();
57             final Bundle b = new Bundle(1);
58             b.putString(PreferenceFragment.ARG_PREFERENCE_ROOT, pref.getKey());
59             f.setArguments(b);
60             startPreferenceFragment(f);
61             return true;
62         }
63     }
64 
65     public static class SubSettingsFragment extends LeanbackPreferenceFragment {
66         @Override
onCreatePreferences(Bundle savedInstanceState, String rootKey)67         public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
68             setPreferencesFromResource(R.xml.quick_settings, rootKey);
69         }
70     }
71 
72 }
73