summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDanesh M <daneshm90@gmail.com>2016-01-18 18:39:02 -0800
committerDanesh M <daneshm90@gmail.com>2016-01-20 10:33:08 -0800
commitd59304c730d9ff61da8857ad18cf1e0646b363ce (patch)
treecfc03ea37a5c8b5af43b7864b564e1f54e0ed755
parentf8e4ab690f3961f2240601b0956c0e1931e6a8d0 (diff)
downloadpackages_apps_SetupWizard-d59304c730d9ff61da8857ad18cf1e0646b363ce.zip
packages_apps_SetupWizard-d59304c730d9ff61da8857ad18cf1e0646b363ce.tar.gz
packages_apps_SetupWizard-d59304c730d9ff61da8857ad18cf1e0646b363ce.tar.bz2
SetupWizard : Switch to mcc/mnc locale
Also ensure we only send stats event once and only if the user actually changed the locale. CYNGNOS-1521 CYNGNOS-1326 Change-Id: I7b0451137e6bf80bf71350da28fe391fc8c52ce8
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/CMSetupWizardData.java8
-rw-r--r--src/com/cyanogenmod/setupwizard/setup/WelcomePage.java53
2 files changed, 55 insertions, 6 deletions
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<com.android.internal.app.LocalePicker.LocaleInfo> 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);
+ }
+ }
}
}