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
This commit is contained in:
Danesh M 2016-01-18 18:39:02 -08:00
parent f8e4ab690f
commit d59304c730
2 changed files with 55 additions and 6 deletions

View File

@ -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)) {

View File

@ -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);
}
}
}
}