Android Open Source - GeoTasker Profile Adapter






From Project

Back to project page GeoTasker.

License

The source code is released under:

GNU General Public License

If you think the Android project GeoTasker 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.fjaviermo.adapter;
//from  w  w  w . j  a va2  s . c om
import java.util.List;

import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.CompoundButton.OnCheckedChangeListener;
import android.widget.Switch;
import android.widget.TextView;

import com.fjaviermo.geotasker.R;
import com.fjaviermo.model.Profile;

public class ProfileAdapter extends ArrayAdapter<Profile> {

  private final Activity context;
  private List<Profile> profiles;
  private ChangeSwitchCallback mDeleteItemCallback;

  static class ViewHolder {
    public TextView profileName;
    public Switch activate;
  }

  public ProfileAdapter(Activity context, List<Profile> names, ChangeSwitchCallback callback) {
    super(context, R.layout.profile_row, names);
    this.context = context;
    this.profiles = names;
    this.mDeleteItemCallback = callback;    
  }

  @Override
  public View getView(final int position, View convertView, ViewGroup parent) {
    View rowView = convertView;
    if (rowView == null) {
      LayoutInflater inflater = context.getLayoutInflater();
      rowView = inflater.inflate(R.layout.profile_row, null);
      ViewHolder viewHolder = new ViewHolder();
      viewHolder.profileName = (TextView) rowView.findViewById(R.id.lblName);
      
      viewHolder.activate = (Switch) rowView.findViewById(R.id.activate);
      viewHolder.activate.setOnCheckedChangeListener(new OnCheckedChangeListener() 
      {               
        @Override
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) 
        {       
          mDeleteItemCallback.changeState(position);
        }
      });
      rowView.setTag(viewHolder);
    }

    ViewHolder holder = (ViewHolder) rowView.getTag();
    Profile profile = profiles.get(position);

    holder.profileName.setText(profile.getName());
    holder.activate.setActivated(profile.isActive());

    return rowView;
  }
  
  public interface ChangeSwitchCallback {
    public void changeState(int position);
  }
}




Java Source Code List

com.fjaviermo.adapter.ProfileAdapter.java
com.fjaviermo.dao.LocationDataSource.java
com.fjaviermo.dao.ProfilesDataSource.java
com.fjaviermo.database.DatabaseHelper.java
com.fjaviermo.database.LocationSQLiteHelper.java
com.fjaviermo.database.ProfilesSQLiteHelper.java
com.fjaviermo.geotasker.AddProfileDialogFragment.java
com.fjaviermo.geotasker.MainActivity.java
com.fjaviermo.geotasker.ProfileFragment.java
com.fjaviermo.geotasker.ProfileListFragment.java
com.fjaviermo.model.Location.java
com.fjaviermo.model.Profile.java