Example usage for android.app DatePickerDialog DatePickerDialog

List of usage examples for android.app DatePickerDialog DatePickerDialog

Introduction

In this page you can find the example usage for android.app DatePickerDialog DatePickerDialog.

Prototype

public DatePickerDialog(@NonNull Context context, @Nullable OnDateSetListener listener, int year, int month,
        int dayOfMonth) 

Source Link

Document

Creates a new date picker dialog for the specified date using the parent context's default date picker dialog theme.

Usage

From source file:com.synvata.modules.DriverLicenseEditActivity.java

private void chooseDate() {
    String d = ((EditText) findViewById(R.id.edt_driverlicense_init_date)).getText().toString();
    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    final Calendar c = Calendar.getInstance();

    try {/*from   ww  w .j  av a2 s .  c  o m*/
        c.setTime(sdf.parse(d));

        Dialog dialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                c.set(Calendar.YEAR, year);
                c.set(Calendar.MONTH, monthOfYear);
                c.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                showDialog(sdf.format(c.getTime()));
            }
        }, c.get(Calendar.YEAR), c.get(Calendar.MONTH), c.get(Calendar.DAY_OF_MONTH));
        dialog.show();
    } catch (Exception e) {
        log(e);
    }

}

From source file:com.adithya321.sharesanalysis.fragments.SharePurchaseFragment.java

@Nullable
@Override//from   w  w w. j  av a  2 s  . com
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
        @Nullable Bundle savedInstanceState) {
    ViewGroup root = (ViewGroup) inflater.inflate(R.layout.fragment_share_purchase, container, false);

    databaseHandler = new DatabaseHandler(getContext());
    sharePurchasesRecyclerView = (RecyclerView) root.findViewById(R.id.share_purchases_recycler_view);
    emptyTV = (TextView) root.findViewById(R.id.empty);
    arrow = (ImageView) root.findViewById(R.id.arrow);
    setRecyclerViewAdapter();

    FloatingActionButton addPurchaseFab = (FloatingActionButton) root.findViewById(R.id.add_purchase_fab);
    addPurchaseFab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Dialog dialog = new Dialog(getContext());
            dialog.setTitle("Add Share Purchase");
            dialog.setContentView(R.layout.dialog_add_share_purchase);
            dialog.getWindow().setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
            dialog.show();

            final AutoCompleteTextView name = (AutoCompleteTextView) dialog.findViewById(R.id.share_name);
            List<String> nseList = ShareUtils.getNseList(getContext());
            FilterWithSpaceAdapter<String> arrayAdapter = new FilterWithSpaceAdapter<>(getContext(),
                    android.R.layout.simple_dropdown_item_1line, nseList);
            name.setThreshold(1);
            name.setAdapter(arrayAdapter);

            final Spinner spinner = (Spinner) dialog.findViewById(R.id.existing_spinner);

            ArrayList<String> shares = new ArrayList<>();
            for (Share share : sharesList) {
                shares.add(share.getName());
            }
            ArrayAdapter<String> spinnerAdapter = new ArrayAdapter<>(getContext(),
                    android.R.layout.simple_spinner_item, shares);
            spinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner.setAdapter(spinnerAdapter);

            final RadioButton newRB = (RadioButton) dialog.findViewById(R.id.radioBtn_new);
            RadioButton existingRB = (RadioButton) dialog.findViewById(R.id.radioBtn_existing);
            if (shares.size() == 0)
                existingRB.setVisibility(View.GONE);
            (newRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.VISIBLE);
                    spinner.setVisibility(View.GONE);
                }
            });

            (existingRB).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    name.setVisibility(View.GONE);
                    spinner.setVisibility(View.VISIBLE);
                }
            });

            Calendar calendar = Calendar.getInstance();
            year_start = calendar.get(Calendar.YEAR);
            month_start = calendar.get(Calendar.MONTH) + 1;
            day_start = calendar.get(Calendar.DAY_OF_MONTH);
            final Button selectDate = (Button) dialog.findViewById(R.id.select_date);
            selectDate.setText(new StringBuilder().append(day_start).append("/").append(month_start).append("/")
                    .append(year_start));
            selectDate.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    Dialog dialog = new DatePickerDialog(getActivity(), onDateSetListener, year_start,
                            month_start - 1, day_start);
                    dialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            selectDate.setText(new StringBuilder().append(day_start).append("/")
                                    .append(month_start).append("/").append(year_start));
                        }
                    });
                    dialog.show();
                }
            });

            Button addPurchaseBtn = (Button) dialog.findViewById(R.id.add_purchase_btn);
            addPurchaseBtn.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Share share = new Share();
                    share.setId(databaseHandler.getNextKey("share"));
                    share.setPurchases(new RealmList<Purchase>());
                    Purchase purchase = new Purchase();
                    purchase.setId(databaseHandler.getNextKey("purchase"));

                    if (newRB.isChecked()) {
                        String sName = name.getText().toString().trim();
                        if (sName.equals("")) {
                            Toast.makeText(getActivity(), "Invalid Name", Toast.LENGTH_SHORT).show();
                            return;
                        } else {
                            share.setName(sName);
                            purchase.setName(sName);
                        }
                    }

                    String stringStartDate = year_start + " " + month_start + " " + day_start;
                    DateFormat format = new SimpleDateFormat("yyyy MM dd", Locale.ENGLISH);
                    try {
                        Date date = format.parse(stringStartDate);
                        share.setDateOfInitialPurchase(date);
                        purchase.setDate(date);
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Date", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText quantity = (EditText) dialog.findViewById(R.id.no_of_shares);
                    try {
                        purchase.setQuantity(Integer.parseInt(quantity.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Number of Shares", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    EditText price = (EditText) dialog.findViewById(R.id.buying_price);
                    try {
                        purchase.setPrice(Double.parseDouble(price.getText().toString()));
                    } catch (Exception e) {
                        Toast.makeText(getActivity(), "Invalid Buying Price", Toast.LENGTH_SHORT).show();
                        return;
                    }

                    purchase.setType("buy");
                    if (newRB.isChecked()) {
                        if (!databaseHandler.addShare(share, purchase)) {
                            Toast.makeText(getActivity(), "Share Already Exists", Toast.LENGTH_SHORT).show();
                            return;
                        }
                    } else {
                        purchase.setName(spinner.getSelectedItem().toString());
                        databaseHandler.addPurchase(spinner.getSelectedItem().toString(), purchase);
                    }
                    setRecyclerViewAdapter();
                    dialog.dismiss();
                }
            });
        }
    });

    return root;
}

