Trying to use only strings from static resources
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 20 Nov 2014 04:10:26 +0000 (05:10 +0100)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Thu, 20 Nov 2014 04:10:26 +0000 (05:10 +0100)
app/src/main/java/name/gumartinm/weather/information/activity/MainTabsActivity.java
app/src/main/java/name/gumartinm/weather/information/boot/BootReceiver.java
app/src/main/java/name/gumartinm/weather/information/fragment/current/CurrentFragment.java
app/src/main/java/name/gumartinm/weather/information/fragment/overview/OverviewFragment.java
app/src/main/java/name/gumartinm/weather/information/notification/NotificationIntentService.java
app/src/main/java/name/gumartinm/weather/information/service/IconsList.java
app/src/main/java/name/gumartinm/weather/information/widget/WidgetConfigure.java
app/src/main/java/name/gumartinm/weather/information/widget/WidgetIntentService.java
app/src/main/res/values/arrays.xml
app/src/main/res/values/strings.xml
app/src/main/res/xml/weather_preferences.xml

index 3e9956f..7fd351c 100644 (file)
@@ -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);
index f8a356f..faa78ae 100644 (file)
@@ -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;
             }
 
index eccfddc..a356579 100644 (file)
@@ -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);
index 06ac0f0..30f4acb 100644 (file)
@@ -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));
 
