private void loadUserDOB() {
    DatePicker.OnDateChangedListener onDateChanged =
        new DatePicker.OnDateChangedListener() {
          @Override
          public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            Log.v(
                Globals.TAG,
                "year : "
                    + year
                    + ", monthOfYear : "
                    + monthOfYear
                    + ", dayOfMonth : "
                    + dayOfMonth);
          }
        };

    if (null != user.getDateOfBirth()) {
      String dob[] = user.getDateOfBirth().split("-");
      year = Integer.parseInt(dob[0]);
      month = Integer.parseInt(dob[1]);
      day = Integer.parseInt(dob[2]);

    } else {
      Calendar c = Calendar.getInstance();
      year = c.get(Calendar.YEAR);
      month = c.get(Calendar.MONTH);
      day = c.get(Calendar.DAY_OF_MONTH);
    }

    pickerDOB.init(year, month, day, onDateChanged);
    pickerDOB.setCalendarViewShown(false);
    pickerDOB.setSpinnersShown(true);
  }
Exemplo n.º 2
0
  /** Called when the activity is first created. */
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    expenseData = new ExpenseContentProvider();

    // wire up interface
    dateToday = (DatePicker) findViewById(R.id.dateToday);
    spinnerExpenseType = (Spinner) findViewById(R.id.spinnerExpenseType);
    layoutNewType = (LinearLayout) findViewById(R.id.layoutNewType);
    layoutExpenseType = (LinearLayout) findViewById(R.id.layoutExpenseType);
    txtAmount = (EditText) findViewById(R.id.txtAmount);
    txtAddType = (EditText) findViewById(R.id.txtAddType);
    lblTodaysSpendValue = (TextView) findViewById(R.id.lblTodaysSpendValue);

    Button btnAddType = (Button) findViewById(R.id.btnAddType);
    Button btnSaveNewType = (Button) findViewById(R.id.btnSaveNewType);
    Button btnSave = (Button) findViewById(R.id.btnSave);

    btnAddType.setOnClickListener(lAddTypeClicked);
    btnSaveNewType.setOnClickListener(lSaveNewTypeClicked);
    btnSave.setOnClickListener(lSaveClicked);

    dateToday.init(
        dateToday.getYear(), dateToday.getMonth(), dateToday.getDayOfMonth(), lDateTodayChanged);

    // set up spinner
    bindExpenseTypeSpinner();

    // set up todays spend
    bindTodaysSpend();
  }
Exemplo n.º 3
0
  private void makeDateOnlyPicker() {

    // 月日選択ダイアログを作る
    AlertDialog.Builder builder = new AlertDialog.Builder(getSherlockActivity());
    datePicker = new DatePicker(getSherlockActivity());

    datePicker.updateDate(calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), 1);
    int day_id = Resources.getSystem().getIdentifier("day", "id", "android");
    datePicker.findViewById(day_id).setVisibility(View.GONE);
    dateDialog =
        builder
            .setView(datePicker)
            .setTitle(
                getSherlockActivity().getApplicationContext().getString(R.string.select_month))
            .setPositiveButton(
                android.R.string.ok,
                new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface d, int w) {
                    previous_month.setText(datePicker.getMonth());
                    calendar.set(datePicker.getYear(), datePicker.getMonth(), 1, 0, 0, 0);
                    target_year = calendar.get(Calendar.YEAR);
                    target_month = calendar.get(Calendar.MONTH);
                    showCommentList(target_year, target_month, 0, near);
                  }
                })
            .setNegativeButton(android.R.string.cancel, null)
            .create();
  }
Exemplo n.º 4
0
  public void AddSubTaskToDB(View view) {
    // Intent intent = new Intent(this, Today.class);
    if (SUB_TASK_CREATED == true) {
      String name = taskName.getText().toString();
      String desc = taskDescription.getText().toString();
      long milliseconds = 0;
      year = taskDatePicker.getYear();
      month = taskDatePicker.getMonth() + 1;
      day = taskDatePicker.getDayOfMonth();
      hour = taskTimePicker.getCurrentHour();
      minute = taskTimePicker.getCurrentMinute();
      try {
        String dateToParse = day + "-" + month + "-" + year + " " + hour + ":" + minute;
        SimpleDateFormat dateFormatter = new SimpleDateFormat("d-M-yyyy hh:mm");
        Date date = dateFormatter.parse(dateToParse);
        milliseconds = date.getTime();
      } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      } // You will need try/catch around this

      BujoDbHandler taskHandler = new BujoDbHandler(view.getContext());
      currentSubTask = new SubTask(name, desc, currentTask.get_id(), milliseconds);
      taskHandler.addSubTask(currentSubTask);
    }
  }
