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