Commit 066c9656 by Wyh

3-19 清機報表字體太小問題

parent f2fd9308
...@@ -7,11 +7,11 @@ import com.gingersoft.gsa.cloud.main.R; ...@@ -7,11 +7,11 @@ import com.gingersoft.gsa.cloud.main.R;
import com.gingersoft.gsa.cloud.main.mvp.contract.SettlementReportContract; import com.gingersoft.gsa.cloud.main.mvp.contract.SettlementReportContract;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.SendSettlement; import com.gingersoft.gsa.cloud.main.mvp.model.bean.SendSettlement;
import com.gingersoft.gsa.cloud.main.mvp.model.bean.SettlementReport; import com.gingersoft.gsa.cloud.main.mvp.model.bean.SettlementReport;
import com.gingersoft.gsa.cloud.ui.bean.view.SectionTextItem3;
import com.gingersoft.gsa.cloud.ui.bean.view.SectionTextItem5;
import com.gingersoft.gsa.cloud.main.mvp.ui.activity.SettlementReportActivity; import com.gingersoft.gsa.cloud.main.mvp.ui.activity.SettlementReportActivity;
import com.gingersoft.gsa.cloud.main.mvp.ui.adapter.SettlementReportItem5Adapter; import com.gingersoft.gsa.cloud.main.mvp.ui.adapter.SettlementReportItem5Adapter;
import com.gingersoft.gsa.cloud.main.mvp.ui.adapter.SettlementReportItemAdapter; import com.gingersoft.gsa.cloud.main.mvp.ui.adapter.SettlementReportItemAdapter;
import com.gingersoft.gsa.cloud.ui.bean.view.SectionTextItem3;
import com.gingersoft.gsa.cloud.ui.bean.view.SectionTextItem5;
import com.jess.arms.di.scope.ActivityScope; import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.http.imageloader.ImageLoader; import com.jess.arms.http.imageloader.ImageLoader;
import com.jess.arms.integration.AppManager; import com.jess.arms.integration.AppManager;
...@@ -65,6 +65,8 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon ...@@ -65,6 +65,8 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon
private SettlementReportItem5Adapter mSettlementReportItem5Adapter; private SettlementReportItem5Adapter mSettlementReportItem5Adapter;
private List<SectionTextItem5> mSettlementReportItem5List= new ArrayList<>(); private List<SectionTextItem5> mSettlementReportItem5List= new ArrayList<>();
public SettlementReportItem5Adapter mPrintAdapter;
@Inject @Inject
public SettlementReportPresenter(SettlementReportContract.Model model, SettlementReportContract.View rootView) { public SettlementReportPresenter(SettlementReportContract.Model model, SettlementReportContract.View rootView) {
super(model, rootView); super(model, rootView);
...@@ -89,6 +91,9 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon ...@@ -89,6 +91,9 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon
mSettlementReportItem5Adapter = new SettlementReportItem5Adapter(IActivity, mSettlementReportItem5List); mSettlementReportItem5Adapter = new SettlementReportItem5Adapter(IActivity, mSettlementReportItem5List);
mRootView.setSettlementReportItem5Adapter(mSettlementReportItem5Adapter); mRootView.setSettlementReportItem5Adapter(mSettlementReportItem5Adapter);
} }
if(mPrintAdapter == null){
mPrintAdapter = new SettlementReportItem5Adapter(IActivity, mSettlementReportItem5List, 24);
}
} }
public void notifyReportItemAdapter(List<SectionTextItem3> settlementReportItems) { public void notifyReportItemAdapter(List<SectionTextItem3> settlementReportItems) {
...@@ -101,6 +106,7 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon ...@@ -101,6 +106,7 @@ public class SettlementReportPresenter extends BasePresenter<SettlementReportCon
mSettlementReportItem5List.clear(); mSettlementReportItem5List.clear();
mSettlementReportItem5List.addAll(settlementReportItems); mSettlementReportItem5List.addAll(settlementReportItems);
mSettlementReportItem5Adapter.notifyDataSetChanged(); mSettlementReportItem5Adapter.notifyDataSetChanged();
mPrintAdapter.notifyDataSetChanged();
} }
public void sendSettlement() { public void sendSettlement() {
......
...@@ -26,10 +26,17 @@ import butterknife.BindViews; ...@@ -26,10 +26,17 @@ import butterknife.BindViews;
public class SettlementReportItem5Adapter extends DefaultAdapter<SectionTextItem5> { public class SettlementReportItem5Adapter extends DefaultAdapter<SectionTextItem5> {
private Context mContext; private Context mContext;
private int textSize;
public SettlementReportItem5Adapter(Context context, List<SectionTextItem5> infos) { public SettlementReportItem5Adapter(Context context, List<SectionTextItem5> infos) {
super(infos); super(infos);
this.mContext = context; this.mContext = context;
textSize = 16;
}
public SettlementReportItem5Adapter(Context context, List<SectionTextItem5> infos, int textSize) {
super(infos);
this.mContext = context;
this.textSize = textSize;
} }
@Override @Override
...@@ -54,42 +61,45 @@ public class SettlementReportItem5Adapter extends DefaultAdapter<SectionTextItem ...@@ -54,42 +61,45 @@ public class SettlementReportItem5Adapter extends DefaultAdapter<SectionTextItem
public SettlementReportItemHolder(View itemView) { public SettlementReportItemHolder(View itemView) {
super(itemView); super(itemView);
for (int i = 0; i < tv_items.length; i++) {
tv_items[i].setTextSize(textSize);
}
} }
@Override @Override
public void setData(SectionTextItem5 reportItem, int position) { public void setData(SectionTextItem5 reportItem, int position) {
if(!TextUtils.isEmpty(reportItem.getItem1())){ if (!TextUtils.isEmpty(reportItem.getItem1())) {
tv_items[0].setText(reportItem.getItem1()); tv_items[0].setText(reportItem.getItem1());
tv_items[0].setVisibility(View.VISIBLE); tv_items[0].setVisibility(View.VISIBLE);
}else { } else {
tv_items[0].setVisibility(View.GONE); tv_items[0].setVisibility(View.GONE);
} }
if(!TextUtils.isEmpty(reportItem.getItem2())){ if (!TextUtils.isEmpty(reportItem.getItem2())) {
tv_items[1].setText(reportItem.getItem2()); tv_items[1].setText(reportItem.getItem2());
tv_items[1].setVisibility(View.VISIBLE); tv_items[1].setVisibility(View.VISIBLE);
}else { } else {
tv_items[1].setVisibility(View.GONE); tv_items[1].setVisibility(View.GONE);
} }
if(!TextUtils.isEmpty(reportItem.getItem3())){ if (!TextUtils.isEmpty(reportItem.getItem3())) {
tv_items[2].setText(reportItem.getItem3()); tv_items[2].setText(reportItem.getItem3());
tv_items[2].setVisibility(View.VISIBLE); tv_items[2].setVisibility(View.VISIBLE);
}else { } else {
tv_items[2].setVisibility(View.GONE); tv_items[2].setVisibility(View.GONE);
} }
if(!TextUtils.isEmpty(reportItem.getItem4())){ if (!TextUtils.isEmpty(reportItem.getItem4())) {
tv_items[3].setText(reportItem.getItem4()); tv_items[3].setText(reportItem.getItem4());
tv_items[3].setVisibility(View.VISIBLE); tv_items[3].setVisibility(View.VISIBLE);
}else { } else {
tv_items[3].setVisibility(View.GONE); tv_items[3].setVisibility(View.GONE);
} }
if(!TextUtils.isEmpty(reportItem.getItem5())){ if (!TextUtils.isEmpty(reportItem.getItem5())) {
tv_items[4].setText(reportItem.getItem5()); tv_items[4].setText(reportItem.getItem5());
tv_items[4].setVisibility(View.VISIBLE); tv_items[4].setVisibility(View.VISIBLE);
}else { } else {
tv_items[4].setVisibility(View.GONE); tv_items[4].setVisibility(View.GONE);
} }
} }
......
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<com.qmuiteam.qmui.widget.QMUIWindowInsetLayout xmlns:android="http://schemas.android.com/apk/res/android" <com.qmuiteam.qmui.widget.QMUIWindowInsetLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
...@@ -9,94 +8,7 @@ ...@@ -9,94 +8,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/qmui_topbar_height" /> android:layout_height="?attr/qmui_topbar_height" />
<ScrollView <include layout="@layout/layout_settlement_report" />
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/qmui_topbar_height"
android:layout_marginBottom="@dimen/dp_45"
android:background="@color/theme_white_color"
android:descendantFocusability="beforeDescendants"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/dp_10">
<TextView
android:id="@+id/tv_last_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="@dimen/dp_5"
android:text="上次清機時間:2020-3-1 21:59:18"
android:textColor="@color/red"
android:textSize="@dimen/dp_16" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_restaurant_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="店鋪名稱:gingersoft"
android:textColor="@color/black"
android:textSize="@dimen/dp_18" />
<TextView
android:id="@+id/tv_business_area_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="店鋪名稱:gingersoft"
android:textColor="@color/black"
android:textSize="@dimen/dp_18" />
<TextView
android:id="@+id/tv_start_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text=""
android:textColor="@color/black"
android:textSize="@dimen/settlement_report_text_size" />
<TextView
android:id="@+id/tv_end_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text=""
android:textColor="@color/black"
android:textSize="@dimen/settlement_report_text_size" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_0_5"
android:layout_marginTop="@dimen/dp_8"
android:background="@color/theme_grey_color" />
<!-- <com.gingersoft.gsa.cloud.base.widget.NoScrollRecyclerView-->
<!-- android:id="@+id/rv_settlement_report_item"-->
<!-- android:layout_width="match_parent"-->
<!-- android:layout_height="wrap_content"-->
<!-- android:divider="@null"-->
<!-- android:fadeScrollbars="false" />-->
<com.gingersoft.gsa.cloud.base.widget.NoScrollRecyclerView
android:id="@+id/rv_settlement_report_item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:fadeScrollbars="false"
android:paddingTop="@dimen/dp_8" />
</LinearLayout>
</ScrollView>
<com.qmuiteam.qmui.alpha.QMUIAlphaButton <com.qmuiteam.qmui.alpha.QMUIAlphaButton
android:id="@+id/btn_send_settlement" android:id="@+id/btn_send_settlement"
......
...@@ -20,7 +20,7 @@ ...@@ -20,7 +20,7 @@
android:id="@+id/tv_item2" android:id="@+id/tv_item2"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="0.5"
android:gravity="center" android:gravity="center"
android:maxLines="1" android:maxLines="1"
android:text="item2" android:text="item2"
...@@ -42,7 +42,7 @@ ...@@ -42,7 +42,7 @@
android:id="@+id/tv_item4" android:id="@+id/tv_item4"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_weight="1" android:layout_weight="0.5"
android:gravity="center" android:gravity="center"
android:text="item4" android:text="item4"
android:maxLines="1" android:maxLines="1"
......
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="?attr/qmui_topbar_height"
android:layout_marginBottom="@dimen/dp_45"
android:background="@color/theme_white_color"
android:descendantFocusability="beforeDescendants"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/dp_10">
<TextView
android:id="@+id/tv_last_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="@dimen/dp_5"
android:text="上次清機時間:2020-3-1 21:59:18"
android:textColor="@color/red"
android:textSize="@dimen/dp_16" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/tv_restaurant_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="店鋪名稱:gingersoft"
android:textColor="@color/black"
android:textSize="@dimen/dp_18" />
<TextView
android:id="@+id/tv_business_area_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="店鋪名稱:gingersoft"
android:textColor="@color/black"
android:textSize="@dimen/dp_18" />
<TextView
android:id="@+id/tv_start_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text=""
android:textColor="@color/black"
android:textSize="@dimen/settlement_report_text_size" />
<TextView
android:id="@+id/tv_end_time"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/dp_5"
android:text=""
android:textColor="@color/black"
android:textSize="@dimen/settlement_report_text_size" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="@dimen/dp_0_5"
android:layout_marginTop="@dimen/dp_8"
android:background="@color/theme_grey_color" />
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/rv_settlement_report_item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:divider="@null"
android:fadeScrollbars="false"
android:paddingTop="@dimen/dp_8" />
</LinearLayout>
</androidx.core.widget.NestedScrollView>
...@@ -344,6 +344,11 @@ public class PrintUtils { ...@@ -344,6 +344,11 @@ public class PrintUtils {
return viewToBitmap(context, view); return viewToBitmap(context, view);
} }
/**
* 獲取清機報表Bitmap
* @param mContext
* @return
*/
private static Bitmap getReportBitmap(Context mContext) { private static Bitmap getReportBitmap(Context mContext) {
View view = PrintTransitUtils.getInstance().getPrintView(); View view = PrintTransitUtils.getInstance().getPrintView();
if (view != null) { if (view != null) {
...@@ -356,6 +361,6 @@ public class PrintUtils { ...@@ -356,6 +361,6 @@ public class PrintUtils {
public static Bitmap viewToBitmap(Context context, View view) { public static Bitmap viewToBitmap(Context context, View view) {
LayoutToBitmapUtils.layoutView(context, view);//先测量view LayoutToBitmapUtils.layoutView(context, view);//先测量view
//580為程序支持的打印紙最大寬度 //580為程序支持的打印紙最大寬度
return ImageUtils.zoomDrawable(LayoutToBitmapUtils.loadBitmapFromView(view), paperWidth);//将view轉bitmap return ImageUtils.zoomDrawable(LayoutToBitmapUtils.loadBitmapFromView(view, paperWidth), paperWidth);//将view轉bitmap
} }
} }
/*
* Copyright (C) 2015 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gingersoft.gsa.cloud.print;
import java.util.List;
/**
* Print
* Created by Alex on 2016/11/10.
*/
public interface PrintDataMaker {
List<byte[]> getPrintData(int type);
}
/*
* Copyright (C) 2015 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gingersoft.gsa.cloud.print;
import android.bluetooth.BluetoothDevice;
import android.os.AsyncTask;
import java.lang.ref.WeakReference;
import java.util.List;
/**
* 打印执行者
* Created by Alex on 2016/11/10.
*/
public class PrintExecutor {
private int type;
private PrintSocketHolder holder;
private int mReconnectTimes = 0;
private int time = 0;
private PrintSocketHolder.OnStateChangedListener listener;
private WeakReference<OnPrintResultListener> mListener;
public PrintExecutor(BluetoothDevice device, int type) {
holder = new PrintSocketHolder(device);
setType(type);
}
public PrintExecutor(String ip, int port, int type) {
holder = new PrintSocketHolder(ip, port);
setType(type);
}
/**
* 执行打印请求
*
* @return 错误代码
*/
private int doRequest(PrintDataMaker maker) {
if (mReconnectTimes == 0) {
holder.onPrinterStateChanged(PrintSocketHolder.STATE_0);
List<byte[]> data = maker.getPrintData(type);
if (!holder.isSocketPrepared()) {
int prepare = holder.prepareSocket();
if (prepare != PrintSocketHolder.ERROR_0)
return prepare;
}
return holder.sendData(data);
} else {
holder.onPrinterStateChanged(PrintSocketHolder.STATE_0);
List<byte[]> data = maker.getPrintData(type);
if (holder.isSocketPrepared()) {
if (sendData(data))
return PrintSocketHolder.ERROR_0;
else
return PrintSocketHolder.ERROR_100;
} else {
if (prepareSocket() && sendData(data)) {
return PrintSocketHolder.ERROR_0;
} else {
return PrintSocketHolder.ERROR_100;
}
}
}
}
/**
* 执行打印请求
*
* @return 错误代码
*/
public int doPrinterRequest(PrintDataMaker maker) {
holder.setOnStateChangedListener(listener);
return doRequest(maker);
}
private boolean prepareSocket() {
time++;
return time < mReconnectTimes &&
(holder.prepareSocket() == PrintSocketHolder.ERROR_0 || prepareSocket());
}
private boolean sendData(List<byte[]> data) {
if (holder.sendData(data) == PrintSocketHolder.ERROR_0) {
time = 0;
return true;
} else {
return prepareSocket() && sendData(data);
}
}
/**
* 异步执行打印请求
*/
public void doPrinterRequestAsync(PrintDataMaker maker) {
new PrintTask().execute(maker);
}
/**
* 销毁
*/
public int closeSocket() {
return holder.closeSocket();
}
/**
* 设置IP及端口
*
* @param ip IP
* @param port 端口
*/
public void setIp(String ip, int port) {
holder.setIp(ip, port);
}
/**
* 设置蓝牙
*
* @param device 设备
*/
public void setDevice(BluetoothDevice device) {
holder.setDevice(device);
}
/**
* 设置打印类型
*
* @param type 打印类型
*/
public void setType(int type) {
this.type = type;
}
/**
* 设置状态监听
*
* @param listener 监听
*/
public void setOnStateChangedListener(PrintSocketHolder.OnStateChangedListener listener) {
this.listener = listener;
}
/**
* 设置重连次数
*
* @param times 次数
*/
public void setReconnectTimes(int times) {
mReconnectTimes = times;
}
/**
* 设置结果回调
*
* @param listener 回调
*/
public void setOnPrintResultListener(OnPrintResultListener listener) {
mListener = new WeakReference<>(listener);
}
public interface OnPrintResultListener {
void onResult(int errorCode);
}
private class PrintTask extends AsyncTask<PrintDataMaker, Integer, Integer> implements
PrintSocketHolder.OnStateChangedListener {
@Override
protected void onPreExecute() {
super.onPreExecute();
holder.setOnStateChangedListener(this);
}
@Override
protected Integer doInBackground(PrintDataMaker... makers) {
if (makers == null || makers.length < 1)
return PrintSocketHolder.ERROR_0;
return doRequest(makers[0]);
}
@Override
protected void onProgressUpdate(Integer... values) {
super.onProgressUpdate(values);
if (values == null || values.length < 1)
return;
if (listener != null)
listener.onStateChanged(values[0]);
}
@Override
protected void onPostExecute(Integer integer) {
super.onPostExecute(integer);
if (integer != null) {
onResult(integer);
}
}
/**
* 打印结果
*
* @param errorCode 错误代码
*/
private void onResult(int errorCode) {
try {
if (mListener != null)
mListener.get().onResult(errorCode);
} catch (Exception e) {
e.printStackTrace();
}
}
@Override
public void onStateChanged(int state) {
publishProgress(state);
}
}
}
/*
* Copyright (C) 2015 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gingersoft.gsa.cloud.print;
import android.annotation.SuppressLint;
import android.bluetooth.BluetoothDevice;
import android.bluetooth.BluetoothSocket;
import com.gingersoft.gsa.cloud.constans.PrintConstans;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.ref.WeakReference;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.util.List;
import java.util.UUID;
/**
* 打印Socket
* Created by Alex on 2016/11/10.
*/
@SuppressWarnings({"WeakerAccess", "unused"})
public class PrintSocketHolder {
public static final int STATE_0 = 0;// 生成测试页面数据
public static final int STATE_1 = 1;// 创建Socket连接
public static final int STATE_2 = 2;// 获取输出流
public static final int STATE_3 = 3;// 写入测试页面数据
public static final int STATE_4 = 4;// 关闭输出流
public static final int ERROR_0 = 0;// 成功
public static final int ERROR_1 = -1;// 生成测试页面数据失败
public static final int ERROR_2 = -2;// 创建Socket失败
public static final int ERROR_3 = -3;// 获取输出流失败
public static final int ERROR_4 = -4;// 写入测试页面数据失败
public static final int ERROR_5 = -5;// 必要参数不能为空
public static final int ERROR_6 = -6;// 关闭Socket出错
public static final int ERROR_100 = -100;// 失败
private static final UUID uuid = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");//蓝牙打印UUID
private String ip;
private int port = 9100;
private BluetoothDevice mDevice;
private Socket socket;
private BluetoothSocket bluetoothSocket;
private OutputStream out;
private WeakReference<OnStateChangedListener> mListener;
public PrintSocketHolder(BluetoothDevice device) {
setDevice(device);
}
public PrintSocketHolder(String ip, int port) {
setIp(ip, port);
}
@SuppressLint("MissingPermission")
public int createSocket() {
onPrinterStateChanged(STATE_1);
if (mDevice == null && ip == null)
return ERROR_5;
try {
if (mDevice != null) {
bluetoothSocket = mDevice.createRfcommSocketToServiceRecord(uuid);
bluetoothSocket.connect();
} else {
socket = new Socket();//ip, port
InetSocketAddress socketAddress = new InetSocketAddress(ip, port);
//设置 超时时间
socket.setSoTimeout(PrintConstans.SO_TIMEOUT);
socket.connect(socketAddress, PrintConstans.PRINT_TIMEOUT);//开始连接ip
}
} catch (Exception e) {
closeSocket();
return ERROR_2;
}
return ERROR_0;
}
public int getOutputStream() {
onPrinterStateChanged(STATE_2);
try {
if (mDevice != null) {
out = bluetoothSocket.getOutputStream();
} else {
out = socket.getOutputStream();
}
} catch (IOException e) {
closeSocket();
return ERROR_3;
}
return ERROR_0;
}
public boolean isSocketPrepared() {
return (bluetoothSocket != null || socket != null) && out != null;
}
public int sendData(List<byte[]> data) {
onPrinterStateChanged(STATE_3);
if (data == null || data.size() <= 0)
return ERROR_0;
for (byte[] item : data) {
try {
out.write(item);
out.flush();
} catch (IOException e) {
closeSocket();
return ERROR_4;
}
}
return ERROR_0;
}
public int sendData(byte[] data) {
onPrinterStateChanged(STATE_3);
try {
out.write(data);
out.flush();
} catch (IOException e) {
closeSocket();
return ERROR_4;
}
return ERROR_0;
}
public int sendData(byte[]... data) {
onPrinterStateChanged(STATE_3);
for (byte[] item : data) {
try {
out.write(item);
out.flush();
} catch (IOException e) {
closeSocket();
return ERROR_4;
}
}
return ERROR_0;
}
public int prepareSocket() {
int create = createSocket();
if (create != PrintSocketHolder.ERROR_0)
return create;
return getOutputStream();
}
/**
* 销毁
*/
public int closeSocket() {
onPrinterStateChanged(STATE_4);
boolean error = false;
try {
if (out != null) {
out.close();
out = null;
}
} catch (IOException e) {
out = null;
error = true;
}
try {
if (socket != null) {
socket.close();
socket = null;
}
} catch (IOException e) {
socket = null;
error = true;
}
try {
if (bluetoothSocket != null) {
bluetoothSocket.close();
bluetoothSocket = null;
}
} catch (IOException e) {
bluetoothSocket = null;
error = true;
}
return error ? ERROR_6 : ERROR_0;
}
/**
* 打印状态变化
*
* @param state 打印状态
*/
public void onPrinterStateChanged(int state) {
try {
if (mListener != null)
mListener.get().onStateChanged(state);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 设置IP及端口
*
* @param ip IP
* @param port 端口
*/
public void setIp(String ip, int port) {
this.ip = ip;
this.port = port;
}
/**
* 设置蓝牙
*
* @param device 设备
*/
public void setDevice(BluetoothDevice device) {
this.mDevice = device;
}
/**
* 设置状态监听
*
* @param listener 监听
*/
public void setOnStateChangedListener(OnStateChangedListener listener) {
mListener = new WeakReference<>(listener);
}
public interface OnStateChangedListener {
void onStateChanged(int state);
}
}
/*
* Copyright (C) 2015 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gingersoft.gsa.cloud.print;
import java.io.IOException;
/**
* 纸宽58mm的打印机
* Created by Alex on 2016/6/17.
*/
@SuppressWarnings("unused")
public class PrinterWriter58mm extends PrinterWriter {
public static final int TYPE_58 = 58;// 纸宽58mm
public int width = 380;
public PrinterWriter58mm() throws IOException {
}
public PrinterWriter58mm(int parting) throws IOException {
super(parting);
}
public PrinterWriter58mm(int parting, int width) throws IOException {
super(parting);
this.width = width;
}
@Override
protected int getLineWidth() {
return 16;
}
@Override
protected int getLineStringWidth(int textSize) {
switch (textSize) {
default:
case 0:
return 31;
case 1:
return 15;
}
}
@Override
protected int getDrawableMaxWidth() {
return width;
}
}
/*
* Copyright (C) 2015 AlexMofer
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.gingersoft.gsa.cloud.print;
import java.io.IOException;
/**
* 纸宽80mm的打印机
* Created by Alex on 2016/6/17.
*/
@SuppressWarnings("unused")
public class PrinterWriter80mm extends PrinterWriter {
public static final int TYPE_80 = 80;// 纸宽80mm
public int width = 500;
public PrinterWriter80mm() throws IOException {
}
public PrinterWriter80mm(int parting) throws IOException {
super(parting);
}
public PrinterWriter80mm(int parting, int width) throws IOException {
super(parting);
this.width = width;
}
@Override
protected int getLineWidth() {
return 24;
}
@Override
protected int getLineStringWidth(int textSize) {
switch (textSize) {
default:
case 0:
return 47;
case 1:
return 23;
}
}
@Override
protected int getDrawableMaxWidth() {
return width;
}
}
...@@ -481,5 +481,5 @@ ...@@ -481,5 +481,5 @@
<dimen name="sp_42">42sp</dimen> <dimen name="sp_42">42sp</dimen>
<dimen name="sp_48">48sp</dimen> <dimen name="sp_48">48sp</dimen>
<!-- 清機報表字體大小 --> <!-- 清機報表字體大小 -->
<dimen name="settlement_report_text_size">@dimen/dp_16</dimen> <dimen name="settlement_report_text_size">@dimen/sp_18</dimen>
</resources> </resources>
\ No newline at end of file
package com.gingersoft.gsa.cloud.table.mvp.ui.activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import androidx.viewpager.widget.ViewPager;
import com.gingersoft.gsa.cloud.base.qmui.arch.QMUIFragmentPagerAdapter;
import com.gingersoft.gsa.cloud.table.R;
import com.gingersoft.gsa.cloud.table.R2;
import com.gingersoft.gsa.cloud.table.di.component.DaggerOrderCenterComponent;
import com.gingersoft.gsa.cloud.table.mvp.contract.OrderCenterContract;
import com.gingersoft.gsa.cloud.table.mvp.presenter.OrderCenterPresenter;
import com.gingersoft.gsa.cloud.table.mvp.ui.fragment.AllOrderFragment;
import com.gingersoft.gsa.cloud.ui.widget.dialog.LoadingDialog;
import com.jess.arms.base.BaseActivity;
import com.jess.arms.di.component.AppComponent;
import com.jess.arms.utils.ArmsUtils;
import com.qmuiteam.qmui.widget.QMUITopBar;
import com.qmuiteam.qmui.widget.tab.QMUITabSegment;
import butterknife.BindView;
import static com.jess.arms.utils.Preconditions.checkNotNull;
/**
* ================================================
* Description:
* <p>
* Created by MVPArmsTemplate on 03/13/2020 14:28
* <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
* <a href="https://github.com/JessYanCoding">Follow me</a>
* <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
* <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
* <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
* ================================================
*/
public class OrderCenterActivity extends BaseActivity<OrderCenterPresenter> implements OrderCenterContract.View {
@BindView(R2.id.topbar)
QMUITopBar mTopBar;
@BindView(R2.id.tabSegment)
QMUITabSegment mTabSegment;
@BindView(R2.id.contentViewPager)
ViewPager mContentViewPager;
private String[] tabTitles = {"全部", "已取消"};
@Override
public void setupActivityComponent(@NonNull AppComponent appComponent) {
DaggerOrderCenterComponent //如找不到该类,请编译一下项目
.builder()
.appComponent(appComponent)
.view(this)
.build()
.inject(this);
}
@Override
public int initView(@Nullable Bundle savedInstanceState) {
return R.layout.activity_order_center; //如果你不需要框架帮你设置 setContentView(id) 需要自行设置,请返回 0
}
@Override
public void initData(@Nullable Bundle savedInstanceState) {
initTabAndPager();
}
private void initTabAndPager() {
QMUIFragmentPagerAdapter pagerAdapter = new QMUIFragmentPagerAdapter(getSupportFragmentManager()) {
@Override
public Fragment createFragment(int position) {
AllOrderFragment fragment = new AllOrderFragment();
Bundle bundle = new Bundle();
bundle.putInt("currentPageIndex", position);
fragment.setArguments(bundle);
return fragment;
}
@Override
public int getCount() {
return 2;
}
@Override
public CharSequence getPageTitle(int position) {
switch (position) {
case 0:
return "全部";
case 1:
return "已取消";
case 3:
default:
return "全部";
}
}
};
mContentViewPager.setAdapter(pagerAdapter);
mTabSegment.setupWithViewPager(mContentViewPager);
}
@Override
public void initIntent() {
}
@Override
public void initTopBar() {
mTopBar.setBackgroundColor(ContextCompat.getColor(this, R.color.theme_color));
mTopBar.addLeftBackImageButton().setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
killMyself();
}
});
mTopBar.setTitle("張單管理");
}
@Override
public void initLanguage() {
}
@Override
public void initLayoutParams() {
}
@Override
public void initLayoutVisible() {
}
@Override
public void showLoading(String message) {
if (message != null)
LoadingDialog.showDialogForLoading(this, message, true);
else
LoadingDialog.showDialogForLoading(this);
}
@Override
public void hideLoading() {
LoadingDialog.cancelDialogForLoading();
}
@Override
public void showMessage(@NonNull String message) {
checkNotNull(message);
ArmsUtils.makeText(this, message);
}
@Override
public void launchActivity(@NonNull Intent intent) {
checkNotNull(intent);
ArmsUtils.startActivity(intent);
}
@Override
public void killMyself() {
finish();
}
}
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