Android Open Source - chat.android Health Overview Activity






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 ww  . ja va2s.  co  m*/
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.chat.android.models.HealthSelectRecorded;
import org.chat.android.models.HealthTheme;
import org.chat.android.models.HealthTopic;
import org.chat.android.models.HealthTopicAccessed;

import com.j256.ormlite.dao.Dao;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class HealthOverviewActivity extends BaseActivity {
  Context context = null;
  int hhId = 0;
  int visitId = 0;
  
  public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
    setContentView(R.layout.activity_health_overview);
    
    Bundle b = getIntent().getExtras();
    hhId = b.getInt("hhId");
    visitId = b.getInt("visitId");
    
    //setupUIElements();
    
    checkThemeComplete();
    }
  
  public void onResume() {
    super.onResume();
    checkThemeComplete();
  }
   
  public void openHealthDetails(View v) {
//    String healthTheme = null;
//    
//    Boolean previouslyAccessedFlag = false;
//    
//    try {
//      Dao<HealthSelectRecorded, Integer> hsrDao = getHelper().getHealthSelectRecordedDao();
//      List<HealthSelectRecorded> hsrList = hsrDao.queryBuilder().where().eq("visit_id",visitId).and().eq("theme", healthTheme).query();      
//      Iterator<HealthSelectRecorded> iter = hsrList.iterator();
//      while (iter.hasNext()) {
//        HealthSelectRecorded hsr = iter.next();
//        previouslyAccessedFlag = true;
//      }
//    } catch (SQLException e2) {
//      // TODO Auto-generated catch block
//      e2.printStackTrace();
//    }
//    
//    
//    Intent i;
//    if (previouslyAccessedFlag == true) {
//      i = new Intent(HealthOverviewActivity.this, HealthDetailsActivity.class);
//    } else {
//      i = new Intent(HealthOverviewActivity.this, HealthOverviewRecordActivity.class);
//    }
    
    String healthTheme = (String) v.getTag();
    Intent i = new Intent(HealthOverviewActivity.this, HealthDetailsActivity.class);
    Bundle b = new Bundle();
    b.putString("healthTheme",healthTheme);
    b.putInt("visitId",visitId);
      b.putInt("hhId",hhId);
    i.putExtras(b);
    startActivity(i);
  }
  
  // TODO: remove from XML, finish me
//  public void setupUIElements() {
//    List <HealthTheme> themes = ModelHelper.getHealthThemes(context);
//    for (HealthTheme ht : themes) {
//      
//    }
//    ((TextView)findViewById(R.id.health_HIV_title_field)).setText("HIV");
//    ((ImageView)findViewById(R.id.health_HIV_button_img)).setTag("HIV");
//    ((ImageView)findViewById(R.id.health_HIV_button)).setTag("HIV");
//  }
  
  public void checkThemeComplete() {
      List<ImageView> imgViewList = new ArrayList<ImageView>();
      imgViewList.add((ImageView)findViewById(R.id.health_HIV_button_img));
      imgViewList.add((ImageView)findViewById(R.id.health_disease_button_img));
      imgViewList.add((ImageView)findViewById(R.id.health_nutrition_button_img));
      imgViewList.add((ImageView)findViewById(R.id.health_development_button_img));
      
      List<ImageView> checkmarkList = new ArrayList<ImageView>();
      checkmarkList.add((ImageView) findViewById(R.id.health_HIV_checkmark));
      checkmarkList.add((ImageView) findViewById(R.id.health_disease_checkmark));
      checkmarkList.add((ImageView) findViewById(R.id.health_nutrition_checkmark));
      checkmarkList.add((ImageView) findViewById(R.id.health_development_checkmark));
      
    // pull all of the topics accessed for this household, then clear those with duplicate 
    List<HealthTopicAccessed> topicsAccessed = new ArrayList<HealthTopicAccessed>();
    try {
      Dao<HealthTopicAccessed, Integer> htaDao = getHelper().getHealthTopicAccessedDao();
      topicsAccessed = htaDao.queryBuilder().where().eq("hh_id",hhId).and().isNotNull("end_time").query();
    } catch (SQLException e2) {
      // TODO Auto-generated catch block
      e2.printStackTrace();
    }
    
    // for each theme (ie button)
    for (int i = 0; i < imgViewList.size(); i++) {
      List<HealthTopic> healthTopics = new ArrayList<HealthTopic>();      
      // pull all topics related to that theme
      try {
        Dao<HealthTopic, Integer> topicDao = getHelper().getHealthTopicsDao();
        healthTopics = topicDao.queryBuilder().where().eq("theme",imgViewList.get(i).getTag()).query();
      } catch (SQLException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
      }
      
      // iterate over the topics list to see if the topic_id is in the hta_list
      int compareCounter = 0;
      for (HealthTopic ht : healthTopics) {
        for (HealthTopicAccessed hta : topicsAccessed) {
          if (ht.getId() == hta.getTopicId()) {
            compareCounter++;
            break;            // user can redo the same topic again, so there may be multiple htas with the same name - break to avoid double counting
          }  
        }
      }
      
      // mark as complete the button if all of the topic_ids are in the hta list (for this household)
      if (healthTopics.size() > 0 && compareCounter == healthTopics.size()) {
        imgViewList.get(i).setAlpha(90);
        checkmarkList.get(i).setVisibility(View.VISIBLE);
      }
      
    }
  }  
}




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