Exemplo n.º 5
0
 private String getDateFromDatePicker(DatePicker datePicker) {
   String date;
   date = String.valueOf(datePicker.getMonth() + 1) + "/";
   date += String.valueOf(datePicker.getDayOfMonth()) + "/";
   date += String.valueOf(datePicker.getYear());
   return date;
 }
Exemplo n.º 6
0
  @Override
  protected void onDialogClosed(boolean positiveResult) {
    // When the user selects "OK", persist the new value

    if (positiveResult) {
      int day = picker.getDayOfMonth();
      int month = picker.getMonth();
      int year = picker.getYear();

      String date = "";
      if (day < 10) {
        date += "0" + day + "/";
      } else {
        date += day + "/";
      }

      if (month < 10) {
        date += "0" + month + "/";
      } else {
        date += month + "/";
      }

      date += "" + year;

      persistString(date);
      setSummary(date);
    }
  }
Exemplo n.º 7
0
  public void onDateSet(DatePicker view, int year, int month, int day) {

    // String dates = date.getText().toString();

    GregorianCalendar GC =
        new GregorianCalendar(view.getYear(), view.getMonth(), view.getDayOfMonth());

    String newDate =
        GC.getDisplayName(GregorianCalendar.DAY_OF_WEEK, GregorianCalendar.SHORT, Locale.UK)
            + " "
            + GC.get(GregorianCalendar.DAY_OF_MONTH)
            + " "
            + GC.getDisplayName(GregorianCalendar.MONTH, GregorianCalendar.SHORT, Locale.UK);

    if (this.button.getId() == R.id.get_check_in) {
      TextView date1 = (TextView) getActivity().findViewById(R.id.startDate1);
      TextView date2 = (TextView) getActivity().findViewById(R.id.startDate2);
      String S1 = newDate;
      String S2 = Integer.toString(GC.get(GregorianCalendar.YEAR));
      date1.setText(S1);
      date2.setText(S2);
    }
    if (this.button.getId() == R.id.get_check_out) {
      TextView date1 = (TextView) getActivity().findViewById(R.id.endDate1);
      TextView date2 = (TextView) getActivity().findViewById(R.id.endDate2);
      String S1 = newDate;
      String S2 = Integer.toString(GC.get(GregorianCalendar.YEAR));
      date1.setText(S1);
      date2.setText(S2);
    }
  }
Exemplo n.º 8
0
 @Override
 public Object getValue() {
   if (Versions.preHC && mType.equals("date")) {
     // We can't use the custom DateTimePicker with a sdk older than 11.
     // Fallback on the native DatePicker.
     DatePicker dp = (DatePicker) mView;
     GregorianCalendar calendar =
         new GregorianCalendar(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
     return formatDateString("yyyy-MM-dd", calendar);
   } else if (mType.equals("time")) {
     TimePicker tp = (TimePicker) mView;
     GregorianCalendar calendar =
         new GregorianCalendar(0, 0, 0, tp.getCurrentHour(), tp.getCurrentMinute());
     return formatDateString("HH:mm", calendar);
   } else {
     DateTimePicker dp = (DateTimePicker) mView;
     GregorianCalendar calendar = new GregorianCalendar();
     calendar.setTimeInMillis(dp.getTimeInMillis());
     if (mType.equals("date")) {
       return formatDateString("yyyy-MM-dd", calendar);
     } else if (mType.equals("week")) {
       return formatDateString("yyyy-'W'ww", calendar);
     } else if (mType.equals("datetime-local")) {
       return formatDateString("yyyy-MM-dd HH:mm", calendar);
     } else if (mType.equals("datetime")) {
       calendar.set(GregorianCalendar.ZONE_OFFSET, 0);
       calendar.setTimeInMillis(dp.getTimeInMillis());
       return formatDateString("yyyy-MM-dd HH:mm", calendar);
     } else if (mType.equals("month")) {
       return formatDateString("yyyy-MM", calendar);
     }
   }
   return super.getValue();
 }
  public void initListViews() {
    DatePicker date = (DatePicker) findViewById(R.id.datePicker);
    date.setMinDate(System.currentTimeMillis() - 1000);

    final TimePicker time = (TimePicker) findViewById(R.id.timePicker);

    CheckBox checkBox = (CheckBox) findViewById(R.id.checkBoxTime);
    checkBox.setOnCheckedChangeListener(
        new CompoundButton.OnCheckedChangeListener() {
          @Override
          public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            time.setEnabled(isChecked);
          }
        });
    checkBox.setChecked(false);

    date.requestFocus();

    Button okButton = (Button) findViewById(R.id.okButton);
    okButton.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            showAppWidget();
          }
        });
  }
