List of usage examples for android.widget CheckBox CheckBox
public CheckBox(Context context)
From source file:com.github.michalbednarski.intentslab.editor.IntentGeneralFragment.java
private void setupCategoryCheckBoxes(Set<String> availableCategories) { mCategoriesContainer.removeAllViews(); mCategoryCheckBoxes = new CheckBox[availableCategories.size()]; int i = 0;/*from ww w. j a v a 2 s .c om*/ for (String category : availableCategories) { CheckBox cb = new CheckBox(getActivity()); cb.setText(category); cb.setTag(category); cb.setChecked(mEditedIntent.hasCategory(category)); mCategoriesContainer.addView(cb); mCategoryCheckBoxes[i++] = cb; } mAddCategoryButton.setVisibility(View.GONE); mCategoriesHeader.setVisibility(availableCategories.size() == 0 ? View.GONE : View.VISIBLE); mCategoryTextInputs = null; }
From source file:syncthing.android.ui.sessionsettings.EditFolderPresenter.java
@BindingAdapter("addShareDevices") public static void addShareDevices(LinearLayout shareDevicesContainer, EditFolderPresenter presenter) { if (presenter == null) return;//w w w. java 2 s . c om shareDevicesContainer.removeAllViews(); for (Map.Entry<String, Boolean> e : presenter.sharedDevices.entrySet()) { final String id = e.getKey(); CheckBox checkBox = new CheckBox(shareDevicesContainer.getContext()); DeviceConfig device = presenter.controller.getDevice(id); if (device == null) { device = new DeviceConfig(); device.deviceID = id; } checkBox.setText(SyncthingUtils.getDisplayName(device)); checkBox.setChecked(e.getValue()); shareDevicesContainer.addView(checkBox); presenter.bindingSubscriptions().add(RxCompoundButton.checkedChanges(checkBox).subscribe(b -> { presenter.setDeviceShared(id, b); })); } }
From source file:de.da_sense.moses.client.FormFragment.java
/** * Displays a multiple 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 *///from w w w .ja v a 2 s .c om private void makeMultipleChoice(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); Log.i(LOG_TAG, "questionView = " + questionView.getText()); final HashSet<String> madeAnswers = new HashSet<String>(); madeAnswers.addAll(Arrays.asList(question.getAnswer().split(","))); madeAnswers.remove(""); // paranoia final CheckBox[] checkBoxs = new CheckBox[possibleAnswers.size()]; for (int i = 0; i < checkBoxs.length; i++) { final PossibleAnswer possibleAnswer = possibleAnswers.get(i); final String possibleAnswerId = String.valueOf(possibleAnswer.getId()); checkBoxs[i] = new CheckBox(getActivity()); if (i % 2 == 0) checkBoxs[i].setBackgroundColor(getActivity().getResources().getColor(R.color.light_gray)); checkBoxs[i].setText(possibleAnswer.getTitle()); checkBoxs[i].setTextAppearance(getActivity(), R.style.PossibleAnswerTextStyle); if (madeAnswers.contains(possibleAnswerId)) checkBoxs[i].setChecked(true); // click handling checkBoxs[i].setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { if (isChecked) madeAnswers.add(possibleAnswerId); else madeAnswers.remove(possibleAnswerId); String newAnswer = ""; for (String madeAnswer1 : madeAnswers) newAnswer = newAnswer + "," + madeAnswer1; if (!newAnswer.isEmpty()) newAnswer = newAnswer.substring(1); // remove the leading "," question.setAnswer(newAnswer); } }); checkBoxs[i].setVisibility(View.VISIBLE); if (mBelongsTo == WelcomeActivityPagerAdapter.TAB_HISTORY) checkBoxs[i].setEnabled(false); questionContainer.addView(checkBoxs[i]); } }
From source file:com.javielinux.fragments.MyActivityFragment.java
public void showDialogSamples() { final boolean[] samplesChecked = new boolean[] { false, false, false, false, false, false, false, false, false, false, false, false }; final CheckBox cb = new CheckBox(getActivity()); cb.setText(R.string.samples_search_lang); cb.setTextColor(Color.GRAY);/*from ww w. ja v a 2 s .c o m*/ AlertDialog builder = new AlertDialog.Builder(getActivity()).setTitle(R.string.samples_search).setView(cb) .setMultiChoiceItems( R.array.actions_samples_search, new boolean[] { false, false, false, false, false, false, false, false, false, false, false, false }, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int whichButton, boolean isChecked) { samplesChecked[whichButton] = isChecked; } }) .setPositiveButton(R.string.alert_dialog_ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { String[] names = getResources().getStringArray(R.array.actions_samples_search); String lang = ""; if (cb.isChecked()) { String[] langs = getResources().getStringArray(R.array.languages_values); for (int l = 0; l < langs.length; l++) { if (langs[l].equals(Locale.getDefault().getLanguage())) { lang = Locale.getDefault().getLanguage(); } } } for (int i = 0; i < samplesChecked.length; i++) { if (samplesChecked[i]) { Entity ent = new Entity("search"); ent.setValue("name", names[i]); ent.setValue("date_create", Utils.now()); ent.setValue("last_modified", Utils.now()); ent.setValue("use_count", 0); if (i == 0) { ent.setValue("lang", lang); ent.setValue("words_and", "android"); ent.setValue("icon_id", 2); ent.setValue("icon_big", "drawable/icon_android"); ent.setValue("icon_small", "drawable/icon_android_small"); } else if (i == 1) { ent.setValue("lang", lang); ent.setValue("words_and", "android"); ent.setValue("words_or", "juego juegos videojuegos videjuego game games"); ent.setValue("icon_id", 2); ent.setValue("icon_big", "drawable/icon_android"); ent.setValue("icon_small", "drawable/icon_android_small"); } else if (i == 2) { ent.setValue("lang", lang); ent.setValue("words_and", "android"); ent.setValue("words_or", "app aplicacion aplication"); ent.setValue("icon_id", 2); ent.setValue("icon_big", "drawable/icon_android"); ent.setValue("icon_small", "drawable/icon_android_small"); } else if (i == 3) { ent.setValue("words_and", "tilt shift"); ent.setValue("filter", 2); ent.setValue("icon_id", 17); ent.setValue("icon_big", "drawable/icon_photo"); ent.setValue("icon_small", "drawable/icon_photo_small"); } else if (i == 4) { ent.setValue("words_and", "hdr"); ent.setValue("filter", 2); ent.setValue("icon_id", 18); ent.setValue("icon_big", "drawable/icon_photo2"); ent.setValue("icon_small", "drawable/icon_photo2_small"); } else if (i == 5) { ent.setValue("lang", lang); ent.setValue("words_and", "true blood"); ent.setValue("icon_id", 1); ent.setValue("icon_big", "drawable/letter_t"); ent.setValue("icon_small", "drawable/letter_t_small"); } else if (i == 6) { ent.setValue("lang", lang); ent.setValue("words_and", "walking dead"); ent.setValue("icon_id", 1); ent.setValue("icon_big", "drawable/letter_w"); ent.setValue("icon_small", "drawable/letter_w_small"); } else if (i == 7) { ent.setValue("words_and", "4 8 15 16 23 42"); ent.setValue("icon_id", 1); ent.setValue("icon_big", "drawable/letter_n"); ent.setValue("icon_small", "drawable/letter_n_small"); } else if (i == 8) { ent.setValue("lang", lang); ent.setValue("words_or", "geek \"humor geek\""); ent.setValue("filter", 5); ent.setValue("icon_id", 14); ent.setValue("icon_big", "drawable/icon_news"); ent.setValue("icon_small", "drawable/icon_news_small"); } else if (i == 9) { ent.setValue("lang", lang); ent.setValue("words_or", "receta recipe"); ent.setValue("filter", 5); ent.setValue("icon_id", 14); ent.setValue("icon_big", "drawable/icon_news"); ent.setValue("icon_small", "drawable/icon_news_small"); } else if (i == 10) { ent.setValue("words_and", "slow motion"); ent.setValue("filter", 3); ent.setValue("icon_id", 3); ent.setValue("icon_big", "drawable/icon_cinema"); ent.setValue("icon_small", "drawable/icon_cinema_small"); } else if (i == 11) { ent.setValue("words_and", "stop motion"); ent.setValue("filter", 3); ent.setValue("icon_id", 4); ent.setValue("icon_big", "drawable/icon_cinema2"); ent.setValue("icon_small", "drawable/icon_cinema2_small"); } ent.save(); } } fillData(); } }).setNegativeButton(R.string.alert_dialog_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { } }).create(); builder.show(); }
From source file:com.example.sensingapp.SensingApp.java
private void refreshUploadFileNameBox() { int i;/* w w w . j a va 2s .co m*/ int nCnt = m_arrChkFilename.length; for (i = nCnt - 1; i >= 0; i--) { m_llUploadData_ChkLayoutFileName.removeViewAt(i); m_arrChkFilename[i] = null; } int nCount = m_lstUnUploadedFileName.size(); m_arrChkFilename = new CheckBox[nCount]; for (i = 0; i < nCount; i++) { m_arrChkFilename[i] = new CheckBox(this); m_arrChkFilename[i].setId(i); m_arrChkFilename[i].setText(getFileName(m_lstUnUploadedFileName.get(i))); m_arrChkFilename[i].setOnCheckedChangeListener(null); m_arrChkFilename[i].setLayoutParams(m_lpFilenameChkParams); m_llUploadData_ChkLayoutFileName.addView(m_arrChkFilename[i]); m_arrChkFilename[i].setEnabled(true); } }
From source file:org.onebusaway.android.report.ui.Open311ProblemFragment.java
/** * Dynamically creates checkboxes/*from www . j av a 2 s.co m*/ * * @param open311Attribute contains the open311 attributes */ private void createMultiValueList(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_multi_value_list_item, null, false); ((ImageView) layout.findViewById(R.id.ri_ic_checkbox)) .setColorFilter(getResources().getColor(R.color.material_gray)); Spannable word = new SpannableString(open311Attribute.getDescription()); ((TextView) layout.findViewById(R.id.rimvli_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.rimvli_textView)).append(wordTwo); } // Restore view state from attribute result hash map AttributeValue av = mAttributeValueHashMap.get(open311Attribute.getCode()); LinearLayout cg = (LinearLayout) layout.findViewById(R.id.rimvli_checkBoxGroup); for (int i = 0; i < values.size(); i++) { LinkedHashMap<String, String> value = (LinkedHashMap<String, String>) values.get(i); CheckBox cb = new CheckBox(getActivity()); cg.addView(cb); String attributeKey = ""; String attributeValue = ""; for (LinkedHashMap.Entry<String, String> entry : value.entrySet()) { if (Open311Attribute.NAME.equals(entry.getKey())) { cb.setText(entry.getValue()); if (av != null && av.getValues().contains(entry.getValue())) { cb.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(), cg); } }
From source file:com.juick.android.MainActivity.java
@TargetApi(VERSION_CODES.ICE_CREAM_SANDWICH) private void selectSourcesForCombined(final String prefix, final String[] codes) { final SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); ScrollView v = new ScrollView(this); v.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); final LinearLayout ll = new LinearLayout(this); ll.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); ll.setOrientation(LinearLayout.VERTICAL); v.addView(ll);/* w w w .j av a 2 s . c o m*/ for (int i = 0; i < codes.length; i++) { final CompoundButton sw = VERSION.SDK_INT >= 14 ? new Switch(this) : new CheckBox(this); sw.setPadding(10, 10, 10, 10); sw.setLayoutParams(new ScrollView.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); sw.setText(codes[i]); sw.setChecked(sp.getBoolean(prefix + codes[i], true)); ll.addView(sw); } new AlertDialog.Builder(MainActivity.this).setView(v).setCancelable(true) .setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { SharedPreferences.Editor e = sp.edit(); for (int i = 0; i < ll.getChildCount(); i++) { CompoundButton cb = (CompoundButton) ll.getChildAt(i); assert cb != null; e.putBoolean(prefix + codes[i], cb.isChecked()); } e.commit(); } }).create().show(); }
From source file:com.android.contacts.common.list.ContactListItemView.java
/** * Returns the {@link CheckBox} view, creating it if necessary. *///w ww. j ava 2s. co m public CheckBox getCheckBox() { if (mCheckBox == null) { mCheckBox = new CheckBox(getContext()); // Make non-focusable, so the rest of the ContactListItemView can be clicked. mCheckBox.setFocusable(false); addView(mCheckBox); } return mCheckBox; }
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();/*w ww . j ava 2s. c o 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 w ww.ja v a 2 s . com } // 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(); } }