Android Open Source - chat.android Assessment1 Fragment






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.pages;
// w w  w.  j  av  a  2s .  co  m
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import org.chat.android.ModelHelper;
import org.chat.android.R;
import org.chat.android.models.HealthSelect;
import org.chat.android.models.HealthSelectRecorded;
import org.chat.android.models.PageAssessment1;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RadioButton;
import android.widget.TextView;

public class Assessment1Fragment extends BaseFragment {
  Context context;
  int clientId = 0;
  
    TextView title = null;
    TextView content1 = null;
    TextView content2 = null;
    TextView content3 = null;
    RadioButton answer1_1 = null;
    RadioButton answer1_2 = null;
    RadioButton answer2_1 = null;
    RadioButton answer2_2 = null;
    RadioButton answer3_1 = null;
    RadioButton answer3_2 = null;
    List<HealthSelect> selects = null;
  
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_assessment1, container, false);
      context = getActivity();
      
    title = (TextView) view.findViewById(R.id.a1title);
    content1 = (TextView) view.findViewById(R.id.a1content1);
    content2 = (TextView) view.findViewById(R.id.a1content2);
    content3 = (TextView) view.findViewById(R.id.a1content3);
    List<RadioButton> rbList = new ArrayList<RadioButton>();
    answer1_1 = (RadioButton) view.findViewById(R.id.a1rb1_1);
    rbList.add(answer1_1);
    answer1_2 = (RadioButton) view.findViewById(R.id.a1rb1_2);
    rbList.add(answer1_2);
    answer2_1 = (RadioButton) view.findViewById(R.id.a1rb2_1);
    rbList.add(answer2_1);
    answer2_2 = (RadioButton) view.findViewById(R.id.a1rb2_2);
    rbList.add(answer2_2);
    answer3_1 = (RadioButton) view.findViewById(R.id.a1rb3_1);
    rbList.add(answer3_1);
    answer3_2 = (RadioButton) view.findViewById(R.id.a1rb3_2);
    rbList.add(answer3_2);
    
    // determine language from current tablet settings
    String lang = Locale.getDefault().getLanguage();
    
    int visitId = getArguments().getInt("visitId");
    clientId = getArguments().getInt("clientId");
    int pageContentId = getArguments().getInt("id");
    
    selects = new ArrayList<HealthSelect>();
    selects = ModelHelper.getSelectsForSubjectId(getHelper(), pageContentId);
        
    populateDisplayedFragment(pageContentId, lang);
      populateClickedRadio(view, visitId, rbList);
      
      return view;
    }
    
    public void populateDisplayedFragment(int pageContentId, String lang) {
      PageAssessment1 pa1 = ModelHelper.getPageAssessment1ForId(getHelper(), pageContentId);
      
      // title
      title.setText(pa1.getType());
      
    // question
    content1.setText(pa1.getContent(lang, "content1"));

    // set up the radio buttons, tagged with ID (to be used when saving)
    if (selects.size() > 0) {
      answer1_1.setVisibility(View.VISIBLE);            // just need these until all the data is populated
      answer1_1.setText(selects.get(0).getContent(lang));
      answer1_1.setTag(selects.get(0).getId());
      answer1_2.setVisibility(View.VISIBLE);
      answer1_2.setText(selects.get(1).getContent(lang));
      answer1_2.setTag(selects.get(1).getId());
    }
    
    if (selects.size() > 2) {
      content2.setText(pa1.getContent(lang, "content2"));
      answer2_1.setText(selects.get(2).getContent(lang));
      answer2_1.setTag(selects.get(2).getId());
      answer2_2.setText(selects.get(3).getContent(lang));
      answer2_2.setTag(selects.get(3).getId());
    }
    
    if (selects.size() > 4) {
      content3.setText(pa1.getContent(lang, "content3"));
      answer3_1.setText(selects.get(4).getContent(lang));
      answer3_1.setTag(selects.get(4).getId());
      answer3_2.setText(selects.get(5).getContent(lang));
      answer3_2.setTag(selects.get(5).getId());
    }

    }
  
  // if the user has navigated back/forward to this page after previously having selected a radio
  public void populateClickedRadio(View view, int visitId, List<RadioButton> rbList) {
    // for each select element on the page
    for (RadioButton rb : rbList) {
      // possibly excessive checks to avoid nullpointerexceptions
      if (rb != null && rb.getTag() != null) {
        int selectId = (Integer) rb.getTag();
        // get the recorded select
        HealthSelectRecorded hsr = ModelHelper.getHealthSelectRecordedsForVisitIdAndTopicNameAndSelectIdAndClientId(getHelper(), visitId, "assessment", selectId, clientId);
        // if it exists, check it
        if (hsr != null) {
          rb.setChecked(true);
        }
      }
      
    }
    // if there is a second set of selects, and yes/first select is checked
    if (selects.size() > 2 && answer1_1.isChecked()) {
      content2.setVisibility(View.VISIBLE);
      answer2_1.setVisibility(View.VISIBLE);
      answer2_2.setVisibility(View.VISIBLE);
    }
    // if there is a second set of selects, and yes/first select is checked
    if (selects.size() > 4 && answer1_1.isChecked()) {
      content3.setVisibility(View.VISIBLE);
      answer3_1.setVisibility(View.VISIBLE);
      answer3_2.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