From source file:com.cachirulop.moneybox.activity.MovementDetailActivity.java

/**
 * Handler for the change insert date button
 * //ww w  .  j  av  a2 s .  co m
 * @param v
 *            view that launch the event
 */
public void onChangeInsertDateClick(View v) {
    Calendar cal;
    DatePickerDialog dlg;
    DatePickerDialog.OnDateSetListener ld;

    cal = Calendar.getInstance();

    ld = new DatePickerDialog.OnDateSetListener() {
        public void onDateSet(DatePicker view, int year, int month, int day) {
            onInsertDateSet(view, year, month, day);
        }
    };

    cal.setTime(_movement.getInsertDate());

    dlg = new DatePickerDialog(this, ld, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
            cal.get(Calendar.DAY_OF_MONTH));
    dlg.show();
}

From source file:com.rsmsa.accapp.ScreenSlidePageFragmentTwo.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.vehicle_two, container, false);

    tab_one = (EditText) rootView.findViewById(R.id.dob_one);

    vehicle_category = (Spinner) rootView.findViewById(R.id.vtype_spinner);

    vehicle_type = (Button) rootView.findViewById(R.id.vehicle_type_select_button);

    /**//  w w w  .  j  ava  2s .  c o  m
     * Defining all layout items
     **/

    inputFatal = (EditText) rootView.findViewById(R.id.fatal_edit);
    inputInjuries = (EditText) rootView.findViewById(R.id.injury_edit);
    inputSimple = (EditText) rootView.findViewById(R.id.simple_edit);
    inputNotInjured = (EditText) rootView.findViewById(R.id.not_injured_edit);

    //driver 0ne details
    surname_one = (EditText) rootView.findViewById(R.id.surname_one);
    othernames_one = (EditText) rootView.findViewById(R.id.othernames_one);
    physical_address_one = (EditText) rootView.findViewById(R.id.physical_address_one);
    address_box_one = (EditText) rootView.findViewById(R.id.address_box_one);
    national_id_one = (EditText) rootView.findViewById(R.id.national_id_one);
    phone_no_one = (EditText) rootView.findViewById(R.id.phone_no_one);
    final RadioButton male = (RadioButton) rootView.findViewById(R.id.male);
    final RadioButton female = (RadioButton) rootView.findViewById(R.id.female);
    nationality_one = (EditText) rootView.findViewById(R.id.nationality_one);
    license_one = (EditText) rootView.findViewById(R.id.license_one);
    occupation_one = (EditText) rootView.findViewById(R.id.occupation_one);

    alcohol_edit = (EditText) rootView.findViewById(R.id.alcohol_edit);
    drug = (CheckBox) rootView.findViewById(R.id.drug_edit);
    phone_use = (CheckBox) rootView.findViewById(R.id.phone_edit);
    seat_belt = (CheckBox) rootView.findViewById(R.id.seat_belt_edit);

    //Vehicle one details
    type_one = (EditText) rootView.findViewById(R.id.type_one);
    registration_number_one = (EditText) rootView.findViewById(R.id.registration_number_one);

    //Vehicle one  Insurance details
    company_one = (EditText) rootView.findViewById(R.id.company_one);
    insurance_type_one = (EditText) rootView.findViewById(R.id.insurance_type_one);
    insurance_phone = (EditText) rootView.findViewById(R.id.insurance_phone);
    policy_period_one = (EditText) rootView.findViewById(R.id.policy_period_one);
    policy_number_one = (EditText) rootView.findViewById(R.id.policy_number_one);
    repair_amount_one = (EditText) rootView.findViewById(R.id.repair_amount_one);

    //Vehicle one  damage details
    vehicle = (EditText) rootView.findViewById(R.id.vehicle_title_edit);
    vehicle_total = (EditText) rootView.findViewById(R.id.vehicle_total_edit);
    infrastructure = (EditText) rootView.findViewById(R.id.infrastructure_edit);
    cost = (EditText) rootView.findViewById(R.id.rescue_cost_edit);

    /**
     * getting values of our view elements
     */
    drug.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (((CheckBox) v).isChecked()) {

                MainActivity.V2_drug_edit = "Drugs Use";
            } else {
                MainActivity.V2_drug_edit = " No Drug use";
            }
        }
    });

    phone_use.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (((CheckBox) v).isChecked()) {

                MainActivity.V2_phone_edit = "Was using Phone";
            } else {
                MainActivity.V2_phone_edit = " No phone use";
            }
        }
    });

    seat_belt.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            if (((CheckBox) v).isChecked()) {

                MainActivity.V2_seat_belt_edit = "Seat belt not fastened";
            } else {
                MainActivity.V2_seat_belt_edit = "Seat belt fastened";
            }
        }
    });

    male.setChecked(true);
    //   Fatal.setChecked(true);

    male.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                female.setChecked(false);
                MainActivity.V2_gender = "male";
            }
        }
    });

    female.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        @Override
        public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
            if (b == true) {
                male.setChecked(false);
                MainActivity.V2_gender = "female";
            }
        }
    });

    cal = Calendar.getInstance();

    day = cal.get(Calendar.DAY_OF_MONTH);

    month = cal.get(Calendar.MONTH);

    year = cal.get(Calendar.YEAR);

    pickDate = (Button) rootView.findViewById(R.id.date_picker);
    pickDate.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), datePickerListener, year,
                    month, day);
            datePickerDialog.show();
        }
    });

    List<String> vehicle_category_list = new ArrayList<String>();
    vehicle_category_list.add("Private");
    vehicle_category_list.add("Commercial");
    vehicle_category_list.add("Government");
    vehicle_category_list.add("Emergency");
    vehicle_category_list.add("Passenger Service Vehicles");

    vehicle_category.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
            selectedSpinner = i;
        }

        @Override
        public void onNothingSelected(AdapterView<?> adapterView) {

        }
    });

    vehicle_type.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(), VehicleType.class);
            intent.putExtra("category", selectedSpinner + "");
            startActivity(intent);
        }
    });

    ArrayAdapter<String> atc_adapter = new ArrayAdapter<String>(getActivity(),
            android.R.layout.simple_spinner_item, vehicle_category_list);
    atc_adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    vehicle_category.setAdapter(atc_adapter);

    return rootView;
}

