Guest User

QR code

a guest
Jun 16th, 2013
10
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.70 KB | None | 0 0
  1. package com.example.bluevillenursery;
  2. import android.app.Activity;
  3. import android.content.Intent;
  4. import android.os.Bundle;
  5. import android.view.Menu;
  6. import android.view.View;
  7. import android.widget.Button;
  8. import android.widget.TextView;
  9.  
  10. // CLASS START
  11. public class MainActivity extends Activity  {
  12.    
  13.     // ON CREATE START
  14.     @Override  
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.        
  17.         // SET UP VAR START
  18.         super.onCreate(savedInstanceState);
  19.         setContentView(R.layout.activity_main);
  20.         final Button button = (Button)findViewById(R.id.button1);  
  21.         final IntentIntegrator integrator = new IntentIntegrator(this);
  22.         // SET UP VAR END
  23.        
  24.         // ON BUTTON CLICK START
  25.         button.setOnClickListener(new View.OnClickListener() {     
  26.             @Override
  27.             public void onClick(View v) {
  28.                 // TODO Auto-generated method stub     
  29.                 integrator.initiateScan(); 
  30.             }          
  31.         });
  32.         // ON BUTTON CLICK END      
  33.        
  34.     }
  35.     // ON CREATE END
  36.    
  37.     // ON RESTART START
  38.     protected void onRestart(Bundle savedInstanceState) {
  39.         // SET UP VAR START
  40.                 super.onCreate(savedInstanceState);
  41.                 setContentView(R.layout.activity_main);
  42.                 final Button button = (Button)findViewById(R.id.button1);  
  43.                 final IntentIntegrator integrator = new IntentIntegrator(this);
  44.                 // SET UP VAR END
  45.                
  46.                 // ON BUTTON CLICK START
  47.                 button.setOnClickListener(new View.OnClickListener() {     
  48.                     @Override
  49.                     public void onClick(View v) {
  50.                         // TODO Auto-generated method stub     
  51.                         integrator.initiateScan(); 
  52.                     }          
  53.                 });
  54.                 // ON BUTTON CLICK END      
  55.     }
  56.     // ON RESTART END
  57.        
  58.     // HANDLE SCAN START
  59.       public void onActivityResult(int requestCode, int resultCode, Intent intent) {
  60.           IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
  61.           if (scanResult != null) {
  62.              
  63.             // SET UP VAR START
  64.               String barcode;
  65.               String typ;
  66.               barcode = scanResult.getContents();
  67.               typ = scanResult.getFormatName();
  68.               final TextView myText = (TextView) findViewById(R.id.textView1);
  69.             // SET UP VAR END
  70.            
  71.               // HANDLE RESULT STRING START
  72.                if (barcode.equals("SEMI-DWARF BRAEBURN")) {
  73.                   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.");               
  74.               }
  75.                
  76.                else if (barcode.equals("SEMI-DWARF GALA")) {
  77.                   myText.setText( "SEMI-DWARF GALA\n\n" +
  78.                          
  79.                           "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"
  80.                          
  81.                         );               
  82.               }
  83.                
  84.              
  85.      
  86.           else  {
  87.               myText.setText(barcode + " " + typ);
  88.           }
  89.          
  90.                
  91.                
  92.                    
  93.               // HANDLE RESULT STRING END
  94.           }
  95.          
  96.           // HANDLE NULL SCAN RESULT START
  97.           else if (scanResult == null)    {
  98.               final TextView myText = (TextView) findViewById(R.id.textView1);
  99.               myText.setText("Null result");         
  100.           }
  101.         // HANDLE NULL SCAN RESULT END
  102.          
  103.          
  104.         }
  105.       // HANDLE SCAN END
  106.        
  107.     // ON CREATE MENU START
  108.     @Override  
  109.     public boolean onCreateOptionsMenu(Menu menu) {
  110.         // Inflate the menu; this adds items to the action bar if it is present.
  111.         getMenuInflater().inflate(R.menu.main, menu);
  112.         return true;       
  113.     }
  114.     // ON CREATE MENU END
  115.    
  116. }
  117. // CLASS END
Advertisement
Add Comment
Please, Sign In to add comment