Back to project page GlassCounter.
The source code is released under:
Apache License
If you think the Android project GlassCounter 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 com.github.barcodeeye.scan; // ww w . j av a 2 s . c o m import java.util.List; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.media.AudioManager; import android.os.Bundle; import android.speech.RecognizerIntent; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.WindowManager; import com.github.barcodeeye.R; import com.google.android.glass.app.Card; import com.google.android.glass.media.Sounds; public class FinalActivity extends Activity { private static final int SPEECH_REQUEST = 0; private String data; private String text; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); Bundle b = getIntent().getExtras(); data = b.getString("data"); Log.i("App","data" +data); View myView = createCards2(); setContentView(myView); } /** * Handle the tap from the touchpad. */ @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { // Handle tap events. case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: AudioManager audio = (AudioManager)getSystemService(Context.AUDIO_SERVICE); audio.playSoundEffect(Sounds.TAP); displaySpeechRecognizer(); return true; default: return super.onKeyDown(keyCode, event); } } private void displaySpeechRecognizer() { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); if(data.equalsIgnoreCase("0671860013624")){ text= "How many valves"; intent.putExtra("android.speech.extra.PROMPT", text); startActivityForResult(intent, SPEECH_REQUEST); }else if(data.equalsIgnoreCase("0821935111124")){ text="How many cylinders"; intent.putExtra("android.speech.extra.PROMPT", text); startActivityForResult(intent, SPEECH_REQUEST); }else if(data.equalsIgnoreCase("5391519890707")){ text="How many containers "; intent.putExtra("android.speech.extra.PROMPT", text); startActivityForResult(intent, SPEECH_REQUEST); }else{ text="How many pipes"; intent.putExtra("android.speech.extra.PROMPT", text); startActivityForResult(intent, SPEECH_REQUEST); } } @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == SPEECH_REQUEST && resultCode == RESULT_OK) { List<String> results = data.getStringArrayListExtra( RecognizerIntent.EXTRA_RESULTS); String spokenText = results.get(0); Log.i("App","Text spoken" +spokenText); if(spokenText!=null){ Intent i = new Intent(this, FourthActivity.class); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); startActivity(i); finish(); } } super.onActivityResult(requestCode, resultCode, data); } public View createCards(String text){ Card card; card = new Card(this); card.setText(text); card.setFootnote("Tap to speak"); card.setImageLayout(Card.ImageLayout.LEFT); card.addImage(R.drawable.sample); View cardView = card.getView(); return cardView; } public View createCards2(){ Card card; card = new Card(this); card.setText("Inventory count"); card.setFootnote("Tap to speak"); card.setImageLayout(Card.ImageLayout.LEFT); card.addImage(R.drawable.inventory); View cardView = card.getView(); return cardView; } @Override public void onResume() { super.onResume(); } @Override public void onPause() { super.onPause(); } @Override public void onDestroy() { super.onDestroy(); } }