Exemplo n.º 10
0
  private static void bindTimePickerValue(final View view, final Object target, final Field f2) {

    f2.setAccessible(true);
    final GregorianCalendar cal = (GregorianCalendar) GregorianCalendar.getInstance();

    DatePicker dp = (DatePicker) view;
    cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
    cal.set(Calendar.MONTH, dp.getMonth());
    cal.set(Calendar.YEAR, dp.getYear());
    try {
      f2.set(target, cal.getTime());
    } catch (Exception e) {
      Log.e("CleanDroid", e.getMessage(), e);
    }

    ((TimePicker) view)
        .setOnTimeChangedListener(
            new OnTimeChangedListener() {

              @Override
              public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
                cal.set(Calendar.HOUR_OF_DAY, hourOfDay);
                cal.set(Calendar.HOUR, hourOfDay);
                cal.set(Calendar.MINUTE, minute);
                try {
                  f2.set(target, cal.getTime());
                } catch (Exception e) {
                  Log.e("CleanDroid", e.getMessage(), e);
                }
              }
            });
  }
 /** {@inheritDoc} */
 @Override
 protected View onCreateDialogView() {
   final Calendar c = this.getPersitendCalendar(this.defValue);
   final DatePicker dp = new DatePicker(this.getContext());
   dp.init(c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH), this);
   return dp;
 }
Exemplo n.º 12
0
  private ContentValues getContent() {
    ContentValues content = new ContentValues();
    EditText aux;

    Long id = getId();
    if (id != -1) {
      content.put("_id", id);
    }

    // date
    DatePicker dp = (DatePicker) findViewById(R.id.date);
    GregorianCalendar date = new GregorianCalendar(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    content.put("date", sdf.format(date.getTime()));

    // km
    aux = (EditText) findViewById(R.id.km);
    content.put("odometer", Float.parseFloat(aux.getText().toString()));

    // liters
    aux = (EditText) findViewById(R.id.liters);
    content.put("liters", Float.parseFloat(aux.getText().toString()));

    // type
    RadioGroup aux2 = (RadioGroup) findViewById(R.id.type);
    RadioButton aux3 = (RadioButton) findViewById(aux2.getCheckedRadioButtonId());
    content.put("fuel", aux3.getText().toString());

    return content;
  }
Exemplo n.º 13
0
  public void findParking(final View aButton) {
    DatePicker datePicker = (DatePicker) findViewById(R.id.date_picker_id);

    TimePicker timepicker = (TimePicker) findViewById(R.id.timePicker1);

    EditText addressText = (EditText) findViewById(R.id.editText1);
    String address = addressText.getText().toString();
    EditText durationText = (EditText) findViewById(R.id.editText2);
    String duration = durationText.getText().toString();
    Intent findParkingIntent = new Intent(this, FindParking.class);
    findParkingIntent.putExtra("address", address);
    findParkingIntent.putExtra("duration", Integer.valueOf(duration));
    // DateTimeFormatter parser1 =
    //    DateTimeFormat.forPattern("dd/MMM/yyyy:HH:mm:ss Z");
    // String dayOfMonthString = (datePicker.getDayOfMonth()<10)?"0"
    String dateAsString =
        datePicker.getYear()
            + "-"
            + datePicker.getMonth()
            + 1
            + "-"
            + datePicker.getDayOfMonth()
            + "T"
            + timepicker.getCurrentHour()
            + ":"
            + timepicker.getCurrentMinute()
            + "Z";
    //		Date date = new Date(datePicker.getYear() - 1900, datePicker.getMonth(),
    // datePicker.getDayOfMonth(),
    //				timepicker.getCurrentHour(),timepicker.getCurrentMinute(),0);
    findParkingIntent.putExtra("date", dateAsString);
    Log.i(TAG, dateAsString);
    startActivity(findParkingIntent);
  }
Exemplo n.º 14
0
  @NonNull
  @Override
  public Dialog onCreateDialog(Bundle savedInstanceState) {

    Locale.setDefault(new Locale("ru"));

    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    final android.widget.DatePicker datePicker = new android.widget.DatePicker(getActivity());
    datePicker.setCalendarViewShown(false);
    builder.setView(datePicker);

    builder.setTitle(getResources().getString(R.string.choose_date));

    builder.setPositiveButton(
        getResources().getString(R.string.ready),
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialog, int which) {
            editText.setText(
                datePicker.getDayOfMonth()
                    + "-"
                    + (datePicker.getMonth() + 1)
                    + "-"
                    + datePicker.getYear());
          }
        });

    return builder.create();
  }
