Pārlūkot izejas kodu

2

味魔方Android
fyf pirms 1 gada
vecāks
revīzija
4b961fdcb5
1 mainītis faili ar 33 papildinājumiem un 41 dzēšanām
  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 Parādīt failu

@@ -57,10 +57,8 @@ public class BottomNavigationMainActivity extends BaseActivity {
MediaPlayerHelper.getInstance().SetConText(getBaseContext());
mNavigateTabBar.onRestoreInstanceState(savedInstanceState);
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(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.comui_tab_person, R.mipmap.comui_tab_person_selected, "我的"));
mNavigateTabBar.setTabSelectListener(mOnNavigationItemSelectedListener);
@@ -79,36 +77,33 @@ public class BottomNavigationMainActivity extends BaseActivity {
super.onDestroy();
}

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

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


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


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

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

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

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

@Override
public void onPageScrollStateChanged(int state) {
}


Notiek ielāde…
Atcelt
Saglabāt