• 大小: 42KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-16
  • 语言: Java
  • 标签: android  zxing  二维码  

资源简介

个人做二维码扫描,觉得效果还不错,留存以后用

资源截图

代码片段和文件信息

/*
 * Copyright (C) 2012 ZXing authors
 *
 * Licensed under the Apache License Version 2.0 (the “License“);
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing software
 * distributed under the License is distributed on an “AS IS“ BASIS
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.toltech.treefrog.qrcodescanner;

import android.content.Context;
import android.content.SharedPreferences;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.preference.PreferenceManager;

import cn.toltech.treefrog.qrcodescanner.camera.CameraManager;
import cn.toltech.treefrog.qrcodescanner.camera.FrontLightMode;

/**
 * Detects ambient light and switches on the front light when very dark and off again when sufficiently light.
 *
 * @author Sean Owen
 * @author Nikolaus Huber
 */
final class AmbientLightManager implements SensorEventListener {

  private static final float TOO_DARK_LUX = 45.0f;
  private static final float BRIGHT_ENOUGH_LUX = 450.0f;

  private final Context context;
  private CameraManager cameraManager;
  private Sensor lightSensor;

  AmbientLightManager(Context context) {
    this.context = context;
  }

  void start(CameraManager cameraManager) {
    this.cameraManager = cameraManager;
    SharedPreferences sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
    if (FrontLightMode.readPref(sharedPrefs) == FrontLightMode.AUTO) {
      SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
      lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);
      if (lightSensor != null) {
        sensorManager.registerListener(this lightSensor SensorManager.SENSOR_DELAY_NORMAL);
      }
    }
  }

  void stop() {
    if (lightSensor != null) {
      SensorManager sensorManager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE);
      sensorManager.unregisterListener(this);
      cameraManager = null;
      lightSensor = null;
    }
  }

  @Override
  public void onSensorChanged(SensorEvent sensorEvent) {
    float ambientLightLux = sensorEvent.values[0];
    if (cameraManager != null) {
      if (ambientLightLux <= TOO_DARK_LUX) {
        cameraManager.setTorch(true);
      } else if (ambientLightLux >= BRIGHT_ENOUGH_LUX) {
        cameraManager.setTorch(false);
      }
    }
  }

  @Override
  public void onAccuracyChanged(Sensor sensor int accuracy) {
    // do nothing
  }

}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2934  2015-10-28 09:18  qrcodescanner\AmbientLightManager.java

     文件       4594  2015-10-28 09:19  qrcodescanner\BeepManager.java

     文件       4326  2015-10-28 09:08  qrcodescanner\camera\AutoFocusManager.java

     文件       5800  2015-10-28 09:08  qrcodescanner\camera\CameraConfigurationManager.java

     文件      16993  2015-10-28 09:08  qrcodescanner\camera\CameraConfigurationUtils.java

     文件      13706  2015-10-29 13:51  qrcodescanner\camera\CameraManager.java

     文件       1312  2015-10-28 09:13  qrcodescanner\camera\FrontLightMode.java

     文件       2521  2015-10-28 09:08  qrcodescanner\camera\open\OpenCameraInterface.java

     文件       1923  2015-10-28 09:08  qrcodescanner\camera\PreviewCallback.java

     文件      11712  2015-10-30 11:02  qrcodescanner\CaptureActivity.java

     文件       5926  2015-10-29 10:10  qrcodescanner\CaptureActivityHandler.java

     文件       3923  2015-10-28 09:08  qrcodescanner\Contents.java

     文件       4116  2015-10-28 09:08  qrcodescanner\DecodeFormatManager.java

     文件       4304  2015-10-29 10:08  qrcodescanner\DecodeHandler.java

     文件       4107  2015-10-29 09:55  qrcodescanner\DecodeThread.java

     文件       3487  2015-10-28 09:08  qrcodescanner\InactivityTimer.java

     文件      10414  2015-10-28 09:08  qrcodescanner\Intents.java

     文件        762  2015-10-28 09:08  qrcodescanner\IntentSource.java

     文件       3205  2015-10-28 09:08  qrcodescanner\PreferencesActivity.java

     文件       4481  2015-10-28 09:23  qrcodescanner\PreferencesFragment.java

     文件      11924  2015-10-29 13:57  qrcodescanner\view\ViewfinderView.java

     文件       1195  2015-10-28 09:23  qrcodescanner\ViewfinderResultPointCallback.java

     目录          0  2015-10-28 09:08  qrcodescanner\camera\open

     目录          0  2015-10-29 13:51  qrcodescanner\camera

     目录          0  2015-10-29 13:57  qrcodescanner\view

     目录          0  2015-10-30 11:02  qrcodescanner

----------- ---------  ---------- -----  ----

               123665                    26


评论

共有 条评论