diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java index 7d510ad..20399cd 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/MainActivity.java @@ -902,6 +902,10 @@ return activeNetwork != null && activeNetwork.isConnected(); } + public static boolean useFahrenheit() { + return sharedPrefs.getBoolean(res.getString(R.string.settings_use_fahrenheit_key), false); + } + public static String formatTimeIntervalToHms(int seconds) { Log.d(TAG, "seconds: " + seconds); int hours = seconds / 3600; @@ -959,8 +963,8 @@ weatherSymbol.setImageDrawable(weather.getWeatherCodeImage()); weatherCity.setText(String.format(Locale.getDefault(), res.getString(R.string.weather_city_display), weather.getCity(), weather.getCountry())); weatherDesc.setText(weather.getWeatherDesc()); - weatherMinTemp.setText(String.format(Locale.getDefault(), res.getString(R.string.preferences_n_degree_floating), weather.getMinTemp())); - weatherMaxTemp.setText(String.format(Locale.getDefault(), res.getString(R.string.preferences_n_degree_floating), weather.getMaxTemp())); + weatherMinTemp.setText(String.format(Locale.getDefault(), res.getString(R.string.preferences_n_degree_c_floating), weather.getMinTemp())); + weatherMaxTemp.setText(String.format(Locale.getDefault(), res.getString(R.string.preferences_n_degree_c_floating), weather.getMaxTemp())); if(weather.isSevereWeather()) weatherCity.setCompoundDrawablesWithIntrinsicBounds(null, null, res.getDrawable(R.drawable.ic_warning, null), null); else weatherCity.setCompoundDrawables(null, null, null, null); weatherHandler.displayHints(weather); diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarDegreePreference.java b/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarDegreePreference.java new file mode 100644 index 0000000..0459152 --- /dev/null +++ b/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarDegreePreference.java @@ -0,0 +1,57 @@ +/** + * This file is part of MountainNavigation. + * + * MountainNavigation is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * MountainNavigation is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with MountainNavigation. If not, see . + * + * @copyright Copyright (c) 2016 Vinzenz Rosenkanz + * + * @author Vinzenz Rosenkranz + */ + +package de.apps4ics.mountainnavigation; + +import android.content.Context; +import android.content.res.TypedArray; +import android.util.AttributeSet; + +import de.apps4ics.mountainnavigation.handlers.WeatherHandler; + +public class SeekBarDegreePreference extends SeekBarPreference { + protected String fText; + + public SeekBarDegreePreference(Context context, AttributeSet attrs) { + super(context, attrs); + } + + @Override + protected void init(AttributeSet attrs) { + TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.MinSeekBar); + TypedArray ta2 = getContext().obtainStyledAttributes(attrs, R.styleable.MinSeekBarDegree); + this.text = ta.getString(R.styleable.MinSeekBar_android_text); + this.maxValue = ta.getInt(R.styleable.MinSeekBar_android_max, DEFAULT_MAX_VALUE); + this.minValue = ta.getInt(R.styleable.MinSeekBar_min, DEFAULT_MIN_VALUE); + this.fText = ta2.getString(R.styleable.MinSeekBarDegree_fahrenheitText); + ta.recycle(); + ta2.recycle(); + } + + @Override + protected String getInfoText(int value) { + if(MainActivity.useFahrenheit()) { + return String.format(fText, (int) Math.round(WeatherHandler.celsiusToFahrenheit(value))); + } else { + return String.format(text, value); + } + } +} diff --git a/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarPreference.java b/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarPreference.java index 90064fd..74b0554 100644 --- a/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarPreference.java +++ b/app/src/main/java/de/apps4ics/mountainnavigation/SeekBarPreference.java @@ -32,21 +32,21 @@ import android.widget.LinearLayout; public class SeekBarPreference extends DialogPreference implements SeekBar.OnSeekBarChangeListener { - private Context context; - private int maxValue; - private int minValue; - private int currentValue; - private int defaultStart; - private boolean isDays; - private String text; + protected Context context; + protected int maxValue; + protected int minValue; + protected int currentValue; + protected int defaultStart; + protected boolean isDays; + protected String text; - private SeekBar seekBar; - private TextView infoText; + protected SeekBar seekBar; + protected TextView infoText; - private final static int DEFAULT_MAX_VALUE = 100; - private final static int DEFAULT_MIN_VALUE = 0; - private final static String DEFAULT_VALUE = "defaultValue"; - private static final String AND_NAMESPACE = "http://schemas.android.com/apk/res/android"; + protected final static int DEFAULT_MAX_VALUE = 100; + protected final static int DEFAULT_MIN_VALUE = 0; + protected final static String DEFAULT_VALUE = "defaultValue"; + protected static final String AND_NAMESPACE = "http://schemas.android.com/apk/res/android"; public SeekBarPreference(Context context) { super(context, null); @@ -59,7 +59,7 @@ init(attrs); } - private void init(AttributeSet attrs) { + protected void init(AttributeSet attrs) { TypedArray ta = getContext().obtainStyledAttributes(attrs, R.styleable.MinSeekBar); this.text = ta.getString(R.styleable.MinSeekBar_android_text); this.maxValue = ta.getInt(R.styleable.MinSeekBar_android_max, DEFAULT_MAX_VALUE); @@ -68,7 +68,7 @@ ta.recycle(); } - private String getInfoText(int value) { + protected String getInfoText(int value) { if(isDays) { return MainActivity.getRes().getQuantityString(R.plurals.number_of_days_plurals, value, value); } else { diff --git a/app/src/main/res/values-de-rDE/strings.xml b/app/src/main/res/values-de-rDE/strings.xml index 0fdf3c1..811cb2e 100644 --- a/app/src/main/res/values-de-rDE/strings.xml +++ b/app/src/main/res/values-de-rDE/strings.xml @@ -119,8 +119,10 @@ Spezifischer Ort Ort… %1$s in %2$s gefunden - %1$s\u2103 - %1$.01f\u2103 + %1$s\u2103 + %1$.01f\u2103 + %1$s\u2109 + %1$.01f\u2109 © OpenStreetMap-Mitwirkende diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml index 56b5b83..06ed9a9 100644 --- a/app/src/main/res/values/attrs.xml +++ b/app/src/main/res/values/attrs.xml @@ -26,4 +26,7 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ba4e97a..f1383ce 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -122,8 +122,10 @@ Custom location Location… %1$s found in %2$s - %1$s\u2103 - %1$.01f\u2103 + %1$s\u2103 + %1$.01f\u2103 + %1$s\u2109 + %1$.01f\u2109 © OpenStreetMap contributors diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index b946f88..ed6a689 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -34,26 +34,26 @@ android:key="@string/settings_hint_enable_key" android:defaultValue="true"> - - - + - +