Android Open Source - chat.android C H A Select Child Adapter






From Project

Back to project page chat.android.

License

The source code is released under:

GNU General Public License

If you think the Android project chat.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

package org.chat.android;
/*from   w w w. j  a va2s.com*/
import static org.chat.android.R.id.client_row;
import static org.chat.android.R.id.client_name;
import static org.chat.android.R.id.client_metadata;
import static org.chat.android.R.id.client_checkbox;

import java.util.ArrayList;
import java.util.List;

import org.chat.android.R;
import org.chat.android.models.Client;

import com.j256.ormlite.android.apptools.OpenHelperManager;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
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.LinearLayout;
import android.widget.TextView;

public class CHASelectChildAdapter extends ArrayAdapter<Client> {
  private LayoutInflater mInflater;
    private List<Client> clientsArray;
    private int visitId = 0;
    private int hhId = 0;
    List<Client> presenceArrayList = new ArrayList<Client>();
    // since we aren't OrmLiteBaseActivity or BaseActivity we can't use getHelper()
    // so we use OpenHelperManager
    private DatabaseHelper databaseHelper = null;

    private DatabaseHelper getHelper() {
        if (databaseHelper == null) {
            databaseHelper =
                OpenHelperManager.getHelper(getContext(), DatabaseHelper.class);
        }
        return databaseHelper;
    }

    private void releaseHelper() {
      if (databaseHelper != null) {
            OpenHelperManager.releaseHelper();
            databaseHelper = null;
        }
    }


    public CHASelectChildAdapter(Context context, int layoutResourceId, List<Client> clientsArray, int vId, int hId) {
        super(context, layoutResourceId, clientsArray);
        visitId = vId;
        hhId = hId;
        this.mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.clientsArray = clientsArray;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        convertView = this.mInflater.inflate(R.layout.cha_select_child_row, null);
        final Context context = getContext();

        final Client c = clientsArray.get(position);

        TextView name = null;
        TextView metadataTv = null;
        CheckBox cBox = null;
        String metadata = null;
        if (convertView != null) {
            name = (TextView)convertView.findViewById(client_name);
            name.setText(c.getFirstName() + " " + c.getLastName());
            metadataTv = (TextView)convertView.findViewById(client_metadata);
            if (c.getGender().equals("male")) {
              metadata = "male, ";
              name.setTextColor(Color.parseColor("#0071bc"));
            } else if (c.getGender().equals("female")) {
              metadata = "female, ";
              name.setTextColor(Color.parseColor("#93278f"));
            } else {
              Log.e("No gender assigned for", c.getFirstName()+" "+c.getLastName());
            }
            metadata += c.getAgeString();
            metadataTv.setText(metadata);

            cBox = (CheckBox)convertView.findViewById(client_checkbox);
            // check off if child has been done for imm and cha
            if (checkCHARequirements(c) == true) {
              cBox.setChecked(true);
            } else {
              cBox.setChecked(false);
            }
        }

        LinearLayout row = (LinearLayout)convertView.findViewById(client_row);

        row.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
              final Intent i = new Intent(context, CHAOverviewActivity.class);
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Bundle b = new Bundle();
            b.putInt("visitId",visitId);
            b.putInt("hhId",hhId);
            b.putInt("clientId",c.getId());
            i.putExtras(b);
            v.getContext().startActivity(i);
            }
        });

        return convertView;
    }

    // again, semi-duplicating functionality in HomeActivity. Think about moving this all to BaseActivity
    // FIXME Colin if this could move to an activity life would be easier. Also note that f is not a very
    // meaningful name and you are using Boolean, would boolean work too? (build in type)
    // Lastly f is set to null. should be true or false???
    private Boolean checkCHARequirements(Client c) {
//      Context context = getContext();
      Boolean f = null;

      Boolean healthFlag = false;
      Boolean immunizationFlag = false;
      if (ModelHelper.getCHAAccessedCompleteForVisitIdAndClientIdAndType(getHelper(), visitId, c.getId(), "health") == true) {
        healthFlag = true;
      } else {
        healthFlag = false;
      }
    Boolean allVaccinesAdministered = ModelHelper.getVaccineRecordedCompleteForClientId(getHelper(), c.getId());
    Boolean chaImmunizationComplete = ModelHelper.getCHAAccessedCompleteForVisitIdAndClientIdAndType(getHelper(), visitId, c.getId(), "immunization");
    if (allVaccinesAdministered || chaImmunizationComplete) {
      immunizationFlag = true;
    } else {
      immunizationFlag = false;
    }

    if (healthFlag == false || immunizationFlag == false) {
      f = false;
    } else {
      f = true;
    }

      return f;
    }

  public List<Client> getSelectedClients() {
    return presenceArrayList;
  }
}




