Android Open Source - clinicalguide Stat Screen Fragment






From Project

Back to project page clinicalguide.

License

The source code is released under:

Apache License

If you think the Android project clinicalguide 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.get.oxicam.clinicalguide.ui;
//from  w ww  . ja  v a 2 s .c om
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Set;

import org.get.oxicam.clinicalguide.ClinicalGuideActivity;
import org.get.oxicam.clinicalguide.R;
import org.get.oxicam.clinicalguide.xml.CGStatsParser;

import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.SimpleAdapter;
import android.widget.SimpleAdapter.ViewBinder;
import android.widget.Spinner;
import android.widget.TextView;

public class StatScreenFragment extends ListFragment {  
    
    private ClinicalGuideActivity mActivity;
    private SimpleAdapter mAdapter;
    private ArrayList<ViewGroup> statResults;
    
    /**
     * Initializes the FormscreenFragment.
     */
    @Override
    public void onActivityCreated(Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        
        mActivity = (ClinicalGuideActivity)getActivity();
        mActivity.setTitle("General Statistics");
    
        // add some dummy data to the list view
        //ArrayList<StatscreenListItem> items = new ArrayList<StatscreenListItem>();
        //items.add(new StatscreenListItem(R.drawable.alerts_and_states_warning, R.string.statscreen_item1_title, R.string.statscreen_item1_description));
        
        ArrayList<ArrayList<String>> items = new ArrayList<ArrayList<String>>();
        ArrayList<String> statsNames = new ArrayList<String>();
        statResults = new ArrayList<ViewGroup>();
        final ArrayList<String> statsIds = new ArrayList<String>();
        final CGStatsParser statsParser = mActivity.getStatsParser();
        HashMap<String, String> map = statsParser.getStatsNamesAndIds();
        Set<String> keySet = map.keySet();
        for(String s : keySet){
            statsIds.add(s);
            statsNames.add(map.get(s));
        }
        items.add(statsNames);
        
        
        ViewGroup viewGroupFooter = new RelativeLayout(mActivity);
        Button button = new Button(mActivity);
        button.setText("Get Statistics");
        button.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Spinner s = (Spinner)mActivity.findViewById(R.id.spinner1);
                String result = statsParser.populateStats(statsIds.get(s.getSelectedItemPosition()));
                Log.v("Stat result", result);
                
                final ViewGroup resultGroup = new RelativeLayout(mActivity);
                Button remove = new Button(mActivity);
                remove.setText("x");
                remove.setId(1);
                remove.setOnClickListener(new View.OnClickListener() {
          
          @Override
          public void onClick(View v) {
            // TODO Auto-generated method stub
            getListView().removeFooterView(resultGroup);
            statResults.remove(resultGroup);
            
          }
        });
                
                resultGroup.addView(remove);
                RelativeLayout.LayoutParams removeFooter = (RelativeLayout.LayoutParams) remove
                        .getLayoutParams();
                
                removeFooter.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
                remove.setLayoutParams(removeFooter);
                
                
                TextView tv = new TextView(mActivity);
                tv.setText(result);
                resultGroup.addView(tv);
                removeFooter = (RelativeLayout.LayoutParams) tv
                        .getLayoutParams();
                removeFooter.addRule(RelativeLayout.LEFT_OF, 1);
                removeFooter.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
                tv.setLayoutParams(removeFooter);
                
                statResults.add(resultGroup);
                getListView().addFooterView(resultGroup);
                
               
            }
        });
        viewGroupFooter.addView(button);
        RelativeLayout.LayoutParams paramsFooter = (RelativeLayout.LayoutParams) button
            .getLayoutParams();
        paramsFooter.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
        paramsFooter.setMargins(0, 50, 0, 0);
        button.setLayoutParams(paramsFooter);
        
        Button clearAll = new Button (mActivity);
        clearAll.setText("Clear All");
        clearAll.setOnClickListener(new View.OnClickListener() {
      
      @Override
      public void onClick(View v) {
        // TODO Auto-generated method stub
        for(ViewGroup vg: statResults){
          getListView().removeFooterView(vg);
        }
        
      }
    });
        
        viewGroupFooter.addView(clearAll);
        RelativeLayout.LayoutParams clearFooter = (RelativeLayout.LayoutParams) clearAll
                .getLayoutParams();
        clearFooter.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
        clearFooter.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
        
        clearAll.setLayoutParams(clearFooter);
        getListView().addFooterView(viewGroupFooter);
        
        populateList(items);
    }
    
    private void populateList(ArrayList<ArrayList<String>> items) {
        // populate a HashMap with all list items
     // populate a HashMap with all list items
        ArrayList<HashMap<String, Object>> itemData = new ArrayList<HashMap<String, Object>>();
        for(ArrayList<String> item : items) {
            HashMap<String, Object> map = new HashMap<String, Object>();
            map.put("texts", item);
            itemData.add(map);  
        }
        
        // Specify source tag to corresponding target ID mapping
        String[] sourceTags = {
                "texts"
        };
        int[] targetIds = {
            R.id.spinner1
        };
        
        // create the ListAdapter
        mAdapter = new SimpleAdapter(getActivity(), itemData, R.layout.statscreen_list_item, sourceTags, targetIds);
        mAdapter.setViewBinder(new FormscreenBinder());
        setListAdapter(mAdapter);
    }
    
    
    class FormscreenBinder implements ViewBinder {

        @Override
        public boolean setViewValue(View view, Object data, String textRepresentation) {
            if(view.getId() == R.id.spinner1){
                
                Spinner s = (Spinner)view;
                s.setPrompt("Select a statistics");
                ArrayAdapter<String> arrAdap = new ArrayAdapter<String>(mActivity, R.layout.spinner_layout, (ArrayList<String>)data);
                arrAdap.setDropDownViewResource(R.layout.spinner_layout);
                s.setAdapter(arrAdap);
                
                return true;    
            }
            
            return false;
        }
    }
    
    
    
    
}




