From 45e5813f151837f0bd7f961ed94f017efa4e8594 Mon Sep 17 00:00:00 2001 From: Jimmy Shih Date: Mon, 8 Jul 2013 13:15:46 -0700 Subject: [PATCH] Set default units to imperial if in US --- MyTracks/res/layout-land/track_list.xml | 1 - MyTracks/res/layout/track_list.xml | 1 - .../apps/mytracks/TrackListActivity.java | 21 ++++---- .../fragments/EulaDialogFragment.java | 7 --- .../android/apps/mytracks/util/EulaUtils.java | 48 +++++++++++++++++-- 5 files changed, 55 insertions(+), 23 deletions(-) diff --git a/MyTracks/res/layout-land/track_list.xml b/MyTracks/res/layout-land/track_list.xml index cd90423ac..746063342 100644 --- a/MyTracks/res/layout-land/track_list.xml +++ b/MyTracks/res/layout-land/track_list.xml @@ -30,7 +30,6 @@ limitations under the License. android:layout_weight="1.0" android:layout_width="0dp" android:text="@string/track_list_empty_message" - android:visibility="gone" style="@style/ListEmptyTextView" > \ No newline at end of file diff --git a/MyTracks/res/layout/track_list.xml b/MyTracks/res/layout/track_list.xml index 1746c5496..51dc9628f 100644 --- a/MyTracks/res/layout/track_list.xml +++ b/MyTracks/res/layout/track_list.xml @@ -29,7 +29,6 @@ limitations under the License. android:layout_weight="1.0" android:layout_width="match_parent" android:text="@string/track_list_empty_message" - android:visibility="gone" style="@style/ListEmptyTextView" > diff --git a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java index 7fd070308..26104ceab 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java +++ b/MyTracks/src/com/google/android/apps/mytracks/TrackListActivity.java @@ -84,6 +84,8 @@ import android.widget.AdapterView.OnItemClickListener; import android.widget.ListView; import android.widget.Toast; +import java.util.Locale; + /** * An activity displaying a list of tracks. * @@ -645,7 +647,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity * Shows start up dialogs. */ public void showStartupDialogs() { - if (!EulaUtils.getAcceptEula(this)) { + if (!EulaUtils.hasAcceptEula(this)) { Fragment fragment = getSupportFragmentManager() .findFragmentByTag(EulaDialogFragment.EULA_DIALOG_TAG); if (fragment == null) { @@ -653,19 +655,20 @@ public class TrackListActivity extends AbstractSendToGoogleActivity .show(getSupportFragmentManager(), EulaDialogFragment.EULA_DIALOG_TAG); } } else { - /* - * Before the welcome sequence, the empty view is not visible so that it - * doesn't show through. - */ - findViewById(R.id.track_list_empty_view).setVisibility(View.VISIBLE); - + if (!EulaUtils.hasDefaultUnits(this)) { + String statsUnits = getString( + Locale.US.equals(Locale.getDefault()) ? R.string.stats_units_imperial + : R.string.stats_units_metric); + PreferencesUtils.setString(this, R.string.stats_units_key, statsUnits); + EulaUtils.setDefaultUnits(this); + } checkGooglePlayServices(); } } @Override public void onEulaDone() { - if (EulaUtils.getAcceptEula(this)) { + if (EulaUtils.hasAcceptEula(this)) { showStartupDialogs(); return; } @@ -692,7 +695,7 @@ public class TrackListActivity extends AbstractSendToGoogleActivity } private void showEnableSync() { - if (EulaUtils.getShowEnableSync(this)) { + if (EulaUtils.hasShowEnableSync(this)) { Fragment fragment = getSupportFragmentManager() .findFragmentByTag(EnableSyncDialogFragment.ENABLE_SYNC_DIALOG_TAG); if (fragment == null) { diff --git a/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java b/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java index 54ebdf249..4c7f15a51 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java +++ b/MyTracks/src/com/google/android/apps/mytracks/fragments/EulaDialogFragment.java @@ -17,7 +17,6 @@ package com.google.android.apps.mytracks.fragments; import com.google.android.apps.mytracks.util.EulaUtils; -import com.google.android.apps.mytracks.util.PreferencesUtils; import com.google.android.maps.mytracks.R; import android.app.Activity; @@ -33,8 +32,6 @@ import android.text.util.Linkify; import android.view.KeyEvent; import android.widget.TextView; -import java.util.Locale; - /** * A DialogFragment to show EULA. * @@ -120,10 +117,6 @@ public class EulaDialogFragment extends DialogFragment { @Override public void onClick(DialogInterface dialog, int which) { EulaUtils.setAcceptEula(fragmentActivity); - String statsUnits = fragmentActivity.getString( - Locale.US.equals(Locale.getDefault()) ? R.string.stats_units_imperial - : R.string.stats_units_metric); - PreferencesUtils.setString(fragmentActivity, R.string.stats_units_key, statsUnits); caller.onEulaDone(); } }); diff --git a/MyTracks/src/com/google/android/apps/mytracks/util/EulaUtils.java b/MyTracks/src/com/google/android/apps/mytracks/util/EulaUtils.java index 2a612385d..5976d3bf1 100644 --- a/MyTracks/src/com/google/android/apps/mytracks/util/EulaUtils.java +++ b/MyTracks/src/com/google/android/apps/mytracks/util/EulaUtils.java @@ -30,25 +30,63 @@ public class EulaUtils { // Accepting Google mobile terms of service private static final String ACCEPT_EULA_PREFERENCE_KEY = "eula.google_mobile_tos_accepted"; + private static final String DEFAULT_UNITS_PREFERENCE_KEY = "defaultUnits"; private static final String SHOW_ENABLE_SYNC_PREFERENCE_KEY = "showEnableSync"; private EulaUtils() {} - public static boolean getAcceptEula(Context context) { + /** + * Returns true if eula is accepted. + * @param context the context + */ + public static boolean hasAcceptEula(Context context) { return getValue(context, ACCEPT_EULA_PREFERENCE_KEY, false); } + /** + * Sets to true that eula is accepted. + * + * @param context the context + */ public static void setAcceptEula(Context context) { setValue(context, ACCEPT_EULA_PREFERENCE_KEY, true); } - - public static boolean getShowEnableSync(Context context) { + + /** + * Returns true if the default units is initialized. + * + * @param context the context + */ + public static boolean hasDefaultUnits(Context context) { + return getValue(context, DEFAULT_UNITS_PREFERENCE_KEY, false); + } + + /** + * Sets to true that the default units is initialized. + * + * @param context the context + */ + public static void setDefaultUnits(Context context) { + setValue(context, DEFAULT_UNITS_PREFERENCE_KEY, true); + } + + /** + * Returns true if show enable sync is needed. + * + * @param context the context + */ + public static boolean hasShowEnableSync(Context context) { return getValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, true); } - + + /** + * Sets to false that show enable sync is needed. + * + * @param context the context + */ public static void setShowEnableSync(Context context) { setValue(context, SHOW_ENABLE_SYNC_PREFERENCE_KEY, false); - } + } private static boolean getValue(Context context, String key, boolean defaultValue) { SharedPreferences sharedPreferences = context.getSharedPreferences(