Exemplo n.º 1
0
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.create_family_diet_chart);

    DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy", Locale.getDefault());
    Date date = new Date();
    mCurrentDate = dateFormat.format(date);
    mAlarm = "0";

    etDate = (EditText) findViewById(R.id.editTextDP);
    etTime = (EditText) findViewById(R.id.etFamilyDietTime);
    // etName = (EditText) findViewById(R.id.etFamilyDietName);
    etFamilyDietName = (Spinner) findViewById(R.id.spinnerFamilyDietName);

    etDescription = (EditText) findViewById(R.id.editFamilyDietDetails);

    cbAlarm = (CheckBox) findViewById(R.id.FamilyDiet_alarm);
    btnSave = (Button) findViewById(R.id.btnSave);

    etDate.setOnClickListener(this);
    etTime.setOnClickListener(this);

    cbAlarm.setOnClickListener(this);
    btnSave.setOnClickListener(this);

    Intent mActivityIntent = getIntent();
    mStrActivityID = mActivityIntent.getStringExtra(FTFLConstants.ACTIVITYID);

    if (mStrActivityID != null) {
      mActivityId = Long.parseLong(mStrActivityID);

      mActivityDataSource = new FamilyDietDataSource(this);
      mUpdateActivity = mActivityDataSource.updateActivityData(mActivityId);

      String mDate = mUpdateActivity.getDate();
      String mTime = mUpdateActivity.getTime();
      String mName = mUpdateActivity.getFamilyDietName();
      String mDescription = mUpdateActivity.getFamilyDietDetails();
      String mAlarm = mUpdateActivity.getAlarm();
      long mActivityAlarm = Long.parseLong(mAlarm);

      // set the value of database to the text field.
      etDate.setText(mDate);
      etTime.setText(mTime);
      etName.setText(mName);
      etDescription.setText(mDescription);
      if (mActivityAlarm == 1) {
        cbAlarm.setChecked(!cbAlarm.isChecked());
      }

      /*
       * change button name
       */
      btnSave.setText(getString(R.string.Update));
    }
    addItemsOnSpinner3();
    addListenerOnSpinnerItemSelection3();
  }
Exemplo n.º 2
0
  @Override
  public void onClick(View v) {
    Toast toast = null;
    switch (v.getId()) {
      case R.id.editTextDP:
        mYear = mCalendar.get(Calendar.YEAR);
        mMonth = mCalendar.get(Calendar.MONTH);
        mDay = mCalendar.get(Calendar.DAY_OF_MONTH);

        DatePickerDialog dialog = new DatePickerDialog(this, this, mYear, mMonth, mDay);
        dialog.show();
        break;

      case R.id.etFamilyDietTime:

        // Process to get Current Time
        mHour = mCalendar.get(Calendar.HOUR_OF_DAY);
        mMinute = mCalendar.get(Calendar.MINUTE);

        // Launch Time Picker Dialog
        TimePickerDialog tpd = new TimePickerDialog(this, this, mHour, mMinute, false);
        tpd.show();
        break;

      case R.id.btnSave:
        mDate = etDate.getText().toString();
        mTime = etTime.getText().toString();
        // mName = etName.getText().toString();
        mName = String.valueOf(etFamilyDietName.getSelectedItem());

        mDescription = etDescription.getText().toString();

        if (cbAlarm.isChecked()) {
          mAlarm = "1";
          Intent alarmIntent = new Intent(AlarmClock.ACTION_SET_ALARM);
          alarmIntent.putExtra(AlarmClock.EXTRA_MESSAGE, mDescription);
          alarmIntent.putExtra(AlarmClock.EXTRA_HOUR, mDbHour);
          alarmIntent.putExtra(AlarmClock.EXTRA_MINUTES, mDbMinute);
          alarmIntent.putExtra(AlarmClock.EXTRA_SKIP_UI, true);
          alarmIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
          startActivity(alarmIntent);
        }

        FamilyDietChart activityDataInsert = new FamilyDietChart();
        activityDataInsert.setDate(mDate);
        activityDataInsert.setTime(mTime);
        activityDataInsert.setFamilyDietName(mName);
        activityDataInsert.setFamilyDietDetails(mDescription);
        activityDataInsert.setAlarm(mAlarm);

        /*
         * if update is needed then update otherwise submit
         */
        if (mStrActivityID != null) {

          mActivityId = Long.parseLong(mStrActivityID);

          activityDS = new FamilyDietDataSource(this);

          if (activityDS.updateData(mActivityId, activityDataInsert) == true) {

            toast =
                Toast.makeText(this, getString(R.string.successfullyUpdated), Toast.LENGTH_LONG);
            toast.show();
            startActivity(
                new Intent(CreatedFamilyDietChart.this, FamilyDeitChartListTodayAndUpcoming.class));
            finish();
          } else {
            toast = Toast.makeText(this, getString(R.string.notUpdated), Toast.LENGTH_LONG);
            toast.show();
          }
        } else {
          activityDS = new FamilyDietDataSource(this);
          if (activityDS.insert(activityDataInsert) == true) {

            toast = Toast.makeText(this, getString(R.string.successfullySaved), Toast.LENGTH_LONG);
            toast.show();

            startActivity(
                new Intent(CreatedFamilyDietChart.this, FamilyDeitChartListTodayAndUpcoming.class));
            finish();
          } else {
            toast = Toast.makeText(this, getString(R.string.notSaved), Toast.LENGTH_LONG);
            toast.show();
          }
        }
        break;
    }
  }