Home | History | Annotate | Download | only in settings
      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.server.telecom.settings;
     18 
     19 import android.app.Activity;
     20 import android.app.AlertDialog;
     21 import android.content.DialogInterface;
     22 import android.os.Bundle;
     23 import android.provider.BlockedNumberContract;
     24 
     25 import com.android.server.telecom.R;
     26 
     27 /**
     28  * Shows a dialog when user taps an notification in notification tray.
     29  */
     30 public class CallBlockDisabledActivity extends Activity {
     31     private AlertDialog mDialog;
     32 
     33     @Override
     34     protected void onCreate(Bundle savedInstanceState) {
     35         super.onCreate(savedInstanceState);
     36         showCallBlockingOffDialog();
     37     }
     38 
     39     @Override
     40     protected void onDestroy() {
     41         super.onDestroy();
     42         dismissCallBlockingOffDialog();
     43     }
     44 
     45     /**
     46      * Shows the dialog that notifies user that [Call Blocking] has been turned off.
     47      */
     48     private void showCallBlockingOffDialog() {
     49         if (isShowingCallBlockingOffDialog()) {
     50             return;
     51         }
     52 
     53         AlertDialog.Builder builder = new AlertDialog.Builder(this);
     54         mDialog = builder
     55                 .setTitle(R.string.phone_strings_emergency_call_made_dialog_title_txt)
     56                 .setMessage(R.string
     57                         .phone_strings_emergency_call_made_dialog_call_blocking_text_txt)
     58                 .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
     59                     @Override
     60                     public void onClick(DialogInterface dialog, int which) {
     61                         BlockedNumbersUtil.setEnhancedBlockSetting(
     62                                 CallBlockDisabledActivity.this,
     63                                 BlockedNumberContract.SystemContract
     64                                         .ENHANCED_SETTING_KEY_SHOW_EMERGENCY_CALL_NOTIFICATION,
     65                                 false);
     66                         BlockedNumbersUtil.updateEmergencyCallNotification(
     67                                 CallBlockDisabledActivity.this, false);
     68                         finish();
     69                     }
     70                 })
     71                 .setOnCancelListener(new DialogInterface.OnCancelListener() {
     72                     @Override
     73                     public void onCancel(DialogInterface dialog) {
     74                         finish();
     75                     }
     76                 })
     77                 .create();
     78         mDialog.setCanceledOnTouchOutside(false);
     79         mDialog.show();
     80     }
     81 
     82     /**
     83      * Dismisses the dialog that notifies user that [Call Blocking] has been turned off.
     84      */
     85     private void dismissCallBlockingOffDialog() {
     86         if (isShowingCallBlockingOffDialog()) {
     87             mDialog.dismiss();
     88         }
     89         mDialog = null;
     90     }
     91 
     92     /**
     93      * Checks whether the dialog is currently showing.
     94      *
     95      * @return true if the dialog is currently showing, false otherwise.
     96      */
     97     private boolean isShowingCallBlockingOffDialog() {
     98         return (mDialog != null && mDialog.isShowing());
     99     }
    100 }
    101