diff options
author | Danesh M <daneshm90@gmail.com> | 2016-01-25 10:41:33 -0800 |
---|---|---|
committer | Danesh M <daneshm90@gmail.com> | 2016-01-25 11:24:33 -0800 |
commit | 00ad2213ff4e290e025bcf8d5748222d21edb1d5 (patch) | |
tree | 3041a87eb317c751efdf4210a87cedc82062738e /src/com/cyanogenmod/setupwizard/setup | |
parent | d59304c730d9ff61da8857ad18cf1e0646b363ce (diff) | |
download | packages_apps_SetupWizard-00ad2213ff4e290e025bcf8d5748222d21edb1d5.zip packages_apps_SetupWizard-00ad2213ff4e290e025bcf8d5748222d21edb1d5.tar.gz packages_apps_SetupWizard-00ad2213ff4e290e025bcf8d5748222d21edb1d5.tar.bz2 |
SetupWizard : Ensure we don't override user locale picks
Take scroll events into consideration when deciding whether to override
user locale with sim locale.
Also move locale fetching to be async so we don't cause any unecessary
blocking.
CYNGNOS-1521
Change-Id: I0c4c1b89dd227f661c1a1cdcce445349fe4a206f
Diffstat (limited to 'src/com/cyanogenmod/setupwizard/setup')
-rw-r--r-- | src/com/cyanogenmod/setupwizard/setup/WelcomePage.java | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java index 3c4e510..248420e 100644 --- a/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java +++ b/src/com/cyanogenmod/setupwizard/setup/WelcomePage.java @@ -27,6 +27,7 @@ import android.content.Context; import android.content.Intent; import android.content.res.Configuration; import android.content.res.Resources; +import android.os.AsyncTask; import android.os.Bundle; import android.os.Handler; import android.telephony.TelephonyManager; @@ -34,6 +35,7 @@ import android.util.Log; import android.view.View; import android.widget.ArrayAdapter; import android.widget.NumberPicker; +import android.widget.Toast; import com.cyanogenmod.setupwizard.R; import com.cyanogenmod.setupwizard.SetupWizardApp; @@ -166,7 +168,7 @@ public class WelcomePage extends SetupPage { public void simChanged() { if (mWelcomeFragment != null) { - mWelcomeFragment.simChanged(); + mWelcomeFragment.fetchAndUpdateSimLocale(); } } @@ -176,9 +178,9 @@ public class WelcomePage extends SetupPage { private Locale mInitialLocale; private Locale mCurrentLocale; private int[] mAdapterIndices; - private boolean mUserPickedLocale; + private boolean mIgnoreSimLocale; private LocalePicker mLanguagePicker; - + private FetchUpdateSimLocaleTask mFetchUpdateSimLocaleTask; private final Handler mHandler = new Handler(); private final Runnable mUpdateLocale = new Runnable() { @@ -201,26 +203,10 @@ 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); mCurrentLocale = mInitialLocale = Locale.getDefault(); - Locale simLocale = getSimLocale(); - if (simLocale != null) { - mCurrentLocale = simLocale; - } + fetchAndUpdateSimLocale(); mAdapterIndices = new int[mLocaleAdapter.getCount()]; int currentLocaleIndex = 0; String [] labels = new String[mLocaleAdapter.getCount()]; @@ -242,10 +228,18 @@ public class WelcomePage extends SetupPage { setLocaleFromPicker(); } }); + mLanguagePicker.setOnScrollListener(new LocalePicker.OnScrollListener() { + @Override + public void onScrollStateChange(LocalePicker view, int scrollState) { + if (scrollState == SCROLL_STATE_TOUCH_SCROLL) { + mIgnoreSimLocale = true; + } + } + }); } private void setLocaleFromPicker() { - mUserPickedLocale = true; + mIgnoreSimLocale = true; int i = mAdapterIndices[mLanguagePicker.getValue()]; final com.android.internal.app.LocalePicker.LocaleInfo localLocaleInfo = mLocaleAdapter.getItem(i); onLocaleChanged(localLocaleInfo.getLocale()); @@ -277,13 +271,42 @@ public class WelcomePage extends SetupPage { } } - public void simChanged() { - if (mUserPickedLocale || isDetached()) { + public void fetchAndUpdateSimLocale() { + if (mIgnoreSimLocale || isDetached()) { return; } - Locale simLocale = getSimLocale(); - if (simLocale != null && !simLocale.equals(mCurrentLocale)) { - onLocaleChanged(simLocale); + if (mFetchUpdateSimLocaleTask != null) { + mFetchUpdateSimLocaleTask.cancel(true); + } + mFetchUpdateSimLocaleTask = new FetchUpdateSimLocaleTask(); + mFetchUpdateSimLocaleTask.execute(); + } + + private class FetchUpdateSimLocaleTask extends AsyncTask<Void, Void, Locale> { + @Override + protected Locale doInBackground(Void... params) { + 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; + } + + @Override + protected void onPostExecute(Locale simLocale) { + if (simLocale != null && !simLocale.equals(mCurrentLocale)) { + if (!mIgnoreSimLocale && !isDetached()) { + String label = getString(R.string.sim_locale_changed, + simLocale.getDisplayName()); + Toast.makeText(getActivity(), label, Toast.LENGTH_SHORT).show(); + onLocaleChanged(simLocale); + } + } } } } |