Android Open Source - SNISI-droid Nutrition Weekly Report






From Project

Back to project page SNISI-droid.

License

The source code is released under:

Apache License

If you think the Android project SNISI-droid 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 com.yeleman.nutrition;
//from   w w w .  j av a2s  .c  o m
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yeleman.snisidroid.CheckedFormActivity;
import com.yeleman.snisidroid.Constants;
import com.yeleman.snisidroid.R;

public class NutritionWeeklyReport extends CheckedFormActivity {

    private final static String TAG = Constants.getLogTag("NutritionWeeklyReport");

    private boolean is_urenam, is_urenas, is_ureni;

    protected TextView urenamLabel, urenasLabel, ureniLabel;

    protected EditText mamScreeningField;
    protected EditText samScreeningField;
    protected EditText samcScreeningField;

    protected EditText mamCasesField;
    protected EditText mamDeathsField;

    protected EditText samCasesField;
    protected EditText samDeathsField;

    protected EditText samcCasesField;
    protected EditText samcDeathsField;

    protected Button saveAndSubmitButton;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.nutrition_weekly_report);
        setTitle(String.format(getString(R.string.sub_app_name_nut),
                               getString(R.string.nutrition_weekly_report_label)));
        Log.d(TAG, "onCreate NutritionWeeklyReport");

        setupSMSReceiver();
        setupUI();
    }

    protected void setupUI() {
        Log.d(TAG, "setupUI NutritionWeeklyReport");
        SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(this);
        is_urenam = sharedPrefs.getBoolean("hc_is_urenam", false);
        is_urenas = sharedPrefs.getBoolean("hc_is_urenas", false);
        is_ureni = sharedPrefs.getBoolean("hc_is_ureni", false);

        mamScreeningField = (EditText) findViewById(R.id.screeningURENAMField);
        mamCasesField = (EditText) findViewById(R.id.casesURENAMField);
        mamDeathsField = (EditText) findViewById(R.id.deathsURENAMField);
        samScreeningField = (EditText) findViewById(R.id.screeningURENASField);
        samCasesField = (EditText) findViewById(R.id.casesURENASField);
        samDeathsField = (EditText) findViewById(R.id.deathsURENASField);
        samcScreeningField = (EditText) findViewById(R.id.screeningURENIField);
        samcCasesField = (EditText) findViewById(R.id.casesURENIField);
        samcDeathsField = (EditText) findViewById(R.id.deathsURENIField);

        if (!is_urenam) {
            LinearLayout linearLayoutURENAM = (LinearLayout) findViewById(R.id.linearLayoutURENAM);
            linearLayoutURENAM.setVisibility(View.GONE);
        }
        if (!is_urenas) {
            LinearLayout linearLayoutURENAS = (LinearLayout) findViewById(R.id.linearLayoutURENAS);
            linearLayoutURENAS.setVisibility(View.GONE);
        }
        if (!is_ureni) {
            LinearLayout linearLayoutURENI = (LinearLayout) findViewById(R.id.linearLayoutURENI);
            linearLayoutURENI.setVisibility(View.GONE);
        }

        // setup invalid inputs checks
        setupInvalidInputChecks();

        final CheckedFormActivity activity = this;
        saveAndSubmitButton = (Button) findViewById(R.id.saveAndSubmitButton);
        saveAndSubmitButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
              // ensure data is OK
                if (!checkInputsAndCoherence()) { return; }

                // save data to DB
                storeReportData();

                // transmit SMS
                requestPasswordAndTransmitSMS(activity, NutritionWeeklyReportData.get().getName(),
                                              Constants.SMS_KEYWORD_NUT_WEEKLY, buildSMSText());
            }
        });

        Log.d(TAG, "requestForResumeReport NutritionWeeklyReport");
        requestForResumeReport(this, NutritionWeeklyReportData.get());
    }

    protected void storeReportData() {
        Log.d(TAG, "storeReportData");
      NutritionWeeklyReportData report = NutritionWeeklyReportData.get();
      report.updateMetaData();

      if (is_urenam) {
        report.mam_screening = integerFromField(mamScreeningField);
        report.mam_cases = integerFromField(mamCasesField);
        report.mam_deaths = integerFromField(mamDeathsField);
      }

      if (is_urenas) {
        report.sam_screening = integerFromField(samScreeningField);
        report.sam_cases = integerFromField(samCasesField);
        report.sam_deaths = integerFromField(samDeathsField);
      }

      if (is_ureni) {
        report.samc_screening = integerFromField(samcScreeningField);
        report.samc_cases = integerFromField(samcCasesField);
        report.samc_deaths = integerFromField(samcDeathsField);
      }
      report.safeSave();
        Log.d(TAG, "storeReportData -- end");
    }

    protected void restoreReportData() {
        Log.d(TAG, "restoreReportData");
    NutritionWeeklyReportData report = NutritionWeeklyReportData.get();

    if (is_urenam) {
        setTextOnField(mamScreeningField, report.mam_screening);
        setTextOnField(mamCasesField, report.mam_cases);
        setTextOnField(mamDeathsField, report.mam_deaths);
      }

      if (is_urenas) {
        setTextOnField(samScreeningField, report.sam_screening);
        setTextOnField(samCasesField, report.sam_cases);
        setTextOnField(samDeathsField, report.sam_deaths);
      }

      if (is_ureni) {
        setTextOnField(samcScreeningField, report.samc_screening);
        setTextOnField(samcCasesField, report.samc_cases);
        setTextOnField(samcDeathsField, report.samc_deaths);
      }
    }

    protected void setupInvalidInputChecks() {
        if (is_urenam) {
            setAssertPositiveInteger(mamScreeningField);
            setAssertPositiveInteger(mamCasesField);
            setAssertPositiveInteger(mamDeathsField);
        }

        if (is_urenas) {
            setAssertPositiveInteger(samScreeningField);
            setAssertPositiveInteger(samCasesField);
            setAssertPositiveInteger(samDeathsField);
        }

        if (is_ureni) {
            setAssertPositiveInteger(samcScreeningField);
            setAssertPositiveInteger(samcCasesField);
            setAssertPositiveInteger(samcDeathsField);
        }
    }

    protected boolean ensureDataCoherence() {
        boolean urenam_checks, urenas_checks, ureni_checks;

        if (is_urenam) {
            urenam_checks = mustBeInferiorOrEqual(mamCasesField, mamCasesField, mamScreeningField) &&
                            mustBeInferiorOrEqual(mamDeathsField, mamDeathsField, mamCasesField);
        } else { urenam_checks = true; }

        if (is_urenas) {
            urenas_checks = mustBeInferiorOrEqual(samCasesField, samCasesField, samScreeningField) &&
                            mustBeInferiorOrEqual(samDeathsField, samDeathsField, samCasesField);
        } else { urenas_checks = true; }

        if (is_ureni) {
            ureni_checks = mustBeInferiorOrEqual(samcCasesField, samcCasesField, samcScreeningField) &&
                           mustBeInferiorOrEqual(samcDeathsField, samcDeathsField, samcCasesField);
        } else { ureni_checks = true; }

        return urenam_checks && urenas_checks && ureni_checks;
    }

    protected String buildSMSText() {
        NutritionWeeklyReportData report = NutritionWeeklyReportData.get();
        return report.buildSMSText();
    }
}




