Android Open Source - SNISI-droid Nutrition Monthly Home






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  a2 s  .c  o m
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
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 com.yeleman.snisidroid.CheckedFormActivity;
import com.yeleman.snisidroid.Constants;
import com.yeleman.snisidroid.Preferences;
import com.yeleman.snisidroid.R;

public class NutritionMonthlyHome extends CheckedFormActivity implements View.OnClickListener {

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

    private Button urenasReportButton;
    private Button ureniReportButton;
    private Button urenamReportButton;
    private Button inputsReportButton;
    private Button resumeReportButton;
    private Button saveAndSubmitButton;

    private boolean is_urenam, is_urenas, is_ureni;

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

        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);

        if (!is_urenam && !is_urenas && !is_ureni) {
            AlertDialog.Builder prefCheckBuilder = new AlertDialog.Builder(this);
            prefCheckBuilder.setCancelable(false);
            prefCheckBuilder.setTitle(
                    getString(R.string.nutrition_level_missing_title));
            prefCheckBuilder.setMessage(
                    getString(R.string.nutrition_level_missing_body));
            prefCheckBuilder.setIcon(R.drawable.ic_launcher);
            prefCheckBuilder.setPositiveButton(R.string.go_to_preferences,
                    new DialogInterface.OnClickListener() {
                        public void onClick(DialogInterface dialog, int which) {
                            // close the dialog (auto)
                            // close the nutrition activity
                            finish();
                            // go to preferences
                            Intent intent = new Intent(
                                    getApplicationContext(),
                                    Preferences.class);
                            startActivity(intent);
                        }
                    });
            AlertDialog prefCheckDialog = prefCheckBuilder.create();
            prefCheckDialog.show();
        } else {
            Log.d(TAG, "requestForResumeReport NutritionURENAMReportData");
            NutritionMonthlyReportData monthlyReport = NutritionMonthlyReportData.get();
            monthlyReport.updateUren(is_urenam, is_urenas, is_ureni);
            if (monthlyReport.atLeastOneIsComplete()) {
                requestForResumeReport(this, NutritionMonthlyReportData.get());
            }
            setupSMSReceiver();
            setupUI();
        }
    }

    @Override
    public void onResume() {
        super.onResume();
        setupUI();
    }

    protected void setupUI() {
        Log.d(TAG, "setupUI NutritionMonthlyHome");

        urenamReportButton = (Button) findViewById(R.id.monthlyURENAMButton);
        urenasReportButton = (Button) findViewById(R.id.monthlyURENASButton);
        ureniReportButton = (Button) findViewById(R.id.monthlyURENIButton);
        inputsReportButton = (Button) findViewById(R.id.monthlyInputsButton);
        resumeReportButton = (Button) findViewById(R.id.resumeReportButton);
        resumeReportButton.setEnabled(false);
        saveAndSubmitButton = (Button) findViewById(R.id.saveAndSubmitButton);
        saveAndSubmitButton.setEnabled(false);

        // URENAM
        if (is_urenam) {
            NutritionURENAMReportData urenamReport = NutritionURENAMReportData.get();
            urenamReportButton.setText(String.format(getString(R.string.nutrition_fillout_report),
                                                     getString(R.string.urenam)));
            Constants.updateButtonCompletion(urenamReportButton, urenamReport.isComplete());
            urenamReportButton.setOnClickListener(this);
        } else {
            urenamReportButton.setVisibility(View.GONE);
        }

        // URENAS
        if (is_urenas) {
            NutritionURENASReportData urenasReport = NutritionURENASReportData.get();
            urenasReportButton.setText(String.format(getString(R.string.nutrition_fillout_report),
                                                     getString(R.string.urenas)));
            Constants.updateButtonCompletion(urenasReportButton, urenasReport.isComplete());
            urenasReportButton.setOnClickListener(this);
        } else {
            urenasReportButton.setVisibility(View.GONE);
        }

        // URENI
        if (is_ureni) {
            NutritionURENIReportData ureniReport = NutritionURENIReportData.get();
            ureniReportButton.setText(String.format(getString(R.string.nutrition_fillout_report),
                                                    getString(R.string.ureni)));
            Constants.updateButtonCompletion(ureniReportButton, ureniReport.isComplete());
            ureniReportButton.setOnClickListener(this);
        } else{
            ureniReportButton.setVisibility(View.GONE);
        }
        // Resume Report
        resumeReportButton.setOnClickListener(this);

        // Stocks
        inputsReportButton.setText(String.format(getString(R.string.nutrition_fillout_report),
                getString(R.string.inputs)));
        NutritionInputsReportData inputsReport = NutritionInputsReportData.get();
        Constants.updateButtonCompletion(inputsReportButton, inputsReport.isComplete());
        inputsReportButton.setOnClickListener(this);

        // Submit Button
        final CheckedFormActivity activity = this;
        saveAndSubmitButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                // transmit SMS
                requestPasswordAndTransmitSMS(activity, NutritionMonthlyReportData.get().getName(),
                                              Constants.SMS_KEYWORD_NUT_MONTHLY, buildSMSText());
            }
        });

        // Update UREN levels
        NutritionMonthlyReportData monthlyReport = NutritionMonthlyReportData.get();
        monthlyReport.updateUren(is_urenam, is_urenas, is_ureni);
        if (monthlyReport.isComplete()) {
            resumeReportButton.setEnabled(true);
            saveAndSubmitButton.setEnabled(true);
        }
    }

    protected void resetReportData(){
        Log.i(TAG, "resetReportData");
        NutritionMonthlyReportData monthlyReport = NutritionMonthlyReportData.get();
        monthlyReport.resetReportData();
        monthlyReport.updateUren(is_urenam, is_urenas, is_ureni);
        setupUI();
    }

    public void onClick(View view) {
        Object activity = null;

        switch (view.getId()) {
            case R.id.monthlyURENAMButton:
                activity = NutritionURENAMReport.class;
                break;
            case R.id.monthlyURENASButton:
                activity = NutritionURENASReport.class;
                break;
            case R.id.monthlyURENIButton:
                activity = NutritionURENIReport.class;
                break;
            case R.id.monthlyInputsButton:
                activity = NutritionInputsReport.class;
                break;
            case R.id.resumeReportButton:
                activity = NutritionSummaryReport.class;
                break;
        }
        Intent intent = new Intent(
                getApplicationContext(),
                (Class<?>) activity);
        startActivity(intent);
    }

    protected String buildSMSText() {
        NutritionMonthlyReportData report = NutritionMonthlyReportData.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