@@ -14,7 +14,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme">
|
||||
<activity android:name=".MainActivity"
|
||||
android:screenOrientation="portrait">
|
||||
android:screenOrientation="portrait">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
|
||||
@@ -23,21 +23,26 @@
|
||||
</activity>
|
||||
<activity
|
||||
android:name="com.king.zxing.CaptureActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".EasyCaptureActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
<activity
|
||||
android:name=".CustomCaptureActivity"/>
|
||||
android:name=".CustomCaptureActivity"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CaptureFragmentActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CustomActivity"
|
||||
android:screenOrientation="portrait"/>
|
||||
android:screenOrientation="portrait"
|
||||
android:theme="@style/CaptureTheme"/>
|
||||
|
||||
<activity
|
||||
android:name=".CodeActivity"
|
||||
|
||||
@@ -56,11 +56,16 @@ public class CodeActivity extends AppCompatActivity {
|
||||
* @param content
|
||||
*/
|
||||
private void createQRCode(String content){
|
||||
//生成二维码最好放子线程生成防止阻塞UI,这里只是演示
|
||||
Bitmap logo = BitmapFactory.decodeResource(getResources(),R.drawable.logo);
|
||||
Bitmap bitmap = CodeUtils.createQRCode(content,600,logo);
|
||||
//显示二维码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
new Thread(() -> {
|
||||
//生成二维码相关放在子线程里面
|
||||
Bitmap logo = BitmapFactory.decodeResource(getResources(),R.drawable.logo);
|
||||
Bitmap bitmap = CodeUtils.createQRCode(content,600,logo);
|
||||
runOnUiThread(()->{
|
||||
//显示二维码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
});
|
||||
}).start();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -68,13 +73,18 @@ public class CodeActivity extends AppCompatActivity {
|
||||
* @param content
|
||||
*/
|
||||
private void createBarCode(String content){
|
||||
//生成条形码最好放子线程生成防止阻塞UI,这里只是演示
|
||||
Bitmap bitmap = CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200,null,true);
|
||||
//显示条形码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
new Thread(() -> {
|
||||
//生成条形码相关放在子线程里面
|
||||
Bitmap bitmap = CodeUtils.createBarCode(content, BarcodeFormat.CODE_128,800,200,null,true);
|
||||
runOnUiThread(()->{
|
||||
//显示条形码
|
||||
ivCode.setImageBitmap(bitmap);
|
||||
});
|
||||
}).start();
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
@@ -82,4 +92,4 @@ public class CodeActivity extends AppCompatActivity {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,6 +32,8 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
|
||||
private ViewfinderView viewfinderView;
|
||||
|
||||
private View ivTorch;
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle icicle) {
|
||||
@@ -51,10 +53,12 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
|
||||
surfaceView = findViewById(R.id.surfaceView);
|
||||
viewfinderView = findViewById(R.id.viewfinderView);
|
||||
ivTorch = findViewById(R.id.ivFlash);
|
||||
ivTorch.setVisibility(View.INVISIBLE);
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
|
||||
mCaptureHelper = new CaptureHelper(this,surfaceView,viewfinderView);
|
||||
mCaptureHelper = new CaptureHelper(this,surfaceView,viewfinderView,ivTorch);
|
||||
mCaptureHelper.setOnCaptureCallback(this);
|
||||
mCaptureHelper.onCreate();
|
||||
mCaptureHelper.vibrate(true)
|
||||
@@ -88,26 +92,6 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
return super.onTouchEvent(event);
|
||||
}
|
||||
|
||||
/**
|
||||
* 关闭闪光灯(手电筒)
|
||||
*/
|
||||
private void offFlash(){
|
||||
Camera camera = mCaptureHelper.getCameraManager().getOpenCamera().getCamera();
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_OFF);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启闪光灯(手电筒)
|
||||
*/
|
||||
public void openFlash(){
|
||||
Camera camera = mCaptureHelper.getCameraManager().getOpenCamera().getCamera();
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
parameters.setFlashMode(Camera.Parameters.FLASH_MODE_TORCH);
|
||||
camera.setParameters(parameters);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 扫码结果回调
|
||||
@@ -123,25 +107,12 @@ public class CustomActivity extends AppCompatActivity implements OnCaptureCallba
|
||||
}
|
||||
|
||||
|
||||
private void clickFlash(View v){
|
||||
if(v.isSelected()){
|
||||
offFlash();
|
||||
v.setSelected(false);
|
||||
}else{
|
||||
openFlash();
|
||||
v.setSelected(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
onBackPressed();
|
||||
break;
|
||||
case R.id.ivFlash:
|
||||
clickFlash(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ import android.widget.Toast;
|
||||
import com.king.zxing.CaptureActivity;
|
||||
import com.king.zxing.app.util.StatusBarUtils;
|
||||
import com.king.zxing.camera.CameraConfigurationUtils;
|
||||
import com.king.zxing.camera.FrontLightMode;
|
||||
|
||||
/**
|
||||
* 自定义继承CaptureActivity
|
||||
@@ -34,8 +35,6 @@ import com.king.zxing.camera.CameraConfigurationUtils;
|
||||
*/
|
||||
public class CustomCaptureActivity extends CaptureActivity {
|
||||
|
||||
private ImageView ivFlash;
|
||||
|
||||
private boolean isContinuousScan;
|
||||
@Override
|
||||
public int getLayoutId() {
|
||||
@@ -51,12 +50,6 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
TextView tvTitle = findViewById(R.id.tvTitle);
|
||||
tvTitle.setText(getIntent().getStringExtra(MainActivity.KEY_TITLE));
|
||||
|
||||
ivFlash = findViewById(R.id.ivFlash);
|
||||
|
||||
if(!hasTorch()){
|
||||
ivFlash.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
isContinuousScan = getIntent().getBooleanExtra(MainActivity.KEY_IS_CONTINUOUS,false);
|
||||
//获取CaptureHelper,里面有扫码相关的配置设置
|
||||
getCaptureHelper().playBeep(false)//播放音效
|
||||
@@ -66,28 +59,12 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
// .framingRectRatio(0.9f)//设置识别区域比例,范围建议在0.625 ~ 1.0之间。非全屏识别时才有效
|
||||
// .framingRectVerticalOffset(0)//设置识别区域垂直方向偏移量,非全屏识别时才有效
|
||||
// .framingRectHorizontalOffset(0)//设置识别区域水平方向偏移量,非全屏识别时才有效
|
||||
.frontLightMode(FrontLightMode.AUTO)//设置闪光灯模式
|
||||
.tooDarkLux(45f)//设置光线太暗时,自动触发开启闪光灯的照度值
|
||||
.brightEnoughLux(450f)//设置光线足够明亮时,自动触发关闭闪光灯的照度值
|
||||
.continuousScan(isContinuousScan);//是否连扫
|
||||
}
|
||||
|
||||
/**
|
||||
* 开启或关闭闪光灯(手电筒)
|
||||
* @param on {@code true}表示开启,{@code false}表示关闭
|
||||
*/
|
||||
public void setTorch(boolean on){
|
||||
Camera camera = getCameraManager().getOpenCamera().getCamera();
|
||||
Camera.Parameters parameters = camera.getParameters();
|
||||
CameraConfigurationUtils.setTorch(parameters,on);
|
||||
camera.setParameters(parameters);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 检测是否支持闪光灯(手电筒)
|
||||
* @return
|
||||
*/
|
||||
public boolean hasTorch(){
|
||||
return getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_FLASH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 扫码结果回调
|
||||
@@ -103,21 +80,11 @@ public class CustomCaptureActivity extends CaptureActivity {
|
||||
return super.onResultCallback(result);
|
||||
}
|
||||
|
||||
|
||||
private void clickFlash(View v){
|
||||
boolean isSelected = v.isSelected();
|
||||
setTorch(!isSelected);
|
||||
v.setSelected(!isSelected);
|
||||
}
|
||||
|
||||
public void onClick(View v){
|
||||
switch (v.getId()){
|
||||
case R.id.ivLeft:
|
||||
onBackPressed();
|
||||
break;
|
||||
case R.id.ivFlash:
|
||||
clickFlash(v);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,7 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
|
||||
private void parsePhoto(Intent data){
|
||||
final String path = UriUtils.INSTANCE.getImagePath(this,data);
|
||||
final String path = UriUtils.getImagePath(this,data);
|
||||
Log.d("Jenly","path:" + path);
|
||||
if(TextUtils.isEmpty(path)){
|
||||
return;
|
||||
@@ -243,4 +243,4 @@ public class MainActivity extends AppCompatActivity implements EasyPermissions.P
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,13 @@ import com.king.zxing.app.R;
|
||||
/**
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public class StatusBarUtils {
|
||||
public final class StatusBarUtils {
|
||||
|
||||
public static void immersiveStatusBar(Activity activity,Toolbar toolbar) {
|
||||
private StatusBarUtils(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static void immersiveStatusBar(Activity activity, Toolbar toolbar) {
|
||||
immersiveStatusBar(activity,toolbar,0.0f);
|
||||
}
|
||||
|
||||
@@ -78,7 +82,7 @@ public class StatusBarUtils {
|
||||
}
|
||||
|
||||
/** 获取状态栏高度 */
|
||||
private static int getStatusBarHeight(Context context) {
|
||||
public static int getStatusBarHeight(Context context) {
|
||||
return context.getResources().getDimensionPixelSize(R.dimen.status_bar_height);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.king.zxing.app.util;
|
||||
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.ContentUris;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
@@ -14,13 +13,16 @@ import android.util.Log;
|
||||
/**
|
||||
* @author Jenly <a href="mailto:jenly1314@gmail.com">Jenly</a>
|
||||
*/
|
||||
public enum UriUtils {
|
||||
INSTANCE;
|
||||
public final class UriUtils {
|
||||
|
||||
private UriUtils(){
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取图片
|
||||
*/
|
||||
public String getImagePath(Context context,Intent data) {
|
||||
public static String getImagePath(Context context,Intent data) {
|
||||
String imagePath = null;
|
||||
Uri uri = data.getData();
|
||||
//获取系統版本
|
||||
@@ -54,7 +56,7 @@ public enum UriUtils {
|
||||
/**
|
||||
* 通过uri和selection来获取真实的图片路径,从相册获取图片时要用
|
||||
*/
|
||||
private String getImagePath(Context context,Uri uri, String selection) {
|
||||
private static String getImagePath(Context context,Uri uri, String selection) {
|
||||
String path = null;
|
||||
Cursor cursor = context.getContentResolver().query(uri, null, selection, null, null);
|
||||
if (cursor != null) {
|
||||
@@ -66,4 +68,4 @@ public enum UriUtils {
|
||||
return path;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 809 B After Width: | Height: | Size: 1.7 KiB |
Binary file not shown.
|
Before Width: | Height: | Size: 712 B After Width: | Height: | Size: 1.5 KiB |
@@ -31,7 +31,6 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp"
|
||||
style="@style/OnClick"/>
|
||||
android:layout_marginTop="160dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
@@ -22,7 +22,7 @@
|
||||
app:labelTextLocation="bottom"
|
||||
app:laserStyle="grid"/>
|
||||
<ImageView
|
||||
android:id="@+id/ivFlash"
|
||||
android:id="@+id/ivTorch"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:src="@drawable/flash_selected_selector"
|
||||
@@ -30,7 +30,6 @@
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
android:layout_marginTop="160dp"
|
||||
style="@style/OnClick"/>
|
||||
android:layout_marginTop="160dp" />
|
||||
<include layout="@layout/toolbar_capture"/>
|
||||
</android.support.constraint.ConstraintLayout>
|
||||
Reference in New Issue
Block a user