index 59d6637..4ec44f9 100644 (file)
@@ -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;
index 5528fc5..ee9d9e6 100644 (file)
@@ -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() {
index cf25bd6..58999e8 100644 (file)
@@ -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(
index 95e37df..1c24dfa 100644 (file)
@@ -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);
 
 
index 0c58da0..09a2a49 100644 (file)
 -->
 <resources>
     <string-array name="weather_preferences_day_forecast">
-        <item>5</item>
-        <item>10</item>
-        <item>14</item>
+        <item>@string/weather_preferences_day_forecast_five_day</item>
+        <item>@string/weather_preferences_day_forecast_ten_day</item>
+        <item>@string/weather_preferences_day_forecast_fourteen_day</item>
     </string-array>
     <string-array name="weather_preferences_day_forecast_human_value">
-        <item>5 day forecast</item>
-        <item>10 day forecast</item>
-        <item>14 day forecast</item>
+        <item>@string/weather_preferences_day_forecast_human_value_five_day</item>
+        <item>@string/weather_preferences_day_forecast_human_value_ten_day</item>
+        <item>@string/weather_preferences_day_forecast_human_value_fourteen_day</item>
     </string-array>
     <string-array name="weather_preferences_update_time_rate">
-        <item>900</item>
-        <item>1800</item>
-        <item>3600</item>       
-        <item>43200</item>
-        <item>86400</item>    
+        <item>@string/update_time_rate_900</item>
+        <item>@string/update_time_rate_1800</item>
+        <item>@string/update_time_rate_3600</item>
+        <item>@string/update_time_rate_43200</item>
+        <item>@string/update_time_rate_86400</item>
     </string-array>
     <string-array name="weather_preferences_update_time_rate_human_value">
-        <item>fifteen minutes</item>
-        <item>half hour</item>
-        <item>one hour</item>   
-        <item>half day</item>
-        <item>one day</item>     
+        <item>@string/weather_preferences_update_time_rate_human_value_fifteen_minutes</item>
+        <item>@string/weather_preferences_update_time_rate_human_value_half_hour</item>
+        <item>@string/weather_preferences_update_time_rate_human_value_one_hour</item>
+        <item>@string/weather_preferences_update_time_rate_human_value_half_day</item>
+        <item>@string/weather_preferences_update_time_rate_human_value_one_day</item>
     </string-array>
     <string-array name="weather_preferences_refresh_interval">
-        <item>300000</item>
-        <item>900000</item>
-        <item>1800000</item>
-        <item>3600000</item>
-        <item>7200000</item>
-        <item>43200000</item>
-        <item>86400000</item>
+        <item>@string/refresh_interval_300000</item>
+        <item>@string/refresh_interval_900000</item>
+        <item>@string/refresh_interval_1800000</item>
+        <item>@string/refresh_interval_3600000</item>
+        <item>@string/refresh_interval_7200000</item>
+        <item>@string/refresh_interval_43200000</item>
+        <item>@string/refresh_interval_86400000</item>
     </string-array>
     <string-array name="weather_preferences_refresh_interval_human_value">
-        <item>five minutes</item>
-        <item>fifteen minutes</item>
-        <item>half hour</item>
-        <item>one hour</item>
-        <item>two hours</item>
-        <item>half day</item>
-        <item>one day</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_five_minutes</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_fifteen_minutes</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_half_hour</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_one_hour</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_two_hours</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_half_day</item>
+        <item>@string/weather_preferences_refresh_interval_human_value_one_day</item>
     </string-array>
     <string-array name="weather_preferences_temperature">
         <item>@string/weather_preferences_temperature_celsius</item>
index 19aef7d..c1be468 100644 (file)
@@ -23,6 +23,7 @@
     <string name="text_tab_five_days_forecast">5 DAY FORECAST</string>
     <string name="text_tab_ten_days_forecast">10 DAY FORECAST</string>
     <string name="text_tab_fourteen_days_forecast">14 DAY FORECAST</string>
+    <string name="text_tab_currently">CURRENTLY</string>
     <string name="text_field_sun_rise">SUN RISE</string>
     <string name="text_field_sun_set">SUN SET</string>
     <string name="text_field_feels_like">FEELS LIKE</string>
     <string name="weather_preferences_notifications_switch_key">weather_preferences_notifications_switch</string>
     <string name="weather_preferences_update_time_rate_key">weather_preferences_update_time_rate</string>
     <string name="weather_preferences_update_time_rate">Update time rate</string>
+    <string name="weather_preferences_update_time_rate_human_value_fifteen_minutes">fifteen minutes</string>
+    <string name="weather_preferences_update_time_rate_human_value_half_hour">half hour</string>
+    <string name="weather_preferences_update_time_rate_human_value_one_hour">one hour</string>
+    <string name="weather_preferences_update_time_rate_human_value_half_day">half day</string>
+    <string name="weather_preferences_update_time_rate_human_value_one_day">one day</string>
+    <string name="weather_preferences_refresh_interval_human_value_five_minutes">five minutes</string>
+    <string name="weather_preferences_refresh_interval_human_value_fifteen_minutes">fifteen minutes</string>
+    <string name="weather_preferences_refresh_interval_human_value_half_hour">half hour</string>
+    <string name="weather_preferences_refresh_interval_human_value_one_hour">one hour</string>
+    <string name="weather_preferences_refresh_interval_human_value_two_hours">two hours</string>
+    <string name="weather_preferences_refresh_interval_human_value_half_day">half day</string>
+    <string name="weather_preferences_refresh_interval_human_value_one_day">one day</string>
     <string name="weather_preferences_notifications_temperature_key">weather_preferences_notifications_temperature</string>
     <string name="weather_preferences_notifications_temperature">Temperature</string>
     <string name="weather_preferences_day_forecast_key">weather_preferences_day_forecast</string>
     <string name="weather_preferences_day_forecast">Forecast days number</string>
+    <string name="weather_preferences_day_forecast_human_value_five_day">5 day forecast</string>
+    <string name="weather_preferences_day_forecast_human_value_ten_day">10 day forecast</string>
+    <string name="weather_preferences_day_forecast_human_value_fourteen_day">14 day forecast</string>
     <string name="weather_preferences_refresh_interval_key">weather_preferences_refresh_interval</string>
     <string name="weather_preferences_refresh_interval">Refresh interval</string>
     <string name="weather_preferences_wind_key">weather_preferences_wind</string>
     <string name="my_url">http://gumartinm.name</string>
     <string name="openweathermap_url">http://openweathermap.org/</string>
     <string name="http_client_agent">Android WeatherInformation Agent</string>
-
+    <string name="update_time_rate_900">900</string>
+    <string name="update_time_rate_1800">1800</string>
+    <string name="update_time_rate_3600">3600</string>
+    <string name="update_time_rate_43200">43200</string>
+    <string name="update_time_rate_86400">86400</string>
+    <string name="refresh_interval_300000">300000</string>
+    <string name="refresh_interval_900000">900000</string>
+    <string name="refresh_interval_1800000">1800000</string>
+    <string name="refresh_interval_3600000">3600000</string>
+    <string name="refresh_interval_7200000">7200000</string>
+    <string name="refresh_interval_43200000">43200000</string>
+    <string name="refresh_interval_86400000">86400000</string>
+    <string name="weather_preferences_day_forecast_five_day">5</string>
+    <string name="weather_preferences_day_forecast_ten_day">10</string>
+    <string name="weather_preferences_day_forecast_fourteen_day">14</string>
 </resources>
index b5978a2..e0244d5 100644 (file)
@@ -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"