]> rtime.felk.cvut.cz Git - hornmich/skoda-qr-demo.git/blob - QRScanner/mobile/src/main/java/cz/cvut/fel/dce/qrscanner/MainActivity.java
Fix application crashing issue
[hornmich/skoda-qr-demo.git] / QRScanner / mobile / src / main / java / cz / cvut / fel / dce / qrscanner / MainActivity.java
1 package cz.cvut.fel.dce.qrscanner;
2
3 import android.content.Intent;
4 import android.support.v7.app.ActionBarActivity;
5 import android.os.Bundle;
6 import android.util.Log;
7 import android.view.Menu;
8 import android.view.MenuItem;
9 import android.view.View;
10
11 import cz.cvut.fel.dce.qrscanner.integration.IntentIntegrator;
12 import cz.cvut.fel.dce.qrscanner.integration.IntentResult;
13
14 /**
15  * An {@link android.app.Activity} showing an immersive card with a Skoda Auto logo, waiting for
16  * user to tap the screen to start the QR code scanning.
17  */
18 public class MainActivity extends ActionBarActivity {
19         /**
20          * An activity tag for debug, error and info messages.
21          */
22         public static final String TAG = "MainActivity";
23
24         @Override
25         protected void onCreate(Bundle savedInstanceState) {
26                 super.onCreate(savedInstanceState);
27                 setContentView(R.layout.activity_main);
28         }
29
30
31         @Override
32         public boolean onCreateOptionsMenu(Menu menu) {
33                 // Inflate the menu; this adds items to the action bar if it is present.
34                 getMenuInflater().inflate(R.menu.menu_main, menu);
35                 return true;
36         }
37
38         @Override
39         public boolean onOptionsItemSelected(MenuItem item) {
40                 int id = item.getItemId();
41
42                 if (id == R.id.start_scan) {
43                         startScan();
44                 }
45
46                 return super.onOptionsItemSelected(item);
47         }
48
49         public void onActivityResult(int requestCode, int resultCode, Intent intent) {
50                 IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
51                 if (scanResult != null) {
52                         Log.i(TAG, scanResult.toString());
53                         Intent preview = new Intent(this, PreviewActivity.class);
54                         preview.putExtra(PreviewActivity.COMP_ID_INTENT_KEY, scanResult.getContents());
55                         startActivity(preview);
56                 }
57         }
58
59         /**
60          * Start the scan code activity
61          */
62         private void startScan() {
63                 IntentIntegrator integrator = new IntentIntegrator(this);
64                 integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);
65         }
66
67         /** Called when the user touches the screen */
68         public void findComponent(View view) {
69                 startScan();
70         }
71 }