List of usage examples for android.widget RadioButton RadioButton
public RadioButton(Context context)
From source file:edu.mum.ml.group7.guessasketch.android.EasyPaint.java
public void refreshLabels(JSONObject jObject) { /* Button btn = new Button(this); btn.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, getResources().getDimensionPixelSize(R.dimen.prediction_text_view_height) )); btn.setTextSize(pixels);/* w ww . ja v a 2 s . c o m*/ btn.setText("Cat"); predictions.addView(btn); */ final List<RadioButton> buttons = new ArrayList<>(); String result = "I think it's: "; try { JSONArray jArray = jObject.getJSONArray("data"); for (int i = 0; i < jArray.length(); i++) { JSONObject prediction = jArray.getJSONObject(i); // Pulling items from the array int score = prediction.getInt("score"); if (score < Constants.minScoreThershold) { continue; } String label = prediction.getString("label"); result += "\"" + label + "\" : " + score + "% "; RadioButton radioButton = new RadioButton(EasyPaint.this); radioButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, getResources().getDimensionPixelSize(R.dimen.prediction_text_view_height))); radioButton.setTextSize(pixels5); radioButton.setText(label + " (" + score + "%)"); radioButton.setTag(label); //radioButton.set //predictions.addView(radioButton); radioButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { saveButton.setTag(view.getTag()); feedbackType = ApiCallType.POSITIVE_FEEDBACK; } }); buttons.add(radioButton); } } catch (JSONException e) { e.printStackTrace(); } final RadioButton radioButton = new RadioButton(EasyPaint.this); radioButton.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, getResources().getDimensionPixelSize(R.dimen.prediction_text_view_height))); radioButton.setTextSize(pixels5); radioButton.setText(R.string.other_label); buttons.add(radioButton); radioButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { AlertDialog.Builder builder = new AlertDialog.Builder(EasyPaint.this); builder.setTitle(R.string.other_label); // Set up the input final EditText input = new EditText(EasyPaint.this); // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text input.setInputType(InputType.TYPE_CLASS_TEXT); builder.setView(input); // Set up the buttons builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { if (input.getText().toString().length() > 0) { radioButton.setText(input.getText().toString()); saveButton.setTag(input.getText().toString()); feedbackType = ApiCallType.NEGATIVE_FEEDBACK; } else { EasyPaint.this.runOnUiThread(new Runnable() { public void run() { Toast.makeText(getApplicationContext(), "You didn't specify a name, try again please", Toast.LENGTH_LONG) .show(); } }); saveButton.setTag(""); feedbackType = ApiCallType.POSITIVE_FEEDBACK; dialog.cancel(); } } }); builder.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { saveButton.setTag(""); feedbackType = ApiCallType.POSITIVE_FEEDBACK; dialog.cancel(); } }); builder.show(); } }); saveButton.setOnClickListener(otherLabelOnClickListener); toastMessage = result; EasyPaint.this.runOnUiThread(new Runnable() { public void run() { resetPredictionsView(predictions, false); Toast.makeText(getApplicationContext(), toastMessage, Toast.LENGTH_LONG).show(); for (RadioButton r : buttons) { predictions.addView(r); } } }); }
From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java
@Override public void onClick(View view) { if (view == btnGoBack) { if (isAtFavorites) { isAtFavorites = false;/*from w w w. ja va2 s .c o m*/ doSearch(); } else { finish(0, view, true); } } else if (view == btnFavorite) { isAtFavorites = true; radioStationList.cancel(); radioStationList.fetchFavorites(getApplication()); updateButtons(); } else if (view == btnSearch) { final Context ctx = getHostActivity(); final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); chkGenre = new RadioButton(ctx); chkGenre.setText(R.string.genre); chkGenre.setChecked(Player.lastRadioSearchWasByGenre); chkGenre.setOnClickListener(this); chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp); chkGenre.setLayoutParams(p); p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); p.topMargin = UI._DLGsppad; btnGenre = new Spinner(ctx); btnGenre.setContentDescription(ctx.getText(R.string.genre)); btnGenre.setLayoutParams(p); p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); p.topMargin = UI._DLGsppad << 1; chkTerm = new RadioButton(ctx); chkTerm.setText(R.string.search_term); chkTerm.setChecked(!Player.lastRadioSearchWasByGenre); chkTerm.setOnClickListener(this); chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp); chkTerm.setLayoutParams(p); p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); p.topMargin = UI._DLGsppad; txtTerm = new EditText(ctx); txtTerm.setContentDescription(ctx.getText(R.string.search_term)); txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm); txtTerm.setOnClickListener(this); txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp); txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES); txtTerm.setSingleLine(); txtTerm.setLayoutParams(p); p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); p.topMargin = UI._DLGsppad; p.bottomMargin = UI._DLGsppad; final TextView lbl = new TextView(ctx); lbl.setAutoLinkMask(0); lbl.setLinksClickable(true); //http://developer.android.com/design/style/color.html lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5)); lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp); lbl.setGravity(Gravity.CENTER_HORIZONTAL); lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org))); lbl.setMovementMethod(LinkMovementMethod.getInstance()); lbl.setLayoutParams(p); l.addView(chkGenre); l.addView(btnGenre); l.addView(chkTerm); l.addView(txtTerm); l.addView(lbl); btnGenre.setAdapter(this); btnGenre.setSelection(getValidGenre(Player.radioLastGenre)); defaultTextColors = txtTerm.getTextColors(); UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l) .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this) .setOnCancelListener(this).create()); } else if (view == btnGoBackToPlayer) { finish(-1, view, false); } else if (view == btnAdd) { addPlaySelectedItem(false); } else if (view == btnPlay) { addPlaySelectedItem(true); } else if (view == chkGenre || view == btnGenre) { chkGenre.setChecked(true); chkTerm.setChecked(false); } else if (view == chkTerm || view == txtTerm) { chkGenre.setChecked(false); chkTerm.setChecked(true); } else if (view == list) { if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0)) onClick(btnFavorite); } }
From source file:de.da_sense.moses.client.FormFragment.java
/** * Displays a single choice question to the user. * @param question the question to be displayed * @param linearLayoutInsideAScrollView the view to add the question to * @param ordinal the ordinal number of the question i.e. 1, 2, 3, 4 or 5 *///ww w . j av a 2 s . c om private void makeSingleChoice(final Question question, LinearLayout linearLayoutInsideAScrollView, int ordinal) { LinearLayout questionContainer = generateQuestionContainer(linearLayoutInsideAScrollView); String questionText = question.getTitle(); List<PossibleAnswer> possibleAnswers = question.getPossibleAnswers(); Collections.sort(possibleAnswers); TextView questionView = new TextView(getActivity()); questionView.setText(ordinal + ". " + questionText); if (question.isMandatory()) questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyleMandatory); else questionView.setTextAppearance(getActivity(), R.style.QuestionTextStyle); questionContainer.addView(questionView); mQuestionTitleMappings.put(question, questionView); final RadioButton[] rb = new RadioButton[possibleAnswers.size()]; RadioGroup rg = new RadioGroup(getActivity()); // create the RadioGroup rg.setOrientation(RadioGroup.VERTICAL);// or RadioGroup.VERTICAL String madeAnswer = question.getAnswer(); int madeAnswerInt = -1; if (!madeAnswer.equals(Question.ANSWER_UNANSWERED)) madeAnswerInt = Integer.parseInt(madeAnswer); for (int i = 0; i < rb.length; i++) { rb[i] = new RadioButton(getActivity()); if (i % 2 == 0) rb[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray)); rg.addView(rb[i]); // the RadioButtons are added to the radioGroup // instead of the layout PossibleAnswer possibleAnswer = possibleAnswers.get(i); rb[i].setText(possibleAnswer.getTitle()); final int possibleAnswerId = possibleAnswer.getId(); if (madeAnswerInt == possibleAnswerId) rb[i].setChecked(true); rb[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle); LayoutParams rowParam = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); rb[i].setLayoutParams(rowParam); // click handling rb[i].setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { question.setAnswer(String.valueOf(possibleAnswerId)); } }); if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) rb[i].setEnabled(false); rb[i].setVisibility(View.VISIBLE); } rg.setVisibility(View.VISIBLE); if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) rg.setEnabled(false); Log.i(LOG_TAG, "last rg = " + rg); questionContainer.addView(rg); }
From source file:com.google.code.twisty.Twisty.java
private void updateRestoreRadioButtons(RadioGroup rg) { rg.removeAllViews();/*from w w w .j ava2 s . c o m*/ int id = 0; String[] gamelist = new File(savegame_dir).list(); for (String filename : gamelist) { RadioButton rb = new RadioButton(Twisty.this); rb.setText(filename); rg.addView(rb); id = rb.getId(); } rg.check(id); // by default, check the last item }
From source file:com.google.code.twisty.Twisty.java
private void updateGameRadioButtons(RadioGroup rg) { rg.removeAllViews();/* w ww. j a v a2 s .c o m*/ game_paths.clear(); int id = 0; for (String path : discovered_games) { RadioButton rb = new RadioButton(Twisty.this); rb.setText(new File(path).getName()); rg.addView(rb); id = rb.getId(); game_paths.put(id, path); } }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates radio buttons/*from www . j av a 2s . co m*/ * * @param open311Attribute contains the open311 attributes */ private void createSingleValueList(Open311Attribute open311Attribute) { ArrayList<Object> values = (ArrayList<Object>) open311Attribute.getValues(); if (values != null && values.size() > 0) { LayoutInflater inflater = LayoutInflater.from(getActivity()); RelativeLayout layout = (RelativeLayout) inflater.inflate(R.layout.report_issue_single_value_list_item, null, false); layout.setSaveEnabled(true); ((ImageView) layout.findViewById(R.id.ri_ic_radio)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.risvli_textView)).setText(word); if (open311Attribute.getRequired()) { Spannable wordTwo = new SpannableString(" *Required"); wordTwo.setSpan(new ForegroundColorSpan(Color.RED), 0, wordTwo.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); ((TextView) layout.findViewById(R.id.risvli_textView)).append(wordTwo); } RadioGroup rg = (RadioGroup) layout.findViewById(R.id.risvli_radioGroup); rg.setOrientation(RadioGroup.VERTICAL); // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); String entryValue = null; if (av != null) { entryValue = av.getSingleValue(); } for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); RadioButton rb = new RadioButton(getActivity()); rg.addView(rb); //the RadioButtons are added to the radioGroup instead of the layout String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { rb.setText(entry.getValue()); if (entryValue != null && entryValue.equalsIgnoreCase(entry.getValue())) { rb.setChecked(true); } attributeKey = open311Attribute.getCode() + entry.getValue(); } else if (Open311Attribute.KEY.equals(entry.getKey())) { attributeValue = entry.getValue(); } } mOpen311AttributeKeyNameMap.put(attributeKey, attributeValue); } mInfoLayout.addView(layout); mDynamicAttributeUIMap.put(open311Attribute.getCode(), rg); } }
From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java
public void processSpeak(StringBuffer sb) { if (mTts.isSpeaking()) { //commented out by Mike, 24 Sept. 2015 mTts.stop();/*from ww w . j a v a 2 s. co m*/ } // Log.d(">>>>currScreen",currScreen+""); switch (currScreen) { //edit later, Mike, Sept. 26, 2013 case UsbongConstants.SIMPLE_ENCRYPT_SCREEN: break; //edit later, Mike, May 23, 2013 case UsbongConstants.DCAT_SUMMARY_SCREEN: break; case UsbongConstants.LINK_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalRadioButtonsInContainer = radioButtonsContainer.size(); for (int i = 0; i < totalRadioButtonsInContainer; i++) { sb.append(((RadioButton) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new RadioButton(this), UsbongUtils.IS_RADIOBUTTON, radioButtonsContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.MULTIPLE_CHECKBOXES_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalCheckBoxesInContainer = checkBoxesContainer.size(); for (int i = 0; i < totalCheckBoxesInContainer; i++) { sb.append(((CheckBox) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new CheckBox(this), UsbongUtils.IS_CHECKBOX, checkBoxesContainer.elementAt(i))).getText() .toString() + ". "); } break; case UsbongConstants.AUDIO_RECORD_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button recordButton = (Button) findViewById(R.id.record_button); Button stopButton = (Button) findViewById(R.id.stop_button); Button playButton = (Button) findViewById(R.id.play_button); sb.append(recordButton.getText() + ". "); sb.append(stopButton.getText() + ". "); sb.append(playButton.getText() + ". "); break; case UsbongConstants.PAINT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button paintButton = (Button) findViewById(R.id.paint_button); sb.append(paintButton.getText() + ". "); break; case UsbongConstants.PHOTO_CAPTURE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button photoCaptureButton = (Button) findViewById(R.id.photo_capture_button); sb.append(photoCaptureButton.getText() + ". "); break; case UsbongConstants.TEXTFIELD_SCREEN: case UsbongConstants.TEXTFIELD_WITH_ANSWER_SCREEN: case UsbongConstants.TEXTFIELD_WITH_UNIT_SCREEN: case UsbongConstants.TEXTFIELD_NUMERICAL_SCREEN: case UsbongConstants.TEXTAREA_SCREEN: case UsbongConstants.TEXTAREA_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); break; case UsbongConstants.CLASSIFICATION_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalClassificationsInContainer = classificationContainer.size(); for (int i = 0; i < totalClassificationsInContainer; i++) { sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, classificationContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.DATE_SCREEN: case UsbongConstants.TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.CLICKABLE_IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.GPS_LOCATION_SCREEN: case UsbongConstants.QR_CODE_READER_SCREEN: case UsbongConstants.TIMESTAMP_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_WITH_TEXT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); // Log.d(">>>>sb",sb.toString()); break; case UsbongConstants.CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_SCREEN: break; case UsbongConstants.YES_NO_DECISION_SCREEN: case UsbongConstants.SEND_TO_WEBSERVER_SCREEN: case UsbongConstants.SEND_TO_CLOUD_BASED_SERVICE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); sb.append(yesStringValue + ". "); sb.append(noStringValue + ". "); break; /* case UsbongConstants.PAINT_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewENGLISH)); } break; */ /* //commented out by Mike, 20160213 case UsbongConstants.END_STATE_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewENGLISH)); } break; */ } //edited by Mike, 21 July 2015 try { currUsbongAudioString = UsbongUtils.getAudioFilePathForThisScreenIfAvailable(currUsbongNode); Log.d(">>>>currUsbongAudioString: ", "" + currUsbongAudioString); Log.d(">>>>currLanguageBeingUsed: ", UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //added by Mike, 2 Oct. 2015 //exception for Mandarin //make simplified and traditional refer to the same audio folder if ((currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_SIMPLIFIED) || (currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_TRADITIONAL)) { currLanguageBeingUsed = UsbongUtils.LANGUAGE_MANDARIN; } String filePath = UsbongUtils.getAudioFilePathFromUTree(currUsbongAudioString, UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); // Log.d(">>>>filePath: ",filePath); if (filePath != null) { Log.d(">>>>", "inside filePath!=null"); Log.d(">>>>filePath: ", filePath); if (myMediaPlayer.isPlaying()) { myMediaPlayer.stop(); } myMediaPlayer.reset(); //edited by Mike, 20151201 // myMediaPlayer.setDataSource(filePath); FileInputStream fis = new FileInputStream(new File(filePath)); myMediaPlayer.setDataSource(fis.getFD()); fis.close(); myMediaPlayer.prepare(); // myMediaPlayer.setVolume(1.0f, 1.0f); myMediaPlayer.start(); // myMediaPlayer.seekTo(0); //added by Mike, 20160417 myMediaPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { if ((UsbongUtils.IS_IN_AUTO_PLAY_MODE) && (UsbongUtils.isAnAutoPlayException(instance))) { processNextButtonPressed(); } } }); } else { //it's either com.svox.pico (default) or com.svox.classic (Japanese, etc) //commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.pico"); //note: this method is already deprecated //20160417 mTtsParams = new HashMap<String, String>(); mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UsbongConstants.MY_UTTERANCE_ID); switch (currLanguageBeingUsed) { case UsbongUtils.LANGUAGE_FILIPINO: mTts.setLanguage(new Locale("spa", "ESP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_JAPANESE: // commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.classic"); //note: this method is already deprecated mTts.setLanguage(new Locale("ja", "JP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_ENGLISH: mTts.setLanguage(new Locale("en", "US")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; default: mTts.setLanguage(new Locale("en", "US")); mTts.speak(sb.toString(), TextToSpeech.QUEUE_ADD, null); //QUEUE_FLUSH break; } //added by Mike, 20160417 mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) { if (utteranceId.equals(UsbongConstants.MY_UTTERANCE_ID)) { //added by Mike, 20160608 if ((UsbongUtils.IS_IN_AUTO_PLAY_MODE) && (UsbongUtils.isAnAutoPlayException(instance))) { instance.runOnUiThread(new Runnable() { @Override public void run() { processNextButtonPressed(); } }); } } } @Override @Deprecated public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:usbong.android.retrocc.UsbongDecisionTreeEngineActivity.java
public void processSpeak(StringBuffer sb) { if (mTts.isSpeaking()) { //commented out by Mike, 24 Sept. 2015 mTts.stop();//from www. j a v a 2 s . c om } // Log.d(">>>>currScreen",currScreen+""); switch (currScreen) { //edit later, Mike, Sept. 26, 2013 case UsbongConstants.SIMPLE_ENCRYPT_SCREEN: break; //edit later, Mike, May 23, 2013 case UsbongConstants.DCAT_SUMMARY_SCREEN: break; case UsbongConstants.LINK_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_SCREEN: case UsbongConstants.MULTIPLE_RADIO_BUTTONS_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalRadioButtonsInContainer = radioButtonsContainer.size(); for (int i = 0; i < totalRadioButtonsInContainer; i++) { sb.append(((RadioButton) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new RadioButton(this), UsbongUtils.IS_RADIOBUTTON, radioButtonsContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.MULTIPLE_CHECKBOXES_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalCheckBoxesInContainer = checkBoxesContainer.size(); for (int i = 0; i < totalCheckBoxesInContainer; i++) { sb.append(((CheckBox) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new CheckBox(this), UsbongUtils.IS_CHECKBOX, checkBoxesContainer.elementAt(i))).getText() .toString() + ". "); } break; case UsbongConstants.AUDIO_RECORD_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button recordButton = (Button) findViewById(R.id.record_button); Button stopButton = (Button) findViewById(R.id.stop_button); Button playButton = (Button) findViewById(R.id.play_button); sb.append(recordButton.getText() + ". "); sb.append(stopButton.getText() + ". "); sb.append(playButton.getText() + ". "); break; case UsbongConstants.PAINT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button paintButton = (Button) findViewById(R.id.paint_button); sb.append(paintButton.getText() + ". "); break; case UsbongConstants.PHOTO_CAPTURE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); Button photoCaptureButton = (Button) findViewById(R.id.photo_capture_button); sb.append(photoCaptureButton.getText() + ". "); break; case UsbongConstants.TEXTFIELD_SCREEN: case UsbongConstants.TEXTFIELD_WITH_ANSWER_SCREEN: case UsbongConstants.TEXTFIELD_WITH_UNIT_SCREEN: case UsbongConstants.TEXTFIELD_NUMERICAL_SCREEN: case UsbongConstants.TEXTAREA_SCREEN: case UsbongConstants.TEXTAREA_WITH_ANSWER_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); break; case UsbongConstants.CLASSIFICATION_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); int totalClassificationsInContainer = classificationContainer.size(); for (int i = 0; i < totalClassificationsInContainer; i++) { sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, classificationContainer.elementAt(i))) .getText().toString() + ". "); } break; case UsbongConstants.DATE_SCREEN: case UsbongConstants.TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.CLICKABLE_IMAGE_TEXT_DISPLAY_SCREEN: case UsbongConstants.TEXT_CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.GPS_LOCATION_SCREEN: case UsbongConstants.QR_CODE_READER_SCREEN: case UsbongConstants.TIMESTAMP_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_WITH_TEXT_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); // Log.d(">>>>sb",sb.toString()); break; case UsbongConstants.CLICKABLE_IMAGE_DISPLAY_SCREEN: case UsbongConstants.IMAGE_DISPLAY_SCREEN: case UsbongConstants.VIDEO_FROM_FILE_SCREEN: break; case UsbongConstants.YES_NO_DECISION_SCREEN: case UsbongConstants.SEND_TO_WEBSERVER_SCREEN: case UsbongConstants.SEND_TO_CLOUD_BASED_SERVICE_SCREEN: sb.append(((TextView) UsbongUtils.applyTagsInView(UsbongDecisionTreeEngineActivity.getInstance(), new TextView(this), UsbongUtils.IS_TEXTVIEW, currUsbongNode)).getText().toString() + ". "); sb.append(yesStringValue + ". "); sb.append(noStringValue + ". "); break; /* case UsbongConstants.PAINT_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongPaintScreenTextViewENGLISH)); } break; */ /* //commented out by Mike, 20160213 case UsbongConstants.END_STATE_SCREEN: if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_FILIPINO) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewFILIPINO)); } else if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_JAPANESE) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewJAPANESE)); } else { //if (currLanguageBeingUsed==UsbongUtils.LANGUAGE_ENGLISH) { sb.append((String) getResources().getText(R.string.UsbongEndStateTextViewENGLISH)); } break; */ } //edited by Mike, 21 July 2015 try { currUsbongAudioString = UsbongUtils.getAudioFilePathForThisScreenIfAvailable(currUsbongNode); Log.d(">>>>currUsbongAudioString: ", "" + currUsbongAudioString); Log.d(">>>>currLanguageBeingUsed: ", UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //added by Mike, 2 Oct. 2015 //exception for Mandarin //make simplified and traditional refer to the same audio folder if ((currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_SIMPLIFIED) || (currLanguageBeingUsed == UsbongUtils.LANGUAGE_MANDARIN_TRADITIONAL)) { currLanguageBeingUsed = UsbongUtils.LANGUAGE_MANDARIN; } String filePath = UsbongUtils.getAudioFilePathFromUTree(currUsbongAudioString, UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); // Log.d(">>>>filePath: ",filePath); if (filePath != null) { Log.d(">>>>", "inside filePath!=null"); Log.d(">>>>filePath: ", filePath); if (myMediaPlayer.isPlaying()) { myMediaPlayer.stop(); } myMediaPlayer.reset(); //edited by Mike, 20151201 // myMediaPlayer.setDataSource(filePath); FileInputStream fis = new FileInputStream(new File(filePath)); myMediaPlayer.setDataSource(fis.getFD()); fis.close(); myMediaPlayer.prepare(); // myMediaPlayer.setVolume(1.0f, 1.0f); myMediaPlayer.start(); // myMediaPlayer.seekTo(0); //added by Mike, 20160417 myMediaPlayer.setOnCompletionListener(new OnCompletionListener() { public void onCompletion(MediaPlayer mp) { if (UsbongUtils.IS_IN_AUTO_PLAY_MODE) { processNextButtonPressed(); } } }); } else { //it's either com.svox.pico (default) or com.svox.classic (Japanese, etc) //commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.pico"); //note: this method is already deprecated //20160417 mTtsParams = new HashMap<String, String>(); mTtsParams.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, UsbongConstants.MY_UTTERANCE_ID); switch (currLanguageBeingUsed) { case UsbongUtils.LANGUAGE_FILIPINO: mTts.setLanguage(new Locale("spa", "ESP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(UsbongUtils.convertFilipinoToSpanishAccentFriendlyText(sb.toString()), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_JAPANESE: // commented out by Mike, 11 Oct. 2015 // mTts.setEngineByPackageName("com.svox.classic"); //note: this method is already deprecated mTts.setLanguage(new Locale("ja", "JP")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; case UsbongUtils.LANGUAGE_ENGLISH: mTts.setLanguage(new Locale("en", "US")); if (Build.VERSION.RELEASE.startsWith("5")) { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null, null); //QUEUE_ADD } else { mTts.speak(sb.toString(), TextToSpeech.QUEUE_FLUSH, null); //QUEUE_ADD } break; default: mTts.setLanguage(new Locale("en", "US")); mTts.speak(sb.toString(), TextToSpeech.QUEUE_ADD, null); //QUEUE_FLUSH break; } //added by Mike, 20160417 mTts.setOnUtteranceProgressListener(new UtteranceProgressListener() { @Override public void onDone(String utteranceId) { if (utteranceId.equals(UsbongConstants.MY_UTTERANCE_ID)) { if (UsbongUtils.IS_IN_AUTO_PLAY_MODE) { instance.runOnUiThread(new Runnable() { @Override public void run() { processNextButtonPressed(); } }); } } } @Override @Deprecated public void onError(String utteranceId) { // TODO Auto-generated method stub } @Override public void onStart(String utteranceId) { // TODO Auto-generated method stub } }); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.example.sensingapp.SensingApp.java
public void show_screen5() { String sSensorList = ""; setContentView(R.layout.screen_5_stop); m_tvGpsUp = (TextView) findViewById(R.id.Screen5_GpsUp); m_tvSensingInfo = (TextView) findViewById(R.id.Screen5_SensingInfo); m_btnScreen5_Stop = (Button) findViewById(R.id.btScreen5_Stop); m_btnScreen5_Stop.setOnClickListener(m_btnStopRecordListener); if (m_blnAcclEnabled) { sSensorList = sSensorList + " - Accelerometer" + "\n"; }/*from w ww. ja v a 2 s . c o m*/ if (m_blnLinearAcclEnabled) { sSensorList = sSensorList + " - Linear Accl" + "\n"; } if (m_blnGravityEnabled) { sSensorList = sSensorList + " - Gravity" + "\n"; } if (m_blnGyroEnabled) { sSensorList = sSensorList + " - Gyroscope" + "\n"; } if (m_blnOrientEnabled) { sSensorList = sSensorList + " - Orientation" + "\n"; } if (m_blnMagnetEnabled) { sSensorList = sSensorList + " - Magnetic Field" + "\n"; } if (m_blnLightEnabled) { sSensorList = sSensorList + " - Light" + "\n"; } if (m_blnBarometerEnabled) { sSensorList = sSensorList + " - Barometer" + "\n"; } if (m_blnMicEnabled) { sSensorList = sSensorList + " - Microphone" + "\n"; } if (m_blnCellularEnabled) { sSensorList = sSensorList + " - Cellular ID" + "\n"; } if (m_blnGPSEnabled) { sSensorList = sSensorList + " - GPS" + "\n"; } if (m_blnWifiEnabled) { sSensorList = sSensorList + " - WiFi" + "\n"; } m_tvSensingInfo.setText(sSensorList); m_etScreen5_TempLabel = (EditText) findViewById(R.id.Screen5_etTempLabel); m_chkScreen5_UseTempLabel = (CheckBox) findViewById(R.id.Screen5_chkUseTempLabel); m_chkScreen5_UseTempLabel.setOnCheckedChangeListener(m_chkScreen5_UseTempLabelListener); m_svScreen5_Label = (ScrollView) findViewById(R.id.Screen5_scrollview); m_rdgpLabelRadioButtonGroup = (RadioGroup) findViewById(R.id.Screen5_LabelRadioButtonGroup); m_rdgpLabelRadioButtonGroup.setOnCheckedChangeListener(m_rdgpScreen5_LabelRadioButtonListener); m_arrLabelButton = new RadioButton[m_lstSensorDataLabel.size()]; for (int i = 0; i < m_lstSensorDataLabel.size(); i++) { m_arrLabelButton[i] = new RadioButton(this); m_arrLabelButton[i].setText(m_lstSensorDataLabel.get(i)); m_rdgpLabelRadioButtonGroup.addView(m_arrLabelButton[i], m_lpLabelButtonParams); if (i == m_nCurrentLabelIndex) { m_arrLabelButton[i].setChecked(true); } } m_svScreen5_Label.post(new Runnable() { public void run() { if (m_nCurrentLabelIndex != -1) { int nY = (int) (m_rdgpLabelRadioButtonGroup.getHeight() * m_nCurrentLabelIndex / m_lstSensorDataLabel.size()); m_svScreen5_Label.scrollTo(0, nY); } } }); String sInfo = ""; if (m_blnNoLabel == true) { sInfo = "No Label"; } else { sInfo = "Labeling"; } m_tvGpsUp.setText(sInfo); }