Exemplo n.º 15
0
 public void onClick(View arg0) {
   _init.setYear(_datePicker.getYear() - 1900);
   _init.setMonth(_datePicker.getMonth());
   _init.setDate(_datePicker.getDayOfMonth());
   _init.setHours(_timePicker.getCurrentHour());
   _init.setMinutes(_timePicker.getCurrentMinute());
   sendResult(_callback, _init, _opaque);
 }
Exemplo n.º 16
0
 private void handleExpansion(Button buttonClicked, DatePicker datePicker) {
   if (datePicker.getVisibility() == View.GONE) {
     datePicker.setVisibility(View.VISIBLE);
   } else {
     datePicker.setVisibility(View.GONE);
     String date = getDateFromDatePicker(datePicker);
     buttonClicked.setText(date);
   }
 }
  // gets the user entered date from the DatePicker
  public int[] getDateTimeFromPickers() {
    DatePicker dp = (DatePicker) findViewById(R.id.agenda_edit_datePicker);

    int month = dp.getMonth();
    int day = dp.getDayOfMonth();
    int year = dp.getYear();

    return new int[] {month, day, year};
  }
Exemplo n.º 18
0
 /** {@inheritDoc} */
 @Override
 public String getAnswer() {
   if (!isViewActive()) return answer;
   else {
     dateAnswer = new Date(dp.getYear(), dp.getMonth(), dp.getDayOfMonth());
     SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
     return sdf.format(dateAnswer);
   }
 }
Exemplo n.º 19
0
  public static Calendar createCalendarFromDatePicker(DatePicker dp) {

    Calendar cal = Calendar.getInstance();
    cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth());
    cal.set(Calendar.MONTH, dp.getMonth());
    cal.set(Calendar.YEAR, dp.getYear());

    return cal;
  }
 /**
  * Called whenever the user clicks on a button. Invokes {@link #onDateChanged(DatePicker, int,
  * int, int)} and {@link #onDialogClosed(boolean)}. Be sure to call the super when overriding.
  */
 @SuppressWarnings("deprecation")
 @Override
 public void onClick(DialogInterface dialog, int which) {
   super.onClick(dialog, which);
   datePicker.clearFocus();
   onDateChanged(
       datePicker, datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
   onDialogClosed(which == DialogInterface.BUTTON1); // OK?
 }
Exemplo n.º 21
0
    public View getView(Context context) throws UnsupportedOperationException {
      if (mType.equals("date")) {
        try {
          DateTimePicker input =
              new DateTimePicker(context, "yyyy-MM-dd", mValue, DateTimePicker.PickersState.DATE);
          input.toggleCalendar(true);
          mView = (View) input;
        } catch (UnsupportedOperationException ex) {
          // We can't use our custom version of the DatePicker widget because the sdk is too old.
          // But we can fallback on the native one.
          DatePicker input = new DatePicker(context);
          try {
            if (!TextUtils.isEmpty(mValue)) {
              GregorianCalendar calendar = new GregorianCalendar();
              calendar.setTime(new SimpleDateFormat("yyyy-MM-dd").parse(mValue));
              input.updateDate(
                  calendar.get(Calendar.YEAR),
                  calendar.get(Calendar.MONTH),
                  calendar.get(Calendar.DAY_OF_MONTH));
            }
          } catch (Exception e) {
            Log.e(LOGTAG, "error parsing format string: " + e);
          }
          mView = (View) input;
        }
      } else if (mType.equals("week")) {
        DateTimePicker input =
            new DateTimePicker(context, "yyyy-'W'ww", mValue, DateTimePicker.PickersState.WEEK);
        mView = (View) input;
      } else if (mType.equals("time")) {
        TimePicker input = new TimePicker(context);
        input.setIs24HourView(DateFormat.is24HourFormat(context));

        GregorianCalendar calendar = new GregorianCalendar();
        if (!TextUtils.isEmpty(mValue)) {
          try {
            calendar.setTime(new SimpleDateFormat("HH:mm").parse(mValue));
          } catch (Exception e) {
          }
        }
        input.setCurrentHour(calendar.get(GregorianCalendar.HOUR_OF_DAY));
        input.setCurrentMinute(calendar.get(GregorianCalendar.MINUTE));
        mView = (View) input;
      } else if (mType.equals("datetime-local") || mType.equals("datetime")) {
        DateTimePicker input =
            new DateTimePicker(
                context, "yyyy-MM-dd HH:mm", mValue, DateTimePicker.PickersState.DATETIME);
        input.toggleCalendar(true);
        mView = (View) input;
      } else if (mType.equals("month")) {
        DateTimePicker input =
            new DateTimePicker(context, "yyyy-MM", mValue, DateTimePicker.PickersState.MONTH);
        mView = (View) input;
      }
      return mView;
    }
Exemplo n.º 22
0
  public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
    // 获得日历实例
    Calendar calendar = Calendar.getInstance();

    calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth());
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    dateTime = sdf.format(calendar.getTime());
    ad.setTitle(dateTime);
  }
