use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class NotificationBuilderService method onCreate.
@Override
public void onCreate() {
super.onCreate();
preferences = new Prefs(this);
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class LargeWidgetProvider method loadFromPreference.
private void loadFromPreference(Prefs preferences, RemoteViews remoteViews, AppWidgetManager appWidgetManager, int[] appWidgetIds, int widgetId) {
WeatherInfo json;
if (preferences.getLargeWidget() != null)
json = new Gson().fromJson(preferences.getLargeWidget(), WeatherInfo.class);
else
return;
double temp = json.getMain().getTemp();
Intent intent = new Intent(context, LargeWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widget_button_refresh, pendingIntent);
remoteViews.setTextViewText(R.id.widget_city, json.getName() + ", " + json.getSys().getCountry());
String ut = new Prefs(context).getUnits().equals("metric") ? "C" : "F";
remoteViews.setTextViewText(R.id.widget_temperature, Integer.toString((int) temp) + "°" + ut);
setWeatherIcon(json.getWeather().get(0).getId(), context, remoteViews);
String rs = json.getWeather().get(0).getDescription();
String[] strArray = rs.split(" ");
StringBuilder builder = new StringBuilder();
for (String s : strArray) {
String cap = s.substring(0, 1).toUpperCase() + s.substring(1);
builder.append(cap.concat(" "));
}
remoteViews.setTextViewText(R.id.widget_description, builder.toString());
remoteViews.setTextViewText(R.id.widget_wind, "Wind : " + json.getWind().getSpeed() + " m/" + (preferences.getUnits().equals("metric") ? "s" : "h"));
remoteViews.setTextViewText(R.id.widget_humidity, "Humidity : " + json.getMain().getHumidity() + " %");
remoteViews.setTextViewText(R.id.widget_pressure, "Pressure : " + json.getMain().getPressure() + " hPa");
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class SmallWidgetProvider method loadFromPreference.
private void loadFromPreference(Prefs preferences, RemoteViews remoteViews, AppWidgetManager appWidgetManager, int[] appWidgetIds, int widgetId) throws JSONException {
JSONObject json;
if (preferences.getSmallWidget() != null)
json = new JSONObject(preferences.getSmallWidget());
else
return;
double temp = json.getJSONObject("main").getDouble("temp");
Intent intent = new Intent(context, SmallWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widget_button_refresh, pendingIntent);
remoteViews.setTextViewText(R.id.widget_city, json.getString("name") + ", " + json.getJSONObject("sys").getString("country"));
String ut = new Prefs(context).getUnits().equals("metric") ? "C" : "F";
remoteViews.setTextViewText(R.id.widget_temperature, Integer.toString((int) temp) + "°" + ut);
setWeatherIcon(json.getJSONArray("weather").getJSONObject(0).getInt("id"), context, remoteViews);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class WidgetProviderAlarm method setAlarm.
public void setAlarm() {
long updatePeriodMills = Long.parseLong(new Prefs(mContext).getTime());
AlarmManager alarmManager = (AlarmManager) mContext.getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime() + updatePeriodMills, updatePeriodMills, getPendingIntent(mCls));
}
use of com.a5corp.weather.preferences.Prefs in project Weather by Sparker0i.
the class LargeWidgetProvider method scheduleNextUpdate.
private static void scheduleNextUpdate(Context context) {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
long now = new Date().getTime();
long nextUpdate = now + Long.parseLong(new Prefs(context).getTime());
Log.i(TAG, "Next widget update: " + android.text.format.DateFormat.getTimeFormat(context).format(new Date(nextUpdate)));
if (Build.VERSION.SDK_INT >= 19) {
alarmManager.setExact(AlarmManager.RTC, nextUpdate, getTimeIntent(context));
} else {
alarmManager.set(AlarmManager.RTC, nextUpdate, getTimeIntent(context));
}
}
Aggregations