Java Source Code List

.PatientDetailsDataSource.java
org.get.oxicam.clinicalguide.ClinicalGuideActivity.java
org.get.oxicam.clinicalguide.FileUtils.java
org.get.oxicam.clinicalguide.LoginActivity.java
org.get.oxicam.clinicalguide.db.DatabaseHelper.java
org.get.oxicam.clinicalguide.db.Database.java
org.get.oxicam.clinicalguide.db.FollowupDataSource.java
org.get.oxicam.clinicalguide.db.FollowupDetails.java
org.get.oxicam.clinicalguide.db.FollowupSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetailsDataSource.java
org.get.oxicam.clinicalguide.db.HistoryDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.HistoryDetails.java
org.get.oxicam.clinicalguide.db.PatientDetailsSQLHelper.java
org.get.oxicam.clinicalguide.db.PatientDetails.java
org.get.oxicam.clinicalguide.db.RegistrationValidator.java
org.get.oxicam.clinicalguide.db.Validator.java
org.get.oxicam.clinicalguide.encryption.Encryption.java
org.get.oxicam.clinicalguide.ui.AnswersReviewFragment.java
org.get.oxicam.clinicalguide.ui.AssessmentDetailFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationFragment.java
org.get.oxicam.clinicalguide.ui.ClassificationListItem.java
org.get.oxicam.clinicalguide.ui.DatePickerFragment.java
org.get.oxicam.clinicalguide.ui.ExportFragment.java
org.get.oxicam.clinicalguide.ui.ExportscreenListItem.java
org.get.oxicam.clinicalguide.ui.FollowUpFragment.java
org.get.oxicam.clinicalguide.ui.FormScreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenFragment.java
org.get.oxicam.clinicalguide.ui.HomescreenListItem.java
org.get.oxicam.clinicalguide.ui.ListItemOnClickListener.java
org.get.oxicam.clinicalguide.ui.MainSymptomFragment.java
org.get.oxicam.clinicalguide.ui.MainSymptomListItem.java
org.get.oxicam.clinicalguide.ui.NumberTickerValueChangeListener.java
org.get.oxicam.clinicalguide.ui.NumberTicker.java
org.get.oxicam.clinicalguide.ui.PatientDetailsFragment.java
org.get.oxicam.clinicalguide.ui.PatientHistoryFragment.java
org.get.oxicam.clinicalguide.ui.PatientsFragment.java
org.get.oxicam.clinicalguide.ui.QuestionListItem.java
org.get.oxicam.clinicalguide.ui.QuestionnaireFragment.java
org.get.oxicam.clinicalguide.ui.StatScreenFragment.java
org.get.oxicam.clinicalguide.ui.SummaryScreenFragment.java
org.get.oxicam.clinicalguide.ui.TextViewCustomFont.java
org.get.oxicam.clinicalguide.ui.TreatmentConfirmationDialog.java
org.get.oxicam.clinicalguide.ui.TreatmentFragment.java
org.get.oxicam.clinicalguide.ui.TreatmentListItem.java
org.get.oxicam.clinicalguide.ui.ViewDetailScreenFragment.java
org.get.oxicam.clinicalguide.xml.CGFormParser.java
org.get.oxicam.clinicalguide.xml.CGParser.java
org.get.oxicam.clinicalguide.xml.CGStatsParser.java
org.get.oxicam.clinicalguide.xml.DateHelper.java
org.get.oxicam.clinicalguide.xml.FormGenerator.java
org.get.oxicam.clinicalguide.xml.ParserHelper.java
org.get.oxicam.clinicalguide.xml.StatsGenerator.java
org.get.oxicam.clinicalguide.xml.XMLHandler.java
org.get.oxicam.clinicalguide.xml.data.AbstractAnswer.java
org.get.oxicam.clinicalguide.xml.data.Annotation.java
org.get.oxicam.clinicalguide.xml.data.AnswerValidator.java
org.get.oxicam.clinicalguide.xml.data.Answer.java
org.get.oxicam.clinicalguide.xml.data.Assessment.java
org.get.oxicam.clinicalguide.xml.data.CombinedAnswer.java
org.get.oxicam.clinicalguide.xml.data.FollowUp.java
org.get.oxicam.clinicalguide.xml.data.FormQuery.java
org.get.oxicam.clinicalguide.xml.data.Info.java
org.get.oxicam.clinicalguide.xml.data.Option.java
org.get.oxicam.clinicalguide.xml.data.PatientAttribute.java
org.get.oxicam.clinicalguide.xml.data.Question.java
org.get.oxicam.clinicalguide.xml.data.Questionnaire.java
org.get.oxicam.clinicalguide.xml.data.SimpleAnswer.java
org.get.oxicam.clinicalguide.xml.data.Symptom.java
org.get.oxicam.clinicalguide.xml.data.TreatmentAction.java
org.get.oxicam.clinicalguide.xml.data.Treatment.java
org.get.oxicam.clinicalguide.xml.data.User.java
org.get.oxicam.clinicalguide.xml.forms.FormCell.java
org.get.oxicam.clinicalguide.xml.forms.FormColumn.java
org.get.oxicam.clinicalguide.xml.forms.FormDuration.java
org.get.oxicam.clinicalguide.xml.forms.Form.java
org.get.oxicam.clinicalguide.xml.query.QueryHelper.java
org.get.oxicam.clinicalguide.xml.query.QueryResultCell.java
org.get.oxicam.clinicalguide.xml.query.QueryResultRow.java
org.get.oxicam.clinicalguide.xml.query.QueryResultTable.java
org.get.oxicam.clinicalguide.xml.stats.AbstractStatsQuestion.java
org.get.oxicam.clinicalguide.xml.stats.StatsAnswerHolder.java
org.get.oxicam.clinicalguide.xml.stats.StatsColumnCompare.java
org.get.oxicam.clinicalguide.xml.stats.StatsComparatorOperator.java
org.get.oxicam.clinicalguide.xml.stats.StatsCompareConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsConstraint.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionAverage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionCount.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionExtrema.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionFactory.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionList.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionPercentage.java
org.get.oxicam.clinicalguide.xml.stats.StatsQuestionRatio.java
org.get.oxicam.clinicalguide.xml.stats.StatsSubject.java
org.get.oxicam.clinicalguide.xml.stats.StatsTimespan.java
org.get.oxicam.clinicalguide.xml.stats.Stats.java