Skip to content

Commit

Permalink
完善Demo
Browse files Browse the repository at this point in the history
  • Loading branch information
maning0303 committed Dec 7, 2020
1 parent c6c9dc2 commit 035c692
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
10 changes: 8 additions & 2 deletions app/src/main/java/com/maning/zxingcodedemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity {
private ImageView imageView;
private EditText editText;
private CheckBox checkbox;
private CheckBox checkbox2;
private Spinner mSpColorBlack;
private Spinner mSpColorWhite;
private Spinner mSpMargin;
Expand All @@ -56,6 +57,7 @@ private void initView() {
imageView = (ImageView) findViewById(R.id.imageView);
editText = (EditText) findViewById(R.id.editText);
checkbox = (CheckBox) findViewById(R.id.checkbox);
checkbox2 = (CheckBox) findViewById(R.id.checkbox2);
mSpColorBlack = (Spinner) findViewById(R.id.sp_color_black);
mSpColorWhite = (Spinner) findViewById(R.id.sp_color_white);
mSpMargin = (Spinner) findViewById(R.id.sp_margin);
Expand Down Expand Up @@ -168,12 +170,16 @@ public void createQRImage(View view) {
return;
}

Bitmap qrImage;
Bitmap qrImage = null;
Bitmap logo = null;
Bitmap foreground_bitmap = null;
if (checkbox.isChecked()) {
logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
}
qrImage = ZXingUtils.createQRCodeImage(str, 500, margin, color_black, color_white, error_correction_level, logo);
if (checkbox2.isChecked()) {
foreground_bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.tmp);
}
qrImage = ZXingUtils.createQRCodeImage(str, 500, margin, color_black, color_white, error_correction_level, logo, foreground_bitmap);
if (qrImage != null) {
imageView.setImageBitmap(qrImage);
} else {
Expand Down
Binary file added app/src/main/res/drawable-xxhdpi/tmp.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 20 additions & 5 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,17 +61,32 @@

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="50dp"
android:hint="输入要生成二维码的文本"
android:textSize="15sp" />

</LinearLayout>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">

<CheckBox
android:id="@+id/checkbox"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.8"
android:hint="输入要生成二维码的文本" />
android:layout_weight="1"
android:text="中间Logo" />

<CheckBox
android:id="@+id/checkbox"
android:id="@+id/checkbox2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:text="Logo" />
android:layout_weight="1"
android:text="图片替代二维码" />

</LinearLayout>

Expand Down

0 comments on commit 035c692

Please sign in to comment.