forked from upstream-mirrors/OpenTracks
Set default units to imperial if in US
This commit is contained in:
@@ -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" >
|
||||
</TextView>
|
||||
</LinearLayout>
|
||||
@@ -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" >
|
||||
</TextView>
|
||||
<include layout="@layout/track_controller" />
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user