diff --git a/README.md b/README.md
index 6541acf..f70df36 100644
--- a/README.md
+++ b/README.md
@@ -16,6 +16,11 @@ Example 1|Example 2|Example 3
------------ | ------------- | -------------
| |
+
+Rounded data dots|Binarized background
+------------ | -------------
+ |
+
### Add dependency, 添加依赖项
Add below lines in build.gradle of your project:
@@ -31,7 +36,7 @@ allprojects {
Then, add below lines in build.gradle of your app module:
```
dependencies {
- compile 'com.github.SumiMakito:AwesomeQRCode:1.0.0'
+ compile 'com.github.SumiMakito:AwesomeQRCode:1.0.2'
}
```
@@ -45,22 +50,26 @@ Bitmap qrCode = AwesomeQRCode.create("Makito loves Kafuu Chino.", 800, 20, 0.3f,
```java
public static Bitmap create(
- String contents, // Contents to encode. 欲编码的内容
- int size, // Width as well as the height of the output QR code, includes margin. 尺寸, 长宽一致
- int margin, // Margin to add around the QR code. 二维码边缘的外边距
- float dataDotScale, // Scale the data blocks and makes them appear smaller. 数据点缩小比例 (0 < scale < 1.0f)
- int colorDark, // Color of blocks. Will be OVERRIDE by autoColor. (BYTE_DTA, BYTE_POS, BYTE_AGN, BYTE_TMG) 实点的颜色
- int colorLight, // Color of empty space. Will be OVERRIDE by autoColor. (BYTE_EPT) 空白点的颜色
- Bitmap backgroundImage, // The background image to embed in the QR code. If null, no background image will be embedded. 欲嵌入的背景图
- boolean whiteMargin, // If true, background image will not be drawn on the margin area. Default is true. 若为 true, 则背景图将不会绘制到外边距区域
- boolean autoColor, // If true, colorDark will be set to the dominant color of backgroundImage. Default is true. 若为 true, 则将从背景图取主要颜色作为实点颜色
- boolean binarize, // If true, background images will be binarized. Default is false. 若为 true, 背景图像将被二值化处理
- int binarizeThreshold // Threshold value used while binarizing background images. Default is 128. 0 < threshold < 255. 控制背景图像二值化的阈值
+ String contents, // Contents to encode. 欲编码的内容
+ int size, // Width as well as the height of the output QR code, includes margin. 尺寸, 长宽一致
+ int margin, // Margin to add around the QR code. 二维码边缘的外边距
+ float dataDotScale, // Scale the data blocks and makes them appear smaller. 数据点缩小比例 (0 < scale < 1.0f)
+ int colorDark, // Color of blocks. Will be OVERRIDE by autoColor. (BYTE_DTA, BYTE_POS, BYTE_AGN, BYTE_TMG) 实点的颜色
+ int colorLight, // Color of empty space. Will be OVERRIDE by autoColor. (BYTE_EPT) 空白点的颜色
+ Bitmap backgroundImage, // The background image to embed in the QR code. If null, no background image will be embedded. 欲嵌入的背景图
+ boolean whiteMargin, // If true, background image will not be drawn on the margin area. Default is true. 若为 true, 则背景图将不会绘制到外边距区域
+ boolean autoColor, // If true, colorDark will be set to the dominant color of backgroundImage. Default is true. 若为 true, 则将从背景图取主要颜色作为实点颜色
+ boolean binarize, // If true, background images will be binarized. Default is false. 若为 true, 背景图像将被二值化处理
+ int binarizeThreshold, // Threshold value used while binarizing background images. Default is 128. 0 < threshold < 255. 控制背景图像二值化的阈值
+ boolean roundedDataDots // If true, data blocks will appear as filled circles. Default is false. 若为 true, 数据点将以圆形绘制
) throws IllegalArgumentException { ... }
```
### Changelog, 更新日志
+#### 1.0.2
+Added an optional parameter which enables the data dots to appear as filled circles.
+
#### 1.0.1
Now background images can be binarized as you like.
diff --git a/app/build.gradle b/app/build.gradle
index d2738b6..ad3297d 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -7,8 +7,8 @@ android {
applicationId "com.github.sumimakito.awesomeqrsample"
minSdkVersion 19
targetSdkVersion 25
- versionCode 4
- versionName "1.3"
+ versionCode 5
+ versionName "1.4"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
diff --git a/app/src/main/java/com/github/sumimakito/awesomeqrsample/MainActivity.java b/app/src/main/java/com/github/sumimakito/awesomeqrsample/MainActivity.java
index fc6f62c..a805898 100644
--- a/app/src/main/java/com/github/sumimakito/awesomeqrsample/MainActivity.java
+++ b/app/src/main/java/com/github/sumimakito/awesomeqrsample/MainActivity.java
@@ -41,6 +41,7 @@ public class MainActivity extends AppCompatActivity {
private EditText etDotScale;
private TextView tvJSHint;
private CheckBox ckbBinarize;
+ private CheckBox ckbRoundedDataDots;
private EditText etBinarizeThreshold;
@Override
@@ -63,7 +64,8 @@ protected void onCreate(Bundle savedInstanceState) {
btGenerate = (Button) findViewById(R.id.generate);
ckbWhiteMargin = (CheckBox) findViewById(R.id.whiteMargin);
ckbAutoColor = (CheckBox) findViewById(R.id.autoColor);
- ckbBinarize= (CheckBox) findViewById(R.id.binarize);
+ ckbBinarize = (CheckBox) findViewById(R.id.binarize);
+ ckbRoundedDataDots = (CheckBox) findViewById(R.id.rounded);
etBinarizeThreshold = (EditText) findViewById(R.id.binarizeThreshold);
ckbAutoColor.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@@ -103,7 +105,6 @@ public void onClick(View v) {
@Override
public void onClick(View v) {
try {
-
generate(etContents.getText().length() == 0 ? "Makito loves Kafuu Chino." : etContents.getText().toString(),
etSize.getText().length() == 0 ? 800 : Integer.parseInt(etSize.getText().toString()),
etMargin.getText().length() == 0 ? 20 : Integer.parseInt(etMargin.getText().toString()),
@@ -114,7 +115,8 @@ public void onClick(View v) {
ckbWhiteMargin.isChecked(),
ckbAutoColor.isChecked(),
ckbBinarize.isChecked(),
- etBinarizeThreshold.getText().length() == 0 ? 128 : Integer.parseInt(etBinarizeThreshold.getText().toString())
+ etBinarizeThreshold.getText().length() == 0 ? 128 : Integer.parseInt(etBinarizeThreshold.getText().toString()),
+ ckbRoundedDataDots.isChecked()
);
} catch (Exception e) {
Toast.makeText(MainActivity.this, "Error occurred, please check your configs.", Toast.LENGTH_LONG).show();
@@ -141,6 +143,8 @@ public void onClick(View v) {
startActivity(i);
}
});
+
+ btGenerate.callOnClick();
}
@Override
@@ -183,7 +187,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
private void generate(final String contents, final int size, final int margin, final float dotScale,
final int colorDark, final int colorLight, final Bitmap background, final boolean whiteMargin,
- final boolean autoColor, final boolean binarize, final int binarizeThreshold) {
+ final boolean autoColor, final boolean binarize, final int binarizeThreshold, final boolean roundedDD) {
if (generating) return;
generating = true;
progressDialog = new ProgressDialog.Builder(this).setMessage("Generating...").setCancelable(false).create();
@@ -192,7 +196,9 @@ private void generate(final String contents, final int size, final int margin, f
@Override
public void run() {
try {
- final Bitmap b = AwesomeQRCode.create(contents, size, margin, dotScale, colorDark, colorLight, background, whiteMargin, autoColor, binarize, binarizeThreshold);
+ final Bitmap b = AwesomeQRCode.create(contents, size, margin, dotScale, colorDark,
+ colorLight, background, whiteMargin, autoColor, binarize, binarizeThreshold,
+ roundedDD);
runOnUiThread(new Runnable() {
@Override
public void run() {
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 684b412..468b0eb 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -149,6 +149,11 @@
android:maxLines="1"
android:singleLine="true" />
+
1) {
throw new IllegalArgumentException("Error: an illegal data dot scale is given. (dataDotScale < 0 || dataDotScale > 1)");
}
- return render(byteMatrix, size - 2 * margin, margin, dataDotScale, colorDark, colorLight, backgroundImage, whiteMargin, autoColor, binarize, binarizeThreshold);
+ return render(byteMatrix, size - 2 * margin, margin, dataDotScale, colorDark, colorLight, backgroundImage, whiteMargin, autoColor, binarize, binarizeThreshold, roundedDataDots);
}
- private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int margin, float dataDotScale, int colorDark, int colorLight, Bitmap backgroundImage, boolean whiteMargin, boolean autoColor, boolean binarize, int binarizeThreshold) {
+ private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int margin, float dataDotScale,
+ int colorDark, int colorLight, Bitmap backgroundImage, boolean whiteMargin,
+ boolean autoColor, boolean binarize, int binarizeThreshold, boolean roundedDataDots) {
int nCount = byteMatrix.getWidth();
float nWidth = (float) innerRenderedSize / nCount;
float nHeight = (float) innerRenderedSize / nCount;
@@ -143,12 +160,15 @@ private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int m
Paint paintDark = new Paint();
paintDark.setColor(colorDark);
paintDark.setAntiAlias(true);
+ paintDark.setStyle(Paint.Style.FILL);
Paint paintLight = new Paint();
paintLight.setColor(colorLight);
paintLight.setAntiAlias(true);
+ paintLight.setStyle(Paint.Style.FILL);
Paint paintProtector = new Paint();
paintProtector.setColor(Color.argb(120, 255, 255, 255));
paintProtector.setAntiAlias(true);
+ paintProtector.setStyle(Paint.Style.FILL);
Canvas canvas = new Canvas(renderedBitmap);
canvas.drawColor(Color.WHITE);
@@ -156,7 +176,6 @@ private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int m
for (int row = 0; row < byteMatrix.getHeight(); row++) {
- String s = "";
for (int col = 0; col < byteMatrix.getWidth(); col++) {
switch (byteMatrix.get(col, row)) {
case BYTE_AGN:
@@ -169,17 +188,24 @@ private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int m
margin + (row + 1.0f) * nHeight,
paintDark
);
- s += "X";
break;
case BYTE_DTA:
- canvas.drawRect(
- margin + (col + 0.5f * (1 - dataDotScale)) * nWidth,
- margin + (row + 0.5f * (1 - dataDotScale)) * nHeight,
- margin + (col + 0.5f * (1 + dataDotScale)) * nWidth,
- margin + (row + 0.5f * (1 + dataDotScale)) * nHeight,
- paintDark
- );
- s += "〇";
+ if (roundedDataDots) {
+ canvas.drawCircle(
+ margin + (col + 0.5f) * nWidth,
+ margin + (row + 0.5f) * nHeight,
+ dataDotScale * nHeight * 0.5f,
+ paintDark
+ );
+ } else {
+ canvas.drawRect(
+ margin + (col + 0.5f * (1 - dataDotScale)) * nWidth,
+ margin + (row + 0.5f * (1 - dataDotScale)) * nHeight,
+ margin + (col + 0.5f * (1 + dataDotScale)) * nWidth,
+ margin + (row + 0.5f * (1 + dataDotScale)) * nHeight,
+ paintDark
+ );
+ }
break;
case BYTE_PTC:
canvas.drawRect(
@@ -189,21 +215,27 @@ private static Bitmap render(ByteMatrix byteMatrix, int innerRenderedSize, int m
margin + (row + 1.0f) * nHeight,
paintProtector
);
- s += "+";
break;
case BYTE_EPT:
- canvas.drawRect(
- margin + (col + 0.5f * (1 - dataDotScale)) * nWidth,
- margin + (row + 0.5f * (1 - dataDotScale)) * nHeight,
- margin + (col + 0.5f * (1 + dataDotScale)) * nWidth,
- margin + (row + 0.5f * (1 + dataDotScale)) * nHeight,
- paintLight
- );
- s += " ";
+ if (roundedDataDots) {
+ canvas.drawCircle(
+ margin + (col + 0.5f) * nWidth,
+ margin + (row + 0.5f) * nHeight,
+ dataDotScale * nHeight * 0.5f,
+ paintLight
+ );
+ } else {
+ canvas.drawRect(
+ margin + (col + 0.5f * (1 - dataDotScale)) * nWidth,
+ margin + (row + 0.5f * (1 - dataDotScale)) * nHeight,
+ margin + (col + 0.5f * (1 + dataDotScale)) * nWidth,
+ margin + (row + 0.5f * (1 + dataDotScale)) * nHeight,
+ paintLight
+ );
+ }
break;
}
}
- Log.d("QR_MAPPING", s);
}
return renderedBitmap;