Android Open Source - mobile2-android Upcoming Events Adapter

From Project

Back to project page mobile2-android.


The source code is released under:

Apache License

If you think the Android project mobile2-android 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

/*w ww  .j  ava  2 s.  c o m*/
import android.content.Context;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.ecollege.api.model.Course;
import com.ecollege.api.model.UpcomingEventItem;
import com.ecollege.api.model.UpcomingEventItem.CategoryType;
import com.ecollege.api.model.UpcomingEventItem.UpcomingEventType;

public class UpcomingEventsAdapter extends UberAdapter<UpcomingEventItem> {

  public UpcomingEventsAdapter(Context context, boolean canLoadMore) {
    super(context, true, false, canLoadMore);
  protected Object groupIdFunction(UpcomingEventItem item) {
    UpcomingEventItem uei = (UpcomingEventItem)item;
    if (uei.getTag() != null) return uei.getTag().toString();
    return "Unknown";
    private static class ViewHolder {
        TextView titleText;
        TextView scheduleText;
        TextView courseTitleText;
        ImageView icon;
    public static String getScheduleText(UpcomingEventItem uei) {
        if (uei.getWhen() == null || uei.getWhen().getTime() == null) {
          return "Schedule Unknown";
        } else {
            if (uei.getCategoryType() == CategoryType.Start) {
              return "Starts at " + DateTimeUtil.getLongFriendlyDate(uei.getWhen().getTime());
            } else if (uei.getCategoryType() == CategoryType.End) {
              return "Ends at " + DateTimeUtil.getLongFriendlyDate(uei.getWhen().getTime());
            } else {
              return "Due at " + DateTimeUtil.getLongFriendlyDate(uei.getWhen().getTime());
  protected View getDataItemView(View convertView, ViewGroup parent, UberItem<UpcomingEventItem> item) {

        // A ViewHolder keeps references to children views to avoid unneccessary calls
        // to findViewById() on each row.
        ViewHolder holder;

        // When convertView is not null, we can reuse it directly, there is no need
        // to reinflate it. We only inflate a new View when the convertView supplied
        // by ListView is null.
        if (convertView == null) {
            convertView = LayoutInflater.from(parent.getContext()).inflate(R.layout.upcoming_item, null);

            // Creates a ViewHolder and store references to the two children views
            // we want to bind data to.
            holder = new ViewHolder();
            holder.titleText = (TextView) convertView.findViewById(;
            holder.scheduleText = (TextView) convertView.findViewById(;
            holder.courseTitleText = (TextView) convertView.findViewById(;
            holder.icon = (ImageView) convertView.findViewById(;
        } else {
            // Get the ViewHolder back to get fast access to the TextView
            // and the ImageView.
            holder = (ViewHolder) convertView.getTag();
        // Bind the data efficiently with the holder.
        UpcomingEventItem uei = item.getDataItem();
        String title = uei.getTitle();
        long courseId = uei.getCourseId();
        Course course = ((ECollegeApplication)parent.getContext().getApplicationContext()).getCourseById(courseId);
        if (uei.getEventType() == UpcomingEventType.Html) {
        } else if (uei.getEventType() == UpcomingEventType.Thread) {
        } else if (uei.getEventType() == UpcomingEventType.QuizExamTest) {
        return convertView;  

Java Source Code List