blob: 88d32fbf585af91a138778c6ef779bf46b0335fb [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;
Andrew Lee5efb1122014-12-05 04:20:42 -080028 private SubscriptionInfoHelper mSubscriptionInfoHelper;
Santos Cordon7d4ddf62013-07-10 11:58:08 -070029
30 @Override
31 protected void onCreate(Bundle icicle) {
32 super.onCreate(icicle);
33
34 addPreferencesFromResource(R.xml.gsm_umts_additional_options);
35
Andrew Leedd4f6df2014-12-09 19:13:51 -080036 mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
Andrew Lee5efb1122014-12-05 04:20:42 -080037 mSubscriptionInfoHelper.setActionBarTitle(
Andrew Lee2b36ba22014-11-05 17:08:49 -080038 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
Andrew Lee5efb1122014-12-05 04:20:42 -080039 mPhone = mSubscriptionInfoHelper.getPhone();
Andrew Lee2b36ba22014-11-05 17:08:49 -080040
Santos Cordon7d4ddf62013-07-10 11:58:08 -070041 PreferenceScreen prefSet = getPreferenceScreen();
42 mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY);
43 mCWButton = (CallWaitingCheckBoxPreference) prefSet.findPreference(BUTTON_CW_KEY);
44
45 mPreferences.add(mCLIRButton);
46 mPreferences.add(mCWButton);
47
48 if (icicle == null) {
49 if (DBG) Log.d(LOG_TAG, "start to init ");
Andrew Lee2b36ba22014-11-05 17:08:49 -080050 mCLIRButton.init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070051 } else {
52 if (DBG) Log.d(LOG_TAG, "restore stored states");
53 mInitIndex = mPreferences.size();
Andrew Lee2b36ba22014-11-05 17:08:49 -080054 mCLIRButton.init(this, true, mPhone);
55 mCWButton.init(this, true, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070056 int[] clirArray = icicle.getIntArray(mCLIRButton.getKey());
57 if (clirArray != null) {
58 if (DBG) Log.d(LOG_TAG, "onCreate: clirArray[0]="
59 + clirArray[0] + ", clirArray[1]=" + clirArray[1]);
60 mCLIRButton.handleGetCLIRResult(clirArray);
61 } else {
Andrew Lee2b36ba22014-11-05 17:08:49 -080062 mCLIRButton.init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070063 }
64 }
65
66 ActionBar actionBar = getActionBar();
67 if (actionBar != null) {
68 // android.R.id.home will be triggered in onOptionsItemSelected()
69 actionBar.setDisplayHomeAsUpEnabled(true);
70 }
71 }
72
73 @Override
74 protected void onSaveInstanceState(Bundle outState) {
75 super.onSaveInstanceState(outState);
76
77 if (mCLIRButton.clirArray != null) {
78 outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray);
79 }
80 }
81
82 @Override
83 public void onFinished(Preference preference, boolean reading) {
84 if (mInitIndex < mPreferences.size()-1 && !isFinishing()) {
85 mInitIndex++;
86 Preference pref = mPreferences.get(mInitIndex);
87 if (pref instanceof CallWaitingCheckBoxPreference) {
Andrew Lee2b36ba22014-11-05 17:08:49 -080088 ((CallWaitingCheckBoxPreference) pref).init(this, false, mPhone);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070089 }
90 }
91 super.onFinished(preference, reading);
92 }
93
94 @Override
95 public boolean onOptionsItemSelected(MenuItem item) {
96 final int itemId = item.getItemId();
97 if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled()
Andrew Lee5efb1122014-12-05 04:20:42 -080098 CallFeaturesSetting.goUpToTopLevelSetting(this, mSubscriptionInfoHelper);
Santos Cordon7d4ddf62013-07-10 11:58:08 -070099 return true;
100 }
101 return super.onOptionsItemSelected(item);
102 }
103}