Commit dfa80941 by Wyh

7.10 prj打印測試版

parent 1e5bffbd
......@@ -156,7 +156,7 @@ public class ImageUtils {
Matrix matrix = new Matrix();
float scaleWidth = ((float) w / width);
float scaleHeight = ((float) h / height);
matrix.postScale(scaleWidth, scaleWidth);
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(oldbmp, 0, 0, width, height,
matrix, true);
}
......@@ -171,6 +171,17 @@ public class ImageUtils {
matrix, true);
}
public static Bitmap zoomDrawable(Bitmap oldbmp, int w, double heightMultiple) {
int width = oldbmp.getWidth();
int height = oldbmp.getHeight();
Matrix matrix = new Matrix();
float scaleWidth = ((float) w / width);
float scaleHeight = (float) (scaleWidth/heightMultiple);
matrix.postScale(scaleWidth, scaleHeight);
return Bitmap.createBitmap(oldbmp, 0, 0, width, height,
matrix, true);
}
/**
* 缩放图片
......
......@@ -66,6 +66,13 @@ public class PrinterDeviceBean implements Serializable {
this.flyPrinterDeviceId2 = flyPrinterDeviceId2;
}
public PrinterDeviceBean(String ip, Integer port, String paperSpecification) {
this.ip = ip;
this.port = port;
this.paperSpecification = paperSpecification;
}
public Long getId() {
return id;
}
......
......@@ -21,6 +21,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Matrix;
import com.gingersoft.gsa.cloud.base.R;
import com.gingersoft.gsa.cloud.base.utils.other.SPUtils;
import com.gingersoft.gsa.cloud.base.widget.DialogUtils;
......@@ -130,36 +131,8 @@ public class PrinterUtils {
* @param num 倍数
* @return bytes for this command
*/
public static byte[] fontSizeSetBig(int num) {
byte realSize = 0;
switch (num) {
case 0:
//noinspection ConstantConditions
realSize = 0;
break;
case 1:
realSize = 17;
break;
case 2:
realSize = 34;
break;
case 3:
realSize = 51;
break;
case 4:
realSize = 68;
break;
case 5:
realSize = 85;
break;
case 6:
realSize = 102;
break;
case 7:
realSize = 119;
break;
}
return PrintCommands.selectCharacterSize(realSize);
public static byte[] fontSizeSetBig(double num) {
return PrintCommands.selectCharacterSize((int) (17 * num));
}
/**
......@@ -168,6 +141,7 @@ public class PrinterUtils {
* and executes a full cut ( cuts the paper completely )
*
* @return bytes for this command
* @return bytes for this command
*/
public static byte[] feedPaperCut() {
return PrintCommands.selectCutModeAndCutPaper(1, 0);
......
......@@ -192,7 +192,7 @@ public abstract class PrinterWriter {
* @param size 文字大小 (0~7)(默认0)
* @throws IOException 异常
*/
public void setFontSize(int size) throws IOException {
public void setFontSize(double size) throws IOException {
write(PrinterUtils.fontSizeSetBig(size));
}
......
......@@ -49,9 +49,9 @@ public class PrinterWriter58mm extends PrinterWriter {
switch (textSize) {
default:
case 0:
return 31;
return 32;
case 1:
return 15;
return 16;
}
}
......
......@@ -49,9 +49,9 @@ public class PrinterWriter80mm extends PrinterWriter {
switch (textSize) {
default:
case 0:
return 47;
return 48;
case 1:
return 23;
return 24;
}
}
......
......@@ -13,63 +13,71 @@
android:layout_height="wrap_content"
android:text="19" />
<androidx.constraintlayout.widget.ConstraintLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/dp_10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_order_num_text"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="訂單號:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:text="訂單號:" />
<TextView
android:id="@+id/tv_order_num"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintLeft_toRightOf="@id/tv_order_num_text"
app:layout_constraintTop_toTopOf="@id/tv_order_num_text" />
android:orientation="horizontal">
<TextView
android:id="@+id/tv_opening_time_text"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="開檯時間:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_order_num_text" />
android:text="開檯時間:" />
<TextView
android:id="@+id/tv_opening_time"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="01-04 18:32"
app:layout_constraintLeft_toRightOf="@id/tv_opening_time_text"
app:layout_constraintTop_toTopOf="@id/tv_opening_time_text" />
android:text="01-04 18:32" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_order_time_text"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="落單時間:"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_opening_time_text" />
android:text="落單時間:" />
<TextView
android:id="@+id/tv_order_time"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="01-04 19:32"
app:layout_constraintLeft_toRightOf="@id/tv_order_time_text"
app:layout_constraintTop_toTopOf="@id/tv_order_time_text" />
android:text="01-04 19:32" />
</LinearLayout>
<TextView
android:id="@+id/tv_kitchen_location"
......@@ -77,9 +85,12 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:text="K1 廚房"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_order_time" />
android:text="K1 廚房" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_people_text"
......@@ -87,29 +98,23 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="人數:"
android:visibility="gone"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="@id/tv_kitchen_location" />
android:visibility="gone" />
<TextView
android:id="@+id/tv_people"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10"
app:layout_constraintBottom_toBottomOf="@id/tv_people_text"
app:layout_constraintLeft_toRightOf="@id/tv_people_text"
app:layout_constraintTop_toTopOf="@id/tv_people_text" />
android:text="1000"
android:visibility="gone" />
</LinearLayout>
<TextView
android:id="@+id/tv_operator"
style="@style/Print_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="gsadmin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@id/tv_people" />
android:text="gsadmin" />
<TextView
android:id="@+id/line_kitchen_info"
......@@ -117,25 +122,22 @@
android:layout_height="wrap_content"
android:maxLines="1"
android:text="——————————————————————————————————————————————————"
app:layout_constraintTop_toBottomOf="@id/tv_people_text" />
app:layout_constraintTop_toBottomOf="@id/tv_operator" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_kitchen_food"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_10"
app:layout_constraintTop_toBottomOf="@id/line_kitchen_info" />
android:layout_marginTop="@dimen/dp_10" />
<TextView
android:id="@+id/tv_kitchen_print_table_number2"
style="@style/Print_kitchen_table_number_text_style"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="19"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/rv_kitchen_food" />
</androidx.constraintlayout.widget.ConstraintLayout>
android:layout_gravity="center_horizontal"
android:text="19" />
</LinearLayout>
</LinearLayout>
\ No newline at end of file
......@@ -282,18 +282,18 @@
</style>
<style name="Print_text_style">
<item name="android:textColor">@color/theme_333_color</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">@dimen/sp_24</item>
</style>
<!-- 廚房單菜品名字體樣式-->
<style name="Print_large_text_style">
<item name="android:textColor">@color/theme_333_color</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">@dimen/sp_34</item>
</style>
<!-- 廚房單台號體樣式-->
<style name="Print_kitchen_table_number_text_style">
<item name="android:textColor">@color/theme_333_color</item>
<item name="android:textColor">@color/black</item>
<item name="android:textSize">@dimen/sp_38</item>
</style>
......
......@@ -7,8 +7,8 @@ ext {
targetSdkVersion : 28,
//正式版: 1.0.1 1
//內部測試版:1.1.1 11
versionCode : 13,
versionName : "1.1.3"
versionCode : 17,
versionName : "1.2.2"
]
version = [
......
......@@ -10,12 +10,11 @@ import com.gingersoft.gsa.cloud.base.common.bean.FoodBean;
import com.gingersoft.gsa.cloud.base.common.bean.RestaurantExpandInfoUtils;
import com.gingersoft.gsa.cloud.base.utils.CommonConfiguration;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.base.utils.MoneyUtil;
import com.gingersoft.gsa.cloud.constans.HttpsConstans;
import com.gingersoft.gsa.cloud.database.bean.Discount;
import com.gingersoft.gsa.cloud.database.bean.ExpandInfo;
import com.gingersoft.gsa.cloud.database.bean.Function;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterListBean;
import com.gingersoft.gsa.cloud.database.utils.ComboItemDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.DiscountDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.ExpandInfoDaoUtils;
......@@ -25,9 +24,10 @@ import com.gingersoft.gsa.cloud.database.utils.FoodModifierDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.FunctionDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.ModifierDaoUtils;
import com.gingersoft.gsa.cloud.database.utils.PrinterDeviceDaoUtils;
import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.ComboItemRespone;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FoodComboRespone;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.DataDownLoadState;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FoodComboRespone;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FoodModifierRespone;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.FunctionRespone;
import com.gingersoft.gsa.cloud.download.mvp.model.bean.ModifierRespone;
......@@ -35,10 +35,17 @@ import com.gingersoft.gsa.cloud.download.mvp.model.downmanager.DownloadManager;
import com.gingersoft.gsa.cloud.download.mvp.model.downmanager.DownloadRequest;
import com.gingersoft.gsa.cloud.download.mvp.ui.activity.DownloadActivity;
import com.gingersoft.gsa.cloud.download.mvp.ui.adapter.DataDownLoadAdapter;
import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.DeviceUtils;
import com.jess.arms.utils.RxLifecycleUtils;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.annotations.NonNull;
......@@ -47,15 +54,6 @@ import io.reactivex.schedulers.Schedulers;
import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;
import javax.inject.Inject;
import com.gingersoft.gsa.cloud.download.mvp.contract.DownloadContract;
import com.jess.arms.utils.DeviceUtils;
import com.jess.arms.utils.RxLifecycleUtils;
import java.util.ArrayList;
import java.util.List;
/**
* ================================================
......@@ -690,9 +688,9 @@ public class DownloadPresenter extends BasePresenter<DownloadContract.Model, Dow
if (result.getData() != null) {
PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(IActivity);
printerDeviceDaoUtils.deleteAll();
List<PrinterDeviceBean> printerDeviceBeanList = JsonUtils.parseArray(result.getData(), PrinterDeviceBean.class);
if (printerDeviceBeanList != null) {
printerDeviceDaoUtils.insertMultPrinterDeviceBean(printerDeviceBeanList);
PrinterListBean printerListBean = JsonUtils.parseObject(result.getData(), PrinterListBean.class);
if (printerListBean != null && printerListBean.getList() != null) {
printerDeviceDaoUtils.insertMultPrinterDeviceBean(printerListBean.getList());
}
}
DataDownLoadState loadState = mList.get(downTag);
......
......@@ -11,6 +11,7 @@
<uses-permission android:name="android.permission.WRITE_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.FOREGROUND_SERVICE"/>
<application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
......
......@@ -81,11 +81,6 @@ public class BaseLoginPresenter<M extends BaseLoginContract.Model, V extends Bas
GsaCloudApplication.userName = info.getData().getUser().getUserName();
mRootView.showMessage("登陸成功");
mRootView.loginSuccess(info);
//開啟Prj打印服務
CC.obtainBuilder("Component.Print")
.setActionName("openPrintService")
.build()
.call();
} else {
GsaCloudApplication.isLogin = false;
mRootView.showMessage(info.getErrMsg());
......
......@@ -101,6 +101,7 @@ public class LoginActivity extends LoginInterfaceImpl<LoginPresenter> implements
@Override
public void initData(@Nullable Bundle savedInstanceState) {
((ImageView)findViewById(R.id.iv_top_bg)).setAdjustViewBounds(true);
// inside your activity (if you did not enable transitions in your theme)
// getWindow().requestFeature(Window.FEATURE_CONTENT_TRANSITIONS);
// set an exit transition
......
......@@ -13,16 +13,19 @@
android:orientation="vertical">
<ImageView
android:id="@+id/iv_top_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:layout_height="wrap_content"
android:src="@drawable/img_login_top_bg" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:paddingLeft="@dimen/dp_19"
android:paddingRight="@dimen/dp_19"
android:layout_marginTop="@dimen/dp_20"
android:orientation="vertical">
<TextView
......@@ -30,14 +33,10 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginTop="80dp"
android:text="@string/user_login_welcome_login"
android:textColor="@color/theme_color"
android:textSize="@dimen/dp_20"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
android:textStyle="bold" />
<TextView
android:id="@+id/tv_account_text"
......@@ -206,22 +205,21 @@
app:layout_constraintTop_toTopOf="@id/rb_auto_login" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_gsa_user_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="@dimen/dp_50"
android:background="@drawable/selector_login_btn"
android:gravity="center"
android:layout_gravity="bottom"
android:layout_marginLeft="@dimen/dp_20"
android:layout_marginRight="@dimen/dp_20"
android:layout_marginTop="@dimen/dp_20"
android:layout_marginBottom="@dimen/dp_60"
android:text="登錄"
android:textColor="@color/white"
android:textSize="@dimen/dp_16" />
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
......@@ -173,6 +173,17 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
} else {
tv_version_name.setText("v_" + DeviceUtils.getVersionName(this));
}
}
@Override
protected void onStart() {
super.onStart();
//開啟Prj打印服務
CC.obtainBuilder("Component.Print")
.setActionName("openPrintService")
.build()
.call();
}
/**
......@@ -184,12 +195,13 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
if (BuildConfig.DEBUG) {
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "複製Token"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "查看日誌"));
// mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "查看日誌"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_mall_center, "商城中心"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_about_us, "關於我們"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_password, "修改密碼"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "設置"));
}
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "查看日誌"));
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_settlement_report, "清機"));
if (BuildConfig.DEBUG) {
mainSideMenuBeans.add(new MainSideMenuBean(R.drawable.ic_setting, "切換環境"));
......@@ -376,6 +388,12 @@ public class NewMainActivity extends BaseFragmentActivity<NewMainPresenter> impl
//切換餐廳,發送關閉接單的廣播,並清除心跳
sendBroadcast(new Intent(AppConstans.CLEAR_ORDER_RECEIVING_HEART));
//关闭Prj打印服務
CC.obtainBuilder("Component.Print")
.setActionName("stopPrintService")
.build()
.call();
BrandsBean.BrandsData brandsBean = RestaurantInfoUtils.getBrandByRestaurantId(brandsBeans, item.getId());
if (brandsBean != null) {
......
......@@ -22,6 +22,7 @@
<activity android:name=".ui.activity.DeliverySettingActivity" />
<activity android:name=".ui.activity.OrderDetailsActivity" />
<activity android:name=".ui.activity.PayActivity" />
<activity android:name=".ui.activity.LogActivity"/>
</application>
</manifest>
\ No newline at end of file
......@@ -3,7 +3,7 @@
package="com.gingersoft.gsa.other_order_mode">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK"/>
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
......@@ -13,7 +13,7 @@
android:networkSecurityConfig="@xml/network_android"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".ui.activity.LogActivity"/>
<activity android:name=".ui.activity.OrderDetailsActivity" />
<activity
android:name=".ui.activity.OtherOrderActivity"
......
......@@ -2,6 +2,7 @@ package com.gingersoft.gsa.other_order_mode.model.viewModel
import android.app.Dialog
import android.content.Context
import android.util.Log
import android.view.Gravity
import android.view.WindowManager
import android.widget.TextView
......@@ -22,6 +23,7 @@ import com.gingersoft.gsa.cloud.print.bean.OrderDetails
import com.gingersoft.gsa.other_order_mode.R
import com.gingersoft.gsa.other_order_mode.data.WeatherRepository
import com.gingersoft.gsa.other_order_mode.data.model.bean.*
import com.gingersoft.gsa.other_order_mode.service.GetInfoUpdateService
import com.gingersoft.gsa.other_order_mode.ui.adapter.DeliveryAdapter
import com.jess.arms.utils.ArmsUtils
import kotlinx.coroutines.Dispatchers
......@@ -40,6 +42,8 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
val CancelOrder = 1005//取消訂單
val CancelLogistics = 1006//取消物流
val ProductionComplete = 1007//製作完成
val DeliveryPrint = 1008//訂單確認成功,是否成功打印回調
}
var mOrderNum = arrayListOf<MutableLiveData<Int>>()
......@@ -110,7 +114,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
mOrderNum[0].value = num
}
}, {
it.printStackTrace()
})
}
......@@ -175,7 +179,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}
}, {
it.printStackTrace()
})
}
......@@ -189,6 +193,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}, {
//出錯
it.printStackTrace()
listener.invoke(null)
})
}
......@@ -262,7 +267,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
launch({
repository.updateIsRead(orderId)
}, {
it.printStackTrace()
})
}
......@@ -304,11 +309,15 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}, {
listener.invoke(0, false)
it.printStackTrace()
Log.e("eee", it.javaClass.name + "錯誤信息111:" + it.message)
GetInfoUpdateService.loginfo.append("錯誤信息111:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
GetInfoUpdateService.loginfo.append("\n")
})
}
fun gsUpdateOrderStatus(orderDetails: OrderDetails.DataBean, payTypeId: Int = 0, payName:String?, listener: (Int, Boolean) -> Unit) {
fun gsUpdateOrderStatus(orderDetails: OrderDetails.DataBean, payTypeId: Int = 0, payName: String?, listener: (Int, Boolean) -> Unit) {
launch({
repository.gsUpdateOrderStatus(orderDetails.ID.toString(), 4, orderDetails.order_type, 3, "", "", "", "0", "", 1, 0, payTypeId).apply {
orderDetails.payType = payTypeId
......@@ -322,12 +331,13 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}, {
listener.invoke(OrderDelivery, false)
it.printStackTrace()
// integralBean.postValue(null)
})
}
/**
* 待確認 --- 確認之後狀態變為 製作中,按鈕顯示:自取:製作完成,外賣:指派送貨----自取的狀態為待取餐,按鈕為結賬,外賣的狀態為派送中,按鈕顯示結賬
* 待確認--- 確認之後狀態變為 製作中,按鈕顯示:自取:製作完成,外賣:指派送貨----自取的狀態為待取餐,按鈕為結賬,外賣的狀態為派送中,按鈕顯示結賬
* 更新訂單信息,自取或是外賣
* status 0,1待確認
* 2 已確認,外賣是指派送單,自取是製作完成
......@@ -459,13 +469,28 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
launch({
//單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯
repository.addPrj(dataBean.Order_ID.toString(), restaurantId, ids.toString())
}, {})
GetInfoUpdateService.loginfo.append("添加PRJ:orderId:" + dataBean.Order_ID.toString() + "restaurantId:" + restaurantId + "orderDetailsIds:" + ids.toString())
GetInfoUpdateService.loginfo.append("\n")
}, {
it.printStackTrace()
Log.e("eee", "錯誤信息222:" + it.message)
GetInfoUpdateService.loginfo.append("錯誤信息222:" + it.message + " LOCALIZEDMESSAGE:" + it.localizedMessage + it.cause)
GetInfoUpdateService.loginfo.append("\n")
})
if (this.code == "1") {
// 打印印單
// 初始化用於打印的view
// 送單成功後,再調用接口獲取取餐碼
repository.getOrderInfo(dataBean.ID.toString()).apply {
printOrder(OrderDelivery, data?.get(0)!!, listener)
if(data != null && data!!.isNotEmpty()){
data?.get(0)?.let {
it.order_type = dataBean.order_type
it.orderPayType = dataBean.orderPayType
printOrder(DeliveryPrint, it, listener)
}
} else {
listener.invoke(OrderDelivery, false)
}
}
} else {
listener.invoke(OrderDelivery, false)
......@@ -478,7 +503,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
* 打印訂單
*/
private fun printOrder(code: Int, dataBean: OrderDetails.DataBean, listener: (Int, Boolean) -> Unit) {
//訂單信息和廚房單
//訂單信息和廚房單,打印前需要修改dataBean的order_type和orderPayType
MyOrderManage.setDataBean(dataBean)
CC.obtainBuilder("Component.Print")
.addParam(PrintConstans.PRINT_TYPE, 5)
......@@ -509,6 +534,13 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
* 打開錢箱
*/
fun openCashBox() {
launch({
//單獨包起來,哪怕這接口報錯也不要影響到正常的邏輯
repository.addPrj("11112364", "153", "48863116,48863117,48863119")
}, {
it.printStackTrace()
Log.e("eee", "錯誤信息222:" + it.message)
})
CC.obtainBuilder("Component.Print")
.addParam(PrintConstans.PRINT_TYPE, 6)
.addParam(PrintConstans.PRINT_LOADING, false)
......@@ -594,7 +626,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
}
}
}, {
it.printStackTrace()
})
} else {
ToastUtils.show(context, "請至少選擇一個送貨員")
......@@ -607,7 +639,7 @@ class PageViewModel(private val repository: WeatherRepository) : ViewModel() {
.show()
}
}, {
it.printStackTrace()
})
}
......
......@@ -18,11 +18,13 @@ import android.os.Build
import android.os.IBinder
import android.os.PowerManager
import android.util.Log
import android.util.TimeUtils
import android.widget.RemoteViews
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication
import com.gingersoft.gsa.cloud.base.utils.okhttpUtils.OkHttp3Utils
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtil
import com.gingersoft.gsa.cloud.constans.AppConstans
import com.gingersoft.gsa.cloud.constans.HttpsConstans
import com.gingersoft.gsa.other_order_mode.R
......@@ -43,7 +45,7 @@ class GetInfoUpdateService : Service() {
/**
* 心跳检测时间
*/
private val HEART_BEAT_RATE = (58 * 1000).toLong()//每隔15秒进行一次对长连接的心跳检测
private val HEART_BEAT_RATE = (27 * 1000).toLong()//每隔15秒进行一次对长连接的心跳检测
private val WEBSOCKET_HOST_AND_PORT = "${ServiceCreator.ROOT_URL}/ricepon-websocket/js/webSocketServer"//可替换为自己的主机名和端口号
private var mWebSocket: WebSocket? = null
......@@ -54,6 +56,11 @@ class GetInfoUpdateService : Service() {
private var newWakeLock: PowerManager.WakeLock? = null
companion object {
@kotlin.jvm.JvmField
var loginfo = StringBuffer()
}
val restaurantId by lazy {
GsaCloudApplication.getRestaurantId(this)
// 26
......@@ -81,7 +88,8 @@ class GetInfoUpdateService : Service() {
//SCREEN_DIM_WAKE_LOCK On Dim Off
//SCREEN_BRIGHT_WAKE_LOCK On Bright Off
//FULL_WAKE_LOCK On Bright Bright
newWakeLock?.acquire()
newWakeLock?.acquire(10 * 60 * 1000L /*10 minutes*/)
putTimeLog("創建服務onCreate")
}
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
......@@ -92,6 +100,7 @@ class GetInfoUpdateService : Service() {
} else {
startNotification()
}
putTimeLog("啟動服務onStartCommand")
return super.onStartCommand(intent, flags, startId)
}
......@@ -153,9 +162,23 @@ class GetInfoUpdateService : Service() {
// 初始化socket
private fun initSocket() {
RxTimerUtil.cancel()
RxTimerUtil.timer({
client = OkHttpClient.Builder().readTimeout(0, TimeUnit.MILLISECONDS).build()
putTimeLog("取消心跳")
RxTimerUtil.cancelInterval()
RxTimerUtil.interval({
newWakeLock?.acquire(10 * 60 * 1000L /*10 minutes*/)
putTimeLog("開啟心跳")
client?.let { it ->
mWebSocket?.let {
it.cancel()
it.send("-1")
it.close(1000, null)
}
it.dispatcher().cancelAll()
}
// if (client == null) {
client = OkHttpClient.Builder().readTimeout(9 * 10, TimeUnit.SECONDS).build()
// }
client?.let {
val request = Request.Builder()
.url(WEBSOCKET_HOST_AND_PORT)
......@@ -168,6 +191,7 @@ class GetInfoUpdateService : Service() {
val token = "weixin_" + restaurantId + "_" + getRandomString(24)
Log.e(TAG, "token:$token")
webSocket.send(Gson().toJson(MsgBean(1, token)))
putTimeLog("連接成功")
}
}
......@@ -179,7 +203,6 @@ class GetInfoUpdateService : Service() {
postCallBack!!.callBack(type)
}
//-1斷開連接,\n-2:消息傳輸錯誤,\n0:連接消息,\n1:登錄通知,\n2:登出通知,\n3:外賣送單通知,\n4:自取送單通知,\n5:歷史訂單通知,\n6:修改訂單狀態通知,\n7:支付成功通知"
if (type == 3 || type == 4 || type == 5
|| type == 6 || type == 7) {
if (type == 6) {
......@@ -191,6 +214,7 @@ class GetInfoUpdateService : Service() {
}
//收到服务器端传过来的消息text
Log.e(TAG, "onMessage:" + text!!)
putTimeLog("收到回調:$text")
}
override fun onMessage(webSocket: WebSocket?, bytes: ByteString?) {
......@@ -200,6 +224,7 @@ class GetInfoUpdateService : Service() {
postCallBack!!.callBack(json.optInt("type"))
}
Log.e(TAG, "onMessage222:" + bytes!!)
putTimeLog("onMessage222:$bytes")
}
override fun onClosing(webSocket: WebSocket?, code: Int, reason: String?) {
......@@ -207,12 +232,14 @@ class GetInfoUpdateService : Service() {
//連接斷開,
Log.e(TAG, "onClosing")
// InitSocketThread().start()//创建一个新的连接
putTimeLog("onClosing關閉連接")
}
override fun onClosed(webSocket: WebSocket?, code: Int, reason: String?) {
super.onClosed(webSocket, code, reason)
Log.e(TAG, "onClosed")
putTimeLog("onClosed斷開連接")
webSocket?.cancel()
}
......@@ -226,6 +253,7 @@ class GetInfoUpdateService : Service() {
webSocket?.cancel()
it.dispatcher().cancelAll()
}
putTimeLog("onFailure連接失敗,等待一分鐘後重新連接")
}
})
it.dispatcher().executorService().shutdown()
......@@ -234,6 +262,7 @@ class GetInfoUpdateService : Service() {
}
private var soundPool: SoundPool? = null
private var lastSoundTime: Long = 0L
fun initSoundPool() {
//实例化SoundPool
......@@ -269,6 +298,12 @@ class GetInfoUpdateService : Service() {
//4.通过FileDescriptor加载
//int load(FileDescriptor fd, long offset, long length, int priority)
//声音ID 加载音频资源,这里用的是第二种,第三个参数为priority,声音的优先级*API中指出,priority参数目前没有效果,建议设置为1。
val nowTime = System.currentTimeMillis()//當前時間減去上次播放的時間,如果超過五秒,那麼才會再次播放提示聲
Log.e("eee", "間隔時間" + (nowTime - lastSoundTime))
putTimeLog("現在時間:$nowTime 上次播放時間:$lastSoundTime")
if (nowTime - lastSoundTime > 5000) {
putTimeLog("新訂單播放:$nowTime")
lastSoundTime = System.currentTimeMillis()
val voiceId = soundPool!!.load(this, R.raw.newordervocal, 1)
//异步需要等待加载完成,音频才能播放成功
soundPool!!.setOnLoadCompleteListener { soundPool, sampleId, status ->
......@@ -283,6 +318,7 @@ class GetInfoUpdateService : Service() {
}
}
}
}
/*获取一条随机字符串*/
fun getRandomString(length: Int): String { //length表示生成字符串的长度
......@@ -325,6 +361,8 @@ class GetInfoUpdateService : Service() {
override fun onDestroy() {
super.onDestroy()
Log.e("eee", "onDestroy")
putTimeLog("服務銷毀onDestroy")
//清除心跳
clearHeart()
isDestroy = true
......@@ -340,7 +378,7 @@ class GetInfoUpdateService : Service() {
mWebSocket!!.close(1000, null)
}
//停止定時心跳
RxTimerUtil.cancel()
RxTimerUtil.cancelInterval()
//停止前台服務
stopForeground(true)
//清除保持喚醒
......@@ -363,6 +401,13 @@ class GetInfoUpdateService : Service() {
}
}
private fun putTimeLog(content: String) {
loginfo.append(TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS))
loginfo.append(":")
loginfo.append(content)
loginfo.append("\n")
}
interface PostCallBack {
fun callBack(type: Int)
}
......
package com.gingersoft.gsa.other_order_mode.ui.activity;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.gingersoft.gsa.other_order_mode.R;
import com.gingersoft.gsa.other_order_mode.service.GetInfoUpdateService;
public class LogActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_log);
loadInfo();
findViewById(R.id.btn_clear_log).setOnClickListener(v -> {
GetInfoUpdateService.loginfo.setLength(0);
loadInfo();
});
findViewById(R.id.btn_back).setOnClickListener(v ->finish());
}
private void loadInfo() {
((TextView) findViewById(R.id.tv_log)).setText(GetInfoUpdateService.loginfo.toString());
}
}
......@@ -21,6 +21,7 @@ import com.gingersoft.gsa.other_order_mode.data.model.bean.BtnBuilder
import com.gingersoft.gsa.other_order_mode.databinding.ActivityOrderDetailsBinding
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel.Companion.Closing
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel.Companion.DeliveryPrint
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel.Companion.OrderDelivery
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel.Companion.PrintCode
import com.gingersoft.gsa.other_order_mode.model.viewModel.PageViewModel.Companion.SendCode
......@@ -167,7 +168,7 @@ class OrderDetailsActivity : BaseActivity() {
cancelLogistics(orderDetails)
BtnBuilder.assignDeliveryBtn ->
//指派送貨
selectorDelivery(this@OrderDetailsActivity, orderDetails, 3) { status, isSuccess -> getOrderDetails(orderId, binding) }
selectorDelivery(this@OrderDetailsActivity, orderDetails, 3) { status, isSuccess -> finish() }
BtnBuilder.cancelBtn ->
//取消訂單
cancelOrder(orderDetails)
......@@ -192,6 +193,14 @@ class OrderDetailsActivity : BaseActivity() {
updateOrderStatusByBtn(btnList[position].type, orderDetails, GsaCloudApplication.getRestaurantId(this@OrderDetailsActivity).toString()) { status, isSuccess ->
cancelDialogForLoading()
when (status) {
DeliveryPrint -> {//訂單已確認,是否打印成功
finish()
ToastUtils.show(this@OrderDetailsActivity, if (isSuccess) {
"打印成功"
} else {
"打印失敗"
})
}
PrintCode -> {
ToastUtils.show(this@OrderDetailsActivity, if (isSuccess) {
"打印成功"
......@@ -205,6 +214,9 @@ class OrderDetailsActivity : BaseActivity() {
} else {
"指派送貨失敗"
})
if(isSuccess){
finish()
}
}
OrderDelivery -> {
//已確認訂單,重新刷新當前頁面
......@@ -236,7 +248,7 @@ class OrderDetailsActivity : BaseActivity() {
}
else -> {
cancelDialogForLoading()
ToastUtils.show(this@OrderDetailsActivity, "修改訂單狀態失敗")
// ToastUtils.show(this@OrderDetailsActivity, "修改訂單狀態失敗")
}
}
}
......
......@@ -446,6 +446,11 @@ class OtherOrderActivity : BaseActivity() {
pageViewModel.openCashBox()
pop!!.dismiss()
}
view.findViewById<QMUIAlphaTextView>(R.id.tv_check_log).setOnClickListener {
//查看日誌
startActivity(Intent(this, LogActivity::class.java))
pop!!.dismiss()
}
} else {
pop!!.show(it)
}
......
package com.gingersoft.gsa.other_order_mode.ui.activity
fun main() {
var aaa = "1234567891023456789"
var cd = aaa.length / 2
var buffer = StringBuffer()
if (cd >= 5) {
cd = aaa.length - 5
}
repeat(cd) {
buffer.append("*")
}
var bbb = aaa.substring(0, 1)
var ccc = aaa.substring(cd + 1, aaa.length)
print(bbb + buffer.toString() + ccc)
}
\ No newline at end of file
......@@ -8,14 +8,15 @@ import java.util.concurrent.TimeUnit
class RxTimerUtil {
companion object {
var mDisposable: Disposable? = null
var mIntervalDisposable: Disposable? = null
var timerDisposable: Disposable? = null
/**
* 执行定时任务
*/
fun timer(block: () -> Unit, milliseconds: Long) {
fun interval(block: () -> Unit, milliseconds: Long) {
Observable.interval(0, milliseconds, TimeUnit.MILLISECONDS)
.observeOn(AndroidSchedulers.mainThread())
.subscribeOn(AndroidSchedulers.mainThread())
.subscribe(object : Observer<Long> {
override fun onError(e: Throwable) {}
override fun onComplete() {}
......@@ -24,7 +25,7 @@ class RxTimerUtil {
}
override fun onSubscribe(d: Disposable) {
mDisposable = d
mIntervalDisposable = d
}
})
}
......@@ -32,10 +33,36 @@ class RxTimerUtil {
/**
* 取消定时器
*/
fun cancel() {
if (mDisposable != null && !mDisposable!!.isDisposed) {
mDisposable!!.dispose()
fun cancelInterval() {
if (mIntervalDisposable != null && !mIntervalDisposable!!.isDisposed) {
mIntervalDisposable!!.dispose()
}
}
fun cancelTimerDisposable() {
if (timerDisposable != null && !timerDisposable!!.isDisposed) {
timerDisposable!!.dispose()
}
}
fun delayFun(block: () -> Unit, milliseconds: Long) {
Observable.timer(milliseconds, TimeUnit.SECONDS)
.subscribe(object : Observer<Long> {
override fun onSubscribe(d: Disposable) {
timerDisposable = d
}
override fun onNext(t: Long) {
block()
}
override fun onError(e: Throwable) {
}
override fun onComplete() {
}
})
}
}
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
tools:context=".ui.activity.LogActivity">
<Button
android:id="@+id/btn_back"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_50"
android:layout_alignParentBottom="true"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:layout_marginBottom="@dimen/dp_10"
android:text="返回"
android:textSize="@dimen/dp_16" />
<Button
android:id="@+id/btn_clear_log"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_50"
android:layout_above="@id/btn_back"
android:layout_margin="@dimen/dp_10"
android:text="清空日誌"
android:textSize="@dimen/dp_16" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/btn_clear_log"
android:scrollbars="vertical"
android:layout_alignParentTop="true">
<TextView
android:id="@+id/tv_log"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:layout_marginTop="@dimen/dp_10"
android:layout_marginRight="@dimen/dp_10"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_16" />
</ScrollView>
</RelativeLayout>
\ No newline at end of file
......@@ -47,4 +47,19 @@
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_14" />
<include layout="@layout/include_horizontal_color_ccc_dividing_line" />
<com.qmuiteam.qmui.alpha.QMUIAlphaTextView
android:id="@+id/tv_check_log"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="@dimen/dp_20"
android:paddingTop="@dimen/dp_10"
android:paddingRight="@dimen/dp_20"
android:paddingBottom="@dimen/dp_10"
android:text="查看日誌"
android:textColor="@color/theme_333_color"
android:textSize="@dimen/dp_14" />
</LinearLayout>
......@@ -42,6 +42,7 @@ dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation 'androidx.appcompat:appcompat:1.1.0'
//不要超過1.0.2,不然android5.1.1用webview會有問題
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
annotationProcessor rootProject.ext.dependencies["dagger2-compiler"]
......
......@@ -2,6 +2,7 @@
package="com.joe.print">
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE"/>
<application>
<activity
android:name=".mvp.ui.activity.PrintActivity"
......
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joe.print">
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joe.print">
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
<uses-permission android:name="android.permission.WAKE_LOCK" />
<application
android:name="com.gingersoft.gsa.cloud.base.application.GsaCloudApplication"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
......@@ -23,7 +23,7 @@
android:theme="@style/AppTheme">
<activity android:name=".mvp.ui.activity.PrintActivity" />
<activity android:name=".mvp.ui.activity.PrinterAddActivity" />
<activity android:name=".mvp.ui.activity.PrinterListActivity">
<activity android:name=".mvp.ui.activity.PrintTestActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<action android:name="android.intent.action.VIEW" />
......@@ -31,10 +31,11 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.joe.print.mvp.ui.activity.PrinterListActivity"/>
<meta-data
android:name="com.gingersoft.gsa.cloud.globalconfig.GlobalConfiguration"
android:value="ConfigModule" />
</application>
</application>
</manifest>
<resources>
<string name="app_name">PrintModule</string>
</resources>
......@@ -55,6 +55,10 @@ public class PrintComponent implements IComponent {
cc.getContext().startService(intent);
CC.sendCCResult(cc.getCallId(), CCResult.success());
break;
case "stopPrintService":
cc.getContext().stopService(new Intent(cc.getContext(), PrjService.class));
CC.sendCCResult(cc.getCallId(), CCResult.success());
break;
default:
// cc.callAsync(new IComponentCallback() {
// @Override
......
package com.joe.print.mvp.model.bean;
public class PrintInfoBean {
//數組多長就有多少列
private String[] content;
// private int[] widght;//每列佔比權重
private Boolean[] isBold = new Boolean[]{false};
private int[] color = new int[]{0};
private double[] size = new double[]{0};
//content數量為1時才生效,默認居中
private int gravity = 1;
public PrintInfoBean(String[] content) {
this.content = content;
}
public PrintInfoBean(String[] content, double[] size) {
this.content = content;
this.size = size;
}
public PrintInfoBean(String[] content, int gravity) {
this.content = content;
this.gravity = gravity;
}
public PrintInfoBean(String[] content, Boolean[] isBold) {
this.content = content;
this.isBold = isBold;
}
public PrintInfoBean(String[] content, double[] size, int gravity) {
this.content = content;
this.size = size;
this.gravity = gravity;
}
public PrintInfoBean(String[] content, Boolean[] isBold, int gravity) {
this.content = content;
this.isBold = isBold;
this.gravity = gravity;
}
public PrintInfoBean(String[] content, Boolean[] isBold, double[] size) {
this.content = content;
this.isBold = isBold;
this.size = size;
}
public PrintInfoBean(String[] content, Boolean[] isBold, double[] size, int gravity) {
this.content = content;
this.isBold = isBold;
this.size = size;
this.gravity = gravity;
}
public String[] getContent() {
return content;
}
public void setContent(String[] content) {
this.content = content;
}
public Boolean[] getIsBold() {
return isBold;
}
public void setIsBold(Boolean[] isBold) {
this.isBold = isBold;
}
public int[] getColor() {
return color;
}
public void setColor(int[] color) {
this.color = color;
}
public double[] getSize() {
return size;
}
public void setSize(double[] size) {
this.size = size;
}
public int getGravity() {
return gravity;
}
public void setGravity(int gravity) {
this.gravity = gravity;
}
}
......@@ -5,6 +5,7 @@ import android.app.Application;
import com.gingersoft.gsa.cloud.base.common.bean.BaseResult;
import com.gingersoft.gsa.cloud.base.common.bean.PrinterManger.PrinterManager;
import com.gingersoft.gsa.cloud.base.utils.JsonUtils;
import com.gingersoft.gsa.cloud.database.bean.PrintModelBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.database.bean.PrinterListBean;
import com.jess.arms.di.scope.FragmentScope;
......@@ -13,7 +14,6 @@ import com.jess.arms.integration.AppManager;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.utils.RxLifecycleUtils;
import com.joe.print.mvp.contract.IpPrintListActivityContract;
import com.gingersoft.gsa.cloud.database.bean.PrintModelBean;
import java.util.List;
......
......@@ -2,9 +2,11 @@ package com.joe.print.mvp.print;
import android.content.Context;
import android.graphics.Bitmap;
import android.util.Log;
import com.epson.epos2.Epos2Exception;
import com.epson.epos2.printer.Printer;
import com.epson.epos2.printer.PrinterStatusInfo;
import com.epson.epos2.printer.ReceiveListener;
public class EpsonPrint {
......@@ -52,6 +54,7 @@ public class EpsonPrint {
mPrinter.clearCommandBuffer();
}
private int lineCount = 42;
/**
* 創建打印數據
*
......@@ -59,7 +62,7 @@ public class EpsonPrint {
*/
private boolean createPrintData(Bitmap bitmap) {
// String method = "";
// StringBuilder textData = new StringBuilder();
StringBuilder textData = new StringBuilder();
// final int barcodeWidth = 2;
// final int barcodeHeight = 100;
if (mPrinter == null) {
......@@ -70,29 +73,58 @@ public class EpsonPrint {
// mPrinter.addPulse(Printer.PARAM_DEFAULT,
// Printer.PARAM_DEFAULT);
// method = "addTextAlign";
// mPrinter.addTextAlign(Printer.ALIGN_CENTER);
// mPrinter.addPageBegin();
// mPrinter.addTextFont(Printer.FONT_A);
// mPrinter.addTextLang(Printer.LANG_ZH_TW);
mPrinter.addTextAlign(Printer.ALIGN_CENTER);
// method = "addImage";
Log.e("ccc", "Epson寬度:" + bitmap.getWidth() + "高度:" + bitmap.getHeight());
mPrinter.addImage(bitmap, 0, 0,
bitmap.getWidth(),
bitmap.getHeight(),
Printer.COLOR_NONE,
Printer.MODE_MONO,
Printer.HALFTONE_DITHER,
Printer.COLOR_1,
Printer.MODE_MONO_HIGH_DENSITY,//高密度
Printer.HALFTONE_DITHER,//半色調抖動
Printer.PARAM_DEFAULT,
Printer.COMPRESS_AUTO);
Printer.COMPRESS_NONE);//壓縮
//COLOR_NONE 為普通顏色 COLOR_2為紅色
// method = "addCut";
// mPrinter.addTextSize(2, 2);
// mPrinter.addTextStyle(0,0,1, Printer.COLOR_1);
// mPrinter.addText("炒爐打印測試\n");
//
// //第一個參數不清楚作用,第二個參數ul是加下劃線,第三個參數em是加深顏色,第四個參數color修改文字顏色
// mPrinter.addTextAlign(Printer.ALIGN_LEFT);
// mPrinter.addTextStyle(0,0,0, Printer.COLOR_1);
// mPrinter.addText("時間:" + TimeUtil.getCurrentDate(TimeUtil.dateFormatYMDHMS)+"\n");
// mPrinter.addTextSize(1, 1);
// mPrinter.addText("-------項目-------\n");
// mPrinter.addText("--測試子食品 x1\n");
// mPrinter.addTextAlign(Printer.ALIGN_CENTER);
// mPrinter.addText("----Powered by Gingersoft----\n");
// mPrinter.addTextLang(Printer.LANG_ZH_TW);
// textData.append("------項目-----\n");
// textData.append("測試食品 x1\n");
// textData.append("測試子食品 x1\n");
// mPrinter.addTextSize(3, 3);
// mPrinter.addText(textData.toString());
// textData.setLength(0);
// mPrinter.addFeedLine(2);
// mPrinter.addPageEnd();
mPrinter.addCut(Printer.CUT_FEED);
// method = "addFeedLine";
// mPrinter.addFeedLine(1);
// textData.append("THE STORE 123 (555) 555 – 5555\n");
// textData.append("STORE DIRECTOR – John Smith\n");
// textData.append("\n");
// textData.append("\n");
// textData.append("7/01/07 16:58 6153 05 0191 134\n");
// textData.append("ST# 21 OP# 001 TE# 01 TR# 747\n");
// textData.append("------------------------------\n");
// method = "addText";
// mPrinter.addText(textData.toString());
// mPrinter.addTextStyle(0,0,0,Printer.COLOR_2);
// mPrinter.addText(textData.toString());
// mPrinter.addCut(Printer.CUT_FEED);
// textData.delete(0, textData.length());
//
// textData.append("400 OHEIDA 3PK SPRINGF 9.99 R\n");
......@@ -142,15 +174,17 @@ public class EpsonPrint {
// textData.delete(0, textData.length());
// method = "addFeedLine";
// mPrinter.addFeedLine(2);
// mPrinter.addPageEnd();
// mPrinter.addCut(Printer.CUT_FEED);
//
// method = "addBarcode";
// mPrinter.addBarcode("01209457",
// Printer.BARCODE_CODE39,
// Printer.HRI_BELOW,
// Printer.FONT_A,
// barcodeWidth,
// barcodeHeight);
// 2, 100);
} catch (Exception e) {
e.printStackTrace();
mPrinter.clearCommandBuffer();
return false;
}
......@@ -158,6 +192,14 @@ public class EpsonPrint {
return true;
}
// private String getDataByTextSize(int textsize){
//
//
//
//
// }
public boolean printData(String ip, Bitmap bitmap) {
if (!createPrintData(bitmap)) {
return false;
......@@ -165,11 +207,14 @@ public class EpsonPrint {
if (mPrinter == null) {
return false;
}
if (!connectPrinter(ip)) {
mPrinter.clearCommandBuffer();
return false;
}
// loginfo(mPrinter.getStatus());
connectPrinter(ip);
// if (!connectPrinter(ip)) {
// mPrinter.clearCommandBuffer();
// return false;
// }
try {
loginfo(mPrinter.getStatus());
mPrinter.sendData(Printer.PARAM_DEFAULT);
} catch (Exception e) {
mPrinter.clearCommandBuffer();
......@@ -185,6 +230,24 @@ public class EpsonPrint {
return true;
}
private void loginfo(PrinterStatusInfo statusInfo) {
int connection = statusInfo.getConnection();
int online = statusInfo.getOnline();
int coverOpen = statusInfo.getCoverOpen();
int paper = statusInfo.getPaper();
int paperFeed = statusInfo.getPaperFeed();
int panelSwitch = statusInfo.getPanelSwitch();
int waitOnline = statusInfo.getOnline();
int drawer = statusInfo.getDrawer();
int errorStatus = statusInfo.getErrorStatus();
int autoRecoverError = statusInfo.getAutoRecoverError();
int buzzer = statusInfo.getBuzzer();
int adapter = statusInfo.getAdapter();
int batteryLevel = statusInfo.getBatteryLevel();
Log.e("eee", "connection->" + connection + "online->" + online + "coverOpen->" + coverOpen + "paper->" + paper + "paperFeed->" + paperFeed + "panelSwitch->" + panelSwitch + "waitOnline->" + waitOnline + "drawer->" + drawer + "errorStatus->" + errorStatus + "autoRecoverError->" + autoRecoverError + "buzzer->" + buzzer + "adapter->" + adapter + "batteryLevel->" + batteryLevel);
}
private boolean isConnect = false;
private boolean connectPrinter(String ip) {
......
......@@ -9,11 +9,7 @@ import android.widget.TextView;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import com.gingersoft.gsa.cloud.base.adapter.print.KitChenPrintFoodAdapter;
import com.gingersoft.gsa.cloud.base.application.GsaCloudApplication;
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.OpenTableManage;
import com.gingersoft.gsa.cloud.base.utils.other.TextUtil;
import com.gingersoft.gsa.cloud.base.utils.time.TimeUtils;
import com.joe.print.R;
......@@ -24,11 +20,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import static com.gingersoft.gsa.cloud.base.common.bean.OrderDetail.DISCOUNT_TYPE;
import static com.gingersoft.gsa.cloud.base.common.bean.OrderDetail.FOOD_TYPE;
import static com.gingersoft.gsa.cloud.base.common.bean.OrderDetail.MODIFIER_TYPE;
/**
* 廚房單打印
......@@ -45,10 +36,22 @@ public class PrintPrjKitchen extends PrinterRoot {
String key = entry.getKey();
List<Bitmap> bitmaps = new ArrayList<>();
Bitmap bitmap = getKitChenPrintBitmap(mContext, key, entry.getValue());
List<PrjBean.DataBean.Bean> noCut = new ArrayList<>();
//不帶*號,所有同樣廚房位置的食品都在一張紙上
for (PrjBean.DataBean.Bean bean : entry.getValue()) {
if (bean.getStatus() == 2) {
List<PrjBean.DataBean.Bean> beans = new ArrayList<>();
beans.add(bean);
Bitmap bitmap = getKitChenPrintBitmap(mContext, key, beans);
bitmaps.add(bitmap);
} else {
noCut.add(bean);
}
}
if(noCut.size()>0) {
Bitmap bitmap = getKitChenPrintBitmap(mContext, key, noCut);
bitmaps.add(bitmap);
}
bitmapMaps.put(key, bitmaps);
}
prjMap.clear();
......@@ -88,6 +91,7 @@ public class PrintPrjKitchen extends PrinterRoot {
}
}
}
// PrintHelper
View view = LinearLayout.inflate(context, R.layout.print_kitchen, null);
TextView tvTableNumber = view.findViewById(R.id.tv_kitchen_print_table_number);
TextView tvOrderNumber = view.findViewById(R.id.tv_order_num);
......@@ -113,9 +117,10 @@ public class PrintPrjKitchen extends PrinterRoot {
tvTableNumber.setText(data.get(0).getTableName());
tvTableNumber2.setText(data.get(0).getTableName());
//人數
if(data.get(0).getPerson() != 0) {
if (data.get(0).getPerson() != 0) {
tvPeople.setText(data.get(0).getPerson() + "");
view.findViewById(R.id.tv_people_text).setVisibility(View.VISIBLE);
view.findViewById(R.id.tv_people).setVisibility(View.VISIBLE);
}
//訂單號
tvOrderNumber.setText(data.get(0).getOrderNo());
......@@ -136,7 +141,7 @@ public class PrintPrjKitchen extends PrinterRoot {
//落單時間,為當前時間
tvOrderTime.setText(TimeUtils.getCurrentTimeInString(TimeUtils.DEFAULT_DATE_FORMAT));
//操作人員
tvOperator.setText("");
tvOperator.setText(GsaCloudApplication.getMemberName(context));
return viewToBitmap(context, view);
}
......
......@@ -353,7 +353,7 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
private void defaultPrint(List<PrinterDeviceBean> printerDeviceBeans, List<Bitmap> bitmaps) {
//獲取默認打印方式,本機、IP
String deftultPrint = (String) SPUtils.get(mContext, PrintConstans.DEFAULT_PRINT_METHOD, "");
if (deftultPrint.equals("")) {
if (deftultPrint != null && deftultPrint.equals("")) {
// 如果沒有默認打印位置,彈出彈窗讓用戶選擇是本機打印還是ip打印
new DialogUtils(mContext, R.layout.print_dialog_select_device) {
@Override
......@@ -390,7 +390,7 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
});
}
}.show();
} else if (deftultPrint.equals(PrintConstans.LOCAL_PRINT)) {
} else if (deftultPrint != null && deftultPrint.equals(PrintConstans.LOCAL_PRINT)) {
// 默認打印方式為本地,進行本地打印
locationPrint(bitmaps, new PrintListener() {
@Override
......@@ -408,7 +408,7 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
setPrintState(PrintActivity.FINISH);
}
});
} else if (deftultPrint.equals(PrintConstans.IP_PRINT)) {
} else if (deftultPrint != null && deftultPrint.equals(PrintConstans.IP_PRINT)) {
// 默認打印方式為ip打印,調用ip打印方法
// 獲取默認ip打印機
if (printerDeviceBeans != null && printerDeviceBeans.size() > 0) {
......@@ -466,7 +466,8 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
}
}
.setHeight(ArmsUtils.getScreenHeidth(mContext) / 2)
.setOnDismissListener(dialog -> setPrintState(PrintActivity.DIMISS_LOADING))
.setWidth((int) (ArmsUtils.getScreenWidth(mContext) * 0.8))
.setOnDismissListener(dialog -> setPrintState(PrintActivity.FINISH))
.show();
}
} else {
......@@ -499,21 +500,23 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
printWidth = 480;
printerDeviceBean.setPaperSpecification(printWidth + "");
}
Log.e("ccc", "紙張寬度:" + printWidth);
//獲取打印機機型,如果是EPSON的打印機,調用EPSON的打印方法
if ((printerDeviceBean.getPrinterName() != null && printerDeviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase()))
&& (printerDeviceBean.getModel() != null && printerDeviceBean.getModel().toLowerCase().contains("TM-U220B".toLowerCase()))) {
List<Bitmap> zoomBitmap = null;
if (bitmaps != null) {
zoomBitmap = new ArrayList<>();
for (int i = 0; i < bitmaps.size(); i++) {
zoomBitmap.add(ImageUtils.zoomDrawable(bitmaps.get(i), printWidth));
if(bitmaps.get(i) != null) {
Bitmap newBitmap = ImageUtils.zoomDrawable(bitmaps.get(i), printWidth, 2d);
zoomBitmap.add(newBitmap);
}
}
}
if (zoomBitmap == null) {
printListener.printFile();
return;
}
//獲取打印機機型,如果是EPSON的打印機,調用EPSON的打印方法
if (printerDeviceBean.getPrinterName().toLowerCase().contains("EPSON".toLowerCase())
|| printerDeviceBean.getModel().toLowerCase().contains("EPSON".toLowerCase())) {
List<Bitmap> finalZoomBitmap = zoomBitmap;
mPrinter = new EpsonPrint();
mPrinter.initializeObject(mContext, this);
......@@ -532,6 +535,19 @@ public abstract class PrinterRoot implements PrintSocketHolder.OnStateChangedLis
}
}).start();
} else {
List<Bitmap> zoomBitmap = null;
if (bitmaps != null) {
zoomBitmap = new ArrayList<>();
for (int i = 0; i < bitmaps.size(); i++) {
Bitmap newBitmap = ImageUtils.zoomDrawable(bitmaps.get(i), printWidth);
Log.e("eee", "寬度:" + newBitmap.getWidth() + "高度:" + newBitmap.getHeight());
zoomBitmap.add(newBitmap);
}
}
if (zoomBitmap == null) {
printListener.printFile();
return;
}
PrintExecutor executor = new PrintExecutor(printerDeviceBean);
executor.setOnStateChangedListener(stateChangedListener);
executor.setOnPrintResultListener(resultListener);
......
package com.joe.print.mvp.print;
import com.gingersoft.gsa.cloud.print.PrintDataMaker;
import com.gingersoft.gsa.cloud.print.PrinterWriter;
import com.gingersoft.gsa.cloud.print.PrinterWriterExecutor;
import com.joe.print.mvp.model.bean.PrintInfoBean;
import java.util.ArrayList;
import java.util.List;
/**
* Created by Wyh on 2020/1/9.
* ip打印類
*/
public class TestPrintMaker implements PrintDataMaker {
private PrinterWriter printer;
private List<PrintInfoBean> printInfoBeans;
public TestPrintMaker(PrinterWriter printer, List<PrintInfoBean> printInfoBeans) {
this.printer = printer;
this.printInfoBeans = printInfoBeans;
}
@Override
public List<byte[]> getPrintData() {
ArrayList<byte[]> data = new ArrayList<>();
try {
for (PrintInfoBean printInfoBean : printInfoBeans) {
if (printInfoBean.getGravity() == 0) {
printer.setAlignLeft();
}
if (printInfoBean.getGravity() == 1) {
printer.setAlignCenter();
}
if (printInfoBean.getGravity() == 2) {
printer.setAlignRight();
}
if(printInfoBean.getSize().length > 1){
//如果打印多列內容,並且字體大小配置多個,則每一列取自己對應的字體大小
for (int i = 0; i < printInfoBean.getSize().length; i++) {
//打印多列
if (printInfoBean.getIsBold()[i]) {
printer.setEmphasizedOn();
} else {
printer.setEmphasizedOff();
}
printer.setFontSize(printInfoBean.getSize()[i]);
printer.print(printInfoBean.getContent()[i]);
}
} else {
if(printInfoBean.getContent().length == 1){
//如果只打印一列內容,則字體大小只取size數組的第一個
if (printInfoBean.getIsBold()[0]) {
printer.setEmphasizedOn();
} else {
printer.setEmphasizedOff();
}
printer.setFontSize(printInfoBean.getSize()[0]);
printer.print(printInfoBean.getContent()[0]);
}
}
printer.print("\n");
}
printer.printLineFeed();
printer.printLineFeed();
printer.feedPaperCutPartial();
data.add(printer.getDataAndReset());
data.add(printer.getDataAndClose());
return data;
} catch (Exception e) {
return new ArrayList<>();
}
}
}
......@@ -57,13 +57,17 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
super.onCreate();
//讀取本地ip打印機
Log.e("eee", "開啟打印服務");
if (printerDeviceBeans == null) {
getPrintList();
//開始請求
startGetPrjInfo();
}
private void getPrintList() {
if (printerDeviceBeans == null || printerDeviceBeans.size() == 0) {
PrinterDeviceDaoUtils printerDeviceDaoUtils = new PrinterDeviceDaoUtils(this);
printerDeviceBeans = printerDeviceDaoUtils.queryAllPrinterDeviceBean();
printerDeviceDaoUtils.closeConnection();
}
//開始請求
startGetPrjInfo();
}
@Nullable
......@@ -110,7 +114,7 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
private void getPrjInfo() {
OkHttp3Utils.get(HttpsConstans.ROOT_SERVER_ADDRESS_FORMAL + "printerRecording/get?restaurantId=" + GsaCloudApplication.getRestaurantId(this))
.subscribeOn(Schedulers.io())//切换到io线程進行網絡請求
.observeOn(AndroidSchedulers.mainThread())//切換到主線程處理請求結果
.observeOn(Schedulers.io())//切換到io线程處理請求結果
.subscribe(new Observer<String>() {
@Override
......@@ -124,6 +128,9 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
//請求到數據,停止輪詢,開始打印,在打印完之後再重新開始輪詢
startPrint(s);
//開啟另一個定時,三十秒之後自動請求,避免上面的打印成功或失敗時沒有回調。
if(wakeDisposable != null){
wakeDisposable.dispose();
}
Observable.timer(10, TimeUnit.SECONDS)
.subscribe(new Observer<Long>() {
@Override
......@@ -192,7 +199,8 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
// if (key.equals("-1")) {
// PrintPrjKitchen.getPrjMap().put("", datas);
// } else {
Log.e("eee", "打印數據條數:" + datas.size());
Log.e("eee", key + "打印數據條數:" + datas.size());
PrintPrjKitchen.getPrjMap().put(key, datas);
// }
printDatas.addAll(datas);
......@@ -204,14 +212,19 @@ public class PrjService extends Service implements PrintSocketHolder.OnStateChan
if (printerInIt == null) {
printerInIt = PrinterRoot.getPrinterByType(PRINT_KITCHEN);
}
// if(printerInIt != null && printerInIt.getPrintBitmap(this).size() <=0){
// return;
// }
getPrintList();
if (printerInIt != null) {
Log.e("aaa", "打印機數量:" +printerDeviceBeans.size());
printerInIt.setmContext(this);
for (Map.Entry<String, List<Bitmap>> entry : printerInIt.getPrintBitmap(this).entrySet()) {
//遍歷所有的需要打印的內容
for (int i = 0; i < printerDeviceBeans.size(); i++) {
//遍歷打印機列表,找到對應的打印機,沒找到的就不打印
if (entry.getKey().equalsIgnoreCase(printerDeviceBeans.get(i).getName())) {
Log.e("eee", entry.getKey() + "開始打印IP:" + printerDeviceBeans.get(i).getIp());
printerInIt.ipDevicePrint(printerDeviceBeans.get(i), entry.getValue(), this, this);
break;
}
......
package com.joe.print.mvp.ui.activity;
import androidx.appcompat.app.AppCompatActivity;
import androidx.print.PrintHelper;
import android.os.Bundle;
import com.gingersoft.gsa.cloud.database.bean.PrinterDeviceBean;
import com.gingersoft.gsa.cloud.print.PrintExecutor;
import com.gingersoft.gsa.cloud.print.PrintSocketHolder;
import com.gingersoft.gsa.cloud.print.PrinterWriter80mm;
import com.joe.print.R;
import com.joe.print.mvp.model.bean.PrintInfoBean;
import com.joe.print.mvp.print.IpPrintMaker;
import com.joe.print.mvp.print.TestPrintMaker;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
public class PrintTestActivity extends AppCompatActivity implements PrintSocketHolder.OnStateChangedListener, PrintExecutor.OnPrintResultListener {
private int lineLength = 42;//一行42個
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_print_test);
PrinterDeviceBean printerDeviceBean = new PrinterDeviceBean("192.168.1.218", 9100, "400");
List<PrintInfoBean> printInfoBeans = new ArrayList<>();
printInfoBeans.add(new PrintInfoBean(new String[]{"正式測試品牌"}, new double[]{1}));
printInfoBeans.add(new PrintInfoBean(new String[]{"純屬餐廳"}, new double[]{1}));
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("自取", 1.5)}, new Boolean[]{true}, new double[]{1.5}));
printInfoBeans.add(new PrintInfoBean(new String[]{"貨到付款"}, new Boolean[]{true}, new double[]{1.5}));
printInfoBeans.add(new PrintInfoBean(new String[]{"07-08(週三)立即"}, new double[]{1.5}));
printInfoBeans.add(new PrintInfoBean(new String[]{getLineBorder("", 1)}));
findViewById(R.id.btn_test).setOnClickListener(view -> {
//打印測試
PrintHelper helper = new PrintHelper(this);
// helper.printBitmap("192.168.1.218", );
PrintExecutor executor = new PrintExecutor(printerDeviceBean);
executor.setOnStateChangedListener(this);
executor.setOnPrintResultListener(this);
TestPrintMaker maker = null;
try {
maker = new TestPrintMaker(new PrinterWriter80mm(255), printInfoBeans);
} catch (IOException e) {
e.printStackTrace();
}
executor.doPrinterRequestAsync(maker);
});
}
@Override
public void onResult(int errorCode, PrinterDeviceBean printerDeviceBean) {
}
@Override
public void onStateChanged(int state, PrinterDeviceBean printerDeviceBean) {
}
private String getLineBorder(String text, double fontSize) {
if(fontSize == 0){
fontSize = 1;
}
int count = (int) ((lineLength / fontSize) - text.length());
StringBuilder builder = new StringBuilder();
for (int i = 0; i < count / 2; i++) {
builder.append("-");
}
builder.append(text);
for (int i = 0; i < count / 2; i++) {
builder.append("-");
}
return builder.toString();
}
}
......@@ -116,12 +116,12 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
mTvModel.setText(printerDeviceBean.getPrinterName() + "\u3000" + printerDeviceBean.getModel());
}
}
mSwitchDefalute.setChecked(printerDeviceBean.getType() == 2);
mSwitchDefalute.setChecked(printerDeviceBean.getPrinterDeviceDefaultId() != null);
if (devicess != null && devicess.size() > 0) {
if (printerDeviceBean.getFlyPrinterDeviceId() != null && printerDeviceBean.getFlyPrinterDeviceId() != 0) {
//有飛單
for (int i = 0; i < devicess.size(); i++) {
if (devicess.get(i).getId() == printerDeviceBean.getFlyPrinterDeviceId()) {
if (devicess.get(i).getId().equals(printerDeviceBean.getFlyPrinterDeviceId())) {
mTvFailNameOne.setText(devicess.get(i).getName());
oneFailPosition = i;
mTvFailNameOne.setTextColor(getResources().getColor(R.color.color_3c));
......@@ -131,7 +131,7 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
if (printerDeviceBean.getFlyPrinterDeviceId2() != null && printerDeviceBean.getFlyPrinterDeviceId2() != 0) {
//有飛單2222
for (int i = 0; i < devicess.size(); i++) {
if (devicess.get(i).getId() == printerDeviceBean.getFlyPrinterDeviceId2()) {
if (devicess.get(i).getId().equals(printerDeviceBean.getFlyPrinterDeviceId2())) {
mTvFailNameTwo.setText(devicess.get(i).getName());
twoFailPosition = i;
mTvFailNameTwo.setTextColor(getResources().getColor(R.color.color_3c));
......@@ -168,7 +168,7 @@ public class PrinterAddActivity extends BaseActivity<PrinterAddPresenter> implem
printModelLabels = new ArrayList<>();
for (int i = 0; i < printModelBeans.size(); i++) {
printModelLabels.add(printModelBeans.get(i).getPrinterName() + "\u3000" + printModelBeans.get(i).getModel());
if (printerDeviceBean != null && printerDeviceBean.getPrinterModelId() == printModelBeans.get(i).getId()) {
if (printerDeviceBean != null && printerDeviceBean.getPrinterModelId() != null && printerDeviceBean.getPrinterModelId() == printModelBeans.get(i).getId()) {
modelPosition = i;
}
}
......
......@@ -3,11 +3,9 @@ package com.joe.print.mvp.ui.fragment;
import android.content.Intent;
import android.os.Bundle;
import android.os.Message;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
......@@ -88,12 +86,6 @@ public class IpPrintListActivityFragment extends BaseFragment<IpPrintListActivit
mPresenter.getPrinterList(GsaCloudApplication.getRestaurantId(mContext));
}
@Override
public void onStart() {
super.onStart();
}
/**
* 通过此方法可以使 Fragment 能够与外界做一些交互和通信, 比如说外部的 Activity 想让自己持有的某个 Fragment 对象执行一些方法,
* 建议在有多个需要与外界交互的方法时, 统一传 {@link Message}, 通过 what 字段来区分不同的方法, 在 {#setData(Object)}
......
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.joe.print.mvp.ui.activity.PrintTestActivity">
<Button
android:id="@+id/btn_test"
android:layout_width="match_parent"
android:layout_height="@dimen/dp_50"
android:layout_centerInParent="true"
android:text="打印測試" />
</RelativeLayout>
......@@ -36,6 +36,7 @@
<TextView
android:id="@+id/tv_printer_port"
android:layout_width="wrap_content"
android:visibility="gone"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp_10"
android:singleLine="true"
......
......@@ -66,6 +66,7 @@
android:singleLine="true"
android:text="端口號:"
android:textColor="@color/normal_color"
android:visibility="gone"
android:textSize="@dimen/dp_12"
app:layout_constraintLeft_toLeftOf="@id/tv_printer_ip"
app:layout_constraintTop_toBottomOf="@id/tv_printer_ip" />
......
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