Skip to content

Commit

Permalink
可以自定义背景色
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Aug 16, 2019
1 parent 4e908d0 commit 4f1e203
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ public void onClick(View v) {
});
}
})
//背景颜色
.setBgColor("#33FF0000")
.builder();
MNScanManager.startScan(this, scanConfig, new MNScanCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ private void initIntent() {
MNScanConfig mnScanConfig = (MNScanConfig) intent.getSerializableExtra(MNScanManager.INTENT_KEY_CONFIG_MODEL);

String scanColor = mnScanConfig.getScanColor();
String maskColor = mnScanConfig.getBgColor();
beepFlag = mnScanConfig.isShowBeep();
vibrateFlag = mnScanConfig.isShowVibrate();
exitAnime = mnScanConfig.getActivityExitAnime();
Expand All @@ -307,6 +308,9 @@ private void initIntent() {
viewfinderView.setLaserColor(Color.parseColor(scanColor));
}
viewfinderView.setLaserStyle(mnScanConfig.getLaserStyle());
if (!TextUtils.isEmpty(maskColor)) {
viewfinderView.setMaskColor(Color.parseColor(maskColor));
}
if (!mnScanConfig.isShowPhotoAlbum()) {
btn_photo.setVisibility(View.GONE);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ public void setLaserStyle(MNScanConfig.LaserStyle laserStyle) {
this.laserStyle = laserStyle;
}

/**
* 背景色
*
* @param maskColor
*/
public void setMaskColor(int maskColor) {
this.maskColor = maskColor;
}

/**
* 设置文案
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public enum LaserStyle {
private ZoomControllerLocation zoomControllerLocation = ZoomControllerLocation.Right;
//自定义View
private int customShadeViewLayoutID;
//扫描背景色
private String bgColor;

private MNScanConfig() {

Expand All @@ -70,6 +72,7 @@ private MNScanConfig(Builder builder) {
showZoomController = builder.showZoomController;
zoomControllerLocation = builder.zoomControllerLocation;
customShadeViewLayoutID = builder.customShadeViewLayoutID;
bgColor = builder.bgColor;
}

public LaserStyle getLaserStyle() {
Expand Down Expand Up @@ -160,6 +163,14 @@ public void setCustomShadeViewLayoutID(int customShadeViewLayoutID) {
this.customShadeViewLayoutID = customShadeViewLayoutID;
}

public String getBgColor() {
return bgColor;
}

public void setBgColor(String bgColor) {
this.bgColor = bgColor;
}

public static class Builder {
private boolean showPhotoAlbum = true;
private boolean showBeep = true;
Expand All @@ -172,6 +183,7 @@ public static class Builder {
private boolean showZoomController = true;
private ZoomControllerLocation zoomControllerLocation = ZoomControllerLocation.Right;
private int customShadeViewLayoutID;
private String bgColor;

public MNScanConfig builder() {
return new MNScanConfig(this);
Expand Down Expand Up @@ -233,6 +245,11 @@ public Builder setCustomShadeViewLayoutID(int customShadeViewLayoutID, MNCustomV
return this;
}

public Builder setBgColor(String bgColor) {
this.bgColor = bgColor;
return this;
}

}

}
2 changes: 1 addition & 1 deletion libraryzxing/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@
-->
<resources>
<color name="mn_scan_viewfinder_laser">#FFff3535</color>
<color name="mn_scan_viewfinder_mask">#96000000</color>
<color name="mn_scan_viewfinder_mask">#80000000</color>
</resources>

0 comments on commit 4f1e203

Please sign in to comment.