diff options
| author | Ralf Kistner <ralf@embarkmobile.com> | 2014-05-16 20:18:26 +0400 |
|---|---|---|
| committer | Ralf Kistner <ralf@embarkmobile.com> | 2014-05-16 20:18:26 +0400 |
| commit | aef6cfb3468e52eb709a10e6608291cef53d0a0a (patch) | |
| tree | e28ccb23ede1aec47d1e828f03a07ec097cf9f42 /sample/src/main/java/example/zxing/MainActivity.java | |
| parent | fbc667aec86e608b3154a052912ce6e4579c2356 (diff) | |
| download | zxing-android-embedded-aef6cfb3468e52eb709a10e6608291cef53d0a0a.tar.xz | |
Add a sample project.
This greatly speeds up the development/test cycle.
Diffstat (limited to 'sample/src/main/java/example/zxing/MainActivity.java')
| -rw-r--r-- | sample/src/main/java/example/zxing/MainActivity.java | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/sample/src/main/java/example/zxing/MainActivity.java b/sample/src/main/java/example/zxing/MainActivity.java new file mode 100644 index 00000000..fe504602 --- /dev/null +++ b/sample/src/main/java/example/zxing/MainActivity.java @@ -0,0 +1,46 @@ +package example.zxing; + +import android.content.Intent; +import android.support.v7.app.ActionBarActivity; +import android.os.Bundle; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.Toast; + +import com.google.zxing.integration.android.IntentIntegrator; +import com.google.zxing.integration.android.IntentResult; + + +public class MainActivity extends ActionBarActivity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + + public void scanBarcode(View view) { + IntentIntegrator.initiateScan(this); + } + + public void scanBarcodeCustomLayout(View view) { + Intent intent = IntentIntegrator.createScanIntent(this); + IntentIntegrator.setCaptureLayout(intent, R.layout.custom_capture_layout); + IntentIntegrator.startIntent(intent, this); + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data); + if(result != null) { + if(result.getContents() == null) { + Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show(); + } else { + Toast.makeText(this, "Scanned: " + result.getContents(), Toast.LENGTH_LONG).show(); + } + + } + } +} |
