Search in sources :

Example 1 with DatePicker

use of android.widget.DatePicker in project android-app-common-tasks by multidots.

the class Common method showDatePickerDialog.

/**
     * use to show datepicker
     *
     * @param mContext
     * @param format    of the date format
     * @param mTextView in which you have to set selected date
     */
public static void showDatePickerDialog(final Context mContext, final String format, final TextView mTextView) {
    new DatePickerDialog(mContext, new OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            SimpleDateFormat dateFormatter = new SimpleDateFormat(format);
            dateTime.set(year, monthOfYear, dayOfMonth);
            mTextView.setText(dateFormatter.format(dateTime.getTime()));
        }
    }, dateTime.get(Calendar.YEAR), dateTime.get(Calendar.MONTH), dateTime.get(Calendar.DAY_OF_MONTH)).show();
}
Also used : OnDateSetListener(android.app.DatePickerDialog.OnDateSetListener) DatePickerDialog(android.app.DatePickerDialog) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat)

Example 2 with DatePicker

use of android.widget.DatePicker in project WordPress-Android by wordpress-mobile.

the class EditPostSettingsFragment method showPostDateSelectionDialog.

private void showPostDateSelectionDialog() {
    final DatePicker datePicker = new DatePicker(getActivity());
    datePicker.init(mYear, mMonth, mDay, null);
    datePicker.setCalendarViewShown(false);
    new AlertDialog.Builder(getActivity()).setTitle(R.string.select_date).setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            mYear = datePicker.getYear();
            mMonth = datePicker.getMonth();
            mDay = datePicker.getDayOfMonth();
            showPostTimeSelectionDialog();
        }
    }).setNeutralButton(getResources().getText(R.string.immediately), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialogInterface, int i) {
            mIsCustomPubDate = true;
            mPubDateText.setText(R.string.immediately);
            updatePostSettingsAndSaveButton();
        }
    }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
        }
    }).setView(datePicker).show();
}
Also used : DialogInterface(android.content.DialogInterface) TaxonomyActionBuilder(org.wordpress.android.fluxc.generated.TaxonomyActionBuilder) SiteActionBuilder(org.wordpress.android.fluxc.generated.SiteActionBuilder) DatePicker(android.widget.DatePicker)

Example 3 with DatePicker

use of android.widget.DatePicker 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;
            }
        }
    });
}
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 4 with DatePicker

use of android.widget.DatePicker 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);
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView)

Example 5 with DatePicker

use of android.widget.DatePicker in project collect by opendatakit.

the class DaylightSavingTest method prepareDateWidget.

private DateWidget prepareDateWidget(int year, int month, int day) {
    QuestionDef questionDefStub = mock(QuestionDef.class);
    IFormElement iformElementStub = mock(IFormElement.class);
    FormEntryPrompt formEntryPromptStub = mock(FormEntryPrompt.class);
    when(iformElementStub.getAdditionalAttribute(anyString(), anyString())).thenReturn(null);
    when(formEntryPromptStub.getQuestion()).thenReturn(questionDefStub);
    when(formEntryPromptStub.getFormElement()).thenReturn(iformElementStub);
    when(formEntryPromptStub.getQuestion().getAppearanceAttr()).thenReturn("no-calendar");
    DatePickerDialog datePickerDialog = mock(DatePickerDialog.class);
    DatePicker datePicker = mock(DatePicker.class);
    when(datePickerDialog.getDatePicker()).thenReturn(datePicker);
    when(datePickerDialog.getDatePicker().getYear()).thenReturn(year);
    when(datePickerDialog.getDatePicker().getMonth()).thenReturn(month);
    when(datePickerDialog.getDatePicker().getDayOfMonth()).thenReturn(day);
    DateWidget dateWidget = new DateWidget(RuntimeEnvironment.application, formEntryPromptStub);
    dateWidget.setDatePickerDialog(datePickerDialog);
    return dateWidget;
}
Also used : IFormElement(org.javarosa.core.model.IFormElement) FormEntryPrompt(org.javarosa.form.api.FormEntryPrompt) DatePickerDialog(android.app.DatePickerDialog) DateWidget(org.odk.collect.android.widgets.DateWidget) DatePicker(android.widget.DatePicker) QuestionDef(org.javarosa.core.model.QuestionDef)

Aggregations

DatePicker (android.widget.DatePicker)67 DatePickerDialog (android.app.DatePickerDialog)46 Calendar (java.util.Calendar)43 View (android.view.View)27 TextView (android.widget.TextView)19 DialogInterface (android.content.DialogInterface)13 Intent (android.content.Intent)13 TimePicker (android.widget.TimePicker)11 EditText (android.widget.EditText)10 Dialog (android.app.Dialog)9 AdapterView (android.widget.AdapterView)9 LinearLayout (android.widget.LinearLayout)9 Date (java.util.Date)9 AlertDialog (android.app.AlertDialog)8 Context (android.content.Context)7 Button (android.widget.Button)7 SimpleDateFormat (java.text.SimpleDateFormat)7 TimePickerDialog (android.app.TimePickerDialog)6 ArrayAdapter (android.widget.ArrayAdapter)6 ImageView (android.widget.ImageView)6