use of android.app.DatePickerDialog in project AdMoney by ErnestoGonAr.
the class Reporte_Egresos method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
initData();
} catch (NullPointerException e) {
Toast toast = Toast.makeText(this, "No hay Egresos", Toast.LENGTH_SHORT);
toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
toast.show();
return;
}
setContentView(R.layout.activity_reporte__egresos);
pieChart = (PieChart) findViewById(R.id.grafico_egresos);
pieChart.setRotationEnabled(true);
pieChart.setHoleRadius(30f);
pieChart.setCenterTextSize(10);
pieChart.setEntryLabelTextSize(4);
pieChart.setTransparentCircleAlpha(0);
Description d = pieChart.getDescription();
d.setText("");
pieChart.setDescription(d);
pieChart.getLegend().setOrientation(Legend.LegendOrientation.VERTICAL);
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_Egresos.this, "Ha gastado $" + res + " en " + categoria, Toast.LENGTH_LONG).show();
}
@Override
public void onNothingSelected() {
}
});
spinner = (Spinner) findViewById(R.id.spinner_r_egresos);
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_egresos);
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_Egresos.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_e);
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:
String dia = calendar.getText().toString();
data = bd.obtenerEgresos(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.obtenerEgresos(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.obtenerEgresos(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 IITB-App by wncc.
the class AddEventFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
container.removeAllViews();
view = inflater.inflate(R.layout.fragment_add_event, container, false);
ButterKnife.bind(this, view);
eventPictureImageView = view.findViewById(R.id.ib_eventImage);
progressDialog = new ProgressDialog(getContext());
cb_permission.setVisibility(View.GONE);
cb_public.setVisibility(View.GONE);
et_mapLocation.setVisibility(View.GONE);
close.setVisibility(View.GONE);
open.setVisibility(View.VISIBLE);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
int mYear = calendar.get(Calendar.YEAR);
int mMonth = calendar.get(Calendar.MONTH);
int mDay = calendar.get(Calendar.DAY_OF_MONTH);
final int mHour = calendar.get(Calendar.HOUR_OF_DAY);
final int mMin = calendar.get(Calendar.MINUTE);
long millis = calendar.getTimeInMillis();
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, final int year, final int month, final int dayOfMonth) {
TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
start.setText(dayOfMonth + "/" + month + "/" + year + " " + hourOfDay + ":" + minute);
}
}, mHour, mMin, true);
timePickerDialog.show();
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
timestamp_start = new Timestamp(millis);
}
});
end.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Calendar calendar = Calendar.getInstance();
int mYear = calendar.get(Calendar.YEAR);
int mMonth = calendar.get(Calendar.MONTH);
int mDay = calendar.get(Calendar.DAY_OF_MONTH);
final int mHour = calendar.get(Calendar.HOUR_OF_DAY);
final int mMin = calendar.get(Calendar.MINUTE);
long millis = calendar.getTimeInMillis();
DatePickerDialog datePickerDialog = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, final int year, final int month, final int dayOfMonth) {
TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
end.setText(dayOfMonth + "/" + month + "/" + year + " " + hourOfDay + ":" + minute);
}
}, mHour, mMin, true);
timePickerDialog.show();
}
}, mYear, mMonth, mDay);
datePickerDialog.show();
timestamp_end = new Timestamp(millis);
}
});
if (cb_permission.isChecked()) {
publicStatus = 1;
} else
publicStatus = 0;
advancedMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (cb_public.getVisibility() == View.VISIBLE) {
open.setVisibility(View.VISIBLE);
close.setVisibility(View.GONE);
cb_permission.setVisibility(View.GONE);
cb_public.setVisibility(View.GONE);
et_mapLocation.setVisibility(View.GONE);
} else {
close.setVisibility(View.VISIBLE);
open.setVisibility(View.GONE);
cb_permission.setVisibility(View.VISIBLE);
cb_public.setVisibility(View.VISIBLE);
et_mapLocation.setVisibility(View.VISIBLE);
}
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
// Permission is not granted
ActivityCompat.requestPermissions(getActivity(), new String[] { Manifest.permission.READ_EXTERNAL_STORAGE }, MY_PERMISSIONS_REQUEST_READ_EXTERNAL_STORAGE);
return;
}
Intent i = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
}
});
createEvent.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
progressDialog.setIndeterminate(true);
progressDialog.setCancelable(false);
progressDialog.show();
sendImage();
}
});
return view;
}
Aggregations