Back to project page Wordilizer.
The source code is released under:
Apache License
If you think the Android project Wordilizer listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
/* * Copyright (C) 2010 The Android Open Source Project *//from w ww . j av a2 s . c o m * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.wordilizer; import java.util.Locale; import android.app.Activity; import android.speech.tts.*; import android.database.Cursor; import android.net.Uri; import android.os.Bundle; import android.util.Log; import android.view.Menu; import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.widget.Button; import android.widget.TextView; /** * Displays a word and its definition. */ public class WordActivity extends Activity implements TextToSpeech.OnInitListener{ private TextToSpeech tts; private Button spk; private TextView word; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.wordsearch); tts = new TextToSpeech(this, this); spk=(Button) findViewById(R.id.button1); Uri uri = getIntent().getData(); @SuppressWarnings("deprecation") Cursor cursor = managedQuery(uri, null, null, null, null); if (cursor == null) { finish(); } else { cursor.moveToFirst(); word = (TextView) findViewById(R.id.word); TextView definition = (TextView) findViewById(R.id.definition); int wIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_WORD); int dIndex = cursor.getColumnIndexOrThrow(DictionaryDatabase.KEY_DEFINITION); word.setText(cursor.getString(wIndex)); definition.setText(cursor.getString(dIndex)); } spk.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View arg0) { speakOut(); } }); } private void speakOut() { String text = word.getText().toString(); tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); } public void onDestroy() { // Don't forget to shutdown tts! if (tts != null) { tts.stop(); tts.shutdown(); } super.onDestroy(); } @Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.options_menu, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.search: onSearchRequested(); return true; default: return false; } } @Override public void onInit(int status) { // TODO Auto-generated method stub if (status == TextToSpeech.SUCCESS) { int result = tts.setLanguage(Locale.US); tts.setPitch((float) 1.5); tts.setSpeechRate((float) 1); if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) { Log.e("TTS", "This Language is not supported"); } else { spk.setEnabled(true); } } else { Log.e("TTS", "Initilization Failed!"); } } }