Commit 5ba69692 authored by pengguangpu's avatar pengguangpu

测试aar包混淆,添加简化方法

parent b18f38db
......@@ -27,9 +27,9 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//打印sdk
api project(':print')
// api project(':print')
//称重sdk
api project(':weighing')
// implementation files('libs/weighing-release.aar')
implementation files('libs/miya-print-1.aar')
}
......@@ -169,7 +169,8 @@ public class PrintActivity extends Activity implements View.OnClickListener {
case R.id.btnBarcode:
if (PrinterManager.getInstance().isConnected()) {
try {
PrinterManager.getInstance().getPrinter().printBarcode(-1, etBarcode.getText().toString(), false);
// PrinterManager.getInstance().getPrinter().printBarcode(-1, etBarcode.getText().toString(), false);
PrinterManager.getInstance().getPrinter().printBarcode(IPrinter.ALIGN_CENTER, "http://60.2717.64.173:18080/Wrapper/jump.do?type=1/jump.do?type=3&orderno=51153001809100005&sjm=1455", false);
} catch (Exception ex) {
ex.printStackTrace();
tvResult.setText(ex.getMessage());
......
apply plugin: 'com.android.library'
//获取生成的产品名
def getSDKName() {
return "miya-print"
}
android {
compileSdkVersion 28
defaultConfig {
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
versionName "1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
......@@ -18,6 +21,7 @@ android {
buildTypes {
release {
minifyEnabled false
debuggable true
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
......@@ -28,6 +32,11 @@ android {
}
}
android.libraryVariants.all { variant ->
variant.outputs.all {
outputFileName = getSDKName() + "-${defaultConfig.versionName}" + '.aar'
}
}
}
dependencies {
......@@ -38,9 +47,6 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
//一些工具类集合,从主工程拷贝过来的
// implementation 'com.blankj:utilcode:1.16.0'
//zxing
implementation files('libs/core-3.3.0.jar')
......
......@@ -113,4 +113,28 @@ public abstract class BasePrinter implements IPrinter {
return this.name;
}
@Override
public int printText(String content) {
return printText(-1, 0, content, true);
}
@Override
public int printImageFast(Bitmap bm) {
return 0;
}
@Override
public int printImage(Bitmap bm) {
return printImage(-1, bm, true);
}
@Override
public int printBarcode(String content) {
return printBarcode(-1, content, true);
}
@Override
public int printQrcode(String content) {
return printQrcode(-1, content, true);
}
}
......@@ -12,7 +12,7 @@ import android.text.TextUtils;
import android.util.Log;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
import com.miya.print.utils.ImageUtils;
import com.printsdk.cmd.PrintCmd;
import com.printsdk.usbsdk.UsbDriver;
......@@ -43,7 +43,7 @@ public class ChuangjiePrinter extends BasePrinter {
@Override
public boolean init(Context context) {
D.i(TAG, "开始初始化创捷打印机");
PrintLogger.i(TAG, "开始初始化创捷打印机");
this.context = context;
if (mUsbDriver == null) {
getUsbDriverService(context);
......@@ -93,7 +93,7 @@ public class ChuangjiePrinter extends BasePrinter {
mUsbDriver = null;
context = null;
}
D.i(TAG, "创捷打印资源已关闭");
PrintLogger.i(TAG, "创捷打印资源已关闭");
return true;
}
......@@ -265,11 +265,11 @@ public class ChuangjiePrinter extends BasePrinter {
actualBm = BitmapUtils.scaleBitmap(bm, MAX_IMG_WIDTH_80MM, 0);
ret = printQrcodeBitmap(actualBm);
} else {
if (align == 1) {
if (this.align == 1) {
//如果是居中打印,则拼接白色左边距
actualBm = BitmapUtils.addWhiteLeftMargin(bm, (MAX_IMG_WIDTH_80MM - bm.getWidth()) / 2);
ret = printQrcodeBitmap(actualBm);
} else if (align == 2) {
} else if (this.align == 2) {
//居右打印
actualBm = BitmapUtils.addWhiteLeftMargin(bm, MAX_IMG_WIDTH_80MM - bm.getWidth());
ret = printQrcodeBitmap(actualBm);
......@@ -299,13 +299,13 @@ public class ChuangjiePrinter extends BasePrinter {
//创捷机器打印二维码不能通过setAlign实现居中,永远会居左打印
if (this.align == 0) {
//居左打印
ret = printQrcode(content, 0, 8, 1);
ret = printQrcode(content, 0, 6, 1);
} else if (this.align == 1) {
//居中打印
ret = printQrcode(content, 24, 8, 1);
ret = printQrcode(content, 24, 6, 1);
} else if (this.align == 2) {
//居右
ret = printQrcode(content, 24, 8, 1);
ret = printQrcode(content, 24, 6, 1);
}
if (isFeed) {
ret = feedPaper();
......@@ -465,11 +465,11 @@ public class ChuangjiePrinter extends BasePrinter {
} else {//USB打印机
mUsbDev2 = device;
mUsbDev = mUsbDev2;
D.i(TAG, "USB连接成功");
PrintLogger.i(TAG, "USB连接成功");
break;
}
} else {
D.i(TAG, "USB连接失败");
PrintLogger.i(TAG, "USB连接失败");
break;
}
}
......
......@@ -10,11 +10,10 @@ import android.os.RemoteException;
import android.text.TextUtils;
import com.hisense.hs650service.aidl.HS650Api;
import com.hisense.hs650service.aidl.Printer;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.AccumulateUtils;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
public class HisensePrinter extends BasePrinter {
......@@ -51,16 +50,16 @@ public class HisensePrinter extends BasePrinter {
hs650Api = HS650Api.Stub.asInterface(service);
if (hs650Api == null) {
//连接打印进程服务失败
D.e(TAG, "连接海信打印进程服务失败");
PrintLogger.e(TAG, "连接海信打印进程服务失败");
} else {
D.i(TAG, "连接海信打印进程服务成功");
PrintLogger.i(TAG, "连接海信打印进程服务成功");
}
try {
initPrinter();
D.i(TAG, "海信打印机初始化成功");
PrintLogger.i(TAG, "海信打印机初始化成功");
} catch (Exception ex) {
ex.printStackTrace();
D.e(TAG, "海信打印机初始化失败");
PrintLogger.e(TAG, "海信打印机初始化失败");
}
}
......@@ -72,7 +71,7 @@ public class HisensePrinter extends BasePrinter {
@Override
public boolean init(Context context) {
D.i(TAG, "开始初始化海信打印机");
PrintLogger.i(TAG, "开始初始化海信打印机");
this.context = context.getApplicationContext();
Intent intent = new Intent();
intent.setPackage(SERVICE_PACKAGE);
......@@ -80,21 +79,20 @@ public class HisensePrinter extends BasePrinter {
// context.getApplicationContext().startService(intent);
boolean result = this.context.bindService(intent, serviceConnection, Context.BIND_AUTO_CREATE);
if (result == false) {
D.e(TAG, "海信打印机服务连接失败");
PrintLogger.e(TAG, "海信打印机服务连接失败");
} else {
D.i(TAG, "海信打印机服务连接成功");
PrintLogger.i(TAG, "海信打印机服务连接成功");
}
return result;
}
@Override
public boolean release() {
checkService();
try {
hs650Api.getPrinter().closePrinter();
} catch (RemoteException e) {
} catch (Exception e) {
e.printStackTrace();
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.status, e.getMessage());
return false;
}
return true;
}
......@@ -400,14 +398,14 @@ public class HisensePrinter extends BasePrinter {
}
}
/**
* 默认居中 正常大小
*
* @param content
*/
public void printText(String content) {
printText(content, 0, 1);
}
// /**
// * 默认居中 正常大小
// *
// * @param content
// */
// public void printText(String content) {
// printText(content, 0, 1);
// }
/**
* 强制打印机走纸一行
......
......@@ -146,4 +146,44 @@ public interface IPrinter {
* @return 打印机器名称
*/
String getPrinterName();
/**
* 按当前对齐方式打印文字,内部默认走纸一行,按照当前字符大小打印
*
* @param content 待打印文字
* @return 状态码(参考状态码枚举)
*/
int printText(String content);
/**
* 按当前对齐方式打印图片
*
* @param bm 待打印图片
* @return 状态码(参考状态码枚举)
*/
int printImage(Bitmap bm);
/**
* 按当前对齐方式打印条码(部分打印机可能强制居中打印)
*
* @param content 待打印二维码内容
* @return 状态码(参考状态码枚举)
*/
int printBarcode(String content);
/**
* 按当前对齐方式打印二维码(部分打印机可能强制居中打印或不支持居右打印)
*
* @param content 待打印二维码内容
* @return 状态码(参考状态码枚举)
*/
int printQrcode(String content);
/**
* 按当前对齐方式打印图片,内部默认走纸一行,同时调整图片大小为合适大小(可能会缩放)进行快速打印
*
* @param bm 待打印图片
* @return 状态码(参考状态码枚举)
*/
int printImageFast(Bitmap bm);
}
\ No newline at end of file
......@@ -2,8 +2,7 @@ package com.miya.print;
import android.content.Context;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
/**
* 打印机管理者
......@@ -15,7 +14,7 @@ public class PrinterManager {
/**
* 设备类型枚举,用于轮询过程中的反射
*/
enum Type {
public enum Type {
//这里添加扩展的驱动
TYPE_HISENSE("hisense", HisensePrinter.class.getName()),
TYPE_SUNMI_TI("sunmiT1", SunmiT1Printer.class.getName()),
......@@ -28,12 +27,12 @@ public class PrinterManager {
/**
* 设备类型名称
*/
String typeName;
public String typeName;
/**
* 设备驱动类全类名
*/
String clsName;
public String clsName;
Type(String typeName, String clsName) {
this.typeName = typeName;
......@@ -84,7 +83,7 @@ public class PrinterManager {
boolean result = printer.init(context);
if (result == true) {
printer.setPrinterName(type.typeName);
D.i(TAG, "初始化打印机成功,打印机器为:" + type.typeName);
PrintLogger.i(TAG, "初始化打印机成功,打印机器为:" + type.typeName);
return true;
}
} catch (Exception e) {
......@@ -101,7 +100,7 @@ public class PrinterManager {
}
printer = null;
}
D.i(TAG, "没找到对应的打印机器,请检查");
PrintLogger.i(TAG, "没找到对应的打印机器,请检查");
return false;
}
......@@ -155,7 +154,7 @@ public class PrinterManager {
boolean result = printer.init(context);
if (result == true) {
printer.setPrinterName(type.typeName);
D.i(TAG, "初始化打印机成功,打印机器为:" + type.typeName);
PrintLogger.i(TAG, "初始化打印机成功,打印机器为:" + type.typeName);
}
return result;
} catch (Exception e) {
......
......@@ -2,11 +2,10 @@ package com.miya.print;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Printer;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
import com.miya.print.utils.PrintFormatUtils;
import com.szsicod.print.escpos.PrinterAPI;
import com.szsicod.print.io.InterfaceAPI;
......@@ -16,7 +15,6 @@ import java.io.File;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;
import java.util.List;
/**
* 桑达机器打印驱动
......@@ -30,7 +28,7 @@ public class SangdaPrinter extends BasePrinter {
@Override
public boolean init(Context context) {
D.i(TAG, "开始初始化桑达打印机");
PrintLogger.i(TAG, "开始初始化桑达打印机");
super.init(context);
mPrinter = PrinterAPI.getInstance();
if (isConnect()) {
......@@ -39,16 +37,16 @@ public class SangdaPrinter extends BasePrinter {
try {
io = new SerialAPI(new File("/dev/ttyS1"), 38400, 0);
if (PrinterAPI.SUCCESS == mPrinter.connect(io)) {
D.i(TAG, "桑达打印机连接成功");
PrintLogger.i(TAG, "桑达打印机连接成功");
return true;
} else {
D.e(TAG, "桑达打印机连接失败");
PrintLogger.e(TAG, "桑达打印机连接失败");
return false;
}
} catch (Exception e) {
e.printStackTrace();
}
D.e(TAG, "桑达打印机连接失败");
PrintLogger.e(TAG, "桑达打印机连接失败");
return false;
}
......@@ -200,7 +198,7 @@ public class SangdaPrinter extends BasePrinter {
if (mPrinter != null) {
mPrinter.disconnect();
mPrinter = null;
D.i(TAG, "桑达打印资源已经关闭");
PrintLogger.i(TAG, "桑达打印资源已经关闭");
}
}
......@@ -257,6 +255,7 @@ public class SangdaPrinter extends BasePrinter {
return PrinterStatusEnum.CODE_SUCCESS.status;
}
@Deprecated
public String getStatusDescribe() {
int status = mPrinter.getStatus();
Arrays.fill(statusList, 0);
......
......@@ -11,7 +11,7 @@ import android.os.RemoteException;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.BytesUtil;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
import com.miya.print.utils.ESCUtil;
import com.sunmi.extprinterservice.ExtPrinterService;
......@@ -34,18 +34,18 @@ class SunmiK1Printer extends BasePrinter {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
D.i(TAG, "商米K1服务连接成功");
PrintLogger.i(TAG, "商米K1服务连接成功");
extPrinterService = ExtPrinterService.Stub.asInterface(service);
try {
int ret = extPrinterService.printerInit();
if (ret == 0) {
D.i(TAG, "商米K1服务printerInit成功");
PrintLogger.i(TAG, "商米K1服务printerInit成功");
} else {
D.i(TAG, "商米K1服务printerInit失败");
PrintLogger.i(TAG, "商米K1服务printerInit失败");
}
} catch (RemoteException e) {
e.printStackTrace();
D.i(TAG, "商米K1服务printerInit失败:" + e.getMessage());
PrintLogger.i(TAG, "商米K1服务printerInit失败:" + e.getMessage());
}
}
};
......@@ -53,7 +53,7 @@ class SunmiK1Printer extends BasePrinter {
@Override
public boolean init(Context context) {
D.i(TAG, "开始初始化商米K1打印机");
PrintLogger.i(TAG, "开始初始化商米K1打印机");
this.context = context;
Intent intent = new Intent();
intent.setPackage(SERVICE_PACKAGE);
......@@ -61,10 +61,10 @@ class SunmiK1Printer extends BasePrinter {
context.getApplicationContext().startService(intent);
boolean result = context.getApplicationContext().bindService(intent, connService, Context.BIND_AUTO_CREATE);
if (result == false) {
D.i(TAG, "商米K1打印机初始化失败");
PrintLogger.i(TAG, "商米K1打印机初始化失败");
return false;
}
D.i(TAG, "商米K1打印机初始化成功");
PrintLogger.i(TAG, "商米K1打印机初始化成功");
return true;
}
......
......@@ -9,12 +9,11 @@ import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.StringDef;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.BytesUtil;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
import com.miya.print.utils.ESCUtil;
import java.io.ByteArrayOutputStream;
......@@ -22,7 +21,6 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import woyou.aidlservice.jiuiv5.ICallback;
import woyou.aidlservice.jiuiv5.IWoyouService;
public class SunmiT1Printer extends BasePrinter {
......@@ -44,10 +42,10 @@ public class SunmiT1Printer extends BasePrinter {
context.getApplicationContext().startService(intent);
boolean result = context.getApplicationContext().bindService(intent, connService, Context.BIND_AUTO_CREATE);
if (result == false) {
D.i(TAG, "商米T1打印机初始化失败");
PrintLogger.i(TAG, "商米T1打印机初始化失败");
return false;
}
D.i(TAG, "商米T1打印机初始化成功");
PrintLogger.i(TAG, "商米T1打印机初始化成功");
return true;
}
......
......@@ -5,7 +5,7 @@ import android.graphics.Bitmap;
import com.miya.print.exception.PrinterException;
import com.miya.print.utils.BitmapUtils;
import com.miya.print.utils.D;
import com.miya.print.utils.PrintLogger;
import com.miya.print.utils.PrintFormatUtils;
import com.szsicod.print.escpos.PrinterAPI;
import com.szsicod.print.io.InterfaceAPI;
......@@ -26,16 +26,16 @@ public class YingtaiPrinter extends BasePrinter {
@Override
public boolean init(Context context) {
D.i(TAG,"开始初始化英泰打印机");
PrintLogger.i(TAG, "开始初始化英泰打印机");
this.context = context;
mPrinter = PrinterAPI.getInstance();
io = new USBAPI(context);
if (!io.isOpen().booleanValue()) {
if (PrinterAPI.SUCCESS == mPrinter.connect(io)) {
D.i(TAG, "英泰打印机连接成功");
PrintLogger.i(TAG, "英泰打印机连接成功");
return true;
} else {
D.e(TAG, "英泰打印机连接失败");
PrintLogger.e(TAG, "英泰打印机连接失败");
return false;
}
}
......@@ -70,6 +70,53 @@ public class YingtaiPrinter extends BasePrinter {
}
}
@Override
public int printText(String content) {
if (mPrinter != null) {
try {
int ret = mPrinter.printString(content, "GBK", true);
return ret;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), e.getMessage());
}
} else {
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), PrinterStatusEnum.CODE_FAILED.getDesc());
}
}
@Override
public int printQrcode(String content) {
if (mPrinter != null) {
int ret = mPrinter.printQRCode(content, 6, false);
ret = feedPaper();
return changeStatus2Custom(ret);
} else {
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), PrinterStatusEnum.CODE_FAILED.getDesc());
}
}
@Override
public int printBarcode(String content) {
if (mPrinter != null) {
try {
//通过printString传入打印指令实现条码的打印
int ret = mPrinter.printString(PrintFormatUtils.getBarcodeCmd(content), "GBK", true);
return ret;
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), e.getMessage());
}
} else {
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), PrinterStatusEnum.CODE_FAILED.getDesc());
}
}
@Override
public int printImage(Bitmap bm) {
return printImage(-1, bm, true);
}
@Override
public int printBarcode(int align, String content, boolean isFeed) {
if (mPrinter != null) {
......@@ -129,6 +176,33 @@ public class YingtaiPrinter extends BasePrinter {
}
}
@Override
public int printImageFast(Bitmap bm) {
if (mPrinter != null && bm != null) {
int ret = setAlign(align);
try {
Bitmap actualBm = BitmapUtils.scaleBitmap(bm, MAX_IMG_WIDTH_80MM / 2, 0);
if (bm.getWidth() > MAX_IMG_WIDTH_80MM / 2) {
//如果超过阈值,则缩放至目标大小
ret = mPrinter.printRasterBitmap(actualBm);
} else {
ret = mPrinter.printRasterBitmap(bm);
}
if (actualBm != null) {
actualBm.recycle();
}
changeStatus2Custom(ret);
} catch (IOException e) {
e.printStackTrace();
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), e.getMessage());
}
//英泰打印图片时,本身就会强制走纸一行,这里不再判断是否再走纸
return ret;
} else {
throw new PrinterException(PrinterStatusEnum.CODE_FAILED.getStatus(), PrinterStatusEnum.CODE_FAILED.getDesc());
}
}
@Override
public int setAlign(int align) {
if (mPrinter != null) {
......@@ -242,6 +316,7 @@ public class YingtaiPrinter extends BasePrinter {
return mPrinter.isConnect();
}
@Deprecated
public static String getStatusDescribe(int getStatus) {
int status = getStatus;
......
......@@ -3,80 +3,89 @@ package com.miya.print.utils;
import com.miya.print.BuildConfig;
public class D {
public class PrintLogger {
private static final String Tag = "HHVerify";
private static final String Tag = PrintLogger.class.getSimpleName();
/**
* 是否开启logcat日志输出
*/
static boolean isOpenLogcat = true;
/**
* 是否开启记录本地日志文件
*/
static boolean isOpenWriteLog = true;
public static void log(String text) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.v(Tag, "-----:" + text);
}
}
public static void v(String tag, String msg) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.v(tag, msg);
}
}
public static void v(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.v(tag, msg, tr);
}
}
public static void d(String tag, String msg) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.d(tag, msg);
}
}
public static void d(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.d(tag, msg, tr);
}
}
public static void i(String tag, String msg) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.i(tag, msg);
}
}
public static void i(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.i(tag, msg, tr);
}
}
public static void w(String tag, String msg) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.w(tag, msg);
}
}
public static void w(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.w(tag, msg, tr);
}
}
public static void w(String tag, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.w(tag, tr);
}
}
public static void e(String tag, String msg) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.e(tag, msg);
}
}
public static void e(String tag, String msg, Throwable tr) {
if (BuildConfig.DEBUG) {
if (isOpenLogcat) {
android.util.Log.e(tag, msg, tr);
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment