Android Open Source - chat.android Select1 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;
/*  ww  w.  j  a  va 2  s . c o  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.HealthTheme;
import org.chat.android.models.PageSelect1;

import android.content.Context;
import android.graphics.Color;
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 Select1Fragment extends BaseFragment {
  Context context;
    TextView title = null;
    TextView content1 = null;
    RadioButton answer1 = null;
    RadioButton answer2 = null;
    RadioButton answer3 = null;
    RadioButton answer4 = null;
  
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_select1, container, false);
      context = getActivity();
      
    title = (TextView) view.findViewById(R.id.s1title);
    content1 = (TextView) view.findViewById(R.id.s1content1);
    answer1 = (RadioButton) view.findViewById(R.id.s1rb1);
    answer2 = (RadioButton) view.findViewById(R.id.s1rb2);
    answer3 = (RadioButton) view.findViewById(R.id.s1rb3);
    answer4 = (RadioButton) view.findViewById(R.id.s1rb4);
    
    // determine language from current tablet settings
    String lang = Locale.getDefault().getLanguage();
    
    int visitId = getArguments().getInt("visitId");
    String themeName = getArguments().getString("themeName");
    String topicName = getArguments().getString("topicName");
    int id = getArguments().getInt("id");
        
      populateDisplayedFragment(themeName, topicName, id, lang);
      populateClickedRadio(view, visitId, topicName);
      
      return view;
    }
    
  public void populateDisplayedFragment(String themeName, String topicName, int pageContentId, String lang) {
    // question
    PageSelect1 ps = ModelHelper.getPageSelect1ForId(getHelper(), pageContentId);
    content1.setText(ps.getContent(lang, "content1"));
    
    // responses/selects
    List<HealthSelect> selects = new ArrayList<HealthSelect>();
    selects = ModelHelper.getSelectsForSubjectId(getHelper(), ps.getId());
    if (selects.size() == 4) {
      // set up the radio buttons, tagged with ID (to be used when saving) - TODO: make me work with Zulu (in the model)
      answer1.setText(selects.get(0).getContent(lang));
      answer1.setTag(selects.get(0).getId());
      answer2.setText(selects.get(1).getContent(lang));
      answer2.setTag(selects.get(1).getId());
      answer3.setText(selects.get(2).getContent(lang));
      answer3.setTag(selects.get(2).getId());
      answer4.setText(selects.get(3).getContent(lang));
      answer4.setTag(selects.get(3).getId());
    }
    
    // colors
    HealthTheme theme = ModelHelper.getThemeForName(getHelper(), themeName);
    int colorRef = Color.parseColor(theme.getColor());
    title.setTextColor(colorRef);
    }
  
  
  
  // NOTE THIS SHOULDNT WORK - WILL RETURN MULTIPLE IDS, SEE BELOW
  // if the user has navigated back/forward to this page after previously having selected a radio
  public void populateClickedRadio(View view, int visitId, String topicName) {
    HealthSelectRecorded hsr = ModelHelper.getHealthSelectRecordedForVisitIdAndTopicName(getHelper(), visitId, topicName);
    if (hsr != null) {
      int selectId = hsr.getSelectId();
      HealthSelect hs = ModelHelper.getHealthSelectForId(getHelper(), selectId);
      int radioId = hs.getId();
      RadioButton rb = (RadioButton)view.findViewWithTag(radioId);
      rb.setChecked(true);
    }
  }
  
//  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.getHealthSelectRecordedsForVisitIdAndTopicNameAndSelectId(context, visitId, "assessment", selectId);
//        // 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);
//    }
//  }
  
  
  
  
  
}




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