Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.bluevillenursery;
- import android.app.Activity;
- import android.content.Intent;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.View;
- import android.widget.Button;
- import android.widget.TextView;
- // CLASS START
- public class MainActivity extends Activity {
- // ON CREATE START
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- // SET UP VAR START
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Button button = (Button)findViewById(R.id.button1);
- final IntentIntegrator integrator = new IntentIntegrator(this);
- // SET UP VAR END
- // ON BUTTON CLICK START
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- integrator.initiateScan();
- }
- });
- // ON BUTTON CLICK END
- }
- // ON CREATE END
- // ON RESTART START
- protected void onRestart(Bundle savedInstanceState) {
- // SET UP VAR START
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- final Button button = (Button)findViewById(R.id.button1);
- final IntentIntegrator integrator = new IntentIntegrator(this);
- // SET UP VAR END
- // ON BUTTON CLICK START
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- // TODO Auto-generated method stub
- integrator.initiateScan();
- }
- });
- // ON BUTTON CLICK END
- }
- // ON RESTART END
- // HANDLE SCAN START
- public void onActivityResult(int requestCode, int resultCode, Intent intent) {
- IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
- if (scanResult != null) {
- // SET UP VAR START
- String barcode;
- String typ;
- barcode = scanResult.getContents();
- typ = scanResult.getFormatName();
- final TextView myText = (TextView) findViewById(R.id.textView1);
- // SET UP VAR END
- // HANDLE RESULT STRING START
- if (barcode.equals("SEMI-DWARF BRAEBURN")) {
- myText.setText( "Mature size: 12\u2019 x 12\u2019 Disease resistance: Moderate\nPollinator required: Yes- can be pollinated with any variety\nThis late-ripening apple tree produces medium to large fruits. Green apples with red \nstriping are crisp, juicy and sweet with a tart bite. Great both fresh and cooked. Fruit matures late September.");
- }
- else if (barcode.equals("SEMI-DWARF GALA")) {
- myText.setText( "SEMI-DWARF GALA\n\n" +
- "Mature size: 10\' x 12\' Disease Resistance: Good. \nOrange-red fruit, flavor is like a spicy Golden Delicious. A top quality eating apple. Fruit matures mid to late September"
- );
- }
- else {
- myText.setText(barcode + " " + typ);
- }
- // HANDLE RESULT STRING END
- }
- // HANDLE NULL SCAN RESULT START
- else if (scanResult == null) {
- final TextView myText = (TextView) findViewById(R.id.textView1);
- myText.setText("Null result");
- }
- // HANDLE NULL SCAN RESULT END
- }
- // HANDLE SCAN END
- // ON CREATE MENU START
- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.main, menu);
- return true;
- }
- // ON CREATE MENU END
- }
- // CLASS END
Advertisement
Add Comment
Please, Sign In to add comment