public void onPreviewFrame(byte[] data, Camera camera) {
    Camera.Parameters parameters = camera.getParameters();
    Camera.Size size = parameters.getPreviewSize();

    Image barcode = new Image(size.width, size.height, "Y800");
    barcode.setData(data);

    int result = mScanner.scanImage(barcode);

    if (result != 0) {
      mCamera.cancelAutoFocus();
      mCamera.setPreviewCallback(null);
      mCamera.stopPreview();
      mPreviewing = false;
      SymbolSet syms = mScanner.getResults();
      for (Symbol sym : syms) {
        String symData = sym.getData();
        if (!TextUtils.isEmpty(symData)) {
          Intent dataIntent = new Intent();
          dataIntent.putExtra(SCAN_RESULT, symData);
          dataIntent.putExtra(SCAN_RESULT_TYPE, sym.getType());
          setResult(Activity.RESULT_OK, dataIntent);
          finish();
          break;
        }
      }
    }
  }
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          String strScanResult = "";

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();
            for (Symbol sym : syms) {
              // scanText.setText("barcode result " + sym.getData());
              strScanResult += sym.getData();
              barcodeScanned = true;
            }

            Intent myIntent = new Intent(MainActivity.this, ValidateBarCodeResult.class);
            myIntent.putExtra("barcode_result", strScanResult);
            startActivity(myIntent);
          }
        }
  public void setupScanner() {
    mScanner = new ImageScanner();
    mScanner.setConfig(0, Config.X_DENSITY, 3);
    mScanner.setConfig(0, Config.Y_DENSITY, 3);

    int[] symbols = getIntent().getIntArrayExtra(SCAN_MODES);
    if (symbols != null) {
      mScanner.setConfig(Symbol.NONE, Config.ENABLE, 0);
      for (int symbol : symbols) {
        mScanner.setConfig(Symbol.QRCODE, Config.ENABLE, 1);
        // mScanner.setConfig(symbol, Config.ENABLE, 1);
      }
    }
  }
Пример #4
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_camera);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    mContext = CameraActivity.this;

    mUsersSQL = "select a.[CORPNO], a.[OPERNO], a.[OPERPASS] from b_opera a;";
    mSearchUsersSQL = "select count(*) from b_opera a where a.[CORPNO] = ? and a.[OPERNO] = ?;";
    mInsertOperaSQL = "INSERT INTO B_OPERA (CORPNO, OPERNO, OPERPASS) VALUES(?, ?, ?, ?, ?);";
    mInsertDownInfoSQL =
        "INSERT INTO B_LOGININFO (CORPNO, PROJDESC, DOWNURL, UPLOADURL, DBFILENAME, DOWNTIME) VALUES(?, ?, ?, ?, ?, ?);";
    mDownLoadInfoSQL =
        "select a.[CORPNO], a.[PROJDESC], a.[DOWNURL], a.[UPLOADURL], a.[DBFILENAME] from b_logininfo a;";
    autoFocusHandler = new Handler();
    mCamera = getCameraInstance();

    /* Instance barcode scanner */
    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);

    Log.i(TAG, "CameraActivity onCreate()");
    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
    preview.addView(mPreview);

    mCamera.setPreviewCallback(previewCb);
    mCamera.startPreview();
    previewing = true;
    mCamera.autoFocus(autoFocusCB);

    // 初始化声音和震动
    AudioManager audioService = (AudioManager) getSystemService(AUDIO_SERVICE);
    // 如果手机是震动模式就震动
    if (audioService.getRingerMode() != AudioManager.RINGER_MODE_NORMAL) {
      playBeep = false;
    }
    // 初始化声音
    initBeepSound();
    initLoginDataBase();
    // MyApp.showToast(CameraActivity.this, "hello");

    Button mButtonBack = (Button) findViewById(R.id.button_back);

    /*返回按钮*/
    mButtonBack.setOnClickListener(
        new View.OnClickListener() {

          @Override
          public void onClick(View v) {
            Intent intent = new Intent();
            intent.putExtra("downloadfile", "");
            setResult(RESULT_OK, intent);
            finish();
          }
        });
  }
  @Override
  public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    vibrator = (Vibrator) getActivity().getSystemService(Context.VIBRATOR_SERVICE);

    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);
  }
