Search in sources :

Example 36 with DatePicker

use of android.widget.DatePicker in project aware-client by denzilferreira.

the class ESM_Date method onCreateDialog.

@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    super.onCreateDialog(savedInstanceState);
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
    LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    datePicked = Calendar.getInstance();
    View ui = inflater.inflate(R.layout.esm_date, null);
    builder.setView(ui);
    esm_dialog = builder.create();
    esm_dialog.setCanceledOnTouchOutside(false);
    try {
        TextView esm_title = (TextView) ui.findViewById(R.id.esm_title);
        esm_title.setText(getTitle());
        TextView esm_instructions = (TextView) ui.findViewById(R.id.esm_instructions);
        esm_instructions.setText(getInstructions());
        final CalendarView calendarPicker = ui.findViewById(R.id.esm_calendar);
        final DatePicker datePicker = ui.findViewById(R.id.esm_datePicker);
        if (isCalendar() || Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
            // date picker doesn't exist for < 21
            calendarPicker.setVisibility(View.VISIBLE);
            calendarPicker.setDate(datePicked.getTimeInMillis());
            calendarPicker.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    try {
                        if (getExpirationThreshold() > 0 && expire_monitor != null)
                            expire_monitor.cancel(true);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            });
            calendarPicker.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {

                @Override
                public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int dayOfMonth) {
                    datePicked.set(Calendar.YEAR, year);
                    datePicked.set(Calendar.MONTH, month);
                    datePicked.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                }
            });
            datePicker.setVisibility(View.GONE);
        } else {
            datePicker.setVisibility(View.VISIBLE);
            datePicker.init(datePicked.get(Calendar.YEAR), datePicked.get(Calendar.MONTH), datePicked.get(Calendar.DAY_OF_MONTH), new DatePicker.OnDateChangedListener() {

                @Override
                public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
                    datePicked.set(Calendar.YEAR, year);
                    datePicked.set(Calendar.MONTH, month);
                    datePicked.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                }
            });
            calendarPicker.setVisibility(View.GONE);
        }
        Button cancel_text = (Button) ui.findViewById(R.id.esm_cancel);
        cancel_text.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                esm_dialog.cancel();
            }
        });
        Button submit_number = (Button) ui.findViewById(R.id.esm_submit);
        submit_number.setText(getSubmitButton());
        submit_number.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                try {
                    if (getExpirationThreshold() > 0 && expire_monitor != null)
                        expire_monitor.cancel(true);
                    SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd Z");
                    ContentValues rowData = new ContentValues();
                    rowData.put(ESM_Provider.ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis());
                    rowData.put(ESM_Provider.ESM_Data.ANSWER, dateFormat.format(datePicked.getTime()));
                    rowData.put(ESM_Provider.ESM_Data.STATUS, ESM.STATUS_ANSWERED);
                    getActivity().getContentResolver().update(ESM_Provider.ESM_Data.CONTENT_URI, rowData, ESM_Provider.ESM_Data._ID + "=" + getID(), null);
                    Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED);
                    answer.putExtra(ESM.EXTRA_ANSWER, rowData.getAsString(ESM_Provider.ESM_Data.ANSWER));
                    getActivity().sendBroadcast(answer);
                    if (Aware.DEBUG)
                        Log.d(Aware.TAG, "Answer:" + rowData.toString());
                    esm_dialog.dismiss();
                } catch (JSONException e) {
                    e.printStackTrace();
                }
            }
        });
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return esm_dialog;
}
Also used : AlertDialog(android.app.AlertDialog) ContentValues(android.content.ContentValues) CalendarView(android.widget.CalendarView) JSONException(org.json.JSONException) Intent(android.content.Intent) CalendarView(android.widget.CalendarView) TextView(android.widget.TextView) View(android.view.View) Button(android.widget.Button) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat) NonNull(androidx.annotation.NonNull)

Example 37 with DatePicker

use of android.widget.DatePicker in project curb by irijwj.

