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