From 2cc1c273a3ee6932368d84c8adf05efed2380a9d Mon Sep 17 00:00:00 2001 From: lyw <刘耀文@DESKTOP-E1TI268> Date: Mon, 15 Apr 2024 16:13:16 +0800 Subject: [PATCH] =?UTF-8?q?lyw=20=20=E4=B8=8A=E4=BC=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BottomNavigationMainActivity.java | 16 +++- .../home/fragment/MakeGoodFragment.java | 19 +--- .../home/fragment/mode/SerialPortRead.java | 65 +++++++++++++ .../home/fragment/mode/ShaoMaSave.java | 4 +- .../activity_bottom_navigation_main.xml | 25 ----- .../main/res/layout/fragment_make_good.xml | 93 ------------------- 6 files changed, 81 insertions(+), 141 deletions(-) create mode 100644 app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SerialPortRead.java diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java index da44943d..b4bf6bdf 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java @@ -7,6 +7,7 @@ import androidx.viewpager.widget.ViewPager; import android.os.Bundle; import android.text.Editable; +import android.text.InputType; import android.text.TextWatcher; import android.util.Log; import android.view.KeyEvent; @@ -40,6 +41,7 @@ import com.bonait.bnframework.modules.home.fragment.MakeGoodFragment; import com.bonait.bnframework.modules.home.fragment.SheZhifragment; import com.bonait.bnframework.modules.home.fragment.mode.SerialInter; import com.bonait.bnframework.modules.home.fragment.mode.SerialManage; +import com.bonait.bnframework.modules.home.fragment.mode.ShaomaTest; import com.bonait.bnframework.modules.mine.fragment.MyFragment; import com.bumptech.glide.Glide; import com.qmuiteam.qmui.widget.QMUIViewPager; @@ -58,8 +60,7 @@ public class BottomNavigationMainActivity extends BaseActivity{ @BindView(R.id.viewpager) QMUIViewPager viewPager; - @BindView(R.id.Test_res) - EditText shaoma_Text; + @Override protected void onCreate(Bundle savedInstanceState) { @@ -78,11 +79,14 @@ public class BottomNavigationMainActivity extends BaseActivity{ initFragment(); Init(); - shaoma_Text.requestFocus(); + + /* shaoma_Text.requestFocus(); + shaoma_Text.setInputType(InputType.TYPE_NULL); shaoma_Text.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { + shaoma_Text.setInputType(InputType.TYPE_NULL); } else { shaoma_Text.clearFocus(); shaoma_Text.requestFocus(); @@ -100,9 +104,11 @@ public class BottomNavigationMainActivity extends BaseActivity{ MakeGoodFragment makeGoodFragment=(MakeGoodFragment) fragmentList.get(2); makeGoodFragment.RecipeRun(msg); } - /*RecipeRun(msg);*/ } shaoma_Text.setText(""); + shaoma_Text.clearFocus(); + shaoma_Text.setInputType(InputType.TYPE_CLASS_TEXT); + shaoma_Text.requestFocus(); } return false; @@ -122,7 +128,7 @@ public class BottomNavigationMainActivity extends BaseActivity{ public void afterTextChanged(Editable s) { im.hideSoftInputFromWindow(shaoma_Text.getWindowToken(), 0); } - }); + });*/ } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java index 89eb00d0..fe61e8f1 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/MakeGoodFragment.java @@ -84,6 +84,8 @@ import com.bonait.bnframework.modules.home.adapter.loadinggood_adapter; import com.bonait.bnframework.modules.home.adapter.wl_adapter; import com.bonait.bnframework.modules.home.fragment.mode.SerialInter; import com.bonait.bnframework.modules.home.fragment.mode.SerialManage; +import com.bonait.bnframework.modules.home.fragment.mode.SerialPortRead; +import com.bonait.bnframework.modules.home.fragment.mode.ShaoMaSave; import com.bonait.bnframework.modules.home.fragment.mode.ShaomaTest; import com.bonait.bnframework.modules.home.fragment.mode.add_makegood_control; import com.bonait.bnframework.modules.home.fragment.mode.add_manguan_control; @@ -169,17 +171,7 @@ public class MakeGoodFragment extends BaseFragment { RelativeLayout loadgoodliebiao; - /** - * 获取扫码内容 - */ - @BindView(R.id.res_text) - EditText shaoma_Text; - /** - * 扫码界面展示 - */ - @BindView(R.id.shaoma_view) - RelativeLayout shaoma_view; private Context context; @@ -205,7 +197,6 @@ public class MakeGoodFragment extends BaseFragment { Initdata(); Run(); - /*ShaomaTest.Getinstance().Open(activity,this.context);*/ /* SerialManage.GetInstance().init(new SerialInter() { @Override @@ -475,7 +466,7 @@ public class MakeGoodFragment extends BaseFragment { }; } - @OnClick({R.id.good_gengxin, R.id.cheng_clear, R.id.loadgood,R.id.no,R.id.yes}) + @OnClick({R.id.good_gengxin, R.id.cheng_clear, R.id.loadgood}) public void onViewClicked(View view) { switch (view.getId()) { case R.id.good_gengxin://刷新 @@ -501,10 +492,6 @@ public class MakeGoodFragment extends BaseFragment { loadgoodliebiao.setVisibility(View.VISIBLE); } break; - case R.id.yes: - shaoma_view.setVisibility(View.INVISIBLE); - case R.id.no: - shaoma_view.setVisibility(View.INVISIBLE); } } diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SerialPortRead.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SerialPortRead.java new file mode 100644 index 00000000..7dea7241 --- /dev/null +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/SerialPortRead.java @@ -0,0 +1,65 @@ +package com.bonait.bnframework.modules.home.fragment.mode; + + +import android.serialport.SerialPort; +import android.util.Log; + +import org.apache.commons.codec.binary.Hex; + +import java.io.BufferedInputStream; +import java.io.InputStream; +import java.math.BigInteger; +import java.nio.charset.StandardCharsets; + +public class SerialPortRead { + private volatile static SerialPortRead _instance; + public static SerialPortRead Getinstance(){ + if (_instance==null){ + _instance = new SerialPortRead(); + } + return _instance; + } + public void Open(String path,int baudrate){ + try{ + SerialPort sp = SerialPort.newBuilder(path,baudrate) + .dataBits(8) + .stopBits(1) + .parity(0) + .build(); + InputStream inputStream = sp.getInputStream(); + new Thread(new Runnable() { + @Override + public void run() { + try{ + while (true){ + byte[] bytes = new byte[5]; + String myString =""; + int size = inputStream.read(bytes); + if (size>0) + Log.e("ceshi",Integer.toHexString(size)); + } + }catch (Exception e){ + + } + + } + }).start(); + }catch (Exception e){ + + } + } + + public String toHexString(byte[] bytes){ + String HexString=""; + for(byte b:bytes){ + HexString += String.format("%02x",b); + } + return HexString; + } + + + + + + +} diff --git a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java index adae439b..c7e916ab 100644 --- a/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java +++ b/app/src/main/java/com/bonait/bnframework/modules/home/fragment/mode/ShaoMaSave.java @@ -98,8 +98,8 @@ public class ShaoMaSave implements Runnable{ while (this.isRead){ if (Thread.currentThread().isInterrupted()) continue; try{ - /*int available = inputStream.available(); - if (available == 0) continue;*/ + int available = inputStream.available(); + if (available == 0) continue; if (inputStream == null) continue; byte[] received = new byte[1]; String x=""; diff --git a/app/src/main/res/layout/activity_bottom_navigation_main.xml b/app/src/main/res/layout/activity_bottom_navigation_main.xml index 1ab1a7cc..c9affdce 100644 --- a/app/src/main/res/layout/activity_bottom_navigation_main.xml +++ b/app/src/main/res/layout/activity_bottom_navigation_main.xml @@ -77,31 +77,6 @@ android:textStyle="bold|italic" /> - - - - - - diff --git a/app/src/main/res/layout/fragment_make_good.xml b/app/src/main/res/layout/fragment_make_good.xml index 81461c25..dd1115fd 100644 --- a/app/src/main/res/layout/fragment_make_good.xml +++ b/app/src/main/res/layout/fragment_make_good.xml @@ -191,98 +191,5 @@ android:layout_height="wrap_content" android:background="@color/app_color_blue" /> - - - - - - - - - - - - - - - - -