1/* 2 * Copyright (C) 2014 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 17package com.android.settings.notification; 18 19import com.android.settings.R; 20import com.android.settings.SettingsActivity; 21import com.android.settings.SettingsPreferenceFragment; 22 23import android.content.Context; 24import android.content.Intent; 25import android.os.Bundle; 26import android.provider.Settings; 27import android.view.LayoutInflater; 28import android.view.View; 29import android.view.ViewGroup; 30import android.widget.RadioButton; 31 32public class RedactionInterstitial extends SettingsActivity { 33 34 @Override 35 public Intent getIntent() { 36 Intent modIntent = new Intent(super.getIntent()); 37 modIntent.putExtra(EXTRA_SHOW_FRAGMENT, RedactionInterstitialFragment.class.getName()); 38 return modIntent; 39 } 40 41 @Override 42 protected boolean isValidFragment(String fragmentName) { 43 return RedactionInterstitialFragment.class.getName().equals(fragmentName); 44 } 45 46 public static Intent createStartIntent(Context ctx) { 47 return new Intent(ctx, RedactionInterstitial.class) 48 .putExtra(EXTRA_PREFS_SHOW_BUTTON_BAR, true) 49 .putExtra(EXTRA_PREFS_SET_BACK_TEXT, (String) null) 50 .putExtra(EXTRA_PREFS_SET_NEXT_TEXT, ctx.getString( 51 R.string.app_notifications_dialog_done)); 52 } 53 54 public static class RedactionInterstitialFragment extends SettingsPreferenceFragment 55 implements View.OnClickListener { 56 57 private RadioButton mShowAllButton; 58 private RadioButton mRedactSensitiveButton; 59 private RadioButton mHideAllButton; 60 61 @Override 62 public View onCreateView(LayoutInflater inflater, ViewGroup container, 63 Bundle savedInstanceState) { 64 View view = inflater.inflate(R.layout.redaction_interstitial, container, false); 65 mShowAllButton = (RadioButton) view.findViewById(R.id.show_all); 66 mRedactSensitiveButton = (RadioButton) view.findViewById(R.id.redact_sensitive); 67 mHideAllButton = (RadioButton) view.findViewById(R.id.hide_all); 68 69 mShowAllButton.setOnClickListener(this); 70 mRedactSensitiveButton.setOnClickListener(this); 71 mHideAllButton.setOnClickListener(this); 72 return view; 73 } 74 75 @Override 76 public void onResume() { 77 super.onResume(); 78 loadFromSettings(); 79 } 80 81 private void loadFromSettings() { 82 final boolean enabled = Settings.Secure.getInt(getContentResolver(), 83 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, 0) != 0; 84 final boolean show = Settings.Secure.getInt(getContentResolver(), 85 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, 1) != 0; 86 mShowAllButton.setChecked(enabled && show); 87 mRedactSensitiveButton.setChecked(enabled && !show); 88 mHideAllButton.setChecked(!enabled); 89 } 90 91 @Override 92 public void onClick(View v) { 93 final boolean show = (v == mShowAllButton); 94 final boolean enabled = (v != mHideAllButton); 95 96 Settings.Secure.putInt(getContentResolver(), 97 Settings.Secure.LOCK_SCREEN_ALLOW_PRIVATE_NOTIFICATIONS, show ? 1 : 0); 98 Settings.Secure.putInt(getContentResolver(), 99 Settings.Secure.LOCK_SCREEN_SHOW_NOTIFICATIONS, enabled ? 1 : 0); 100 } 101 } 102} 103