Android Open Source - UTHPortal-Android-Gradle Settings Adapter






From Project

Back to project page UTHPortal-Android-Gradle.

License

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.

Java Source Code

package com.uth.uthportal.adapter;
/*from   w ww  .  j ava2s  .  co m*/
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import com.uth.uthportal.R;
import com.uth.uthportal.collections.AvailableCourse;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
/**
 * This adapter is used for listing available courses
 * with a check box next to them.
 * @author GeorgeT
 *
 */
public class SettingsAdapter extends ArrayAdapter<AvailableCourse>{
  List<AvailableCourse> availableCoursesList;
  Context _context;

  public SettingsAdapter(Context context, int resource, List<AvailableCourse> objects) {
    super(context, resource, objects);
    availableCoursesList = new ArrayList<AvailableCourse>(); //Initialize list
    availableCoursesList.addAll(objects); //clone list
    _context = context;
  }
  private class ViewHolder{
    TextView code;
    CheckBox name;
  }
    public List<String> getCheckedCourses(){
        List<String> result = new ArrayList<String>();

        for (AvailableCourse course : availableCoursesList) {
            if (course.getAnnouncements)
                result.add(course.code);
        }

        return result;
    }

   @Override
    public View getView(final int position, View convertView, ViewGroup parent) {
    
     ViewHolder holder = null;
     Log.v("ConvertView", String.valueOf(position));
    
     if (convertView == null) {
       LayoutInflater vi = (LayoutInflater)this._context
          .getSystemService(Context.LAYOUT_INFLATER_SERVICE); //get system layout inflater service
       convertView = vi.inflate(R.layout.list_settings_item, null);
      
       holder = new ViewHolder();
       holder.code = (TextView) convertView.findViewById(R.id.settingsCourseCode);
       holder.name = (CheckBox) convertView.findViewById(R.id.settingsCourseCheck);
       convertView.setTag(holder);

           holder.name.setOnCheckedChangeListener(new CheckBox.OnCheckedChangeListener(){
               @Override
               public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
                   String text = buttonView.getText().toString();

                   for (AvailableCourse course : availableCoursesList) {
                       if (course.info.name.equals(text))
                           course.getAnnouncements = isChecked;
                   }
               }
           });

           holder.code.setOnClickListener( new View.OnClickListener() {
                public void onClick(View v) {
                    TextView textView = (TextView)v;
                    Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(textView.getText().toString()));
                    _context.startActivity(browserIntent);
               }
            });
     } else {
           holder = (ViewHolder) convertView.getTag();
     }
    
     AvailableCourse course = availableCoursesList.get(position); //get the course at position of list
     holder.code.setText(" (" + course.code + ")");
     holder.name.setText(course.info.name);
     holder.name.setChecked(course.getAnnouncements);
     holder.name.setTag(course);
    
     return convertView;
    
    }
}




Java Source Code List

com.uth.uthportal.AboutScreen.java
com.uth.uthportal.CoursesFragment.java
com.uth.uthportal.DepartmentFragment.java
com.uth.uthportal.FoodFragment.java
com.uth.uthportal.MainScreen.java
com.uth.uthportal.SettingsScreen.java
com.uth.uthportal.adapter.AdapterManager.java
com.uth.uthportal.adapter.AdapterProvider.java
com.uth.uthportal.adapter.ExpandableListAdapter.java
com.uth.uthportal.adapter.SettingsAdapter.java
com.uth.uthportal.adapter.TabsPagerAdapter.java
com.uth.uthportal.buffers.AvailableCoursesParser.java
com.uth.uthportal.buffers.CoursesParser.java
com.uth.uthportal.buffers.FileOperation.java
com.uth.uthportal.buffers.FoodParser.java
com.uth.uthportal.buffers.GeneralAnnParser.java
com.uth.uthportal.buffers.SettingsManager.java
com.uth.uthportal.collections.AnnItem.java
com.uth.uthportal.collections.Announcements.java
com.uth.uthportal.collections.AvailableCourse.java
com.uth.uthportal.collections.CourseInfo.java
com.uth.uthportal.collections.Course.java
com.uth.uthportal.collections.DayMenu.java
com.uth.uthportal.collections.DefaultIntervals.java
com.uth.uthportal.collections.Dish.java
com.uth.uthportal.collections.Food.java
com.uth.uthportal.collections.GeneralAnnouncement.java
com.uth.uthportal.collections.Settings.java
com.uth.uthportal.network.ApiLinks.java
com.uth.uthportal.network.AppRater.java
com.uth.uthportal.network.AsyncJSONDownloader.java
com.uth.uthportal.network.JSONDownloader.java
com.uth.uthportal.service.DataSyncService.java
com.uth.uthportal.util.SystemUiHiderBase.java
com.uth.uthportal.util.SystemUiHiderHoneycomb.java
com.uth.uthportal.util.SystemUiHider.java