Back to project page keepmoving.
The source code is released under:
GNU General Public License
If you think the Android project keepmoving listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package it.rainbowbreeze.keepmoving.ui; //w w w.j a v a 2 s . c om import android.app.Activity; import android.content.Intent; import android.os.Bundle; import android.speech.RecognizerIntent; import android.support.wearable.view.WatchViewStub; import android.view.View; import android.widget.Button; import android.widget.TextView; import android.widget.Toast; import java.util.List; import it.rainbowbreeze.keepmoving.R; public class TimetableActivity extends Activity { private static final int SPEECH_REQUEST_CODE = 102; private TextView mTextView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.act_timetable); final WatchViewStub stub = (WatchViewStub) findViewById(R.id.watch_view_stub); stub.setOnLayoutInflatedListener(new WatchViewStub.OnLayoutInflatedListener() { @Override public void onLayoutInflated(WatchViewStub stub) { mTextView = (TextView) stub.findViewById(R.id.text); Button btn = (Button) stub.findViewById(R.id.timetable_btnInput); btn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM); // Start the activity, the intent will be populated with the speech text startActivityForResult(intent, SPEECH_REQUEST_CODE); } }); } }); } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case SPEECH_REQUEST_CODE: if (RESULT_OK == resultCode) { List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); mTextView.setText(spokenText); } else { Toast.makeText(this, "No voice input received", Toast.LENGTH_SHORT).show(); } break; default: super.onActivityResult(requestCode, resultCode, data); break; } } }