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.View;
15 import android.view.ViewGroup;
16 import android.widget.AdapterView;
18 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
19 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
22 * An {@link Activity} showing a tuggable "Hello World!" card.
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}.
29 * @see <a href="https://developers.google.com/glass/develop/gdk/touch">GDK Developer Guide</a>
31 public class MainActivity extends Activity {
32 public final static String TAG = "MainActivity";
35 * {@link CardScrollView} to use as the main content view.
37 private CardScrollView mCardScroller;
40 * "Hello World!" {@link View} generated by {@link #buildView()}.
45 protected void onCreate(Bundle bundle) {
46 super.onCreate(bundle);
50 mCardScroller = new CardScrollView(this);
51 mCardScroller.setAdapter(new CardScrollAdapter() {
53 public int getCount() {
58 public Object getItem(int position) {
63 public View getView(int position, View convertView, ViewGroup parent) {
68 public int getPosition(Object item) {
69 if (mView.equals(item)) {
72 return AdapterView.INVALID_POSITION;
75 // Handle the TAP event.
76 mCardScroller.setOnItemClickListener(new AdapterView.OnItemClickListener() {
78 public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
82 setContentView(mCardScroller);
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());
90 // else continue with any other code you need in the method
95 protected void onResume() {
97 mCardScroller.activate();
101 protected void onPause() {
102 mCardScroller.deactivate();
106 private void startScan() {
107 IntentIntegrator integrator = new IntentIntegrator(this);
108 integrator.initiateScan();
112 * Builds a Glass styled "Hello World!" view using the {@link CardBuilder} class.
114 private View buildView() {
115 CardBuilder card = new CardBuilder(this, CardBuilder.Layout.TEXT);
117 card.setText(R.string.hello_world);
118 return card.getView();