List of usage examples for android.widget DatePicker getYear
public int getYear()
From source file:at.florian_lentsch.expirysync.EditProductActivity.java
/** * Updates the entry that is being edited with data entered by the user *///from w ww . j av a 2 s . c o m private void updateCurrentEntryFromFormData() { final DatabaseManager dbManager = DatabaseManager.getInstance(); EditText nameField = ((EditText) findViewById(R.id.product_name_field)); EditText amountField = ((EditText) findViewById(R.id.amount_field)); String amountStr = amountField.getText().toString(); this.curEntry.article.barcode = ((EditText) findViewById(R.id.barcode_field)).getText().toString(); this.curEntry.article.name = nameField.getText().toString(); this.curEntry.article = dbManager.updateOrAddArticle(this.curEntry.article); if (amountStr.trim().equals("")) { amountStr = DEFAULT_AMOUNT; } this.curEntry.amount = Integer.parseInt(amountStr); this.curEntry.description = ((EditText) findViewById(R.id.product_description_field)).getText().toString(); DatePicker datePicker = (DatePicker) findViewById(R.id.expiration_date_field); this.curEntry.expiration_date = (new GregorianCalendar(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth())).getTime(); }
From source file:edu.rit.csh.androidwebnews.SearchActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DatePicker startDate; setContentView(R.layout.activity_search); dialog = new InvalidApiKeyDialog(this); hc = new HttpsConnector(this); hc.getNewsGroups(); // used for list of newsgroups to look through sf = (SearchFragment) getSupportFragmentManager().findFragmentById(R.id.search_fragment); startDate = (DatePicker) findViewById(R.id.search_datePicker1); startDate.init(startDate.getYear() - 1, startDate.getMonth(), startDate.getDayOfMonth(), null); setTitle("Search"); }
From source file:ca.ualberta.cs.cmput301w15t04team04project.EditItemActivity.java
/** * <ol>/*from w ww .ja va 2s . c o m*/ * <li type = "square">The item of the option menu will call this function to confirm the change. * <ul> * <li>It will find the needed views by their id * <li>It will test the user chose to either edit or add an Item * <li>It will save the change that a user made * </ul> * </ol> * @param item The option item which belongs to the option menu. * @author Yufei Zhang * @version 1.0 * @since 2015-03-02 */ public void confirm(MenuItem item) { /** * we need to add code here doing the following things: 1. Add a new * item to the current claim 2. Update the changes of the chosen item **/ /** * this part should be in controller. Chenrui */ // get the views boolean completeCheck = true; EditText itemName = (EditText) findViewById(R.id.itemNameEditText); DatePicker itemDateDatePicker = (DatePicker) findViewById(R.id.itemDateDatePicker); Calendar calendar = Calendar.getInstance(); calendar.set(itemDateDatePicker.getYear(), itemDateDatePicker.getMonth(), itemDateDatePicker.getDayOfMonth()); Spinner itemCategorySpinner = (Spinner) findViewById(R.id.itemCategorySpinner); Spinner currencyUnitsSpinner = (Spinner) findViewById(R.id.currencyUnitsSpinner); EditText itemCurrencyEeditText = (EditText) findViewById(R.id.itemCurrencyEditText); EditText fragmentEditItem2DiscriptionEditText = (EditText) findViewById( R.id.fragmentEditItem2DiscriptionEditText); ImageButton imageButton = (ImageButton) findViewById(R.id.addRecieptImageButton); // create an item if (addEditItemStatus == 0) { Item newitem = new Item(itemName.getText().toString()); newitem.setItemDate(calendar.getTime()); newitem.setItemCategory(itemCategorySpinner.getSelectedItem().toString()); String tempAmountStr = itemCurrencyEeditText.getText().toString(); int tempAmountInt = 0; try { tempAmountInt = Integer.valueOf(tempAmountStr); } catch (NumberFormatException e) { tempAmountInt = 0; } Currency tempCurrency = new Currency(currencyUnitsSpinner.getSelectedItem().toString(), tempAmountInt); newitem.setItemCurrency(tempCurrency); newitem.setItemDescription(fragmentEditItem2DiscriptionEditText.getText().toString()); // controller.addItem(this.item); if (receiptFlag == 1) { newitem.setReceipBitmap(bitmap); } Toast.makeText(this, "added", Toast.LENGTH_LONG).show(); controller.addItem(newitem); UpdateThread update = new UpdateThread(controller.getClaim()); update.start(); /** * part end here */ } else { Toast.makeText(this, controller.getClaim().getClaim() + itemId + controller.getClaim().getItems().size(), Toast.LENGTH_LONG).show(); controller.getClaim().getPosition(itemId).setItemDate(calendar.getTime()); controller.getClaim().getPosition(itemId).setItemName(itemName.getText().toString()); controller.getClaim().getPosition(itemId) .setItemCategory(itemCategorySpinner.getSelectedItem().toString()); String tempAmountStr = itemCurrencyEeditText.getText().toString(); int tempAmountInt = 0; try { tempAmountInt = Integer.valueOf(tempAmountStr); } catch (NumberFormatException e) { tempAmountInt = 0; } Currency tempCurrency = new Currency(currencyUnitsSpinner.getSelectedItem().toString(), tempAmountInt); controller.getClaim().getPosition(itemId).setItemCurrency(tempCurrency); controller.getClaim().getPosition(itemId) .setItemDescription(fragmentEditItem2DiscriptionEditText.getText().toString()); if (receiptFlag == 1) { controller.getClaim().getPosition(itemId).setReceipBitmap(bitmap); } UpdateThread update = new UpdateThread(controller.getClaim()); update.start(); } Intent intent = new Intent(EditItemActivity.this, OneClaimActivity.class); intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("MyClaimName", claimName); startActivity(intent); finish(); }
From source file:com.spacejake.jake.ultimatepurduediner.NavigationDrawerFragment.java
public void showDatePicker() { new DatePickerDialog(getActivity(), new DatePickerDialog.OnDateSetListener() { @Override//w ww .j a v a 2 s. c o m public void onDateSet(DatePicker datePicker, int year, int month, int day) { if (!dateSet) { Calendar cal = Calendar.getInstance(); ((MainActivity) getActivity()).dateChange(year, month, day); if (datePicker.getDayOfMonth() == cal.get(Calendar.DAY_OF_MONTH) && datePicker.getYear() == cal.get(Calendar.YEAR)) { datePickerButton.setTitle("Today"); } else { DateFormatSymbols dfs = new DateFormatSymbols(new Locale("en")); cal.set(year, month, day); datePickerButton.setTitle(String.format("%s, %d/%d/%d", dfs.getShortWeekdays()[cal.get(Calendar.DAY_OF_WEEK)], month + 1, day, year)); } dateSet = true; } else { dateSet = false; } } }, year, month, day).show(); }
From source file:pro.jariz.reisplanner.fragments.PlannerFragment.java
public Bundle BuildBundle() { //create bundle from views to pass to select activity Bundle bundle = new Bundle(); AutoCompleteTextView auto = (AutoCompleteTextView) thisView.findViewById(R.id.AutoCompleteTextView1); AutoCompleteTextView auto2 = (AutoCompleteTextView) thisView.findViewById(R.id.AutoCompleteTextView2); AutoCompleteTextView auto3 = (AutoCompleteTextView) thisView.findViewById(R.id.AutoCompleteTextView3); CheckBox check = (CheckBox) thisView.findViewById(R.id.extraOptions); DatePicker picker = (DatePicker) thisView.findViewById(R.id.datePicker1); TimePicker time = (TimePicker) thisView.findViewById(R.id.timePicker1); bundle.putString("from", auto.getText().toString()); bundle.putString("via", auto2.getText().toString()); bundle.putString("to", auto3.getText().toString()); if (check.isChecked()) { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm"); bundle.putString("date", format.format(new Date(picker.getYear(), picker.getMonth(), picker.getDayOfMonth(), time.getCurrentHour(), time.getCurrentMinute(), 0))); }//www . ja va2s . c o m return bundle; }
From source file:ca.ualberta.cs.cmput301w15t04team04project.EditClaimActivity.java
/** * This function controls the MenuItem and shown as a on the scream.<br> * <ol>The MenuItem has the following functions: * <ul>//w w w . j a v a 2s .c om * <li>The function will find all needed views by their id. * <li>The function will test the user chooses either adding or editing. * <li>If user chooses to add a claim, the class "AddThread" will be called * <li>Else if user chooses to edit a claim, the class "updateThread will be called * </ul> * </ol> * * @author Chenrui Lei * @author Ji Yang * @author Yufei Zhang * @version 1.1 * @since 2015-03-12 * @version 1.2 * @since 2015-03-20 */ @SuppressWarnings("deprecation") public void confirmClaim(MenuItem item) { EditText claimName = (EditText) findViewById(R.id.claimNameEditText); EditText description = (EditText) findViewById(R.id.descriptionEditText); EditText tag = (EditText) findViewById(R.id.tagEditText); DatePicker fromDatePicker = (DatePicker) findViewById(R.id.fromDatePicker); DatePicker toDatePicker = (DatePicker) findViewById(R.id.toDatePicker); Date sDate = new Date(); Date eDate = new Date(); String cName = claimName.getText().toString(); String cDescription = description.getText().toString(); String cTag = tag.getText().toString(); sDate.setDate(fromDatePicker.getDayOfMonth()); sDate.setMonth(fromDatePicker.getMonth()); sDate.setYear(fromDatePicker.getYear() - 1900); eDate.setDate(toDatePicker.getDayOfMonth()); eDate.setMonth(toDatePicker.getMonth()); eDate.setYear(toDatePicker.getYear() - 1900); if (addEditStatus == 0) { ArrayList<Item> cItem = new ArrayList<Item>(); ArrayList<String> cComments = new ArrayList<String>(); Claim claim = controller.setClaim(cName, cDescription, cTag, sDate, eDate, destinationList, user.getName(), cItem, cComments, claimLocation); Thread add = new AddThread(claim); add.start(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } else { Claim claim = controller.setClaim(cName, cDescription, cTag, sDate, eDate, destinationList, user.getName(), items, comments, claimLocation); Thread update = new UpdateThread(claim); update.start(); try { Thread.sleep(500); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:com.kunze.androidlocaltodo.TaskListActivity.java
private void ShowTaskDialog(Task task, OnClickListener okListener) { LayoutInflater inflater = this.getLayoutInflater(); View dlgView = inflater.inflate(R.layout.dialog_task, null); AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setView(dlgView);/*from w w w .j av a 2s. c o m*/ builder.setTitle("Task"); final TextView nameEdit = (TextView) dlgView.findViewById(R.id.task_name_edit); nameEdit.setText(task.mName); final TextView descriptionEdit = (TextView) dlgView.findViewById(R.id.task_description_edit); descriptionEdit.setText(task.mDescription); final TextView dueDateView = (TextView) dlgView.findViewById(R.id.task_due_date); SetFriendlyDueDateText(dueDateView, task.mDueDate); Button dueDateButton = (Button) dlgView.findViewById(R.id.task_due_date_choose); final Calendar dueDate = task.mDueDate; final Task thisTask = task; dueDateButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ShowDueDateDialog(dueDate, new OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int id) { Dialog dlg = (Dialog) dialogInterface; DatePicker datePicker = (DatePicker) dlg.findViewById(R.id.due_date_calendar); Calendar calendar = Calendar.getInstance(); calendar.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); thisTask.mDueDate = calendar; SetFriendlyDueDateText(dueDateView, thisTask.mDueDate); } }); } }); final CheckBox repeatCheck = (CheckBox) dlgView.findViewById(R.id.repeat); repeatCheck.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { View dialog = (View) buttonView.getParent(); SetRepeatVisibility(dialog, isChecked); } }); Boolean repeat = task.mRepeatUnit != Task.RepeatUnit.NONE; repeatCheck.setChecked(repeat); SetRepeatVisibility(dlgView, repeat); final EditText repeatTimeEdit = (EditText) dlgView.findViewById(R.id.repeat_time); repeatTimeEdit.setText(Integer.toString(task.mRepeatTime)); final Spinner repeatUnitSpinner = (Spinner) dlgView.findViewById(R.id.repeat_unit); String[] repeatUnits = { "Days", "Weeks", "Months", "Years" }; repeatUnitSpinner .setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, repeatUnits)); int repeatUnitPos = 0; switch (task.mRepeatUnit) { case DAYS: repeatUnitPos = 0; break; case WEEKS: repeatUnitPos = 1; break; case MONTHS: repeatUnitPos = 2; break; case YEARS: repeatUnitPos = 3; break; case NONE: repeatUnitPos = 0; } repeatUnitSpinner.setSelection(repeatUnitPos); final RadioButton repeatFromComplete = (RadioButton) dlgView.findViewById(R.id.repeat_from_complete); final RadioButton repeatFromDue = (RadioButton) dlgView.findViewById(R.id.repeat_from_due); if (task.mRepeatFromComplete) { repeatFromComplete.setChecked(true); } else { repeatFromDue.setChecked(true); } // Here's a trick: We cascade the OnClick listeners so we can extract // the dialog contents into the task before calling the second listener. final OnClickListener userListener = okListener; final Task myTask = task; OnClickListener cascadedListener = new OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { myTask.mName = nameEdit.getText().toString(); myTask.mDescription = descriptionEdit.getText().toString(); myTask.mRepeatUnit = Task.RepeatUnit.NONE; if (repeatCheck.isChecked()) { switch (repeatUnitSpinner.getSelectedItemPosition()) { case 0: myTask.mRepeatUnit = Task.RepeatUnit.DAYS; break; case 1: myTask.mRepeatUnit = Task.RepeatUnit.WEEKS; break; case 2: myTask.mRepeatUnit = Task.RepeatUnit.MONTHS; break; case 3: myTask.mRepeatUnit = Task.RepeatUnit.YEARS; break; } myTask.mRepeatTime = Integer.parseInt(repeatTimeEdit.getText().toString()); myTask.mRepeatFromComplete = repeatFromComplete.isChecked(); } userListener.onClick(dialog, which); } }; builder.setNegativeButton("Cancel", null); builder.setPositiveButton("OK", cascadedListener); builder.show(); }
From source file:net.reichholf.dreamdroid.activities.TimerEditActivity.java
/** * @param dialog//from w w w . jav a 2s .c o m * The dialog containing the date and the time picker * @return <code>Calendar</code> container set to the date and time of the * Date- and TimePicker */ private Calendar getCalendarFromPicker(final Dialog dialog) { Calendar cal = GregorianCalendar.getInstance(); DatePicker dp = (DatePicker) dialog.findViewById(R.id.DatePicker); TimePicker tp = (TimePicker) dialog.findViewById(R.id.TimePicker); cal.set(Calendar.YEAR, dp.getYear()); cal.set(Calendar.MONTH, dp.getMonth()); cal.set(Calendar.DAY_OF_MONTH, dp.getDayOfMonth()); cal.set(Calendar.HOUR_OF_DAY, tp.getCurrentHour()); cal.set(Calendar.MINUTE, tp.getCurrentMinute()); cal.set(Calendar.SECOND, 0); return cal; }
From source file:com.medisa.myspacecal.Range.java
@Override public void onSideNavigationItemClick(int itemId) { switch (itemId) { case R.id.side_navigation_menu_calendario: range = 0;/*w w w. ja v a2 s. c o m*/ Intent i = new Intent(this, MainActivity.class); startActivity(i); break; case R.id.side_navigation_menu_date_range: // custom dialog final Dialog dialog = new Dialog(this); dialog.setContentView(R.layout.custom_range_date); dialog.setTitle("Data range"); // set the custom dialog components - text, image and button final DatePicker dpStart = (DatePicker) dialog.findViewById(R.id.dpStart); final DatePicker dpEnd = (DatePicker) dialog.findViewById(R.id.dpEnd); Button btnSalva = (Button) dialog.findViewById(R.id.btnSalva); final CheckBox cbIntegralBox = (CheckBox) dialog.findViewById(R.id.cbIntegral); // if button is clicked, close the custom dialog btnSalva.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { dateStart = Funzioni.addZero(dpStart.getDayOfMonth(), 2) + "-" + Funzioni.addZero(dpStart.getMonth(), 2) + "-" + dpStart.getYear(); dateEnd = Funzioni.addZero(dpEnd.getDayOfMonth(), 2) + "-" + Funzioni.addZero(dpEnd.getMonth(), 2) + "-" + dpEnd.getYear(); Log.e(dateStart, dateEnd); if (cbIntegralBox.isChecked()) { //#########################JSON AsyncHttpClient client = new AsyncHttpClient(); client.get("http://199.180.196.10/json/integral?startdate=" + dateStart + "&enddate=" + dateEnd, new AsyncHttpResponseHandler() { @Override public void onSuccess(String response) { Log.e("SCARICATO", response); JSONArray jObject; try { jObject = new JSONArray(response); for (int i = 0; i < jObject.length(); i++) { JSONArray menuObject = jObject.getJSONArray(i); String dataStart = menuObject.getString(0); String dataEnd = menuObject.getString(1); String raj2000 = menuObject.getString(2); String decj2000 = menuObject.getString(3); String target = menuObject.getString(4); Log.e("", dataStart + " " + dataEnd + " " + raj2000 + " " + decj2000 + " " + target); satellitiIntegral.add(new SatelliteIntegral(dataStart, dataEnd, raj2000, decj2000, target)); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } dialog.dismiss(); // Intent mioIntent= new Intent(ctx, Range.class); // startActivity(mioIntent); } }); dialog.show(); break; // case R.id.side_navigation_menu_item3: // invokeActivity(getString(R.string.title3), R.drawable.ic_android3); // break; // // case R.id.side_navigation_menu_item4: // invokeActivity(getString(R.string.title4), R.drawable.ic_android4); // break; // // case R.id.side_navigation_menu_item5: // invokeActivity(getString(R.string.title5), R.drawable.ic_android5); // break; default: return; } }
From source file:com.sixwonders.courtkiosk.CheckInActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); activity = this; view = LayoutInflater.from(this).inflate(R.layout.activity_check_in, null); btnInfoSubmit = (Button) view.findViewById(R.id.btnInfoSubmit); btnIdScan = (Button) view.findViewById(R.id.btnLicenseScan); btnIdScan.setOnClickListener(new View.OnClickListener() { @Override// www . j ava 2 s.co m public void onClick(View view) { callToScan(); } }); btnInfoSubmit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(view.getContext()); builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { } }); final View custom = LayoutInflater.from(activity) .inflate(R.layout.check_in_personal_info_alertdialog, null); builder.setTitle(R.string.userInformationInput).setPositiveButton(R.string.continueText, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { //TODO call webservice to check for user EditText firstName = (EditText) custom.findViewById(R.id.etFirstName); EditText lastName = (EditText) custom.findViewById(R.id.etLastName); DatePicker dob = (DatePicker) custom.findViewById(R.id.dpDob); if (dob == null) { int i = 0; i++; i++; } int monthInt = dob.getMonth() + 1; String month = ""; if (monthInt < 10) { month += "0"; } month += monthInt; int dayInt = dob.getDayOfMonth(); String day = ""; if (dayInt < 10) { day += "0"; } day += dayInt; int yearInt = dob.getYear(); String year = ""; if (yearInt < 10) { year += "0"; } year += yearInt; String dobStr = month + "/" + day + "/" + year; ConnectionUtil connectionUtil = new ConnectionUtil(); connectionUtil.authCall(firstName.getText().toString(), lastName.getText().toString(), dobStr, (AsyncResponse) activity); } }); builder.setView(custom); datePicker = (DatePicker) custom.findViewById(R.id.dpDob); setUpDatePicker(); AlertDialog alert = builder.create(); alert.show(); } }); setContentView(view); }