List of usage examples for android.media MediaPlayer MediaPlayer
public MediaPlayer()
From source file:usbong.android.likha_collection_1.UsbongDecisionTreeEngineActivity.java
public void init() { //if return is null, then currScreen=0 // currScreen=Integer.parseInt(getIntent().getStringExtra("currScreen")); //modified by JPT, May 25, 2015 if (getIntent().getStringExtra("currScreen") != null) { currScreen = Integer.parseInt(getIntent().getStringExtra("currScreen")); }/* www .j a v a2 s .c o m*/ //updated by Mike, 20160608 /* currLanguageBeingUsed=UsbongUtils.LANGUAGE_ENGLISH; UsbongUtils.setCurrLanguage("English"); //added by Mike, 22 Sept. 2015 */ //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 9 June 2015 //answer by Elenasys //added by Mike, 9 June 2015 SharedPreferences prefs = getSharedPreferences(UsbongConstants.MY_SAVED_LANGUAGE_SETTING, MODE_PRIVATE); if (prefs != null) { //@todo: remove this id thing, immediately use the String; otherwise it'll be cumbersome to keep on adding language ids currLanguageBeingUsed = prefs.getInt("preferredLanguage", UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage())); //default is Filipino /* //commented out by Mike, 20160608 * //default language will be set based on the default language set in the .xml of the .utree file * UsbongUtils.setDefaultLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); */ UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed));//prefs.getInt("preferredLanguage", 0))); //updated by Mike, 20160612 } else { //default.. currLanguageBeingUsed = UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage()); //UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //updated by Mike, 20160612 } /* //commented out by Mike, 20160618 * //why? the index numbers used by currSelectedItemForSetLanguage does not always match with currLanguageBeingUsed * //added by Mike, 20160608 * currSelectedItemForSetLanguage = currLanguageBeingUsed; */ //================================================================== //text-to-speech stuff /*//comment out, not needed in DAHON, * commented out by Mike, 20160613 Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, UsbongUtils.MY_DATA_CHECK_CODE); */ mTts = new TextToSpeech(this, this); mTts.setLanguage(new Locale("en", "US"));//default //================================================================== myMediaPlayer = new MediaPlayer(); myMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); //added by Mike, 22 July 2015 myMediaPlayer.setVolume(1.0f, 1.0f); //added by Mike, 25 Sept. 2015 myBGMediaPlayer = new MediaPlayer(); myBGMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); myBGMediaPlayer.setVolume(0.5f, 0.5f); //added by Mike, 22 July 2015 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); usbongNodeContainer = new Vector<String>(); classificationContainer = new Vector<String>(); radioButtonsContainer = new Vector<String>(); usbongAnswerContainer = new Vector<String>(); checkBoxesContainer = new Vector<String>(); decisionTrackerContainer = new Vector<String>(); usedBackButton = false; currAnswer = ""; try { //commented out by Mike, 4 Oct. 2015 UsbongUtils.createUsbongFileStructure(); //added by Mike, 20160417 UsbongUtils.initUsbongConfigFile(); //create the usbong_demo_tree and store it in sdcard/usbong/usbong_trees // UsbongUtils.storeAssetsFileIntoSDCard(this,"usbong_demo_tree.xml"); // UsbongUtils.storeAssetsFileIntoSDCard(this,UsbongUtils.DEFAULT_UTREE_TO_LOAD+".utree"); //edited by Mike, 20161111 UsbongUtils.storeAssetsFileIntoSDCard(this, "pagtsing.utree"); UsbongUtils.storeAssetsFileIntoSDCard(this, "gamugamo.utree"); UsbongUtils.storeAssetsFileIntoSDCard(this, "juant.utree"); UsbongUtils.storeAssetsFileIntoSDCard(this, "pagtsing_icon.png"); UsbongUtils.storeAssetsFileIntoSDCard(this, "gamugamo_icon.png"); UsbongUtils.storeAssetsFileIntoSDCard(this, "juant_icon.png"); } catch (IOException ioe) { ioe.printStackTrace(); } //Reference: http://stackoverflow.com/questions/2793004/java-lista-addalllistb-fires-nullpointerexception //Last accessed: 14 March 2012 attachmentFilePaths = new ArrayList<String>(); // attachmentFilePaths.clear(); // System.out.println(">>>>>>>>> attachmentFilePaths.clear!"); currAudioRecorder = null; myQRCodeContent = ""; hasReturnedFromAnotherActivity = false; //camera, paint, email, etc //added by Mike, March 4, 2013 usbongAnswerContainerCounter = 0; /* ArrayList<String> skuList = new ArrayList<String> (); skuList.add(UsbongConstants.ALL_LOCAL_LANGUAGES_PRODUCT_ID); skuList.add(UsbongConstants.ALL_FOREIGN_LANGUAGES_PRODUCT_ID); Bundle querySkus = new Bundle(); querySkus.putStringArrayList("ITEM_ID_LIST", skuList); */ new AsyncTask<String, Integer, Boolean>() { @Override protected void onPostExecute(Boolean result) { //added by Mike, 20160421 //init purchase languages list purchaseLanguagesListDialog = new AlertDialog.Builder(getInstance()); myPurchaseLanguageBundleListAdapter = new PurchaseLanguageBundleListAdapter(getInstance(), UsbongUtils.getInAppOwnedItems(), UsbongUtils.getInAppMService()); purchaseLanguagesListDialog.setTitle("Purchase"); purchaseLanguagesListDialog.setSingleChoiceItems(myPurchaseLanguageBundleListAdapter, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Log.i("Selected Item : ", (String) myPurchaseLanguageBundleListAdapter.getItem(which)); dialog.dismiss(); //edited by Mike, 20160508 // purchaseLanguagesListDialogInterface = dialog; } }); purchaseLanguagesListDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } @Override protected Boolean doInBackground(String... params) { try { UsbongUtils.initInAppBillingService(getInstance()); UsbongUtils.initInAppBillingService(getInstance()); //need to call this twice to get the updated languageBundleList } catch (Exception e) { e.printStackTrace(); } return true; } }.execute(); //reference: Labeeb P's answer from stackoverflow; //http://stackoverflow.com/questions/4275797/view-setpadding-accepts-only-in-px-is-there-anyway-to-setpadding-in-dp; //last accessed: 23 May 2013 final float scale = getResources().getDisplayMetrics().density; padding_in_px = (int) (padding_in_dp * scale + 0.5f); //added by Mike, 25 June 2013 UsbongUtils.setDebugMode(UsbongUtils.isInDebugMode()); //added by Mike, 25 Feb. 2014 // UsbongUtils.setStoreOutput(UsbongUtils.checkIfStoreOutput()); UsbongUtils.setStoreOutput(false); //don't store output, added by Mike, 27 Sept. 2015 myUsbongScreenProcessor = new UsbongScreenProcessor(UsbongDecisionTreeEngineActivity.getInstance()); myUsbongVariableMemory = new HashMap<String, String>(); //added by Mike, March 26, 2014 try { Log.d(">>>>", "" + UsbongUtils.STORE_OUTPUT); if (UsbongUtils.STORE_OUTPUT) { //added by Mike, 27 Sept. 2015 UsbongUtils.createNewOutputFolderStructure(); } } catch (Exception e) { e.printStackTrace(); } /*//commented out by Mike, 20161110 //added by Mike, 30 April 2015 isInTreeLoader=false; myTree = UsbongUtils.DEFAULT_UTREE_TO_LOAD; //edited by Mike, 20160418 UsbongUtils.clearTempFolder(); */ initTreeLoader(); }
From source file:com.googlecode.mindbell.accessors.ContextAccessor.java
/** * Start playing bell sound and call runWhenDone when playing finishes but only if bell is not muted - returns true when * sound has been started, false otherwise. *//*from w w w . jav a 2 s . com*/ private boolean startPlayingSound(ActivityPrefsAccessor activityPrefs, final Runnable runWhenDone) { Uri bellUri = activityPrefs.getSoundUri(context); audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); if (prefs.isNoSoundOnMusic() && audioManager.isMusicActive()) { MindBell.logDebug("Sound suppressed because setting is no sound on music and music is playing"); return false; } else if (bellUri == null) { MindBell.logDebug("Sound suppressed because no sound has been set"); return false; } else if (prefs.isPauseAudioOnSound()) { int requestResult = audioManager.requestAudioFocus(this, prefs.getAudioStream(), retrieveDurationHint()); if (requestResult == AUDIOFOCUS_REQUEST_FAILED) { MindBell.logDebug( "Sound suppressed because setting is pause audio on sound and request of audio focus failed"); return false; } MindBell.logDebug("Audio focus successfully requested"); } if (prefs.isUseAudioStreamVolumeSetting()) { // we don't care about setting the volume MindBell.logDebug("Start playing sound without touching audio stream volume"); } else { int originalVolume = getAlarmVolume(); int alarmMaxVolume = getAlarmMaxVolume(); if (originalVolume == alarmMaxVolume) { // "someone" else set it to max, so we don't touch it MindBell.logDebug("Start playing sound found originalVolume " + originalVolume + " to be max, alarm volume left untouched"); } else { MindBell.logDebug("Start playing sound found and stored originalVolume " + originalVolume + ", setting alarm volume to max"); setAlarmVolume(alarmMaxVolume); prefs.setOriginalVolume(originalVolume); } } mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(prefs.getAudioStream()); if (!prefs.isUseAudioStreamVolumeSetting()) { // care about setting the volume float bellVolume = activityPrefs.getVolume(); mediaPlayer.setVolume(bellVolume, bellVolume); } try { try { mediaPlayer.setDataSource(context, bellUri); } catch (IOException e) { // probably because of withdrawn permissions, hence use default bell mediaPlayer.setDataSource(context, prefs.getDefaultReminderBellSoundUri(context)); } mediaPlayer.prepare(); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { public void onCompletion(MediaPlayer mp) { finishBellSound(); if (runWhenDone != null) { runWhenDone.run(); } } }); mediaPlayer.start(); return true; } catch (IOException e) { Log.e(TAG, "Could not start playing sound: " + e.getMessage(), e); finishBellSound(); return false; } }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
public void tapOnSpeakableButton(final IOSpeakableImageButton spkBtn, final Integer level) { if (IOGlobalConfiguration.isEditing) { AlertDialog.Builder builder = new AlertDialog.Builder(this); LayoutInflater inflater = getLayoutInflater(); View layoutView = inflater.inflate(R.layout.editmode_alertview, null); builder.setTitle(getString(R.string.choose)); builder.setView(layoutView);/*from ww w. j a v a 2s . c o m*/ final AlertDialog dialog = builder.create(); final Switch matrioskaSwitch = (Switch) layoutView.findViewById(R.id.editModeAlertToggleBoard); Button editPictoButton = (Button) layoutView.findViewById(R.id.editModeAlertActionPicture); final Button editBoardButton = (Button) layoutView.findViewById(R.id.editModeAlertActionBoard); matrioskaSwitch.setChecked(spkBtn.getIsMatrioska()); editBoardButton.setEnabled(spkBtn.getIsMatrioska()); matrioskaSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { spkBtn.setIsMatrioska(isChecked); editBoardButton.setEnabled(isChecked); } }); editPictoButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //spkBtn.showInsertDialog(); Intent cIntent = new Intent(getApplicationContext(), IOCreateButtonActivity.class); cIntent.putExtra(BUTTON_INDEX, mActualLevel.getBoardAtIndex(mActualIndex).getButtons().indexOf(spkBtn)); cIntent.putExtra(BUTTON_TEXT, spkBtn.getSentence()); cIntent.putExtra(BUTTON_TITLE, spkBtn.getmTitle()); cIntent.putExtra(BUTTON_IMAGE_FILE, spkBtn.getmImageFile()); cIntent.putExtra(BUTTON_AUDIO_FILE, spkBtn.getAudioFile()); startActivityForResult(cIntent, CREATE_BUTTON_CODE); matrioskaSwitch.setOnCheckedChangeListener(null); dialog.dismiss(); } }); editBoardButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { IOLevel nestedBoard = spkBtn.getLevel(); pushLevel(nestedBoard); matrioskaSwitch.setOnCheckedChangeListener(null); dialog.dismiss(); } }); dialog.show(); } else { if (IOGlobalConfiguration.isScanMode) { IOSpeakableImageButton scannedButton = mActualLevel.getBoardAtIndex(mActualIndex).getButtons() .get(mActualScanIndex); if (scannedButton.getAudioFile() != null && scannedButton.getAudioFile().length() > 0) { final MediaPlayer mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(scannedButton.getAudioFile()); mPlayer.prepare(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mPlayer.release(); } }); mPlayer.start(); } catch (IOException e) { Log.e("playback_debug", "prepare() failed"); } } else if (mCanSpeak) { Log.d("speakable_debug", "should say: " + scannedButton.getSentence()); if (scannedButton.getSentence() == "") tts.speak(getResources().getString(R.string.tts_nosentence), TextToSpeech.QUEUE_FLUSH, null); else tts.speak(scannedButton.getSentence(), TextToSpeech.QUEUE_FLUSH, null); } else { Toast.makeText(this, getResources().getString(R.string.tts_notinitialized), Toast.LENGTH_LONG) .show(); } if (scannedButton.getIsMatrioska() && null != scannedButton.getLevel()) { pushLevel(scannedButton.getLevel()); } } else { if (spkBtn.getAudioFile() != null && spkBtn.getAudioFile().length() > 0) { final MediaPlayer mPlayer = new MediaPlayer(); try { mPlayer.setDataSource(spkBtn.getAudioFile()); mPlayer.prepare(); mPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { mPlayer.release(); } }); mPlayer.start(); } catch (IOException e) { Log.e("playback_debug", "prepare() failed"); } } else if (mCanSpeak) { Log.d("speakable_debug", "should say: " + spkBtn.getSentence()); if (spkBtn.getSentence() == "") tts.speak(getResources().getString(R.string.tts_nosentence), TextToSpeech.QUEUE_FLUSH, null); else tts.speak(spkBtn.getSentence(), TextToSpeech.QUEUE_FLUSH, null); } else { Toast.makeText(this, getResources().getString(R.string.tts_notinitialized), Toast.LENGTH_LONG) .show(); } if (spkBtn.getIsMatrioska() && null != spkBtn.getLevel()) { pushLevel(spkBtn.getLevel()); } } } }
From source file:edu.chl.dat255.sofiase.readyforapet.viewcontroller.PetActivity.java
/** * Method called when dog dies./*from w w w.j ava2 s . c om*/ * Sets text, disables buttons, starts deathmusic and deletes saved file. * */ private void killPet() { petResponse.setText(petName + " has unfortunately died!"); showPetAge.setVisibility(View.GONE); //Disabling buttons play.setEnabled(false); eat.setEnabled(false); walk.setEnabled(false); sleep.setEnabled(false); musicCheckBox.setEnabled(false); //Stops the default background music player.stop(); //Music that plays when dog dies try { deathAfd = getAssets().openFd("deathsound.m4v"); deathplayer = new MediaPlayer(); deathplayer.setDataSource(deathAfd.getFileDescriptor(), deathAfd.getStartOffset(), deathAfd.getLength()); deathplayer.prepare(); deathplayer.start(); } catch (IOException e) { e.printStackTrace(); } //Deleting the existing saved dog deleteFile("pet_file.dat"); }
From source file:audio.lisn.adapter.StoreBookViewAdapter.java
private void playPreview() { isLoadingPreview = true;// w ww . ja va2s . c o m isPlayingPreview = false; pausePlayer(); notifyDataSetChanged(); if (connectionDetector.isConnectingToInternet()) { if (mediaPlayer == null) { mediaPlayer = new MediaPlayer(); } if (mediaPlayer.isPlaying()) { mediaPlayer.stop(); if (timerUpdateThread != null) { timerUpdateThread.interrupt(); } } mediaPlayer.reset(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try { mediaPlayer.setDataSource(selectedAudioBook.getPreview_audio()); } catch (IOException e) { Log.v("playPreview", "IOException" + e.getMessage()); e.printStackTrace(); } mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { public void onPrepared(MediaPlayer mp) { isPlayingPreview = true; isLoadingPreview = false; startTimer(); mp.start(); notifyDataSetChanged(); } }); mediaPlayer.setOnErrorListener(new MediaPlayer.OnErrorListener() { public boolean onError(MediaPlayer mp, int what, int extra) { notifyDataSetChanged(); String msg = ""; if (extra == MediaPlayer.MEDIA_ERROR_IO) { msg = "MEDIA_ERROR_IO"; } else if (extra == MediaPlayer.MEDIA_ERROR_MALFORMED) { msg = "MEDIA_ERROR_MALFORMED"; } else if (extra == MediaPlayer.MEDIA_ERROR_UNSUPPORTED) { msg = "MEDIA_ERROR_UNSUPPORTED"; } else if (extra == MediaPlayer.MEDIA_ERROR_TIMED_OUT) { msg = "MEDIA_ERROR_TIMED_OUT"; } else { msg = "video_error_unknown_error"; } showErrorMessage(msg); return false; } }); mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { isPlayingPreview = false; isLoadingPreview = false; stopTimer(); notifyDataSetChanged(); } }); try { mediaPlayer.prepareAsync(); // prepare async to not block main } catch (Exception e) { showErrorMessage(e.getMessage()); isPlayingPreview = false; isLoadingPreview = false; stopTimer(); notifyDataSetChanged(); } } else { AlertDialog.Builder builder = new AlertDialog.Builder(selectedView.getContext()); builder.setTitle(R.string.NO_INTERNET_TITLE).setMessage(R.string.NO_INTERNET_MESSAGE) .setPositiveButton(R.string.BUTTON_OK, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // FIRE ZE MISSILES! } }); AlertDialog dialog = builder.create(); dialog.show(); } }
From source file:usbong.android.retrocc.UsbongDecisionTreeEngineActivity.java
public void init() { //if return is null, then currScreen=0 // currScreen=Integer.parseInt(getIntent().getStringExtra("currScreen")); //modified by JPT, May 25, 2015 if (getIntent().getStringExtra("currScreen") != null) { currScreen = Integer.parseInt(getIntent().getStringExtra("currScreen")); }//from ww w. jav a 2s . c o m //updated by Mike, 20160608 /* currLanguageBeingUsed=UsbongUtils.LANGUAGE_ENGLISH; UsbongUtils.setCurrLanguage("English"); //added by Mike, 22 Sept. 2015 */ //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 9 June 2015 //answer by Elenasys //added by Mike, 9 June 2015 SharedPreferences prefs = getSharedPreferences(UsbongConstants.MY_SAVED_LANGUAGE_SETTING, MODE_PRIVATE); if (prefs != null) { //@todo: remove this id thing, immediately use the String; otherwise it'll be cumbersome to keep on adding language ids currLanguageBeingUsed = prefs.getInt("preferredLanguage", UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage())); //default is Filipino /* //commented out by Mike, 20160608 * //default language will be set based on the default language set in the .xml of the .utree file * UsbongUtils.setDefaultLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); */ UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed));//prefs.getInt("preferredLanguage", 0))); //updated by Mike, 20160612 } else { //default.. currLanguageBeingUsed = UsbongUtils.getLanguageID(UsbongUtils.getCurrLanguage()); //UsbongUtils.setCurrLanguage(UsbongUtils.getLanguageBasedOnID(currLanguageBeingUsed)); //updated by Mike, 20160612 } /* //commented out by Mike, 20160618 * //why? the index numbers used by currSelectedItemForSetLanguage does not always match with currLanguageBeingUsed * //added by Mike, 20160608 * currSelectedItemForSetLanguage = currLanguageBeingUsed; */ //================================================================== //text-to-speech stuff /*//comment out, not needed in DAHON, * commented out by Mike, 20160613 Intent checkIntent = new Intent(); checkIntent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA); startActivityForResult(checkIntent, UsbongUtils.MY_DATA_CHECK_CODE); */ mTts = new TextToSpeech(this, this); mTts.setLanguage(new Locale("en", "US"));//default //================================================================== myMediaPlayer = new MediaPlayer(); myMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); //added by Mike, 22 July 2015 myMediaPlayer.setVolume(1.0f, 1.0f); //added by Mike, 25 Sept. 2015 myBGMediaPlayer = new MediaPlayer(); myBGMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); myBGMediaPlayer.setVolume(0.5f, 0.5f); //added by Mike, 22 July 2015 AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE); am.setStreamVolume(AudioManager.STREAM_MUSIC, am.getStreamMaxVolume(AudioManager.STREAM_MUSIC), 0); usbongNodeContainer = new Vector<String>(); classificationContainer = new Vector<String>(); radioButtonsContainer = new Vector<String>(); usbongAnswerContainer = new Vector<String>(); checkBoxesContainer = new Vector<String>(); decisionTrackerContainer = new Vector<String>(); usedBackButton = false; currAnswer = ""; try { //commented out by Mike, 4 Oct. 2015 UsbongUtils.createUsbongFileStructure(); //added by Mike, 20160417 UsbongUtils.initUsbongConfigFile(); //create the usbong_demo_tree and store it in sdcard/usbong/usbong_trees // UsbongUtils.storeAssetsFileIntoSDCard(this,"usbong_demo_tree.xml"); /* UsbongUtils.storeAssetsFileIntoSDCard(this,UsbongUtils.DEFAULT_UTREE_TO_LOAD+".utree"); */ //edited by Mike, 20160119 UsbongUtils.storeAssetsFileIntoSDCard(this, UsbongConstants.TREE_TYPE_SELL + ".utree"); UsbongUtils.storeAssetsFileIntoSDCard(this, UsbongConstants.TREE_TYPE_REQUEST + ".utree"); UsbongUtils.storeAssetsFileIntoSDCard(this, UsbongConstants.TREE_TYPE_BUY + ".utree"); //added by Mike, 20160126 //added by Mike, 20160126 UsbongUtils.storeAssetsFileIntoSDCard(this, UsbongConstants.ITEMS_LIST_COMICS + ".txt"); UsbongUtils.storeAssetsFileIntoSDCard(this, UsbongConstants.ITEMS_LIST_TOYS + ".txt"); } catch (IOException ioe) { ioe.printStackTrace(); } //Reference: http://stackoverflow.com/questions/2793004/java-lista-addalllistb-fires-nullpointerexception //Last accessed: 14 March 2012 attachmentFilePaths = new ArrayList<String>(); // attachmentFilePaths.clear(); // System.out.println(">>>>>>>>> attachmentFilePaths.clear!"); currAudioRecorder = null; myQRCodeContent = ""; hasReturnedFromAnotherActivity = false; //camera, paint, email, etc //added by Mike, March 4, 2013 usbongAnswerContainerCounter = 0; /* ArrayList<String> skuList = new ArrayList<String> (); skuList.add(UsbongConstants.ALL_LOCAL_LANGUAGES_PRODUCT_ID); skuList.add(UsbongConstants.ALL_FOREIGN_LANGUAGES_PRODUCT_ID); Bundle querySkus = new Bundle(); querySkus.putStringArrayList("ITEM_ID_LIST", skuList); */ new AsyncTask<String, Integer, Boolean>() { @Override protected void onPostExecute(Boolean result) { //added by Mike, 20160421 //init purchase languages list purchaseLanguagesListDialog = new AlertDialog.Builder(getInstance()); myPurchaseLanguageBundleListAdapter = new PurchaseLanguageBundleListAdapter(getInstance(), UsbongUtils.getInAppOwnedItems(), UsbongUtils.getInAppMService()); purchaseLanguagesListDialog.setTitle("Purchase"); purchaseLanguagesListDialog.setSingleChoiceItems(myPurchaseLanguageBundleListAdapter, 0, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { // Log.i("Selected Item : ", (String) myPurchaseLanguageBundleListAdapter.getItem(which)); dialog.dismiss(); //edited by Mike, 20160508 // purchaseLanguagesListDialogInterface = dialog; } }); purchaseLanguagesListDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); } }); } @Override protected Boolean doInBackground(String... params) { try { UsbongUtils.initInAppBillingService(getInstance()); UsbongUtils.initInAppBillingService(getInstance()); //need to call this twice to get the updated languageBundleList } catch (Exception e) { e.printStackTrace(); } return true; } }.execute(); //reference: Labeeb P's answer from stackoverflow; //http://stackoverflow.com/questions/4275797/view-setpadding-accepts-only-in-px-is-there-anyway-to-setpadding-in-dp; //last accessed: 23 May 2013 final float scale = getResources().getDisplayMetrics().density; padding_in_px = (int) (padding_in_dp * scale + 0.5f); //added by Mike, 25 June 2013 UsbongUtils.setDebugMode(UsbongUtils.isInDebugMode()); //added by Mike, 25 Feb. 2014 // UsbongUtils.setStoreOutput(UsbongUtils.checkIfStoreOutput()); UsbongUtils.setStoreOutput(false); //don't store output, added by Mike, 27 Sept. 2015 myUsbongScreenProcessor = new UsbongScreenProcessor(UsbongDecisionTreeEngineActivity.getInstance()); myUsbongVariableMemory = new HashMap<String, String>(); /* //Reference: http://stackoverflow.com/questions/23024831/android-shared-preferences-example //; last accessed: 20150609 //answer by Elenasys //added by Mike, 20150207 prefs = getSharedPreferences(UsbongConstants.MY_ACCOUNT_DETAILS, MODE_PRIVATE); if (prefs!=null) { setVariableOntoMyUsbongVariableMemory("firstName", prefs.getString("firstName", ""));//"" is the default value. setVariableOntoMyUsbongVariableMemory("surname", prefs.getString("surname", ""));//"" is the default value. setVariableOntoMyUsbongVariableMemory("contactNumber", prefs.getString("contactNumber", ""));//"" is the default value. setVariableOntoMyUsbongVariableMemory("shippingAddress", prefs.getString("shippingAddress", ""));//"" is the default value. } else { setVariableOntoMyUsbongVariableMemory("firstName", "");//"" is the default value. setVariableOntoMyUsbongVariableMemory("surname", "");//"" is the default value. setVariableOntoMyUsbongVariableMemory("contactNumber", "");//"" is the default value. setVariableOntoMyUsbongVariableMemory("shippingAddress", "");//"" is the default value. } */ //added by Mike, March 26, 2014 try { Log.d(">>>>", "" + UsbongUtils.STORE_OUTPUT); if (UsbongUtils.STORE_OUTPUT) { //added by Mike, 27 Sept. 2015 UsbongUtils.createNewOutputFolderStructure(); } } catch (Exception e) { e.printStackTrace(); } /* // initTreeLoader(); //added by JPT, May 25, 2015 if(getIntent().getStringExtra(Constants.UTREE_KEY) != null) { Log.d("DecisionTree", getIntent().getStringExtra(Constants.UTREE_KEY)); initParser(getIntent().getStringExtra(Constants.UTREE_KEY)); } else { initTreeLoader(); } */ /* initTreeLoader(); //not needed in Usbong Kuto, Mike, 25 Sept 2015 */ //added by Mike, 30 April 2015 isInTreeLoader = false; //added by Mike, 20160119 if (getIntent().getStringExtra("utreeToLoad") != null) { myTree = getIntent().getStringExtra("utreeToLoad"); } else { myTree = UsbongUtils.DEFAULT_UTREE_TO_LOAD; //edited by Mike, 20160418 } UsbongUtils.clearTempFolder(); // isr=null; //set inputStreamReader to null; i.e. new tree /* initParser(); */ // myProgressDialog.dismiss(); /* //added by Mike, 29 Sept. 2015 //Reference: http://stackoverflow.com/questions/10407159/how-to-manage-startactivityforresult-on-android; //last accessed: 29 Sept. 2015; answer by Nishant, 2 May 2012; edited by Daniel Nugent, 9 July 2015 Intent returnIntent = new Intent(); returnIntent.putExtra("result","result"); setResult(RESULT_OK,returnIntent); */ }
From source file:com.mitre.holdshort.MainActivity.java
private void startMainActivity() { // Set screen layout setContentView(R.layout.main);//from w w w. jav a 2s . c o m imageHelper = new ImageHelper(); summaryGestureDetector = new GestureDetector(new summaryGester()); // Get Reference to Shared Preferences file auralAlerts = settings.getBoolean("auralAlerts", true); settings.edit().putBoolean("auralAlerts", auralAlerts); announceRWY = settings.getBoolean("announceRWY", true); settings.edit().putBoolean("announceRWY", announceRWY); // Airport ID airportID = (TextView) findViewById(R.id.airportID); airportID.setText("K" + airport); // SpeechButton speechBtn = (ImageView) findViewById(R.id.speechBtn); speechBtn.setOnClickListener(speechBtnClickListener); // Get open close button openClose = (TextView) findViewById(R.id.openClose); openClose.setText("close"); // openClose.setTextColor(Color.argb(200, 255, 255, 255)); openClose.setOnClickListener(openCloseListener); // departure runway button depRwyBtn = (TextView) findViewById(R.id.depRwyBtn); depRwyBtn.setOnClickListener(depRwyListener); depRwyBtn.setText("Departure Rwy"); depRwyBtn.setBackgroundResource(R.drawable.hatched_small_bg_layer); depRwyBtn.setPadding(10, 5, 10, 5); // info button - used to start prefs activity infoBtn = (ImageButton) findViewById(R.id.info_btn); // infoBtn.setBackgroundColor(Color.rgb(0,0,0)); infoBtn.setOnClickListener(settingsMenuListener); // taxi button - used to start Taxi instruction activity taxiBtn = (ImageButton) findViewById(R.id.taxi_btn); // taxiBtn.setBackgroundColor(Color.rgb(0,0,0)); taxiBtn.setOnClickListener(taxiBtnListener); // summary info - when drawer is closed summaryBar = (RelativeLayout) findViewById(R.id.summaryBar); summaryBar.setOnTouchListener(summaryTouchListener); runwayContainer = (LinearLayout) findViewById(R.id.holder); innerHolder = (LinearLayout) findViewById(R.id.innerHolder); slidingPanel = (SlidingPanel) findViewById(R.id.slidingDrawer); // header header = (RelativeLayout) findViewById(R.id.header); headerDropShadow = (View) findViewById(R.id.header_drop_shadow); slidingPanel.setHeaderDropShadow(headerDropShadow); slidingPanel.setRunwayContainer(runwayContainer); slidingPanel.setOpenCloseTextView(openClose); slidingPanel.setHandler(this.handler); summaryInfo = (RelativeLayout) findViewById(R.id.summary_info); summary_index = (TextView) findViewById(R.id.summary_index); summary_thumb = (TextView) findViewById(R.id.summary_thumb); summary_thumb.setWidth(90); // Taxi path area taxiClearance = (TextView) findViewById(R.id.taxiClearance); taxiClearance.setTextSize(12); taxiClearance.setPadding(5, 0, 5, 0); taxiClearance.setTextColor(Color.WHITE); // taxiClearance.setBackgroundColor(Color.rgb(0,0,0)); taxiClearance.setOnClickListener(taxiPathListener); // Airport Diagram plateView = (AirportPlateView) findViewById(R.id.plateView); // Set up the nav control for the moving map // this is used when ownship is off screen navControl = (ImageView) findViewById(R.id.showNavBtn); plateView.setNavControls(navControl); navControl.setVisibility(ImageView.INVISIBLE); navControl.setOnClickListener(navControlListener); // // Lat/Lon Ref 1 SFO Point latLon1 = new Point(37.627827, -122.366794); Point latLon2 = new Point(37.606827, -122.380724); XYPoint xy1 = new XYPoint(134, 173); XYPoint xy2 = new XYPoint(340, 281); // Lat/Lon Ref 1 HEF // Point latLon1 = new Point(38.727680,-77.518803); // Point latLon2 = new Point(38.714041,-77.508976); // XYPoint xy1 = new XYPoint(140,187); // XYPoint xy2 = new XYPoint(322,513); plateView.geoReference(latLon1, latLon2, xy1, xy2); Location loc = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER); plateView.updatePosition(loc.getBearing(), loc.getLatitude(), loc.getLongitude()); // navView.setScroll(plateView); TextView emptyPlate = (TextView) findViewById(R.id.emptyPlate); if (!(plateView.setImage(airport))) { // Place holder if no plate is available emptyPlate.setVisibility(View.VISIBLE); plateView.setVisibility(View.GONE); } else { // Show plate. Hide placeholder plateView.setImage(airport); emptyPlate.setVisibility(View.GONE); } // Create logger for alerts alertLogger = new AlertLogger(airport, MainActivity.this); // Alert Panels alertScreen = (RelativeLayout) findViewById(R.id.alertScreen); betaControls = (LinearLayout) findViewById(R.id.betaControls); goodAlert = (TextView) findViewById(R.id.goodAlert); goodAlert.setOnClickListener(alertResponseListener); badAlert = (TextView) findViewById(R.id.badAlert); badAlert.setOnClickListener(alertResponseListener); lateAlert = (TextView) findViewById(R.id.lateAlert); lateAlert.setOnClickListener(alertResponseListener); earlyAlert = (TextView) findViewById(R.id.earlyAlert); earlyAlert.setOnClickListener(alertResponseListener); miniAlert = (TextView) findViewById(R.id.miniAlertText); miniAlert.setOnClickListener(maximizeAlert); holdShort = (LinearLayout) findViewById(R.id.holdShort); holdShort.getChildAt(0).setBackgroundDrawable(imageHelper .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10)); holdShort.setOnClickListener(minimizeAlert); noClearance = (LinearLayout) findViewById(R.id.noClearance); noClearance.setOnClickListener(minimizeAlert); noClearance.getChildAt(0).setBackgroundDrawable(imageHelper .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10)); crossingAlert = (LinearLayout) findViewById(R.id.crossingAlert); noTakeoffClearance = (LinearLayout) findViewById(R.id.noTakeoffClearance); noTakeoffClearance.getChildAt(0).setBackgroundDrawable(imageHelper .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.alert), 10)); noTakeoffClearance.setOnClickListener(minimizeAlert); disabled_gps = (LinearLayout) findViewById(R.id.disabled_gps); disabled_gps.getChildAt(0).setBackgroundDrawable(imageHelper .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.disabled), 10)); disabled_gps.setOnClickListener(minimizeAlert); disabled_speed = (LinearLayout) findViewById(R.id.disabled_speed); disabled_speed.getChildAt(0).setBackgroundDrawable(imageHelper .getRoundedCornerBitmap(BitmapFactory.decodeResource(getResources(), R.drawable.disabled), 10)); disabled_speed.setOnClickListener(minimizeAlert); // Instantiate media player & set completion listener mp = new MediaPlayer(); mp.setOnCompletionListener(alertPlaybackListener); // Instruction List instantiation instructionList = new ArrayList<String>(); setUpRunways(); slidingPanel.setOnTouchListener(summaryTouchListener); // Instantiate Alert Manager alertManager = new AlertManager(rwyMgr); allSetUp = true; }
From source file:org.mercycorps.translationcards.activity.RecordingActivity.java
private void startListening() { recordButton.setBackgroundResource(R.drawable.button_record_disabled); listenButton.setBackgroundResource(R.drawable.button_listen_active); recordingStatus = RecordingStatus.LISTENING; mediaPlayer = new MediaPlayer(); mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); try {/*from w ww .j a v a2 s . co m*/ if (isAsset) { AssetFileDescriptor fd = getAssets().openFd(filename); mediaPlayer.setDataSource(fd.getFileDescriptor(), fd.getStartOffset(), fd.getLength()); fd.close(); } else { mediaPlayer.setDataSource(new FileInputStream(filename).getFD()); } mediaPlayer.prepare(); } catch (IOException e) { Log.d(TAG, "Error preparing audio."); throw new IllegalArgumentException(e); // TODO(nworden): something } mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() { @Override public void onCompletion(MediaPlayer mp) { finishListening(); } }); mediaPlayer.start(); }
From source file:com.bayapps.android.robophish.playback.LocalPlayback.java
/** * Makes sure the media player exists and has been reset. This will create * the media player if needed, or reset the existing media player if one * already exists.// ww w. j a va2 s . c o m */ private MediaPlayer createMediaPlayer(MediaPlayer player) { LogHelper.d(TAG, "createMediaPlayerIfNeeded. needed? ", (player == null)); if (player == null) { player = new MediaPlayer(); // Make sure the media player will acquire a wake-lock while // playing. If we don't do that, the CPU might go to sleep while the // song is playing, causing playback to stop. player.setWakeMode(mContext.getApplicationContext(), PowerManager.PARTIAL_WAKE_LOCK); // we want the media player to notify us when it's ready preparing, // and when it's done playing: player.setOnPreparedListener(this); player.setOnCompletionListener(this); player.setOnErrorListener(this); player.setOnSeekCompleteListener(this); } else { player.reset(); } return player; }
From source file:dk.ciid.android.infobooth.activities.IntroductionActivity.java
private void initMediaPlayer() { String PATH_TO_FILE = voice1; mediaPlayer = new MediaPlayer(); try {/*from w ww .j a v a2 s . co m*/ mediaPlayer.setDataSource(PATH_TO_FILE); mediaPlayer.prepare(); //Toast.makeText(this, PATH_TO_FILE, Toast.LENGTH_LONG).show(); stateMediaPlayer = stateMP_NotStarter; } catch (IllegalArgumentException e) { // TODO Auto-generated catch block e.printStackTrace(); //Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); stateMediaPlayer = stateMP_Error; } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); //Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); stateMediaPlayer = stateMP_Error; } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); //Toast.makeText(this, e.toString(), Toast.LENGTH_LONG).show(); stateMediaPlayer = stateMP_Error; } }