]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/glass/src/main/java/cz/cvut/fel/dce/qrscanner/MainActivity.java
Initial commit
[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.os.Bundle;
13 import android.util.Log;
14 import android.view.View;
15 import android.view.ViewGroup;
16 import android.widget.AdapterView;
17
18 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
19 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
20
21 /**
22  * An {@link Activity} showing a tuggable "Hello World!" card.
23  * <p/>
24  * The main content view is composed of a one-card {@link CardScrollView} that provides tugging
25  * feedback to the user when swipe gestures are detected.
26  * If your Glassware intends to intercept swipe gestures, you should set the content view directly
27  * and use a {@link com.google.android.glass.touchpad.GestureDetector}.
28  *
29  * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
30  */
31 public class MainActivity extends Activity {
32         public final static String TAG = "MainActivity";
33
34         /**
35          * {@link CardScrollView} to use as the main content view.
36          */
37         private CardScrollView mCardScroller;
38
39         /**
40          * "Hello World!" {@link View} generated by {@link #buildView()}.
41          */
42         private View mView;
43
44         @Override
45         protected void onCreate(Bundle bundle) {
46                 super.onCreate(bundle);
47
48                 mView = buildView();
49
50                 mCardScroller = new CardScrollView(this);
51                 mCardScroller.setAdapter(new CardScrollAdapter() {
52                         @Override
53                         public int getCount() {
54                                 return 1;
55                         }
56
57                         @Override
58                         public Object getItem(int position) {
59                                 return mView;
60                         }
61
62                         @Override
63                         public View getView(int position, View convertView, ViewGroup parent) {
64                                 return mView;
65                         }
66
67                         @Override
68                         public int getPosition(Object item) {
69                                 if (mView.equals(item)) {
70                                         return 0;
71                                 }
72                                 return AdapterView.INVALID_POSITION;
73                         }
74                 });
75                 // Handle the TAP event.
76                 mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
77                         @Override
78                         public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
79                                 startScan();
80                         }
81                 });
82                 setContentView(mCardScroller);
83         }
84
85         public void onActivityResult(int requestCode, int resultCode, Intent intent) {
86                 IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
87                 if (scanResult != null) {
88                         Log.i(TAG, scanResult.toString());
89                 }
90                 // else continue with any other code you need in the method
91
92         }
93
94         @Override
95         protected void onResume() {
96                 super.onResume();
97                 mCardScroller.activate();
98         }
99
100         @Override
101         protected void onPause() {
102                 mCardScroller.deactivate();
103                 super.onPause();
104         }
105
106         private void startScan() {
107                 IntentIntegrator integrator = new IntentIntegrator(this);
108                 integrator.initiateScan();
109         }
110
111         /**
112          * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
113          */
114         private View buildView() {
115                 CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
116
117                 card.setText(R.string.hello_world);
118                 return card.getView();
119         }
120
121 }