コード例 #1
0
 /** Resumes the {@link AppCompatActivity} and resumes the Barcode Scanner */
 @Override
 protected void onResume() {
   super.onResume();
   barcodeScannerView.resume();
 }
コード例 #2
0
  /**
   * Method that checks if the data input to the {@link EditText} field matches a valid format and
   * that it matches a value stored for a point. Then navigates the use to the point data scanned.
   *
   * <p>Otherwise an error message is shown to the user and the input is cleared ready for the next
   * input.
   */
  private void submit() {

    // Hide keyboard when submit is pressed so Snackbar can be seen
    View view = this.getCurrentFocus();
    if (view != null) {
      InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
      imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
    }

    EditText etCodePinEntry = (EditText) findViewById(R.id.etCodePinEntry);
    String result = etCodePinEntry.getText().toString();
    // Check if the point came from being scanned

    // Check if a point or a tour was submitted
    boolean isTour = false;
    if (result.length() > 6 && result.substring(0, 6).equals("POINT-")) {
      // Takes identification part of point id
      result = result.substring(6);
    } else if (result.length() > 2 && result.substring(0, 2).equals("SN")) {
      // Takes identification part of session passphrase
      result = result.substring(2);
      // Sets to identify as a tour
      isTour = true;
    }

    entry = result;

    // Check if user wants to add a session or a point
    if (isTour) {
      // For when the user attempts to add a session
      try {
        // Checks to see if tour session is already on device
        Cursor sessionCursor = FeedActivity.database.getAll(SESSION_TABLE);
        boolean alreadyExists = false;
        for (int i = 0; i < sessionCursor.getCount(); i++) {
          sessionCursor.moveToPosition(i);
          if (result.equals(sessionCursor.getString(sessionCursor.getColumnIndex(PASSPHRASE)))) {
            alreadyExists = true;
          }
        }
        if (alreadyExists) {
          Log.d("FeedActivity", "Tour for " + entry + " already exists!");
          Snackbar.make(
                  barcodeScannerView,
                  "Tour already downloaded on this device.",
                  Snackbar.LENGTH_LONG)
              .show();
          barcodeScannerView.resume();
          clearInput();
        } else {
          // Attempts to download tour if the passphrase is valid
          TourSubmit tourSubmit = new TourSubmit();
          tourSubmit.execute(result);
        }
      } catch (NotInSchemaException e) {
        Log.e("DATABASE_FAIL", Log.getStackTraceString(e));
      }
    } else {
      // Calls FeedActivity#onActivityResult if the point exists.
      // Displays a message otherwise.
      if (pointExistsInTour(result)) {
        Intent data = new Intent();
        data.putExtra("mode", "point");
        data.putExtra(DetailActivity.EXTRA_PIN, result);

        // Replace unlock with a value of 1
        Map<String, String> tourPointColumnsMap = new HashMap<>();
        tourPointColumnsMap.put(UNLOCK, UNLOCK_STATE_UNLOCKED);
        Map<String, String> tourPointPrimaryKeysMap = new HashMap<>();
        Log.i("inScanning", "" + FeedActivity.currentTourId);
        tourPointPrimaryKeysMap.put(TOUR_ID, "" + FeedActivity.currentTourId);
        tourPointPrimaryKeysMap.put(POINT_ID, result);
        try {
          Cursor cursorGetRank =
              FeedActivity.database.getWholeByPrimaryPartial(
                  POINT_TOUR_TABLE, tourPointPrimaryKeysMap);
          cursorGetRank.moveToFirst();
          String pointRank = cursorGetRank.getString(cursorGetRank.getColumnIndex(RANK));
          tourPointColumnsMap.put(RANK, pointRank);
          FeedActivity.database.insert(
              tourPointColumnsMap, tourPointPrimaryKeysMap, POINT_TOUR_TABLE);
        } catch (NotInSchemaException e) {
          Log.e("DATABASE_FAIL", Log.getStackTraceString(e));
        }
        // Notify the feedAdapter that a viewHolder's view has to update.
        ObservableLock observableLock = new ObservableLock();
        observableLock.addObserver(FeedActivity.getCurrentFeedAdapter());
        observableLock.setChange(result, FeedActivity.currentTourId);
        setResult(RESULT_OK, data);
        finish();
      } else {
        Log.d("FeedActivity", "Point for " + entry + " not found!");
        Snackbar.make(
                barcodeScannerView, "Point not found, please try again.", Snackbar.LENGTH_LONG)
            .show();
        barcodeScannerView.resume();
        clearInput();
      }
    }
  }