Jason Monk | 295a337 | 2015-05-11 16:57:15 -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.systemui.tuner; |
| 17 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 18 | import android.app.AlertDialog; |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 19 | import android.app.Dialog; |
| 20 | import android.app.DialogFragment; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 21 | import android.content.DialogInterface; |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 22 | import android.database.ContentObserver; |
| 23 | import android.net.Uri; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 24 | import android.os.Bundle; |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 25 | import android.os.Handler; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 26 | import android.provider.Settings; |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 27 | import android.provider.Settings.System; |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 28 | import android.support.v14.preference.PreferenceFragment; |
| 29 | import android.support.v14.preference.SwitchPreference; |
| 30 | import android.support.v7.preference.Preference; |
| 31 | import android.support.v7.preference.Preference.OnPreferenceChangeListener; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 32 | import android.view.Menu; |
| 33 | import android.view.MenuInflater; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 34 | import android.view.MenuItem; |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 35 | |
Jason Monk | a403159 | 2015-07-16 14:15:50 -0400 | [diff] [blame] | 36 | import com.android.internal.logging.MetricsLogger; |
Tamas Berghammer | cbd3f0c | 2016-06-22 15:21:38 +0100 | [diff] [blame^] | 37 | import com.android.internal.logging.nano.MetricsProto.MetricsEvent; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 38 | import com.android.systemui.R; |
Jason Monk | fe7c91b | 2015-08-13 15:42:28 -0400 | [diff] [blame] | 39 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 40 | public class TunerFragment extends PreferenceFragment { |
| 41 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 42 | private static final String TAG = "TunerFragment"; |
| 43 | |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 44 | private static final String KEY_BATTERY_PCT = "battery_pct"; |
| 45 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 46 | public static final String SETTING_SEEN_TUNER_WARNING = "seen_tuner_warning"; |
| 47 | |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 48 | private static final String WARNING_TAG = "tuner_warning"; |
| 49 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 50 | private static final int MENU_REMOVE = Menu.FIRST + 1; |
| 51 | |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 52 | @Override |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 53 | public void onCreate(Bundle savedInstanceState) { |
| 54 | super.onCreate(savedInstanceState); |
| 55 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 56 | setHasOptionsMenu(true); |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 57 | } |
Jason Monk | 11a7744 | 2015-05-12 19:29:02 -0400 | [diff] [blame] | 58 | |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 59 | @Override |
Jason Monk | a9f1288 | 2016-01-24 12:03:19 -0500 | [diff] [blame] | 60 | public void onActivityCreated(Bundle savedInstanceState) { |
| 61 | super.onActivityCreated(savedInstanceState); |
| 62 | getActivity().getActionBar().setDisplayHomeAsUpEnabled(true); |
| 63 | } |
| 64 | |
| 65 | @Override |
Jason Monk | 87ccd55 | 2015-12-11 21:39:54 -0500 | [diff] [blame] | 66 | public void onCreatePreferences(Bundle savedInstanceState, String rootKey) { |
| 67 | addPreferencesFromResource(R.xml.tuner_prefs); |
| 68 | |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 69 | if (Settings.Secure.getInt(getContext().getContentResolver(), SETTING_SEEN_TUNER_WARNING, |
| 70 | 0) == 0) { |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 71 | if (getFragmentManager().findFragmentByTag(WARNING_TAG) == null) { |
| 72 | new TunerWarningFragment().show(getFragmentManager(), WARNING_TAG); |
| 73 | } |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 74 | } |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 75 | } |
| 76 | |
| 77 | @Override |
| 78 | public void onResume() { |
| 79 | super.onResume(); |
Jason Monk | f0c6f64 | 2016-01-20 22:24:50 -0500 | [diff] [blame] | 80 | getActivity().setTitle(R.string.system_ui_tuner); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 81 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 82 | MetricsLogger.visibility(getContext(), MetricsEvent.TUNER, true); |
John Spurlock | f40d08f | 2015-05-29 10:48:22 -0400 | [diff] [blame] | 83 | } |
| 84 | |
| 85 | @Override |
| 86 | public void onPause() { |
| 87 | super.onPause(); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 88 | |
Chris Wren | f6e9228b | 2016-01-26 18:04:35 -0500 | [diff] [blame] | 89 | MetricsLogger.visibility(getContext(), MetricsEvent.TUNER, false); |
Jason Monk | 5e74517 | 2015-06-02 19:14:44 -0400 | [diff] [blame] | 90 | } |
| 91 | |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 92 | @Override |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 93 | public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { |
| 94 | menu.add(Menu.NONE, MENU_REMOVE, Menu.NONE, R.string.remove_from_settings); |
| 95 | } |
| 96 | |
| 97 | @Override |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 98 | public boolean onOptionsItemSelected(MenuItem item) { |
| 99 | switch (item.getItemId()) { |
| 100 | case android.R.id.home: |
| 101 | getActivity().finish(); |
| 102 | return true; |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 103 | case MENU_REMOVE: |
| 104 | TunerService.showResetRequest(getContext(), new Runnable() { |
| 105 | @Override |
| 106 | public void run() { |
Akira Oshimi | 8fbcb76 | 2016-09-29 12:17:24 +0900 | [diff] [blame] | 107 | if (getActivity() != null) { |
| 108 | getActivity().finish(); |
| 109 | } |
Jason Monk | 431ad73 | 2015-07-16 08:58:15 -0400 | [diff] [blame] | 110 | } |
| 111 | }); |
| 112 | return true; |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 113 | } |
| 114 | return super.onOptionsItemSelected(item); |
| 115 | } |
| 116 | |
Jason Monk | 72def0d | 2015-11-10 16:03:06 -0500 | [diff] [blame] | 117 | public static class TunerWarningFragment extends DialogFragment { |
| 118 | @Override |
| 119 | public Dialog onCreateDialog(Bundle savedInstanceState) { |
| 120 | return new AlertDialog.Builder(getContext()) |
| 121 | .setTitle(R.string.tuner_warning_title) |
| 122 | .setMessage(R.string.tuner_warning) |
| 123 | .setPositiveButton(R.string.got_it, new DialogInterface.OnClickListener() { |
| 124 | @Override |
| 125 | public void onClick(DialogInterface dialog, int which) { |
| 126 | Settings.Secure.putInt(getContext().getContentResolver(), |
| 127 | SETTING_SEEN_TUNER_WARNING, 1); |
| 128 | } |
| 129 | }).show(); |
| 130 | } |
| 131 | } |
Jason Monk | 295a337 | 2015-05-11 16:57:15 -0400 | [diff] [blame] | 132 | } |