Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <h2>I found one solution, but it might not be ideal!</h2> <p>I set a <strong>repeating alarm</strong> in the onEnable() of the AppWidgetProvider and cancel it in the onDisabled(). That alarm triggers a BroadcastReceiver that updates the widget views and use <strong>setRelativeScrollPosition()</strong> on the RemoteView.</p> <p>Here's a few lines of code: </p> <ul> <li><p>In the class extending AppWidgetProvider</p> <pre><code>public void onEnabled(Context context) { [...] // create alarm that will move the widget list content every n seconds AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); long firstTime = SystemClock.elapsedRealtime(); firstTime += 10*1000; Intent i = new Intent(context, WidgetAutoScroller.class); PendingIntent widgetAutoScroll = PendingIntent.getBroadcast(context, 0, i, 0); alarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME, firstTime, 10*1000, widgetAutoScroll); super.onEnabled(context); } @Override public void onDisabled(Context context) { // deactivate the alarm that moves the widget content Intent i = new Intent(context, WidgetAutoScroller.class); PendingIntent widgetAutoScroll = PendingIntent.getBroadcast(context, 0, i, 0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); alarmManager.cancel(widgetAutoScroll); super.onDisabled(context); } </code></pre></li> <li><p>WidgetAutoScroller.java</p></li> </ul> <p><code> public class WidgetAutoScroller extends BroadcastReceiver {</p> <pre><code> @Override public void onReceive(Context context, Intent intent) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, CascadeWidgetProvider.class)); for( int i=0 ; i&lt;appWidgetIds.length ; i++) { int appWidgetId = appWidgetIds[i]; RemoteViews rv = CascadeWidgetProvider.getWidgetView(context, appWidgetId); rv.setRelativeScrollPosition(R.id.widget_collection, 1); appWidgetManager.updateAppWidget(appWidgetId, rv); } } } </code></pre> <p></code></p> <p><b>If you have a better solution to my problem, please answer.</b></p> <p><strong>EDIT</strong>: Another problem is: what to do when I reach the end of my list? <br/> I would want to go to the first item of the list, but I don't know how to get the current position of the list from my RemoteView or appWidgetId ...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload