1 package com.android.phone;
2 
3 import android.app.ActionBar;
4 import android.content.Intent;
5 import android.os.Bundle;
6 import android.preference.Preference;
7 import android.preference.PreferenceScreen;
8 import android.util.Log;
9 import android.view.MenuItem;
10 
11 import com.android.internal.telephony.Phone;
12 
13 import java.util.ArrayList;
14 
15 public class GsmUmtsAdditionalCallOptions extends TimeConsumingPreferenceActivity {
16     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>();
26     private int mInitIndex = 0;
27     private Phone mPhone;
28     private SubscriptionInfoHelper mSubscriptionInfoHelper;
29 
30     @Override
onCreate(Bundle icicle)31     protected void onCreate(Bundle icicle) {
32         super.onCreate(icicle);
33 
34         addPreferencesFromResource(R.xml.gsm_umts_additional_options);
35 
36         mSubscriptionInfoHelper = new SubscriptionInfoHelper(this, getIntent());
37         mSubscriptionInfoHelper.setActionBarTitle(
38                 getActionBar(), getResources(), R.string.additional_gsm_call_settings_with_label);
39         mPhone = mSubscriptionInfoHelper.getPhone();
40 
41         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 ");
50             mCLIRButton.init(this, false, mPhone);
51         } else {
52             if (DBG) Log.d(LOG_TAG, "restore stored states");
53             mInitIndex = mPreferences.size();
54             mCLIRButton.init(this, true, mPhone);
55             mCWButton.init(this, true, mPhone);
56             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 {
62                 mCLIRButton.init(this, false, mPhone);
63             }
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
onSaveInstanceState(Bundle outState)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
onFinished(Preference preference, boolean reading)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) {
88                 ((CallWaitingCheckBoxPreference) pref).init(this, false, mPhone);
89             }
90         }
91         super.onFinished(preference, reading);
92     }
93 
94     @Override
onOptionsItemSelected(MenuItem item)95     public boolean onOptionsItemSelected(MenuItem item) {
96         final int itemId = item.getItemId();
97         if (itemId == android.R.id.home) {  // See ActionBar#setDisplayHomeAsUpEnabled()
98             CallFeaturesSetting.goUpToTopLevelSetting(this, mSubscriptionInfoHelper);
99             return true;
100         }
101         return super.onOptionsItemSelected(item);
102     }
103 }
104