Android Open Source - camp-food-manager Menu Fragment






From Project

Back to project page camp-food-manager.

License

The source code is released under:

GNU General Public License

If you think the Android project camp-food-manager 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.V4Creations.FSMK.campfoodmanager.fragment;
//from   ww w .j av  a2  s.c  o  m
import java.util.Calendar;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;

import com.V4Creations.FSMK.campfoodmanager.R;
import com.V4Creations.FSMK.campfoodmanager.ui.CampFoodManagerMainActivity;
import com.V4Creations.FSMK.campfoodmanager.ui.PreferencesActivity;
import com.V4Creations.FSMK.campfoodmanager.util.Settings;
import com.actionbarsherlock.app.SherlockFragment;

public class MenuFragment extends SherlockFragment {
  String TAG = "MenuFragment";
  CampFoodManagerMainActivity activity;
  public static final int TYPE_BREAK_FAST = 0;
  public static final int TYPE_LUNCH = 1;
  public static final int TYPE_DINNER = 2;

  private Button mCsvButton, mSettingsButton, mContinueButton, mDeleteButton;
  private CheckBox mConfirmCheckBox;
  private Spinner mDateSpinner;
  private RadioGroup mRadioGroup;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {
    activity = (CampFoodManagerMainActivity) getActivity();
    return inflater.inflate(R.layout.menu_layout, null, false);
  }

  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    initView();
    initValues();
  }

  private void initValues() {
    initDate();
    initFoodTime();
    initListeners();
    mConfirmCheckBox.setChecked(Settings.isConfirmEachQRCode(activity));
  }

  private void initListeners() {
    mRadioGroup
        .setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(RadioGroup group, int checkedId) {
            activity.reFetchCount();
          }
        });
    mDateSpinner
        .setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

          @Override
          public void onItemSelected(AdapterView<?> arg0, View arg1,
              int arg2, long arg3) {
            activity.reFetchCount();
          }

          @Override
          public void onNothingSelected(AdapterView<?> arg0) {
          }
        });
    mCsvButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        activity.generatCSV();
      }
    });
    mSettingsButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        Intent settingsActivity = new Intent(activity,
            PreferencesActivity.class);
        startActivityForResult(settingsActivity, 0);
      }
    });
    mContinueButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        activity.toggle();
      }
    });
    mDeleteButton.setOnClickListener(new View.OnClickListener() {

      @Override
      public void onClick(View v) {
        showLastScanDeleteDialog();
      }
    });
    mConfirmCheckBox
        .setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {

          @Override
          public void onCheckedChanged(CompoundButton buttonView,
              boolean isChecked) {
            Settings.setConfirmEachQRCode(activity, isChecked);
          }
        });
  }

  protected void showLastScanDeleteDialog() {
    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
    builder.setMessage(R.string.do_you_want_to_delete_your_last_scan)
        .setCancelable(false)
        .setPositiveButton(android.R.string.yes,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                activity.deleteLastScanFoodItem();
              }
            })
        .setNegativeButton(android.R.string.no,
            new DialogInterface.OnClickListener() {
              public void onClick(DialogInterface dialog, int id) {
                dialog.cancel();
              }
            });
    AlertDialog alert = builder.create();
    alert.setTitle(R.string.delete_last_scan);
    alert.setIcon(R.drawable.ic_action_delete_light);
    alert.show();
  }

  private void initFoodTime() {
    int hourOfDay = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
    if (hourOfDay < 11) {
      RadioButton breakfastRadioButton = (RadioButton) getView()
          .findViewById(R.id.breakFastRadioButton);
      breakfastRadioButton.setChecked(true);
    } else if (hourOfDay < 17) {
      RadioButton lunchRadioButton = (RadioButton) getView()
          .findViewById(R.id.lunchRadioButton);
      lunchRadioButton.setChecked(true);
    } else {
      RadioButton dinnerRadioButton = (RadioButton) getView()
          .findViewById(R.id.dinnerRadioButton);
      dinnerRadioButton.setChecked(true);
    }
  }

  private void initDate() {
    int dayOfMonth = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);
    int index = dayOfMonth - 19;
    if (index < 0)
      index = 0;
    mDateSpinner.setSelection(index);
  }

  private void initView() {
    mCsvButton = (Button) getView().findViewById(R.id.csvButton);
    mSettingsButton = (Button) getView().findViewById(R.id.settingsButton);
    mContinueButton = (Button) getView().findViewById(R.id.continueButton);
    mDeleteButton = (Button) getView().findViewById(R.id.deleteButton);
    mConfirmCheckBox = (CheckBox) getView().findViewById(
        R.id.confirmCheckBox);
    mDateSpinner = (Spinner) getView().findViewById(R.id.dateSpinner);
    mRadioGroup = (RadioGroup) getView().findViewById(
        R.id.foodTimeRadioGroup);
  }

  public String getSelectedDate() {
    return (String) mDateSpinner.getSelectedItem();
  }

  public int getFoodType() {
    int id = mRadioGroup.getCheckedRadioButtonId();
    RadioButton radioButton = (RadioButton) getView().findViewById(id);
    return getTypeFromString(radioButton.getText().toString());
  }

  private int getTypeFromString(String string) {
    if (string.equals(getString(R.string.break_fast)))
      return TYPE_BREAK_FAST;
    else if (string.equals(getString(R.string.lunch)))
      return TYPE_LUNCH;
    else
      return TYPE_DINNER;
  }

  public boolean isConfirmEachQRCode() {
    return mConfirmCheckBox.isChecked();
  }
}