From source file:com.shalzz.attendance.fragment.TimeTablePagerFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.menu_logout) {
        userAccount.Logout();/*from ww w  . j  ava2  s .com*/
        return true;
    } else if (item.getItemId() == R.id.menu_refresh) {
        // We make sure that the SwipeRefreshLayout is displaying it's refreshing indicator
        if (!mSwipeRefreshLayout.isRefreshing()) {
            mSwipeRefreshLayout.setRefreshing(true);
            mController.updatePeriods();
            return true;
        }
    } else if (item.getItemId() == R.id.menu_date) {
        Calendar today = Calendar.getInstance();
        today.setTime(new Date());
        DatePickerDialog mDatePickerDialog = new DatePickerDialog(mContext, onDateSetListener(),
                today.get(Calendar.YEAR), today.get(Calendar.MONTH), today.get(Calendar.DAY_OF_MONTH));
        mDatePickerDialog.setOnCancelListener(dialog -> {
            mTracker.send(new HitBuilders.EventBuilder().setCategory("Scroll to Date").setAction("Button")
                    .setLabel("Cancel").build());
        });
        mDatePickerDialog.show();

        mTracker.send(new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Date").build());
        return true;
    } else if (item.getItemId() == R.id.menu_today) {
        mController.setToday();

        mTracker.send(
                new HitBuilders.EventBuilder().setCategory("Action").setAction("Scroll to Today").build());
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.ubundude.timesheet.ReportFragment.java

@Override
public void onStart() {
    super.onStart();
    /** Get the shared preference for the first day of the week */
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity());
    firstDay = prefs.getString(getActivity().getString(R.string.prefDOWKey), "SUNDAY");

    firstDOW = getFirstDay(firstDay);//  w ww . ja  v a2  s . c  o m

    hoursTextView = (TextView) getView().findViewById(R.id.rHoursTV);
    rSpinner = (Spinner) getView().findViewById(R.id.rSpinner);
    ArrayAdapter<CharSequence> adapt = ArrayAdapter.createFromResource(getActivity(), R.array.reports,
            android.R.layout.simple_spinner_item);

    adapt.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    rSpinner.setAdapter(adapt);
    rSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) {
            switch (pos) {
            case 0:
                sendDate = formDate.format(c.getTime());
                dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime());
                dateEditText.setText(dateView);
                reportType = 0;
                getTimestamps(sendDate, reportType);
                break;
            case 1:
                dateView = formWIY.format(c.getTime());
                sendDate = dateView;
                dateEditText.setText(dateView);
                reportType = 1;
                getTimestamps(sendDate, reportType);
                break;
            case 2:
                sendDate = formMonthNum.format(c.getTime());
                monthHelp = Integer.parseInt(sendDate) - 1;
                sendDate = Integer.toString(monthHelp);
                Log.d("Spinner Switch", "Date is: " + sendDate);
                dateView = formMonth.format(c.getTime());
                Log.d("Spinner Switch", "DateView is: " + dateView);
                dateEditText.setText(dateView);
                reportType = 2;
                getTimestamps(sendDate, reportType);
                break;
            }
        }

        public void onNothingSelected(AdapterView<?> parent) {

        }
    });

    dateView = formDay.format(c.getTime()) + "\n" + formDate.format(c.getTime());
    sendDate = formDate.format(c.getTime());
    gDate = sendDate;

    getTimestamps(sendDate, reportType);

    /** Instantiates the dateEditText, set's it's text to the dateView, and sets the onClickListener */
    dateEditText = (EditText) getView().findViewById(R.id.rDateEditText);
    dateEditText.setText(dateView);
    dateEditText.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            /** Gets the date based on the report type selected */
            switch (reportType) {
            case 0:
                Log.d("Initial Dates", "In the On Click Listener");
                arrDate = gDate.split("/");

                year = Integer.valueOf(arrDate[2]);
                month = Integer.valueOf(arrDate[0]) - 1;
                dayOfMonth = Integer.valueOf(arrDate[1]);
                new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show();

                break;
            case 1:
                sendDate = dateEditText.getText().toString();
                arrDate = gDate.split("/");

                year = Integer.valueOf(arrDate[2]);
                month = Integer.valueOf(arrDate[0]) - 1;
                dayOfMonth = Integer.valueOf(arrDate[1]);
                new DatePickerDialog(getActivity(), d, year, month, dayOfMonth).show();
                break;
            case 2:
                pickMonth();
                break;
            }
        }
    });

    /**
       * Initialize minus button
       * 
       * This method calls the minus button handler and stores the date returned
       * and also gets new timestamps for the date returned. */
    minusButton = (Button) getView().findViewById(R.id.rMinusButton);
    minusButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            try {
                sendDate = minusButtonHandler();
                getTimestamps(sendDate, reportType);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }

    });

    /**
     * Initialize plus button 
     * 
     * This method calls the plus button handler and stores the date returned
     * and also gets new timestamps for the date returned. */
    plusButton = (Button) getView().findViewById(R.id.rPlusButton);
    plusButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            try {
                sendDate = plusButtonHandler();
                getTimestamps(sendDate, reportType);
            } catch (ParseException e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:com.commonsdroid.fragmentdialog.AlertFragmentDialog.java

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    setCancelable(isCancelable);/*from w  w  w  .  j a  v  a2  s .c  o m*/
    if (TextUtils.isEmpty(positiveText)) {
        positiveText = "OK";
        Log.d("CHECK", "" + com.commonsdroid.fragmentdialog.R.string.ok);
    }

    if (TextUtils.isEmpty(negativeText)) {
        negativeText = "Cancel";
    }
    switch (type) {
    case DIALOG_TYPE_OK:
        /*show dialog with positive button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).create();
    case DIALOG_TYPE_YES_NO:
        /*show dialog with positive and negative button*/
        return new AlertDialog.Builder(getActivity()).setTitle(title).setMessage(message)
                .setPositiveButton(positiveText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onPositiveButtonClick(identifier);

                    }
                }).setNegativeButton(negativeText, new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int whichButton) {
                        dialog.dismiss();
                        if (alertButtonClickListener != null)
                            alertButtonClickListener.onNegativeButtonClick(identifier);

                    }
                }).create();
    case DATE_DIALOG:
        /*show date picker dialog*/
        return new DatePickerDialog(getActivity(), AlertFragmentDialog.this, sYear, sMonth, sDate);
    case TIME_DIALOG:
        /*show time picker dialog*/
        return new TimePickerDialog(getActivity(), AlertFragmentDialog.this, sHour, sMinute, true);
    case SIMPLE_LIST_DIALOG:
        /**
         * show simple list dialog
         */
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_item).create();
    case SINGLE_CHOICE_LIST_DIALOG:
        /*show single choice list dialog*/
        return getAlertBuilder(title, dialogList, android.R.layout.select_dialog_singlechoice).create();
    case MULTI_CHOICE_LIST_DIALOG:
        /*show multichoice list dialog*/
        Dialog multipleChoice = new Dialog(getActivity());
        multipleChoice.setContentView(R.layout.list_multichoice);
        multipleChoice.setTitle(title);
        ListView listView = (ListView) multipleChoice.findViewById(R.id.lstMultichoiceList);
        listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                // Manage selected items here

                CheckedTextView textView = (CheckedTextView) view;
                if (textView.isChecked()) {

                } else {

                }
                Log.e("CHECK", "clicked pos : " + position + " checked : " + textView.isChecked());
            }
        });

        final ArrayAdapter<String> arraySingleChoiceAdapter = new ArrayAdapter<String>(getActivity(),
                android.R.layout.select_dialog_multichoice, dialogList);

        listView.setAdapter(arraySingleChoiceAdapter);
        multipleChoice.show();
        /*multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
        multipleChoice.setPositiveButton(R.string.cancel, new OnClickListener() {
           @Override
           public void onClick(DialogInterface dialog, int which) {
              dismiss();      
              sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
           }
        });*/
        /* multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        //         multipleChoice.create();

        //         singleChoiceListDialog.setCancelable(false);

        /* multipleChoice.setMultiChoiceItems(items, null,
            new DialogInterface.OnMultiChoiceClickListener() {
             @Override
                public void onClick(DialogInterface dialog, int which,
                        boolean isChecked) {
                    if (isChecked) {
                        alSelectedItem.add(items[which]);
                    } else {
                        alSelectedItem.remove(items[which]);
                    }
                }
            });
           multipleChoice.setNegativeButton(R.string.cancel,
            new DialogInterface.OnClickListener() {
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();
                }
            });
           multipleChoice.setPositiveButton(R.string.ok,
            new DialogInterface.OnClickListener() {
                
                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (alSelectedItem.size() != 0) {
                        sListDialogListener.onMultiChoiceSelected(identifier, alSelectedItem);
                    }
                }
            });*/
        return multipleChoice;//.create();

    }
    return null;
}

