use of android.app.DatePickerDialog in project weex-example by KalicyZhou.
the class DatePickerImpl method pickDate.
public static void pickDate(@NonNull Context context, String value, String max, String min, @NonNull final OnPickListener listener) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(parseDate(value));
final DatePickerDialog dialog = new DatePickerDialog(context, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
int realMonth = monthOfYear + 1;
String realMonthString = realMonth < 10 ? "0" + realMonth : String.valueOf(realMonth);
String result = year + "-" + realMonthString + "-" + dayOfMonth;
listener.onPick(true, result);
}
}, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
final DatePicker datePicker = dialog.getDatePicker();
final Calendar defaultMinDate = Calendar.getInstance(Locale.getDefault());
final Calendar defaultMaxDate = Calendar.getInstance(Locale.getDefault());
defaultMinDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
defaultMaxDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
if (!TextUtils.isEmpty(min)) {
long minDate = parseDate(min).getTime();
if (datePicker.getMaxDate() >= minDate) {
datePicker.setMinDate(parseDate(min).getTime());
} else {
datePicker.setMinDate(defaultMinDate.getTimeInMillis());
datePicker.setMaxDate(defaultMaxDate.getTimeInMillis());
}
}
if (!TextUtils.isEmpty(max)) {
long maxDate = parseDate(max).getTime();
if (datePicker.getMinDate() <= maxDate) {
datePicker.setMaxDate(parseDate(max).getTime());
} else {
datePicker.setMinDate(defaultMinDate.getTimeInMillis());
datePicker.setMaxDate(defaultMaxDate.getTimeInMillis());
}
}
dialog.setOnCancelListener(new DialogInterface.OnCancelListener() {
@Override
public void onCancel(DialogInterface dialog) {
listener.onPick(false, null);
}
});
dialog.show();
}
use of android.app.DatePickerDialog in project android-player-samples by BrightcoveOS.
the class DatePickerFragment method onCreateDialog.
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
// Use the current date as the default date in the picker
final Calendar calendar = Calendar.getInstance();
int year = calendar.get(Calendar.YEAR);
int month = calendar.get(Calendar.MONTH);
int day = calendar.get(Calendar.DAY_OF_MONTH);
Activity activity = getActivity();
DatePickerDialog dialog = new DatePickerDialog(activity, R.style.DialogWithTitle, onDateSetListener, year, month, day);
if (title != null) {
dialog.setTitle(title);
}
return dialog;
}
use of android.app.DatePickerDialog in project AdMoney by ErnestoGonAr.
the class Reporte_Ingresos method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
initData();
} catch (NullPointerException e) {
Toast toast = Toast.makeText(this, "No hay Ingresos", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
setContentView(R.layout.activity_reporte__ingresos);
pieChart = (PieChart) findViewById(R.id.grafico_ingresos);
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(30f);
pieChart.setCenterTextSize(10);
pieChart.setTransparentCircleAlpha(0);
Description d = pieChart.getDescription();
d.setText("");
pieChart.setDescription(d);
pieChart.getLegend().setOrientation(Legend.LegendOrientation.VERTICAL);
pieChart.setEntryLabelTextSize(4);
pieChart.getLegend().setTextSize(12);
pieChart.getLegend().setPosition(Legend.LegendPosition.LEFT_OF_CHART);
if (xData.length == 0)
return;
addData();
pieChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {
@Override
public void onValueSelected(Entry e, Highlight h) {
Log.d(TAG, "onValueSelected: Value selected from chart");
Log.d(TAG, e.toString());
Log.d(TAG, h.toString());
int pos1 = e.toString().indexOf("Entry, x: 0.0 y: ");
String res = e.toString().substring(pos1 + 17);
for (int i = 0; i < yData.length; i++) {
if (yData[i] == Float.parseFloat(res)) {
pos1 = i;
break;
}
}
String categoria = xData[pos1];
Toast.makeText(Reporte_Ingresos.this, "Ha obtenido $" + res + " en ingresos\n" + "por " + categoria, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected() {
}
});
spinner = (Spinner) findViewById(R.id.spinner_r_ingresos);
spinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
calendar.setText("Selecciona una fecha");
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
año = 2017;
mes = 5;
diad = 17;
calendar = (EditText) findViewById(R.id.fecha_r_ingresos);
calendar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
// To show current date in the datepicker
final Calendar mcurrentDate = Calendar.getInstance();
mYear = mcurrentDate.get(Calendar.YEAR);
mMonth = mcurrentDate.get(Calendar.MONTH);
mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
DatePickerDialog mDatePicker = new DatePickerDialog(Reporte_Ingresos.this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
año = selectedyear;
mes = selectedmonth + 1;
diad = selectedday;
calendar.setText(selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Selecciona fecha");
mDatePicker.show();
}
});
consultar = (Button) findViewById(R.id.consultar);
consultar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (calendar.getText().toString().equals("Selecciona una fecha")) {
calendar.requestFocus();
calendar.callOnClick();
return;
}
String[][] data;
switch(spinner.getSelectedItemPosition()) {
case 1:
data = bd.obtenerIngresos(diad + "", mes + "", año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
case 2:
data = bd.obtenerIngresos(mes + "", año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
case 3:
data = bd.obtenerIngresos(año + "");
if (data == null) {
Toast toast = Toast.makeText(getApplicationContext(), "No hay registros para esta fecha", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
pieChart.setVisibility(View.INVISIBLE);
break;
}
pieChart.clear();
initData(data);
addData();
pieChart.setVisibility(View.VISIBLE);
break;
default:
pieChart.clear();
initData();
addData();
pieChart.setVisibility(View.VISIBLE);
break;
}
}
});
}
use of android.app.DatePickerDialog in project AdMoney by ErnestoGonAr.
the class Detalles_Ingresos_Egresos_Activity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
// noinspection SimplifiableIfStatement
if (id == R.id.action_borrar) {
if (this.item2.tipo == 0) {
new AlertDialog.Builder(this).setMessage("Eliminar Registro?").setCancelable(false).setPositiveButton("Si", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
bd.eliminarEgresos(item2.id);
onBackPressed();
}
}).setNegativeButton("No", null).show();
} else {
// egreso
new AlertDialog.Builder(this).setMessage("Eliminar Registro?").setCancelable(false).setPositiveButton("Si", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
bd.eliminarIngresos(item2.id);
onBackPressed();
}
}).setNegativeButton("No", null).show();
}
}
if (id == R.id.action_modificar) {
categoria.setClickable(true);
cantidad.setEnabled(true);
fecha.getEditableText();
cantidad.getEditableText();
fecha.setEnabled(true);
// fecha_p.setVisibility(View.VISIBLE);
descripcion.setEnabled(true);
// descripcion.getEditableText();
linearLayout.setVisibility(View.VISIBLE);
fecha.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final Calendar mcurrentDate = Calendar.getInstance();
mYear = mcurrentDate.get(Calendar.YEAR);
mMonth = mcurrentDate.get(Calendar.MONTH);
mDay = mcurrentDate.get(Calendar.DAY_OF_MONTH);
final DatePickerDialog mDatePicker = new DatePickerDialog(Detalles_Ingresos_Egresos_Activity.this, new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday) {
// TODO Auto-generated method stub
/*SimpleDateFormat simpledateformat = new SimpleDateFormat("EEEE");
Date date = new Date(selectedyear, selectedmonth, selectedday-1);
String dayOfWeek = simpledateformat.format(date);
fechaCadena=selectedday+"-"+(selectedmonth+1)+"-"+selectedyear;
d.setText(dayOfWeek+"," +fechaCadena);*/
fechaCadena = selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday;
fecha.setText(fechaCadena);
}
}, mYear, mMonth, mDay);
mDatePicker.setTitle("Selecciona la fecha");
mDatePicker.show();
// date=mDay+"-"+mMonth+"-"+mYear;
}
});
}
return super.onOptionsItemSelected(item);
}
use of android.app.DatePickerDialog in project xabber-android by redsolution.
the class AccountInfoEditorFragment method updateDatePickerDialog.
public void updateDatePickerDialog() {
Calendar calendar = null;
String vCardBirthDate = vCard.getField(VCardProperty.BDAY.name());
if (vCardBirthDate != null) {
DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT, Locale.US);
Date result = null;
try {
result = dateFormat.parse(vCardBirthDate);
} catch (ParseException e) {
LogManager.exception(this, e);
}
if (result != null) {
calendar = new GregorianCalendar();
calendar.setTime(result);
}
}
if (calendar == null) {
calendar = Calendar.getInstance(TimeZone.getDefault());
}
datePicker = new DatePickerDialog(getActivity(), AccountInfoEditorFragment.this, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH));
datePicker.setCancelable(false);
}
Aggregations