Exemplo n.º 23
0
  public static long getTimeMsFromDatePicker(DatePicker datePicker, boolean addOneDay) {
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, datePicker.getYear());
    calendar.set(Calendar.MONTH, datePicker.getMonth());
    calendar.set(Calendar.DATE, datePicker.getDayOfMonth());
    clearCalendarValuesUnder(calendar, Calendar.DATE);
    if (addOneDay) calendar.add(Calendar.DATE, 1);

    return calendar.getTimeInMillis();
  }
Exemplo n.º 24
0
  public static java.util.Date getDateFromDatePicker(DatePicker datePicker) {
    int day = datePicker.getDayOfMonth();
    int month = datePicker.getMonth();
    int year = datePicker.getYear();

    Calendar calendar = Calendar.getInstance();
    calendar.set(year, month, day);

    return calendar.getTime();
  }
Exemplo n.º 25
0
  private String extractDatePickerDateString(DatePicker datePicker) {
    final char separator = '-';

    return new StringBuilder()
        .append(datePicker.getYear())
        .append(separator)
        .append(datePicker.getMonth() + 1) // Why is this off by one?
        .append(separator)
        .append(datePicker.getDayOfMonth())
        .toString();
  }
Exemplo n.º 26
0
 public void setValue(long value, boolean suppressEvent) {
   DatePicker picker = (DatePicker) getNativeView();
   Calendar calendar = Calendar.getInstance();
   calendar.setTimeInMillis(value);
   suppressChangeEvent = suppressEvent;
   picker.updateDate(
       calendar.get(Calendar.YEAR),
       calendar.get(Calendar.MONTH),
       calendar.get(Calendar.DAY_OF_MONTH));
   suppressChangeEvent = false;
 }