From source file:net.niyonkuru.koodroid.ui.UsageFragment.java

@Override
public boolean onMenuItemClick(MenuItem item) {
    int id = item.getItemId();

    switch (id) {
    case R.id.edit_billing_cycle:
        Calendar cal = new GregorianCalendar(TimeZone.getTimeZone("UTC"));
        cal.setTime((Date) mPeriodFrom.getTag());

        DatePickerDialog dialog = new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() {
            @Override//from w  w  w  .jav a 2  s .com
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                ContentValues values = new ContentValues(1);
                values.put(Settings.BILLING_CYCLE, dayOfMonth);
                mContext.getContentResolver().insert(Settings.CONTENT_URI, values);
            }
        }, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DATE));

        dialog.setMessage(getResources().getString(R.string.billing_cycle_dialog));

        //                DatePicker datePicker = dialog.getDatePicker();
        //                datePicker.setMaxDate(System.currentTimeMillis());

        dialog.show();

        return true;
    case R.id.enable_airtime: {
        getLoaderManager().restartLoader(AIRTIME_TOKEN, null, this);
    }
    case R.id.disable_airtime:
        View airtimeContent = getView().findViewById(R.id.airtime_content);
        AnimUtils.show(airtimeContent);

        toggleService(Settings.AIRTIME_SERVICE, id == R.id.enable_airtime);

        /* refresh the widget to show or hide data */
        IntentUtils.updateWidget(mContext);

        return true;
    case R.id.refresh_airtime:
        sync(SyncService.AIRTIME);
        return true;
    case R.id.enable_data: {
        LoaderManager loaderManager = getLoaderManager();

        loaderManager.restartLoader(DATA_TOKEN, null, this);
        loaderManager.restartLoader(TEXT_TOKEN, null, this);
    }
    case R.id.disable_data:
        View dataContent = getView().findViewById(R.id.data_content);
        AnimUtils.show(dataContent);

        View textContent = getView().findViewById(R.id.text_content);
        AnimUtils.show(textContent);

        toggleService(Settings.USAGE_SERVICE, id == R.id.enable_data);

        /* refresh the widget to show or hide data */
        IntentUtils.updateWidget(mContext);

        return true;
    case R.id.refresh_data:
        sync(SyncService.USAGE);
        return true;
    case R.id.detail_data:
        mCallBack.onShowDataTransactions(getSubscriber());
        return true;
    }

    return false;
}

