Android Open Source - chat.android Services 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 www  .ja va  2s  . c  om*/
import static org.chat.android.R.id.service_row;

import java.util.List;
import java.util.Locale;

import org.chat.android.models.Service;
import org.chat.android.models.ServiceAccessed;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
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 ServicesAdapter extends ArrayAdapter<Service> {
  private LayoutInflater mInflater;
  private List<Service> servicesArray;
  private List<ServiceAccessed> saList;
  int visitId = 0;
  int hhId = 0;
  
  String lang = Locale.getDefault().getLanguage();

    public ServicesAdapter(Context context, int layoutResourceId, List<Service> servicesArray, List<ServiceAccessed> sal, int vId, int hId) {
        super(context, layoutResourceId, servicesArray);
        this.mInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.servicesArray = servicesArray;
        saList = sal;
        visitId = vId;
        hhId = hId;
    }
    
    public View getView(int position, View convertView, ViewGroup parent) {
      convertView = this.mInflater.inflate(R.layout.service_details_listview_row, null);
  
      Service s = servicesArray.get(position);

      TextView name = null;
      if (convertView != null) {
        LinearLayout row = (LinearLayout)convertView.findViewById(service_row);
        row.setTag(s);
        name = (TextView)convertView.findViewById(R.id.service_subtype_name);
        name.setText(s.getName(lang));
      }
      
      final CheckBox cb = (CheckBox) convertView.findViewById(R.id.service_subtype_checkbox);
        // go through the list of services delivered to this household on this visit
        for (ServiceAccessed sa : saList) {
            // if service matches tag, check off cb
          if (sa.getServiceId() == s.getId()) {
            cb.setChecked(true);
          }
        }
      
        LinearLayout row = (LinearLayout)convertView.findViewById(service_row);
        row.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
              cb.setChecked(true);          // checking it off here, cause we never hit the onCreate/onResume to redraw the UI after delivering the service
              
              final Intent i = new Intent(getContext(), ServiceDeliveryActivity.class);
              i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Bundle b = new Bundle();
            Service s = (Service) v.getTag();
            b.putString("serviceName",s.getName("en"));
            b.putInt("visitId",visitId);
            b.putInt("hhId",hhId);
            b.putBoolean("adInfoFlag",false);
            i.putExtras(b);      
            v.getContext().startActivity(i);
            }
        });
        
        
        

        

        // hacky way to override standard Android behaviour. Checkboxes have been made unclickable in the xml. presenceArrayList holds the checked (ie attending) client objects
//        row.setOnClickListener(new View.OnClickListener() {
//            public void onClick(View v) {
//                // maybe just do this with Strings instead of the whole object
//                Service s = (Service) cb.getTag();
//                if (cb.isChecked()) {
//                  cb.setChecked(false);
//                  selectedServices.remove(s);
//                } else {
//                  cb.setChecked(true);
//                  selectedServices.add(s);               
//                }
//            }
//        });
        

      return convertView;
    }
    

    
//  public ArrayList<String> getSelectedServices() {
//    ArrayList<String> sNames = new ArrayList<String>();
//    for (int i = 0; i < selectedServices.size(); i++) {
//      Service s = selectedServices.get(i);
//      sNames.add(s.getName(lang));
//    }
//    
//    return sNames;
//  }    
}




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