blob: 05405471a26e04146d8b62005834f31daa462642 [file] [log] [blame]
Santos Cordon7d4ddf62013-07-10 11:58:08 -07001package com.android.phone;
2
3import android.app.ActionBar;
4import android.content.Intent;
5import android.os.Bundle;
6import android.preference.Preference;
7import android.preference.PreferenceScreen;
8import android.util.Log;
9import android.view.MenuItem;
10
Andrew Lee2b36ba22014-11-05 17:08:49 -080011import com.android.internal.telephony.Phone;
12
Santos Cordon7d4ddf62013-07-10 11:58:08 -070013import java.util.ArrayList;
14
Andrew Lee2b36ba22014-11-05 17:08:49 -080015public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
Santos Cordon7d4ddf62013-07-10 11:58:08 -070016 private static final String LOG_TAG = "GsmUmtsAdditionalCallOptions";
17 private final boolean DBG = (PhoneGlobals.DBG_LEVEL >= 2);
18
19 private static final String BUTTON_CLIR_KEY = "button_clir_key";
20 private static final String BUTTON_CW_KEY = "button_cw_key";
21
22 private CLIRListPreference mCLIRButton;
23 private CallWaitingCheckBoxPreference mCWButton;
24
25 private final ArrayList<Preference> mPreferences = new ArrayList<Preference>();
Andrew Lee2b36ba22014-11-05 17:08:49 -080026 private int mInitIndex = 0;
27 private Phone mPhone;
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 Lee2b36ba22014-11-05 17:08:49 -080035 SubscriptionInfoHelper subscriptionInfoHelper = new SubscriptionInfoHelper(getIntent());
36 subscriptionInfoHelper.setActionBarTitle(
37 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
38 mPhone = subscriptionInfoHelper.getPhone();
39
Santos Cordon7d4ddf62013-07-10 11:58:08 -070040 PreferenceScreen prefSet = getPreferenceScreen();
41 mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
42 mCWButton = (CallWaitingCheckBoxPreference) prefSet.findPreference(BUTTON_CW_KEY);
43
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);
86 if (pref instanceof CallWaitingCheckBoxPreference) {
Andrew Lee2b36ba22014-11-05 17:08:49 -080087 ((CallWaitingCheckBoxPreference) 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()
97 CallFeaturesSetting.goUpToTopLevelSetting(this);
98 return true;
99 }
100 return super.onOptionsItemSelected(item);
101 }
102}