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