From source file:com.ranglerz.tlc.tlc.com.ranglerz.tlc.tlc.Insurance.AddDriver.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_driver);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null) {
        setSupportActionBar(toolbar);/*ww  w .  ja  v  a2  s  . co m*/
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }
    createNetErrorDialog();
    checkWriteExternalPermission();
    checkReadExternalStoragePermission();

    DriverName = (EditText) findViewById(R.id.drivername);
    DriverLicence = (EditText) findViewById(R.id.driverlicense);
    TlcLicence = (EditText) findViewById(R.id.tlclicence);
    PolicyNumber = (EditText) findViewById(R.id.policynumber);
    PlateNumber = (EditText) findViewById(R.id.platanum);
    StartDriving = (EditText) findViewById(R.id.startdriving);
    TicketRecived = (EditText) findViewById(R.id.numberofticket);
    FleetName = (EditText) findViewById(R.id.fleetname);
    AddComment = (EditText) findViewById(R.id.adddriveraddcoment);

    UtilityBill = (Button) findViewById(R.id.utilitybills);
    BaseLetter = (Button) findViewById(R.id.baseletter);
    DriverLicensebtn = (Button) findViewById(R.id.driverlicenseadddriver);
    TlcLicensebtn = (Button) findViewById(R.id.tlclicenceadddriver);
    Submit = (Button) findViewById(R.id.submitadddriver);

    //        Endorsmentform = (Button)findViewById(R.id.endorsmentform);

    UtilityBillImageView = (ImageView) findViewById(R.id.utilitybillsImageView);
    BaseLetterImageView = (ImageView) findViewById(R.id.baseletterImageView);
    DriverLicenseImageView = (ImageView) findViewById(R.id.driverlicenseadddriverImageView);
    TlcLicenseImageView = (ImageView) findViewById(R.id.tlclicenceadddriverImageView);

    //        EndorsmentformImageView = (ImageView)findViewById(R.id.endorsmentformImageView);

    UtilityBillImageView.setVisibility(View.GONE);
    BaseLetterImageView.setVisibility(View.GONE);
    DriverLicenseImageView.setVisibility(View.GONE);
    TlcLicenseImageView.setVisibility(View.GONE);

    UtilityBill.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = UtilityBillsButton;
        }
    });

    BaseLetter.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = BaseLetterButton;
        }
    });
    DriverLicensebtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = DriverLicenseButton;
        }
    });
    TlcLicensebtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            selectImage();
            btnClicked = TlcLicenseButton;
        }
    });

    final DatePickerDialog.OnDateSetListener date = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            // TODO Auto-generated method stub
            myCalendar.set(Calendar.YEAR, year);
            myCalendar.set(Calendar.MONTH, monthOfYear);
            myCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            updateLabel();
        }

    };

    StartDriving.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            new DatePickerDialog(AddDriver.this, date, myCalendar.get(Calendar.YEAR),
                    myCalendar.get(Calendar.MONTH), myCalendar.get(Calendar.DAY_OF_MONTH)).show();
        }
    });
    Submit.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {

            strDriverName = DriverName.getText().toString();
            strTlcLicence = TlcLicence.getText().toString();
            strDriverLicence = DriverLicence.getText().toString();
            strPolicyNumber = PolicyNumber.getText().toString();
            strPlateNumber = PlateNumber.getText().toString();
            strFleetname = FleetName.getText().toString();
            strStartDriving = StartDriving.getText().toString();
            strTicketRecived = TicketRecived.getText().toString();
            strAddComment = AddComment.getText().toString();
            Log.d("driver", "" + strDriverName);
            Log.d("driver", "" + strDriverLicence);

            if (strDriverName.equals("")) {
                DriverName.setError("Please Enter Driver Name");
            } else if (strDriverLicence.equals("")) {
                DriverLicence.setError("Please Enter Driver License");
            } else if (strTlcLicence.equals("")) {
                TlcLicence.setError("Please Enter TLC License");
            } else if (strPlateNumber.equals("")) {
                PlateNumber.setError("Please Enter Plate Number License");
            } else if (strPolicyNumber.equals("")) {
                PolicyNumber.setError("Please Enter Policy Number");
            } else if (strFleetname.equals("")) {
                FleetName.setError("Please Enter Corporation/Base... Number");
            } else if (strStartDriving.equals("")) {
                StartDriving.setError("Please Enter When you start Driving");
            } else if (strTicketRecived.equals("")) {
                TicketRecived.setError("Please Enter Number of Tickets Received");
            } else if (UtilityBillImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Utility BillI Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (BaseLetterImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Base Letter Image", Toast.LENGTH_SHORT)
                        .show();
            } else if (DriverLicenseImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload Driver License Image",
                        Toast.LENGTH_SHORT).show();
            } else if (TlcLicenseImageView.getDrawable() == null) {
                Toast.makeText(getApplicationContext(), "Please Upload TLC License Image", Toast.LENGTH_SHORT)
                        .show();
            } else {

                sharedPreferences = getSharedPreferences("email", 1);
                String email = sharedPreferences.getString(emailkey, null);

                message = "User Email: " + email + "\n\nDriver Name: " + strDriverName + "\nDriver License: "
                        + strDriverLicence + "\nTLC License: " + strTlcLicence + "\nPolicy Number: "
                        + strPolicyNumber + "\nStart Driving: " + strStartDriving + "\nTicket Received: "
                        + strTicketRecived;

                //new SendEmail().execute();
                new AddDriverAsyncTask().execute();
                Log.d("", "driver" + strDriverName);
                Log.d("", "driver" + strDriverLicence);
            }

        }
    });

}

