List of usage examples for android.speech.tts TextToSpeech TextToSpeech
public TextToSpeech(Context context, OnInitListener listener)
From source file:com.example.sherrychuang.splitsmart.Activity.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from w w w. ja va2 s.c o m*/ @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); itemInputs = new ArrayList<>(); e = (Event) getIntent().getSerializableExtra("event"); itemInputsTest = new ArrayList<>(); String s = "Apple"; List<Tag> tmp = new ArrayList<Tag>(); itemInputsTest.add(new ItemInput(false, s, "", tmp)); // Set good defaults for capturing text. itemInputsTest.get(0).setPrice("2"); ItemAr = new String[itemInputs.size()]; PriceAr = new String[itemInputs.size()]; for (int j = 0; j < itemInputs.size(); j++) { ItemAr[j] = itemInputs.get(j).getItemName(); PriceAr[j] = itemInputs.get(j).getPrice(); } boolean autoFocus = true; boolean useFlash = false; // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); // TODO: Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { if (status == TextToSpeech.SUCCESS) { Log.d("TTS", "Text to speech engine started successfully."); tts.setLanguage(Locale.US); } else { Log.d("TTS", "Error starting the text to speech engine."); } } }; tts = new TextToSpeech(this.getApplicationContext(), listener); //button for saving item and price Button btn = (Button) findViewById(R.id.done); btn.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Log.d("OcrCaptureActivity", "done"); Intent myIntent = new Intent(OcrCaptureActivity.this, BillPage.class); myIntent.putExtra("Event", e); myIntent.putExtra("ItemInput", ItemAr); myIntent.putExtra("PriceInput", PriceAr); onPause(); OcrCaptureActivity.this.startActivity(myIntent); /*if(itemInputs!=null) { Intent myIntent = new Intent(view.getContext(), BillContentPage.class); myIntent.putExtra("ItemInput", itemInputsTest); OcrCaptureActivity.this.startActivity(myIntent); }*/ } }); }
From source file:it.iziozi.iziozi.gui.IOBoardActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_board); this.mDecorView = getWindow().getDecorView(); this.mActiveConfig = IOConfiguration.getSavedConfiguration(); if (this.mActiveConfig == null) { this.mActiveConfig = new IOConfiguration(); showHintAlert();//from w w w . ja v a 2 s . co m } else { lockUI(); } mActualLevel = mActiveConfig.getLevel(); mFrameLayout = (FrameLayout) findViewById(R.id.mainLayoutTableContainer); FragmentManager fm = getSupportFragmentManager(); fm.beginTransaction().add(mFrameLayout.getId(), IOPaginatedBoardFragment.newInstance(mActualLevel)) .commit(); setupNavButtons(); /* * Neurosky Mindwave support * */ btAdapter = BluetoothAdapter.getDefaultAdapter(); if (btAdapter != null) { tgDevice = new TGDevice(btAdapter, handler); } this.tts = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { @Override public void onInit(int i) { if (tts.isLanguageAvailable(Locale.getDefault()) >= 0) tts.setLanguage(Locale.getDefault()); else tts.setLanguage(Locale.ENGLISH); tts.speak(getResources().getString(R.string.tts_ready), TextToSpeech.QUEUE_FLUSH, null); mCanSpeak = true; } }); this.mDecorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() { @Override public void onSystemUiVisibilityChange(int visibility) { // Note that system bars will only be "visible" if none of the // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set. if (visibility == View.VISIBLE && IOBoardActivity.this.mUnlockAlert == null) { // TODO: The system bars are visible. if (mUILocked && !IOGlobalConfiguration.isEditing && canGoImmersive()) showUnlockAlert(); } else { // TODO: The system bars are NOT visible. } } }); }
From source file:divya.myvision.TessActivity.java
public void setLang(String lang) { Locale locale;/*from w w w.ja v a2 s . co m*/ if (lang.equals("Spanish")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { Locale locSpanish = new Locale("spa", "MEX"); tts.setLanguage(locSpanish); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("spa", "MEX"); } else if (lang.equals("French")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.FRENCH); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("fr"); } else if (lang.equals("Japanese")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.JAPANESE); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("ja"); } else if (lang.equals("Chinese")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.CHINESE); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("zh"); } else if (lang.equals("German")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.GERMAN); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("de"); } else if (lang.equals("Italian")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.ITALIAN); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("it"); } else if (lang.equals("Korean")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.KOREAN); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("ko"); } else if (lang.equals("Hindi")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { Locale locHindhi = new Locale("hi"); tts.setLanguage(locHindhi); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("hi"); } else if (lang.equals("Russian")) { // Set up the Text To Speech engine. TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { Locale locHindhi = new Locale("ru"); tts.setLanguage(locHindhi); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("ru"); } else { TextToSpeech.OnInitListener listener = new TextToSpeech.OnInitListener() { @Override public void onInit(final int status) { tts.setLanguage(Locale.US); } }; tts = new TextToSpeech(this.getApplicationContext(), listener); locale = new Locale("en"); } Locale.setDefault(locale); Configuration config = new Configuration(); config.setLocale(locale); this.getApplicationContext().getResources().updateConfiguration(config, null); }
From source file:com.phonegap.plugins.speech.TTS.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackContext = callbackContext; try {//from ww w. j a v a2 s . c o m if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.speak(text, TextToSpeech.QUEUE_ADD, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("interrupt")) { String text = args.getString(0); if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); //map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("stop")) { if (isReady()) { mTts.stop(); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("silence")) { if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("speed")) { if (isReady()) { float speed = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setSpeechRate(speed); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("pitch")) { if (isReady()) { float pitch = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setPitch(pitch); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("startup")) { this.startupCallbackContext = callbackContext; if (mTts == null) { state = TTS.INITIALIZING; mTts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this); } PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); startupCallbackContext.sendPluginResult(pluginResult); } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); } callbackContext.sendPluginResult(new PluginResult(status, result)); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } return true; } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return false; }
From source file:com.firerunner.cordova.TTS.java
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; this.callbackContext = callbackContext; try {// w w w . java 2 s. c o m if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.speak(text, TextToSpeech.QUEUE_ADD, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("interrupt")) { String text = args.getString(0); if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); //map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackId); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("stop")) { if (isReady()) { mTts.stop(); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("silence")) { if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("speed")) { if (isReady()) { float speed = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setSpeechRate(speed); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("pitch")) { if (isReady()) { float pitch = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setPitch(pitch); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("startup")) { this.startupCallbackContext = callbackContext; if (mTts == null) { state = TTS.INITIALIZING; mTts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this); PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); // do not send this as onInit is more reliable: domaemon // startupCallbackContext.sendPluginResult(pluginResult); } else { PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); startupCallbackContext.sendPluginResult(pluginResult); } } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); mTts = null; } callbackContext.sendPluginResult(new PluginResult(status, result)); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } return true; } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return false; }
From source file:org.apache.cordova.plugins.speech.TTS.java
/** * Executes the request and returns PluginResult. * * @param action//from www.j a va 2s. c om * The action to execute. * @param args * JSONArry of arguments for the plugin. * @param callbackContext * The callback context used when calling back into JavaScript. * @return True if the action was valid, false otherwise. */ @Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { // Dispatcher PluginResult.Status status = PluginResult.Status.OK; String result = ""; try { if (action.equals("speak")) { String text = args.getString(0); if (isReady()) { Log.d(LOG_TAG, "Speak " + text + "."); HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.speak(text, TextToSpeech.QUEUE_ADD, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { Log.d(LOG_TAG, "TTS service is still initialzing."); JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("interrupt")) { String text = args.getString(0); if (isReady()) { HashMap<String, String> map = null; map = new HashMap<String, String>(); map.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, callbackContext.getCallbackId()); mTts.speak(text, TextToSpeech.QUEUE_FLUSH, map); PluginResult pr = new PluginResult(PluginResult.Status.NO_RESULT); pr.setKeepCallback(true); callbackContext.sendPluginResult(pr); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("stop")) { if (isReady()) { mTts.stop(); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("silence")) { if (isReady()) { mTts.playSilence(args.getLong(0), TextToSpeech.QUEUE_ADD, null); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("speed")) { if (isReady()) { float speed = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setSpeechRate(speed); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("pitch")) { if (isReady()) { float pitch = (float) (args.optLong(0, 100)) / (float) 100.0; mTts.setPitch(pitch); callbackContext.sendPluginResult(new PluginResult(status, result)); } else { JSONObject error = new JSONObject(); error.put("message", "TTS service is still initialzing."); error.put("code", TTS.INITIALIZING); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); } } else if (action.equals("startup")) { if (mTts == null) { this.callbackContext = callbackContext; state = TTS.INITIALIZING; mTts = new TextToSpeech(cordova.getActivity().getApplicationContext(), this); } PluginResult pluginResult = new PluginResult(status, TTS.INITIALIZING); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (action.equals("shutdown")) { if (mTts != null) { mTts.shutdown(); } callbackContext.sendPluginResult(new PluginResult(status, result)); } else if (action.equals("getLanguage")) { if (mTts != null) { result = mTts.getLanguage().toString(); callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("isLanguageAvailable")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.isLanguageAvailable(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } else if (action.equals("setLanguage")) { if (mTts != null) { Locale loc = new Locale(args.getString(0)); int available = mTts.setLanguage(loc); result = (available < 0) ? "false" : "true"; callbackContext.sendPluginResult(new PluginResult(status, result)); } } else { String res = "Unknown action: " + action; callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION, res)); return false; } } catch (JSONException e) { e.printStackTrace(); callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION)); } return true; }
From source file:com.microsoft.mimickeralarm.mimics.MimicWithForecastFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_forecast_weather_mimic, container, false); ProgressButton progressButton = (ProgressButton) view.findViewById(R.id.capture_button); progressButton.setReadyState(ProgressButton.State.ReadyAudio); mStateManager = new MimicStateManager(); mStateManager.registerCountDownTimer((CountDownTimerView) view.findViewById(R.id.countdown_timer), TIMEOUT_MILLISECONDS); mStateManager.registerStateBanner((MimicStateBanner) view.findViewById(R.id.mimic_state)); mStateManager.registerProgressButton(progressButton, MimicButtonBehavior.AUDIO); mStateManager.registerMimic(this); mTextResponse = (TextView) view.findViewById(R.id.understood_text); mTextResponse.setOnClickListener(this); myTTS = new TextToSpeech(getActivity().getApplicationContext(), new TextToSpeech.OnInitListener() { @Override/* w w w . j av a 2 s .c om*/ public void onInit(int status) { if (status != TextToSpeech.ERROR) { myTTS.setLanguage(Locale.KOREAN); } } }); // Button finishButton = (Button) view.findViewById(R.id.fin_button); // Bundle args = getArguments(); // mShareableUri = args.getString("shareable-uri"); // // // Set up timer to dismiss the sharing fragment if there is no user interaction with the buttons // mSharingFragmentDismissTask = new Runnable() { // @Override // public void run() { // finishShare(); // } // }; // mHandler = new Handler(); return view; }
From source file:com.surveyorexpert.TalkToMe.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.talk_main);/*from www.j a v a 2s. co m*/ SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); String online = preferences.getString("ONLINE", ""); if (!online.equalsIgnoreCase("")) { ONLINE = online; } String PhotoPath = preferences.getString("PhotoPath", ""); if (!PhotoPath.equalsIgnoreCase("")) { mPhotoPath = PhotoPath; } String ServerPhotoPath = preferences.getString("ServerPhotoPath", ""); if (!ServerPhotoPath.equalsIgnoreCase("")) { mServerPhotoPath = ServerPhotoPath; } setTitle("mServerPhotoPath " + mServerPhotoPath); Bundle extras = getIntent().getExtras(); if (extras != null) { domain = extras.getString("domain"); project = extras.getString("project"); resource = extras.getString("resource"); nbcMarker = extras.getString("nbcMarker"); nbcDescription = extras.getString("nbcDescription"); userName = extras.getString("userName"); user_id = extras.getString("user_id"); severity = extras.getString("severity"); costEst = extras.getString("costEst"); version = extras.getString("version"); strLongitude = extras.getString("strLongitude"); strLatitude = extras.getString("strLatitude"); section = extras.getString("section"); element = extras.getString("element"); childPos = ""; //extras.getString("childPos"); parentPos = ""; //extras.getString("parentPos"); } // File imgFile = new File("/sdcard/Images/test_image.jpg"); // File imgFile = new File("/storage/emulated/0/1405349215602.jpg"); String path = Environment.getExternalStorageDirectory() + "/DCIM/Camera/1405349215602.jpg"; /* Toast.makeText(TalkToMe.this, "mServerPhotoPath = " + mServerPhotoPath , Toast.LENGTH_LONG).show(); */ /* Toast.makeText(getBaseContext(), "mPhotoPath = " + mPhotoPath, "mServerPhotoPath = " + mServerPhotoPath, Toast.LENGTH_LONG).show(); */ File imgFile = new File(mPhotoPath); if (imgFile.exists()) { Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath()); ImageView myImage = (ImageView) findViewById(R.id.finalImg); myImage.setImageBitmap(myBitmap); // Toast.makeText(getBaseContext(),"Set File " , Toast.LENGTH_LONG).show(); } else { Toast.makeText(getBaseContext(), "Not found " + imgFile.getName(), Toast.LENGTH_LONG).show(); } speak = (Button) findViewById(R.id.bt_speak); speak.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { sendRecognizeIntent(); } }); speak.setEnabled(false); confirm = (Button) findViewById(R.id.btWriteToServer); confirm.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { new PostComment().execute(); Toast.makeText(getBaseContext(), "TalkToMe Send to Server : " + "\nmPhotoPath : " + mPhotoPath + "\nsection : " + section + "\nelement : " + element + "\ngotMessage : " + gotMessage + "\ndomain : " + domain + "\nproject : " + project + "\nresource : " + resource + "\nnbcMarker : " + nbcMarker + "\nnbcDescription : " + nbcDescription + "\nuserName : " + userName + "\nuser_id : " + user_id + "\nseverity : " + severity + "\ncostEst : " + costEst + "\nversion : " + version + "\nstrLongitude : " + strLongitude + "\nstrLatitude : " + strLatitude, Toast.LENGTH_LONG).show(); } }); // confirm.setEnabled(false); result = (TextView) findViewById(R.id.tv_result); // message = (TextView)findViewById(R.id.tvTalkMessage); // message.setText(mServerPhotoPath); tts = new TextToSpeech(this, this); }
From source file:com.marvin.rocklock.RockLockActivity.java
/** Called when the activity is first created. */ @Override// w ww. java 2 s . com public void onCreate(Bundle savedInstanceState) { mSelf = this; sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory()))); mPlayer = new RockLockMusicPlayer(this); super.onCreate(savedInstanceState); requestWindowFeature(android.view.Window.FEATURE_NO_TITLE); getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED); setContentView(R.layout.main); mIconDisplay = (ImageView) findViewById(R.id.gestureIcon); mCurrentTrack = (TextView) findViewById(R.id.current_track); mCurrentInfo = (TextView) findViewById(R.id.current_info); mUpcomingText = (TextView) findViewById(R.id.upcoming); mModeText = (TextView) findViewById(R.id.mode_text); mGestureOverlay = (MusicGestureOverlay) findViewById(R.id.gestureLayer); mGestureOverlay.setGestureListener(new PlayerGestureListener(), true); updateDisplayText(null, null, false); mTts = new TextToSpeech(this, new TextToSpeech.OnInitListener() { @Override public void onInit(int status) { mTts.setOnUtteranceCompletedListener(new OnUtteranceCompletedListener() { @Override public void onUtteranceCompleted(String utteranceId) { if (mCurrentUtteranceId != null && mCurrentUtteranceId.equals(utteranceId)) { mPlayer.restoreMusic(); } } }); } }); mTts.addEarcon(TOCK_EARCON, RockLockActivity.class.getPackage().getName(), R.raw.tock_snd); mTts.addEarcon(TICK_EARCON, RockLockActivity.class.getPackage().getName(), R.raw.tick_snd); mVibe = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE); mWasStartedByService = getIntent().getBooleanExtra(EXTRA_STARTED_BY_SERVICE, false); mPhoneListener = new RockLockPhoneListener(); final TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE); tm.listen(mPhoneListener, PhoneStateListener.LISTEN_CALL_STATE); mPausedForCall = false; // Start the service in case it is not already running startService(new Intent(this, ScreenOnHandlerService.class)); // Get notification manager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); loadBookmarks(); // Browsing preference mPrefs = PreferenceManager.getDefaultSharedPreferences(this); mBrowsingPref = mPrefs.getBoolean(getString(R.string.browse_mode), true); }
From source file:com.codebutler.farebot.activities.CardInfoActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_card_info); final ViewPager viewPager = (ViewPager) findViewById(R.id.pager); mTabsAdapter = new TabPagerAdapter(this, viewPager); final ActionBar actionBar = getSupportActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setTitle(R.string.loading); new AsyncTask<Void, Void, Void>() { private Exception mException; public boolean mSpeakBalanceEnabled; @Override/*from w w w.j a v a 2s . co m*/ protected Void doInBackground(Void... voids) { try { Uri uri = getIntent().getData(); Cursor cursor = getContentResolver().query(uri, null, null, null, null); startManagingCursor(cursor); cursor.moveToFirst(); String data = cursor.getString(cursor.getColumnIndex(CardsTableColumns.DATA)); mCard = Card.fromXml(data); mTransitData = mCard.parseTransitData(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(CardInfoActivity.this); mSpeakBalanceEnabled = prefs.getBoolean("pref_key_speak_balance", false); } catch (Exception ex) { mException = ex; } return null; } @Override protected void onPostExecute(Void aVoid) { findViewById(R.id.loading).setVisibility(View.GONE); findViewById(R.id.pager).setVisibility(View.VISIBLE); if (mException != null) { if (mCard == null) { Utils.showErrorAndFinish(CardInfoActivity.this, mException); } else { Log.e("CardInfoActivity", "Error parsing transit data", mException); showAdvancedInfo(mException); finish(); } return; } if (mTransitData == null) { showAdvancedInfo(new UnsupportedCardException()); finish(); return; } String titleSerial = (mTransitData.getSerialNumber() != null) ? mTransitData.getSerialNumber() : Utils.getHexString(mCard.getTagId(), ""); actionBar.setTitle(mTransitData.getCardName() + " " + titleSerial); Bundle args = new Bundle(); args.putParcelable(AdvancedCardInfoActivity.EXTRA_CARD, mCard); args.putParcelable(EXTRA_TRANSIT_DATA, mTransitData); mTabsAdapter.addTab(actionBar.newTab().setText(R.string.balance), CardBalanceFragment.class, args); if (mTransitData.getTrips() != null) { int textId = (mTransitData instanceof SuicaTransitData) ? R.string.history : R.string.trips; mTabsAdapter.addTab(actionBar.newTab().setText(textId), CardTripsFragment.class, args); } if (mTransitData.getRefills() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.refills), CardRefillsFragment.class, args); } if (mTransitData.getSubscriptions() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.subscriptions), CardSubscriptionsFragment.class, args); } if (mTransitData.getInfo() != null) { mTabsAdapter.addTab(actionBar.newTab().setText(R.string.info), CardInfoFragment.class, args); } if (mTabsAdapter.getCount() > 1) { actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); } boolean speakBalanceRequested = getIntent().getBooleanExtra(SPEAK_BALANCE_EXTRA, false); if (mSpeakBalanceEnabled && speakBalanceRequested) { mTTS = new TextToSpeech(CardInfoActivity.this, mTTSInitListener); } if (savedInstanceState != null) { viewPager.setCurrentItem(savedInstanceState.getInt(KEY_SELECTED_TAB, 0)); } } }.execute(); }