Example usage for android.speech.tts TextToSpeech TextToSpeech

List of usage examples for android.speech.tts TextToSpeech TextToSpeech

Introduction

In this page you can find the example usage for android.speech.tts TextToSpeech TextToSpeech.

Prototype

public TextToSpeech(Context context, OnInitListener listener) 

Source Link

Document

The constructor for the TextToSpeech class, using the default TTS engine.

Usage

From source file:com.nbplus.vbroadlauncher.BroadcastWebViewActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    Log.d(TAG, ">>> onActivityResult...");
    switch (requestCode) {
    case Constants.START_ACTIVITY_REQUEST_CHECK_TTS_DATA:
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // check korean
            mText2Speech = new TextToSpeech(this, this);
        } else {/*w  w w  . ja  va 2 s  . c  om*/
            Log.d(TAG, "   ??.... ? ??...");
            showText2SpeechAlertDialog();

            LauncherSettings.getInstance(this).setIsCheckedTTSEngine(true);
        }
        break;
    case Constants.START_ACTIVITY_REQUEST_ENABLE_BT:
        if (mWebViewClient.getUpdateIoTDevicesDialogFragment() != null) {
            mWebViewClient.getUpdateIoTDevicesDialogFragment().onActivityResult(requestCode, resultCode, data);
        }
        break;
    }
}

From source file:net.zorgblub.typhon.fragment.ReadingFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setHasOptionsMenu(true);//from www .  j av a 2  s  .  c  o m

    this.bookView.init();

    this.progressBar.setFocusable(true);
    this.progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        private int seekValue;

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            bookView.navigateToPercentage(this.seekValue);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                seekValue = progress;
                percentageField.setText(progress + "% ");
            }
        }
    });

    this.mediaProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                seekToPointInPlayback(progress);
            }
        }
    });

    this.textToSpeech = new TextToSpeech(context, this::onTextToSpeechInit);

    this.bookView.addListener(this);
    this.bookView.setTextSelectionCallback(this);

    this.dictionaryPane.setBookReader(this);
}

From source file:com.aujur.ebookreader.activity.ReadingFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    setHasOptionsMenu(true);/*  ww  w . j av a 2  s.  com*/
    this.bookView.init();

    readingFragmentWraper = new ReadingFragmentWraper();
    readingFragmentWraper.setReadingFragment(this);

    bookViewWraper = new BookViewWraper();
    bookViewWraper.setBookView(this.bookView);

    searchResultWraper = new SearchResultWraper();
    searchResultWraper.setSearchResult(this.searchResults);

    this.progressBar.setFocusable(true);
    this.progressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        private int seekValue;

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            bookView.navigateToPercentage(this.seekValue);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                seekValue = progress;
                percentageField.setText(progress + "% ");
            }
        }
    });

    this.mediaProgressBar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            if (fromUser) {
                seekToPointInPlayback(progress);
            }
        }
    });

    this.textToSpeech = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
        @Override
        public void onInit(int status) {
            onTextToSpeechInit(status);
        }
    });

    this.bookView.addListener(this);
    this.bookView.setTextSelectionCallback(this);
}

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"));
    }//  w  ww .  j  a  va 2  s .  co  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.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    switch (requestCode) {
    case Constants.START_ACTIVITY_REQUEST_CHECK_TTS_DATA:
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            // check korean
            mText2Speech = new TextToSpeech(this, this);
        } else {//from   www .j  a v a2 s  . co m
            Log.d(TAG, "   ??.... ? ??...");
            showText2SpeechAlertDialog();

            LauncherSettings.getInstance(this).setIsCheckedTTSEngine(true);
        }
        break;
    }
}

