Skip to content

Commit

Permalink
added regular network location check into visuals
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomas Huryn committed Apr 12, 2017
1 parent bf637dc commit dbcda92
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 29 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ out/
*.apk
release.properties
gradle.properties
local.properties
local.properties
/.nb-gradle/
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ public void run() {
String requestResult = "";
HttpURLConnection connection = null;
try {
URL url = getWeatherForecastUrl(latitude, longitude, units, locale);
URL url = getWeatherForecastUrl(Constants.WEATHER_FORECAST_ENDPOINT, latitude, longitude, units, locale);
connection = (HttpURLConnection) url.openConnection();

if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void run() {
String requestResult = "";
HttpURLConnection connection = null;
try {
URL url = getWeatherForecastUrl(latitude, longitude, units, locale);
URL url = getWeatherForecastUrl(Constants.WEATHER_FORECAST_ENDPOINT, latitude, longitude, units, locale);
connection = (HttpURLConnection) url.openConnection();

if (connection.getResponseCode() == HttpURLConnection.HTTP_OK) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.asdtm.goodweather.utils.Utils;

import java.util.Locale;
import org.asdtm.goodweather.service.LocationUpdateService;

public class MoreWidgetProvider extends AppWidgetProvider {

Expand All @@ -29,13 +30,14 @@ public void onEnabled(Context context) {
AppWidgetProviderAlarm appWidgetProviderAlarm =
new AppWidgetProviderAlarm(context, MoreWidgetProvider.class);
appWidgetProviderAlarm.setAlarm();
AppPreference.setLocale(context, Constants.APP_SETTINGS_NAME);
}

@Override
public void onReceive(Context context, Intent intent) {
switch (intent.getAction()) {
case Constants.ACTION_FORCED_APPWIDGET_UPDATE:
context.startService(new Intent(context, MoreWidgetService.class));
context.startService(new Intent(context, LocationUpdateService.class));
break;
case Intent.ACTION_LOCALE_CHANGED:
AppPreference.setLocale(context, Constants.APP_SETTINGS_NAME);
Expand Down Expand Up @@ -100,8 +102,6 @@ public void onDisabled(Context context) {
private void preLoadWeather(Context context, RemoteViews remoteViews) {
SharedPreferences weatherPref = context.getSharedPreferences(Constants.PREF_WEATHER_NAME,
Context.MODE_PRIVATE);
String[] cityAndCountryArray = AppPreference.getCityAndCode(context);
String cityAndCountry = cityAndCountryArray[0] + ", " + cityAndCountryArray[1];
String temperatureScale = Utils.getTemperatureScale(context);
String speedScale = Utils.getSpeedScale(context);
String percentSign = context.getString(R.string.percent_sign);
Expand Down Expand Up @@ -137,7 +137,7 @@ private void preLoadWeather(Context context, RemoteViews remoteViews) {
String lastUpdate = Utils.setLastUpdateTime(context,
AppPreference.getLastUpdateTimeMillis(context));

remoteViews.setTextViewText(R.id.widget_city, cityAndCountry);
remoteViews.setTextViewText(R.id.widget_city, Utils.getCityAndCountry(context));
remoteViews.setTextViewText(R.id.widget_temperature, temperature + temperatureScale);
if(!AppPreference.hideDescription(context))
remoteViews.setTextViewText(R.id.widget_description, description);
Expand All @@ -152,20 +152,9 @@ private void preLoadWeather(Context context, RemoteViews remoteViews) {
}

private void setWidgetTheme(Context context, RemoteViews remoteViews) {
int textColorId;
int backgroundColorId;

if (!AppPreference.isLightThemeEnabled(context)) {
backgroundColorId = ContextCompat.getColor(context,
R.color.widget_darkTheme_colorBackground);
textColorId = ContextCompat.getColor(context,
R.color.widget_darkTheme_textColorPrimary);
} else {
backgroundColorId = ContextCompat.getColor(context,
R.color.widget_lightTheme_colorBackground);
textColorId = ContextCompat.getColor(context,
R.color.widget_lightTheme_textColorPrimary);
}
int textColorId = AppPreference.getTextColor(context);
int backgroundColorId = AppPreference.getBackgroundColor(context);
int windowHeaderBackgroundColorId = AppPreference.getWindowHeaderBackgroundColorId(context);

remoteViews.setInt(R.id.widget_root, "setBackgroundColor", backgroundColorId);
remoteViews.setTextColor(R.id.widget_temperature, textColorId);
Expand All @@ -175,5 +164,6 @@ private void setWidgetTheme(Context context, RemoteViews remoteViews) {
remoteViews.setTextColor(R.id.widget_humidity, textColorId);
remoteViews.setTextColor(R.id.widget_pressure, textColorId);
remoteViews.setTextColor(R.id.widget_clouds, textColorId);
remoteViews.setInt(R.id.header_layout, "setBackgroundColor", windowHeaderBackgroundColorId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
import android.content.SharedPreferences;
import android.util.Log;
import android.widget.RemoteViews;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;

import org.asdtm.goodweather.ConnectionDetector;
import org.asdtm.goodweather.R;
Expand Down Expand Up @@ -54,15 +57,13 @@ protected void onHandleIntent(Intent intent) {
stopSelf();
}
}

private void updateWidget(Weather weather) {
AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
ComponentName widgetComponent = new ComponentName(this, MoreWidgetProvider.class);

int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
for (int appWidgetId : widgetIds) {
String[] cityAndCountryArray = AppPreference.getCityAndCode(this);
String cityAndCountry = cityAndCountryArray[0] + ", " + cityAndCountryArray[1];
String temperatureScale = Utils.getTemperatureScale(this);
String speedScale = Utils.getSpeedScale(this);
String percentSign = getString(R.string.percent_sign);
Expand Down Expand Up @@ -91,7 +92,7 @@ private void updateWidget(Weather weather) {

RemoteViews remoteViews = new RemoteViews(this.getPackageName(),
R.layout.widget_more_3x3);
remoteViews.setTextViewText(R.id.widget_city, cityAndCountry);
remoteViews.setTextViewText(R.id.widget_city, Utils.getCityAndCountry(this));
remoteViews.setTextViewText(R.id.widget_temperature, temperature + temperatureScale);
if(!AppPreference.hideDescription(this))
remoteViews.setTextViewText(R.id.widget_description,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/widget_less_3x1.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:background="@color/widget_darkTheme_window_colorBackground"
android:orientation="horizontal">

<TextView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/widget_more_3x3.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
android:id="@+id/header_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:background="@color/widget_darkTheme_window_colorBackground"
android:orientation="horizontal">

<TextView
Expand Down
15 changes: 15 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
</string-array>

<string-array name="widget_update_period_entries">
<item>@string/update_period_15min</item>
<item>@string/update_period_30min</item>
<item>@string/update_period_1hour</item>
<item>@string/update_period_3hours</item>
Expand All @@ -37,13 +38,25 @@
<item>@string/update_period_24hours</item>
</string-array>
<string-array name="widget_update_period_values" translatable="false">
<item>15</item>
<item>30</item>
<item>60</item>
<item>180</item>
<item>360</item>
<item>720</item>
<item>1440</item>
</string-array>

<string-array name="widget_theme_entries">
<item>@string/theme_dark</item>
<item>@string/theme_light</item>
<item>@string/theme_transparent</item>
</string-array>
<string-array name="widget_theme_values" translatable="false">
<item>dark</item>
<item>light</item>
<item>transparent</item>
</string-array>

<!-- Wind directions array -->
<string-array name="wind_directions">
Expand Down Expand Up @@ -78,6 +91,7 @@
<item name="japanese">日本語</item>
<item name="polish">Polski</item>
<item name="russian">Русский</item>
<item name="czech">Čeština</item>
</string-array>
<string-array name="language_values">
<item name="default"></item>
Expand All @@ -89,5 +103,6 @@
<item name="japanese">ja_JP</item>
<item name="polish">pl_PL</item>
<item name="russian">ru_RU</item>
<item name="czech">cs</item>
</string-array>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@

<color name="widget_darkTheme_colorBackground">#fa202020</color>
<color name="widget_darkTheme_textColorPrimary">#FFFFFF</color>
<color name="widget_darkTheme_window_colorBackground">#009688</color>

<color name="widget_lightTheme_colorBackground">#f5e7e7e7</color>
<color name="widget_lightTheme_textColorPrimary">#000000</color>
<color name="widget_lightTheme_window_colorBackground">#009688</color>

<color name="widget_transparentTheme_colorBackground">#00e7e7e7</color>
<color name="widget_transparentTheme_textColorPrimary">#FFFFFF</color>
<color name="widget_transparentTheme_window_colorBackground">#00e7e7e7</color>
</resources>
9 changes: 7 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,14 +86,19 @@
<string name="update_period_12hours">12 hours</string>
<string name="update_period_24hours">24 hours</string>
<string name="pref_title_vibrate">Vibrate</string>
<string name="preference_widget_light_theme">Light theme</string>
<string name="preference_widget_title_update_period">Update Period</string>
<string name="preference_title_activity_general">General settings</string>
<string name="preference_title_activity_widget">Widget settings</string>
<string name="preference_widget_update_location">Update location</string>
<string name="preference_widget_use_geocoder">Use geolocation for displaying</string>
<string name="preference_widget_theme_title">Widget theme</string>
<string name="theme_dark">Dark</string>
<string name="theme_light">Light</string>
<string name="theme_transparent">Transparent</string>
<string name="preference_title_category_display">Display</string>
<string name="pref_title_language">Language</string>
<string name="pref_language_default">Default Language</string>

<!-- Preference Screen About -->
<string name="preference_title_activity_about">About</string>
<string name="about_version_pref_title">Version</string>
Expand Down

0 comments on commit dbcda92

Please sign in to comment.