]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/MainActivity.java
1f9ca08d14e3bcb4c18403100638c912a5ba1d5e
[hornmich/skoda-qr-demo.git] / QRScanner / glass / src / main / java / cz / cvut / fel / dce / qrscanner / MainActivity.java
1 package cz.cvut.fel.dce.qrscanner;
2
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;
7
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;
21
22 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
23 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
24
25 /**
26  * An {@link Activity} showing a tuggable "Hello World!" card.
27  * <p/>
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}.
32  *
33  * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
34  */
35 public class MainActivity extends Activity {
36         public final static String TAG = "MainActivity";
37
38         /**
39          * {@link CardScrollView} to use as the main content view.
40          */
41         private CardScrollView mCardScroller;
42
43         /**
44          * "Hello World!" {@link View} generated by {@link #buildView()}.
45          */
46         private View mView;
47
48         @Override
49         protected void onCreate(Bundle bundle) {
50                 super.onCreate(bundle);
51                 setContentView(R.layout.activity_main);
52
53         }
54
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);
64
65                 }
66                 // else continue with any other code you need in the method
67
68         }
69
70         @Override
71         protected void onResume() {
72                 super.onResume();
73         }
74
75         @Override
76         protected void onPause() {
77                 super.onPause();
78         }
79
80         @Override
81         public boolean onKeyDown(int keyCode, KeyEvent event) {
82                 if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER) {
83                         startScan();
84                         AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
85                         audio.playSoundEffect(Sounds.TAP);
86                         return true;
87                 }
88                 return super.onKeyDown(keyCode, event);
89         }
90
91         private void startScan() {
92                 IntentIntegrator integrator = new IntentIntegrator(this);
93                 integrator.initiateScan();
94         }
95
96         /**
97          * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
98          */
99         private View buildView() {
100                 CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
101
102                 card.setText(R.string.hello_world);
103                 return card.getView();
104         }
105
106 }