All Projects → HeyAlex → WidgetUpdateHelper

HeyAlex / WidgetUpdateHelper

Licence: other
No description or website provided.

Programming Languages

java
68154 projects - #9 most used programming language
kotlin
9241 projects

Projects that are alternatives of or similar to WidgetUpdateHelper

stomt-unreal-plugin
Collect feedback in-game/in-app with STOMT for Unreal Engine.
Stars: ✭ 23 (-46.51%)
Mutual labels:  widget
ws-repl
MIGRATED TO https://vcs.rowanthorpe.com/rowan/ws-repl - THIS IS AN ARCHIVED VERSION... Arbitrary REPL in a web-page using websocketd
Stars: ✭ 38 (-11.63%)
Mutual labels:  widget
cumulocity-app-builder
The Application Builder for Cumulocity provides a simple, coding-free way to create new applications inside Cumulocity. Application Builder is an open-source tool for you to create web applications in a no-code environment. Created by Global Presales.
Stars: ✭ 18 (-58.14%)
Mutual labels:  widget
shinyTime
A timeInput widget for Shiny
Stars: ✭ 23 (-46.51%)
Mutual labels:  widget
GridFragment
Android parent Fragment for working with GridViews.
Stars: ✭ 17 (-60.47%)
Mutual labels:  widget
sqlops-widgets
SQL Operations Studio Dashboard Widgets - including Always ON
Stars: ✭ 22 (-48.84%)
Mutual labels:  widget
FlutterNote
Easy to learn Flutter(Flutter 即学即用,Flutter 速成必备)
Stars: ✭ 22 (-48.84%)
Mutual labels:  widget
ZVRefreshing
A pure-swift and wieldy refresh component.
Stars: ✭ 29 (-32.56%)
Mutual labels:  widget
VBBNow
A VBB NotificationCenter Widget. It shows the nearby transit information
Stars: ✭ 23 (-46.51%)
Mutual labels:  widget
DailyImageWidget
Android 桌面小部件(widget)日签 Or 日历,可作为桌面日历。Just For Fun! 🎮
Stars: ✭ 30 (-30.23%)
Mutual labels:  widget
covid-19-status
Menu bar widget for MacOS with COVID-19 statistics
Stars: ✭ 50 (+16.28%)
Mutual labels:  widget
posts-in-sidebar
Publish a list of posts in your sidebar
Stars: ✭ 19 (-55.81%)
Mutual labels:  widget
CatLearnQt
CatLearnQt,提供QWidget,Quick,网络,串口,基础库和示例。案例软件支持样式切换,与国际化。
Stars: ✭ 63 (+46.51%)
Mutual labels:  widget
CheckableTextView
A simple and flexible Checked TextView or Checkable TextView
Stars: ✭ 108 (+151.16%)
Mutual labels:  widget
simple-analog-clock
Simple clock view for displaying uh...time?
Stars: ✭ 24 (-44.19%)
Mutual labels:  widget
DiscoverRandomQuotes
Spontaneous - Random quotes is a free iOS app that generates random quotes. It values ease-of-use just as much as the users' privacy, so there are no ads or trackers to disrupt their experience. The app currently includes more than 75000 quotes, which you can only discover randomly.
Stars: ✭ 34 (-20.93%)
Mutual labels:  widget
iOS-Today-Extension-Simple-Tutorial
iOS Today Extension Simple Tutorial
Stars: ✭ 24 (-44.19%)
Mutual labels:  widget
Android-Model-View-Presenter
No description or website provided.
Stars: ✭ 26 (-39.53%)
Mutual labels:  widget
nl.fokkezb.button
Bootstrap Button widget for Appcelerator (Titanium)
Stars: ✭ 72 (+67.44%)
Mutual labels:  widget
wp-team-list
👨‍👩‍👧‍👧 A WordPress plugin to display your teammates (users) anywhere on your WordPress site.
Stars: ✭ 15 (-65.12%)
Mutual labels:  widget

WidgetUpdateHelper

