From: Gustavo Martin Morcuende Date: Thu, 20 Nov 2014 04:10:26 +0000 (+0100) Subject: Trying to use only strings from static resources X-Git-Tag: weatherinformation-1.0~41 X-Git-Url: https://git.gumartinm.name/?a=commitdiff_plain;h=0e2ab572fac267984eee069f604d8a85ec215f4f;p=AndroidWeatherInformation Trying to use only strings from static resources --- diff --git a/app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java b/app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java index 3e9956f..7fd351c 100644 --- a/app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java +++ b/app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java @@ -92,8 +92,8 @@ public class MainTabsActivity extends FragmentActivity { }; - actionBar.addTab(actionBar.newTab().setText("CURRENTLY").setTabListener(tabListener)); - actionBar.addTab(actionBar.newTab().setText("FORECAST").setTabListener(tabListener)); + actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_currently)).setTabListener(tabListener)); + actionBar.addTab(actionBar.newTab().setText(this.getString(R.string.text_tab_five_days_forecast)).setTabListener(tabListener)); } @Override @@ -164,11 +164,11 @@ public class MainTabsActivity extends FragmentActivity { final String keyPreference = this.getString(R.string.weather_preferences_day_forecast_key); final String value = sharedPreferences.getString(keyPreference, ""); String humanValue = ""; - if (value.equals("5")) { + if (value.equals(this.getString(R.string.weather_preferences_day_forecast_five_day))) { humanValue = this.getString(R.string.text_tab_five_days_forecast); - } else if (value.equals("10")) { + } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_ten_day))) { humanValue = this.getString(R.string.text_tab_ten_days_forecast); - } else if (value.equals("14")) { + } else if (value.equals(this.getString(R.string.weather_preferences_day_forecast_fourteen_day))) { humanValue = this.getString(R.string.text_tab_fourteen_days_forecast); } actionBar.getTabAt(1).setText(humanValue); diff --git a/app/src/main/java/name/gumartinm/weather/information/boot/BootReceiver.java b/app/src/main/java/name/gumartinm/weather/information/boot/BootReceiver.java index f8a356f..faa78ae 100644 --- a/app/src/main/java/name/gumartinm/weather/information/boot/BootReceiver.java +++ b/app/src/main/java/name/gumartinm/weather/information/boot/BootReceiver.java @@ -41,15 +41,15 @@ public class BootReceiver extends BroadcastReceiver { .getString(R.string.weather_preferences_update_time_rate_key); final String updateTimeRate = sharedPreferences.getString(keyPreference, ""); long chosenInterval = 0; - if (updateTimeRate.equals("900")) { + if (updateTimeRate.equals(context.getString(R.string.update_time_rate_900))) { chosenInterval = AlarmManager.INTERVAL_FIFTEEN_MINUTES; - } else if (updateTimeRate.equals("1800")) { + } else if (updateTimeRate.equals(context.getString(R.string.update_time_rate_1800))) { chosenInterval = AlarmManager.INTERVAL_HALF_HOUR; - } else if (updateTimeRate.equals("3600")) { + } else if (updateTimeRate.equals(context.getString(R.string.update_time_rate_3600))) { chosenInterval = AlarmManager.INTERVAL_HOUR; - } else if (updateTimeRate.equals("43200")) { + } else if (updateTimeRate.equals(context.getString(R.string.update_time_rate_43200))) { chosenInterval = AlarmManager.INTERVAL_HALF_DAY; - } else if (updateTimeRate.equals("86400")) { + } else if (updateTimeRate.equals(context.getString(R.string.update_time_rate_86400))) { chosenInterval = AlarmManager.INTERVAL_DAY; } diff --git a/app/src/main/java/name/gumartinm/weather/information/fragment/current/CurrentFragment.java b/app/src/main/java/name/gumartinm/weather/information/fragment/current/CurrentFragment.java index eccfddc..a356579 100644 --- a/app/src/main/java/name/gumartinm/weather/information/fragment/current/CurrentFragment.java +++ b/app/src/main/java/name/gumartinm/weather/information/fragment/current/CurrentFragment.java @@ -182,7 +182,7 @@ public class CurrentFragment extends Fragment { if (current != null && this.isDataFresh(weatherLocation.getLastCurrentUIUpdate())) { this.updateUI(current); } else { - // Load remote data (aynchronous) + // Load remote data (asynchronous) // Gets the data from the web. this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.VISIBLE); this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE); diff --git a/app/src/main/java/name/gumartinm/weather/information/fragment/overview/OverviewFragment.java b/app/src/main/java/name/gumartinm/weather/information/fragment/overview/OverviewFragment.java index 06ac0f0..30f4acb 100644 --- a/app/src/main/java/name/gumartinm/weather/information/fragment/overview/OverviewFragment.java +++ b/app/src/main/java/name/gumartinm/weather/information/fragment/overview/OverviewFragment.java @@ -351,8 +351,7 @@ public class OverviewFragment extends ListFragment { final String APIVersion = localContext.getResources().getString(R.string.api_version); final String urlAPI = localContext.getResources().getString(R.string.uri_api_weather_forecast); - // TODO: number as resource - final String url = weatherService.createURIAPIForecast(urlAPI, APIVersion, latitude, longitude, "14"); + final String url = weatherService.createURIAPIForecast(urlAPI, APIVersion, latitude, longitude, localContext.getString(R.string.weather_preferences_day_forecast_fourteen_day)); final String urlWithoutCache = url.concat("&time=" + System.currentTimeMillis()); final String jsonData = HTTPClient.retrieveDataAsString(new URL(urlWithoutCache)); diff --git a/app/src/main/java/name/gumartinm/weather/information/notification/NotificationIntentService.java b/app/src/main/java/name/gumartinm/weather/information/notification/NotificationIntentService.java index 59d6637..4ec44f9 100644 --- a/app/src/main/java/name/gumartinm/weather/information/notification/NotificationIntentService.java +++ b/app/src/main/java/name/gumartinm/weather/information/notification/NotificationIntentService.java @@ -120,7 +120,6 @@ public class NotificationIntentService extends IntentService { final SharedPreferences sharedPreferences = PreferenceManager .getDefaultSharedPreferences(this.getApplicationContext()); - // TODO: repeating the same code in Overview, Specific and Current!!! // 1. Update units of measurement. // 1.1 Temperature String tempSymbol; diff --git a/app/src/main/java/name/gumartinm/weather/information/service/IconsList.java b/app/src/main/java/name/gumartinm/weather/information/service/IconsList.java index 5528fc5..ee9d9e6 100644 --- a/app/src/main/java/name/gumartinm/weather/information/service/IconsList.java +++ b/app/src/main/java/name/gumartinm/weather/information/service/IconsList.java @@ -90,6 +90,15 @@ public enum IconsList { return R.drawable.weather_showers; } }, + // TODO: I am sometimes receiving this code, there is no documentation about it on the + // openweathermap site.... But it exists!!! Some day, try to find out more information about it. + // see: http://openweathermap.org/img/w/10dd.png + ICON_10dd("10dd") { + @Override + public int getResourceDrawable() { + return R.drawable.weather_showers_scattered; + } + }, ICON_10d("10d") { @Override public int getResourceDrawable() { diff --git a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java index cf25bd6..58999e8 100644 --- a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java +++ b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java @@ -30,6 +30,7 @@ import android.widget.Switch; import name.gumartinm.weather.information.R; public class WidgetConfigure extends Activity { + private static final String WIDGET_PREFERENCES_NAME = "WIDGET_PREFERENCES"; private int mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; @Override @@ -68,7 +69,7 @@ public class WidgetConfigure extends Activity { String realKeyPreference = keyPreference + "_" + mAppWidgetId; // What was saved to permanent storage (or default values if it is the first time) - final boolean isShowCountry = this.getSharedPreferences("WIDGET_PREFERENCES", Context.MODE_PRIVATE) + final boolean isShowCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getBoolean(realKeyPreference, false); // What is shown on the screen @@ -97,7 +98,7 @@ public class WidgetConfigure extends Activity { realKeyPreference = keyPreference + "_" + mAppWidgetId; // What was saved to permanent storage (or default values if it is the first time) - final int tempValue = this.getSharedPreferences("WIDGET_PREFERENCES", Context.MODE_PRIVATE).getInt(realKeyPreference, 0); + final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE).getInt(realKeyPreference, 0); // What is shown on the screen final Spinner tempUnits = (Spinner) this.findViewById(R.id.weather_appwidget_configure_temperature_units); @@ -133,7 +134,7 @@ public class WidgetConfigure extends Activity { public void onClickOk(final View view) { // Save to permanent storage final SharedPreferences.Editor prefs = this.getSharedPreferences( - "WIDGET_PREFERENCES", + WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE).edit(); /******************* Show/hide country field *******************/ @@ -167,7 +168,7 @@ public class WidgetConfigure extends Activity { public static void deletePreference(final Context context, final int appWidgetId) { final SharedPreferences.Editor prefs = context.getApplicationContext() - .getSharedPreferences("WIDGET_PREFERENCES", Context.MODE_PRIVATE).edit(); + .getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE).edit(); /******************* Show/hide country field *******************/ String keyPreference = context.getApplicationContext().getString( diff --git a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java index 95e37df..1c24dfa 100644 --- a/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java +++ b/app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java @@ -52,7 +52,7 @@ import java.util.Locale; public class WidgetIntentService extends IntentService { private static final String TAG = "WidgetIntentService"; - private static final String WIDGET_PREFERENCES = "WIDGET_PREFERENCES"; + private static final String WIDGET_PREFERENCES_NAME = "WIDGET_PREFERENCES"; public WidgetIntentService() { super("WIS-Thread"); @@ -197,7 +197,7 @@ public class WidgetIntentService extends IntentService { String keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_temperature_units_key); String realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) - final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES, Context.MODE_PRIVATE).getInt(realKeyPreference, 0); + final int tempValue = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE).getInt(realKeyPreference, 0); final String tempSymbol = this.getResources().getStringArray(R.array.weather_preferences_temperature)[tempValue]; if (tempValue == 0) { tempUnitsConversor = new UnitsConversor(){ @@ -233,7 +233,7 @@ public class WidgetIntentService extends IntentService { keyPreference = this.getApplicationContext().getString(R.string.widget_preferences_country_switch_key); realKeyPreference = keyPreference + "_" + appWidgetId; // What was saved to permanent storage (or default values if it is the first time) - final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES, Context.MODE_PRIVATE) + final boolean isCountry = this.getSharedPreferences(WIDGET_PREFERENCES_NAME, Context.MODE_PRIVATE) .getBoolean(realKeyPreference, false); diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml index 0c58da0..09a2a49 100644 --- a/app/src/main/res/values/arrays.xml +++ b/app/src/main/res/values/arrays.xml @@ -16,46 +16,46 @@ --> - 5 - 10 - 14 + @string/weather_preferences_day_forecast_five_day + @string/weather_preferences_day_forecast_ten_day + @string/weather_preferences_day_forecast_fourteen_day - 5 day forecast - 10 day forecast - 14 day forecast + @string/weather_preferences_day_forecast_human_value_five_day + @string/weather_preferences_day_forecast_human_value_ten_day + @string/weather_preferences_day_forecast_human_value_fourteen_day - 900 - 1800 - 3600 - 43200 - 86400 + @string/update_time_rate_900 + @string/update_time_rate_1800 + @string/update_time_rate_3600 + @string/update_time_rate_43200 + @string/update_time_rate_86400 - fifteen minutes - half hour - one hour - half day - one day + @string/weather_preferences_update_time_rate_human_value_fifteen_minutes + @string/weather_preferences_update_time_rate_human_value_half_hour + @string/weather_preferences_update_time_rate_human_value_one_hour + @string/weather_preferences_update_time_rate_human_value_half_day + @string/weather_preferences_update_time_rate_human_value_one_day - 300000 - 900000 - 1800000 - 3600000 - 7200000 - 43200000 - 86400000 + @string/refresh_interval_300000 + @string/refresh_interval_900000 + @string/refresh_interval_1800000 + @string/refresh_interval_3600000 + @string/refresh_interval_7200000 + @string/refresh_interval_43200000 + @string/refresh_interval_86400000 - five minutes - fifteen minutes - half hour - one hour - two hours - half day - one day + @string/weather_preferences_refresh_interval_human_value_five_minutes + @string/weather_preferences_refresh_interval_human_value_fifteen_minutes + @string/weather_preferences_refresh_interval_human_value_half_hour + @string/weather_preferences_refresh_interval_human_value_one_hour + @string/weather_preferences_refresh_interval_human_value_two_hours + @string/weather_preferences_refresh_interval_human_value_half_day + @string/weather_preferences_refresh_interval_human_value_one_day @string/weather_preferences_temperature_celsius diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 19aef7d..c1be468 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -23,6 +23,7 @@ 5 DAY FORECAST 10 DAY FORECAST 14 DAY FORECAST + CURRENTLY SUN RISE SUN SET FEELS LIKE @@ -57,10 +58,25 @@ weather_preferences_notifications_switch weather_preferences_update_time_rate Update time rate + fifteen minutes + half hour + one hour + half day + one day + five minutes + fifteen minutes + half hour + one hour + two hours + half day + one day weather_preferences_notifications_temperature Temperature weather_preferences_day_forecast Forecast days number + 5 day forecast + 10 day forecast + 14 day forecast weather_preferences_refresh_interval Refresh interval weather_preferences_wind @@ -124,5 +140,19 @@ http://gumartinm.name http://openweathermap.org/ Android WeatherInformation Agent - + 900 + 1800 + 3600 + 43200 + 86400 + 300000 + 900000 + 1800000 + 3600000 + 7200000 + 43200000 + 86400000 + 5 + 10 + 14 diff --git a/app/src/main/res/xml/weather_preferences.xml b/app/src/main/res/xml/weather_preferences.xml index b5978a2..e0244d5 100644 --- a/app/src/main/res/xml/weather_preferences.xml +++ b/app/src/main/res/xml/weather_preferences.xml @@ -72,7 +72,7 @@ android:entries="@array/weather_preferences_update_time_rate_human_value" android:entryValues="@array/weather_preferences_update_time_rate" android:title="@string/weather_preferences_update_time_rate" - android:defaultValue="900" + android:defaultValue="@string/update_time_rate_900" android:persistent="true" android:selectable="true" android:summary="fifteen minutes"