Android Open Source - droid-talks Conference Widget Service






From Project

Back to project page droid-talks.

License

The source code is released under:

GNU General Public License

If you think the Android project droid-talks 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.gareth.assignment.conferencewidget;
/*from   w  ww .j  av  a 2s. co m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.RemoteViews;
import android.widget.RemoteViewsService;


public class ConferenceWidgetService extends RemoteViewsService {

  @Override
  public RemoteViewsFactory onGetViewFactory(Intent intent) {
    return new ListRemoteViewsFactory(this.getApplicationContext(), intent);
  }

}


class ListRemoteViewsFactory implements RemoteViewsService.RemoteViewsFactory {
  
  private static final String LOG_TAG = "ListRemoteViewsFactory";
  
  private static long[] sessionsForDay;
    private List<WidgetCollectionItem> listWidgetItems = new ArrayList<WidgetCollectionItem>();
    private Context context;

    
    public ListRemoteViewsFactory(Context ctx, Intent intent) {
        context = ctx;
    }
    
    
    public void onCreate() {
      Log.i(LOG_TAG, "In onCreate");
    }


    public void onDestroy() {
      Log.i(LOG_TAG, "In onDestroy");
    }

    
    public int getCount() {
        return sessionsForDay.length;
    }
  
    
  public RemoteViews getViewAt(int position) {
        // position will always range from 0 to getCount() - 1.
    Log.i(LOG_TAG, "In getViewAt");
        // Construct a remote views item based on the widget_item.xml file, and set the
        // text based on the position.
        RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_item);
        rv.setTextViewText(R.id.widget_item_start_end, 
            listWidgetItems.get(position).getSessionTimeWithHyphen());
        rv.setTextViewText(R.id.widget_item_title, 
            listWidgetItems.get(position).getSessionTitle());
        rv.setTextViewText(R.id.widget_item_type, 
            listWidgetItems.get(position).getSessionType());

        // Return the remote views object.
        return rv;
    }

  
  public RemoteViews getLoadingView() {
        return null;
    }

    public int getViewTypeCount() {
        return 1;
    }

    public long getItemId(int position) {
        return position;
    }

    public boolean hasStableIds() {
        return true;
    }

    
    public void onDataSetChanged() {
      Log.i(LOG_TAG, "In onDataSetChanged");
      
      // Clear listWidgetItems to refresh with new day data when
      // the next / previous day button is pressed
      listWidgetItems.clear();
      
      sessionsForDay = ConferenceWidget.getDBAccessInstance().getSessionsForDayId(
          ConferenceWidget.getCurrentDayId());
      String startTime = null;
      String endTime = null;
      String type = null;
      String title = null;
      
        for (int i = 0; i < sessionsForDay.length; i++) {
          startTime = ConferenceWidget.getDBAccessInstance().getStartTimeForSessionId(
              sessionsForDay[i]);
          endTime = ConferenceWidget.getDBAccessInstance().getEndTimeForSessionId(
              sessionsForDay[i]);
          type = ConferenceWidget.getDBAccessInstance().getTypeForSessionId(
              sessionsForDay[i]);
          title = ConferenceWidget.getDBAccessInstance().getSessionTitleForSessionId(
              sessionsForDay[i]);
          // Add a new WidgetCollectionItem for each row in the ListView
            listWidgetItems.add(new WidgetCollectionItem(startTime, endTime, type, title));
        }

        Log.i(LOG_TAG, title);
        Log.i(LOG_TAG, type);
    }

}




Java Source Code List

com.gareth.assignment.conferencewidget.ConferenceWidgetService.java
com.gareth.assignment.conferencewidget.ConferenceWidget.java
com.gareth.assignment.conferencewidget.DBAccess.java
com.gareth.assignment.conferencewidget.WidgetCollectionItem.java