TunerActivity.java revision 87ccd55e8a90ff5d1c30f852941d523a83ab735a
1/* 2 * Copyright (C) 2015 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 */ 16package com.android.systemui.tuner; 17 18import android.app.Fragment; 19import android.app.FragmentTransaction; 20import android.os.Bundle; 21import android.support.v14.preference.PreferenceFragment; 22import android.support.v7.preference.Preference; 23import android.support.v7.preference.PreferenceScreen; 24import android.util.Log; 25 26import com.android.settingslib.drawer.SettingsDrawerActivity; 27import com.android.systemui.R; 28 29public class TunerActivity extends SettingsDrawerActivity implements 30 PreferenceFragment.OnPreferenceStartFragmentCallback, 31 PreferenceFragment.OnPreferenceStartScreenCallback { 32 33 protected void onCreate(Bundle savedInstanceState) { 34 super.onCreate(savedInstanceState); 35 36 getFragmentManager().beginTransaction().replace(R.id.content_frame, new TunerFragment()) 37 .commit(); 38 } 39 40 @Override 41 public boolean onPreferenceStartFragment(PreferenceFragment caller, Preference pref) { 42 try { 43 Class<?> cls = Class.forName(pref.getFragment()); 44 Fragment fragment = (Fragment) cls.newInstance(); 45 FragmentTransaction transaction = getFragmentManager().beginTransaction(); 46 transaction.replace(R.id.content_frame, fragment); 47 transaction.addToBackStack("PreferenceFragment"); 48 transaction.commit(); 49 return true; 50 } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { 51 Log.d("TunerActivity", "Problem launching fragment", e); 52 return false; 53 } 54 } 55 56 @Override 57 public boolean onPreferenceStartScreen(PreferenceFragment caller, PreferenceScreen pref) { 58 FragmentTransaction transaction = getFragmentManager().beginTransaction(); 59 SubSettingsFragment fragment = new SubSettingsFragment(); 60 final Bundle b = new Bundle(1); 61 b.putString(PreferenceFragment.ARG_PREFERENCE_ROOT, pref.getKey()); 62 fragment.setArguments(b); 63 fragment.setTargetFragment(caller, 0); 64 transaction.replace(R.id.content_frame, fragment); 65 transaction.addToBackStack("PreferenceFragment"); 66 transaction.commit(); 67 return true; 68 } 69 70 public static class SubSettingsFragment extends PreferenceFragment { 71 @Override 72 public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { 73 setPreferenceScreen((PreferenceScreen) ((PreferenceFragment) getTargetFragment()) 74 .getPreferenceScreen().findPreference(rootKey)); 75 } 76 } 77 78} 79