• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 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.phone;
18 
19 import android.content.Context;
20 import android.os.Bundle;
21 import android.telephony.ServiceState;
22 import android.util.AttributeSet;
23 import android.util.Log;
24 import android.view.View;
25 import android.widget.EditText;
26 
27 import com.android.internal.telephony.Phone;
28 import com.android.internal.telephony.imsphone.ImsPhone;
29 import com.android.phone.settings.fdn.EditPinPreference;
30 
31 /**
32  * This preference represents the status of disable all barring option.
33  */
34 public class CallBarringDeselectAllPreference extends EditPinPreference {
35     private static final String LOG_TAG = "CallBarringDeselectAllPreference";
36     private static final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
37 
38     private boolean mShowPassword;
39     private Phone mPhone;
40 
41     /**
42      * CallBarringDeselectAllPreference constructor.
43      *
44      * @param context The context of view.
45      * @param attrs The attributes of the XML tag that is inflating EditTextPreference.
46      */
CallBarringDeselectAllPreference(Context context, AttributeSet attrs)47     public CallBarringDeselectAllPreference(Context context, AttributeSet attrs) {
48         super(context, attrs);
49     }
50 
51     @Override
showDialog(Bundle state)52     protected void showDialog(Bundle state) {
53         // Finds out if the password field should be shown or not.
54         ImsPhone imsPhone = mPhone != null ? (ImsPhone) mPhone.getImsPhone() : null;
55         mShowPassword = !(imsPhone != null
56                 && ((imsPhone.getServiceState().getState() == ServiceState.STATE_IN_SERVICE)
57                         || imsPhone.isUtEnabled()));
58 
59         // Selects dialog message depending on if the password field is shown or not.
60         setDialogMessage(getContext().getString(mShowPassword
61                 ? R.string.messageCallBarring : R.string.call_barring_deactivate_all_no_password));
62 
63         if (DBG) {
64             Log.d(LOG_TAG, "showDialog: mShowPassword: " + mShowPassword);
65         }
66 
67         super.showDialog(state);
68     }
69 
init(Phone phone)70     void init(Phone phone) {
71         if (DBG) {
72             Log.d(LOG_TAG, "init: phoneId = " + phone.getPhoneId());
73         }
74         mPhone = phone;
75     }
76 
77     @Override
onBindDialogView(View view)78     protected void onBindDialogView(View view) {
79         super.onBindDialogView(view);
80 
81         final EditText editText = (EditText) view.findViewById(android.R.id.edit);
82         if (editText != null) {
83             // Hide the input-text-line if the password is not shown.
84             editText.setVisibility(mShowPassword ? View.VISIBLE : View.GONE);
85         }
86     }
87 
88     @Override
needInputMethod()89     protected boolean needInputMethod() {
90         // Input method should only be displayed if the password-field is shown.
91         return mShowPassword;
92     }
93 
94     /**
95      * Returns whether the password field is shown.
96      */
isPasswordShown()97     boolean isPasswordShown() {
98         return mShowPassword;
99     }
100 }
101