widget: add option for dark background, configurable update interval
This commit is contained in:
parent
ab36647865
commit
b185300695
@ -12,6 +12,7 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
|
||||
|
||||
<application
|
||||
android:name=".Application"
|
||||
@ -205,12 +206,19 @@
|
||||
android:name="com.google.android.backup.api_key"
|
||||
android:value="AEdPqrEAAAAIwG6zsGB4qo6ZhjfwIJpm9WI7AqmWaoRXm6ZJnA" />
|
||||
|
||||
<receiver android:name=".util.DeviceBootReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".tasker.TaskerReceiver" >
|
||||
<intent-filter>
|
||||
<action android:name="com.twofortyfouram.locale.intent.action.QUERY_CONDITION" />
|
||||
<action android:name="com.twofortyfouram.locale.intent.action.FIRE_SETTING" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
<receiver android:name=".widget.SmallWidgetProvider" >
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
|
@ -2,6 +2,8 @@ package org.fox.ttrss;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.app.AlarmManager;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.app.PendingIntent;
|
||||
@ -37,6 +39,7 @@ import com.nostra13.universalimageloader.core.ImageLoader;
|
||||
import com.nostra13.universalimageloader.core.ImageLoaderConfiguration;
|
||||
|
||||
import org.fox.ttrss.util.DatabaseHelper;
|
||||
import org.fox.ttrss.widget.SmallWidgetProvider;
|
||||
import org.jsoup.Jsoup;
|
||||
import org.jsoup.nodes.Document;
|
||||
import org.jsoup.select.Elements;
|
||||
@ -159,6 +162,8 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
|
||||
|
||||
m_prefs.registerOnSharedPreferenceChangeListener(this);
|
||||
|
||||
setupWidgetUpdates(this);
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
m_theme = savedInstanceState.getString("theme");
|
||||
} else {
|
||||
@ -237,7 +242,7 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||
Log.d(TAG, "onSharedPreferenceChanged:" + key);
|
||||
|
||||
String[] filter = new String[] { "theme", "enable_cats", "headline_mode" };
|
||||
String[] filter = new String[] { "theme", "enable_cats", "headline_mode", "widget_update_interval" };
|
||||
|
||||
m_needRestart = Arrays.asList(filter).indexOf(key) != -1;
|
||||
}
|
||||
@ -414,6 +419,29 @@ public class CommonActivity extends ActionBarActivity implements SharedPreferenc
|
||||
}
|
||||
}
|
||||
|
||||
public static void setupWidgetUpdates(Context context) {
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
|
||||
int updateInterval = Integer.parseInt(prefs.getString("widget_update_interval", "15")) * 60 * 1000;
|
||||
|
||||
Log.d("setupWidgetUpdates", "setupWidgetUpdate: interval= " + updateInterval);
|
||||
|
||||
AlarmManager alarmManager = (AlarmManager)context.getSystemService(ALARM_SERVICE);
|
||||
|
||||
Intent intentUpdate = new Intent(SmallWidgetProvider.ACTION_REQUEST_UPDATE);
|
||||
|
||||
PendingIntent pendingIntentAlarm = PendingIntent.getBroadcast(context,
|
||||
0, intentUpdate, PendingIntent.FLAG_UPDATE_CURRENT);
|
||||
|
||||
alarmManager.cancel(pendingIntentAlarm);
|
||||
|
||||
alarmManager.setRepeating(AlarmManager.RTC,
|
||||
System.currentTimeMillis() + updateInterval,
|
||||
updateInterval,
|
||||
pendingIntentAlarm);
|
||||
|
||||
}
|
||||
|
||||
public void displayImageCaption(String url, String htmlContent) {
|
||||
// Android doesn't give us an easy way to access title tags;
|
||||
// we'll use Jsoup on the body text to grab the title text
|
||||
|
@ -0,0 +1,16 @@
|
||||
package org.fox.ttrss.util;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import org.fox.ttrss.CommonActivity;
|
||||
|
||||
public class DeviceBootReceiver extends BroadcastReceiver {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (intent.getAction().equals("android.intent.action.BOOT_COMPLETED")) {
|
||||
CommonActivity.setupWidgetUpdates(context);
|
||||
}
|
||||
}
|
||||
}
|
@ -6,7 +6,11 @@ import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
import org.fox.ttrss.OnlineActivity;
|
||||
@ -17,6 +21,7 @@ public class SmallWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
public static final String ACTION_REQUEST_UPDATE = "org.fox.ttrss.WIDGET_FORCE_UPDATE";
|
||||
public static final String ACTION_UPDATE_RESULT = "org.fox.ttrss.WIDGET_UPDATE_RESULT";
|
||||
public static final String ACTION_SETTINGS_CHANGED = "org.fox.ttrss.WIDGET_SETTINGS_CHANGED";
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
@ -28,11 +33,20 @@ public class SmallWidgetProvider extends AppWidgetProvider {
|
||||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_small);
|
||||
views.setOnClickPendingIntent(R.id.widget_main, pendingIntent);
|
||||
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean darkMode = prefs.getBoolean("widget_dark_mode", false);
|
||||
|
||||
if (darkMode) {
|
||||
views.setViewVisibility(R.id.widget_dark, View.VISIBLE);
|
||||
} else {
|
||||
views.setViewVisibility(R.id.widget_dark, View.INVISIBLE);
|
||||
}
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetIds, views);
|
||||
|
||||
Intent serviceIntent = new Intent(context.getApplicationContext(), WidgetUpdateService.class);
|
||||
context.startService(serviceIntent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@ -55,6 +69,11 @@ public class SmallWidgetProvider extends AppWidgetProvider {
|
||||
Log.d(TAG, "onReceive: got update result from service: " + unread + " " + resultCode);
|
||||
|
||||
updateWidgetsText(context, appWidgetManager, appWidgetIds, unread, resultCode);
|
||||
} else if (ACTION_SETTINGS_CHANGED.equals(intent.getAction())) {
|
||||
Log.d(TAG, "onReceive: got settings changed");
|
||||
|
||||
// TODO
|
||||
|
||||
} else {
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
|
@ -4,8 +4,20 @@
|
||||
android:layout_height="fill_parent"
|
||||
android:padding="@dimen/widget_margin" >
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_light"
|
||||
android:background="@color/cardview_light_background"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/widget_dark"
|
||||
android:visibility="invisible"
|
||||
android:background="@color/cardview_dark_background"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent" />
|
||||
|
||||
<LinearLayout
|
||||
android:background="@android:color/white"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
android:orientation="vertical" >
|
||||
|
@ -30,5 +30,11 @@
|
||||
<item>1000</item>
|
||||
<item>1500</item>
|
||||
<item>2000</item>
|
||||
</string-array>
|
||||
</string-array>
|
||||
<string-array name="pref_widget_update_intervals" translatable="false">
|
||||
<item>15</item>
|
||||
<item>30</item>
|
||||
<item>45</item>
|
||||
<item>60</item>
|
||||
</string-array>
|
||||
</resources>
|
@ -247,4 +247,6 @@
|
||||
<string name="headline_undo_row_prompt">Marked as read</string>
|
||||
<string name="pref_headlines_swipe_to_dismiss">Swipe to dismiss</string>
|
||||
<string name="pref_headlines_swipe_to_dismiss_long">Disables headlines context menu</string>
|
||||
<string name="pref_widget_update_interval">Update interval (in minutes)</string>
|
||||
<string name="pref_widget_dark_background">Use dark background</string>
|
||||
</resources>
|
||||
|
@ -189,6 +189,18 @@
|
||||
android:title="@string/offline_image_cache_enabled" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/prefs_widget" >
|
||||
<ListPreference
|
||||
android:defaultValue="15"
|
||||
android:entries="@array/pref_widget_update_intervals"
|
||||
android:entryValues="@array/pref_widget_update_intervals"
|
||||
android:key="widget_update_interval"
|
||||
android:title="@string/pref_widget_update_interval" />
|
||||
|
||||
<org.fox.ttrss.util.LessBrokenSwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="widget_dark_mode"
|
||||
android:title="@string/pref_widget_dark_background" />
|
||||
|
||||
<org.fox.ttrss.util.LessBrokenSwitchPreference
|
||||
android:defaultValue="true"
|
||||
android:key="widget_show_fresh"
|
||||
|
@ -1,7 +1,6 @@
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:minWidth="40dp"
|
||||
android:minHeight="40dp"
|
||||
android:updatePeriodMillis="86400000"
|
||||
android:initialLayout="@layout/widget_small"
|
||||
android:resizeMode="none"
|
||||
android:widgetCategory="home_screen">
|
||||
|
Loading…
Reference in New Issue
Block a user