moonlightcheese

Untitled

Aug 5th, 2011
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.53 KB | None | 0 0
  1. case DIALOG_VIN_ENTRY:
  2.             {
  3.                 //do things
  4.                 Dialog dialog = new Dialog(this);
  5.                 builder = new AlertDialog.Builder(this);
  6.                 builder.setTitle("Vehicle Entry");
  7.                 final View dialogLayout = inflater.inflate(R.layout.dialog_vin_entry, null);
  8.                
  9.                 final EditText vin = (EditText)dialogLayout.findViewById(R.id.vin_in);
  10.                 final Spinner make = (Spinner)dialogLayout.findViewById(R.id.make_spn);
  11.                 final Spinner model = (Spinner)dialogLayout.findViewById(R.id.model_spn);
  12.                 final Spinner year = (Spinner)dialogLayout.findViewById(R.id.year_spn);
  13.                 final Spinner title = (Spinner)dialogLayout.findViewById(R.id.title_spn);
  14.                 final Spinner color = (Spinner)dialogLayout.findViewById(R.id.color_spn);
  15.                
  16.                 //check for a VIN scan string and place appropriately
  17.                 if(b!=null && b.containsKey("scannerRead")) {
  18.                     vin.setText(b.getString("scannerRead"));
  19.                 }
  20.                
  21.                 // Create a BroadcastReceiver for ACTION_FOUND, ACTION_STATE_CHANGED, ACTION_DISCOVERY_FINISHED
  22.                 final BroadcastReceiver dialogReceiver = new BroadcastReceiver() {
  23.                     public void onReceive(Context context, Intent intent) {
  24.                         String action = intent.getAction();
  25.                         if (ScannerService.ACTION_READ_SCANNER.equals(action)) {
  26.                             String tmp = intent.getStringExtra("scannerRead");
  27.                            
  28.                             vin.setText(tmp);
  29.                         }
  30.                     }
  31.                 };
  32.                
  33.                 //make will have to be a CursorAdapter implementation
  34.                 //model will have to be a CursorAdapter implementation
  35.                 //attach year to the dynamic array we created with years
  36.                 ArrayAdapter yearAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, mYearList);
  37.                 yearAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  38.                 year.setAdapter(yearAdapter);
  39.                 //attach title to the static title array.
  40.                 ArrayAdapter titleAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.title_array));
  41.                 titleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  42.                 title.setAdapter(titleAdapter);
  43.                 //attach color to the static color array
  44.                 ArrayAdapter colorAdapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, getResources().getStringArray(R.array.color_array));
  45.                 colorAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  46.                 color.setAdapter(colorAdapter);
  47.                
  48.                 builder = new AlertDialog.Builder(this);
  49.                 builder.setView(dialogLayout);
  50.                 builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
  51.                         public void onClick(DialogInterface dialog, int id) {
  52.                             String vinString = vin.getText().toString();
  53.                             String makeString = (String)make.getSelectedItem();
  54.                             String modelString = (String)model.getSelectedItem();
  55.                             String yearString = (String)year.getSelectedItem();
  56.                             String titleString = (String)title.getSelectedItem();
  57.                             String colorString = (String)color.getSelectedItem();
  58.                            
  59.                             dialog.getContext().unregisterReceiver(dialogReceiver);
  60.                             dialog.dismiss();
  61.                         }
  62.                     });
  63.                 builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
  64.                         public void onClick(DialogInterface dialog, int id) {
  65.                             dialog.getContext().unregisterReceiver(dialogReceiver);
  66.                             dialog.dismiss();
  67.                         }
  68.                     });
  69.                 dialog = builder.create();
  70.                 IntentFilter filter = new IntentFilter();
  71.                 filter.addAction(ScannerService.ACTION_READ_SCANNER);
  72.                 dialog.getContext().registerReceiver(dialogReceiver, filter);
  73.                 return dialog;
  74.             }
Advertisement
Add Comment
Please, Sign In to add comment