the class InformationCreateFragment method showDatePicker.

private void showDatePicker() {
    AlertDialog.Builder lc_builder = new AlertDialog.Builder(m_activity);
    lc_builder.setPositiveButton("确认", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            m_AddInfoEditDate.setText(year + "-" + month + "-" + day);
        }
    });
    lc_builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {

        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.dismiss();
        }
    });
    AlertDialog lc_alertDialog = lc_builder.create();
    DatePicker lc_datePicker = new DatePicker(m_activity);
    lc_datePicker.setElevation(3);
    Calendar lc_calendar = Calendar.getInstance();
    int lc_currentYear = lc_calendar.get(Calendar.YEAR);
    int lc_currentMonth = lc_calendar.get(Calendar.MONTH);
    int lc_currentDay = lc_calendar.get(Calendar.DAY_OF_MONTH);
    setDate(lc_currentYear, lc_currentMonth, lc_currentDay);
    lc_datePicker.init(lc_currentYear, lc_currentMonth, lc_currentDay, new DatePicker.OnDateChangedListener() {

        @Override
        public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            setDate(year, monthOfYear + 1, dayOfMonth);
        }
    });
    LinearLayout lc_linearLayout = new LinearLayout(m_activity);
    LinearLayout.LayoutParams lc_layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    lc_layoutParams.gravity = Gravity.CENTER;
    lc_linearLayout.setLayoutParams(lc_layoutParams);
    lc_linearLayout.setOrientation(LinearLayout.VERTICAL);
    lc_linearLayout.addView(lc_datePicker);
    lc_alertDialog.setView(lc_linearLayout);
    lc_alertDialog.show();
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker) LinearLayout(android.widget.LinearLayout)

Example 38 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);
    FormEntryPrompt formEntryPromptStub = new MockFormEntryPromptBuilder().withIndex("index").build();
    IFormElement iformElementStub = formEntryPromptStub.getFormElement();
    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);
    return new DateWidget(widgetActivity, new QuestionDetails(formEntryPromptStub), widgetUtils);
}
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) MockFormEntryPromptBuilder(org.odk.collect.android.support.MockFormEntryPromptBuilder) DatePicker(android.widget.DatePicker) QuestionDetails(org.odk.collect.android.formentry.questions.QuestionDetails) QuestionDef(org.javarosa.core.model.QuestionDef)

Example 39 with DatePicker

use of android.widget.DatePicker in project AdMoney by ErnestoGonAr.

