Santos Cordon | 7d4ddf6 | 2013-07-10 11:58:08 -0700 | [diff] [blame] | 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 java.util.ArrayList; |
| 12 | |
| 13 | public class GsmUmtsAdditionalCallOptions extends |
| 14 | 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 CallWaitingCheckBoxPreference mCWButton; |
| 23 | |
| 24 | private final ArrayList<Preference> mPreferences = new ArrayList<Preference>(); |
| 25 | private int mInitIndex= 0; |
| 26 | |
| 27 | @Override |
| 28 | protected void onCreate(Bundle icicle) { |
| 29 | super.onCreate(icicle); |
| 30 | |
| 31 | addPreferencesFromResource(R.xml.gsm_umts_additional_options); |
| 32 | |
| 33 | PreferenceScreen prefSet = getPreferenceScreen(); |
| 34 | mCLIRButton = (CLIRListPreference) prefSet.findPreference(BUTTON_CLIR_KEY); |
| 35 | mCWButton = (CallWaitingCheckBoxPreference) prefSet.findPreference(BUTTON_CW_KEY); |
| 36 | |
| 37 | mPreferences.add(mCLIRButton); |
| 38 | mPreferences.add(mCWButton); |
| 39 | |
| 40 | if (icicle == null) { |
| 41 | if (DBG) Log.d(LOG_TAG, "start to init "); |
| 42 | mCLIRButton.init(this, false); |
| 43 | } else { |
| 44 | if (DBG) Log.d(LOG_TAG, "restore stored states"); |
| 45 | mInitIndex = mPreferences.size(); |
| 46 | mCLIRButton.init(this, true); |
| 47 | mCWButton.init(this, true); |
| 48 | int[] clirArray = icicle.getIntArray(mCLIRButton.getKey()); |
| 49 | if (clirArray != null) { |
| 50 | if (DBG) Log.d(LOG_TAG, "onCreate: clirArray[0]=" |
| 51 | + clirArray[0] + ", clirArray[1]=" + clirArray[1]); |
| 52 | mCLIRButton.handleGetCLIRResult(clirArray); |
| 53 | } else { |
| 54 | mCLIRButton.init(this, false); |
| 55 | } |
| 56 | } |
| 57 | |
| 58 | ActionBar actionBar = getActionBar(); |
| 59 | if (actionBar != null) { |
| 60 | // android.R.id.home will be triggered in onOptionsItemSelected() |
| 61 | actionBar.setDisplayHomeAsUpEnabled(true); |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | protected void onSaveInstanceState(Bundle outState) { |
| 67 | super.onSaveInstanceState(outState); |
| 68 | |
| 69 | if (mCLIRButton.clirArray != null) { |
| 70 | outState.putIntArray(mCLIRButton.getKey(), mCLIRButton.clirArray); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public void onFinished(Preference preference, boolean reading) { |
| 76 | if (mInitIndex < mPreferences.size()-1 && !isFinishing()) { |
| 77 | mInitIndex++; |
| 78 | Preference pref = mPreferences.get(mInitIndex); |
| 79 | if (pref instanceof CallWaitingCheckBoxPreference) { |
| 80 | ((CallWaitingCheckBoxPreference) pref).init(this, false); |
| 81 | } |
| 82 | } |
| 83 | super.onFinished(preference, reading); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public boolean onOptionsItemSelected(MenuItem item) { |
| 88 | final int itemId = item.getItemId(); |
| 89 | if (itemId == android.R.id.home) { // See ActionBar#setDisplayHomeAsUpEnabled() |
| 90 | CallFeaturesSetting.goUpToTopLevelSetting(this); |
| 91 | return true; |
| 92 | } |
| 93 | return super.onOptionsItemSelected(item); |
| 94 | } |
| 95 | } |