blob: 8740a3c2f45a2fc167ef09f5db271fc3a1612844 [file] [log] [blame]
Julia Reynolds4d920ff2016-04-06 20:31:05 -04001/**
2 * Copyright (c) 2016, 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 com.android.internal.logging.MetricsLogger;
Tamas Berghammercbd3f0c2016-06-22 15:21:38 +010019import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
Julia Reynolds4d920ff2016-04-06 20:31:05 -040020import com.android.systemui.R;
21
22import android.annotation.Nullable;
23import android.app.Fragment;
24import android.os.Bundle;
25import android.provider.Settings;
26import android.view.LayoutInflater;
27import android.view.View;
28import android.view.ViewGroup;
29import android.widget.Switch;
30import android.widget.TextView;
31
32public class PowerNotificationControlsFragment extends Fragment {
33
34 private static final String KEY_SHOW_PNC = "show_importance_slider";
35
36 @Override
37 public void onCreate(@Nullable Bundle savedInstanceState) {
38 super.onCreate(savedInstanceState);
39 }
40
41 @Override
42 public View onCreateView(LayoutInflater inflater, ViewGroup container,
43 Bundle savedInstanceState) {
44 return inflater.inflate(R.layout.power_notification_controls_settings, container, false);
45 }
46
47 @Override
48 public void onViewCreated(View view, Bundle savedInstanceState) {
49 super.onViewCreated(view, savedInstanceState);
50 final View switchBar = view.findViewById(R.id.switch_bar);
51 final Switch switchWidget = (Switch) switchBar.findViewById(android.R.id.switch_widget);
52 final TextView switchText = (TextView) switchBar.findViewById(R.id.switch_text);
53 switchWidget.setChecked(isEnabled());
54 switchText.setText(isEnabled()
55 ? getString(R.string.switch_bar_on)
56 : getString(R.string.switch_bar_off));
57
58 switchWidget.setOnClickListener(new View.OnClickListener() {
59 @Override
60 public void onClick(View v) {
61 boolean newState = !isEnabled();
62 MetricsLogger.action(getContext(),
63 MetricsEvent.ACTION_TUNER_POWER_NOTIFICATION_CONTROLS, newState);
64 Settings.Secure.putInt(getContext().getContentResolver(),
65 KEY_SHOW_PNC, newState ? 1 : 0);
66 switchWidget.setChecked(newState);
67 switchText.setText(newState
68 ? getString(R.string.switch_bar_on)
69 : getString(R.string.switch_bar_off));
70 }
71 });
72 }
73
74 @Override
75 public void onResume() {
76 super.onResume();
77 MetricsLogger.visibility(
78 getContext(), MetricsEvent.TUNER_POWER_NOTIFICATION_CONTROLS, true);
79 }
80
81 @Override
82 public void onPause() {
83 super.onPause();
84 MetricsLogger.visibility(
85 getContext(), MetricsEvent.TUNER_POWER_NOTIFICATION_CONTROLS, false);
86 }
87
88 private boolean isEnabled() {
89 int setting = Settings.Secure.getInt(getContext().getContentResolver(), KEY_SHOW_PNC, 0);
90 return setting == 1;
91 }
92
93}