diff --git a/src/com/cyanogenmod/setupwizard/setup/CMSetupWizardData.java b/src/com/cyanogenmod/setupwizard/setup/CMSetupWizardData.java index fa32537..ca0d9de 100644 --- a/src/com/cyanogenmod/setupwizard/setup/CMSetupWizardData.java +++ b/src/com/cyanogenmod/setupwizard/setup/CMSetupWizardData.java @@ -89,6 +89,7 @@ public class CMSetupWizardData extends AbstractSetupData { showHideDataSimPage(); showHideSimMissingPage(); showHideMobileDataPage(); + updateWelcomePage(); } else if (intent.getAction() .equals(ConnectivityManager.CONNECTIVITY_ACTION)) { showHideMobileDataPage(); @@ -160,6 +161,13 @@ public class CMSetupWizardData extends AbstractSetupData { } } + private void updateWelcomePage() { + WelcomePage welcomePage = (WelcomePage) getPage(WelcomePage.TAG); + if (welcomePage != null) { + welcomePage.simChanged(); + } + } + public IntentFilter getIntentFilter() { IntentFilter filter = new IntentFilter(); if (SetupWizardUtils.hasTelephony(mContext)) { diff --git a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java index b925b32..3c4e510 100644 --- a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java +++ b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java @@ -29,6 +29,7 @@ import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; import android.os.Handler; +import android.telephony.TelephonyManager; import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; @@ -79,6 +80,9 @@ public class WelcomePage extends SetupPage { confirmCyanogenCredentials(mWelcomeFragment); return true; } else { + if (mWelcomeFragment != null) { + mWelcomeFragment.sendLocaleStats(); + } return super.doNextAction(); } } @@ -160,13 +164,19 @@ public class WelcomePage extends SetupPage { return false; } + public void simChanged() { + if (mWelcomeFragment != null) { + mWelcomeFragment.simChanged(); + } + } + public static class WelcomeFragment extends SetupPageFragment { private ArrayAdapter mLocaleAdapter; private Locale mInitialLocale; private Locale mCurrentLocale; private int[] mAdapterIndices; - + private boolean mUserPickedLocale; private LocalePicker mLanguagePicker; private final Handler mHandler = new Handler(); @@ -191,10 +201,26 @@ public class WelcomePage extends SetupPage { } } + private Locale getSimLocale() { + Activity activity = getActivity(); + if (activity != null) { + TelephonyManager telephonyManager = (TelephonyManager) activity. + getSystemService(Context.TELEPHONY_SERVICE); + String locale = telephonyManager.getLocaleFromDefaultSim(); + if (locale != null) { + return Locale.forLanguageTag(locale); + } + } + return null; + } + private void loadLanguages() { mLocaleAdapter = com.android.internal.app.LocalePicker.constructAdapter(getActivity(), R.layout.locale_picker_item, R.id.locale); - mInitialLocale = Locale.getDefault(); - mCurrentLocale = mInitialLocale; + mCurrentLocale = mInitialLocale = Locale.getDefault(); + Locale simLocale = getSimLocale(); + if (simLocale != null) { + mCurrentLocale = simLocale; + } mAdapterIndices = new int[mLocaleAdapter.getCount()]; int currentLocaleIndex = 0; String [] labels = new String[mLocaleAdapter.getCount()]; @@ -219,6 +245,7 @@ public class WelcomePage extends SetupPage { } private void setLocaleFromPicker() { + mUserPickedLocale = true; int i = mAdapterIndices[mLanguagePicker.getValue()]; final com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo = mLocaleAdapter.getItem(i); onLocaleChanged(localLocaleInfo.getLocale()); @@ -234,9 +261,6 @@ public class WelcomePage extends SetupPage { localResources.updateConfiguration(localConfiguration1, null); mHandler.removeCallbacks(mUpdateLocale); mCurrentLocale = paramLocale; - SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED, - SetupStats.Action.CHANGE_LOCALE, SetupStats.Label.LOCALE, - mCurrentLocale.getDisplayName()); mHandler.postDelayed(mUpdateLocale, 1000); } @@ -245,6 +269,23 @@ public class WelcomePage extends SetupPage { return R.layout.setup_welcome_page; } + public void sendLocaleStats() { + if (!mCurrentLocale.equals(mInitialLocale)) { + SetupStats.addEvent(SetupStats.Categories.SETTING_CHANGED, + SetupStats.Action.CHANGE_LOCALE, SetupStats.Label.LOCALE, + mCurrentLocale.getDisplayName()); + } + } + + public void simChanged() { + if (mUserPickedLocale || isDetached()) { + return; + } + Locale simLocale = getSimLocale(); + if (simLocale != null && !simLocale.equals(mCurrentLocale)) { + onLocaleChanged(simLocale); + } + } } }