Search in sources :

Example 1 with Prefs

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);
}
Also used : Prefs(com.a5corp.weather.preferences.Prefs)

Example 2 with Prefs

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);
}
Also used : WeatherInfo(com.a5corp.weather.model.WeatherInfo) Gson(com.google.gson.Gson) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Prefs(com.a5corp.weather.preferences.Prefs)

Example 3 with Prefs

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);
}
Also used : JSONObject(org.json.JSONObject) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent) Prefs(com.a5corp.weather.preferences.Prefs)

Example 4 with Prefs

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));
}
Also used : AlarmManager(android.app.AlarmManager) Prefs(com.a5corp.weather.preferences.Prefs)

Example 5 with Prefs

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));
    }
}
Also used : AlarmManager(android.app.AlarmManager) Prefs(com.a5corp.weather.preferences.Prefs) Date(java.util.Date)

Aggregations

Prefs (com.a5corp.weather.preferences.Prefs)25 AlarmManager (android.app.AlarmManager)6 Intent (android.content.Intent)6 PendingIntent (android.app.PendingIntent)5 Context (android.content.Context)5 WeatherInfo (com.a5corp.weather.model.WeatherInfo)3 Date (java.util.Date)3 Bundle (android.os.Bundle)2 View (android.view.View)2 WeatherActivity (com.a5corp.weather.activity.WeatherActivity)2 WeatherFragment (com.a5corp.weather.fragment.WeatherFragment)2 CheckConnection (com.a5corp.weather.internet.CheckConnection)2 Gson (com.google.gson.Gson)2 IOException (java.io.IOException)2 Locale (java.util.Locale)2 SharedPreferences (android.content.SharedPreferences)1 Configuration (android.content.res.Configuration)1 Handler (android.os.Handler)1 KeyEvent (android.view.KeyEvent)1 Button (android.widget.Button)1