This library helps managing the updates of widgets. Just update all your widgets on background thread with android.app.IntentService, that provides that library. It's provide an easy and simple way to update app widgets.

API CircleCI

How to use WidgetUpdateHelper

WidgetBuilder

There is an abstract class WidgetUpdater, which has only two methods: abstract update(Context context, Bundle dataBundle, int... ids) and makeNotification(Context context) with default implementation.

public class SingleUpdater extends WidgetUpdater {
    @Override
    public void update(Context context, Bundle dataBundle, int... ids) {
        //This callback will be running on background thread
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
       
        try {
            //DB or Internet requests
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        //make RemoteViews depends on dataBundle and update by widget ID
        RemoteViews remoteViews = new RemoteViews();
        for (int widgetId : ids) {
            appWidgetManager.updateAppWidget(widgetId, remoteViews);
        }
    }
    
    @RequiresApi(api = Build.VERSION_CODES.O)
    @Override
    public Notification makeNotification(@NonNull Context context) {
        //This callback will be also running on background thread
        
        //make custom notification if you need (WidgetUpdater already has default implementation)
        
        //this notification will be shown on Android Oreo devices and higher (don't forget about NotificationChannel)
        return new Notification();
    }
}

WidgetProvider

When creating your own widget you can use RemoteViewsUpdater annotation to link the WidgetUpdater's child with your android.appwidget.AppWidgetProvider as below. WidgetUpdateService is an android.app.IntentService which will invokes your WidgetUpdater by calling method updateWidgets(Context context, AppWidgetsProvider provider, Bundle dataBundle, int... ids).

@RemoteViewsUpdater(SingleUpdater.class)
public class ExampleSingleAppWidget extends AppWidgetProvider {
        @Override
        public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
             // trigger you WidgetUpdater by this call
             WidgetUpdateService.updateWidgets(context, this, bundle, appWidgetIds);
        }

        @Override
        public void onEnabled(Context context) {
             AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
             int[] widgetIds = appWidgetManager.getAppWidgetIds(
                           new ComponentName(context, ExampleSingleAppWidget.class));
           
             // add some params for RemoteViews
             Bundle bundle = new Bundle();
             //...
             // update widgets
             WidgetUpdateService.updateWidgets(context, this, bundle, widgetIds);
        }

        @Override
        public void onDisabled(Context context) {
            //...
        }
}

RemoteViews extensions

List of helper extensions on RemoteViews:

method public static void setBackgroundColor(android.widget.RemoteViews, @IdRes int viewId, @ColorInt int color);
method public static void setBackgroundResource(android.widget.RemoteViews, @IdRes int viewId, @DrawableRes int drawable);
method public static void setEnabled(android.widget.RemoteViews, @IdRes int viewId, boolean enabled);
method public static void setImageViewAlpha(android.widget.RemoteViews, @IdRes int viewId, @IntRange(from=0L, to=255L) int alpha);
method public static void setImageViewMaxHeight(android.widget.RemoteViews, @IdRes int viewId, @DimenRes int height);
method public static void setImageViewMaxWidth(android.widget.RemoteViews, @IdRes int viewId, @DimenRes int width);
method public static void setTextViewMaxLines(android.widget.RemoteViews, @IdRes int viewId, int lines);
method public static void setTextViewMinLines(android.widget.RemoteViews, @IdRes int viewId, int lines);
method public static void setTextViewPaintFlags(android.widget.RemoteViews, @IdRes int viewId, int flags);
method public static void setTextViewTextSize(android.widget.RemoteViews, @IdRes int viewId, @DimenRes float size);

Please, have a look at the example project, if you have problems with implementation

Integration

The library is published to the jitpack repository, your project's build.gradle must contain:

allprojects {
	repositories {
		...
		maven { url 'https://jitpack.io' }
	}
}

To use this library add following to your module's build.gradle:

dependencies {
    implementation 'com.github.HeyAlex:WidgetUpdateHelper:1.4'
}

Why to use

All updates are on background thread. So if you need to make RemoteViews depends on data from Database or Internet, that's what you need. Android P is also supported.

License

WTFPL
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].