Jason Monk | 39b4674 | 2015-09-10 15:52:51 -0400 | [diff] [blame] | 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 | */ |
| 16 | package com.android.settings; |
| 17 | |
| 18 | import android.annotation.Nullable; |
| 19 | import android.os.Bundle; |
| 20 | import android.support.v14.preference.PreferenceFragment; |
| 21 | import android.support.v7.preference.Preference; |
| 22 | import android.support.v7.preference.PreferenceScreen; |
| 23 | |
| 24 | public class PreferenceActivity extends SettingsActivity { |
| 25 | |
| 26 | private PreferenceActivityFragment mFragment; |
| 27 | |
| 28 | @Override |
| 29 | protected void onCreate(@Nullable Bundle savedInstanceState) { |
| 30 | getIntent().putExtra(EXTRA_SHOW_FRAGMENT, PreferenceActivityFragment.class.getName()); |
| 31 | super.onCreate(savedInstanceState); |
| 32 | } |
| 33 | |
| 34 | public void addPreferencesFromResource(int resource) { |
| 35 | mFragment.addPreferencesFromResource(resource); |
| 36 | } |
| 37 | |
| 38 | public Preference findPreference(String preference) { |
| 39 | return mFragment.findPreference(preference); |
| 40 | } |
| 41 | |
| 42 | public PreferenceScreen getPreferenceScreen() { |
| 43 | return mFragment.getPreferenceScreen(); |
| 44 | } |
| 45 | |
| 46 | public void setPreferenceScreen(PreferenceScreen screen) { |
| 47 | mFragment.setPreferenceScreen(screen); |
| 48 | } |
| 49 | |
| 50 | public boolean onPreferenceTreeClick(Preference preference) { |
| 51 | return false; |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | protected boolean isValidFragment(String fragmentName) { |
| 56 | return super.isValidFragment(fragmentName) |
| 57 | || PreferenceActivityFragment.class.getName().equals(fragmentName); |
| 58 | } |
| 59 | |
| 60 | public static class PreferenceActivityFragment extends PreferenceFragment { |
| 61 | @Override |
| 62 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
| 63 | ((PreferenceActivity) getActivity()).mFragment = this; |
| 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public boolean onPreferenceTreeClick(Preference preference) { |
| 68 | if (((PreferenceActivity) getActivity()).onPreferenceTreeClick(preference)) { |
| 69 | return true; |
| 70 | } |
| 71 | return super.onPreferenceTreeClick(preference); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | } |