If you think the Android project frc-notebook 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.plnyyanks.frcnotebook.dialogs;
/*fromwww.java2s.com*/import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import com.plnyyanks.frcnotebook.Constants;
import java.util.Arrays;
import java.util.Calendar;
/**
* File created by phil on 4/15/14.
* Copyright 2014, Phil Lopreiato
* This file is part of FRC Notebook.
* FRC Notebook is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
* FRC Notebook is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along with FRC Notebook. If not, see http://www.gnu.org/licenses/.
*/publicclass DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener {
private Button parentView;
public DatePickerFragment(){
}
public DatePickerFragment(View v){
parentView = (Button)v;
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
int year,month,day;
if(parentView == null || parentView.getText().toString().split("-").length!=3) {
final Calendar c = Calendar.getInstance();
year = c.get(Calendar.YEAR);
month = c.get(Calendar.MONTH);
day = c.get(Calendar.DAY_OF_MONTH);
}else{
String[] split = parentView.getText().toString().split("-");
Log.d(Constants.LOG_TAG, Arrays.toString(split));
month = Integer.parseInt(split[1]);
day = Integer.parseInt(split[2]);
year = Integer.parseInt(split[0]);
}
// Create a new instance of DatePickerDialog and return it
returnnew DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
publicvoid onDateSet(DatePicker view, int year, int month, int day) {
if(parentView == null) return;
parentView.setText(year+"-"+(month+1)+"-"+day);
}
}