Java Source Code List

com.V4Creations.FSMK.campfoodmanager.adapter.ResultListViewAdapter.java
com.V4Creations.FSMK.campfoodmanager.db.CampFoodManagerDataBase.java
com.V4Creations.FSMK.campfoodmanager.db.DatabaseHelper.java
com.V4Creations.FSMK.campfoodmanager.db.GetAllStudensDetailsHelperAsynzTask.java
com.V4Creations.FSMK.campfoodmanager.db.GetDetailsHelperAsynzTask.java
com.V4Creations.FSMK.campfoodmanager.flash.Constants.java
com.V4Creations.FSMK.campfoodmanager.flash.Droid22Flashlight.java
com.V4Creations.FSMK.campfoodmanager.flash.Flashlight.java
com.V4Creations.FSMK.campfoodmanager.flash.FroyoLedFlashlight.java
com.V4Creations.FSMK.campfoodmanager.flash.HtcLedFlashlight.java
com.V4Creations.FSMK.campfoodmanager.flash.LedFlashlightReceiver.java
com.V4Creations.FSMK.campfoodmanager.flash.Moto21LedFlashlight.java
com.V4Creations.FSMK.campfoodmanager.fragment.MenuFragment.java
com.V4Creations.FSMK.campfoodmanager.interfaces.GetFullStudentsDetailsInterface.java
com.V4Creations.FSMK.campfoodmanager.interfaces.GetSingleItemDetailsInterface.java
com.V4Creations.FSMK.campfoodmanager.ui.CampFoodManagerMainActivity.java
com.V4Creations.FSMK.campfoodmanager.ui.PreferencesActivity.java
com.V4Creations.FSMK.campfoodmanager.util.BaseActivity.java
com.V4Creations.FSMK.campfoodmanager.util.Settings.java
com.google.zxing.client.android.AmbientLightManager.java
com.google.zxing.client.android.BeepManager.java
com.google.zxing.client.android.CaptureActivityHandler.java
com.google.zxing.client.android.DecodeFormatManager.java
com.google.zxing.client.android.DecodeHandler.java
com.google.zxing.client.android.DecodeHintManager.java
com.google.zxing.client.android.DecodeThread.java
com.google.zxing.client.android.FinishListener.java
com.google.zxing.client.android.InactivityTimer.java
com.google.zxing.client.android.IntentSource.java
com.google.zxing.client.android.Intents.java
com.google.zxing.client.android.ViewfinderResultPointCallback.java
com.google.zxing.client.android.ViewfinderView.java
com.google.zxing.client.android.camera.AutoFocusManager.java
com.google.zxing.client.android.camera.CameraConfigurationManager.java
com.google.zxing.client.android.camera.CameraManager.java
com.google.zxing.client.android.camera.FrontLightMode.java
com.google.zxing.client.android.camera.PreviewCallback.java
com.google.zxing.client.android.camera.exposure.DefaultExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureInterface.java
com.google.zxing.client.android.camera.exposure.ExposureManager.java
com.google.zxing.client.android.camera.exposure.FroyoExposureInterface.java
com.google.zxing.client.android.camera.open.DefaultOpenCameraInterface.java
com.google.zxing.client.android.camera.open.GingerbreadOpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraInterface.java
com.google.zxing.client.android.camera.open.OpenCameraManager.java
com.google.zxing.client.android.common.PlatformSupportManager.java
com.google.zxing.client.android.common.executor.AsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.AsyncTaskExecManager.java
com.google.zxing.client.android.common.executor.DefaultAsyncTaskExecInterface.java
com.google.zxing.client.android.common.executor.HoneycombAsyncTaskExecInterface.java