blob: b79cdd8f7501e3133b8dd2eed5cd69c76203566b [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001package com.android.phone;
2
3import android.app.ActionBar;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07004import android.os.Bundle;
SongFerngWangf6fd9922018-06-28 17:21:43 +08005import android.os.PersistableBundle;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07006import android.preference.Preference;
7import android.preference.PreferenceScreen;
SongFerngWangf6fd9922018-06-28 17:21:43 +08008import android.telephony.CarrierConfigManager;
Santos Cordon7d4ddf62013-07-10 11:58:08 -07009import android.util.Log;
10import android.view.MenuItem;
11
Andrew Lee2b36ba22014-11-05 17:08:49 -080012import com.android.internal.telephony.Phone;
13
Santos Cordon7d4ddf62013-07-10 11:58:08 -070014import java.util.ArrayList;
15
Andrew Lee2b36ba22014-11-05 17:08:49 -080016public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070017 private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
18 private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
19
20 private static final String BUTTON_CLIR_KEY = "button_clir_key";
21 private static final String BUTTON_CW_KEY = "button_cw_key";
22
23 private CLIRListPreference mCLIRButton;
fionaxue46e69f2017-04-27 14:32:46 -070024 private CallWaitingSwitchPreference mCWButton;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070025
26 private final ArrayList<Preference> mPreferences = new ArrayList<Preference>();
Andrew Lee2b36ba22014-11-05 17:08:49 -080027 private int mInitIndex = 0;
28 private Phone mPhone;
Andrew Lee5efb1122014-12-05 04:20:42 -080029 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070030
SongFerngWangf6fd9922018-06-28 17:21:43 +080031 private boolean mShowCLIRButton;
32 private boolean mShowCWButton;
33
Santos Cordon7d4ddf62013-07-10 11:58:08 -070034 @Override
35 protected void onCreate(Bundle icicle) {
36 super.onCreate(icicle);
37
38 addPreferencesFromResource(R.xml.gsm_umts_additional_options);
39
Andrew Leedd4f6df2014-12-09 19:13:51 -080040 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5efb1122014-12-05 04:20:42 -080041 mSubscriptionInfoHelper.setActionBarTitle(
Andrew Lee2b36ba22014-11-05 17:08:49 -080042 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
Andrew Lee5efb1122014-12-05 04:20:42 -080043 mPhone = mSubscriptionInfoHelper.getPhone();
Andrew Lee2b36ba22014-11-05 17:08:49 -080044
Santos Cordon7d4ddf62013-07-10 11:58:08 -070045 PreferenceScreen prefSet = getPreferenceScreen();
46 mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
fionaxue46e69f2017-04-27 14:32:46 -070047 mCWButton = (CallWaitingSwitchPreference) prefSet.findPreference(BUTTON_CW_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070048
SongFerngWangf6fd9922018-06-28 17:21:43 +080049 PersistableBundle b = null;
50 if (mSubscriptionInfoHelper.hasSubId()) {
51 b = PhoneGlobals.getInstance().getCarrierConfigForSubId(
52 mSubscriptionInfoHelper.getSubId());
Santos Cordon7d4ddf62013-07-10 11:58:08 -070053 } else {
SongFerngWangf6fd9922018-06-28 17:21:43 +080054 b = PhoneGlobals.getInstance().getCarrierConfig();
55 }
56
57 if (b != null) {
58 mShowCLIRButton = b.getBoolean(
59 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALLER_ID_VISIBILITY_BOOL);
60 mShowCWButton = b.getBoolean(
61 CarrierConfigManager.KEY_ADDITIONAL_SETTINGS_CALL_WAITING_VISIBILITY_BOOL);
62 }
63
64 if (mCLIRButton != null) {
65 if (mShowCLIRButton) {
66 mPreferences.add(mCLIRButton);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070067 } else {
SongFerngWangf6fd9922018-06-28 17:21:43 +080068 prefSet.removePreference(mCLIRButton);
69 }
70 }
71
72 if (mCWButton != null) {
73 if (mShowCWButton) {
74 mPreferences.add(mCWButton);
75 } else {
76 prefSet.removePreference(mCWButton);
77 }
78 }
79
80 if (mPreferences.size() != 0) {
81 if (icicle == null) {
82 if (DBG) Log.d(LOG_TAG, "start to init ");
83 doPreferenceInit(mInitIndex);
84 } else {
85 if (DBG) Log.d(LOG_TAG, "restore stored states");
86 mInitIndex = mPreferences.size();
87 if (mShowCWButton) {
88 mCWButton.init(this, true, mPhone);
89 }
90 if (mShowCLIRButton) {
91 mCLIRButton.init(this, true, mPhone);
92 int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
93 if (clirArray != null) {
94 if (DBG) {
95 Log.d(LOG_TAG, "onCreate: clirArray[0]="
96 + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
97 }
98 mCLIRButton.handleGetCLIRResult(clirArray);
99 } else {
100 mCLIRButton.init(this, false, mPhone);
101 }
102 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700103 }
104 }
105
106 ActionBar actionBar = getActionBar();
107 if (actionBar != null) {
108 // android.R.id.home will be triggered in onOptionsItemSelected()
109 actionBar.setDisplayHomeAsUpEnabled(true);
110 }
111 }
112
113 @Override
114 protected void onSaveInstanceState(Bundle outState) {
115 super.onSaveInstanceState(outState);
116
SongFerngWangf6fd9922018-06-28 17:21:43 +0800117 if (mShowCLIRButton && mCLIRButton.clirArray != null) {
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700118 outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
119 }
120 }
121
122 @Override
123 public void onFinished(Preference preference, boolean reading) {
124 if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
125 mInitIndex++;
SongFerngWangf6fd9922018-06-28 17:21:43 +0800126 doPreferenceInit(mInitIndex);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700127 }
128 super.onFinished(preference, reading);
129 }
130
131 @Override
132 public boolean onOptionsItemSelected(MenuItem item) {
133 final int itemId = item.getItemId();
134 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Andrew Lee5efb1122014-12-05 04:20:42 -0800135 CallFeaturesSetting.goUpToTopLevelSetting(this, mSubscriptionInfoHelper);
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700136 return true;
137 }
138 return super.onOptionsItemSelected(item);
139 }
SongFerngWangf6fd9922018-06-28 17:21:43 +0800140
141 private void doPreferenceInit(int index) {
142 if (mPreferences.size() != 0) {
143 Preference pref = mPreferences.get(index);
144 if (pref instanceof CallWaitingSwitchPreference) {
145 ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
146 } else if (pref instanceof CLIRListPreference) {
147 ((CLIRListPreference) pref).init(this, false, mPhone);
148 }
149 }
150 }
Santos Cordon7d4ddf62013-07-10 11:58:08 -0700151}