1 package cz.cvut.fel.dce.qrscanner;
3 import com.google.android.glass.media.Sounds;
4 import com.google.android.glass.widget.CardBuilder;
5 import com.google.android.glass.widget.CardScrollAdapter;
6 import com.google.android.glass.widget.CardScrollView;
8 import android.app.Activity;
9 import android.content.Context;
10 import android.content.Intent;
11 import android.media.AudioManager;
12 import android.media.SoundPool;
13 import android.os.Bundle;
14 import android.util.Log;
15 import android.view.KeyEvent;
16 import android.view.MotionEvent;
17 import android.view.SoundEffectConstants;
18 import android.view.View;
19 import android.view.ViewGroup;
20 import android.widget.AdapterView;
22 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
23 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
26 * An {@link Activity} showing a tuggable "Hello World!" card.
28 * The main content view is composed of a one-card {@link CardScrollView} that provides tugging
29 * feedback to the user when swipe gestures are detected.
30 * If your Glassware intends to intercept swipe gestures, you should set the content view directly
31 * and use a {@link com.google.android.glass.touchpad.GestureDetector}.
33 * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
35 public class MainActivity extends Activity {
36 public final static String TAG = "MainActivity";
39 * {@link CardScrollView} to use as the main content view.
41 private CardScrollView mCardScroller;
44 * "Hello World!" {@link View} generated by {@link #buildView()}.
49 protected void onCreate(Bundle bundle) {
50 super.onCreate(bundle);
51 setContentView(R.layout.activity_main);
55 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
56 IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
57 if (scanResult != null) {
58 AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
59 audio.playSoundEffect(Sounds.SUCCESS);
60 Log.i(TAG, scanResult.toString());
61 Intent preview = new Intent(this, PreviewActivity.class);
62 preview.putExtra("COMPONENT_ID", scanResult.getContents());
63 startActivity(preview);
66 // else continue with any other code you need in the method
71 protected void onResume() {
76 protected void onPause() {
81 public boolean onKeyDown(int keyCode, KeyEvent event) {
82 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
84 AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
85 audio.playSoundEffect(Sounds.TAP);
88 return super.onKeyDown(keyCode, event);
91 private void startScan() {
92 IntentIntegrator integrator = new IntentIntegrator(this);
93 integrator.initiateScan();
97 * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
99 private View buildView() {
100 CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
102 card.setText(R.string.hello_world);
103 return card.getView();