Browse Source

2

味魔方Android
fyf 1 year ago
parent
commit
4b961fdcb5
1 changed files with 33 additions and 41 deletions
  1. +33
    -41
      app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java

+ 33
- 41
app/src/main/java/com/bonait/bnframework/modules/home/activity/BottomNavigationMainActivity.java View File

@@ -57,10 +57,8 @@ public class BottomNavigationMainActivity extends BaseActivity {
MediaPlayerHelper.getInstance().SetConText(getBaseContext()); MediaPlayerHelper.getInstance().SetConText(getBaseContext());
mNavigateTabBar.onRestoreInstanceState(savedInstanceState); mNavigateTabBar.onRestoreInstanceState(savedInstanceState);
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.gongneng, R.mipmap.gongneng_selected, "功能"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.jiaoyan, R.mipmap.jiaoyan_selected, "校验"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "订单")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.dingdan, R.mipmap.dingdan_selected, "订单"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, "")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(0, 0, ""));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_message, R.mipmap.comui_tab_message_selected, "管理"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.shezhi, R.mipmap.shezhi_selected, "设置"));
mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的")); mNavigateTabBar.addTab(null, new MainNavigateTabBar.TabParam(R.mipmap.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的"));
mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener); mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener);
@@ -79,36 +77,33 @@ public class BottomNavigationMainActivity extends BaseActivity {
super.onDestroy(); super.onDestroy();
} }


private List<Fragment> fragmentList=new ArrayList<Fragment>();
private List<Fragment> fragmentList = new ArrayList<Fragment>();

/** /**
* viewPager里添加fragment * viewPager里添加fragment
*/ */
private void initFragment() { private void initFragment() {
fragmentList = new ArrayList<>(); fragmentList = new ArrayList<>();
fragmentList.add(new GongnengFragment()); fragmentList.add(new GongnengFragment());
fragmentList.add(new JiaoYanFragment());
fragmentList.add(new DingDanfragment()); fragmentList.add(new DingDanfragment());
fragmentList.add(new MakeGoodFragment()); fragmentList.add(new MakeGoodFragment());
fragmentList.add(new GuanLifragment());
fragmentList.add(new SheZhifragment()); fragmentList.add(new SheZhifragment());
fragmentList.add(new MyFragment()); fragmentList.add(new MyFragment());
ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(),fragmentList);
ConfigName.getInstance().fragmentAdapter = new FragmentAdapter(getSupportFragmentManager(), fragmentList);
viewPager.setAdapter(ConfigName.getInstance().fragmentAdapter); viewPager.setAdapter(ConfigName.getInstance().fragmentAdapter);
ConfigName.getInstance().fragmentAdapter.SetViewPage(viewPager); ConfigName.getInstance().fragmentAdapter.SetViewPage(viewPager);
//手指滑动 //手指滑动
viewPager.addOnPageChangeListener(pageChangeListener); viewPager.addOnPageChangeListener(pageChangeListener);
// 设置viewPager缓存多少个fragment // 设置viewPager缓存多少个fragment
viewPager.setOffscreenPageLimit(7);
// 再来一
viewPager.setCurrentItem(3);
viewPager.setOffscreenPageLimit(5);
// 再来一
viewPager.setCurrentItem(2);
} }



/** /**
* 初始化 * 初始化
*/ */
public void Init()
{
public void Init() {
//1.同步时间 //1.同步时间
NetworkUtils.SynchronizationTime(); NetworkUtils.SynchronizationTime();
//主持 //主持
@@ -121,51 +116,46 @@ public class BottomNavigationMainActivity extends BaseActivity {
OrderServer.Get().MqttInit(); OrderServer.Get().MqttInit();
} }



/** /**
* 重新连接plc * 重新连接plc
*/ */
public void ReconnectModbus()
{
public void ReconnectModbus() {
try { try {


ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() { ThreadManager.Get().StartLong("PLC断线重连线程", true, new IThread() {
@Override @Override
public void Run() throws InterruptedException { public void Run() throws InterruptedException {
try { try {
if(ConfigName.getInstance().PlcIsConnect)
{
if (ConfigName.getInstance().PlcIsConnect) {
//ping 不通 //ping 不通
boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address,1,1);
if(!status) //ping 不通 连接
boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1);
if (!status) //ping 不通 连接
{ {
MessageLog.ShowInfo("PLC状态断开,尝试连接..."); MessageLog.ShowInfo("PLC状态断开,尝试连接...");
ConfigName.getInstance().PlcIsConnect=false;
ConfigName.getInstance().PlcIsConnect = false;
} }
}else
{
boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address,1,1);
if(status)
{
} else {
boolean status = ModbusTcpServer.ping2(ConfigName.getInstance().Address, 1, 1);
if (status) {
MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!"); MessageLog.ShowInfo("设备 " + ConfigName.getInstance().Address + " PLC通讯正常,准备连接!");
ModbusTcpServer.ConnectPLC(); ModbusTcpServer.ConnectPLC();
}else
{
} else {
MessageLog.ShowInfo("PLC状态断开,尝试连接..."); MessageLog.ShowInfo("PLC状态断开,尝试连接...");
ConfigName.getInstance().PlcIsConnect=false;
ConfigName.getInstance().PlcIsConnect = false;
} }
} }
Thread.sleep(10000); Thread.sleep(10000);
} catch (Exception e) { } catch (Exception e) {
Log.i("PLC", "PLC重连接失败!"+e.getMessage());
Log.i("PLC", "PLC重连接失败!" + e.getMessage());
} }
} }

@Override @Override
public void RunComplete() throws InterruptedException { public void RunComplete() throws InterruptedException {
} }
}); });
}catch (Exception e) {
MessageLog.ShowInfo("重新连接Modbus异常," +e.getMessage());
} catch (Exception e) {
MessageLog.ShowInfo("重新连接Modbus异常," + e.getMessage());
} }
} }


@@ -177,22 +167,22 @@ public class BottomNavigationMainActivity extends BaseActivity {
= new MainNavigateTabBar.OnTabSelectedListener() { = new MainNavigateTabBar.OnTabSelectedListener() {
@Override @Override
public void onTabSelected(MainNavigateTabBar.ViewHolder holder) { public void onTabSelected(MainNavigateTabBar.ViewHolder holder) {
int _postion=3;
int _postion = 2;
switch (holder.tag) { switch (holder.tag) {
case "功能": case "功能":
_postion=0;
break;
case "校验":_postion=1;
break;
case "订单":_postion=2;
_postion = 0;
break; break;
case "管理":_postion=4;
case "订单":
_postion = 1;
break; break;
case "设置":_postion=5;
case "设置":
_postion = 3;
break; break;
case "我的":_postion=6;
case "我的":
_postion = 4;
break; break;
case "":_postion=3;
case "":
_postion = 2;
break; break;
} }
viewPager.setCurrentItem(_postion); viewPager.setCurrentItem(_postion);
@@ -206,11 +196,13 @@ public class BottomNavigationMainActivity extends BaseActivity {
@Override @Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
} }

@Override @Override
public void onPageSelected(int position) { public void onPageSelected(int position) {
mNavigateTabBar.setCurrentSelectedTab(position); mNavigateTabBar.setCurrentSelectedTab(position);
mNavigateTabBar.SetDataResh(position); mNavigateTabBar.SetDataResh(position);
} }

@Override @Override
public void onPageScrollStateChanged(int state) { public void onPageScrollStateChanged(int state) {
} }


Loading…
Cancel
Save