Пример #6
0
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Camera.Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();

            playBeepSoundAndVibrate(); // 播放声音和振动代表成功获取二维码

            for (Symbol sym : syms) {
              // 将扫描后的信息返回
              String resultStr = sym.getData();
              Log.i(TAG, "resultStr: " + resultStr);
              if (resultStr.isEmpty() || !resultStr.substring(0, 7).equalsIgnoreCase("http://")) {
                // Message msg = new Message();
                // msg.what = MSG_SCANRESULT_NONE;
                // myHandler.sendMessage(msg);
                MyApp.showToast(mContext, "二维码信息内容不符合房产投票项目的要求, 请联系管理人员!");
                Intent intent = new Intent();
                intent.putExtra("downloadfile", "");
                setResult(RESULT_OK, intent);
                finish();
              } else {
                downLoadDBFile(resultStr);
                //      mLoginSqldb.close();
                //       mVoteSqldb.close();
                Intent intent = new Intent();
                intent.putExtra("downloadfile", mDownloadfile);
                setResult(RESULT_OK, intent);
                finish();
              }
            }
          }
        }
Пример #7
0
        public void onPreviewFrame(byte[] data, Camera camera) {
          Camera.Parameters parameters = camera.getParameters();
          Size size = parameters.getPreviewSize();

          Image barcode = new Image(size.width, size.height, "Y800");
          barcode.setData(data);

          int result = scanner.scanImage(barcode);

          if (result != 0) {
            previewing = false;
            mCamera.setPreviewCallback(null);
            //  mCamera.stopPreview();

            SymbolSet syms = scanner.getResults();
            for (Symbol sym : syms) {
              scanText.setText("barcode" + sym.getData());

              barcodeScanned = true;
              launchIntent(syms);
            }
          }
        }
Пример #8
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    barcodeScanned = false;
    previewing = true;
    setContentView(R.layout.activity_scan);

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    autoFocusHandler = new Handler();
    mCamera = getCameraInstance();

    /* Instance barcode scanner */
    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);

    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
    preview.addView(mPreview);

    scanText = (TextView) findViewById(R.id.scanText);

    scanButton = (Button) findViewById(R.id.ScanButton);
    scanButton.setOnClickListener(
        new OnClickListener() {
          public void onClick(View v) {
            if (barcodeScanned) {
              barcodeScanned = false;
              scanText.setText("Scanning...");
              mCamera.setPreviewCallback(previewCb);
              mCamera.startPreview();
              previewing = true;
              mCamera.autoFocus(autoFocusCB);
            }
          }
        });
  }
  @Override
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); // To avoid screen timeout

    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

    autoFocusHandler = new Handler();
    mCamera = getCameraInstance();

    /* Instance barcode scanner */
    scanner = new ImageScanner();
    scanner.setConfig(0, Config.X_DENSITY, 3);
    scanner.setConfig(0, Config.Y_DENSITY, 3);

    mPreview = new CameraPreview(this, mCamera, previewCb, autoFocusCB);
    FrameLayout preview = (FrameLayout) findViewById(R.id.cameraPreview);
    preview.addView(mPreview);

    // scanText = (TextView) findViewById(R.id.scanText);

    /*
    quitButton = (Button) findViewById(R.id.quitButton);

    quitButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            sp = getSharedPreferences(String.valueOf(storagePreference.admin_id), Context.MODE_PRIVATE);
            ed = sp.edit();
            ed.clear();
            ed.commit();

            android.os.Process.killProcess(android.os.Process.myPid());
            System.exit(1);
        }
    });


    adminLoginButton = (Button) findViewById(R.id.adminLoginButton);
    adminLoginButton.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent myIntent = new Intent(MainActivity.this, AdminLogin.class);
            startActivity(myIntent);
        }
    });
    */

    /*
    scanButton = (Button) findViewById(R.id.ScanButton);

    scanButton.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            if (barcodeScanned) {
                barcodeScanned = false;
                scanText.setText("Hold over barcode.");
                mCamera.setPreviewCallback(previewCb);
                mCamera.startPreview();
                previewing = true;
                mCamera.autoFocus(autoFocusCB);
            }
        }
    });
    */

  }