/[projects]/android/BarcodeSample/app/src/main/java/dk/thoerup/android/barcodesample/MainActivity.java
ViewVC logotype

Annotation of /android/BarcodeSample/app/src/main/java/dk/thoerup/android/barcodesample/MainActivity.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2529 - (hide annotations) (download)
Thu May 7 11:01:37 2015 UTC (9 years ago) by torben
File size: 3628 byte(s)


1 torben 2527 package dk.thoerup.android.barcodesample;
2    
3     import android.content.Intent;
4     import android.support.v7.app.ActionBarActivity;
5     import android.os.Bundle;
6     import android.view.Menu;
7     import android.view.MenuItem;
8     import android.view.View;
9     import android.widget.Button;
10     import android.widget.TextView;
11     import android.widget.Toast;
12    
13     import com.google.zxing.integration.android.IntentIntegrator;
14     import com.google.zxing.integration.android.IntentResult;
15    
16     /*
17     http://blog.dihaw.com/integrating-zxing-in-your-android-app-as-standalone-scanner/
18    
19     http://code.tutsplus.com/tutorials/android-sdk-create-a-barcode-reader--mobile-17162
20    
21    
22     http://stackoverflow.com/questions/27851512/how-to-integrate-zxing-library-to-android-studio-for-barcode-scanning
23    
24     */
25    
26     public class MainActivity extends ActionBarActivity {
27    
28     private Button scanBtn;
29     private TextView formatTxt, contentTxt;
30    
31 torben 2529 //ved rotate bliver activity'en genstartet - så enten skal variablerne gøres static/gemmes på anden vis eller også skal man låse for rotation
32     static String scanContent = "";
33     static String scanFormat = "";
34    
35    
36    
37 torben 2527 @Override
38     protected void onCreate(Bundle savedInstanceState) {
39     super.onCreate(savedInstanceState);
40     setContentView(R.layout.activity_main);
41    
42     scanBtn = (Button) findViewById(R.id.button);
43     formatTxt = (TextView)findViewById(R.id.scan_format);
44     contentTxt = (TextView)findViewById(R.id.scan_content);
45    
46    
47    
48    
49     scanBtn.setOnClickListener(new View.OnClickListener() {
50    
51     @Override
52     public void onClick(View v) {
53     /*Intent intent = new Intent("com.google.zxing.client.android.SCAN");
54     intent.putExtra("com.google.zxing.client.android.SCAN.SCAN_MODE", "QR_CODE_MODE");
55     startActivityForResult(intent, 0);*/
56    
57     IntentIntegrator scanIntegrator = new IntentIntegrator(MainActivity.this);
58     scanIntegrator.initiateScan();
59     }
60     });
61    
62     }
63    
64 torben 2529 @Override
65     protected void onStart() {
66     super.onStart();
67     updateLabels();
68     }
69    
70 torben 2527 public void onActivityResult(int requestCode, int resultCode, Intent intent) {
71     IntentResult scanningResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
72    
73     if (scanningResult != null) {
74 torben 2529 scanContent = scanningResult.getContents();
75     scanFormat = scanningResult.getFormatName();
76 torben 2527
77 torben 2529 updateLabels();
78 torben 2527 }
79     else{
80     Toast toast = Toast.makeText(getApplicationContext(), "No scan data received!", Toast.LENGTH_SHORT);
81     toast.show();
82     }
83     }
84    
85 torben 2529 private void updateLabels() {
86     formatTxt.setText("FORMAT: " + scanFormat);
87     contentTxt.setText("CONTENT: " + scanContent);
88     }
89    
90 torben 2527 @Override
91     public boolean onCreateOptionsMenu(Menu menu) {
92     // Inflate the menu; this adds items to the action bar if it is present.
93     getMenuInflater().inflate(R.menu.menu_main, menu);
94     return true;
95     }
96    
97     @Override
98     public boolean onOptionsItemSelected(MenuItem item) {
99     // Handle action bar item clicks here. The action bar will
100     // automatically handle clicks on the Home/Up button, so long
101     // as you specify a parent activity in AndroidManifest.xml.
102     int id = item.getItemId();
103    
104     //noinspection SimplifiableIfStatement
105     if (id == R.id.action_settings) {
106     return true;
107     }
108    
109     return super.onOptionsItemSelected(item);
110     }
111     }

  ViewVC Help
Powered by ViewVC 1.1.20