Skip to content

Commit

Permalink
Merge pull request #5 from SumiMakito/develop
Browse files Browse the repository at this point in the history
Ver 1.0.2
  • Loading branch information
sumimakito authored May 2, 2017
2 parents bca53a3 + ef477a6 commit 4788ebe
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 67 deletions.
33 changes: 21 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ Example 1|Example 2|Example 3
------------ | ------------- | -------------
<img src="art/awesome-qr-1.png" width="400"> | <img src="art/awesome-qr-2.png" width="400"> | <img src="art/awesome-qr-3.png" width="400">


Rounded data dots|Binarized background
------------ | -------------
<img src="art/awesome-qr-4.png" width="400"> | <img src="art/awesome-qr-5.png" width="400">

### Add dependency, 添加依赖项

Add below lines in build.gradle of your project:
Expand All @@ -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'
}
```

Expand All @@ -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.

Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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() {
Expand Down Expand Up @@ -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()),
Expand All @@ -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();
Expand All @@ -141,6 +143,8 @@ public void onClick(View v) {
startActivity(i);
}
});

btGenerate.callOnClick();
}

@Override
Expand Down Expand Up @@ -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();
Expand All @@ -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() {
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,11 @@
android:maxLines="1"
android:singleLine="true" />

<CheckBox
android:id="@+id/rounded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Rounded data dots" />

<CheckBox
android:id="@+id/autoColor"
Expand Down
Binary file added art/awesome-qr-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added art/awesome-qr-5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
versionCode 3
versionName "1.0.2"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Loading

0 comments on commit 4788ebe

Please sign in to comment.