Java Source Code List

com.yeleman.nutrition.NutritionHome.java
com.yeleman.nutrition.NutritionInputsReportData.java
com.yeleman.nutrition.NutritionInputsReport.java
com.yeleman.nutrition.NutritionMonthlyHome.java
com.yeleman.nutrition.NutritionMonthlyReportData.java
com.yeleman.nutrition.NutritionSummaryReport.java
com.yeleman.nutrition.NutritionURENAMExsamReport.java
com.yeleman.nutrition.NutritionURENAMO59Report.java
com.yeleman.nutrition.NutritionURENAMPWReport.java
com.yeleman.nutrition.NutritionURENAMReportData.java
com.yeleman.nutrition.NutritionURENAMReport.java
com.yeleman.nutrition.NutritionURENAMU23O6Report.java
com.yeleman.nutrition.NutritionURENAMU59O23Report.java
com.yeleman.nutrition.NutritionURENASO59Report.java
com.yeleman.nutrition.NutritionURENASReportData.java
com.yeleman.nutrition.NutritionURENASReport.java
com.yeleman.nutrition.NutritionURENASU59O6Report.java
com.yeleman.nutrition.NutritionURENFormIface.java
com.yeleman.nutrition.NutritionURENForm.java
com.yeleman.nutrition.NutritionURENIO59Report.java
com.yeleman.nutrition.NutritionURENIReportData.java
com.yeleman.nutrition.NutritionURENIReport.java
com.yeleman.nutrition.NutritionURENIU59O6Report.java
com.yeleman.nutrition.NutritionURENIU6Report.java
com.yeleman.nutrition.NutritionWeeklyReportData.java
com.yeleman.nutrition.NutritionWeeklyReport.java
com.yeleman.projetsnisi.ApplicationTest.java
com.yeleman.smir.Constants.java
com.yeleman.smir.CustomOnItemSelectedListener.java
com.yeleman.smir.SMIRAlert.java
com.yeleman.smir.SMIRHome.java
com.yeleman.smir.SharedChecks.java
com.yeleman.snisidroid.ChangePassword.java
com.yeleman.snisidroid.CheckedFormActivity.java
com.yeleman.snisidroid.Constants.java
com.yeleman.snisidroid.Popups.java
com.yeleman.snisidroid.Preferences.java
com.yeleman.snisidroid.ReportData.java
com.yeleman.snisidroid.SMSDeliveredReceiver.java
com.yeleman.snisidroid.SMSReceiver.java
com.yeleman.snisidroid.SMSSentReceiver.java
com.yeleman.snisidroid.SMSUpdater.java
com.yeleman.snisidroid.SNISIAbout.java
com.yeleman.snisidroid.SNISIApp.java
com.yeleman.snisidroid.SNISIHome.java
com.yeleman.snisidroid.SharedChecks.java