Commit 8dba2f2b by Wyh

3-11 打印優化。啟動圖,自動登陸,webview適配

parent deb9628d
...@@ -24,7 +24,7 @@ ext { ...@@ -24,7 +24,7 @@ ext {
dependencies = [ dependencies = [
//support //support
"appcompat-v7" : 'androidx.appcompat:appcompat:1.0.0', "appcompat-v7" : 'androidx.appcompat:appcompat:1.1.0',//不要超過1.0.2,不然android5.1.1用webview會有問題
"design" : 'com.google.android.material:material:1.0.0', "design" : 'com.google.android.material:material:1.0.0',
"support-v4" : 'androidx.legacy:legacy-support-v4:1.0.0', "support-v4" : 'androidx.legacy:legacy-support-v4:1.0.0',
"cardview-v7" : 'androidx.cardview:cardview:1.0.0', "cardview-v7" : 'androidx.cardview:cardview:1.0.0',
......
...@@ -113,7 +113,7 @@ public class BusinessReportPresenter extends BasePresenter<BusinessReportContrac ...@@ -113,7 +113,7 @@ public class BusinessReportPresenter extends BasePresenter<BusinessReportContrac
HomeTurnoverBean.DataBean dataBean = data.get(TimeUtils.getOldDate(0)); HomeTurnoverBean.DataBean dataBean = data.get(TimeUtils.getOldDate(0));
//底部信息默認顯示今天的數據 //底部信息默認顯示今天的數據
List<BusinessBean> businessBeans = new ArrayList<>(); List<BusinessBean> businessBeans = new ArrayList<>();
if (dataBean != null) { if (dataBean != null && dataBean.getBusiness_amount() != null) {
businessBeans.add(new BusinessBean(itemNames[0], dataBean.getBusiness_amount())); businessBeans.add(new BusinessBean(itemNames[0], dataBean.getBusiness_amount()));
businessBeans.add(new BusinessBean(itemNames[1], dataBean.getDiscount())); businessBeans.add(new BusinessBean(itemNames[1], dataBean.getDiscount()));
businessBeans.add(new BusinessBean(itemNames[2], dataBean.getServicecharge())); businessBeans.add(new BusinessBean(itemNames[2], dataBean.getServicecharge()));
......
...@@ -65,7 +65,7 @@ public class PaymentMethodReportPresenter extends BasePresenter<PaymentMethodRep ...@@ -65,7 +65,7 @@ public class PaymentMethodReportPresenter extends BasePresenter<PaymentMethodRep
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("restaurantId", restaurandId) .add("restaurantId", restaurandId)
.add("startTime", startTime)//TimeUtils.getYesterdayTime(TimeUtils.DATE_FORMAT_DATE) .add("startTime", startTime)//TimeUtils.getYesterdayTime(TimeUtils.DATE_FORMAT_DATE)
.add("endTime", TimeUtils.getYear(0))//TimeUtils.getCurrentTimeInString(TimeUtils.DATE_FORMAT_DATE) .add("endTime", TimeUtils.getOldDate(1))//TimeUtils.getCurrentTimeInString(TimeUtils.DATE_FORMAT_DATE)
.build(); .build();
mModel.getPaymentInfo(requestBody) mModel.getPaymentInfo(requestBody)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
......
...@@ -67,7 +67,7 @@ public class SalesPresenter extends BasePresenter<SalesContract.Model, SalesCont ...@@ -67,7 +67,7 @@ public class SalesPresenter extends BasePresenter<SalesContract.Model, SalesCont
RequestBody requestBody = new FormBody.Builder() RequestBody requestBody = new FormBody.Builder()
.add("restaurantId", restaurantId) .add("restaurantId", restaurantId)
.add("startTime", startTime)//TimeUtils.getYesterdayTime(TimeUtils.DATE_FORMAT_DATE) .add("startTime", startTime)//TimeUtils.getYesterdayTime(TimeUtils.DATE_FORMAT_DATE)
.add("endTime", TimeUtils.getYear(0))//TimeUtils.getCurrentTimeInString(TimeUtils.DATE_FORMAT_DATE) .add("endTime", TimeUtils.getOldDate(1))//TimeUtils.getCurrentTimeInString(TimeUtils.DATE_FORMAT_DATE)
.build(); .build();
mModel.getSalesReportInfo(requestBody) mModel.getSalesReportInfo(requestBody)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
......
...@@ -8,6 +8,12 @@ import android.view.View; ...@@ -8,6 +8,12 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.time.TimePickerUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimePickerUtils;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
...@@ -36,11 +42,6 @@ import java.util.Calendar; ...@@ -36,11 +42,6 @@ import java.util.Calendar;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -99,7 +100,7 @@ public class BusinessReportFragment extends BaseFragment<BusinessReportPresenter ...@@ -99,7 +100,7 @@ public class BusinessReportFragment extends BaseFragment<BusinessReportPresenter
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
//獲取一段時間內的營業信息,默認獲取七天的數據 //獲取一段時間內的營業信息,默認獲取七天的數據
mPresenter.getRestaurantBusinessInfo(GsaCloudApplication.getRestaurantId(mContext) + "", TimeUtils.getOldDate(-6), TimeUtils.getOldDate(0)); mPresenter.getRestaurantBusinessInfo(GsaCloudApplication.getRestaurantId(mContext) + "", TimeUtils.getOldDate(-6), TimeUtils.getOldDate(1));
mRestaurantName.setText(GsaCloudApplication.getRestaurantName(mContext)); mRestaurantName.setText(GsaCloudApplication.getRestaurantName(mContext));
mTvStartTime.setText(TimeUtils.getOldDate(-6)); mTvStartTime.setText(TimeUtils.getOldDate(-6));
......
...@@ -9,6 +9,12 @@ import android.view.View; ...@@ -9,6 +9,12 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.time.TimePickerUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimePickerUtils;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils; import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
...@@ -38,11 +44,6 @@ import java.util.ArrayList; ...@@ -38,11 +44,6 @@ import java.util.ArrayList;
import java.util.Calendar; import java.util.Calendar;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -99,7 +100,7 @@ public class PaymentMethodReportFragment extends BaseFragment<PaymentMethodRepor ...@@ -99,7 +100,7 @@ public class PaymentMethodReportFragment extends BaseFragment<PaymentMethodRepor
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
mPresenter.getPaymentInfo(GsaCloudApplication.getRestaurantId(mContext) + "", TimeUtils.getYear(-1)); mPresenter.getPaymentInfo(GsaCloudApplication.getRestaurantId(mContext) + "", TimeUtils.getOldDate(-6));
mTvStartTime.setText(TimeUtils.getOldDate(-6)); mTvStartTime.setText(TimeUtils.getOldDate(-6));
mTvEndTime.setText(TimeUtils.getOldDate(0)); mTvEndTime.setText(TimeUtils.getOldDate(0));
......
...@@ -40,11 +40,11 @@ android { ...@@ -40,11 +40,11 @@ android {
dependencies { dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0' implementation 'androidx.appcompat:appcompat:1.1.0'//不要超過1.0.2,不然android5.1.1用webview會有問題
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"] annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
implementation 'am.util:printer:2.1.0' implementation 'am.util:printer:2.1.0'//打印
implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"] implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
implementation rootProject.ext.dependencies["yzjRecyclerView"] implementation rootProject.ext.dependencies["yzjRecyclerView"]
// implementation rootProject.ext.dependencies["fastjson"] // implementation rootProject.ext.dependencies["fastjson"]
......
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joe.print"> package="com.joe.print">
<uses-permission android:name="android.permission.INTERNET" />
<application> <application>
<activity <activity
android:name=".mvp.ui.activity.OldPrintActivity" android:name=".mvp.ui.activity.IpPrintActivity"
android:launchMode="singleTop" android:launchMode="singleTop"
android:theme="@style/print_TranslucentTheme" /> android:theme="@style/print_TranslucentTheme" />
<activity <activity
......
...@@ -11,17 +11,17 @@ ...@@ -11,17 +11,17 @@
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
android:label="@string/app_name" android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_logo"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme"> android:theme="@style/AppTheme">
<!-- <activity--> <!-- <activity-->
<!-- android:name=".mvp.ui.activity.PrintActivity"--> <!-- android:name=".mvp.ui.activity.PrintActivity"-->
<!-- android:theme="@style/print_TranslucentTheme" />--> <!-- android:theme="@style/print_TranslucentTheme" />-->
<activity android:name=".mvp.ui.activity.PrinterAddActivity" /> <activity android:name=".mvp.ui.activity.PrintActivity" />
<activity <activity
android:name=".mvp.ui.activity.OldPrintActivity" android:name=".mvp.ui.activity.IpPrintActivity"
android:theme="@style/print_TranslucentTheme" /> <!-- PrinterListActivity android:theme="@style/print_TranslucentTheme" --> android:theme="@style/print_TranslucentTheme" /> <!-- PrinterListActivity android:theme="@style/print_TranslucentTheme" -->
<activity android:name=".mvp.ui.activity.PrintActivity"> <activity android:name=".mvp.ui.activity.PrinterAddActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
</application> </application>
</manifest> </manifest>
\ No newline at end of file
...@@ -8,10 +8,12 @@ import com.billy.cc.core.component.CC; ...@@ -8,10 +8,12 @@ import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult; import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
import com.billy.cc.core.component.IComponent; import com.billy.cc.core.component.IComponent;
import com.joe.print.mvp.ui.activity.OldPrintActivity; import com.joe.print.mvp.ui.activity.IpPrintActivity;
import com.joe.print.mvp.ui.activity.PrintActivity; import com.joe.print.mvp.ui.activity.PrintActivity;
import com.joe.print.mvp.ui.activity.PrinterListActivity; import com.joe.print.mvp.ui.activity.PrinterListActivity;
import static com.billy.cc.core.component.CCUtil.EXTRA_KEY_CALL_ID;
public class PrintComponent implements IComponent { public class PrintComponent implements IComponent {
...@@ -95,13 +97,13 @@ public class PrintComponent implements IComponent { ...@@ -95,13 +97,13 @@ public class PrintComponent implements IComponent {
private boolean printOrderInfo(CC cc) { private boolean printOrderInfo(CC cc) {
Context context = cc.getContext(); Context context = cc.getContext();
Intent intent = new Intent(context, OldPrintActivity.class); Intent intent = new Intent(context, IpPrintActivity.class);
if (!(context instanceof Activity)) { if (!(context instanceof Activity)) {
//调用方没有设置context或app间组件跳转,context为application //调用方没有设置context或app间组件跳转,context为application
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
} }
//将cc的callId传给Activity,登录完成后通过这个callId来回传结果 //将cc的callId传给Activity,登录完成后通过这个callId来回传结果
intent.putExtra("callId", cc.getCallId()); intent.putExtra(EXTRA_KEY_CALL_ID, cc.getCallId());
context.startActivity(intent); context.startActivity(intent);
//返回true,不立即调用CC.sendCCResult //返回true,不立即调用CC.sendCCResult
return true; return true;
......
...@@ -5,6 +5,7 @@ import android.graphics.Bitmap; ...@@ -5,6 +5,7 @@ import android.graphics.Bitmap;
import android.graphics.Canvas; import android.graphics.Canvas;
import android.graphics.Matrix; import android.graphics.Matrix;
import android.graphics.Rect; import android.graphics.Rect;
import android.util.Log;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils; import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
...@@ -43,7 +44,6 @@ public class SendPrint implements PrintDataMaker { ...@@ -43,7 +44,6 @@ public class SendPrint implements PrintDataMaker {
PrinterWriter printer; PrinterWriter printer;
printer = type == PrinterWriter58mm.TYPE_58 ? new PrinterWriter58mm(parting, width) : new PrinterWriter80mm(parting, width); printer = type == PrinterWriter58mm.TYPE_58 ? new PrinterWriter58mm(parting, width) : new PrinterWriter80mm(parting, width);
printer.setAlignCenter(); printer.setAlignCenter();
data.add(printer.getDataAndReset()); data.add(printer.getDataAndReset());
List<Bitmap> bitmaps = PrintUtils.getPrintBitmap(mContext, printType, width);//根據打印類型獲得不同的bitmap List<Bitmap> bitmaps = PrintUtils.getPrintBitmap(mContext, printType, width);//根據打印類型獲得不同的bitmap
if (bitmaps.size() <= 0) { if (bitmaps.size() <= 0) {
...@@ -53,14 +53,14 @@ public class SendPrint implements PrintDataMaker { ...@@ -53,14 +53,14 @@ public class SendPrint implements PrintDataMaker {
for (int i = 0; i < bitmaps.size(); i++) { for (int i = 0; i < bitmaps.size(); i++) {
// printer.getImageByte(bitmaps.get(i)); // printer.getImageByte(bitmaps.get(i));
// data.addAll(PrinterUtils.decodeBitmapToDataList(bitmaps.get(i), parting)); // data.addAll(PrinterUtils.decodeBitmapToDataList(bitmaps.get(i), parting));
data.add(draw2PxPoint2(bitmaps.get(i))); ArrayList<byte[]> image1 = printer.getImageByte(bitmaps.get(i));
data.addAll(image1);//draw2PxPoint2(bitmaps.get(i)
printer.printLineFeed(); printer.printLineFeed();
printer.printLineFeed(); printer.printLineFeed();
printer.printLineFeed(); printer.printLineFeed();
printer.printLineFeed(); printer.printLineFeed();
printer.printLineFeed(); printer.printLineFeed();
printer.feedPaperCutPartial(); printer.feedPaperCutPartial();
data.add(printer.getDataAndClose());
} }
// String bitmapPath = FileUtils.getExternalFilesDir(context, "Temp") + "tmp_qr.jpg"; // String bitmapPath = FileUtils.getExternalFilesDir(context, "Temp") + "tmp_qr.jpg";
// if (QRCodeUtil.createQRImage(qr, 380, 380, null, bitmapPath)) { // if (QRCodeUtil.createQRImage(qr, 380, 380, null, bitmapPath)) {
...@@ -71,7 +71,7 @@ public class SendPrint implements PrintDataMaker { ...@@ -71,7 +71,7 @@ public class SendPrint implements PrintDataMaker {
// .getImageByte(context.getResources(), R.drawable.ic_printer_qr); // .getImageByte(context.getResources(), R.drawable.ic_printer_qr);
// data.addAll(image2); // data.addAll(image2);
// } // }
data.add(printer.getDataAndClose());
return data; return data;
} catch (Exception e) { } catch (Exception e) {
return new ArrayList<>(); return new ArrayList<>();
...@@ -137,19 +137,22 @@ public class SendPrint implements PrintDataMaker { ...@@ -137,19 +137,22 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 把一张Bitmap图片转化为打印机可以打印的bit(将图片压缩为360*360) * 把一张Bitmap图片转化为打印机可以打印的bit(将图片压缩为360*360)
* 效率很高(相对于下面) * 效率很高(相对于下面)
*
* @param bit * @param bit
* @return * @return
*/ */
public static byte[] draw2PxPoint2(Bitmap bit) { public static byte[] draw2PxPoint2(Bitmap bit) {
byte[] data = new byte[16290]; byte[] data = new byte[16290];
int height = bit.getHeight() + (24 - bit.getHeight() % 24);
int y = height / 24;
int k = 0; int k = 0;
for (int j = 0; j < 15; j++) { for (int j = 0; j < y; j++) {
data[k++] = 0x1B; data[k++] = 0x1B;
data[k++] = 0x2A; data[k++] = 0x2A;
data[k++] = 33; // m=33时,选择24点双密度打印,分辨率达到200DPI。 data[k++] = 33; // m=33时,选择24点双密度打印,分辨率达到200DPI。
data[k++] = 0x68; data[k++] = 0x68;
data[k++] = 0x01; data[k++] = 0x01;
for (int i = 0; i < 360; i++) { for (int i = 0; i < bit.getWidth(); i++) {
for (int m = 0; m < 3; m++) { for (int m = 0; m < 3; m++) {
for (int n = 0; n < 8; n++) { for (int n = 0; n < 8; n++) {
byte b = px2Byte(i, j * 24 + m * 8 + n, bit); byte b = px2Byte(i, j * 24 + m * 8 + n, bit);
...@@ -165,10 +168,11 @@ public class SendPrint implements PrintDataMaker { ...@@ -165,10 +168,11 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 把一张Bitmap图片转化为打印机可以打印的bit * 把一张Bitmap图片转化为打印机可以打印的bit
*
* @param bit * @param bit
* @return * @return
*/ */
public static byte[] pic2PxPoint(Bitmap bit){ public static byte[] pic2PxPoint(Bitmap bit) {
long start = System.currentTimeMillis(); long start = System.currentTimeMillis();
byte[] data = new byte[16290]; byte[] data = new byte[16290];
int k = 0; int k = 0;
...@@ -180,9 +184,9 @@ public class SendPrint implements PrintDataMaker { ...@@ -180,9 +184,9 @@ public class SendPrint implements PrintDataMaker {
data[k++] = 0x01; data[k++] = 0x01;
for (int x = 0; x < 360; x++) { for (int x = 0; x < 360; x++) {
for (int m = 0; m < 3; m++) { for (int m = 0; m < 3; m++) {
byte[] by = new byte[8]; byte[] by = new byte[8];
for (int n = 0; n < 8; n++) { for (int n = 0; n < 8; n++) {
byte b = px2Byte(x, i * 24 + m * 8 +7-n, bit); byte b = px2Byte(x, i * 24 + m * 8 + 7 - n, bit);
by[n] = b; by[n] = b;
} }
data[k] = (byte) changePointPx1(by); data[k] = (byte) changePointPx1(by);
...@@ -198,19 +202,23 @@ public class SendPrint implements PrintDataMaker { ...@@ -198,19 +202,23 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 图片二值化,黑色是1,白色是0 * 图片二值化,黑色是1,白色是0
* @param x 横坐标 *
* @param y 纵坐标 * @param x 横坐标
* @param y 纵坐标
* @param bit 位图 * @param bit 位图
* @return * @return
*/ */
public static byte px2Byte(int x, int y, Bitmap bit) { public static byte px2Byte(int x, int y, Bitmap bit) {
byte b; byte b;
if (y >= bit.getHeight()) {
return 0;
}
int pixel = bit.getPixel(x, y); int pixel = bit.getPixel(x, y);
int red = (pixel & 0x00ff0000) >> 16; // 取高两位 int red = (pixel & 0x00ff0000) >> 16; // 取高两位
int green = (pixel & 0x0000ff00) >> 8; // 取中两位 int green = (pixel & 0x0000ff00) >> 8; // 取中两位
int blue = pixel & 0x000000ff; // 取低两位 int blue = pixel & 0x000000ff; // 取低两位
int gray = RGB2Gray(red, green, blue); int gray = RGB2Gray(red, green, blue);
if ( gray < 128 ){ if (gray < 128) {
b = 1; b = 1;
} else { } else {
b = 0; b = 0;
...@@ -220,18 +228,20 @@ public class SendPrint implements PrintDataMaker { ...@@ -220,18 +228,20 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 图片灰度的转化 * 图片灰度的转化
*
* @param r * @param r
* @param g * @param g
* @param b * @param b
* @return * @return
*/ */
private static int RGB2Gray(int r, int g, int b){ private static int RGB2Gray(int r, int g, int b) {
int gray = (int) (0.29900 * r + 0.58700 * g + 0.11400 * b); //灰度转化公式 int gray = (int) (0.29900 * r + 0.58700 * g + 0.11400 * b); //灰度转化公式
return gray; return gray;
} }
/** /**
* 对图片进行压缩(去除透明度) * 对图片进行压缩(去除透明度)
*
* @param bitmapOrg * @param bitmapOrg
*/ */
public static Bitmap compressPic(Bitmap bitmapOrg) { public static Bitmap compressPic(Bitmap bitmapOrg) {
...@@ -251,6 +261,7 @@ public class SendPrint implements PrintDataMaker { ...@@ -251,6 +261,7 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 对图片进行压缩(不去除透明度) * 对图片进行压缩(不去除透明度)
*
* @param bitmapOrg * @param bitmapOrg
*/ */
public static Bitmap compressBitmap(Bitmap bitmapOrg) { public static Bitmap compressBitmap(Bitmap bitmapOrg) {
...@@ -270,7 +281,7 @@ public class SendPrint implements PrintDataMaker { ...@@ -270,7 +281,7 @@ public class SendPrint implements PrintDataMaker {
// 缩放图片动作 // 缩放图片动作
matrix.postScale(scaleWidth, scaleHeight); matrix.postScale(scaleWidth, scaleHeight);
// 创建新的图片 // 创建新的图片
Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width,height, matrix, true); Bitmap resizedBitmap = Bitmap.createBitmap(bitmapOrg, 0, 0, width, height, matrix, true);
// 将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中 // 将上面创建的Bitmap转换成Drawable对象,使得其可以使用在ImageView, ImageButton中
// BitmapDrawable bmd = new BitmapDrawable(resizedBitmap); // BitmapDrawable bmd = new BitmapDrawable(resizedBitmap);
return resizedBitmap; return resizedBitmap;
...@@ -278,13 +289,14 @@ public class SendPrint implements PrintDataMaker { ...@@ -278,13 +289,14 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值(效率更高) * 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值(效率更高)
*
* @param arry * @param arry
* @return * @return
*/ */
public static int changePointPx1(byte[] arry){ public static int changePointPx1(byte[] arry) {
int v = 0; int v = 0;
for (int j = 0; j <arry.length; j++) { for (int j = 0; j < arry.length; j++) {
if( arry[j] == 1) { if (arry[j] == 1) {
v = v | 1 << j; v = v | 1 << j;
} }
} }
...@@ -293,10 +305,11 @@ public class SendPrint implements PrintDataMaker { ...@@ -293,10 +305,11 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值 * 将[1,0,0,1,0,0,0,1]这样的二进制转为化十进制的数值
*
* @param arry * @param arry
* @return * @return
*/ */
public byte changePointPx(byte[] arry){ public byte changePointPx(byte[] arry) {
byte v = 0; byte v = 0;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
v += v + arry[i]; v += v + arry[i];
...@@ -306,10 +319,11 @@ public class SendPrint implements PrintDataMaker { ...@@ -306,10 +319,11 @@ public class SendPrint implements PrintDataMaker {
/** /**
* 得到位图的某个点的像素值 * 得到位图的某个点的像素值
*
* @param bitmap * @param bitmap
* @return * @return
*/ */
public byte[] getPicPx(Bitmap bitmap){ public byte[] getPicPx(Bitmap bitmap) {
int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];// 保存所有的像素的数组,图片宽×高 int[] pixels = new int[bitmap.getWidth() * bitmap.getHeight()];// 保存所有的像素的数组,图片宽×高
bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight()); bitmap.getPixels(pixels, 0, bitmap.getWidth(), 0, 0, bitmap.getWidth(), bitmap.getHeight());
for (int i = 0; i < pixels.length; i++) { for (int i = 0; i < pixels.length; i++) {
......
package com.joe.print.mvp.print;
import android.content.Context;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.sunmi.peripheral.printer.InnerPrinterCallback;
import com.sunmi.peripheral.printer.InnerPrinterException;
import com.sunmi.peripheral.printer.InnerPrinterManager;
/**
* Created by Wyh on 2020/2/10.
*/
public class SunMiPrint {
public static boolean bindService(Context context, InnerPrinterCallback callback) {
try {
return InnerPrinterManager.getInstance().bindService(context, callback);
} catch (InnerPrinterException e) {
e.printStackTrace();
ToastUtils.show(context, "連接失敗,錯誤信息:" + e.getMessage());
return false;
}
}
}
package com.joe.print.mvp.print;
import android.content.Context;
import com.joe.print.R;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;
import am.util.printer.PrintDataMaker;
import am.util.printer.PrinterWriter;
import am.util.printer.PrinterWriter58mm;
import am.util.printer.PrinterWriter80mm;
/**
* 测试数据生成
*/
public class TestPrintDataMaker implements PrintDataMaker {
private Context context;
// private String qr;
private int width;
private int height;
public TestPrintDataMaker(Context context, int width, int height) {
this.context = context;
// this.qr = qr;
this.width = width;
this.height = height;
}
@Override
public List<byte[]> getPrintData(int type) {
ArrayList<byte[]> data = new ArrayList<>();
try {
PrinterWriter printer;
printer = type == PrinterWriter58mm.TYPE_58 ? new PrinterWriter58mm(height, width) : new PrinterWriter80mm(height, width);
printer.setAlignCenter();
data.add(printer.getDataAndReset());
ArrayList<byte[]> image1 = printer.getImageByte(context.getResources(), R.mipmap.ic_logo);
data.addAll(image1);
printer.setAlignLeft();
printer.printLine();
printer.printLineFeed();
printer.printLineFeed();
printer.setAlignCenter();
printer.setEmphasizedOn();
printer.setFontSize(1);
printer.print("Selftest");
printer.printLineFeed();
printer.setFontSize(0);
printer.setEmphasizedOff();
printer.printLineFeed();
printer.print("Gingersoft");
printer.printLineFeed();
printer.print("客服电话:××××××××");
printer.printLineFeed();
printer.setAlignLeft();
printer.printLineFeed();
printer.print("订单号:88888888888888888");
printer.printLineFeed();
printer.print("预计送达:" +
new SimpleDateFormat("yyyy/MM/dd HH:mm", Locale.getDefault())
.format(new Date(System.currentTimeMillis())));
printer.printLineFeed();
printer.setEmphasizedOn();
printer.print("#8(已付款)");
printer.printLineFeed();
printer.print("××区××路×××大厦××楼×××室");
printer.printLineFeed();
printer.setEmphasizedOff();
// printer.print("13843211234");
// printer.print("(张某某)");
printer.printLineFeed();
printer.print("备注:多加点辣椒,多加点香菜,多加点酸萝卜,多送点一次性手套");
printer.printLineFeed();
printer.printLine();
printer.printLineFeed();
printer.printLineFeed();
printer.printLineFeed();
printer.feedPaperCutPartial();
data.add(printer.getDataAndClose());
return data;
} catch (Exception e) {
return new ArrayList<>();
}
}
}
...@@ -5,33 +5,46 @@ import android.app.Dialog; ...@@ -5,33 +5,46 @@ import android.app.Dialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle; import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.View;
import android.view.Window;
import android.view.WindowManager; import android.view.WindowManager;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.Nullable;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult; import com.billy.cc.core.component.CCResult;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils; import com.joe.print.R;
import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog;
import com.joe.print.mvp.print.SendPrint; import com.joe.print.mvp.print.SendPrint;
import com.joe.print.mvp.print.TestPrintDataMaker;
import am.util.printer.PrintExecutor; import am.util.printer.PrintExecutor;
import am.util.printer.PrintSocketHolder; import am.util.printer.PrintSocketHolder;
import am.util.printer.PrinterWriter58mm; import am.util.printer.PrinterWriter58mm;
import am.util.printer.PrinterWriter80mm; import am.util.printer.PrinterWriter80mm;
import androidx.annotation.Nullable;
import static com.billy.cc.core.component.CCUtil.EXTRA_KEY_CALL_ID;
/** /**
* Created by Wyh on 2020/1/7. * Created by Wyh on 2020/1/7.
*/ */
public class OldPrintActivity extends Activity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener, DialogInterface.OnDismissListener { public class IpPrintActivity extends Activity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener, DialogInterface.OnDismissListener {
private Context mContext;
private PrintExecutor executor; private PrintExecutor executor;
private SendPrint maker; private SendPrint maker;
private Dialog dialog;
private String callId; private String callId;
/**- /**
* -
* 是否打印成功 true:成功 * 是否打印成功 true:成功
*/ */
private boolean printStatus = false; private boolean printStatus = false;
...@@ -49,24 +62,59 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt ...@@ -49,24 +62,59 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
*/ */
private int type = -1; private int type = -1;
private TextView mTvLoadingTip;
private Dialog mLoadingDialog;
@Override @Override
protected void onCreate(@Nullable Bundle savedInstanceState) { protected void onCreate(@Nullable Bundle savedInstanceState) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE getWindow().addFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
| WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH); | WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH);
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
mContext = this;
getWindow().setBackgroundDrawable(null); getWindow().setBackgroundDrawable(null);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS); getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
initDialog();
initIntent(); initIntent();
callId = getIntent().getStringExtra("callId"); callId = getIntent().getStringExtra(EXTRA_KEY_CALL_ID);
printOrder(this); printOrder(this);
} }
private void initDialog() {
try {
View view = LayoutInflater.from(mContext).inflate(R.layout.ui_dialog_loading, null);
mTvLoadingTip = view.findViewById(R.id.tv_loading_dialog_text);
mLoadingDialog = new Dialog(mContext, R.style.ui_loading_dialog);
mLoadingDialog.setCancelable(true);
mLoadingDialog.setCanceledOnTouchOutside(false);
Window window = mLoadingDialog.getWindow();
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
// window.getDecorView().setBackgroundResource(android.R.color.transparent);
mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
mLoadingDialog.show();
mLoadingDialog.setOnDismissListener(dialog -> dismiss());
setLoadingText("加載中...");
} catch (Exception e) {
e.printStackTrace();
}
}
private void setLoadingText(String tip) {
if (mLoadingDialog != null && mLoadingDialog.isShowing()) {
mTvLoadingTip.setText(tip);
}
}
@Override @Override
public boolean dispatchTouchEvent(MotionEvent ev) { public boolean dispatchTouchEvent(MotionEvent ev) {
//點擊當前頁面任意地方自動關閉 //點擊當前頁面任意地方自動關閉
finish(); finish();
return true; return true;
} }
private void initIntent() { private void initIntent() {
Intent intent = getIntent(); Intent intent = getIntent();
ip = intent.getStringExtra("ip"); ip = intent.getStringExtra("ip");
...@@ -86,12 +134,6 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt ...@@ -86,12 +134,6 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
} }
public void printOrder(Context context) { public void printOrder(Context context) {
if (dialog != null) {
dialog.dismiss();
}
dialog = LoadingDialog.showNewDialogForLoading(this, "初始化...", true);
dialog.setOnDismissListener(dialog -> dismiss(""));
dialog.setOnCancelListener(dialog -> dismiss(""));
if (executor == null) { if (executor == null) {
executor = new PrintExecutor(ip, port, paperType); executor = new PrintExecutor(ip, port, paperType);
executor.setOnStateChangedListener(this); executor.setOnStateChangedListener(this);
...@@ -101,87 +143,101 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt ...@@ -101,87 +143,101 @@ public class OldPrintActivity extends Activity implements PrintSocketHolder.OnSt
maker = new SendPrint(context, 255, printWidth, type); maker = new SendPrint(context, 255, printWidth, type);
} }
executor.setIp(ip, port); executor.setIp(ip, port);
executor.doPrinterRequestAsync(maker); if (type == -1) {
executor.setReconnectTimes(3); executor.doPrinterRequestAsync(new TestPrintDataMaker(context, 380, 255));
} else {
executor.doPrinterRequestAsync(maker);
}
} }
@Override @Override
public void onResult(int errorCode) { public void onResult(int errorCode) {
String msg = ""; String tip;
switch (errorCode) { switch (errorCode) {
case PrintSocketHolder.ERROR_0: case PrintSocketHolder.ERROR_0:
//打印成功 Log.e("eee", "打印成功");
msg = "打印成功"; tip = "打印成功";
printStatus = true; printStatus = true;
dismiss(msg); setLoadingText(tip);
dismiss();
break; break;
case PrintSocketHolder.ERROR_2: case PrintSocketHolder.ERROR_1:
case PrintSocketHolder.ERROR_100: Log.e("eee", "生成測試頁面數據失敗");
//创建Socket失败 tip = "生成打印數據失敗";
msg = "連接打印機失敗";
printStatus = false; printStatus = false;
dismiss(msg); setLoadingText(tip);
dismiss();
break; break;
case PrintSocketHolder.ERROR_1: case PrintSocketHolder.ERROR_2:
Log.e("eee", "連接打印機失敗" + System.currentTimeMillis());
case PrintSocketHolder.ERROR_3: case PrintSocketHolder.ERROR_3:
case PrintSocketHolder.ERROR_4: Log.e("eee", "獲取輸出流失敗");
case PrintSocketHolder.ERROR_5: tip = "連接打印機失敗";
//打印失敗
msg = "打印失敗";
dismiss(msg);
printStatus = false; printStatus = false;
setLoadingText(tip);
dismiss();
break; break;
default: case PrintSocketHolder.ERROR_4:
Log.e("eee", "寫入測試頁面數據失敗");
tip = "寫入測試頁面數據失敗";
setLoadingText(tip);
break;
case PrintSocketHolder.ERROR_5:
Log.e("eee", "必要的參數不能為空");
tip = "必要的參數不能為空";
setLoadingText(tip);
break; break;
} }
LoadingDialog.setText(msg);
} }
@Override @Override
public void onStateChanged(int state) { public void onStateChanged(int state) {
String msg = ""; String tip = "打印中...";
switch (state) { switch (state) {
case PrintSocketHolder.STATE_0: case PrintSocketHolder.STATE_0:
Log.e("eee", "生成測試頁數據");
case PrintSocketHolder.STATE_1: case PrintSocketHolder.STATE_1:
//创建Socket连接 Log.e("eee", "開始創建連接");
msg = "連接打印機..."; tip = "開始創建連接";
break; break;
case PrintSocketHolder.STATE_2: case PrintSocketHolder.STATE_2:
Log.e("eee", "創建連接成功,開始發送數據");
tip = "創建連接成功,開始發送數據";
break;
case PrintSocketHolder.STATE_3: case PrintSocketHolder.STATE_3:
//写入测试页面数据 Log.e("eee", "開始寫入數據");
msg = "正在打印..."; tip = "開始寫入數據";
break; break;
case PrintSocketHolder.STATE_4: case PrintSocketHolder.STATE_4:
msg = "正在關閉..."; Log.e("eee", "關閉中");
dismiss(msg); tip = "關閉中";
break; break;
} }
LoadingDialog.setText(msg); setLoadingText(tip);
} }
private void dismiss(String msg) { private void dismiss() {
if (msg != null && !msg.equals("")) {
ToastUtils.show(this, msg);
}
//延遲一秒 //延遲一秒
dialog.dismiss(); new Handler().postDelayed(() -> {
dialog.setOnCancelListener(dialog -> finish()); if (mLoadingDialog != null) {
LoadingDialog.cancelDialogForLoading(); mLoadingDialog.dismiss();
//判断是否为CC调用打开本页面 //判断是否为CC调用打开本页面
if (callId != null) { if (callId != null) {
CCResult result; CCResult result;
if (printStatus) { if (printStatus) {
result = CCResult.success(); result = CCResult.success();
} else { } else {
result = CCResult.error("print error"); result = CCResult.error("print error");
}
//为确保不管登录成功与否都会调用CC.sendCCResult,在onDestroy方法中调用
CC.sendCCResult(callId, result);
}
} }
//为确保不管登录成功与否都会调用CC.sendCCResult,在onDestroy方法中调用 finish();
CC.sendCCResult(callId, result); }, 1500);
}
finish();
} }
@Override @Override
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
finish(); finish();
......
...@@ -12,6 +12,12 @@ import android.util.Log; ...@@ -12,6 +12,12 @@ import android.util.Log;
import android.view.MotionEvent; import android.view.MotionEvent;
import android.view.WindowManager; import android.view.WindowManager;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult; import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.CCUtil; import com.billy.cc.core.component.CCUtil;
...@@ -40,13 +46,9 @@ import com.sunmi.peripheral.printer.InnerResultCallbcak; ...@@ -40,13 +46,9 @@ import com.sunmi.peripheral.printer.InnerResultCallbcak;
import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration; import com.yanzhenjie.recyclerview.widget.DefaultItemDecoration;
import java.util.List; import java.util.List;
import java.util.Objects;
import androidx.annotation.NonNull; import static com.billy.cc.core.component.CCUtil.EXTRA_KEY_CALL_ID;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import static com.jess.arms.utils.Preconditions.checkNotNull; import static com.jess.arms.utils.Preconditions.checkNotNull;
...@@ -82,6 +84,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -82,6 +84,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
private int type = -1; private int type = -1;
public final static int ADD_PRINT_CODE = 1001;//添加打印機回調 public final static int ADD_PRINT_CODE = 1001;//添加打印機回調
private String callId;
@Override @Override
public void setupActivityComponent(@NonNull AppComponent appComponent) { public void setupActivityComponent(@NonNull AppComponent appComponent) {
...@@ -104,6 +107,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -104,6 +107,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
@Override @Override
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
callId = CCUtil.getNavigateCallId(this);
initPrint(); initPrint();
//獲取打印類型,根據打印類型生成對應的bitmap //獲取打印類型,根據打印類型生成對應的bitmap
type = CCUtil.getNavigateParam(this, "type", 1001); type = CCUtil.getNavigateParam(this, "type", 1001);
...@@ -114,19 +118,19 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -114,19 +118,19 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
finish(); finish();
return; return;
} }
// 獲得用戶默認的打印方式 // 獲得用戶默認的打印方式
// if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), "")) { if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), "")) {
//如果沒有默認打印位置 // 如果沒有默認打印位置
// noDefaultPrintMethod(bitmaps); noDefaultPrintMethod(bitmaps);
// } else if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), Constans.LOCAL_PRINT)) { } else if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), Constans.LOCAL_PRINT)) {
//默認打印方式為本地,進行本地打印 // 默認打印方式為本地,進行本地打印
for (int i = 0; i < bitmaps.size(); i++) { for (int i = 0; i < bitmaps.size(); i++) {
locationPrint(bitmaps.get(i)); locationPrint(bitmaps.get(i));
}
} else if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), Constans.IP_PRINT)) {
// 默認打印方式為ip打印,調用ip打印方法
ipPrint();
} }
// } else if (Objects.equals(SPUtils.get(mContext, Constans.DEFAULT_PRINT_METHOD, ""), Constans.IP_PRINT)) {
//默認打印方式為ip打印,調用ip打印方法
// ipPrint();
// }
} }
@Override @Override
...@@ -175,7 +179,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -175,7 +179,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
}); });
hepler.setViewClick(R.id.internet_print, v -> { hepler.setViewClick(R.id.internet_print, v -> {
//修改默認打印方式為IP打印 //修改默認打印方式為IP打印
SPUtils.put(mContext, Constans.DEFAULT_PRINT_METHOD, Constans.LOCAL_PRINT); SPUtils.put(mContext, Constans.DEFAULT_PRINT_METHOD, Constans.IP_PRINT);
ipPrint(); ipPrint();
}); });
} }
...@@ -295,8 +299,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -295,8 +299,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
* 打印失敗 * 打印失敗
*/ */
private void printFile() { private void printFile() {
String callId = CCUtil.getNavigateCallId(this);
Log.e("error", "PrintActivity :printFile" + callId);
CC.sendCCResult(callId, CCResult.error("print error")); CC.sendCCResult(callId, CCResult.error("print error"));
finish(); finish();
} }
...@@ -305,19 +307,11 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -305,19 +307,11 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
* 打印成功 * 打印成功
*/ */
private void printSuccess() { private void printSuccess() {
String callId = CCUtil.getNavigateCallId(this);
Log.e("error", "PrintActivity :printSuccess" + callId);
CC.sendCCResult(callId, CCResult.success()); CC.sendCCResult(callId, CCResult.success());
finish(); finish();
} }
@Override @Override
protected void onDestroy() {
super.onDestroy();
Log.e("error", "PrintActivity :onDestroy");
}
@Override
public void initIntent() { public void initIntent() {
} }
...@@ -397,7 +391,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -397,7 +391,6 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
dialog.dismiss(); dialog.dismiss();
}); });
dialog.setOnDismissListener(PrintActivity.this); dialog.setOnDismissListener(PrintActivity.this);
dialog.setOnCancelListener(dialog1 -> finish());
} }
} }
.setHeight(ArmsUtils.getScreenHeidth(mContext) / 2) .setHeight(ArmsUtils.getScreenHeidth(mContext) / 2)
...@@ -411,11 +404,13 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -411,11 +404,13 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
} }
private void startToIpPrint(PrinterDeviceBean deviceBean) { private void startToIpPrint(PrinterDeviceBean deviceBean) {
Intent intent = new Intent(mContext, OldPrintActivity.class); dialogCount = 2;//設置為2為了不讓回調打印失敗,因為這裡是跳轉ip打印,會關閉選擇ip的dialog,dialog關閉時會調用onDismiss方法,如果dialogCount小於2就會回調打印失敗
Intent intent = new Intent(mContext, IpPrintActivity.class);
intent.putExtra("ip", deviceBean.getIp()); intent.putExtra("ip", deviceBean.getIp());
intent.putExtra("port", deviceBean.getPort()); intent.putExtra("port", deviceBean.getPort());
intent.putExtra("paperType", deviceBean.getType()); intent.putExtra("paperType", deviceBean.getType());
intent.putExtra("type", type); intent.putExtra("type", type);
intent.putExtra(EXTRA_KEY_CALL_ID, callId);
startActivity(intent); startActivity(intent);
finish(); finish();
} }
...@@ -435,6 +430,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print ...@@ -435,6 +430,7 @@ public class PrintActivity extends BaseActivity<PrintPresenter> implements Print
public void onDismiss(DialogInterface dialog) { public void onDismiss(DialogInterface dialog) {
dialogCount--; dialogCount--;
if (dialogCount <= 0) { if (dialogCount <= 0) {
printFile();
finish(); finish();
} }
} }
......
...@@ -11,6 +11,9 @@ import android.widget.EditText; ...@@ -11,6 +11,9 @@ import android.widget.EditText;
import android.widget.RadioGroup; import android.widget.RadioGroup;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils; import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean; import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
...@@ -24,8 +27,6 @@ import com.joe.print.mvp.contract.PrinterAddContract; ...@@ -24,8 +27,6 @@ import com.joe.print.mvp.contract.PrinterAddContract;
import com.joe.print.mvp.presenter.PrinterAddPresenter; import com.joe.print.mvp.presenter.PrinterAddPresenter;
import com.qmuiteam.qmui.widget.QMUITopBar; import com.qmuiteam.qmui.widget.QMUITopBar;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView; import butterknife.BindView;
import butterknife.BindViews; import butterknife.BindViews;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -72,6 +73,12 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem ...@@ -72,6 +73,12 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
public void initData(@Nullable Bundle savedInstanceState) { public void initData(@Nullable Bundle savedInstanceState) {
// etPort.setInputType(EditorInfo.TYPE_CLASS_NUMBER); // etPort.setInputType(EditorInfo.TYPE_CLASS_NUMBER);
String[] ips = new String[4]; String[] ips = new String[4];
// if (BuildConfig.DEBUG) {
// ips[0] = "192";
// ips[1] = "168";
// ips[2] = "1";
// ips[3] = "240";
// }
//如果不為空,則是編輯打印機,初始化信息 //如果不為空,則是編輯打印機,初始化信息
if (printerDeviceBean != null) { if (printerDeviceBean != null) {
ips = printerDeviceBean.getIp().split("[.]"); ips = printerDeviceBean.getIp().split("[.]");
...@@ -185,11 +192,11 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem ...@@ -185,11 +192,11 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
} else { } else {
mPresenter.addPrinter(GsaCloudApplication.getRestaurantId(mContext), ipAddress.substring(0, ipAddress.lastIndexOf(".")), etPort.getText().toString(), paperType); mPresenter.addPrinter(GsaCloudApplication.getRestaurantId(mContext), ipAddress.substring(0, ipAddress.lastIndexOf(".")), etPort.getText().toString(), paperType);
} }
} else if(v.getId() == R.id.print_test){ } else if (v.getId() == R.id.print_test) {
//打印測試 //打印測試
Intent intent = new Intent(mContext, OldPrintActivity.class); Intent intent = new Intent(mContext, IpPrintActivity.class);
intent.putExtra("ip", ipAddress.substring(0, ipAddress.lastIndexOf("."))); intent.putExtra("ip", ipAddress.substring(0, ipAddress.lastIndexOf(".")));
intent.putExtra("port", etPort.getText().toString()); intent.putExtra("port", Integer.parseInt(etPort.getText().toString()));
intent.putExtra("paperType", paperType); intent.putExtra("paperType", paperType);
startActivity(intent); startActivity(intent);
} }
......
...@@ -67,7 +67,6 @@ dependencies { ...@@ -67,7 +67,6 @@ dependencies {
testImplementation rootProject.ext.dependencies["canary-release"] testImplementation rootProject.ext.dependencies["canary-release"]
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"] annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"] implementation rootProject.ext.dependencies["BaseRecyclerViewAdapter"]
// implementation 'androidx.appcompat:appcompat:1.1.0'
testImplementation 'junit:junit:4.12' testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.2.0' androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
...@@ -81,7 +80,6 @@ dependencies { ...@@ -81,7 +80,6 @@ dependencies {
implementation 'com.android.support:design:28.0.0' implementation 'com.android.support:design:28.0.0'
implementation 'com.gcssloop.recyclerview:pagerlayoutmanager:2.3.8' implementation 'com.gcssloop.recyclerview:pagerlayoutmanager:2.3.8'
//陰影背景 //陰影背景
// implementation 'com.github.Liberuman:ShadowDrawable:0.1'
api 'com.github.lihangleo2:ShadowLayout:2.1.6' api 'com.github.lihangleo2:ShadowLayout:2.1.6'
api 'com.contrarywind:Android-PickerView:3.2.4' api 'com.contrarywind:Android-PickerView:3.2.4'
//時間選擇控件 //時間選擇控件
......
package com.gingersoft.gsa.cloud.base.adapter.print; package com.gingersoft.gsa.cloud.base.adapter.print;
import androidx.annotation.Nullable;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder; import com.chad.library.adapter.base.BaseViewHolder;
import com.gingersoft.gsa.cloud.base.R; import com.gingersoft.gsa.cloud.base.R;
import com.gingersoft.gsa.cloud.base.common.bean.OrderDetail; import com.gingersoft.gsa.cloud.base.common.bean.OrderDetail;
import com.gingersoft.gsa.cloud.database.bean.Food;
import java.util.List; import java.util.List;
import androidx.annotation.Nullable;
/** /**
* Created by Wyh on 2020/1/9. * Created by Wyh on 2020/1/9.
...@@ -19,7 +20,13 @@ public class FoodAdapter extends BaseQuickAdapter<OrderDetail, BaseViewHolder> { ...@@ -19,7 +20,13 @@ public class FoodAdapter extends BaseQuickAdapter<OrderDetail, BaseViewHolder> {
@Override @Override
protected void convert(BaseViewHolder helper, OrderDetail item) { protected void convert(BaseViewHolder helper, OrderDetail item) {
helper.setText(R.id.tv_food_name, item.getProductName()); if(item.getItemType() == 3){
//菜品
helper.setText(R.id.tv_food_name, item.getProductName());
} else if(item.getItemType() == 4){
//細項,縮進
helper.setText(R.id.tv_food_name, "\\u3000"+item.getProductName());
}
helper.setText(R.id.tv_food_quantity, String.valueOf(item.getNumber())); helper.setText(R.id.tv_food_quantity, String.valueOf(item.getNumber()));
helper.setText(R.id.tv_food_price, "$" + item.getPrice()); helper.setText(R.id.tv_food_price, "$" + item.getPrice());
} }
......
...@@ -7,6 +7,7 @@ public class UserConstans { ...@@ -7,6 +7,7 @@ public class UserConstans {
public final static String LOGIN_USERNAME = "login_account"; public final static String LOGIN_USERNAME = "login_account";
public final static String LOGIN_PASSWORD = "login_password"; public final static String LOGIN_PASSWORD = "login_password";
public final static String AUTO_LOGIN = "auto_login";
public static String memberId = "member_id"; public static String memberId = "member_id";
public static String memberName = "member_name"; public static String memberName = "member_name";
......
...@@ -27,7 +27,6 @@ import com.gingersoft.gsa.cloud.base.R; ...@@ -27,7 +27,6 @@ import com.gingersoft.gsa.cloud.base.R;
*/ */
public abstract class DialogUtils { public abstract class DialogUtils {
private Context mContext; private Context mContext;
// private int xmlLayout;
private Dialog dialog = null; private Dialog dialog = null;
private View view; private View view;
private int style = R.style.PhotoDialog; private int style = R.style.PhotoDialog;
...@@ -77,9 +76,6 @@ public abstract class DialogUtils { ...@@ -77,9 +76,6 @@ public abstract class DialogUtils {
dialogWindow.setAttributes(p); dialogWindow.setAttributes(p);
// android Activity改成dialog样式后 怎设置点击空白处关闭窗体,点击窗体以外的地方关闭窗体 // android Activity改成dialog样式后 怎设置点击空白处关闭窗体,点击窗体以外的地方关闭窗体
dialog.setCanceledOnTouchOutside(true); dialog.setCanceledOnTouchOutside(true);
dialog.setOnDismissListener(dialog -> {
});
dialog.setCancelable(true); dialog.setCancelable(true);
// dialog.show(); // dialog.show();
return this; return this;
......
/** /**
// AAChartModel.java * // AAChartModel.java
// AAChartCore * // AAChartCore
// * //
// Created by AnAn on 2017/9/8.. * // Created by AnAn on 2017/9/8..
// Copyright © 2018年 An An. All rights reserved. * // Copyright © 2018年 An An. All rights reserved.
* <p>
* ◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ ...... SOURCE CODE ......◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ * ◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ ...... SOURCE CODE ......◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉
* ◉◉◉................................................... ◉◉◉ * ◉◉◉................................................... ◉◉◉
* ◉◉◉ https://github.com/AAChartModel/AAChartCore ◉◉◉ * ◉◉◉ https://github.com/AAChartModel/AAChartCore ◉◉◉
* ◉◉◉ https://github.com/AAChartModel/AAChartCore-Kotlin ◉◉◉ * ◉◉◉ https://github.com/AAChartModel/AAChartCore-Kotlin ◉◉◉
* ◉◉◉................................................... ◉◉◉ * ◉◉◉................................................... ◉◉◉
* ◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ ...... SOURCE CODE ......◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ * ◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉ ...... SOURCE CODE ......◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉◉
* <p>
* <p>
* ------------------------------------------------------------------------------- * -------------------------------------------------------------------------------
* * <p>
* 🌕 🌖 🌗 🌘 ❀❀❀ WARM TIPS!!! ❀❀❀ 🌑 🌒 🌓 🌔 * 🌕 🌖 🌗 🌘 ❀❀❀ WARM TIPS!!! ❀❀❀ 🌑 🌒 🌓 🌔
* * <p>
* Please contact me on GitHub,if there are any problems encountered in use. * Please contact me on GitHub,if there are any problems encountered in use.
* GitHub Issues : https://github.com/AAChartModel/AAChartCore/issues * GitHub Issues : https://github.com/AAChartModel/AAChartCore/issues
* ------------------------------------------------------------------------------- * -------------------------------------------------------------------------------
...@@ -25,15 +25,15 @@ ...@@ -25,15 +25,15 @@
* StackOverflow : https://stackoverflow.com/users/7842508/codeforu * StackOverflow : https://stackoverflow.com/users/7842508/codeforu
* JianShu : http://www.jianshu.com/u/f1e6753d4254 * JianShu : http://www.jianshu.com/u/f1e6753d4254
* SegmentFault : https://segmentfault.com/u/huanghunbieguan * SegmentFault : https://segmentfault.com/u/huanghunbieguan
* * <p>
* ------------------------------------------------------------------------------- * -------------------------------------------------------------------------------
*/ */
package com.gingersoft.gsa.cloud.ui.AAChartCore.AAChartCoreLib.AAChartConfiger; package com.gingersoft.gsa.cloud.ui.AAChartCore.AAChartCoreLib.AAChartConfiger;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.res.Configuration;
import android.os.Build; import android.os.Build;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.webkit.JavascriptInterface; import android.webkit.JavascriptInterface;
...@@ -56,6 +56,7 @@ public class AAChartView extends WebView { ...@@ -56,6 +56,7 @@ public class AAChartView extends WebView {
public interface AAChartViewCallBack { public interface AAChartViewCallBack {
void chartViewDidFinishLoad(AAChartView aaChartView); void chartViewDidFinishLoad(AAChartView aaChartView);
void chartViewMoveOverEventMessage( void chartViewMoveOverEventMessage(
AAChartView aaChartView, AAChartView aaChartView,
AAMoveOverEventMessageModel messageModel AAMoveOverEventMessageModel messageModel
...@@ -104,30 +105,53 @@ public class AAChartView extends WebView { ...@@ -104,30 +105,53 @@ public class AAChartView extends WebView {
private String optionsJson; private String optionsJson;
public AAChartView( public AAChartView(Context context) {
Context context super(getFixedContext(context));
) {
super(context);
setupBasicContent(); setupBasicContent();
} }
public AAChartView( public AAChartView(Context context, AttributeSet attrs) {
Context context, super(getFixedContext(context), attrs);
AttributeSet attrs
) {
super(context, attrs);
setupBasicContent(); setupBasicContent();
} }
public AAChartView( public AAChartView(Context context, AttributeSet attrs, int defStyleAttr) {
Context context, super(getFixedContext(context), attrs, defStyleAttr);
AttributeSet attrs,
int defStyleAttr
) {
super(context, attrs, defStyleAttr);
setupBasicContent(); setupBasicContent();
} }
/**
* 修復android 5.0 5.1webview報錯問題
* @param context
* @return
*/
public static Context getFixedContext(Context context) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
return context.createConfigurationContext(new Configuration());
} else {
return context;
}
}
// public AAChartView(Context context) {
// super(context);
// setupBasicContent();
// }
//
// public AAChartView(Context context,AttributeSet attrs) {
// super(context, attrs);
// setupBasicContent();
// }
//
// public AAChartView(
// Context context,
// AttributeSet attrs,
// int defStyleAttr
// ) {
// super(context, attrs, defStyleAttr);
// setupBasicContent();
// }
private void setupBasicContent() { private void setupBasicContent() {
// Do some initialize work. // Do some initialize work.
this.contentWidth = 420f; this.contentWidth = 420f;
...@@ -151,7 +175,7 @@ public class AAChartView extends WebView { ...@@ -151,7 +175,7 @@ public class AAChartView extends WebView {
messageBody = gson.fromJson(message, messageBody.getClass()); messageBody = gson.fromJson(message, messageBody.getClass());
AAMoveOverEventMessageModel eventMessageModel = getEventMessageModel(messageBody); AAMoveOverEventMessageModel eventMessageModel = getEventMessageModel(messageBody);
if (callBack != null) { if (callBack != null) {
callBack.chartViewMoveOverEventMessage(this,eventMessageModel); callBack.chartViewMoveOverEventMessage(this, eventMessageModel);
} }
// Log.i("androidMethod","++++++++++++++++显示总共调用了几次"); // Log.i("androidMethod","++++++++++++++++显示总共调用了几次");
return ""; return "";
...@@ -185,7 +209,7 @@ public class AAChartView extends WebView { ...@@ -185,7 +209,7 @@ public class AAChartView extends WebView {
public void aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray( public void aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(
AASeriesElement[] seriesElementsArr AASeriesElement[] seriesElementsArr
) { ) {
aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(seriesElementsArr,true); aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(seriesElementsArr, true);
} }
public void aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray( public void aa_onlyRefreshTheChartDataWithChartOptionsSeriesArray(
...@@ -199,21 +223,21 @@ public class AAChartView extends WebView { ...@@ -199,21 +223,21 @@ public class AAChartView extends WebView {
} }
public void aa_updateChartWithOptions( public void aa_updateChartWithOptions(
Object options, Object options,
Boolean redraw Boolean redraw
) { ) {
String classNameStr = options.getClass().getSimpleName(); String classNameStr = options.getClass().getSimpleName();
classNameStr = classNameStr.replace("AA",""); classNameStr = classNameStr.replace("AA", "");
//convert fist character to be lowercase string //convert fist character to be lowercase string
String firstChar = classNameStr.substring(0,1); String firstChar = classNameStr.substring(0, 1);
String lowercaseFirstStr = firstChar.toLowerCase(); String lowercaseFirstStr = firstChar.toLowerCase();
classNameStr = classNameStr.substring(1); classNameStr = classNameStr.substring(1);
String finalClassName = lowercaseFirstStr + classNameStr; String finalClassName = lowercaseFirstStr + classNameStr;
Map finalOptionsMap = new HashMap(); Map finalOptionsMap = new HashMap();
finalOptionsMap.put(finalClassName,options); finalOptionsMap.put(finalClassName, options);
String optionsStr = new Gson().toJson(finalOptionsMap); String optionsStr = new Gson().toJson(finalOptionsMap);
String javaScriptStr = "updateChart('" + optionsStr + "','" + redraw + "')"; String javaScriptStr = "updateChart('" + optionsStr + "','" + redraw + "')";
...@@ -229,6 +253,7 @@ public class AAChartView extends WebView { ...@@ -229,6 +253,7 @@ public class AAChartView extends WebView {
options, options,
true); true);
} }
public void aa_addPointToChartSeriesElement( public void aa_addPointToChartSeriesElement(
Integer elementIndex, Integer elementIndex,
Object options, Object options,
...@@ -251,7 +276,7 @@ public class AAChartView extends WebView { ...@@ -251,7 +276,7 @@ public class AAChartView extends WebView {
Boolean animation Boolean animation
) { ) {
String optionsStr; String optionsStr;
if ( options instanceof Integer if (options instanceof Integer
|| options instanceof Float || options instanceof Float
|| options instanceof Double) { || options instanceof Double) {
optionsStr = String.valueOf(options); optionsStr = String.valueOf(options);
...@@ -302,7 +327,6 @@ public class AAChartView extends WebView { ...@@ -302,7 +327,6 @@ public class AAChartView extends WebView {
} }
private void loadLocalFilesAndDrawChart(final AAOptions aaOptions) { private void loadLocalFilesAndDrawChart(final AAOptions aaOptions) {
this.loadUrl("file:///android_asset/AAChartView.html"); this.loadUrl("file:///android_asset/AAChartView.html");
this.setWebViewClient(new WebViewClient() { this.setWebViewClient(new WebViewClient() {
...@@ -351,7 +375,7 @@ public class AAChartView extends WebView { ...@@ -351,7 +375,7 @@ public class AAChartView extends WebView {
new AlertDialog.Builder(getContext()) new AlertDialog.Builder(getContext())
.setTitle("JavaScript alert Information")//设置对话框标题 .setTitle("JavaScript alert Information")//设置对话框标题
.setMessage(alertMessageStr) .setMessage(alertMessageStr)
.setNeutralButton("sure",null) .setNeutralButton("sure", null)
.show(); .show();
return true; return true;
...@@ -360,7 +384,7 @@ public class AAChartView extends WebView { ...@@ -360,7 +384,7 @@ public class AAChartView extends WebView {
} }
private AAMoveOverEventMessageModel getEventMessageModel(Map messageBody) { private AAMoveOverEventMessageModel getEventMessageModel(Map messageBody) {
AAMoveOverEventMessageModel eventMessageModel = new AAMoveOverEventMessageModel(); AAMoveOverEventMessageModel eventMessageModel = new AAMoveOverEventMessageModel();
eventMessageModel.name = messageBody.get("name").toString(); eventMessageModel.name = messageBody.get("name").toString();
eventMessageModel.x = (Double) messageBody.get("x"); eventMessageModel.x = (Double) messageBody.get("x");
eventMessageModel.y = (Double) messageBody.get("y"); eventMessageModel.y = (Double) messageBody.get("y");
...@@ -374,18 +398,16 @@ public class AAChartView extends WebView { ...@@ -374,18 +398,16 @@ public class AAChartView extends WebView {
private void safeEvaluateJavaScriptString(String javaScriptString) { private void safeEvaluateJavaScriptString(String javaScriptString) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
this.evaluateJavascript("javascript:"+javaScriptString, new ValueCallback<String>() { this.evaluateJavascript("javascript:" + javaScriptString, new ValueCallback<String>() {
@Override @Override
public void onReceiveValue(String s) { public void onReceiveValue(String s) {
// Log.i("call back information","输出打印查看回调的结果"+s); // Log.i("call back information","输出打印查看回调的结果"+s);
} }
}); });
} else { } else {
this.loadUrl("javascript:"+javaScriptString); this.loadUrl("javascript:" + javaScriptString);
} }
} }
} }
...@@ -346,8 +346,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod ...@@ -346,8 +346,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod
setOrderId((Double) info.getData()); setOrderId((Double) info.getData());
} }
mRootView.showMessage("送單成功"); mRootView.showMessage("送單成功");
printSendOrder(getOrderFoodLists()); printSendOrder(getOrderFoodLists(), true);
IActivity.returnTableActivity(true);
} else { } else {
mRootView.showMessage("送單失敗"); mRootView.showMessage("送單失敗");
} }
...@@ -375,12 +374,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod ...@@ -375,12 +374,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod
public void onNext(@NonNull BaseResult info) { public void onNext(@NonNull BaseResult info) {
if (info != null && info.isSuccess()) { if (info != null && info.isSuccess()) {
mRootView.showMessage("送單成功"); mRootView.showMessage("送單成功");
if (OpenTableManage.getDefault() != null) { printSendOrder(foodLists, false);
//通知更新餐台状态
EventBus.getDefault().post(OpenTableManage.getDefault().getTableBean().getId(), "initTable_status_event");
}
printSendOrder(foodLists);
mRootView.killMyself();
} else { } else {
if (!hasNesOrderFoods()) { if (!hasNesOrderFoods()) {
//TODO 未新增食品點擊送單 後台不讓過直接提示即可 //TODO 未新增食品點擊送單 後台不讓過直接提示即可
...@@ -389,8 +383,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod ...@@ -389,8 +383,7 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod
//通知更新餐台状态 //通知更新餐台状态
EventBus.getDefault().post(OpenTableManage.getDefault().getTableBean().getId(), "initTable_status_event"); EventBus.getDefault().post(OpenTableManage.getDefault().getTableBean().getId(), "initTable_status_event");
} }
printSendOrder(foodLists); printSendOrder(foodLists, false);
mRootView.killMyself();
} else { } else {
mRootView.showMessage("送單失敗"); mRootView.showMessage("送單失敗");
} }
...@@ -401,17 +394,26 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod ...@@ -401,17 +394,26 @@ public class MealStandPresenter extends BaseOrderPresenter<MealStandContract.Mod
/** /**
* 打印上菜紙 * 打印上菜紙
* @param newFoods 當前送單新增食品
* @param initTable 是否是開台
*/ */
private void printSendOrder(List<OrderDetail> newFoods) { private void printSendOrder(List<OrderDetail> newFoods, boolean initTable) {
MyOrderManage.getInstance().setNewFoodList(newFoods); MyOrderManage.getInstance().setNewFoodList(newFoods);
CC.obtainBuilder("Component.Print") CC.obtainBuilder("Component.Print")
.setActionName("printActivity") .setActionName("printActivity")
.addParam("type", 3) .addParam("type", 3)
.build() .build()
.callAsync((cc, result) -> { .callAsync((cc, result) -> {
if (result.isSuccess()) { // if (result.isSuccess()) {
//打印成功 //打印成功
} if (initTable) {
IActivity.returnTableActivity(initTable);
} else {
mRootView.killMyself();
}
// } else {
// mRootView.showMessage("打印失敗");
// }
}); });
......
...@@ -7,7 +7,6 @@ import android.view.View; ...@@ -7,7 +7,6 @@ import android.view.View;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult; import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.common.bean.OrderBean;
import com.gingersoft.gsa.cloud.base.common.bean.OrderDetail; import com.gingersoft.gsa.cloud.base.common.bean.OrderDetail;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage;
...@@ -111,7 +110,7 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra ...@@ -111,7 +110,7 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra
sendOrder(false); sendOrder(false);
break; break;
case 1: case 1:
//打印 //印單
sendOrder(true); sendOrder(true);
break; break;
case 2: case 2:
...@@ -192,17 +191,16 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra ...@@ -192,17 +191,16 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra
} else { } else {
mRootView.showMessage("送單成功"); mRootView.showMessage("送單成功");
printSendOrder(foodLists); printSendOrder(foodLists);
mRootView.sendSuccess();
} }
} else { } else {
if (isPrint) { if (isPrint) {
printOrder(OpenTableManage.getDefault().getTableBean().getId()); printOrder(OpenTableManage.getDefault().getTableBean().getId());
} else { } else {
if(!hasNesOrderFoods()){ if(!hasNesOrderFoods()){
//TODO 未新增食品點擊送單 後台不讓過直接提示即可 //TODO 未新增食品點擊送單 後台不讓過直接提示即可,不調用打印
mRootView.showMessage("送單成功"); mRootView.showMessage("送單成功");
printSendOrder(foodLists);
mRootView.sendSuccess(); mRootView.sendSuccess();
// printSendOrder(foodLists);
}else { }else {
mRootView.showMessage("送單失敗"); mRootView.showMessage("送單失敗");
} }
...@@ -223,9 +221,11 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra ...@@ -223,9 +221,11 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra
.build() .build()
.callAsync((cc, result) -> { .callAsync((cc, result) -> {
Log.e("error", "是否成功打印:" + result.isSuccess()); Log.e("error", "是否成功打印:" + result.isSuccess());
if (result.isSuccess()) { // if (result.isSuccess()) {
//打印成功 // //打印成功
} //
// }
mRootView.sendSuccess();
}); });
...@@ -268,11 +268,12 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra ...@@ -268,11 +268,12 @@ public class OrderContentPresenter extends BaseOrderPresenter<OrderContentContra
Log.e("error", "是否成功打印:" + result.isSuccess()); Log.e("error", "是否成功打印:" + result.isSuccess());
if (result.isSuccess()) { if (result.isSuccess()) {
//打印成功 //打印成功
mRootView.printSuccess(); mRootView.showMessage("打印成功!");
} else { } else {
mRootView.printSuccess();
mRootView.showMessage("打印失敗!"); mRootView.showMessage("打印失敗!");
} }
//不管打印是否成功,都需要退出當前頁面
mRootView.printSuccess();
}); });
//打印 //打印
} else { } else {
......
...@@ -22,6 +22,16 @@ import android.widget.LinearLayout; ...@@ -22,6 +22,16 @@ import android.widget.LinearLayout;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.common.bean.TableBean; import com.gingersoft.gsa.cloud.base.common.bean.TableBean;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage;
...@@ -67,15 +77,6 @@ import java.util.ArrayList; ...@@ -67,15 +77,6 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.DefaultItemAnimator;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.viewpager.widget.ViewPager;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
import butterknife.OnLongClick; import butterknife.OnLongClick;
......
...@@ -9,6 +9,10 @@ import android.widget.Button; ...@@ -9,6 +9,10 @@ import android.widget.Button;
import android.widget.Chronometer; import android.widget.Chronometer;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage;
...@@ -31,9 +35,6 @@ import org.simple.eventbus.EventBus; ...@@ -31,9 +35,6 @@ import org.simple.eventbus.EventBus;
import java.util.Date; import java.util.Date;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -224,7 +225,7 @@ public class OrderContentActivity extends BaseActivity<OrderContentPresenter> im ...@@ -224,7 +225,7 @@ public class OrderContentActivity extends BaseActivity<OrderContentPresenter> im
//选择的人数大于0 //选择的人数大于0
// if (Integer.parseInt(number) > 0) { // if (Integer.parseInt(number) > 0) {
// } // }
mPresenter.updateOrderPerson(number,btn_people_num); mPresenter.updateOrderPerson(number, btn_people_num);
} }
@Override @Override
......
...@@ -11,11 +11,16 @@ import android.view.View; ...@@ -11,11 +11,16 @@ import android.view.View;
import android.widget.Button; import android.widget.Button;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import com.billy.cc.core.component.CC;
import com.chad.library.adapter.base.BaseQuickAdapter; import com.chad.library.adapter.base.BaseQuickAdapter;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage; import com.gingersoft.gsa.cloud.base.common.bean.PayMethod;
import com.billy.cc.core.component.CC;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage; import com.gingersoft.gsa.cloud.base.common.bean.mealManage.MyOrderManage;
import com.gingersoft.gsa.cloud.base.common.bean.mealManage.OpenTableManage;
import com.gingersoft.gsa.cloud.base.utils.VibratorUtils; import com.gingersoft.gsa.cloud.base.utils.VibratorUtils;
import com.gingersoft.gsa.cloud.base.utils.gson.GsonUtils; import com.gingersoft.gsa.cloud.base.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.base.utils.log.LogUtil; import com.gingersoft.gsa.cloud.base.utils.log.LogUtil;
...@@ -31,12 +36,11 @@ import com.gingersoft.gsa.cloud.table.app.payment.bean.VoidRespose; ...@@ -31,12 +36,11 @@ import com.gingersoft.gsa.cloud.table.app.payment.bean.VoidRespose;
import com.gingersoft.gsa.cloud.table.app.payment.contract.IN5Callback; import com.gingersoft.gsa.cloud.table.app.payment.contract.IN5Callback;
import com.gingersoft.gsa.cloud.table.di.component.DaggerOrderPayComponent; import com.gingersoft.gsa.cloud.table.di.component.DaggerOrderPayComponent;
import com.gingersoft.gsa.cloud.table.mvp.contract.OrderPayContract; import com.gingersoft.gsa.cloud.table.mvp.contract.OrderPayContract;
import com.gingersoft.gsa.cloud.base.common.bean.PayMethod;
import com.gingersoft.gsa.cloud.table.mvp.presenter.OrderPayPresenter; import com.gingersoft.gsa.cloud.table.mvp.presenter.OrderPayPresenter;
import com.gingersoft.gsa.cloud.table.mvp.ui.widget.PayKeypadDialog; import com.gingersoft.gsa.cloud.table.mvp.ui.widget.PayKeypadDialog;
import com.gingersoft.gsa.cloud.ui.recylcler.decorator.GridDividerItemDecoration; import com.gingersoft.gsa.cloud.ui.recylcler.decorator.GridDividerItemDecoration;
import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog;
import com.gingersoft.gsa.cloud.ui.view.MaxHeightRecyclerView; import com.gingersoft.gsa.cloud.ui.view.MaxHeightRecyclerView;
import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog;
import com.gingersoft.gsa.cloud.ui.widget.dialog.StatusLoadingDialog; import com.gingersoft.gsa.cloud.ui.widget.dialog.StatusLoadingDialog;
import com.jess.arms.base.BaseActivity; import com.jess.arms.base.BaseActivity;
import com.jess.arms.base.DefaultAdapter; import com.jess.arms.base.DefaultAdapter;
...@@ -55,9 +59,6 @@ import java.util.Date; ...@@ -55,9 +59,6 @@ import java.util.Date;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
...@@ -205,7 +206,7 @@ public class OrderPayActivity extends BaseActivity<OrderPayPresenter> implements ...@@ -205,7 +206,7 @@ public class OrderPayActivity extends BaseActivity<OrderPayPresenter> implements
tv_time.setText("時間:" + openTime); tv_time.setText("時間:" + openTime);
btn_people_num.setText(OpenTableManage.getDefault().getPeopleNumber() + ""); btn_people_num.setText(OpenTableManage.getDefault().getPeopleNumber() + "");
tv_server_main.setText( GsaCloudApplication.getMemberName(this)); tv_server_main.setText(GsaCloudApplication.getMemberName(this));
tv_action_name.setBackgroundColor(Color.parseColor("#C50000")); tv_action_name.setBackgroundColor(Color.parseColor("#C50000"));
tv_action_name.setText("結賬"); tv_action_name.setText("結賬");
...@@ -513,13 +514,13 @@ public class OrderPayActivity extends BaseActivity<OrderPayPresenter> implements ...@@ -513,13 +514,13 @@ public class OrderPayActivity extends BaseActivity<OrderPayPresenter> implements
.build() .build()
.callAsync((cc, result) -> { .callAsync((cc, result) -> {
Log.e("error", "是否成功打印:" + result.isSuccess()); Log.e("error", "是否成功打印:" + result.isSuccess());
if (result.isSuccess()) { // if (result.isSuccess()) {
//打印成功 // //打印成功
//
} // }
setResult(Activity.RESULT_OK, null);
killMyself();
}); });
setResult(Activity.RESULT_OK, null);
killMyself();
} }
public void setBillMethodAdapter(BaseQuickAdapter adapter) { public void setBillMethodAdapter(BaseQuickAdapter adapter) {
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_SETTINGS" /> <uses-permission android:name="android.permission.WRITE_SETTINGS" />
<application <application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication" android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
android:allowBackup="true" android:allowBackup="true"
...@@ -23,7 +24,7 @@ ...@@ -23,7 +24,7 @@
tools:replace="android:label"> tools:replace="android:label">
<activity <activity
android:name=".mvp.ui.activity.LoginActivity" android:name=".mvp.ui.activity.WelcomeActivity"
android:launchMode="singleTop"> android:launchMode="singleTop">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
...@@ -32,6 +33,9 @@ ...@@ -32,6 +33,9 @@
<category android:name="android.intent.category.LAUNCHER" /> <category android:name="android.intent.category.LAUNCHER" />
</intent-filter> </intent-filter>
</activity> </activity>
<activity
android:name=".mvp.ui.activity.LoginActivity"
android:launchMode="singleTop" />
<activity android:name=".mvp.ui.activity.SwitchServerActivity" /> <activity android:name=".mvp.ui.activity.SwitchServerActivity" />
<meta-data <meta-data
......
...@@ -20,8 +20,9 @@ ...@@ -20,8 +20,9 @@
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/AppTheme" android:theme="@style/AppTheme"
tools:replace="android:label"> tools:replace="android:label">
<activity android:name=".mvp.ui.activity.SwitchServerActivity"></activity> <activity android:name=".mvp.ui.activity.LoginActivity"/>
<activity android:name=".mvp.ui.activity.LoginActivity"> <activity android:name=".mvp.ui.activity.SwitchServerActivity" />
<activity android:name=".mvp.ui.activity.WelcomeActivity">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" /> <action android:name="android.intent.action.VIEW" />
......
package com.gingersoft.gsa.cloud.user.login.di.component;
import com.gingersoft.gsa.cloud.user.login.di.module.WelcomeModule;
import com.gingersoft.gsa.cloud.user.login.mvp.ui.activity.WelcomeActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.di.scope.ActivityScope;
import dagger.Component;
@ActivityScope
@Component(modules = WelcomeModule.class, dependencies = AppComponent.class)
public interface WelcomeComponent {
void inject(WelcomeActivity activity);
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.di.module;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.WelcomeContract;
import com.gingersoft.gsa.cloud.user.login.mvp.model.WelcomeModel;
import com.jess.arms.di.scope.ActivityScope;
import dagger.Module;
import dagger.Provides;
@Module
public class WelcomeModule {
private WelcomeContract.View view;
/**
* 构建WelcomeModule时,将View的实现类传进来,这样就可以提供View的实现类给presenter
*
* @param view
*/
public WelcomeModule(WelcomeContract.View view) {
this.view = view;
}
@ActivityScope
@Provides
WelcomeContract.View provideWelcomeView() {
return this.view;
}
@ActivityScope
@Provides
WelcomeContract.Model provideWelcomeModel(WelcomeModel model) {
return model;
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.mvp.contract;
import com.jess.arms.mvp.IView;
import com.jess.arms.mvp.IModel;
public interface WelcomeContract {
//对于经常使用的关于UI的方法可以定义到IView中,如显示隐藏进度条,和显示文字消息
interface View extends IView {
}
//Model层定义接口,外部只需关心Model返回的数据,无需关心内部细节,即是否使用缓存
interface Model extends IModel {
}
}
package com.gingersoft.gsa.cloud.user.login.mvp.model;
import android.app.Application;
import com.google.gson.Gson;
import com.jess.arms.integration.IRepositoryManager;
import com.jess.arms.mvp.BaseModel;
import com.jess.arms.di.scope.ActivityScope;
import javax.inject.Inject;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.WelcomeContract;
@ActivityScope
public class WelcomeModel extends BaseModel implements WelcomeContract.Model {
@Inject
Gson mGson;
@Inject
Application mApplication;
@Inject
public WelcomeModel(IRepositoryManager repositoryManager) {
super(repositoryManager);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mGson = null;
this.mApplication = null;
}
}
\ No newline at end of file
package com.gingersoft.gsa.cloud.user.login.mvp.presenter;
import android.app.Application;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.WelcomeContract;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import javax.inject.Inject;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
@ActivityScope
public class WelcomePresenter extends BasePresenter<WelcomeContract.Model, WelcomeContract.View> {
@Inject
RxErrorHandler mErrorHandler;
@Inject
Application mApplication;
@Inject
ImageLoader mImageLoader;
@Inject
AppManager mAppManager;
@Inject
public WelcomePresenter(WelcomeContract.Model model, WelcomeContract.View rootView) {
super(model, rootView);
}
@Override
public void onDestroy() {
super.onDestroy();
this.mErrorHandler = null;
this.mAppManager = null;
this.mImageLoader = null;
this.mApplication = null;
}
}
...@@ -15,15 +15,18 @@ import android.widget.CheckBox; ...@@ -15,15 +15,18 @@ import android.widget.CheckBox;
import android.widget.EditText; import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.billy.cc.core.component.CC; import com.billy.cc.core.component.CC;
import com.billy.cc.core.component.CCResult;
import com.billy.cc.core.component.IComponentCallback;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication; import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils; import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.base.utils.constans.UserConstans; import com.gingersoft.gsa.cloud.base.utils.constans.UserConstans;
import com.gingersoft.gsa.cloud.base.utils.encryption.Aes;
import com.gingersoft.gsa.cloud.base.utils.gson.GsonUtils; import com.gingersoft.gsa.cloud.base.utils.gson.GsonUtils;
import com.gingersoft.gsa.cloud.base.utils.log.LogUtil; import com.gingersoft.gsa.cloud.base.utils.log.LogUtil;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils; import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.base.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils; import com.gingersoft.gsa.cloud.base.utils.toast.ToastUtils;
import com.gingersoft.gsa.cloud.ui.bean.mode.LoginBean; import com.gingersoft.gsa.cloud.ui.bean.mode.LoginBean;
import com.gingersoft.gsa.cloud.ui.widget.dialog.ChooseRestaurantDialog; import com.gingersoft.gsa.cloud.ui.widget.dialog.ChooseRestaurantDialog;
...@@ -45,8 +48,6 @@ import java.util.Objects; ...@@ -45,8 +48,6 @@ import java.util.Objects;
import javax.inject.Inject; import javax.inject.Inject;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import butterknife.BindView; import butterknife.BindView;
import butterknife.OnClick; import butterknife.OnClick;
import okhttp3.Call; import okhttp3.Call;
...@@ -87,6 +88,8 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -87,6 +88,8 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
ImageView icClearAccount; ImageView icClearAccount;
@BindView(R2.id.rb_remember_password) @BindView(R2.id.rb_remember_password)
CheckBox mRbRememberPwd; CheckBox mRbRememberPwd;
@BindView(R2.id.rb_auto_login)
CheckBox mRbAutoLogin;
@BindView(R2.id.ic_look_pwd) @BindView(R2.id.ic_look_pwd)
ImageView mIvSeePwd; ImageView mIvSeePwd;
...@@ -124,13 +127,29 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -124,13 +127,29 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
edAccount.setText("" + SPUtils.get(mContext, UserConstans.LOGIN_USERNAME, "")); edAccount.setText("" + SPUtils.get(mContext, UserConstans.LOGIN_USERNAME, ""));
mRbRememberPwd.setChecked(true); mRbRememberPwd.setChecked(true);
} }
if (!Objects.equals(SPUtils.get(mContext, UserConstans.LOGIN_PASSWORD, ""), "")) { String pwd = Aes.aesDecrypt((String) SPUtils.get(mContext, UserConstans.LOGIN_PASSWORD, ""));
edPwd.setText("" + SPUtils.get(mContext, UserConstans.LOGIN_PASSWORD, "")); if (!TextUtil.isEmptyOrNullOrUndefined(pwd)) {
edPwd.setText(pwd);
} }
// if(GsaCloudApplication.getLoginToken(mContext).length() > 0){ mRbAutoLogin.setOnCheckedChangeListener((buttonView, isChecked) -> {
// jumpActivity(); //選中自動登陸,選中記住密碼
// finish(); if (isChecked) {
// } mRbRememberPwd.setChecked(true);
}
});
mRbRememberPwd.setOnCheckedChangeListener((buttonView, isChecked) -> {
//如果用戶沒有選中記住密碼,那麼取消自動登陸選中
if (!isChecked) {
mRbAutoLogin.setChecked(false);
}
});
if ((boolean) SPUtils.get(mContext, UserConstans.AUTO_LOGIN, false)) {
//自動登陸
mPresenter.login(SPUtils.get(mContext, UserConstans.LOGIN_USERNAME, "") + "", pwd);
mRbAutoLogin.setChecked(true);
}
edPwd.setOnFocusChangeListener(mOnFocusChangeListener); edPwd.setOnFocusChangeListener(mOnFocusChangeListener);
edAccount.setOnFocusChangeListener(mOnFocusChangeListener); edAccount.setOnFocusChangeListener(mOnFocusChangeListener);
edPwd.addTextChangedListener(new TextWatcher() { edPwd.addTextChangedListener(new TextWatcher() {
...@@ -290,7 +309,8 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -290,7 +309,8 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
public void loginSuccess(LoginBean loginBean) { public void loginSuccess(LoginBean loginBean) {
//記住密碼 //記住密碼
RememberPwd(); RememberPwd();
//自動登陸
autoLogin();
GsaCloudApplication.setBrandRestaurantInfos(this, ""); GsaCloudApplication.setBrandRestaurantInfos(this, "");
if (loginBean.getData() != null) { if (loginBean.getData() != null) {
GsaCloudApplication.setLoginToken(LoginActivity.this, loginBean.getData().getToken()); GsaCloudApplication.setLoginToken(LoginActivity.this, loginBean.getData().getToken());
...@@ -358,13 +378,18 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -358,13 +378,18 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
if (mRbRememberPwd.isChecked()) { if (mRbRememberPwd.isChecked()) {
//登陸成功後,如果選中了記住密碼,則保存密碼 //登陸成功後,如果選中了記住密碼,則保存密碼
SPUtils.put(mContext, UserConstans.LOGIN_USERNAME, edAccount.getText().toString()); SPUtils.put(mContext, UserConstans.LOGIN_USERNAME, edAccount.getText().toString());
SPUtils.put(mContext, UserConstans.LOGIN_PASSWORD, edPwd.getText().toString()); //將密碼加密再保存
SPUtils.put(mContext, UserConstans.LOGIN_PASSWORD, Aes.aesEncrypt(edPwd.getText().toString()).replaceAll("\r|\n", ""));
} else { } else {
SPUtils.put(mContext, UserConstans.LOGIN_USERNAME, ""); SPUtils.put(mContext, UserConstans.LOGIN_USERNAME, "");
SPUtils.put(mContext, UserConstans.LOGIN_PASSWORD, ""); SPUtils.put(mContext, UserConstans.LOGIN_PASSWORD, "");
} }
} }
private void autoLogin() {
SPUtils.put(mContext, UserConstans.AUTO_LOGIN, mRbAutoLogin.isChecked());
}
private void saveBrandAndRestaurantInfo(int brandId, String brandName, int restaurantId, String restaurantName) { private void saveBrandAndRestaurantInfo(int brandId, String brandName, int restaurantId, String restaurantName) {
GsaCloudApplication.setBrandId(LoginActivity.this, brandId); GsaCloudApplication.setBrandId(LoginActivity.this, brandId);
GsaCloudApplication.setBrandName(LoginActivity.this, brandName); GsaCloudApplication.setBrandName(LoginActivity.this, brandName);
...@@ -442,7 +467,7 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -442,7 +467,7 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
} }
@OnClick({R2.id.tv_gsa_user_login, R2.id.iv_clear_pwd, R2.id.iv_clear_account, R2.id.tv_remember_pwd_text, R2.id.ic_look_pwd}) @OnClick({R2.id.tv_gsa_user_login, R2.id.iv_clear_pwd, R2.id.iv_clear_account, R2.id.tv_remember_pwd_text, R2.id.ic_look_pwd, R2.id.tv_auto_login_text})
public void onClick(View v) { public void onClick(View v) {
switch (v.getId()) { switch (v.getId()) {
case R.id.ic_look_pwd: case R.id.ic_look_pwd:
...@@ -464,6 +489,13 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login ...@@ -464,6 +489,13 @@ public class LoginActivity extends BaseActivity<LoginPresenter> implements Login
//記住密碼 //記住密碼
mRbRememberPwd.toggle(); mRbRememberPwd.toggle();
break; break;
case R.id.tv_auto_login_text:
//自動登陸
mRbAutoLogin.toggle();
if (mRbAutoLogin.isChecked()) {
mRbRememberPwd.setChecked(true);
}
break;
case R.id.tv_gsa_user_login: case R.id.tv_gsa_user_login:
//登陸 //登陸
if (edAccount.getText() != null && edPwd.getText() != null) { if (edAccount.getText() != null && edPwd.getText() != null) {
......
package com.gingersoft.gsa.cloud.user.login.mvp.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.gingersoft.gsa.cloud.user.login.R;
import com.gingersoft.gsa.cloud.user.login.di.component.DaggerWelcomeComponent;
import com.gingersoft.gsa.cloud.user.login.di.module.WelcomeModule;
import com.gingersoft.gsa.cloud.user.login.mvp.contract.WelcomeContract;
import com.gingersoft.gsa.cloud.user.login.mvp.presenter.WelcomePresenter;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import butterknife.BindView;
import static com.jess.arms.utils.Preconditions.checkNotNull;
public class WelcomeActivity extends BaseActivity<WelcomePresenter> implements WelcomeContract.View {
@BindView(R.id.content_view)
ConstraintLayout contentView;
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
DaggerWelcomeComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.welcomeModule(new WelcomeModule(this))
.build()
.inject(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.activity_welcome; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
ScaleAnimation animation = new ScaleAnimation(1.0f, 1.06f, 1.0f, 1.06f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(2000);
animation.setFillAfter(true);
contentView.setAnimation(animation);
animation.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
startActivity(new Intent(mContext, LoginActivity.class));
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
}
@Override
public void initIntent() {
}
@Override
public void initTopBar() {
}
@Override
public void initLanguage() {
}
@Override
public void initLayoutParams() {
}
@Override
public void initLayoutVisible() {
}
@Override
public void showLoading(String message) {
}
@Override
public void hideLoading() {
}
@Override
public void showMessage(@NonNull String message) {
checkNotNull(message);
ArmsUtils.snackbarText(message);
}
@Override
public void launchActivity(@NonNull Intent intent) {
checkNotNull(intent);
ArmsUtils.startActivity(intent);
}
@Override
public void killMyself() {
finish();
}
}
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/content_view"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/tv_welcome_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="多功能管理,讓管理更輕鬆"
android:textColor="@color/theme_color"
android:textSize="@dimen/sp_16"
app:layout_constraintVertical_chainStyle="packed"
app:layout_constraintBottom_toTopOf="@id/iv_welcome_center"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageView
android:id="@+id/iv_welcome_center"
android:layout_width="@dimen/dp_203"
android:layout_height="@dimen/dp_256"
android:layout_marginTop="@dimen/dp_36"
android:src="@mipmap/png_welcome_center"
app:layout_constraintVertical_bias="0.6"
app:layout_constraintBottom_toTopOf="@id/iv_welcome_logo"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_welcome_title" />
<ImageView
android:id="@+id/iv_welcome_logo"
android:layout_width="@dimen/dp_56"
android:layout_height="@dimen/dp_56"
android:layout_marginTop="@dimen/dp_16"
android:src="@mipmap/ic_logo"
app:layout_constraintBottom_toTopOf="@id/iv_welcome_bottom"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/iv_welcome_center" />
<ImageView
android:id="@+id/iv_welcome_bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="@mipmap/png_welcome_bottom"
app:layout_constraintBottom_toBottomOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?><!--<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"--> <?xml version="1.0" encoding="utf-8"?>
<!-- xmlns:app="http://schemas.android.com/apk/res-auto"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="match_parent"-->
<!-- android:fillViewport="true">-->
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
...@@ -99,8 +94,9 @@ ...@@ -99,8 +94,9 @@
app:layout_constraintRight_toLeftOf="@id/ic_look_pwd" app:layout_constraintRight_toLeftOf="@id/ic_look_pwd"
app:layout_constraintTop_toTopOf="@id/iv_login_pwd_icon" /> app:layout_constraintTop_toTopOf="@id/iv_login_pwd_icon" />
<CheckBox <CheckBox
android:id="@+id/rb_remember_password" android:id="@+id/rb_auto_login"
android:layout_width="@dimen/dp_30" android:layout_width="@dimen/dp_30"
android:layout_height="@dimen/dp_30" android:layout_height="@dimen/dp_30"
android:layout_marginTop="@dimen/dp_15" android:layout_marginTop="@dimen/dp_15"
...@@ -108,6 +104,28 @@ ...@@ -108,6 +104,28 @@
app:layout_constraintTop_toBottomOf="@id/ed_login_user_pwd" /> app:layout_constraintTop_toBottomOf="@id/ed_login_user_pwd" />
<TextView <TextView
android:id="@+id/tv_auto_login_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_5"
android:text="自動登陸"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/sp_14"
app:layout_constraintBottom_toBottomOf="@id/rb_auto_login"
app:layout_constraintLeft_toRightOf="@id/rb_auto_login"
app:layout_constraintTop_toTopOf="@id/rb_auto_login" />
<CheckBox
android:id="@+id/rb_remember_password"
android:layout_width="@dimen/dp_30"
android:layout_height="@dimen/dp_30"
android:layout_marginLeft="@dimen/dp_15"
android:layout_marginTop="@dimen/dp_15"
app:layout_constraintLeft_toRightOf="@id/tv_auto_login_text"
app:layout_constraintTop_toBottomOf="@id/ed_login_user_pwd" />
<TextView
android:id="@+id/tv_remember_pwd_text" android:id="@+id/tv_remember_pwd_text"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
...@@ -180,4 +198,5 @@ ...@@ -180,4 +198,5 @@
app:layout_constraintLeft_toLeftOf="parent" app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent" /> app:layout_constraintRight_toRightOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout><!--</ScrollView>--> </androidx.constraintlayout.widget.ConstraintLayout>
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