Search in sources :

Example 21 with DatePickerDialog

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;
            }
        }
    });
}
Also used : OnChartValueSelectedListener(com.github.mikephil.charting.listener.OnChartValueSelectedListener) Description(com.github.mikephil.charting.components.Description) Highlight(com.github.mikephil.charting.highlight.Highlight) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) View(android.view.View) AdapterView(android.widget.AdapterView) Entry(com.github.mikephil.charting.data.Entry) PieEntry(com.github.mikephil.charting.data.PieEntry) Toast(android.widget.Toast) AdapterView(android.widget.AdapterView) DatePicker(android.widget.DatePicker)

Example 22 with DatePickerDialog

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;
}
Also used : TimePicker(android.widget.TimePicker) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) TimePickerDialog(android.app.TimePickerDialog) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) ImageView(android.widget.ImageView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) Timestamp(java.sql.Timestamp) DatePicker(android.widget.DatePicker)

Aggregations

DatePickerDialog (android.app.DatePickerDialog)22 Calendar (java.util.Calendar)14 DatePicker (android.widget.DatePicker)11 TimePickerDialog (android.app.TimePickerDialog)5 View (android.view.View)5 DialogInterface (android.content.DialogInterface)4 Intent (android.content.Intent)3 AdapterView (android.widget.AdapterView)3 TextView (android.widget.TextView)3 SimpleDateFormat (java.text.SimpleDateFormat)3 AlertDialog (android.app.AlertDialog)2 OnDateSetListener (android.app.DatePickerDialog.OnDateSetListener)2 ImageView (android.widget.ImageView)2 Toast (android.widget.Toast)2 Description (com.github.mikephil.charting.components.Description)2 Entry (com.github.mikephil.charting.data.Entry)2 PieEntry (com.github.mikephil.charting.data.PieEntry)2 Highlight (com.github.mikephil.charting.highlight.Highlight)2 OnChartValueSelectedListener (com.github.mikephil.charting.listener.OnChartValueSelectedListener)2 Date (java.util.Date)2