Skip to content

Commit

Permalink
更新demo和apk
Browse files Browse the repository at this point in the history
  • Loading branch information
yuzhiqiang1993 committed Apr 4, 2018
1 parent 1e98a5c commit a352370
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 6 deletions.
Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ dependencies {
implementation "com.android.support:support-vector-drawable:$support_version"
implementation 'com.yanzhenjie:permission:2.0.0-rc4'
//implementation project(':zxinglibrary')
implementation 'com.github.yuzhiqiang1993:zxing:2.1.5'
implementation 'com.github.yuzhiqiang1993:zxing:2.1.6'


}
Binary file modified app/release/zxing.apk
Binary file not shown.
48 changes: 44 additions & 4 deletions app/src/main/java/com/yzq/zxing/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.yzq.zxing;

import android.Manifest;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.Settings;
Expand Down Expand Up @@ -43,6 +43,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private ImageView contentIv;
private Toolbar toolbar;
private int REQUEST_CODE_SCAN = 111;
/**
* 生成带logo的二维码
*/
private Button encodeBtnWithLogo;
private ImageView contentIvWithLogo;
private String contentEtString;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -74,10 +80,21 @@ private void initView() {
getSupportActionBar().setDisplayHomeAsUpEnabled(true);


toolbar = (Toolbar) findViewById(R.id.toolbar);
result = (TextView) findViewById(R.id.result);
scanBtn = (Button) findViewById(R.id.scanBtn);
contentEt = (EditText) findViewById(R.id.contentEt);
encodeBtnWithLogo = (Button) findViewById(R.id.encodeBtnWithLogo);
encodeBtnWithLogo.setOnClickListener(this);
contentIvWithLogo = (ImageView) findViewById(R.id.contentIvWithLogo);
encodeBtn = (Button) findViewById(R.id.encodeBtn);
contentIv = (ImageView) findViewById(R.id.contentIv);
}

@Override
public void onClick(View v) {

Bitmap bitmap = null;
switch (v.getId()) {
case R.id.scanBtn:

Expand Down Expand Up @@ -116,15 +133,16 @@ public void onAction(List<String> permissions) {

break;
case R.id.encodeBtn:
String contentEtString = contentEt.getText().toString().trim();
contentEtString = contentEt.getText().toString().trim();
if (TextUtils.isEmpty(contentEtString)) {
Toast.makeText(this, "contentEtString不能为空", Toast.LENGTH_SHORT).show();
Toast.makeText(this, "请输入要生成二维码图片的字符串", Toast.LENGTH_SHORT).show();
return;
}

Bitmap bitmap = null;

try {
bitmap = CodeCreator.createQRCode(contentEtString, 400, 400, null);

} catch (WriterException e) {
e.printStackTrace();
}
Expand All @@ -134,6 +152,28 @@ public void onAction(List<String> permissions) {

break;

case R.id.encodeBtnWithLogo:

contentEtString = contentEt.getText().toString().trim();
if (TextUtils.isEmpty(contentEtString)) {
Toast.makeText(this, "请输入要生成二维码图片的字符串", Toast.LENGTH_SHORT).show();
return;
}

bitmap = null;
try {
Bitmap logo = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
bitmap = CodeCreator.createQRCode(contentEtString, 400, 400, logo);

} catch (WriterException e) {
e.printStackTrace();
}
if (bitmap != null) {
contentIvWithLogo.setImageBitmap(bitmap);
}

break;

default:
}
}
Expand Down
20 changes: 19 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,26 @@
android:layout_width="match_parent"
android:layout_height="56dp" />

<Button
android:id="@+id/encodeBtnWithLogo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="生成带logo的二维码" />


<ImageView
android:id="@+id/contentIvWithLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"

/>

<Button
android:id="@+id/encodeBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="生成二维码" />
android:text="生成不带logo的二维码" />


<ImageView
Expand All @@ -55,4 +70,7 @@

/>




</LinearLayout>

0 comments on commit a352370

Please sign in to comment.