Android Open Source - Timetable Event View Provider






From Project

Back to project page Timetable.

License

The source code is released under:

GNU General Public License

If you think the Android project Timetable 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.timetable.android;
/*from w w  w. j  ava 2s.co m*/
import java.util.ArrayList;
import java.util.List;

import android.content.Context;

/*
 * Class that should be used to create EventViews.
 * It tries to reuse EventView, if it is possible.
 * After EventView is not needed(visible) anymore, method releaseViews should be called.
 */
public class EventViewProvider {

  private static EventViewProvider mInstance;
  
  private Context mContext;
  
  private static final int ID_NO_OWNER = 0;
  
  private List<ViewContainer> views = new ArrayList<ViewContainer>();
  
  private EventViewProvider(Context context) {
    mContext = context;
  }
  
  public static EventViewProvider getInstance(Context context) {
    if (mInstance == null) {
      return new EventViewProvider(context);
    }
    return mInstance;
  }
  
  /*
   * Get view. If there is free view, return it.
   * Assign view to given owner.
   */
  public EventView getView(int ownerId) {
    if (ownerId == ID_NO_OWNER) {
      return null;
    }
    for (ViewContainer view: views) {
      if (!hasOwner(view)) {
        view.ownerId = ownerId;
        return view.eventView;
      }
    }
    return new EventView(mContext);
  }
  
  /*
   * Release all views, attached to given owner, so that they can be used later by another owner.
   */
  public void releaseViews(int ownerId) {
    for (ViewContainer view: views) {
      if (view.ownerId == ownerId) {
        view.ownerId = ID_NO_OWNER;
      }
    }
  }
  
  private boolean hasOwner(ViewContainer view) {
    return view.ownerId != ID_NO_OWNER;
  }
  
  static class ViewContainer {
    
    public int ownerId;
    
    public EventView eventView;
    
    public ViewContainer(EventView _eventView, int _ownerId) {
      eventView = _eventView;
      ownerId = _ownerId;
    }
    
  }
}




Java Source Code List

com.timetable.android.AlarmSoundPreference.java
com.timetable.android.BroadcastActions.java
com.timetable.android.DeviceMuteService.java
com.timetable.android.EventBroadcastSender.java
com.timetable.android.EventChecker.java
com.timetable.android.EventController.java
com.timetable.android.EventPager.java
com.timetable.android.EventPeriod.java
com.timetable.android.EventService.java
com.timetable.android.EventViewProvider.java
com.timetable.android.EventView.java
com.timetable.android.Event.java
com.timetable.android.IllegalEventDataException.java
com.timetable.android.Logger.java
com.timetable.android.ServiceStarter.java
com.timetable.android.TimetableApp.java
com.timetable.android.TimetableDatabase.java
com.timetable.android.activities.EventAddActivity.java
com.timetable.android.activities.EventCopyActivity.java
com.timetable.android.activities.EventDayViewActivity.java
com.timetable.android.activities.EventEditActivity.java
com.timetable.android.activities.SettingsActivity.java
com.timetable.android.alarm.AlarmDialogActivity.java
com.timetable.android.alarm.AlarmService.java
com.timetable.android.alarm.EventAlarm.java
com.timetable.android.uitests.AlarmDialogActivityTestCase.java
com.timetable.android.uitests.EventAddActivityTestCase.java
com.timetable.android.uitests.TimetableUiTestCase.java
com.timetable.android.utils.DateFormatFactory.java
com.timetable.android.utils.DateUtils.java
com.timetable.android.utils.FakeTimeProvider.java
com.timetable.android.utils.SimpleTimeProvider.java
com.timetable.android.utils.TestAlarmStarter.java
com.timetable.android.utils.TimeProvider.java
com.timetable.android.utils.Utils.java