Back to project page UTHPortal-Android-Gradle.
The source code is released under:
MIT License
If you think the Android project UTHPortal-Android-Gradle listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.uth.uthportal.adapter; //from w w w . j a v a2 s . c om import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import android.content.Context; import com.uth.uthportal.R; import com.uth.uthportal.collections.AnnItem; import com.uth.uthportal.collections.Course; import com.uth.uthportal.collections.DayMenu; import com.uth.uthportal.collections.Dish; import com.uth.uthportal.collections.Food; import com.uth.uthportal.collections.GeneralAnnouncement; /** * This class provides adapters for custom list views. * @author GeorgeT * */ public class AdapterProvider { //TODO add for the rest tabs public static ExpandableListAdapter getCoursesAdapter(Context context,List<Course> courses){ //Initialize list elements List<String> listParent = new ArrayList<String>(); HashMap<String, List<String>> listChild = new HashMap<String, List<String>>(); //-------------- for(Course course : courses){ listParent.add( String.format("%s - %S",course.info.name,course.code) ); //add parent items format: Name - Code List<String> childData = new ArrayList<String>(); //initialize child data for(AnnItem item : course.announcements.items){ String date = formatDateToString(item.date,item.hasTime,true); //get date string childData.add( String.format("<font color=\"#9b0000\">- %s -</font><br />%s", date, item.html) ); } listChild.put(listParent.get(listParent.size()-1),childData); //map childData to Parent } //create adapter return new ExpandableListAdapter(context, listParent, listChild); } public static ExpandableListAdapter getGeneralAnnAdapter(Context context, List<GeneralAnnouncement> announcements ){ List<String> listParent = new ArrayList<String>(); HashMap<String,List<String>> listChild = new HashMap<String, List<String>>(); //-------------- for (GeneralAnnouncement announcement: announcements){ String date = formatDateToString(announcement.date, false, true); //get date string listParent.add( String.format("<font color=\"#9b0000\">%s</font> - %s", date, announcement.title) ); List<String> childData = new ArrayList<String>(); //initialize child data childData.add(announcement.html); listChild.put(listParent.get(listParent.size() - 1 ), childData); } return new ExpandableListAdapter(context, listParent, listChild); } public static ExpandableListAdapter getFoodAdapter(Context context,Food food){ //Initialize list elements List<String> listParent = new ArrayList<String>(); HashMap<String, List<String>> listChild = new HashMap<String, List<String>>(); //-------------- for(DayMenu dayMenu : food.weekMenu){ listParent.add( String.format("%s - <font color=\"#9b0000\">%s</font>", dayMenu.name, formatDateToString(dayMenu.date, false, false)) ); List<String> childData = new ArrayList<String>(); //add lunch and dinner for each day childData.add(formatDinnerLunch(context, dayMenu.lunch, R.string.lunch)); childData.add(formatDinnerLunch(context, dayMenu.dinner, R.string.dinner)); //!-------------------------------- listChild.put(listParent.get(listParent.size()-1),childData); //map childData to Parent } return new ExpandableListAdapter(context, listParent, listChild); } private static String formatDinnerLunch(Context context, Dish dinnerLunch, int name){ return String.format("<font color=\"#9b0000\">- %s -</font><br>" + "<font color=\"#2b9eb5\">%s: </font> %s<br>" + "<font color=\"#2b9eb5\">%s: </font> %s<br>" + "<font color=\"#2b9eb5\">%s: </font> %s<br>" ,context.getString(name), context.getString(R.string.main_plate), dinnerLunch.main, context.getString(R.string.salad),dinnerLunch.salad, context.getString(R.string.desert),dinnerLunch.desert); } private static String formatDateToString(Date date,Boolean addTime, Boolean addDay){ SimpleDateFormat sdFormat; String result; if (addTime){ sdFormat = new SimpleDateFormat("E, MMMM d, yyyy HH:mm"); } else { if(addDay){ sdFormat = new SimpleDateFormat("E, MMMM d, yyyy"); } else { sdFormat = new SimpleDateFormat("MMMM d, yyyy"); } } result = sdFormat.format(date); return result; } }