Android Open Source - RssReader Widget Provider






From Project

Back to project page RssReader.

License

The source code is released under:

MIT License

If you think the Android project RssReader listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.vicmns.rssreader.widget;
// ww  w. ja v a2  s  . c  o m
import com.vicmns.rssreader.R;
import com.vicmns.rssreader.activities.RssItemDetailsActivity;
import com.vicmns.rssreader.services.GetRssItemsService;

import android.annotation.SuppressLint;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;

public class WidgetProvider extends AppWidgetProvider {
  
  @Override
  public void onEnabled(Context context) {
    super.onEnabled(context);
  }

  @Override
  public void onReceive(Context context, Intent intent) {
    Bundle bundle = intent.getBundleExtra("AdapterBundle");
        if (bundle != null) {
          int appWidgetId = bundle.getInt(
            AppWidgetManager.EXTRA_APPWIDGET_ID,
            AppWidgetManager.INVALID_APPWIDGET_ID);
          Log.i(this.getClass().getSimpleName(), "appWidgetId: " + appWidgetId);
          updateWidget(context, appWidgetId, bundle);
        }
        
        super.onReceive(context, intent);
  }
  
  

  @Override
  public void onUpdate(Context context, AppWidgetManager appWidgetManager,
      int[] appWidgetIds) {
    /*
     * int[] appWidgetIds holds ids of multiple instance of your widget
     * meaning you are placing more than one widgets on your homescreen
     */
    final int N = appWidgetIds.length;
    for (int i = 0; i < N; ++i) {
      Intent intent = new Intent(context, GetRssItemsService.class);
        Bundle bundle = new Bundle();
        bundle.putInt(GetRssItemsService.WIDGET_ID, appWidgetIds[N - 1]);
        intent.putExtra(GetRssItemsService.BUNDLE_TAG, bundle);
        
        context.startService(intent);
    }
  }
  
  
  private void updateWidget(Context context, int appWidgetId, Bundle bundle) {
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    RemoteViews remoteViews = updateWidgetListView(context,
        appWidgetId, bundle);
        manager.updateAppWidget(appWidgetId, remoteViews);
  }

  @SuppressWarnings("deprecation")
  @SuppressLint("NewApi")
  private RemoteViews updateWidgetListView(Context context, int appWidgetId, Bundle bundle) {
    RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
        R.layout.widget_main_layout);
    Intent svcIntent = new Intent(context, WidgetService.class);
    svcIntent.putExtra("AdapterBundle",bundle);
    svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME)));
    if(Build.VERSION.SDK_INT < 14)
      remoteViews.setRemoteAdapter(appWidgetId, R.id.widget_list_view,
          svcIntent);
    else
      remoteViews.setRemoteAdapter(R.id.widget_list_view, svcIntent);
    
    remoteViews.setViewVisibility(R.id.widget_loading_indicator, View.GONE);
    remoteViews.setEmptyView(R.id.widget_main_layout, R.id.widget_empty_view_layout);
    
    Intent startActivityIntent = new Intent(context, RssItemDetailsActivity.class);
        PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, 0);
        remoteViews.setPendingIntentTemplate(R.id.widget_list_view, startActivityPendingIntent);

    
    return remoteViews;
  }

}




Java Source Code List

com.vicmns.rssreader.activities.MainActivity.java
com.vicmns.rssreader.activities.RssItemDetailsActivity.java
com.vicmns.rssreader.adapters.RssItemsAdapter.java
com.vicmns.rssreader.app.RssReaderApplication.java
com.vicmns.rssreader.http.GetRssItems.java
com.vicmns.rssreader.http.GetWidgetRssItems.java
com.vicmns.rssreader.http.SimpleXmlRequest.java
com.vicmns.rssreader.interfaces.GetRssItemsCallbacks.java
com.vicmns.rssreader.interfaces.HttpConsumerCallbacks.java
com.vicmns.rssreader.interfaces.ListOverlayLayoutCallbacks.java
com.vicmns.rssreader.models.RssItem.java
com.vicmns.rssreader.models.RssItems.java
com.vicmns.rssreader.services.GetRssItemsService.java
com.vicmns.rssreader.views.ListOverlayLayoutView.java
com.vicmns.rssreader.views.SquareImageView.java
com.vicmns.rssreader.widget.WidgetListProvider.java
com.vicmns.rssreader.widget.WidgetProvider.java
com.vicmns.rssreader.widget.WidgetService.java
fr.castorflex.android.smoothprogressbar.ColorsShape.java
fr.castorflex.android.smoothprogressbar.ContentLoadingSmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBarUtils.java
fr.castorflex.android.smoothprogressbar.SmoothProgressBar.java
fr.castorflex.android.smoothprogressbar.SmoothProgressDrawable.java
org.robolectric.shadows.ShadowSupportMenuInflater.java