Skip to content

Commit

Permalink
New Pull Request added, Minimum support from 14, Target Version incre…
Browse files Browse the repository at this point in the history
…ase and Android X support included
  • Loading branch information
androidmads committed Dec 30, 2019
1 parent 825d068 commit c7f64fe
Show file tree
Hide file tree
Showing 14 changed files with 266 additions and 121 deletions.
116 changes: 116 additions & 0 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 1 addition & 11 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions QRGenearator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ apply plugin: 'com.jfrog.bintray'
apply plugin: 'com.github.dcendents.android-maven'

group = 'androidmads.library.qrgenearator' // Change this to match your package name
version = '1.0.3' // Change this to match your version number
version = '1.0.4' // Change this to match your version number

android {
compileSdkVersion 25
buildToolsVersion "25.0.2"
compileSdkVersion 28
buildToolsVersion "28.0.3"

defaultConfig {
minSdkVersion 15
targetSdkVersion 25
minSdkVersion 14
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
Expand All @@ -24,7 +24,7 @@ android {
}

dependencies {
compile 'com.google.zxing:core:3.2.0'
implementation 'com.google.zxing:core:3.2.0'
}

Properties properties = new Properties()
Expand All @@ -38,10 +38,10 @@ bintray {
name = 'androidmads.library.qrgenearator'

version {
name = '1.0.3'
name = '1.0.4'
desc = 'QR Generator Library'
released = new Date()
vcsTag = '1.0.3'
vcsTag = '1.0.4'
}

licenses = ['Apache-2.0']
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class QRGContents {
public static final class ImageType {
public static int IMAGE_PNG = 0;
public static int IMAGE_JPEG = 1;
public static int IMAGE_WEBP = 2;
}

public static final class Type {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.google.zxing.BarcodeFormat;
import com.google.zxing.EncodeHintType;
import com.google.zxing.MultiFormatWriter;
import com.google.zxing.WriterException;
import com.google.zxing.common.BitMatrix;

import java.util.Collection;
Expand All @@ -21,31 +20,38 @@ public class QRGEncoder {

private int WHITE = 0xFFFFFFFF;
private int BLACK = 0xFF000000;


private int dimension = Integer.MIN_VALUE;
private String contents = null;
private String displayContents = null;
private String title = null;
private BarcodeFormat format = null;
private boolean encoded = false;

public void setColorWhite(int color){
this.WHITE=color
public void setColorWhite(int color) {
this.WHITE = color;
}
public void setColorBlack(int color){
this.BLACK=color

public void setColorBlack(int color) {
this.BLACK = color;
}
public int getColorWhite(){

public int getColorWhite() {
return this.WHITE;
}

public int getColorBlack(){
return this.Black;

public int getColorBlack() {
return this.BLACK;
}

public QRGEncoder(String data, String type) {
encoded = encodeContents(data, null, QRGContents.Type.TEXT);
}

public QRGEncoder(String data, String type, int dimension) {
this.dimension = dimension;
encoded = encodeContents(data, null, QRGContents.Type.TEXT);
}

public QRGEncoder(String data, Bundle bundle, String type, int dimension) {
this.dimension = dimension;
encoded = encodeContents(data, bundle, type);
Expand Down Expand Up @@ -107,17 +113,17 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
StringBuilder newContents = new StringBuilder(100);
StringBuilder newDisplayContents = new StringBuilder(100);

newContents.append("MECARD:");
newContents.append("VCARD:");

String name = trim(bundle.getString(ContactsContract.Intents.Insert.NAME));
if (name != null) {
newContents.append("N:").append(escapeMECARD(name)).append(';');
newContents.append("N:").append(escapeVCard(name)).append(';');
newDisplayContents.append(name);
}

String address = trim(bundle.getString(ContactsContract.Intents.Insert.POSTAL));
if (address != null) {
newContents.append("ADR:").append(escapeMECARD(address)).append(';');
newContents.append("ADR:").append(escapeVCard(address)).append(';');
newDisplayContents.append('\n').append(address);
}

Expand All @@ -129,7 +135,7 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
}
}
for (String phone : uniquePhones) {
newContents.append("TEL:").append(escapeMECARD(phone)).append(';');
newContents.append("TEL:").append(escapeVCard(phone)).append(';');
//noinspection deprecation
newDisplayContents.append('\n').append(PhoneNumberUtils.formatNumber(phone));
}
Expand All @@ -142,20 +148,20 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
}
}
for (String email : uniqueEmails) {
newContents.append("EMAIL:").append(escapeMECARD(email)).append(';');
newContents.append("EMAIL:").append(escapeVCard(email)).append(';');
newDisplayContents.append('\n').append(email);
}

String url = trim(bundle.getString(QRGContents.URL_KEY));
if (url != null) {
// escapeMECARD(url) -> wrong escape e.g. http\://zxing.google.com
// escapeVCard(url) -> wrong escape e.g. http\://zxing.google.com
newContents.append("URL:").append(url).append(';');
newDisplayContents.append('\n').append(url);
}

String note = trim(bundle.getString(QRGContents.NOTE_KEY));
if (note != null) {
newContents.append("NOTE:").append(escapeMECARD(note)).append(';');
newContents.append("NOTE:").append(escapeVCard(note)).append(';');
newDisplayContents.append('\n').append(note);
}

Expand Down Expand Up @@ -187,34 +193,37 @@ private void encodeQRCodeContents(String data, Bundle bundle, String type) {
}
}

public Bitmap encodeAsBitmap() throws WriterException {
public Bitmap getBitmap() {
if (!encoded) return null;

Map<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contents);
if (encoding != null) {
hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
// All are 0, or black, by default
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? getColorBlack() : getColorWhite();
try {
Map<EncodeHintType, Object> hints = null;
String encoding = guessAppropriateEncoding(contents);
if (encoding != null) {
hints = new EnumMap<>(EncodeHintType.class);
hints.put(EncodeHintType.CHARACTER_SET, encoding);
}
MultiFormatWriter writer = new MultiFormatWriter();
BitMatrix result = writer.encode(contents, format, dimension, dimension, hints);
int width = result.getWidth();
int height = result.getHeight();
int[] pixels = new int[width * height];
// All are 0, or black, by default
for (int y = 0; y < height; y++) {
int offset = y * width;
for (int x = 0; x < width; x++) {
pixels[offset + x] = result.get(x, y) ? getColorBlack() : getColorWhite();
}
}
}

Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
bitmap.setPixels(pixels, 0, width, 0, 0, width, height);
return bitmap;
} catch (Exception ex) {
return null;
}
}

private static String guessAppropriateEncoding(CharSequence contents) {
private String guessAppropriateEncoding(CharSequence contents) {
// Very crude at the moment
for (int i = 0; i < contents.length(); i++) {
if (contents.charAt(i) > 0xFF) {
Expand All @@ -224,15 +233,15 @@ private static String guessAppropriateEncoding(CharSequence contents) {
return null;
}

private static String trim(String s) {
private String trim(String s) {
if (s == null) {
return null;
}
String result = s.trim();
return result.length() == 0 ? null : result;
}

private static String escapeMECARD(String input) {
private String escapeVCard(String input) {
if (input == null || (input.indexOf(':') < 0 && input.indexOf(';') < 0)) {
return input;
}
Expand Down
Loading

0 comments on commit c7f64fe

Please sign in to comment.