the class PagoRecurrenteActivity method onCreate.

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.pagos_recurrentes);
    bd = new BDHandlerAM(this);
    guardar = (Button) findViewById(R.id.PRguardar);
    salir = (Button) findViewById(R.id.PRsalir);
    n = (EditText) findViewById(R.id.nombre_pago);
    cant = (EditText) findViewById(R.id.PRcantidad);
    sp = (Spinner) findViewById(R.id.spinner_repetir);
    frecuencia = sp.getSelectedItemPosition();
    fecha = (DatePicker) findViewById(R.id.datepicker);
    tx = (TextView) findViewById(R.id.textoFrecuencia);
    d = (EditText) findViewById(R.id.txtdia);
    fecha.setVisibility(View.GONE);
    d.setVisibility(View.GONE);
    d.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(PagoRecurrenteActivity.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 = selectedyear + "-" + (selectedmonth + 1) + "-" + selectedday;
                    d.setText(dayOfWeek + "," + fechaCadena);
                }
            }, mYear, mMonth, mDay);
            mDatePicker.setTitle("Selecciona la fecha");
            mDatePicker.show();
            date = mDay + "-" + mMonth + "-" + mYear;
        }
    });
    d.setText(date);
    sp.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {

        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            if (sp.getSelectedItemPosition() == 0) {
                fecha.setVisibility(View.VISIBLE);
                d.setVisibility(View.GONE);
            }
            if (sp.getSelectedItemPosition() == 1) {
                fecha.setVisibility(View.VISIBLE);
                d.setVisibility(View.GONE);
            }
            if (sp.getSelectedItemPosition() == 2) {
                d.setVisibility(View.VISIBLE);
                fecha.setVisibility(View.GONE);
            }
            if (sp.getSelectedItemPosition() == 3) {
                fecha.setVisibility(View.VISIBLE);
                d.setVisibility(View.GONE);
            }
            if (sp.getSelectedItemPosition() == 4) {
                fecha.setVisibility(View.VISIBLE);
                d.setVisibility(View.GONE);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {
        }
    });
    fechaCadena = fecha.getYear() + "-" + (fecha.getMonth() + 1) + "-" + fecha.getDayOfMonth();
    fecha.init(fecha.getYear(), fecha.getMonth(), fecha.getDayOfMonth(), new DatePicker.OnDateChangedListener() {

        @Override
        public void onDateChanged(DatePicker datePicker, int year, int month, int dayOfMonth) {
            fechaCadena = fecha.getYear() + "-" + (fecha.getMonth() + 1) + "-" + fecha.getDayOfMonth();
        }
    });
    salir.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            onBackPressed();
        }
    });
    guardar.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (validar()) {
                if (cant.getText().toString().equals("")) {
                    cant.setText("0.0");
                }
                try {
                    cantidad = Float.parseFloat(cant.getText().toString());
                    if (!validar2(cantidad)) {
                        return;
                    }
                } catch (NumberFormatException e) {
                }
                nombre = n.getText().toString();
                bd.insertarRecurrentes(nombre, cantidad, fechaCadena, frecuencia);
                int idr = bd.ultIdRec();
                new AgregarNotf().agregarNotf(getApplicationContext(), nombre, cantidad, fechaCadena, frecuencia, idr);
                Intent i = new Intent(PagoRecurrenteActivity.this, MainActivity.class);
                startActivity(i);
            }
        }
    });
}
Also used : DatePickerDialog(android.app.DatePickerDialog) Calendar(java.util.Calendar) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) CalendarView(android.widget.CalendarView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) Date(java.util.Date) AdapterView(android.widget.AdapterView) DatePicker(android.widget.DatePicker) SimpleDateFormat(java.text.SimpleDateFormat)

Example 40 with DatePicker

use of android.widget.DatePicker in project diary by billthefarmer.

the class DatePickerFragment method onCreateDialog.

// onCreateDialog
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Bundle bundle = getArguments();
    long time = bundle.getLong(Diary.DATE);
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(time);
    // Create a new instance of DatePickerDialog
    DatePickerDialog dialog = new DatePickerDialog(getActivity(), (DatePickerDialog.OnDateSetListener) getActivity(), calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DATE));
    // Set up the date picker
    if (Build.VERSION.SDK_INT < Diary.VERSION_NOUGAT) {
        DatePicker picker = dialog.getDatePicker();
        Configuration config = getResources().getConfiguration();
        switch(config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) {
            case Configuration.SCREENLAYOUT_SIZE_SMALL:
                picker.setCalendarViewShown(true);
                picker.setSpinnersShown(false);
                break;
            case Configuration.SCREENLAYOUT_SIZE_NORMAL:
                switch(config.orientation) {
                    case Configuration.ORIENTATION_PORTRAIT:
                        picker.setCalendarViewShown(true);
                        picker.setSpinnersShown(false);
                        break;
                    case Configuration.ORIENTATION_LANDSCAPE:
                        picker.setCalendarViewShown(true);
                        break;
                }
                break;
            default:
                picker.setCalendarViewShown(true);
                break;
        }
    }
    return dialog;
}
Also used : Configuration(android.content.res.Configuration) DatePickerDialog(android.app.DatePickerDialog) Bundle(android.os.Bundle) Calendar(java.util.Calendar) DatePicker(android.widget.DatePicker)

Aggregations

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