Java Source Code List

org.chat.android.BaseActivity.java
org.chat.android.CHADelivery.java
org.chat.android.CHAOverviewActivity.java
org.chat.android.CHASelectChildActivity.java
org.chat.android.CHASelectChildAdapter.java
org.chat.android.ChatUtil.java
org.chat.android.ClientsAdapter.java
org.chat.android.DatabaseHelper.java
org.chat.android.GPSTracker.java
org.chat.android.HealthDeliveryActivity.java
org.chat.android.HealthDetailsActivity.java
org.chat.android.HealthOverviewActivity.java
org.chat.android.HealthOverviewRecordActivity.java
org.chat.android.HomeActivity.java
org.chat.android.ImmunizationsReceivedActivity.java
org.chat.android.ImmunizationsSummaryActivity.java
org.chat.android.LoginActivity.java
org.chat.android.Mail.java
org.chat.android.ModelHelper.java
org.chat.android.MyApplication.java
org.chat.android.ResourcesActivity.java
org.chat.android.RestoreVisitActivity.java
org.chat.android.ServiceDeliveryActivity.java
org.chat.android.ServiceDeliveryAdapter.java
org.chat.android.ServiceDetailsActivity.java
org.chat.android.ServiceOtherActivity.java
org.chat.android.ServiceOverviewActivity.java
org.chat.android.ServicesAdapter.java
org.chat.android.SetupDB.java
org.chat.android.SetupVisitActivity.java
org.chat.android.SyncResourcesActivity.java
org.chat.android.Auth.AccountGeneral.java
org.chat.android.Auth.AuthenticatorService.java
org.chat.android.Auth.Authenticator.java
org.chat.android.Auth.ChatAuthServerAuthenticate.java
org.chat.android.Auth.MainActivity.java
org.chat.android.Auth.ServerAuthenticate.java
org.chat.android.Sync.StubProvider.java
org.chat.android.Sync.SyncAdapter.java
org.chat.android.Sync.SyncService.java
org.chat.android.Sync.provider.ChatContentProvider.java
org.chat.android.models.Attendance.java
org.chat.android.models.CHAAccessed.java
org.chat.android.models.Client.java
org.chat.android.models.HealthPage.java
org.chat.android.models.HealthSelectRecorded.java
org.chat.android.models.HealthSelect.java
org.chat.android.models.HealthTheme.java
org.chat.android.models.HealthTopicAccessed.java
org.chat.android.models.HealthTopic.java
org.chat.android.models.Household.java
org.chat.android.models.PageAssessment1.java
org.chat.android.models.PageSelect1.java
org.chat.android.models.PageText1.java
org.chat.android.models.PageVideo1.java
org.chat.android.models.ResourceAccessed.java
org.chat.android.models.Resource.java
org.chat.android.models.Role.java
org.chat.android.models.ServiceAccessed.java
org.chat.android.models.Service.java
org.chat.android.models.TopicVideo.java
org.chat.android.models.Util.java
org.chat.android.models.VaccineRecorded.java
org.chat.android.models.Vaccine.java
org.chat.android.models.VideoAccessed.java
org.chat.android.models.Video.java
org.chat.android.models.Visit.java
org.chat.android.models.Worker.java
org.chat.android.pages.Assessment1Fragment.java
org.chat.android.pages.BaseFragment.java
org.chat.android.pages.ReferralFragment.java
org.chat.android.pages.Select1Fragment.java
org.chat.android.pages.Text1Fragment.java
org.chat.android.pages.Video1Fragment.java