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.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;
20 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
21 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
24 * An {@link Activity} showing a tuggable "Hello World!" card.
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}.
31 * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
33 public class MainActivity extends Activity {
34 public final static String TAG = "MainActivity";
37 * {@link CardScrollView} to use as the main content view.
39 private CardScrollView mCardScroller;
42 * "Hello World!" {@link View} generated by {@link #buildView()}.
47 protected void onCreate(Bundle bundle) {
48 super.onCreate(bundle);
52 mCardScroller = new CardScrollView(this);
53 mCardScroller.setAdapter(new CardScrollAdapter() {
55 public int getCount() {
60 public Object getItem(int position) {
65 public View getView(int position, View convertView, ViewGroup parent) {
70 public int getPosition(Object item) {
71 if (mView.equals(item)) {
74 return AdapterView.INVALID_POSITION;
77 // Handle the TAP event.
78 mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
80 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
84 setContentView(mCardScroller);
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);
96 // else continue with any other code you need in the method
101 protected void onResume() {
103 mCardScroller.activate();
107 protected void onPause() {
108 mCardScroller.deactivate();
112 private void startScan() {
113 IntentIntegrator integrator = new IntentIntegrator(this);
114 integrator.initiateScan();
118 * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
120 private View buildView() {
121 CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
123 card.setText(R.string.hello_world);
124 return card.getView();