From source file:org.onebusaway.android.ui.TripPlanFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Init Google Play Services as early as possible in the Fragment lifecycle to give it time
    if (GooglePlayServicesUtil.isGooglePlayServicesAvailable(getActivity()) == ConnectionResult.SUCCESS) {
        mGoogleApiClient = LocationUtils.getGoogleApiClientWithCallbacks(getContext());
        mGoogleApiClient.connect();/*  w  ww .ja va  2 s . c  o  m*/
    }

    Bundle bundle = getArguments();
    mBuilder = new TripRequestBuilder(bundle);

    final View view = inflater.inflate(R.layout.fragment_trip_plan, container, false);
    setHasOptionsMenu(true);

    mFromAddressTextArea = (AutoCompleteTextView) view.findViewById(R.id.fromAddressTextArea);
    mToAddressTextArea = (AutoCompleteTextView) view.findViewById(R.id.toAddressTextArea);
    mFromCurrentLocationImageButton = (ImageButton) view.findViewById(R.id.fromCurrentLocationImageButton);
    mToCurrentLocationImageButton = (ImageButton) view.findViewById(R.id.toCurrentLocationImageButton);
    mDate = (Spinner) view.findViewById(R.id.date);
    mDateAdapter = new ArrayAdapter(getActivity(), R.layout.simple_list_item);
    mDate.setAdapter(mDateAdapter);

    mTime = (Spinner) view.findViewById(R.id.time);
    mTimeAdapter = new ArrayAdapter(getActivity(), R.layout.simple_list_item);
    mTime.setAdapter(mTimeAdapter);

    mLeavingChoice = (Spinner) view.findViewById(R.id.leavingChoiceSpinner);

    mLeavingChoiceAdapter = ArrayAdapter.createFromResource(getContext(),
            R.array.trip_plan_leaving_arriving_array, R.layout.simple_list_item);
    mLeavingChoiceAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mLeavingChoice.setAdapter(mLeavingChoiceAdapter);

    // Set mLeavingChoice onclick adapter in onResume() so we do not fire it when setting it
    final TimePickerDialog.OnTimeSetListener timeCallback = new TimePickerDialog.OnTimeSetListener() {
        @Override
        public void onTimeSet(TimePicker view, int hour, int minute) {
            mMyCalendar.set(Calendar.HOUR_OF_DAY, hour);
            mMyCalendar.set(Calendar.MINUTE, minute);
            resetDateTimeLabels();
            mBuilder.setDateTime(mMyCalendar);
            checkRequestAndSubmit();
        }
    };

    final DatePickerDialog.OnDateSetListener dateCallback = new DatePickerDialog.OnDateSetListener() {

        @Override
        public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
            mMyCalendar.set(Calendar.YEAR, year);
            mMyCalendar.set(Calendar.MONTH, monthOfYear);
            mMyCalendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
            resetDateTimeLabels();
            mBuilder.setDateTime(mMyCalendar);
            checkRequestAndSubmit();
        }

    };

    mDate.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                new DatePickerDialog(view.getContext(), dateCallback, mMyCalendar.get(Calendar.YEAR),
                        mMyCalendar.get(Calendar.MONTH), mMyCalendar.get(Calendar.DAY_OF_MONTH)).show();
            }

            return true;
        }
    });

    mTime.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View view, MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                new TimePickerDialog(view.getContext(), timeCallback, mMyCalendar.get(Calendar.HOUR_OF_DAY),
                        mMyCalendar.get(Calendar.MINUTE), false).show();
            }
            return true;
        }
    });

    ImageButton resetTimeButton = (ImageButton) view.findViewById(R.id.resetTimeImageButton);

    resetTimeButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mMyCalendar = Calendar.getInstance();
            mBuilder.setDateTime(mMyCalendar);
            resetDateTimeLabels();
            checkRequestAndSubmit();
        }
    });

    setUpAutocomplete(mFromAddressTextArea, USE_FROM_ADDRESS);
    setUpAutocomplete(mToAddressTextArea, USE_TO_ADDRESS);

    mToCurrentLocationImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mToAddressTextArea.setText(getString(R.string.tripplanner_current_location));
            mToAddress = makeAddressFromLocation();
            mBuilder.setTo(mToAddress);
            checkRequestAndSubmit();
        }
    });

    mFromCurrentLocationImageButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mFromAddressTextArea.setText(getString(R.string.tripplanner_current_location));
            mFromAddress = makeAddressFromLocation();
            mBuilder.setFrom(mFromAddress);
            checkRequestAndSubmit();
        }
    });

    // Start: default from address is Current Location, to address is unset
    return view;
}