Exemplo n.º 27
0
 private void setEndTime(final TimeObject startTime) {
   LinearLayout layout = new LinearLayout(PlayBackActivity.this);
   layout.setOrientation(LinearLayout.VERTICAL);
   layout.setBackgroundColor(getResources().getColor(R.color.white));
   final TimePicker mTimePicker = new TimePicker(PlayBackActivity.this);
   final DatePicker mDatePicker = new DatePicker(PlayBackActivity.this);
   mTimePicker.setDescendantFocusability(TimePicker.FOCUS_BLOCK_DESCENDANTS);
   mTimePicker.setIs24HourView(true);
   mDatePicker.setDescendantFocusability(DatePicker.FOCUS_BLOCK_DESCENDANTS);
   final TextView tv = new TextView(PlayBackActivity.this);
   String time = String.format("%02d:%02d", startTime.getHour(), startTime.getMinute());
   String date =
       String.valueOf(startTime.getYear())
           + "年"
           + String.format("%02d", startTime.getMonth())
           + "月"
           + String.format("%02d", startTime.getDay())
           + "日";
   tv.setText("开始时间:" + date + "  " + time);
   int version = Integer.valueOf(android.os.Build.VERSION.SDK);
   if (version >= 11) mDatePicker.setCalendarViewShown(false);
   layout.addView(tv, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mDatePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   layout.addView(
       mTimePicker, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
   new AlertDialog.Builder(PlayBackActivity.this)
       .setTitle("请选择结束时间:")
       .setView(layout)
       .setPositiveButton(
           android.R.string.ok,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {
               TimeObject endTime =
                   new TimeObject(
                       mTimePicker.getCurrentMinute(),
                       mTimePicker.getCurrentHour(),
                       mDatePicker.getDayOfMonth(),
                       mDatePicker.getMonth() + 1,
                       mDatePicker.getYear());
               System.out.println("时间:" + endTime.getMinute() + "  " + startTime.getMinute());
               onTimeSearch(startTime, endTime);
             }
           })
       .setNegativeButton(
           android.R.string.cancel,
           new DialogInterface.OnClickListener() {
             @Override
             public void onClick(DialogInterface arg0, int arg1) {}
           })
       .create()
       .show();
 }
Exemplo n.º 28
0
 public static String makeShortDate(DatePicker datePicker) {
   int month = datePicker.getMonth() + 1;
   String theDate =
       String.valueOf(datePicker.getYear())
           + "-"
           + (month < 10 ? "0" + month : String.valueOf(month))
           + "-"
           + (datePicker.getDayOfMonth() < 10
               ? "0" + datePicker.getDayOfMonth()
               : String.valueOf(datePicker.getDayOfMonth()));
   return theDate;
 }
Exemplo n.º 29
0
 @Override
 public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
   Calendar calendar = Calendar.getInstance();
   calendar.set(
       datePicker.getYear(),
       datePicker.getMonth(),
       datePicker.getDayOfMonth(),
       timePicker.getCurrentHour(),
       timePicker.getCurrentMinute());
   nowDateTime = formatDateTime(calendar.getTime(), DF_YYYY_MM_DD_HH_MM_SS);
   dialog.setTitle(nowDateTime);
 }
  /** Answer to search button, go to next activity to do a search */
  public void searchPatient() {
    Intent intent = new Intent(this, FoundPatientsActivity.class);

    // Passing data to next activity
    EditText editFirstName = (EditText) findViewById(R.id.edit_first_name);
    if (editFirstName.getText().length() == 0) {
      intent.putExtra(EXTRA_FIRST_NAME, "");
    } else {
      String first_name = editFirstName.getText().toString();
      intent.putExtra(EXTRA_FIRST_NAME, first_name);
    }

    EditText editLastName = (EditText) findViewById(R.id.edit_last_name);
    if (editLastName.getText().length() == 0) {
      Toast.makeText(this, R.string.invalidFamilyName, Toast.LENGTH_LONG).show();
      return;
    } else {
      String last_name = editLastName.getText().toString();
      intent.putExtra(EXTRA_LAST_NAME, last_name);
    }

    // Check value of Gender Radio Group
    RadioButton maleButton = (RadioButton) findViewById(R.id.radio0);
    RadioButton femaleButton = (RadioButton) findViewById(R.id.radio1);

    if (maleButton.isChecked()) {
      intent.putExtra(EXTRA_GENDER, "t");
    } else if (femaleButton.isChecked()) {
      intent.putExtra(EXTRA_GENDER, "f");
    } else {
      intent.putExtra(EXTRA_GENDER, "");
    }

    if (SEND_DATE) {
      // Getting date of birth
      DatePicker birth = (DatePicker) findViewById(R.id.datePicker);
      String born_on =
          DateUtils.dateString(birth.getDayOfMonth(), birth.getMonth(), birth.getYear());

      intent.putExtra(EXTRA_BORN_ON, born_on);
    } else {
      intent.putExtra(EXTRA_BORN_ON, "");
    }

    intent.putExtra(EXTRA_VILLAGE_ID, village_id);

    // Avoid the Activity finish when back key is pressed in next Activity
    intent.putExtra(EXTRA_FINISH_ACTIVITY, false);

    // Starting new activity and hoping a result for finish by itself
    startActivityForResult(intent, 0);
  }