List of usage examples for android.widget DatePicker getMonth
public int getMonth()
From source file:org.cobaltians.cobalt.fragments.CobaltDatePickerFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { Bundle args = getArguments();/*from www.j a va 2s . co m*/ if (args != null) { int year = args.getInt(ARG_YEAR); int month = args.getInt(ARG_MONTH); int day = args.getInt(ARG_DAY); mCallbackId = args.getString(ARG_CALLBACK_ID); mTitle = args.getString(ARG_TITLE); mDelete = args.getString(ARG_DELETE); mCancel = args.getString(ARG_CANCEL); mValidate = args.getString(ARG_VALIDATE); if (year != 0 && month >= 0 && day != 0) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } } if (mDelete == null && mCancel == null && mValidate == null && mTitle == null) { return new DatePickerDialog(mContext, this, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH)); } else { LayoutInflater inflater = ((Activity) mContext).getLayoutInflater(); final DatePicker datePicker = (DatePicker) inflater.inflate(R.layout.date_picker_cobalt, null); AlertDialog.Builder datePickerBuilder = new AlertDialog.Builder(mContext); datePickerBuilder.setView(datePicker); /* // Init the datePicker with mindate under 1900 //TODO test for under HoneyComb if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { final SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy", Locale.FRANCE); Calendar minDate = Calendar.getInstance(); try { minDate.setTime(formatter.parse("01.01.1800")); } catch (ParseException e) { e.printStackTrace(); } datePicker.setMinDate(minDate.getTimeInMillis()); } else { datePicker.init(1800, 01, 01, new OnDateChangedListener() { @Override public void onDateChanged(DatePicker datePicker, int year, int month, int day) { Calendar newDate = Calendar.getInstance(); newDate.set(year, month, day); } }); }*/ // View settings int year = cal.get(Calendar.YEAR); int month = cal.get(Calendar.MONTH); int day = cal.get(Calendar.DAY_OF_MONTH); if (mTitle != null) { datePickerBuilder.setTitle(mTitle); } // Buttons datePickerBuilder.setNegativeButton(mDelete, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.clear(); if (mListener != null) { mListener.sendDate(-1, -1, -1, mCallbackId); } } }); datePickerBuilder.setNeutralButton(mCancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { dialog.dismiss(); } }); datePickerBuilder.setPositiveButton(mValidate, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { cal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); if (mListener != null) { mListener.sendDate(cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH), mCallbackId); } dialog.dismiss(); } }); final AlertDialog dialog = datePickerBuilder.create(); datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int month, int day) { cal.set(Calendar.YEAR, year); cal.set(Calendar.MONTH, month); cal.set(Calendar.DAY_OF_MONTH, day); } }); return dialog; } }
From source file:com.roque.rueda.cashflows.fragments.AddMovementFragment.java
/** * Create a date time dialog to allow the user choose the date for the movement. * *///from w w w . java 2s . co m private void createDateTimeDialog() { // Add a listener to display a dialog when the user taps on this view. mDateText.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Set the current date if it's one the saved instance object. final Calendar c = Calendar.getInstance(); c.setTimeInMillis(mCurrentDate); // Dialog settings. AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), AlertDialog.THEME_HOLO_DARK); LayoutInflater layoutInflater = getActivity().getLayoutInflater(); builder.setTitle(R.string.time_date_dialog_title); // Custom view used to display date picker and time picker. View dateTimeLayout = layoutInflater.inflate(R.layout.date_time_layout, null); // Text used to display the selected date. final TextView selectedDate = (TextView) dateTimeLayout.findViewById(R.id.selected_date); final Date selectedDateByUser = new Date(getInputDate()); selectedDate.setText(StringFormatter.formatDate(selectedDateByUser)); final DatePicker datePicker = (DatePicker) dateTimeLayout.findViewById(R.id.date_picker); final TimePicker timePicker = (TimePicker) dateTimeLayout.findViewById(R.id.time_picker); Calendar calendar = Calendar.getInstance(); calendar.setTime(selectedDateByUser); int year = calendar.get(Calendar.YEAR); int month = calendar.get(Calendar.MONTH); int day = calendar.get(Calendar.DAY_OF_MONTH); int hourOfTheDay = calendar.get(Calendar.HOUR_OF_DAY); int minute = calendar.get(Calendar.MINUTE); timePicker.setCurrentHour(hourOfTheDay); timePicker.setCurrentMinute(minute); // Initialize the date picker, also add a listener to // update the label when user change the values. datePicker.init(year, month, day, new DatePicker.OnDateChangedListener() { @Override public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, year); calendar.set(Calendar.MONTH, monthOfYear); calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth); calendar.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour()); calendar.set(Calendar.MINUTE, timePicker.getCurrentMinute()); calendar.set(Calendar.SECOND, 0); Date modifyDate = calendar.getTime(); // Update the text view. selectedDate.setText(StringFormatter.formatDate(modifyDate)); } }); // Listener used to update the values when time is selected. timePicker.setOnTimeChangedListener(new TimePicker.OnTimeChangedListener() { @Override public void onTimeChanged(TimePicker view, int hourOfDay, int minute) { Calendar calendar = Calendar.getInstance(); calendar.set(Calendar.YEAR, datePicker.getYear()); calendar.set(Calendar.MONTH, datePicker.getMonth()); calendar.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth()); calendar.set(Calendar.HOUR_OF_DAY, hourOfDay); calendar.set(Calendar.MINUTE, minute); calendar.set(Calendar.SECOND, 0); Date modifyDate = calendar.getTime(); // Update the text view. selectedDate.setText(StringFormatter.formatDate(modifyDate)); } }); // Set the view to the dialog. builder.setView(dateTimeLayout); // Accept button behaviour. builder.setPositiveButton(R.string.accept, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Calendar dialogDate = Calendar.getInstance(); dialogDate.set(Calendar.YEAR, datePicker.getYear()); dialogDate.set(Calendar.MONTH, datePicker.getMonth()); dialogDate.set(Calendar.DAY_OF_MONTH, datePicker.getDayOfMonth()); dialogDate.set(Calendar.HOUR_OF_DAY, timePicker.getCurrentHour()); dialogDate.set(Calendar.MINUTE, timePicker.getCurrentMinute()); dialogDate.set(Calendar.SECOND, 0); setCurrentDateText(dialogDate.getTime()); dialog.dismiss(); } }); // Cancel button behaviour. builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.cancel(); } }); // Create and display the dialog. Dialog dateDialog = builder.create(); dateDialog.show(); } }); }
From source file:org.sufficientlysecure.keychain.ui.dialog.EditSubkeyExpiryDialogFragment.java
/** * Creates dialog/*from www. ja va 2 s.c o m*/ */ @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { Activity activity = getActivity(); mMessenger = getArguments().getParcelable(ARG_MESSENGER); long creation = getArguments().getLong(ARG_CREATION); long expiry = getArguments().getLong(ARG_EXPIRY); final Calendar creationCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); creationCal.setTimeInMillis(creation * 1000); Calendar expiryCal = Calendar.getInstance(TimeZone.getTimeZone("UTC")); expiryCal.setTimeInMillis(expiry * 1000); // date picker works with default time zone, we need to convert from UTC to default timezone creationCal.setTimeZone(TimeZone.getDefault()); expiryCal.setTimeZone(TimeZone.getDefault()); // Explicitly not using DatePickerDialog here! // DatePickerDialog is difficult to customize and has many problems (see old git versions) CustomAlertDialogBuilder alert = new CustomAlertDialogBuilder(activity); alert.setTitle(R.string.expiry_date_dialog_title); LayoutInflater inflater = activity.getLayoutInflater(); View view = inflater.inflate(R.layout.edit_subkey_expiry_dialog, null); alert.setView(view); final CheckBox noExpiry = (CheckBox) view.findViewById(R.id.edit_subkey_expiry_no_expiry); final DatePicker datePicker = (DatePicker) view.findViewById(R.id.edit_subkey_expiry_date_picker); final TextView currentExpiry = (TextView) view.findViewById(R.id.edit_subkey_expiry_current_expiry); final LinearLayout expiryLayout = (LinearLayout) view.findViewById(R.id.edit_subkey_expiry_layout); noExpiry.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) { expiryLayout.setVisibility(View.GONE); } else { expiryLayout.setVisibility(View.VISIBLE); } } }); if (expiry == 0L) { noExpiry.setChecked(true); expiryLayout.setVisibility(View.GONE); currentExpiry.setText(R.string.btn_no_date); } else { noExpiry.setChecked(false); expiryLayout.setVisibility(View.VISIBLE); currentExpiry.setText(DateFormat.getDateFormat(getActivity()).format(expiryCal.getTime())); } // date picker works based on default time zone Calendar todayCal = Calendar.getInstance(TimeZone.getDefault()); if (creationCal.after(todayCal)) { // NOTE: This is just for the rare cases where creation is _after_ today // Min Date: Creation date + 1 day Calendar creationCalPlusOne = (Calendar) creationCal.clone(); creationCalPlusOne.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(creationCalPlusOne.getTime().getTime()); datePicker.init(creationCalPlusOne.get(Calendar.YEAR), creationCalPlusOne.get(Calendar.MONTH), creationCalPlusOne.get(Calendar.DAY_OF_MONTH), null); } else { // Min Date: today + 1 day // at least one day after creation (today) todayCal.add(Calendar.DAY_OF_YEAR, 1); datePicker.setMinDate(todayCal.getTime().getTime()); datePicker.init(todayCal.get(Calendar.YEAR), todayCal.get(Calendar.MONTH), todayCal.get(Calendar.DAY_OF_MONTH), null); } alert.setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); long expiry; if (noExpiry.isChecked()) { expiry = 0L; } else { Calendar selectedCal = Calendar.getInstance(TimeZone.getDefault()); //noinspection ResourceType selectedCal.set(datePicker.getYear(), datePicker.getMonth(), datePicker.getDayOfMonth()); // date picker uses default time zone, we need to convert to UTC selectedCal.setTimeZone(TimeZone.getTimeZone("UTC")); long numDays = (selectedCal.getTimeInMillis() / 86400000) - (creationCal.getTimeInMillis() / 86400000); if (numDays <= 0) { Activity activity = getActivity(); if (activity != null) { Notify.create(activity, R.string.error_expiry_past, Style.ERROR).show(); } return; } expiry = selectedCal.getTime().getTime() / 1000; } Bundle data = new Bundle(); data.putSerializable(MESSAGE_DATA_EXPIRY, expiry); sendMessageToHandler(MESSAGE_NEW_EXPIRY, data); } }); alert.setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return alert.show(); }
From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java
public void processNextButtonPressed() { wasNextButtonPressed = true;/*w w w.ja v a 2 s. c o m*/ hasUpdatedDecisionTrackerContainer = false; //edited by Mike, 20160417 if ((mTts != null) && (mTts.isSpeaking())) { mTts.stop(); } //edited by Mike, 20160417 if ((myMediaPlayer != null) && (myMediaPlayer.isPlaying())) { myMediaPlayer.stop(); } if (currAudioRecorder != null) { try { //if stop button is pressable if (stopButton.isEnabled()) { currAudioRecorder.stop(); } if (currAudioRecorder.isPlaying()) { currAudioRecorder.stopPlayback(); } } catch (Exception e) { e.printStackTrace(); } String path = currAudioRecorder.getPath(); // System.out.println(">>>>>>>>>>>>>>>>>>>currAudioRecorder: "+currAudioRecorder); if (!attachmentFilePaths.contains(path)) { attachmentFilePaths.add(path); // System.out.println(">>>>>>>>>>>>>>>>adding path: "+path); } } //END_STATE_SCREEN = last screen if (currScreen == UsbongConstants.END_STATE_SCREEN) { int usbongAnswerContainerSize = usbongAnswerContainer.size(); StringBuffer outputStringBuffer = new StringBuffer(); for (int i = 0; i < usbongAnswerContainerSize; i++) { outputStringBuffer.append(usbongAnswerContainer.elementAt(i)); } myOutputDirectory = UsbongUtils.getDateTimeStamp() + "/"; if (UsbongUtils.STORE_OUTPUT) { try { UsbongUtils.createNewOutputFolderStructure(); } catch (Exception e) { e.printStackTrace(); } UsbongUtils.storeOutputInSDCard( UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getDateTimeStamp() + ".csv", outputStringBuffer.toString()); } else { UsbongUtils.deleteRecursive(new File(UsbongUtils.BASE_FILE_PATH + myOutputDirectory)); } //wasNextButtonPressed=false; //no need to make this true, because this is the last node hasUpdatedDecisionTrackerContainer = true; /* //send to server UsbongUtils.performFileUpload(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getTimeStamp() + ".csv"); //send to email Intent emailIntent = UsbongUtils.performEmailProcess(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getTimeStamp() + ".csv", attachmentFilePaths); emailIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); // emailIntent.addFlags(RESULT_OK); startActivityForResult(Intent.createChooser(emailIntent, "Email:"),EMAIL_SENDING_SUCCESS); */ //added by Mike, Sept. 10, 2014 UsbongUtils.clearTempFolder(); //added by Mike, 20160415 if (UsbongUtils.IS_IN_AUTO_LOOP_MODE) { //added by Mike, 20161118 AppRater.showRateDialog(this); isAutoLoopedTree = true; initParser(myTree); return; } else { //return to main activity finish(); //added by Mike, 20161118 Intent toUsbongMainActivityIntent = new Intent(UsbongDecisionTreeEngineActivity.this, UsbongMainActivity.class); toUsbongMainActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); toUsbongMainActivityIntent.putExtra("completed_tree", "true"); startActivity(toUsbongMainActivityIntent); } } else { if (currScreen == UsbongConstants.YES_NO_DECISION_SCREEN) { RadioButton myYesRadioButton = (RadioButton) findViewById(R.id.yes_radiobutton); RadioButton myNoRadioButton = (RadioButton) findViewById(R.id.no_radiobutton); if (myYesRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else if (myNoRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfNo; // usbongAnswerContainer.addElement("N;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "N;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else { //if no radio button was checked if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } } else if (currScreen == UsbongConstants.SEND_TO_WEBSERVER_SCREEN) { RadioButton myYesRadioButton = (RadioButton) findViewById(R.id.yes_radiobutton); RadioButton myNoRadioButton = (RadioButton) findViewById(R.id.no_radiobutton); if (myYesRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfYes; // usbongAnswerContainer.addElement("Y;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; decisionTrackerContainer.addElement(usbongAnswerContainer.lastElement()); // wasNextButtonPressed=false; //no need to make this true, because "Y;" has already been added to decisionTrackerContainer hasUpdatedDecisionTrackerContainer = true; //edited by Mike, March 4, 2013 //"save" the output into the SDCard as "output.txt" // int usbongAnswerContainerSize = usbongAnswerContainer.size(); int usbongAnswerContainerSize = usbongAnswerContainerCounter; StringBuffer outputStringBuffer = new StringBuffer(); for (int i = 0; i < usbongAnswerContainerSize; i++) { outputStringBuffer.append(usbongAnswerContainer.elementAt(i)); } myOutputDirectory = UsbongUtils.getDateTimeStamp() + "/"; try { UsbongUtils.createNewOutputFolderStructure(); } catch (Exception e) { e.printStackTrace(); } UsbongUtils.storeOutputInSDCard(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getDateTimeStamp() + ".csv", outputStringBuffer.toString()); //send to server UsbongUtils.performFileUpload(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getDateTimeStamp() + ".csv"); } else if (myNoRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfNo; // usbongAnswerContainer.addElement("N;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "N;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; } else { //if no radio button was checked if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; // initParser(); } initParser(); } else if (currScreen == UsbongConstants.SEND_TO_CLOUD_BASED_SERVICE_SCREEN) { RadioButton myYesRadioButton = (RadioButton) findViewById(R.id.yes_radiobutton); RadioButton myNoRadioButton = (RadioButton) findViewById(R.id.no_radiobutton); if (myYesRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfYes; // usbongAnswerContainer.addElement("Y;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; decisionTrackerContainer.addElement(usbongAnswerContainer.lastElement()); // wasNextButtonPressed=false; //no need to make this true, because "Y;" has already been added to decisionTrackerContainer hasUpdatedDecisionTrackerContainer = true; StringBuffer sb = new StringBuffer(); for (int i = 0; i < decisionTrackerContainer.size(); i++) { sb.append(decisionTrackerContainer.elementAt(i)); } Log.d(">>>>>>>>>>>>>decisionTrackerContainer", sb.toString()); //edited by Mike, March 4, 2013 //"save" the output into the SDCard as "output.txt" // int usbongAnswerContainerSize = usbongAnswerContainer.size(); int usbongAnswerContainerSize = usbongAnswerContainerCounter; StringBuffer outputStringBuffer = new StringBuffer(); for (int i = 0; i < usbongAnswerContainerSize; i++) { outputStringBuffer.append(usbongAnswerContainer.elementAt(i)); } myOutputDirectory = UsbongUtils.getDateTimeStamp() + "/"; try { UsbongUtils.createNewOutputFolderStructure(); } catch (Exception e) { e.printStackTrace(); } UsbongUtils.storeOutputInSDCard(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getDateTimeStamp() + ".csv", outputStringBuffer.toString()); //send to cloud-based service Intent sendToCloudBasedServiceIntent = UsbongUtils .performSendToCloudBasedServiceProcess(UsbongUtils.BASE_FILE_PATH + myOutputDirectory + UsbongUtils.getDateTimeStamp() + ".csv", attachmentFilePaths); /*emailIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); */ // emailIntent.addFlags(RESULT_OK); // startActivityForResult(Intent.createChooser(emailIntent, "Email:"),EMAIL_SENDING_SUCCESS); //answer from Llango J, stackoverflow //Reference: http://stackoverflow.com/questions/7479883/problem-with-sending-email-goes-back-to-previous-activity; //last accessed: 22 Oct. 2012 startActivity( Intent.createChooser(sendToCloudBasedServiceIntent, "Send to Cloud-based Service:")); } else if (myNoRadioButton.isChecked()) { currUsbongNode = nextUsbongNodeIfNo; // usbongAnswerContainer.addElement("N;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "N;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; } else { //if no radio button was checked if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; // initParser(); /* if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed=false; hasUpdatedDecisionTrackerContainer=true; return; } else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" // usbongAnswerContainer.addElement("A;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } */ } /* currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" usbongAnswerContainer.addElement("Any;"); */ initParser(); } else if (currScreen == UsbongConstants.MULTIPLE_CHECKBOXES_SCREEN) { // requiredTotalCheckedBoxes LinearLayout myMultipleCheckboxesLinearLayout = (LinearLayout) findViewById( R.id.multiple_checkboxes_linearlayout); StringBuffer sb = new StringBuffer(); int totalCheckedBoxes = 0; int totalCheckBoxChildren = myMultipleCheckboxesLinearLayout.getChildCount(); //begin with i=1, because i=0 is for checkboxes_textview for (int i = 1; i < totalCheckBoxChildren; i++) { if (((CheckBox) myMultipleCheckboxesLinearLayout.getChildAt(i)).isChecked()) { totalCheckedBoxes++; sb.append("," + (i - 1)); //do a (i-1) so that i starts with 0 for the checkboxes (excluding checkboxes_textview) to maintain consistency with the other components } } if (totalCheckedBoxes >= requiredTotalCheckedBoxes) { currUsbongNode = nextUsbongNodeIfYes; sb.insert(0, "Y"); //insert in front of stringBuffer sb.append(";"); } else { currUsbongNode = nextUsbongNodeIfNo; sb.delete(0, sb.length()); sb.append("N,;"); //make sure to add the comma } // usbongAnswerContainer.addElement(sb.toString()); UsbongUtils.addElementToContainer(usbongAnswerContainer, sb.toString(), usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else if (currScreen == UsbongConstants.MULTIPLE_RADIO_BUTTONS_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.multiple_radio_buttons_radiogroup); // if (UsbongUtils.IS_IN_DEBUG_MODE==false) { if (myRadioGroup.getCheckedRadioButtonId() == -1) { //no radio button checked if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); // } } else { // usbongAnswerContainer.addElement(myRadioGroup.getCheckedRadioButtonId()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, myRadioGroup.getCheckedRadioButtonId() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } // } /* else { // usbongAnswerContainer.addElement(myRadioGroup.getCheckedRadioButtonId()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, myRadioGroup.getCheckedRadioButtonId()+";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } */ } else if (currScreen == UsbongConstants.MULTIPLE_RADIO_BUTTONS_WITH_ANSWER_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.multiple_radio_buttons_radiogroup); /* if (UsbongUtils.IS_IN_DEBUG_MODE==false) { */ if (myRadioGroup.getCheckedRadioButtonId() == -1) { //no radio button checked if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //choose Yes if "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myRadioGroup.getCheckedRadioButtonId() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); // } } else { if (myMultipleRadioButtonsWithAnswerScreenAnswer .equals("" + myRadioGroup.getCheckedRadioButtonId())) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y," + myRadioGroup.getCheckedRadioButtonId() + ";", usbongAnswerContainerCounter); } else { currUsbongNode = nextUsbongNodeIfNo; UsbongUtils.addElementToContainer(usbongAnswerContainer, "N," + myRadioGroup.getCheckedRadioButtonId() + ";", usbongAnswerContainerCounter); } usbongAnswerContainerCounter++; initParser(); } } else if (currScreen == UsbongConstants.LINK_SCREEN) { RadioGroup myRadioGroup = (RadioGroup) findViewById(R.id.multiple_radio_buttons_radiogroup); try { currUsbongNode = UsbongUtils.getLinkFromRadioButton( radioButtonsContainer.elementAt(myRadioGroup.getCheckedRadioButtonId())); } catch (Exception e) { //if the user hasn't ticked any radio button yet //put the currUsbongNode to default // currUsbongNode = UsbongUtils.getLinkFromRadioButton(nextUsbongNodeIfYes); //nextUsbongNodeIfNo will also do, since this is "Any" //of course, showPleaseAnswerAlert() will be called //edited by Mike, 20160613 //don't change the currUsbongNode anymore if no radio button has been ticked } // Log.d(">>>>>>>>>>currUsbongNode",currUsbongNode); if (myRadioGroup.getCheckedRadioButtonId() == -1) { //no radio button checked // if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_CHOOSE_AN_ANSWER_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } // } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); // } } else { // usbongAnswerContainer.addElement(myRadioGroup.getCheckedRadioButtonId()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, myRadioGroup.getCheckedRadioButtonId() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } /* } else { usbongAnswerContainer.addElement(myRadioGroup.getCheckedRadioButtonId()+";"); initParser(); } */ } else if ((currScreen == UsbongConstants.TEXTFIELD_SCREEN) || (currScreen == UsbongConstants.TEXTFIELD_WITH_UNIT_SCREEN) || (currScreen == UsbongConstants.TEXTFIELD_NUMERICAL_SCREEN)) { currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do EditText myTextFieldScreenEditText = (EditText) findViewById(R.id.textfield_edittext); // if (UsbongUtils.IS_IN_DEBUG_MODE==false) { //if it's blank if (myTextFieldScreenEditText.getText().toString().trim().equals("")) { if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_ANSWER_FIELD_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" // usbongAnswerContainer.addElement("A;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A,;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); // } } else { // usbongAnswerContainer.addElement("A,"+myTextFieldScreenEditText.getText()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myTextFieldScreenEditText.getText() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } } else if (currScreen == UsbongConstants.TEXTFIELD_WITH_ANSWER_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; EditText myTextFieldScreenEditText = (EditText) findViewById(R.id.textfield_edittext); //if it's blank if (myTextFieldScreenEditText.getText().toString().trim().equals("")) { if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_ANSWER_FIELD_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } currUsbongNode = nextUsbongNodeIfYes; //choose Yes if "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myTextFieldScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else { //added by Mike, Jan. 27, 2014 Vector<String> myPossibleAnswers = new Vector<String>(); StringTokenizer myPossibleAnswersStringTokenizer = new StringTokenizer( myTextFieldWithAnswerScreenAnswer, "||"); if (myPossibleAnswersStringTokenizer != null) { while (myPossibleAnswersStringTokenizer.hasMoreTokens()) { //get last element (i.e. Mike in "textFieldWithAnswer~Who is the founder of Usbong (nickname)?Answer=Mike") myPossibleAnswers.add(myPossibleAnswersStringTokenizer.nextToken()); } } int size = myPossibleAnswers.size(); for (int i = 0; i < size; i++) { if (myPossibleAnswers.elementAt(i) .equals(myTextFieldScreenEditText.getText().toString().trim())) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y," + myTextFieldScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); break; } if (i == size - 1) { //if this is the last element in the vector currUsbongNode = nextUsbongNodeIfNo; UsbongUtils.addElementToContainer(usbongAnswerContainer, "N," + myTextFieldScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); } } /* if (myTextFieldWithAnswerScreenAnswer.equals(myTextFieldScreenEditText.getText().toString().trim())) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y,"+myTextFieldScreenEditText.getText().toString().trim()+";", usbongAnswerContainerCounter); } else { currUsbongNode = nextUsbongNodeIfNo; UsbongUtils.addElementToContainer(usbongAnswerContainer, "N,"+myTextFieldScreenEditText.getText().toString().trim()+";", usbongAnswerContainerCounter); } */ usbongAnswerContainerCounter++; initParser(); } } else if ((currScreen == UsbongConstants.TEXTAREA_SCREEN)) { currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do EditText myTextAreaScreenEditText = (EditText) findViewById(R.id.textarea_edittext); // if (UsbongUtils.IS_IN_DEBUG_MODE==false) { //if it's blank if (myTextAreaScreenEditText.getText().toString().trim().equals("")) { if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_ANSWER_FIELD_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } // else { currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A,;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); // } } else { // usbongAnswerContainer.addElement("A,"+myTextAreaScreenEditText.getText()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myTextAreaScreenEditText.getText() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } } else if (currScreen == UsbongConstants.TEXTAREA_WITH_ANSWER_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; EditText myTextAreaScreenEditText = (EditText) findViewById(R.id.textarea_edittext); //if it's blank if (myTextAreaScreenEditText.getText().toString().trim().equals("")) { if (!UsbongUtils.IS_IN_DEBUG_MODE) { if (!isAnOptionalNode) { showRequiredFieldAlert(PLEASE_ANSWER_FIELD_ALERT_TYPE); wasNextButtonPressed = false; hasUpdatedDecisionTrackerContainer = true; return; } } currUsbongNode = nextUsbongNodeIfYes; //choose Yes if "Any" UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myTextAreaScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else { /* if (myTextAreaWithAnswerScreenAnswer.equals(myTextAreaScreenEditText.getText().toString().trim())) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y,"+myTextAreaScreenEditText.getText().toString().trim()+";", usbongAnswerContainerCounter); } else { currUsbongNode = nextUsbongNodeIfNo; UsbongUtils.addElementToContainer(usbongAnswerContainer, "N,"+myTextAreaScreenEditText.getText().toString().trim()+";", usbongAnswerContainerCounter); } */ //added by Mike, Jan. 27, 2014 Vector<String> myPossibleAnswers = new Vector<String>(); StringTokenizer myPossibleAnswersStringTokenizer = new StringTokenizer( myTextAreaWithAnswerScreenAnswer, "||"); if (myPossibleAnswersStringTokenizer != null) { while (myPossibleAnswersStringTokenizer.hasMoreTokens()) { //get last element (i.e. Mike in "textAreaWithAnswer~Who is the founder of Usbong (nickname)?Answer=Mike||mike") myPossibleAnswers.add(myPossibleAnswersStringTokenizer.nextToken()); } } int size = myPossibleAnswers.size(); for (int i = 0; i < size; i++) { // Log.d(">>>>>>myPossibleAnswers: ",myPossibleAnswers.elementAt(i)); if (myPossibleAnswers.elementAt(i) .equals(myTextAreaScreenEditText.getText().toString().trim())) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y," + myTextAreaScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); break; } if (i == size - 1) { //if this is the last element in the vector currUsbongNode = nextUsbongNodeIfNo; UsbongUtils.addElementToContainer(usbongAnswerContainer, "N," + myTextAreaScreenEditText.getText().toString().trim() + ";", usbongAnswerContainerCounter); } } usbongAnswerContainerCounter++; initParser(); } } else if (currScreen == UsbongConstants.GPS_LOCATION_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do TextView myLongitudeTextView = (TextView) findViewById(R.id.longitude_textview); TextView myLatitudeTextView = (TextView) findViewById(R.id.latitude_textview); // usbongAnswerContainer.addElement(myLongitudeTextView.getText()+","+myLatitudeTextView.getText()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myLongitudeTextView.getText() + "," + myLatitudeTextView.getText() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else if (currScreen == UsbongConstants.SIMPLE_ENCRYPT_SCREEN) { EditText myPinEditText = (EditText) findViewById(R.id.pin_edittext); if (myPinEditText.getText().toString().length() != 4) { String message = ""; if (currLanguageBeingUsed == UsbongUtils.LANGUAGE_FILIPINO) { message = (String) getResources().getText(R.string.Usbong4DigitsPinAlertMessageFILIPINO); } else if (currLanguageBeingUsed == UsbongUtils.LANGUAGE_JAPANESE) { message = (String) getResources().getText(R.string.Usbong4DigitsPinAlertMessageJAPANESE); } else { //if (udtea.currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { message = (String) getResources().getText(R.string.Usbong4DigitsPinAlertMessageENGLISH); } new AlertDialog.Builder(UsbongDecisionTreeEngineActivity.this).setTitle("Hey!") .setMessage(message).setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }).show(); } else { int yourKey = Integer.parseInt(myPinEditText.getText().toString()); currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; // Log.d(">>>>>>>start encode","encode"); for (int i = 0; i < usbongAnswerContainerCounter; i++) { try { usbongAnswerContainer.set(i, UsbongUtils.performSimpleFileEncrypt(yourKey, usbongAnswerContainer.elementAt(i))); // Log.d(">>>>>>"+i,""+usbongAnswerContainer.get(i)); // Log.d(">>>decoded"+i,""+UsbongUtils.performSimpleFileDecode(yourKey, usbongAnswerContainer.get(i))); } catch (Exception e) { e.printStackTrace(); } } initParser(); } } else if (currScreen == UsbongConstants.DATE_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; //added by Mike, 13 Oct. 2015 DatePicker myDatePicker = (DatePicker) findViewById(R.id.date_picker); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A," + myDatePicker.getMonth() + myDatePicker.getDayOfMonth() + "," + myDatePicker.getYear() + ";", usbongAnswerContainerCounter); /* Spinner dateMonthSpinner = (Spinner) findViewById(R.id.date_month_spinner); Spinner dateDaySpinner = (Spinner) findViewById(R.id.date_day_spinner); EditText myDateYearEditText = (EditText)findViewById(R.id.date_edittext); // usbongAnswerContainer.addElement("A,"+monthAdapter.getItem(dateMonthSpinner.getSelectedItemPosition()).toString() + // dayAdapter.getItem(dateDaySpinner.getSelectedItemPosition()).toString() + "," + // myDateYearEditText.getText().toString()+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A,"+monthAdapter.getItem(dateMonthSpinner.getSelectedItemPosition()).toString() + dayAdapter.getItem(dateDaySpinner.getSelectedItemPosition()).toString() + "," + myDateYearEditText.getText().toString()+";", usbongAnswerContainerCounter); */ usbongAnswerContainerCounter++; // System.out.println(">>>>>>>>>>>>>Date screen: "+usbongAnswerContainer.lastElement()); initParser(); } else if (currScreen == UsbongConstants.TIMESTAMP_DISPLAY_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; UsbongUtils.addElementToContainer(usbongAnswerContainer, timestampString + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else if (currScreen == UsbongConstants.QR_CODE_READER_SCREEN) { currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do if (!myQRCodeContent.equals("")) { // usbongAnswerContainer.addElement("Y,"+myQRCodeContent+";"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "Y," + myQRCodeContent + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; } else { // usbongAnswerContainer.addElement("N;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "N;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; } initParser(); } else if ((currScreen == UsbongConstants.DCAT_SUMMARY_SCREEN)) { currUsbongNode = nextUsbongNodeIfYes; //= nextIMCIQuestionIfNo will also do /* LinearLayout myDCATSummaryLinearLayout = (LinearLayout)findViewById(R.id.dcat_summary_linearlayout); int total = myDCATSummaryLinearLayout.getChildCount(); StringBuffer dcatSummary= new StringBuffer(); for (int i=0; i<total; i++) { dcatSummary.append(((TextView) myDCATSummaryLinearLayout.getChildAt(i)).getText().toString()); } */ // UsbongUtils.addElementToContainer(usbongAnswerContainer, "dcat_end;", usbongAnswerContainerCounter); UsbongUtils.addElementToContainer(usbongAnswerContainer, "dcat_end," + myDcatSummaryStringBuffer.toString() + ";", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } else { //TODO: do this for now currUsbongNode = nextUsbongNodeIfYes; //nextUsbongNodeIfNo will also do, since this is "Any" // usbongAnswerContainer.addElement("A;"); UsbongUtils.addElementToContainer(usbongAnswerContainer, "A;", usbongAnswerContainerCounter); usbongAnswerContainerCounter++; initParser(); } } }