Android Open Source - chat.android Health Details 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 ww w .  j a  v a 2 s  .  c o  m
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

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

import com.j256.ormlite.dao.Dao;

import android.content.Context;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.TextView;

public class HealthDetailsActivity extends BaseActivity {
  Context context;
  int hhId = 0;
  int visitId = 0;
  String healthTheme = null;
  Boolean largeTopicScreen = false;
  String[] themesArray;
  
  List<ImageView> imgView = null;
  List<ImageView> checkmark = null;
  
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        context = getApplicationContext();
        
    Bundle b = getIntent().getExtras();
    hhId = b.getInt("hhId");
    visitId = b.getInt("visitId");
    healthTheme = b.getString("healthTheme");
    themesArray = getResources().getStringArray(R.array.themes_array);
    
    // sloppy/hacky way of choosing whether the view is going to have 4 or 6 topics (disease and nutrition have 6, so largeTopicScreen == true)
    if (healthTheme.equals(themesArray[1]) || healthTheme.equals(themesArray[2])) {
      largeTopicScreen = true;
      setContentView(R.layout.activity_health_details_large);
    } else {
      setContentView(R.layout.activity_health_details_small);
    }
    
    // create UI elements
    setupTopicButtons(healthTheme);
    // grey out elements based on topic completion
    updateUIElements();
    }
    
    @Override
    public void onResume() {
      super.onResume();
      //Toast.makeText(getApplicationContext(),"onResume triggered",Toast.LENGTH_SHORT).show();
    updateUIElements();
    }
    
    public void openHealthDelivery(View v) {
      String topic = null;
        topic = (String) v.getTag();
      
      Intent i = new Intent(HealthDetailsActivity.this, HealthDeliveryActivity.class);
      Bundle b = new Bundle();
      b.putInt("hhId",hhId);
      b.putInt("visitId",visitId);
      b.putString("healthTheme",healthTheme);
      b.putString("topic",topic);
      i.putExtras(b);
      startActivity(i);  
    }
    
    public void setupTopicButtons(String healthTheme) {
    // set the topics based on the health theme that was passed into this activity
      // these get put in ArrayLists so that they can easily be referred in conditional statements without having to refer to the actual string values (which could change)
      List<TextView> topicTitle = new ArrayList<TextView>();
      topicTitle.add((TextView) findViewById(R.id.health_topic1_title_field));
      topicTitle.add((TextView) findViewById(R.id.health_topic2_title_field));
      topicTitle.add((TextView) findViewById(R.id.health_topic3_title_field));
      topicTitle.add((TextView) findViewById(R.id.health_topic4_title_field));
      
      List<View> divider = new ArrayList<View>();
      divider.add((View) findViewById(R.id.health_topic1_divider));
      divider.add((View) findViewById(R.id.health_topic2_divider));
      divider.add((View) findViewById(R.id.health_topic3_divider));
      divider.add((View) findViewById(R.id.health_topic4_divider));
      
      imgView = new ArrayList<ImageView>();
      imgView.add((ImageView) findViewById(R.id.health_topic1_button_img));
      imgView.add((ImageView) findViewById(R.id.health_topic2_button_img));
      imgView.add((ImageView) findViewById(R.id.health_topic3_button_img));
      imgView.add((ImageView) findViewById(R.id.health_topic4_button_img));
      
      checkmark = new ArrayList<ImageView>();
      checkmark.add((ImageView) findViewById(R.id.health_topic1_checkmark));
      checkmark.add((ImageView) findViewById(R.id.health_topic2_checkmark));
      checkmark.add((ImageView) findViewById(R.id.health_topic3_checkmark));
      checkmark.add((ImageView) findViewById(R.id.health_topic4_checkmark));
      
      List<ImageButton> imgBtn = new ArrayList<ImageButton>();
      imgBtn.add((ImageButton) findViewById(R.id.health_topic1_button));
      imgBtn.add((ImageButton) findViewById(R.id.health_topic2_button));
      imgBtn.add((ImageButton) findViewById(R.id.health_topic3_button));
      imgBtn.add((ImageButton) findViewById(R.id.health_topic4_button));
      
      // if we're using the large layout, we need the additional elements
      if (largeTopicScreen == true) {
        topicTitle.add((TextView) findViewById(R.id.health_topic5_title_field));
          topicTitle.add((TextView) findViewById(R.id.health_topic6_title_field));
          divider.add((View) findViewById(R.id.health_topic5_divider));
          divider.add((View) findViewById(R.id.health_topic6_divider));
          imgView.add((ImageView) findViewById(R.id.health_topic5_button_img));
          imgView.add((ImageView) findViewById(R.id.health_topic6_button_img));
          checkmark.add((ImageView) findViewById(R.id.health_topic5_checkmark));
          checkmark.add((ImageView) findViewById(R.id.health_topic6_checkmark));
          imgBtn.add((ImageButton) findViewById(R.id.health_topic5_button));
          imgBtn.add((ImageButton) findViewById(R.id.health_topic6_button));
      }
      
      List<HealthTopic> topicList = ModelHelper.getTopicsForThemeName(getHelper(), healthTheme);
    String color = ModelHelper.getThemeForName(getHelper(), healthTheme).getColor();
    int colorRef = Color.parseColor(color);
    int imageRef = 0;
      
      // setup up the drawable depending on the theme - TODO: maybe move the resource reference to the DB
    if (healthTheme.equals(themesArray[0])) {
      imageRef = R.drawable.hivgobutton;
    } else if (healthTheme.equals(themesArray[1])) {
      imageRef = R.drawable.childhooddiseasesgobutton;
    } else if (healthTheme.equals(themesArray[2])) {
      imageRef = R.drawable.nutritiongobutton;
    } else if (healthTheme.equals(themesArray[3])) {
      imageRef = R.drawable.developmentgobutton;
    } else {
      Log.e("Error, can't find drawable for theme: ",healthTheme);
    }
    
    for (int i = 0; i < topicList.size(); i++) {
      topicTitle.get(i).setTextColor(colorRef);
      divider.get(i).setBackgroundColor(colorRef);        
      topicTitle.get(i).setText(topicList.get(i).getName());
      
      int screenshotId = getResources().getIdentifier(topicList.get(i).getScreenshot(), "drawable", context.getPackageName());
      imgView.get(i).setImageResource(screenshotId);
      
      imgView.get(i).setTag(topicList.get(i).getName());
      imgBtn.get(i).setTag(topicList.get(i).getName());
      imgBtn.get(i).setImageResource(imageRef);
    }
    }

  // grey out the buttons that have already been accessed
    public void updateUIElements() {
    // pull all of the completed topics accessed for this household
    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 health topic that has been accessed by this household
    for (HealthTopicAccessed hta : topicsAccessed) {
      // for each button on this page
      // for (ImageView iv : imgView) {
      for (int i = 0; i < imgView.size(); i++) {
        // if the button's tag is the topic accessed (ie if this button should be greyed out)
        if (imgView.get(i).getTag().equals(hta.getTopicName())) {
          imgView.get(i).setAlpha(90);
          checkmark.get(i).setVisibility(View.VISIBLE);
          // imgBtn.get(i).setAlpha(90);
          // topicTitle.get(i).setTextColor(Color.argb(90, 255, 0, 0));
          // divider.get(i).setAlpha(90);
        }
      }      
    }
    }

}




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