List of usage examples for android.widget RadioGroup getCheckedRadioButtonId
@IdRes public int getCheckedRadioButtonId()
Returns the identifier of the selected radio button in this group.
From source file:org.readium.sdk.android.biblemesh.ViewerSettingsDialog.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { mListener = (OnViewerSettingsChange) getArguments().getSerializable("listener"); mOriginalSettings = (ViewerSettings) getArguments().getSerializable("settings"); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); LayoutInflater inflater = getActivity().getLayoutInflater(); final View dialogView = inflater.inflate(R.layout.viewer_settings, null); final RadioGroup spreadGroup = (RadioGroup) dialogView.findViewById(R.id.spreadSettings); switch (mOriginalSettings.getSyntheticSpreadMode()) { case AUTO:/*w w w . jav a2 s . co m*/ spreadGroup.check(R.id.spreadAuto); break; case DOUBLE: spreadGroup.check(R.id.spreadDouble); break; case SINGLE: spreadGroup.check(R.id.spreadSingle); break; } final RadioGroup scrollGroup = (RadioGroup) dialogView.findViewById(R.id.scrollSettings); switch (mOriginalSettings.getScrollMode()) { case AUTO: scrollGroup.check(R.id.scrollAuto); break; case DOCUMENT: scrollGroup.check(R.id.scrollDocument); break; case CONTINUOUS: scrollGroup.check(R.id.scrollContinuous); break; } final EditText fontSizeText = (EditText) dialogView.findViewById(R.id.fontSize); fontSizeText.setText("" + mOriginalSettings.getFontSize()); final EditText columnGapText = (EditText) dialogView.findViewById(R.id.columnGap); columnGapText.setText("" + mOriginalSettings.getColumnGap()); final Button minusFont = (Button) dialogView.findViewById(R.id.minusbutton); minusFont.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Integer f = Integer.parseInt(fontSizeText.getText().toString()); f -= 10; if (f > 0) { fontSizeText.setText(f.toString()); } } }); final Button plusFont = (Button) dialogView.findViewById(R.id.plusbutton); plusFont.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Integer f = Integer.parseInt(fontSizeText.getText().toString()); f += 10; fontSizeText.setText(f.toString()); } }); builder.setView(dialogView).setTitle(R.string.settings) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int id) { if (mListener != null) { int fontSize = parseString(fontSizeText.getText().toString(), 100); int columnGap = parseString(columnGapText.getText().toString(), 20); ViewerSettings.SyntheticSpreadMode syntheticSpreadMode = null; switch (spreadGroup.getCheckedRadioButtonId()) { case R.id.spreadAuto: syntheticSpreadMode = ViewerSettings.SyntheticSpreadMode.AUTO; break; case R.id.spreadSingle: syntheticSpreadMode = ViewerSettings.SyntheticSpreadMode.SINGLE; break; case R.id.spreadDouble: syntheticSpreadMode = ViewerSettings.SyntheticSpreadMode.DOUBLE; break; } ViewerSettings.ScrollMode scrollMode = null; switch (scrollGroup.getCheckedRadioButtonId()) { case R.id.scrollAuto: scrollMode = ViewerSettings.ScrollMode.AUTO; break; case R.id.scrollDocument: scrollMode = ViewerSettings.ScrollMode.DOCUMENT; break; case R.id.scrollContinuous: scrollMode = ViewerSettings.ScrollMode.CONTINUOUS; break; } ViewerSettings settings = new ViewerSettings(syntheticSpreadMode, scrollMode, fontSize, columnGap); mListener.onViewerSettingsChange(settings); } dismiss(); } private int parseString(String s, int defaultValue) { try { return parseInt(s); } catch (Exception e) { Log.e(TAG, "" + e.getMessage(), e); } return defaultValue; } }).setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dismiss(); } }); return builder.create(); }
From source file:com.afwsamples.testdpc.policy.PolicyManagementFragment.java
/** * Shows the default response for future runtime permission requests by applications, and lets * the user change the default value.//from w ww.jav a2 s .c o m */ @TargetApi(Build.VERSION_CODES.M) private void showSetPermissionPolicyDialog() { if (getActivity() == null || getActivity().isFinishing()) { return; } View setPermissionPolicyView = getActivity().getLayoutInflater().inflate(R.layout.set_permission_policy, null); final RadioGroup permissionGroup = (RadioGroup) setPermissionPolicyView .findViewById(R.id.set_permission_group); int permissionPolicy = mDevicePolicyManager.getPermissionPolicy(mAdminComponentName); switch (permissionPolicy) { case DevicePolicyManager.PERMISSION_POLICY_PROMPT: ((RadioButton) permissionGroup.findViewById(R.id.prompt)).toggle(); break; case DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT: ((RadioButton) permissionGroup.findViewById(R.id.accept)).toggle(); break; case DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY: ((RadioButton) permissionGroup.findViewById(R.id.deny)).toggle(); break; } new AlertDialog.Builder(getActivity()).setTitle(getString(R.string.set_default_permission_policy)) .setView(setPermissionPolicyView) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { int policy = 0; int checked = permissionGroup.getCheckedRadioButtonId(); switch (checked) { case (R.id.prompt): policy = DevicePolicyManager.PERMISSION_POLICY_PROMPT; break; case (R.id.accept): policy = DevicePolicyManager.PERMISSION_POLICY_AUTO_GRANT; break; case (R.id.deny): policy = DevicePolicyManager.PERMISSION_POLICY_AUTO_DENY; break; } mDevicePolicyManager.setPermissionPolicy(mAdminComponentName, policy); dialog.dismiss(); } }).show(); }
From source file:biz.bokhorst.xprivacy.ActivityMain.java
@SuppressLint("InflateParams") private void optionSort() { LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE); View view = inflater.inflate(R.layout.sort, null); final RadioGroup rgSMode = (RadioGroup) view.findViewById(R.id.rgSMode); final CheckBox cbSInvert = (CheckBox) view.findViewById(R.id.cbSInvert); // Initialise controls switch (mSortMode) { case SORT_BY_NAME: rgSMode.check(R.id.rbSName);//from ww w . j a va2 s. c o m break; case SORT_BY_UID: rgSMode.check(R.id.rbSUid); break; case SORT_BY_INSTALL_TIME: rgSMode.check(R.id.rbSInstalled); break; case SORT_BY_UPDATE_TIME: rgSMode.check(R.id.rbSUpdated); break; case SORT_BY_MODIFY_TIME: rgSMode.check(R.id.rbSModified); break; case SORT_BY_STATE: rgSMode.check(R.id.rbSState); break; } cbSInvert.setChecked(mSortInvert); // Build dialog AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ActivityMain.this); alertDialogBuilder.setTitle(R.string.menu_sort); alertDialogBuilder.setIcon(getThemed(R.attr.icon_launcher)); alertDialogBuilder.setView(view); alertDialogBuilder.setPositiveButton(ActivityMain.this.getString(android.R.string.ok), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { switch (rgSMode.getCheckedRadioButtonId()) { case R.id.rbSName: mSortMode = SORT_BY_NAME; break; case R.id.rbSUid: mSortMode = SORT_BY_UID; break; case R.id.rbSInstalled: mSortMode = SORT_BY_INSTALL_TIME; break; case R.id.rbSUpdated: mSortMode = SORT_BY_UPDATE_TIME; break; case R.id.rbSModified: mSortMode = SORT_BY_MODIFY_TIME; break; case R.id.rbSState: mSortMode = SORT_BY_STATE; break; } mSortInvert = cbSInvert.isChecked(); int userId = Util.getUserId(Process.myUid()); PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortMode, Integer.toString(mSortMode)); PrivacyManager.setSetting(userId, PrivacyManager.cSettingSortInverted, Boolean.toString(mSortInvert)); applySort(); } }); alertDialogBuilder.setNegativeButton(ActivityMain.this.getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // Do nothing } }); // Show dialog AlertDialog alertDialog = alertDialogBuilder.create(); alertDialog.show(); }
From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java
public void processNextButtonPressed() { wasNextButtonPressed = true;//from www . j ava2s .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(); } } }
From source file:usbong.android.retrocc.UsbongDecisionTreeEngineActivity.java
public void processNextButtonPressed() { wasNextButtonPressed = true;// w w w . j a va2 s .com 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, 20161117 AppRater.showRateDialog(this); isAutoLoopedTree = true; initParser(myTree); return; } else { //return to main activity finish(); //added by Mike, 20161117 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, "Email Book Request:")); } 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 } // 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 { //added by Mike, 20170207 TextView myTextFieldScreenTextView = (TextView) this.findViewById(R.id.textfield_textview); //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 20150609 //answer by Elenasys //added by Mike, 20170207 SharedPreferences.Editor editor = getSharedPreferences(UsbongConstants.MY_ACCOUNT_DETAILS, MODE_PRIVATE).edit(); if (myTextFieldScreenTextView.getText().toString().contains("First Name")) { editor.putString("firstName", myTextFieldScreenEditText.getText().toString()); } else if (myTextFieldScreenTextView.getText().toString().contains("Surname")) { editor.putString("surname", myTextFieldScreenEditText.getText().toString()); } else if (myTextFieldScreenTextView.getText().toString().contains("Contact Number")) { editor.putString("contactNumber", myTextFieldScreenEditText.getText().toString()); } else if (myTextFieldScreenTextView.getText().toString().contains("Shipping Address")) { editor.putString("shippingAddress", myTextFieldScreenEditText.getText().toString()); } editor.commit(); // 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; 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(); } } }
From source file:com.aware.ui.ESM_UI.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { // getActivity().getWindow().setType(WindowManager.LayoutParams.TYPE_PRIORITY_PHONE); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); // getActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON); builder = new AlertDialog.Builder(getActivity()); inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); inputManager = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE); TAG = Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG).length() > 0 ? Aware.getSetting(getActivity().getApplicationContext(), Aware_Preferences.DEBUG_TAG) : TAG;/* w w w.j a va2 s. c o m*/ Cursor visible_esm = getActivity().getContentResolver().query(ESM_Data.CONTENT_URI, null, ESM_Data.STATUS + "=" + ESM.STATUS_NEW, null, ESM_Data.TIMESTAMP + " ASC LIMIT 1"); if (visible_esm != null && visible_esm.moveToFirst()) { esm_id = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data._ID)); //Fixed: set the esm as not new anymore, to avoid displaying the same ESM twice due to changes in orientation ContentValues update_state = new ContentValues(); update_state.put(ESM_Data.STATUS, ESM.STATUS_VISIBLE); getActivity().getContentResolver().update(ESM_Data.CONTENT_URI, update_state, ESM_Data._ID + "=" + esm_id, null); esm_type = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.TYPE)); expires_seconds = visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.EXPIRATION_THREASHOLD)); builder.setTitle(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.TITLE))); View ui = null; switch (esm_type) { case ESM.TYPE_ESM_TEXT: ui = inflater.inflate(R.layout.esm_text, null); break; case ESM.TYPE_ESM_RADIO: ui = inflater.inflate(R.layout.esm_radio, null); break; case ESM.TYPE_ESM_CHECKBOX: ui = inflater.inflate(R.layout.esm_checkbox, null); break; case ESM.TYPE_ESM_LIKERT: ui = inflater.inflate(R.layout.esm_likert, null); break; case ESM.TYPE_ESM_QUICK_ANSWERS: ui = inflater.inflate(R.layout.esm_quick, null); break; } final View layout = ui; builder.setView(layout); current_dialog = builder.create(); sContext = current_dialog.getContext(); TextView esm_instructions = (TextView) layout.findViewById(R.id.esm_instructions); esm_instructions.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.INSTRUCTIONS))); switch (esm_type) { case ESM.TYPE_ESM_TEXT: final EditText feedback = (EditText) layout.findViewById(R.id.esm_feedback); Button cancel_text = (Button) layout.findViewById(R.id.esm_cancel); cancel_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); current_dialog.cancel(); } }); Button submit_text = (Button) layout.findViewById(R.id.esm_submit); submit_text.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_text.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { inputManager.hideSoftInputFromWindow(feedback.getWindowToken(), 0); if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, feedback.getText().toString()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_RADIO: try { final RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); final JSONArray radios = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.RADIOS))); for (int i = 0; i < radios.length(); i++) { final RadioButton radioOption = new RadioButton(getActivity()); radioOption.setId(i); radioOption.setText(radios.getString(i)); radioOptions.addView(radioOption); if (radios.getString(i).equals("Other")) { radioOption.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) radioOption.setText(otherText.getText()); inputManager.hideSoftInputFromWindow(otherText.getWindowToken(), 0); editOther.dismiss(); } }); editor.addView(confirm); } }); } } Button cancel_radio = (Button) layout.findViewById(R.id.esm_cancel); cancel_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_radio = (Button) layout.findViewById(R.id.esm_submit); submit_radio.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_radio.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); RadioGroup radioOptions = (RadioGroup) layout.findViewById(R.id.esm_radio); if (radioOptions.getCheckedRadioButtonId() != -1) { RadioButton selected = (RadioButton) radioOptions .getChildAt(radioOptions.getCheckedRadioButtonId()); rowData.put(ESM_Data.ANSWER, selected.getText().toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_CHECKBOX: try { final LinearLayout checkboxes = (LinearLayout) layout.findViewById(R.id.esm_checkboxes); final JSONArray checks = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.CHECKBOXES))); for (int i = 0; i < checks.length(); i++) { final CheckBox checked = new CheckBox(getActivity()); checked.setText(checks.getString(i)); checked.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(final CompoundButton buttonView, boolean isChecked) { if (isChecked) { if (buttonView.getText().equals("Other")) { checked.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { final Dialog editOther = new Dialog(getActivity()); editOther.setTitle("Can you be more specific, please?"); editOther.getWindow() .setType(WindowManager.LayoutParams.TYPE_SYSTEM_ALERT); editOther.getWindow().setGravity(Gravity.TOP); editOther.getWindow().setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); LinearLayout editor = new LinearLayout(getActivity()); editor.setOrientation(LinearLayout.VERTICAL); editOther.setContentView(editor); editOther.show(); final EditText otherText = new EditText(getActivity()); editor.addView(otherText); Button confirm = new Button(getActivity()); confirm.setText("OK"); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (otherText.length() > 0) { inputManager.hideSoftInputFromWindow( otherText.getWindowToken(), 0); selected_options .remove(buttonView.getText().toString()); checked.setText(otherText.getText()); selected_options.add(otherText.getText().toString()); } editOther.dismiss(); } }); editor.addView(confirm); } }); } else { selected_options.add(buttonView.getText().toString()); } } else { selected_options.remove(buttonView.getText().toString()); } } }); checkboxes.addView(checked); } Button cancel_checkbox = (Button) layout.findViewById(R.id.esm_cancel); cancel_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit_checkbox = (Button) layout.findViewById(R.id.esm_submit); submit_checkbox.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit_checkbox.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); if (selected_options.size() > 0) { rowData.put(ESM_Data.ANSWER, selected_options.toString()); } rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); } catch (JSONException e) { e.printStackTrace(); } break; case ESM.TYPE_ESM_LIKERT: final RatingBar ratingBar = (RatingBar) layout.findViewById(R.id.esm_likert); ratingBar.setMax(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); ratingBar.setStepSize( (float) visible_esm.getDouble(visible_esm.getColumnIndex(ESM_Data.LIKERT_STEP))); ratingBar.setNumStars(visible_esm.getInt(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX))); TextView min_label = (TextView) layout.findViewById(R.id.esm_min); min_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MIN_LABEL))); TextView max_label = (TextView) layout.findViewById(R.id.esm_max); max_label.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.LIKERT_MAX_LABEL))); Button cancel = (Button) layout.findViewById(R.id.esm_cancel); cancel.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { current_dialog.cancel(); } }); Button submit = (Button) layout.findViewById(R.id.esm_submit); submit.setText(visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.SUBMIT))); submit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.ANSWER, ratingBar.getRating()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); break; case ESM.TYPE_ESM_QUICK_ANSWERS: try { final JSONArray answers = new JSONArray( visible_esm.getString(visible_esm.getColumnIndex(ESM_Data.QUICK_ANSWERS))); final LinearLayout answersHolder = (LinearLayout) layout.findViewById(R.id.esm_answers); //If we have more than 3 possibilities, better that the UI is vertical for UX if (answers.length() > 3) { answersHolder.setOrientation(LinearLayout.VERTICAL); } for (int i = 0; i < answers.length(); i++) { final Button answer = new Button(getActivity()); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT, 1.0f); answer.setLayoutParams(params); answer.setText(answers.getString(i)); answer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (expires_seconds > 0 && expire_monitor != null) expire_monitor.cancel(true); ContentValues rowData = new ContentValues(); rowData.put(ESM_Data.ANSWER_TIMESTAMP, System.currentTimeMillis()); rowData.put(ESM_Data.STATUS, ESM.STATUS_ANSWERED); rowData.put(ESM_Data.ANSWER, (String) answer.getText()); sContext.getContentResolver().update(ESM_Data.CONTENT_URI, rowData, ESM_Data._ID + "=" + esm_id, null); Intent answer = new Intent(ESM.ACTION_AWARE_ESM_ANSWERED); getActivity().sendBroadcast(answer); if (Aware.DEBUG) Log.d(TAG, "Answer:" + rowData.toString()); current_dialog.dismiss(); } }); answersHolder.addView(answer); } } catch (JSONException e) { e.printStackTrace(); } break; } } if (visible_esm != null && !visible_esm.isClosed()) visible_esm.close(); //Start dialog visibility threshold if (expires_seconds > 0) { expire_monitor = new ESMExpireMonitor(System.currentTimeMillis(), expires_seconds, esm_id); expire_monitor.execute(); } //Fixed: doesn't dismiss the dialog if touched outside or ghost touches current_dialog.setCanceledOnTouchOutside(false); return current_dialog; }