aboutsummaryrefslogtreecommitdiffstats
path: root/src/com/cyanogenmod/lockclock/ClockWidgetService.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/cyanogenmod/lockclock/ClockWidgetService.java')
-rw-r--r--src/com/cyanogenmod/lockclock/ClockWidgetService.java81
1 files changed, 65 insertions, 16 deletions
diff --git a/src/com/cyanogenmod/lockclock/ClockWidgetService.java b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
index d5f6635..bf4be2c 100644
--- a/src/com/cyanogenmod/lockclock/ClockWidgetService.java
+++ b/src/com/cyanogenmod/lockclock/ClockWidgetService.java
@@ -27,21 +27,24 @@ import android.content.Intent;
import android.content.res.Resources;
import android.net.Uri;
import android.os.Bundle;
-import android.provider.Settings;
import android.text.TextUtils;
import android.text.format.DateFormat;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.widget.RemoteViews;
-
import com.cyanogenmod.lockclock.calendar.CalendarViewsService;
import com.cyanogenmod.lockclock.misc.Constants;
import com.cyanogenmod.lockclock.misc.IconUtils;
import com.cyanogenmod.lockclock.misc.Preferences;
import com.cyanogenmod.lockclock.misc.WidgetUtils;
-import com.cyanogenmod.lockclock.weather.WeatherInfo;
+import com.cyanogenmod.lockclock.weather.Utils;
import com.cyanogenmod.lockclock.weather.WeatherUpdateService;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.FAHRENHEIT;
+import static cyanogenmod.providers.WeatherContract.WeatherColumns.TempUnit.CELSIUS;
+import cyanogenmod.weather.CMWeatherManager;
+import cyanogenmod.weather.WeatherInfo;
+import cyanogenmod.weather.util.WeatherUtils;
import java.text.SimpleDateFormat;
import java.util.Date;
@@ -60,6 +63,7 @@ public class ClockWidgetService extends IntentService {
private int[] mWidgetIds;
private AppWidgetManager mAppWidgetManager;
+ private Context mContext;
public ClockWidgetService() {
super("ClockWidgetService");
@@ -72,6 +76,7 @@ public class ClockWidgetService extends IntentService {
ComponentName thisWidget = new ComponentName(this, ClockWidgetProvider.class);
mAppWidgetManager = AppWidgetManager.getInstance(this);
mWidgetIds = mAppWidgetManager.getAppWidgetIds(thisWidget);
+ mContext = getApplicationContext();
}
@Override
@@ -413,27 +418,48 @@ public class ClockWidgetService extends IntentService {
int color = Preferences.weatherFontColor(this);
int timestampColor = Preferences.weatherTimestampFontColor(this);
String iconsSet = Preferences.getWeatherIconSet(this);
+ final boolean useMetric = Preferences.useMetricUnits(mContext);
// Reset no weather visibility
weatherViews.setViewVisibility(R.id.weather_no_data, View.GONE);
weatherViews.setViewVisibility(R.id.weather_refresh, View.GONE);
// Weather Image
- int resId = w.getConditionResource(iconsSet);
+ int resId = IconUtils.getWeatherIconResource(mContext, iconsSet, w.getConditionCode());
weatherViews.setViewVisibility(R.id.weather_image, View.VISIBLE);
if (resId != 0) {
- weatherViews.setImageViewResource(R.id.weather_image, w.getConditionResource(iconsSet));
+ weatherViews.setImageViewResource(R.id.weather_image,
+ IconUtils.getWeatherIconResource(mContext, iconsSet, w.getConditionCode()));
} else {
- weatherViews.setImageViewBitmap(R.id.weather_image, w.getConditionBitmap(iconsSet, color));
+ weatherViews.setImageViewBitmap(R.id.weather_image,
+ IconUtils.getWeatherIconBitmap(mContext, iconsSet, color,
+ w.getConditionCode()));
}
// Weather Condition
- weatherViews.setTextViewText(R.id.weather_condition, w.getCondition());
+ weatherViews.setTextViewText(R.id.weather_condition,
+ Utils.resolveWeatherCondition(mContext, w.getConditionCode()));
weatherViews.setViewVisibility(R.id.weather_condition, View.VISIBLE);
weatherViews.setTextColor(R.id.weather_condition, color);
// Weather Temps Panel
- weatherViews.setTextViewText(R.id.weather_temp, w.getFormattedTemperature());
+ double temp = w.getTemperature();
+ double todaysLow = w.getTodaysLow();
+ double todaysHigh = w.getTodaysHigh();
+ int tempUnit = w.getTemperatureUnit();
+ if (tempUnit == FAHRENHEIT && useMetric) {
+ temp = WeatherUtils.fahrenheitToCelsius(temp);
+ todaysLow = WeatherUtils.fahrenheitToCelsius(todaysLow);
+ todaysHigh = WeatherUtils.fahrenheitToCelsius(todaysHigh);
+ tempUnit = CELSIUS;
+ } else if (tempUnit == CELSIUS && !useMetric) {
+ temp = WeatherUtils.celsiusToFahrenheit(temp);
+ todaysLow = WeatherUtils.celsiusToFahrenheit(todaysLow);
+ todaysHigh = WeatherUtils.celsiusToFahrenheit(todaysHigh);
+ tempUnit = FAHRENHEIT;
+ }
+ weatherViews.setTextViewText(R.id.weather_temp,
+ WeatherUtils.formatTemperature(temp, tempUnit));
weatherViews.setViewVisibility(R.id.weather_temps_panel, View.VISIBLE);
weatherViews.setTextColor(R.id.weather_temp, color);
@@ -450,7 +476,7 @@ public class ClockWidgetService extends IntentService {
// Weather Update Time
if (showTimestamp) {
- Date updateTime = w.getTimestamp();
+ Date updateTime = new Date(w.getTimestamp());
StringBuilder sb = new StringBuilder();
sb.append(DateFormat.format("E", updateTime));
sb.append(" ");
@@ -464,8 +490,8 @@ public class ClockWidgetService extends IntentService {
// Weather Temps Panel additional items
boolean invertLowhigh = Preferences.invertLowHighTemperature(this);
- final String low = w.getFormattedLow();
- final String high = w.getFormattedHigh();
+ final String low = WeatherUtils.formatTemperature(todaysLow, tempUnit);
+ final String high = WeatherUtils.formatTemperature(todaysHigh, tempUnit);
weatherViews.setTextViewText(R.id.weather_low_high, invertLowhigh ? high + " | " + low : low + " | " + high);
weatherViews.setTextColor(R.id.weather_low_high, color);
}
@@ -482,8 +508,15 @@ public class ClockWidgetService extends IntentService {
boolean firstRun = Preferences.isFirstWeatherUpdate(this);
// Hide the normal weather stuff
- int providerNameResource = Preferences.weatherProvider(this).getNameResourceId();
- String noData = getString(R.string.weather_cannot_reach_provider, getString(providerNameResource));
+ final CMWeatherManager weatherManager = CMWeatherManager.getInstance(mContext);
+ final String activeProviderLabel = weatherManager.getActiveWeatherServiceProviderLabel();
+ String noData;
+ if (activeProviderLabel != null) {
+ noData = getString(R.string.weather_cannot_reach_provider, activeProviderLabel);
+ } else {
+ noData = getString(R.string.weather_source_title) + " "
+ + getString(R.string.weather_source_not_selected);
+ }
weatherViews.setViewVisibility(R.id.weather_image, View.INVISIBLE);
if (!smallWidget) {
weatherViews.setViewVisibility(R.id.weather_city, View.GONE);
@@ -493,7 +526,13 @@ public class ClockWidgetService extends IntentService {
// Set up the no data and refresh indicators
weatherViews.setTextViewText(R.id.weather_no_data, noData);
- weatherViews.setTextViewText(R.id.weather_refresh, getString(R.string.weather_tap_to_refresh));
+ if (activeProviderLabel != null) {
+ weatherViews.setTextViewText(R.id.weather_refresh,
+ getString(R.string.weather_tap_to_refresh));
+ } else {
+ weatherViews.setTextViewText(R.id.weather_refresh,
+ getString(R.string.weather_tap_to_select_source));
+ }
weatherViews.setTextColor(R.id.weather_no_data, color);
weatherViews.setTextColor(R.id.weather_refresh, color);
@@ -509,7 +548,11 @@ public class ClockWidgetService extends IntentService {
// Register an onClickListener on Weather with the default (Refresh) action
if (!firstRun) {
- setWeatherClickListener(weatherViews, true);
+ if (activeProviderLabel != null) {
+ setWeatherClickListener(weatherViews, true);
+ } else {
+ setWeatherClickListener(weatherViews);
+ }
}
}
@@ -528,7 +571,13 @@ public class ClockWidgetService extends IntentService {
weatherViews.setOnClickPendingIntent(R.id.weather_panel, pi);
}
-
+ private void setWeatherClickListener(RemoteViews weatherViews) {
+ PendingIntent pi = PendingIntent.getActivity(mContext, 0,
+ new Intent("cyanogenmod.intent.action.MANAGE_WEATHER_PROVIDER_SERVICES"),
+ PendingIntent.FLAG_UPDATE_CURRENT);
+ weatherViews.setOnClickPendingIntent(R.id.weather_panel, pi);
+ }
+
//===============================================================================================
// Calendar related functionality
//===============================================================================================