Home | History | Annotate | Download | only in development
      1 /*
      2  * Copyright (C) 2017 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 
     17 package com.android.tv.settings.system.development;
     18 
     19 import android.app.AlertDialog;
     20 import android.app.Dialog;
     21 import android.content.Context;
     22 import android.support.annotation.Nullable;
     23 import android.support.v7.preference.Preference;
     24 
     25 import com.android.settingslib.core.lifecycle.Lifecycle;
     26 import com.android.settingslib.development.AbstractLogpersistPreferenceController;
     27 import com.android.tv.settings.R;
     28 
     29 /**
     30  * Preference controller for the Logpersist development preference
     31  */
     32 public class LogpersistPreferenceController extends AbstractLogpersistPreferenceController {
     33 
     34     private Dialog mLogpersistClearDialog;
     35 
     36     LogpersistPreferenceController(Context context, Lifecycle lifecycle) {
     37         super(context, lifecycle);
     38     }
     39 
     40     @Override
     41     public void showConfirmationDialog(@Nullable Preference preference) {
     42         // TODO: figure out how to do this with fragments (it's harder than you might think)
     43         if (preference == null) {
     44             return;
     45         }
     46         if (mLogpersistClearDialog != null) dismissConfirmationDialog();
     47         mLogpersistClearDialog = new AlertDialog.Builder(mContext)
     48                 .setMessage(R.string.dev_logpersist_clear_warning_message)
     49                 .setTitle(R.string.dev_logpersist_clear_warning_title)
     50                 .setPositiveButton(android.R.string.yes, (dialog, which) -> setLogpersistOff(true))
     51                 .setNegativeButton(android.R.string.no, (dialog, which) -> updateLogpersistValues())
     52                 .show();
     53         mLogpersistClearDialog.setOnDismissListener(dialog -> mLogpersistClearDialog = null);
     54     }
     55 
     56     @Override
     57     public void dismissConfirmationDialog() {
     58         if (mLogpersistClearDialog != null) {
     59             mLogpersistClearDialog.dismiss();
     60             mLogpersistClearDialog = null;
     61         }
     62     }
     63 
     64     @Override
     65     public boolean isConfirmationDialogShowing() {
     66         return mLogpersistClearDialog != null;
     67     }
     68 }
     69