From source file:com.microsoft.projectoxford.face.samples.ui.IdentificationActivity.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == MY_DATA_CHECK_CODE) {
        myTTS = new TextToSpeech(this, this);
    }//from ww  w .  j  a va 2  s . co m

    switch (requestCode) {
    case REQUEST_SELECT_IMAGE:
        if (resultCode == RESULT_OK) {
            detected = false;

            // If image is selected successfully, set the image URI and bitmap.
            Uri imageUri = data.getData();
            if (mBitmap == null) {
                mBitmap = ImageHelper.loadSizeLimitedBitmapFromUri(imageUri, getContentResolver());
                if (mBitmap != null) {
                    // Show the image on screen.
                    ImageView imageView = (ImageView) findViewById(R.id.image);
                    imageView.setImageBitmap(mBitmap);
                }
            }

            // Clear the identification result.
            FaceListAdapter faceListAdapter = new FaceListAdapter(null);
            ListView listView = (ListView) findViewById(R.id.list_identified_faces);
            listView.setAdapter(faceListAdapter);

            // Clear the information panel.
            setInfo("");

            // TODO -> Load image from Firebase, and save it as a Bitmap Object here.

            // Start detecting in image.
            detect(mBitmap);
        }
        break;
    default:
        break;
    }
}

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"));
    }/* w ww  .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, 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.lofland.housebot.BotController.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.housebot);/*from   w  w  w  .  ja  v a  2s . co  m*/
    Log.d(TAG, "onCreate");

    /*
     * TODO: If you need to maintain and pass around context:
     * http://stackoverflow.com/questions/987072/using-application-context-everywhere
     */

    // Display start up toast:
    // http://developer.android.com/guide/topics/ui/notifiers/toasts.html
    Context context = getApplicationContext();
    CharSequence text = "ex Nehilo!";
    int duration = Toast.LENGTH_SHORT;
    Toast toast = Toast.makeText(context, text, duration);
    // Display said toast
    toast.show();

    /*
     *  Turn on WiFi if it is off
     *  http://stackoverflow.com/questions/8863509/how-to-programmatically-turn-off-wifi-on-android-device
     */
    WifiManager wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
    wifiManager.setWifiEnabled(true);

    // Prevent keyboard from popping up as soon as app launches: (it works!)
    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    /*
     * Keep the screen on, because as long as we are talking to the robot, this needs to be up http://stackoverflow.com/questions/9335908/how-to- prevent-the-screen-of
     * -an-android-device-to-turn-off-during-the-execution
     */
    this.getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

    /*
     * One or more of these three lines sets the screen to minimum brightness, Which should extend battery drain, and be less distracting on the robot.
     */
    final WindowManager.LayoutParams winParams = this.getWindow().getAttributes();
    winParams.screenBrightness = 0.01f;
    winParams.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;

    // The "Connect" screen has a "Name" and "Address box"
    // I'm not really sure what one puts in these, and if you leave them
    // empty it works fine.
    // So not 110% sure what to do with these. Can the text just be: ""?
    // Just comment these out, and run the command with nulls?
    // mName = (EditText) findViewById(R.id.name_edit);
    // mAddress = (EditText) findViewById(R.id.address_edit);
    // The NXT Remote Control app pops up a list of seen NXTs, so maybe I
    // need to implement that instead.

    // Text to speech
    tts = new TextToSpeech(this, this);

    btnSpeak = (Button) findViewById(R.id.btnSpeak);

    txtText = (EditText) findViewById(R.id.txtSpeakText);

    // Now we need a Robot object before we an use any Roboty values!
    // We can pass defaults in or use the ones it provides
    myRobot = new Robot(INITIALTRAVELSPEED, INITIALROTATESPEED, DEFAULTVIEWANGLE);
    // We may have to pass this robot around a bit. ;)

    // Status Lines
    TextView distanceText = (TextView) findViewById(R.id.distanceText);
    distanceText.setText("???");
    TextView distanceLeftText = (TextView) findViewById(R.id.distanceLeftText);
    distanceLeftText.setText("???");
    TextView distanceRightText = (TextView) findViewById(R.id.distanceRightText);
    distanceRightText.setText("???");
    TextView headingText = (TextView) findViewById(R.id.headingText);
    headingText.setText("???");
    TextView actionText = (TextView) findViewById(R.id.isDoingText);
    actionText.setText("None");

    // Travel speed slider bar
    SeekBar travelSpeedBar = (SeekBar) findViewById(R.id.travelSpeed_seekBar);
    travelSpeedBar.setProgress(myRobot.getTravelSpeed());
    travelSpeedBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setTravelSpeed(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    // View angle slider bar
    SeekBar viewAngleBar = (SeekBar) findViewById(R.id.viewAngle_seekBar);
    viewAngleBar.setProgress(myRobot.getViewAngle());
    viewAngleBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setViewAngle(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            Log.d(TAG, "View Angle Slider ");
            /*
             * If this gets sent every few milliseconds with the normal output, then there is no need to send a specific command every time it changes!
             */
            // sendCommandToRobot(Command.VIEWANGLE);
        }
    });

    // Rotation speed slider bar speedSP_seekBar
    SeekBar rotateSpeedBar = (SeekBar) findViewById(R.id.rotateSpeed_seekBar);
    rotateSpeedBar.setProgress(myRobot.getRotateSpeed());
    rotateSpeedBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
            myRobot.setRotateSpeed(progress);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });

    /*
     * This is where we find the four direction buttons defined So we could define ALL buttons this way, set up an ENUM with all options, and call the same function for ALL
     * options!
     * 
     * Just be sure the "release" only stops the robot on these, and not every button on the screen.
     * 
     * Maybe see how the code I stole this form does it?
     */
    Button buttonUp = (Button) findViewById(R.id.forward_button);
    buttonUp.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.FORWARD));
    Button buttonDown = (Button) findViewById(R.id.reverse_button);
    buttonDown.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.REVERSE));
    Button buttonLeft = (Button) findViewById(R.id.left_button);
    buttonLeft.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.LEFT));
    Button buttonRight = (Button) findViewById(R.id.right_button);
    buttonRight.setOnTouchListener(new DirectionButtonOnTouchListener(Direction.RIGHT));

    // button on click event
    btnSpeak.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View arg0) {
            speakOut();
        }

    });

    /*
     * This causes the typed text to be spoken when the Enter key is pressed.
     */
    txtText.setOnKeyListener(new View.OnKeyListener() {
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            // If the event is a key-down event on the "enter" button
            if ((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER)) {
                // Perform action on key press
                // Toast.makeText(HelloFormStuff.this, edittext.getText(), Toast.LENGTH_SHORT).show();
                speakOut();
                return true;
            }
            return false;
        }
    });

    // Connect button
    connectToggleButton = (ToggleButton) findViewById(R.id.connectToggleButton);
    connectToggleButton.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
        public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
            if (isChecked) {
                // The toggle is enabled
                Log.d(TAG, "Connect button Toggled On!");
                myRobot.setConnectRequested(true);
            } else {
                // The toggle is disabled
                Log.d(TAG, "Connect button Toggled OFF.");
                myRobot.setConnectRequested(false);
            }
        }
    });

    if (nxtStatusMessageHandler == null)
        nxtStatusMessageHandler = new StatusMessageHandler();

    mStatusThread = new StatusThread(context, nxtStatusMessageHandler);
    mStatusThread.start();

    // Start the web service!
    Log.d(TAG, "Start web service here:");
    // Initiate message handler for web service
    if (robotWebServerMessageHandler == null)
        robotWebServerMessageHandler = new WebServerMessageHandler(this); // Has to include "this" to send context, see WebServerMessageHandler for explanation

    robotWebServer = new WebServer(context, PORT, robotWebServerMessageHandler, myRobot);

    try {
        robotWebServer.start();
    } catch (IOException e) {
        Log.d(TAG, "robotWebServer failed to start");
        //e.printStackTrace();
    }

    // TODO:
    /*
     * See this reference on how to rebuild this handler in onCreate if it is gone: http://stackoverflow.com/questions/18221593/android-handler-changing-weakreference
     */
    // TODO - Should I stop this thread in Destroy or some such place?

    Log.d(TAG, "Web service was started.");

}

From source file:com.example.app_2.activities.ImageGridActivity.java

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TTS_REQUEST_CODE) {
        if (resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS) {
            tts = new TextToSpeech(this, this); // success, crate the TTS instance
        } else {// ww  w  .  j  a  v  a  2s.c  o m
            // missing data, install it
            Intent installIntent = new Intent();
            installIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
            startActivity(installIntent);
        }
    }
}

From source file:org.de.jmg.learn.MainActivity.java

private void StartTextToSpeech() {
    tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
        @Override//ww  w .  j  a  v  a 2s .c  om
        public void onInit(int status) {
            if (status == TextToSpeech.SUCCESS) {
                int res = tts.setLanguage(Locale.US);
                if (res < 0) {
                    blnTextToSpeech = false;
                } else {
                    tts.setSpeechRate(.75f);
                }
            } else {
                blnTextToSpeech = false;
            }
        }
    });
}