blob: 082eaa9e2a2673babe320f50a094c006b7a8e054 [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;
5import android.preference.Preference;
6import android.preference.PreferenceScreen;
7import android.util.Log;
8import android.view.MenuItem;
9
Andrew Lee2b36ba22014-11-05 17:08:49 -080010import com.android.internal.telephony.Phone;
11
Santos Cordon7d4ddf62013-07-10 11:58:08 -070012import java.util.ArrayList;
13
Andrew Lee2b36ba22014-11-05 17:08:49 -080014public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070015 private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
16 private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
17
18 private static final String BUTTON_CLIR_KEY = "button_clir_key";
19 private static final String BUTTON_CW_KEY = "button_cw_key";
20
21 private CLIRListPreference mCLIRButton;
fionaxue46e69f2017-04-27 14:32:46 -070022 private CallWaitingSwitchPreference mCWButton;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070023
24 private final ArrayList<Preference> mPreferences = new ArrayList<Preference>();
Andrew Lee2b36ba22014-11-05 17:08:49 -080025 private int mInitIndex = 0;
26 private Phone mPhone;
Andrew Lee5efb1122014-12-05 04:20:42 -080027 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070028
29 @Override
30 protected void onCreate(Bundle icicle) {
31 super.onCreate(icicle);
32
33 addPreferencesFromResource(R.xml.gsm_umts_additional_options);
34
Andrew Leedd4f6df2014-12-09 19:13:51 -080035 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5efb1122014-12-05 04:20:42 -080036 mSubscriptionInfoHelper.setActionBarTitle(
Andrew Lee2b36ba22014-11-05 17:08:49 -080037 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
Andrew Lee5efb1122014-12-05 04:20:42 -080038 mPhone = mSubscriptionInfoHelper.getPhone();
Andrew Lee2b36ba22014-11-05 17:08:49 -080039
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040 PreferenceScreen prefSet = getPreferenceScreen();
41 mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
fionaxue46e69f2017-04-27 14:32:46 -070042 mCWButton = (CallWaitingSwitchPreference) prefSet.findPreference(BUTTON_CW_KEY);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070043
44 mPreferences.add(mCLIRButton);
45 mPreferences.add(mCWButton);
46
47 if (icicle == null) {
48 if (DBG) Log.d(LOG_TAG, "start to init ");
Andrew Lee2b36ba22014-11-05 17:08:49 -080049 mCLIRButton.init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070050 } else {
51 if (DBG) Log.d(LOG_TAG, "restore stored states");
52 mInitIndex = mPreferences.size();
Andrew Lee2b36ba22014-11-05 17:08:49 -080053 mCLIRButton.init(this, true, mPhone);
54 mCWButton.init(this, true, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070055 int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
56 if (clirArray != null) {
57 if (DBG) Log.d(LOG_TAG, "onCreate: clirArray[0]="
58 + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
59 mCLIRButton.handleGetCLIRResult(clirArray);
60 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -080061 mCLIRButton.init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070062 }
63 }
64
65 ActionBar actionBar = getActionBar();
66 if (actionBar != null) {
67 // android.R.id.home will be triggered in onOptionsItemSelected()
68 actionBar.setDisplayHomeAsUpEnabled(true);
69 }
70 }
71
72 @Override
73 protected void onSaveInstanceState(Bundle outState) {
74 super.onSaveInstanceState(outState);
75
76 if (mCLIRButton.clirArray != null) {
77 outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
78 }
79 }
80
81 @Override
82 public void onFinished(Preference preference, boolean reading) {
83 if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
84 mInitIndex++;
85 Preference pref = mPreferences.get(mInitIndex);
fionaxue46e69f2017-04-27 14:32:46 -070086 if (pref instanceof CallWaitingSwitchPreference) {
87 ((CallWaitingSwitchPreference) pref).init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070088 }
89 }
90 super.onFinished(preference, reading);
91 }
92
93 @Override
94 public boolean onOptionsItemSelected(MenuItem item) {
95 final int itemId = item.getItemId();
96 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Andrew Lee5efb1122014-12-05 04:20:42 -080097 CallFeaturesSetting.goUpToTopLevelSetting(this, mSubscriptionInfoHelper);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070098 return true;
99 }
100 return super.onOptionsItemSelected(item);
101 }
102}