package com.sunvote.xpadapp; import android.annotation.SuppressLint; import android.app.Fragment; import android.app.FragmentManager; import android.app.FragmentTransaction; import android.app.ProgressDialog; import android.content.BroadcastReceiver; import android.content.DialogInterface; import android.content.Intent; import android.net.Uri; import android.os.Build; import android.os.Bundle; import android.os.Environment; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.MotionEvent; import android.view.View; import android.widget.Toast; import com.sunvote.xpadapp.audition.DownloadType; import com.sunvote.xpadapp.audition.EvaluationRuleInfo; import com.sunvote.xpadapp.audition.ScoreNameInfo; import com.sunvote.xpadapp.audition.ScoreRuleExplainInfo; import com.sunvote.xpadapp.audition.ScoreRuleInfo; import com.sunvote.xpadapp.audition.dao.ScoreNameDao; import com.sunvote.xpadapp.audition.dao.ScoreNameDaoImpl; import com.sunvote.xpadapp.audition.dao.ScoreNameRuleDao; import com.sunvote.xpadapp.audition.dao.ScoreNameRuleDaoImpl; import com.sunvote.xpadapp.audition.dao.ScoreNameRuleInfo; import com.sunvote.xpadapp.base.BaseActivity; import com.sunvote.xpadapp.base.BaseFragment; import com.sunvote.xpadapp.db.DBManager; import com.sunvote.xpadapp.db.modal.BillInfo; import com.sunvote.xpadapp.db.modal.MeetingInfo; import com.sunvote.xpadapp.db.modal.MultiTitleItem; import com.sunvote.xpadapp.db.modal.UIType; import com.sunvote.xpadapp.fragments.AdminFragment; import com.sunvote.xpadapp.fragments.ComErrorFragment; import com.sunvote.xpadapp.fragments.CommunicationTestFragment; import com.sunvote.xpadapp.fragments.ContentVoteFragment; import com.sunvote.xpadapp.fragments.DocumentBrowserFragment; import com.sunvote.xpadapp.fragments.DownloadAuditionFragment; import com.sunvote.xpadapp.fragments.DownloadFragment; import com.sunvote.xpadapp.fragments.ElectionFragment; import com.sunvote.xpadapp.fragments.FirmUpdateFragment; import com.sunvote.xpadapp.fragments.KeypadTestChoice10Fragment; import com.sunvote.xpadapp.fragments.KeypadTestFragment; import com.sunvote.xpadapp.fragments.MeetingWelcomeFragment; import com.sunvote.xpadapp.fragments.MultiContentDetailFragment; import com.sunvote.xpadapp.fragments.MultiContentFragment; import com.sunvote.xpadapp.fragments.MultiPingshengFragment; import com.sunvote.xpadapp.fragments.MultiTitleFragment; import com.sunvote.xpadapp.fragments.NoFileFragment; import com.sunvote.xpadapp.fragments.OfflineFragment; import com.sunvote.xpadapp.fragments.OnLineFragment; import com.sunvote.xpadapp.fragments.PDFContextShowFragment; import com.sunvote.xpadapp.fragments.ResultElectionFragment; import com.sunvote.xpadapp.fragments.ResultMultiVoteFragment; import com.sunvote.xpadapp.fragments.ResultVoteFragment; import com.sunvote.xpadapp.fragments.ShowIdFragment; import com.sunvote.xpadapp.fragments.SigninFragment; import com.sunvote.xpadapp.fragments.SingleTitleFragment; import com.sunvote.xpadapp.fragments.TableMainFragment; import com.sunvote.xpadapp.presenter.ServicePresent; import com.sunvote.xpadapp.presenter.XPadPresenter; import com.sunvote.xpadapp.utils.FileUtil; import com.sunvote.xpadapp.utils.LogUtil; import com.sunvote.xpadapp.utils.MyStringUtil; import com.sunvote.xpadapp.utils.SharedPreferencesUtil; import com.sunvote.xpadcomm.ComListener; import com.sunvote.xpadcomm.FileRecver; import com.sunvote.xpadcomm.ScreenUtil; import com.sunvote.xpadcomm.XPadApi; import com.sunvote.xpadcomm.XPadApiInterface.BaseInfo; import com.sunvote.xpadcomm.XPadApiInterface.CmdDataInfo; import com.sunvote.xpadcomm.XPadApiInterface.KeypadInfo; import com.sunvote.xpadcomm.XPadApiInterface.ModelInfo; import com.sunvote.xpadcomm.XPadApiInterface.OnLineInfo; import com.sunvote.xpadcomm.XPadApiInterface.VoteInfo; import com.sunvote.xpadcomm.XPadSystem; import java.io.File; import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Timer; import java.util.TimerTask; @SuppressLint("NewApi") public class MainActivity extends BaseActivity implements ComListener { private final int Msg_ComError = 0; private final int Msg_Offline = 1; private final int Msg_Online = 2; private final int Msg_Download = 3; private final int Msg_Welcome = 4; // private final int Msg_Signin = 5; // private final int Msg_QuickVote = 6; // private final int Msg_SingleTitleVote = 7; // private final int Msg_MultiTitleVote = 8; // private final int Msg_SingleContentVote = 9; // private final int Msg_MultiContentVote = 10; // private final int Msg_ElectionVote = 11; private final int Msg_StopDownload = 12; // private final int Msg_KeypadTest = 13; private final int Msg_CommunicationTest = 14;//100次成功率 private final int Msg_ShowID = 15; private final int Msg_HideShowID = 17; // private final int Msg_MultiPingShengVote = 16; private final int Msg_onVoteEvent = 20; private final int Msg_onCommitSuccessEvent = 21; private final int Msg_onCommitAllOkSuccessEvent = 22; private final int Msg_onMultiPackageData = 23;//显示结果 private final int Msg_HideVoteResult = 24; private final int Msg_ShowMultiVoteResult = 25; private final int Msg_DBfileNotExist = 30; private final int Msg_MatchInfo = 31; private final int Msg_CommunicationTestHideResult = 32; private final int Msg_onCommitErrorEvent = 33; private final int Msg_DocumentBroswer = 40; private final int Msg_ShowBill = 41; private final int Msg_ScreenDark = 50; private final int Msg_ChangeBright = 51; private final int Msg_ScreenAutoDark = 52; private final int Msg_FirmUpdate = 53; private final int Msg_HideFirmUpdate = 54; private final int Msg_ClearLocalFile = 55; public static final int MSG_DELAY_TO_VIEW = 56; private final int Msg_ShowElectionVoteResult = 60; private final int Msg_ShowCustomTitleResult = 61; private final int Msg_EnterAdmin = 62; private final int Msg_onServiceCommitOk = 63; private final int Msg_DownloadFile = 73; private final int Msg_SynchronBrowser = 66; public BroadcastReceiver batteryLevelRcvr; public boolean isLoadPDF = false; // WifiManager wifiManager; // WifiConnector wac; private static String TAG = "MainActivity"; FragmentManager fm = getFragmentManager(); private FileRecver cs = null; private String ip = "192.168.0.105"; private int port = 15154; private BaseFragment billFragment; public BaseFragment currFragment; public BaseFragment addCurrFragment; public BaseFragment multiContentFragment; public BaseFragment pdfFragment; private DownloadFragment downloadFragment; private DocumentBrowserFragment docFragment; private Fragment keypadTestFragment; private Fragment showIdFragment; public Fragment resultFragment; private FirmUpdateFragment firmFragment; private String wifiSsid; private String wifiPwd; private String serverIp; private int serverPort; public XPadPresenter presenter; public OnLineInfo mOnlineInfo; public BaseInfo mBaseInfo; public KeypadInfo mKeypadInfo; public VoteInfo mVoteInfo; public ModelInfo mModelInfo; public String meetingDir; public MeetingInfo meetingInfo; public BillInfo currBillInfo; public BillInfo subBillInfo; public DBManager dbm; public int meetingId; public int roleType;//1 正式代表 , 0列席代表 private boolean inKeyTesting = false; private long lastTouchTime; private Timer screenTimer; private long scrTimerCnt; private Integer brigntLevel; private Integer darkTime;// minit public long startVoteTime;// 启动投票时间 用于测试10选1 功能 public AdminFragment adminFragment; private ServicePresent servicePresent; private View service; private boolean isActivitiActive; // private NetworkConnectChangedReceiver wifiReciver = new // NetworkConnectChangedReceiver(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Log.d(TAG, "onCreate: "); // Window window = getWindow(); // WindowManager.LayoutParams params = window.getAttributes(); // params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION ; // window.setAttributes(params); setContentView(R.layout.activity_main); service = findViewById(R.id.service); if(service != null){ service.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showServiceDialog(); service.setVisibility(View.GONE); } }); } mOnlineInfo = new OnLineInfo(); mOnlineInfo.onLine = 0; presenter = new XPadPresenter(this); setOfflineFragment(); // // wifiSsid = "SunVote_RD_2.4G"; // //wifiSsid = "SunVote_RD_5G"; // wifiPwd="sunvote1502"; // serverIp = "192.168.0.123"; // serverPort = 4002; // mKeypadInfo = new KeypadInfo(); // mKeypadInfo.keyId = 5; // // FragmentTransaction transaction = fm.beginTransaction(); // transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); // downloadFragment = new DownloadFragment(); // downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort,mKeypadInfo.keyId); // transaction.add(R.id.frame_content, downloadFragment); // transaction.commitAllowingStateLoss(); // // darkTime = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "darkTime", 3); brigntLevel = (Integer) SharedPreferencesUtil.getData(MainActivity.this, "bright", 30); ScreenUtil.setNormalMode(MainActivity.this, brigntLevel); screenTimer = new Timer(true); screenTimer.schedule(screenTask, 1000, 1000); // 延时1000ms后执行,1000ms执行一次 clearApkFile(); FirmUpdateFragment.clearUpdateFile(); } @Override public void onAttachedToWindow() { // if(true) { // this.getWindow().setType(WindowManager.LayoutParams.TYPE_KEYGUARD); // } super.onAttachedToWindow(); } public void hideBottomUIMenu() { // 隐藏虚拟按键,并且全屏 if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower // api View v = this.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else if (Build.VERSION.SDK_INT >= 19) { // for new api versions. View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | 0x00002000; decorView.setSystemUiVisibility(uiOptions); } XPadSystem.setNavgationGone(this); } public void showBottomUIMenu() { // 隐藏虚拟按键,并且全屏 if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower // api View v = this.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else if (Build.VERSION.SDK_INT >= 19) { // for new api versions. View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY //| View.SYSTEM_UI_FLAG_FULLSCREEN & ~0x00002000; decorView.setSystemUiVisibility(uiOptions); } XPadSystem.setNavgationVisible(this); } @Override protected void onResume() { hideBottomUIMenu(); isActivitiActive = true; super.onResume(); } @Override protected void onPause() { Log.d(TAG, "onPause"); isActivitiActive = false; ScreenUtil.setNormalMode(MainActivity.this, brigntLevel); super.onPause(); } @Override protected void onStop() { Log.d(TAG, "onstop"); XPadSystem.setNavgationVisible(this); super.onStop(); } @Override protected void onDestroy() { super.onDestroy(); showBottomUIMenu(); if (batteryLevelRcvr != null) { unregisterReceiver(batteryLevelRcvr); } } public Handler myHandler = new Handler() { @SuppressLint("ShowToast") public void handleMessage(Message msg) { switch (msg.what) { case Msg_ComError: LogUtil.d(TAG,"Msg_ComError"); setComErrorFragment(); break; case Msg_Offline: LogUtil.d(TAG,"Msg_Offline"); setOfflineFragment(); break; case Msg_Online: LogUtil.d(TAG,"on Msg_Online"); setOnlineFragment(); break; case Msg_Download: LogUtil.d(TAG,"on Msg_Download"); setDownloadFragment(); break; case Msg_StopDownload: LogUtil.d(TAG,"on Msg_StopDownload"); if (downloadFragment != null) { downloadFragment.stopDownload(); hideDownloadFragment(); } if (dbm != null) { try { dbm.closeDB(); dbm = null; }catch (Exception e){ e.printStackTrace(); } } docFragment = null; File apkFile = checkUpdateApkFile(); File firmFile = FirmUpdateFragment.checkFirmFile(); String str = String.format("Msg_StopDownload apkFile:%s ,firmFile:%s",apkFile!=null?"Y":"N",firmFile!=null?"Y":"N"); //Toast.makeText(MainActivity.this,str,Toast.LENGTH_LONG).show(); Log.d(TAG, "handleMessage: "+ str); if ( firmFile != null) { Log.i(TAG, "handleMessage: firm update"); setFirmUpdateFragment(); } else if (apkFile != null) { Log.i(TAG, "handleMessage: install apk"); installApk(apkFile); } else { Log.i(TAG, "handleMessage: stop download and getBaseStatus"); presenter.getBaseStatus(); } // dbm.closeDB(); // if (meetingInfo != null) { // setWelcomeFragment(); // } else { // setOnlineFragment(); // } break; case Msg_Welcome: LogUtil.d(TAG,"Msg_Welcome"); setWelcomeFragment(); break; case Msg_ShowBill: BaseInfo baseInfo = (BaseInfo) msg.obj; LogUtil.d(TAG,"on Msg_ShowBill pageNo:"+baseInfo.pageNo); /*if(baseInfo.pageNo<=0){ showBill(null,1); }*/ if(baseInfo.pageNo>0){ setPDFContextShowFragment(baseInfo); }else{ showBill(null,baseInfo.pageNo); } break; case Msg_DocumentBroswer: LogUtil.d(TAG,"on Msg_DocumentBroswer"); setDocumentBrowserFragment(); break; case MSG_DELAY_TO_VIEW: if (mBaseInfo != null && mBaseInfo.billId == 255) { // 自由浏览 freeBrowsing(); } break; case Msg_onVoteEvent: LogUtil.d(TAG,"on Msg_onVoteEvent"); VoteInfo vote = (VoteInfo) msg.obj; doVote(vote); break; case Msg_onCommitSuccessEvent: LogUtil.d(TAG,"on Msg_onCommitSuccessEvent"); if(multiContentFragment!=null){ multiContentFragment.onVoteSubmitSuccess(); } if (currFragment != null) { currFragment.onVoteSubmitSuccess(); } if(addCurrFragment != null){ addCurrFragment.onVoteSubmitSuccess(); } break; case Msg_onCommitErrorEvent: LogUtil.d(TAG,"on Msg_onCommitErrorEvent"); if(multiContentFragment!=null){ multiContentFragment.onVoteSubmitError(); }else{ if (currFragment != null) { currFragment.onVoteSubmitError(); } } if(addCurrFragment != null){ addCurrFragment.onVoteSubmitError(); } break; case Msg_onCommitAllOkSuccessEvent: LogUtil.d(TAG,"on Msg_onCommitAllOkSuccessEvent"); if(multiContentFragment!=null){ multiContentFragment.onVoteSubmitAllOkSuccess(); } if (currFragment != null) { currFragment.onVoteSubmitAllOkSuccess(); } if(addCurrFragment != null){ addCurrFragment.onVoteSubmitAllOkSuccess(); } break; case Msg_onMultiPackageData:// 显示结果 LogUtil.d(TAG,"on Msg_onMultiPackageData"); break; case Msg_ShowMultiVoteResult: LogUtil.d(TAG,"on Msg_ShowMultiVoteResult"); showMultiVoteResultFragment((byte[]) msg.obj); break; case Msg_ShowCustomTitleResult: LogUtil.d(TAG,"on Msg_ShowCustomTitleResult"); showVoteResultFragment((byte[]) msg.obj); break; case Msg_ShowElectionVoteResult: LogUtil.d(TAG,"on Msg_ShowElectionVoteResult"); showResultElectionFragment((byte[]) msg.obj); break; case Msg_HideVoteResult:// 隐藏结果 LogUtil.d(TAG,"on Msg_HideVoteResult"); hideResultFragment(); break; case Msg_DBfileNotExist: LogUtil.d(TAG,"on Msg_DBfileNotExist"); setNoFileFragment(); break; case Msg_CommunicationTest: LogUtil.d(TAG,"on Msg_CommunicationTest"); showCommucationFragment((byte[]) msg.obj); break; case Msg_ShowID: LogUtil.d(TAG,"on Msg_ShowID"); setShowIdFragment(); break; case Msg_HideShowID: LogUtil.d(TAG,"on Msg_HideShowID"); hideShowIdFragment(); break; case Msg_MatchInfo: LogUtil.d(TAG,"on Msg_MatchInfo"); KeypadInfo info = (KeypadInfo) msg.obj; ShowMatchInfo(info); break; case Msg_CommunicationTestHideResult: LogUtil.d(TAG,"on Msg_CommunicationTestHideResult"); dlg.dismiss(); break; case Msg_ScreenDark: ScreenUtil.setDarkMode(MainActivity.this); break; case Msg_ChangeBright: LogUtil.d(TAG,"on Msg_onCoMsg_ChangeBrightmmitAllOkSuccessEvent"); brigntLevel = msg.arg1; Log.d(TAG, "-----change bright percent :" + brigntLevel); ScreenUtil.setNormalMode(MainActivity.this, brigntLevel); break; case Msg_ScreenAutoDark: if (! isLoadPDF) { ScreenUtil.setDarkMode(MainActivity.this); } break; case Msg_FirmUpdate: LogUtil.d(TAG,"on Msg_FirmUpdate"); setFirmUpdateFragment(); break; case Msg_HideFirmUpdate: LogUtil.d(TAG,"on Msg_HideFirmUpdate"); hideFirmUpdateFragment(); break; case Msg_ClearLocalFile: clearLocalFile(); break; case Msg_EnterAdmin: showAdmin(); break; case Msg_onServiceCommitOk: servicePresent.onServiceSubmitSuccess(); break; case Msg_SynchronBrowser: break; case Msg_DownloadFile:// 文件下载 if(addCurrFragment instanceof DownloadAuditionFragment){ addCurrFragment.onSubmitData(msg.arg1,msg.obj); }else{ addCurrFragment(new DownloadAuditionFragment(msg.obj,msg.arg1)); } break; default: } super.handleMessage(msg); } }; private void showAdmin(){ FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); AdminFragment fAdmin = new AdminFragment(); tx.setCustomAnimations(android.R.animator.fade_in,android.R.animator.fade_out); tx.add(R.id.frame_content, fAdmin, "admin"); tx.addToBackStack(null); tx.commitAllowingStateLoss(); } private void ShowMatchInfo(KeypadInfo info) { if (info.cmd1 == 8) { // 配对 String strMsg = null; if (info.ok == 1) { strMsg = "配对成功,频点:" + info.chan + " 键盘编号:" + info.keyId; } else { strMsg = "配对失败"; } Toast.makeText(this, strMsg, Toast.LENGTH_LONG).show(); } else if (info.cmd1 == 9) { String strMsg = null; if (info.ok == 1) { strMsg = "配置成功,频点:" + info.chan + " 键盘编号:" + info.keyId; } else { strMsg = "配置失败"; } Toast.makeText(this, strMsg, Toast.LENGTH_LONG).show(); } } private void hideResultFragment() { if (resultFragment == null) { return; } FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(resultFragment); tx.commitAllowingStateLoss(); resultFragment = null; } private ProgressDialog dlg = null; private CommunicationTestFragment commFragment; private void showCommucationFragment(byte[] info) { if (dlg == null) { dlg = new ProgressDialog(MainActivity.this); dlg.setCancelable(true);// 设置是否可以通过点击Back键取消 dlg.setCanceledOnTouchOutside(true);// 设置在点击Dialog外是否取消Dialog进度条 } if (!dlg.isShowing()) { dlg.show(); } dlg.setTitle("通讯测试"); dlg.setMessage("通讯测试 次数:" + info[0] + " 成功次数:" + info[1] + " 基站信号:" + info[2] + " 键盘信号:" + info[3]); myHandler.postDelayed(new Runnable() { @Override public void run() { Message message = new Message(); message.what = Msg_CommunicationTestHideResult; myHandler.sendMessage(message); } }, 60000); } private void showResultElectionFragment(byte[] buffer) { Log.e(TAG, "showVoteResultFragment"); int voteId = buffer[3] & 0xff; if (dbm == null) { Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show(); return; } currBillInfo = dbm.getBillInfo(meetingId, voteId); if (currBillInfo == null) { Toast.makeText(this, "显示选举结果失败,没有找到会议资料", Toast.LENGTH_LONG).show(); return; } if(currBillInfo.billNo==0 && currBillInfo.billId==0){ Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } hideCurrFragment(); hideResultFragment(); FragmentTransaction transaction = fm.beginTransaction(); ResultElectionFragment fr = new ResultElectionFragment(); fr.data = buffer; fr.bill = currBillInfo; resultFragment = fr; transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.add(R.id.frame_content, fr); transaction.addToBackStack(null); transaction.commitAllowingStateLoss(); } private void showVoteResultFragment(byte[] buffer) { Log.e(TAG, "showVoteResultFragment"); int voteId = buffer[3] & 0xff; if (dbm == null) { Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show(); return; } currBillInfo = dbm.getBillInfo(meetingId, voteId); if (currBillInfo == null) { Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_LONG).show(); return; } if (currBillInfo.billOptions == null) { Toast.makeText(this, "显示结果失败,选项为空", Toast.LENGTH_LONG).show(); return; } hideCurrFragment(); hideResultFragment(); FragmentTransaction transaction = fm.beginTransaction(); ResultVoteFragment fr = new ResultVoteFragment(); fr.voteInfo = null; fr.data = buffer; fr.bill = currBillInfo; fr.options = currBillInfo.billOptions.split("/"); resultFragment = fr; transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.add(R.id.frame_content, fr); transaction.addToBackStack(null); transaction.commitAllowingStateLoss(); } private void showVoteResultFragment(VoteInfo vote) { Log.e(TAG, "showVoteResultFragment"); if (dbm == null) { Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show(); return; } FragmentTransaction transaction = fm.beginTransaction(); ResultVoteFragment fr = new ResultVoteFragment(); fr.voteInfo = vote; fr.bill = currBillInfo; resultFragment = fr; transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.add(R.id.frame_content, fr); transaction.addToBackStack("resultVote"); transaction.commitAllowingStateLoss(); } private void showMultiVoteResultFragment(byte[] buffer) { Log.e(TAG, "showMultiVoteResultFragment"); int voteId = buffer[3] & 0xff; if (dbm == null) { Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show(); return; } currBillInfo = dbm.getBillInfo(meetingId, voteId); if (currBillInfo == null) { Toast.makeText(this, "显示批次结果失败,没有找到会议资料", Toast.LENGTH_LONG).show(); return; } if (currBillInfo.billOptions == null) { Toast.makeText(this, "显示批次结果失败,选项为空", Toast.LENGTH_LONG).show(); return; } hideCurrFragment(); hideResultFragment(); FragmentTransaction transaction = fm.beginTransaction(); ResultMultiVoteFragment fr = new ResultMultiVoteFragment(); fr.bill = currBillInfo; fr.data = buffer; resultFragment = fr; // transaction.setCustomAnimations(android.R.animator.fade_in,android.R.animator.fade_out); transaction.add(R.id.frame_content, fr); transaction.addToBackStack(null); transaction.commitAllowingStateLoss(); } private void setFirmUpdateFragment() { // if (firmFragment != null) { // Log.d(TAG, "setFirmUpdateFragment: firmFragment != null,return"); // return; // } Log.d(TAG, "setFirmUpdateFragment: "); FragmentTransaction transaction = fm.beginTransaction(); firmFragment = new FirmUpdateFragment(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.frame_content, firmFragment); // transaction.addToBackStack(null); transaction.commitAllowingStateLoss(); } private void hideFirmUpdateFragment() { if (firmFragment != null) { FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(firmFragment); tx.commitAllowingStateLoss(); firmFragment = null; } } private void showNoFileMessage() { FragmentTransaction transaction = fm.beginTransaction(); Fragment fr = new MeetingWelcomeFragment(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setOfflineFragment() { FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); Fragment fr = new OfflineFragment(); transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setComErrorFragment() { FragmentTransaction transaction = fm.beginTransaction(); Fragment fr = new ComErrorFragment(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setOnlineFragment() { FragmentTransaction transaction = fm.beginTransaction(); Fragment fr = new OnLineFragment(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setShowIdFragment() { if (showIdFragment == null) { FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); showIdFragment = new ShowIdFragment(); transaction.add(R.id.frame_content, showIdFragment); transaction.addToBackStack(null); transaction.commitAllowingStateLoss(); } } private void hideShowIdFragment() { if (showIdFragment != null) { FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(showIdFragment); tx.commitAllowingStateLoss(); showIdFragment = null; } } private void setKeypadTestFragment() { if(keypadTestFragment != null){ return; } inKeyTesting = true; FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); keypadTestFragment = new KeypadTestFragment(); tx.add(R.id.frame_content, keypadTestFragment, "keytest"); tx.addToBackStack(null); tx.commitAllowingStateLoss(); } private void setChoice10Fragment() { if(keypadTestFragment != null){ return; } inKeyTesting = true; FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); keypadTestFragment = new KeypadTestChoice10Fragment(); tx.add(R.id.frame_content, keypadTestFragment, "keytest"); tx.addToBackStack(null); tx.commitAllowingStateLoss(); } private void hideKeypadTestFragment() { inKeyTesting = false; if (keypadTestFragment != null) { FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(keypadTestFragment); tx.commitAllowingStateLoss(); keypadTestFragment = null; } } private long lastSetDownloadTime = 0; private void setDownloadFragment() { if (downloadFragment != null) { LogUtil.d(TAG, "downloading ,ignore redownload"); return; } clearApkFile(); FirmUpdateFragment.clearUpdateFile(); if (mKeypadInfo == null) { presenter.getKeypadParam(); } if (wifiSsid == null || wifiSsid.length() == 0) { Toast.makeText(this, "wifiSsid is null ", Toast.LENGTH_SHORT).show(); LogUtil.d(TAG, "wifiSsid is null"); return; } if (wifiPwd == null || wifiPwd.length() == 0) { Toast.makeText(this, "wifiPwd is null ", Toast.LENGTH_SHORT).show(); LogUtil.d(TAG, "wifiPwd is null"); return; } if (serverIp == null || serverIp.length() == 0) { Toast.makeText(this, "serverIp is null ", Toast.LENGTH_SHORT).show(); LogUtil.d(TAG, "serverIp is null"); return; } // if(serverPort == 0){ // Toast.makeText(this, "serverPort is 0 ", Toast.LENGTH_SHORT); // return; // } LogUtil.d(TAG, "start show Download UI------"); serverPort = 4002; lastSetDownloadTime = System.currentTimeMillis(); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); downloadFragment = new DownloadFragment(); downloadFragment.setInfo(wifiSsid, wifiPwd, serverIp, serverPort,mKeypadInfo.keyId); transaction.add(R.id.frame_content, downloadFragment); transaction.commitAllowingStateLoss(); } private void hideDownloadFragment() { if (downloadFragment != null) { if(downloadFragment.isFinishDownload == false){ LogUtil.d(TAG, "forceStopDownload--"); downloadFragment.forceStopDownload(); } LogUtil.d(TAG, "start hide Download UI------"); FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(downloadFragment); tx.commitAllowingStateLoss(); downloadFragment = null; } } private void setWelcomeFragment() { LogUtil.d(TAG,"setWelcomeFragment"); // if (mBaseInfo == null) { // mBaseInfo = new BaseInfo(); // mBaseInfo.confId = 1; // } if (meetingInfo != null) { Log.d(TAG, "setWelcomeFragment " + meetingInfo.meetingTitle); } if(billFragment!=null){ if (billFragment != null) { FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(billFragment); tx.commitAllowingStateLoss(); billFragment = null; } } FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); Fragment fr = new MeetingWelcomeFragment(); transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setNoFileFragment() { // if (mBaseInfo == null) { // mBaseInfo = new BaseInfo(); // mBaseInfo.confId = 1; // } if(downloadFragment != null){ return; } if (meetingInfo != null) { Log.d(TAG, "setNoFileFragment " + meetingInfo.meetingTitle); } FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); NoFileFragment fr = new NoFileFragment(); fr.meetingId = meetingId; transaction.replace(R.id.frame_content, fr); transaction.commitAllowingStateLoss(); } private void setSigninFragment(VoteInfo info) { FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); SigninFragment fr = new SigninFragment(); fr.setInfo(info); currFragment = fr; transaction.add(R.id.frame_content, currFragment); transaction.addToBackStack("sign"); transaction.commitAllowingStateLoss(); } private void setQuickVoteFragment() { FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); SingleTitleFragment fr = new SingleTitleFragment(); fr.setInfo(currBillInfo); currFragment = fr; transaction.replace(R.id.frame_content, currFragment); transaction.commitAllowingStateLoss(); } private void setTitleVoteFragment(VoteInfo vote) { if(vote.mode4==101) { //自定义评测 if (currBillInfo == null) { Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } if(MyStringUtil.isEmpty(currBillInfo.billOptions)){ Toast.makeText(this, "显示批次结果失败,选项为空", Toast.LENGTH_LONG).show(); return; } } FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); SingleTitleFragment fr = new SingleTitleFragment(); fr.setInfo(currBillInfo,vote); currFragment = fr; transaction.add(R.id.frame_content, currFragment); transaction.addToBackStack("titleVote"); transaction.commitAllowingStateLoss(); } private void setMultiTitleVoteFragment(VoteInfo vote) { Log.d(TAG, "setMultiTitleVoteFragment"); if (currBillInfo == null) { Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } if(currBillInfo.billNo==0 && currBillInfo.billId==0){ Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } if(currBillInfo.billOptions.split("/") == null){ Toast.makeText(this, "显示批次结果失败,选项为空", Toast.LENGTH_LONG).show(); return; } ArrayList list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); MultiTitleFragment fr = new MultiTitleFragment(); fr.setInfo(currBillInfo, vote, list); currFragment = fr; transaction.add(R.id.frame_content, currFragment); transaction.addToBackStack("multititleVote"); transaction.commitAllowingStateLoss(); } private void setSingleContentVoteFragment() { FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); ContentVoteFragment fr = new ContentVoteFragment(); fr.setInfo(currBillInfo); currFragment = fr; transaction.replace(R.id.frame_content, currFragment); transaction.commitAllowingStateLoss(); } private void setMultiContentVoteFragment() { ArrayList list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); MultiContentFragment fr = new MultiContentFragment(); fr.setInfo(currBillInfo,list); currFragment = fr; transaction.replace(R.id.frame_content, currFragment); transaction.commitAllowingStateLoss(); } private void setDocumentBrowserFragment() { ArrayList list = dbm.getBillItemsMain(meetingId); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); if (docFragment == null) { docFragment = new DocumentBrowserFragment(); docFragment.setInfo(list,false); } transaction.replace(R.id.frame_content, docFragment); transaction.commitAllowingStateLoss(); } private void showBill(final VoteInfo vInfo, final int pageNo) { if (currBillInfo.billFile == null) { return; } FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); if (vInfo != null) { MultiContentDetailFragment fr = new MultiContentDetailFragment(); fr.setInfo(currBillInfo, vInfo, false,pageNo, UIType.SingleCoutent); currFragment = fr; tx.add(R.id.frame_content, currFragment, "fDetail"); tx.addToBackStack(null); tx.commitAllowingStateLoss(); } else { if(billFragment instanceof MultiContentDetailFragment){ ((MultiContentDetailFragment)billFragment).setPdfPage(pageNo); }else{ MultiContentDetailFragment fDetail = new MultiContentDetailFragment(); fDetail.setInfo(currBillInfo,vInfo,false,pageNo, UIType.SingleCoutent); tx.add(R.id.frame_content, fDetail, "fDetail"); billFragment = fDetail; tx.addToBackStack(null); tx.commitAllowingStateLoss(); } } /*tx.addToBackStack(null); tx.commitAllowingStateLoss();*/ } private void setMultiPinsShengFragment() { ArrayList list = dbm.getMultiTitleItems(meetingId, currBillInfo.billId); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); MultiPingshengFragment fr = new MultiPingshengFragment(); fr.setInfo(currBillInfo, list); currFragment = fr; transaction.replace(R.id.frame_content, currFragment); transaction.commitAllowingStateLoss(); } private void setPDFContextShowFragment(BaseInfo baseInfo) { Log.d(TAG, "setPDFContextShowFragment: pgageNo:"+baseInfo.pageNo); if (currBillInfo == null) { Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } String dataPath = android.os.Environment.getExternalStorageDirectory().getAbsolutePath(); String filePath = dataPath + "/sunvote/" + meetingId + "/" + currBillInfo.billFile; File file=new File(filePath); if (!file.exists()) { Toast.makeText(this,"议案文件未找到",Toast.LENGTH_LONG).show(); return; } FragmentManager fm = getFragmentManager(); FragmentTransaction tx = fm.beginTransaction(); PDFContextShowFragment fr = new PDFContextShowFragment(); fr.setInfo(filePath, currBillInfo.billFile,baseInfo.pageNo+"","1",true); if(isLoadPDF){ if(!fr.PDFLastOpenFilename.equals(currBillInfo.billFile)){ removePDFContextShowFragment(); isLoadPDF = false; }else{ fr.setTopBarstate(); fr.setPageIndex(baseInfo.pageNo); fr.lockPageState(1); } } pdfFragment = fr; tx.add(R.id.frame_content, fr, "PDF"); tx.addToBackStack(null); tx.commitAllowingStateLoss(); } public void removePDFContextShowFragment() { if(pdfFragment!=null){ PDFContextShowFragment fr = (PDFContextShowFragment)pdfFragment; fr.setCloseFile(); pdfFragment = null; } } private void setElectionVoteFragment(VoteInfo vote) { /* meetingId=1; if (dbm == null || !dbm.checkDB() || dbm.confId != meetingId) { dbm = new DBManager(this, meetingId);// 如果没打开,则打开数据库 }*/ if (dbm == null) { Toast.makeText(this, "请先开始会议", Toast.LENGTH_LONG).show(); return; } currBillInfo = dbm.getBillInfo(meetingId, vote.electInfo.voteid); if (currBillInfo == null) { Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } if(currBillInfo.billNo==0 && currBillInfo.billId==0){ Toast.makeText(this, "没找到议案信息", Toast.LENGTH_LONG).show(); return; } ArrayList list = dbm.getCandidateList(meetingId, currBillInfo.billId); FragmentTransaction transaction = fm.beginTransaction(); transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); ElectionFragment fr = new ElectionFragment(); fr.setInfo(currBillInfo,list,vote); currFragment = fr; transaction.add(R.id.frame_content, currFragment); transaction.addToBackStack("electionVote"); transaction.commitAllowingStateLoss(); } public void getBillInfo(int billId) { currBillInfo = dbm.getBillInfo(meetingId, billId); } @Override public void onComData(byte[] data, int len) { // TODO Auto-generated method stub } @Override public void onSendData(byte[] data, int len) { // TODO Auto-generated method stub } @Override public void onModelEvent(ModelInfo info) { Log.d(TAG, "onModelEvent"); mModelInfo = info; if (firmFragment != null) { Intent intent = new Intent(); intent.setAction("com.xpad.firm"); intent.putExtra("ver", info.sVer); MainActivity.this.sendBroadcast(intent); Log.d(TAG, "send broadcast"); // firmFragment.setFirmVer(mModelInfo.sVer); } } private boolean isSameBaseInfo(BaseInfo bInfo){ return bInfo.pageNo == mBaseInfo.pageNo && bInfo.attrib == mBaseInfo.attrib && bInfo.authCode == mBaseInfo.authCode && bInfo.baseId == mBaseInfo.baseId && bInfo.billId == mBaseInfo.billId && bInfo.idMode == mBaseInfo.idMode && bInfo.confId == mBaseInfo.confId && bInfo.login == mBaseInfo.login && bInfo.report == mBaseInfo.report && bInfo.offTime == mBaseInfo.offTime; } private long lastBaseEventTime = 0; @Override public void onBaseEvent(BaseInfo info) { if (System.currentTimeMillis() - lastBaseEventTime < XPadPresenter.REPEAT_INTERVAL && isSameBaseInfo(info)) { LogUtil.d(TAG, "ignore repeat onBaseEvent"); return; } mBaseInfo = info; LogUtil.d(TAG, "baseEvent ------------------- confId:" + info.confId + " bill ID:" + info.billId); meetingId = info.confId; if (info.confId != 0) { presenter.getVoteStatus(); if (dbm != null && dbm.confId != info.confId) { dbm.closeDB(); docFragment = null; } if (dbm == null || !dbm.checkDB() || dbm.confId != info.confId) { dbm = new DBManager(this, info.confId);// 如果没打开,则打开数据库 } if (!dbm.checkDB()) { Message message = new Message(); message.what = Msg_DBfileNotExist; myHandler.sendMessage(message); return; } if (meetingInfo == null || info.billId <= 1) { meetingInfo = dbm.getMettingInfo(info.confId); } if (info.billId == 0) { // 没有议案的情况,显示欢迎界面 if (mOnlineInfo.onLine == 1) { /*if(mVoteInfo!=null && (mVoteInfo.mode!= 0 || mVoteInfo.mode1_msgType == 2)){ return; }*/ removePDFContextShowFragment(); Message message = new Message(); message.what = Msg_Welcome; myHandler.sendMessage(message); } } else if (info.billId == 255) { // 自由浏览 if (dbm.checkDB()) { /*if(mVoteInfo!=null && mVoteInfo.mode!= 0){ return; }*/ removePDFContextShowFragment(); Message message = new Message(); message.what = Msg_DocumentBroswer; myHandler.sendMessage(message); } } else {// 进入议案 /*if(mVoteInfo!=null && (mVoteInfo.mode!= 0 || mVoteInfo.mode1_msgType == 2)){ return; }*/ currBillInfo = dbm.getBillInfo(info.confId, info.billId); Message message = new Message(); message.what = Msg_ShowBill; message.obj = info; myHandler.sendMessage(message); // processBaseEvent(); } // 显示会议标题 } else {// confId为0 ,表示停止会议 Log.d(TAG, "baseEvent confId为0--- send Msg_Online and close DB"); if (mOnlineInfo.onLine == 1) { Message message = new Message(); message.what = Msg_Online; myHandler.sendMessage(message); } if (dbm != null) { dbm.closeDB(); } } } private void freeBrowsing() { if (dbm.checkDB()) { removePDFContextShowFragment(); Message message = new Message(); message.what = Msg_DocumentBroswer; myHandler.sendMessage(message); } } @Override public void onVoteEvent(VoteInfo info) { startVoteTime = System.currentTimeMillis(); LogUtil.d(TAG, "onVoteEvent ========== mode=" + info.mode + " voteId:" + info.voteid); // if(meetingId == 0 && info.voteid != 0){ // Log.d(TAG, "onVoteEvent: meetingid=0,voteid="+info.voteid + " ,abort ! getBaseStatus"); // //Toast.makeText(this, "启动表决失败,未取到会议ID", Toast.LENGTH_LONG).show(); // try{ // Thread.sleep(500); // }catch (Exception e){ // e.printStackTrace(); // } // presenter.getBaseStatus(); // return; // } Message message = new Message(); message.what = Msg_onVoteEvent; message.obj = info; myHandler.sendMessage(message); } private void hideCurrFragment() { removeAddCurrFragment(); if (currFragment != null) { FragmentTransaction tx = fm.beginTransaction(); tx.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out); tx.remove(currFragment); tx.commitAllowingStateLoss(); currFragment = null; } } private void doVote(VoteInfo voteInfo) { mVoteInfo=voteInfo; /*if(mBaseInfo!=null && mBaseInfo.pageNo!=0){ return; }*/ if (voteInfo.mode == XPadApi.VoteType_KeypadTest) { setKeypadTestFragment(); return; } else if (voteInfo.mode == XPadApi.VoteType_Choice && voteInfo.mode5 == 10) { setChoice10Fragment(); return; } else if (voteInfo.mode == XPadApi.VoteType_Stop) { if (inKeyTesting) { hideKeypadTestFragment(); return; } } if(mBaseInfo!=null){ if(mBaseInfo.billId==0 || mBaseInfo.billId==255){ removePDFContextShowFragment(); } } hideResultFragment(); /* * 暂时去掉角色 if (mKeypadInfo != null && dbm != null) { roleType = * dbm.getKeypadRole(mKeypadInfo.keyId); Log.d(TAG, "roleType:" + * roleType); } if (roleType == 0) {// 列席代表不处理 return; } */ tmpMulResultBuffer = null; if (!(voteInfo.mode == XPadApi.VoteType_Stop && voteInfo.mode1_msgType == 2 && voteInfo.resultInfo.resultType == XPadApi.VoteType_BatchVote)) { hideCurrFragment(); } if (dbm == null || !dbm.checkDB() ) { dbm = new DBManager(this, this.meetingId);// 如果没打开,则打开数据库 } // voteInfo.voteid = 1;//debug if (voteInfo.voteid > 0 && voteInfo.voteid < 255) { try { currBillInfo = dbm.getBillInfo(meetingId, voteInfo.voteid); } catch (Exception e) { e.printStackTrace(); } } if (currBillInfo == null) { Log.e(TAG, "BillInfo not found!!!"); } if (voteInfo.mode == XPadApi.VoteType_Stop) { Log.d(TAG, "getBackStackEntryCount:" + fm.getBackStackEntryCount()); if (voteInfo.mode1_msgType == 2) { // 结果显示 if (voteInfo.resultInfo.resultType == XPadApi.VoteType_BatchVote) { // 多项 if (currFragment != null) { currFragment.onVoteEvent(voteInfo); } } else { if (voteInfo.resultInfo.resultType !=101 && voteInfo.resultInfo.resultType != XPadApi.VoteType_BatchElect){ showVoteResultFragment(voteInfo); } } } } else if (voteInfo.mode == XPadApi.VoteType_Signin) { setSigninFragment(voteInfo); }else if (voteInfo.mode == XPadApi.VoteType_Evaluate){ }else if(voteInfo.mode == XPadApi.VoteType_BatchElect){ setElectionVoteFragment(voteInfo); }else if(voteInfo.mode==XPadApi.VoteType_BatchEvalue){//综合测评带名称(实名制) ScoreNameDao scoreNameDao=new ScoreNameDaoImpl(); ScoreNameRuleDao scoreNameRuleDao=new ScoreNameRuleDaoImpl(); if(!scoreNameDao.isBooleanData() && !scoreNameRuleDao.isBooleanData()){ Toast.makeText(this, "显示评分失败,没有找到评分资料", Toast.LENGTH_LONG).show(); return; } replaceCurrFragment(new TableMainFragment(mVoteInfo)); }else if(voteInfo.mode==XPadApi.VoteType_BatchIDEvalue) { ScoreNameDao scoreNameDao=new ScoreNameDaoImpl(); ScoreNameRuleDao scoreNameRuleDao=new ScoreNameRuleDaoImpl(); if(!scoreNameDao.isBooleanData() && !scoreNameRuleDao.isBooleanData()){ Toast.makeText(this, "显示评分失败,没有找到评分资料", Toast.LENGTH_LONG).show(); return; } replaceCurrFragment(new TableMainFragment(mVoteInfo)); }else { if (voteInfo.mode == XPadApi.VoteType_BatchVote) { if (dbm != null && dbm.checkDB()) { setMultiTitleVoteFragment(voteInfo); } else { Log.d(TAG, "doVote: "+"启动批次表决失败,会议" + meetingId + "不存在,请下载会议资料"); if(meetingId>0) { Toast.makeText(this, "启动批次表决失败,会议" + meetingId + "不存在,请下载会议资料", Toast.LENGTH_LONG).show(); }//presenter.getBaseStatus(); } } else { if (voteInfo.init == 0 || checkHasBillFile(currBillInfo) == false) { setTitleVoteFragment(voteInfo); } else { billFragment=null; showBill(voteInfo,1); } } } // if (currFragment != null) { // currFragment.onVoteEvent(msg.arg1, msg.arg2, msg.obj); // } } private boolean checkHasBillFile(BillInfo bill) { return (bill != null && bill.billFile != null && bill.billFile.length() > 0); } @Override public void onVoteSubmitSuccess() { Message message = new Message(); message.what = Msg_onCommitSuccessEvent; myHandler.sendMessage(message); } @Override public void onVoteSubmitAllOkSuccess() { Message message = new Message(); message.what = Msg_onCommitAllOkSuccessEvent; myHandler.sendMessage(message); } @Override public void onServiceSubmitSuccess() { Message message = new Message(); message.what = Msg_onServiceCommitOk; myHandler.sendMessage(message); } @Override public void onKeyPadEvent(KeypadInfo info) { Log.d(TAG, "onKeyPadEvent"); mKeypadInfo = info; XPadSystem.setStatusBarPadID(this, info.keyId); XPadSystem.setStatusBarChannel(this, info.chan); if (info.cmd1 == 8 || info.cmd1 == 9) { Message message = new Message(); message.what = Msg_MatchInfo; message.obj = info; myHandler.sendMessage(message); } } @Override public void onOnLineEvent(OnLineInfo info) { if (info.comError == 1) { if (info.comError != mOnlineInfo.comError) { Message message = new Message(); message.what = Msg_ComError; myHandler.sendMessage(message); } LogUtil.i(TAG, "onOnLineEvent: comError"); } else { if (info.onLine != mOnlineInfo.onLine) { if (info.onLine == 1) { Message message = new Message(); message.what = Msg_Online; myHandler.sendMessage(message); LogUtil.i(TAG, "onOnLineEvent: onLine , getBaseStatus"); myHandler.postDelayed(new Runnable() { @Override public void run() { LogUtil.d(TAG,"presenter.getBaseStatus()"); presenter.getBaseStatus(); } },2000); } else { Message message = new Message(); message.what = Msg_Offline; myHandler.sendMessage(message); LogUtil.i(TAG, "onOnLineEvent: offLine"); } } } mOnlineInfo = info; XPadSystem.setStatusBarDataIcon(this, info.tx, info.rx); XPadSystem.setStatusBarChannel(this, info.chan); XPadSystem.setStatusBarBaseId(this, getString(R.string.base_id) + ":" + info.baseId); XPadSystem.setStatusBarSingal(this, info.rssi); } private CmdDataInfo cmdInfo; private long lastRecvCmdDataTime; @Override public void onCmdData(CmdDataInfo info) { if (cmdInfo != null && info.cmd == cmdInfo.cmd && Arrays.equals(info.data, cmdInfo.data) && (System.currentTimeMillis() - lastRecvCmdDataTime < 2000)) { Log.i(TAG, "onCmdData,recv same data, ignore!"); return; } lastRecvCmdDataTime = System.currentTimeMillis(); cmdInfo = info; XPadApi.printDataBuf(info.data, info.data.length, "cmd:" + info.cmd + " data:"); if (info.cmd == 7) { // 键盘测试 Message message = new Message(); message.what = Msg_CommunicationTest; message.obj = info.data; myHandler.sendMessage(message); } else if (info.cmd == 10) {// 显示编号 if (info.data[0] == 0) { Log.d(TAG, "Msg_HideShowID"); Message message = new Message(); message.what = Msg_HideShowID; myHandler.sendMessage(message); } else { Log.d(TAG, "Msg_ShowID"); Message message = new Message(); message.what = Msg_ShowID; myHandler.sendMessage(message); } } else if (info.cmd == 5) {// 关机 XPadSystem.powerOffXPad(this); } else if (info.cmd == 50) {// 主控透传 byte cmd = info.data[0]; Log.i(TAG, "cmd:" + cmd); byte[] data = Arrays.copyOfRange(info.data, 1, 18); Message message = null; switch (cmd) { case 0x31:// wifi ssid wifiSsid = new String(data).trim(); Log.d(TAG, "receve 0x31 wifi ssid:" + wifiSsid); break; case 0x32:// wifi pwd wifiPwd = new String(data).trim(); Log.d(TAG, "receve 0x32 wifi pwd:" + wifiPwd); break; case 0x33: // ip serverIp = new String(data).trim(); Log.d(TAG, "receve 0x33 server ip:" + serverIp); break; case 0x34: // start download Log.d(TAG, "receve start download"); message = new Message(); message.what = Msg_Download; myHandler.sendMessage(message); break; case 0x35: // stop download Log.d(TAG, "receve stop download"); message = new Message(); message.what = Msg_StopDownload; myHandler.sendMessage(message); break; case 0x36: // 暂去掉角色控制 Log.d(TAG, "not support"); break; // roleType = info.data[1] == 0x30 ? 0 : 1; // 1是正式代表,0是列席代表,不响应投票 // dbm.writeKeypadRole(mKeypadInfo.keyId, roleType); // Log.d(TAG, "role:" + roleType); // break; case 0x37: XPadSystem.rebootXPad(this); break; case 0x38: message = new Message(); message.what = Msg_HideVoteResult; myHandler.sendMessage(message); break; case 0x39: message = new Message(); message.what = Msg_ChangeBright; message.arg1 = info.data[1]; myHandler.sendMessage(message); SharedPreferencesUtil.saveData(MainActivity.this, "bright", Integer.valueOf(info.data[1])); break; case 0x40: if (info.data[1] == 0) { message = new Message(); message.what = Msg_ScreenDark; myHandler.sendMessage(message); } else { message = new Message(); message.what = Msg_ChangeBright; message.arg1 = brigntLevel; myHandler.sendMessage(message); } break; case 0x41: darkTime = Integer.valueOf(info.data[1]); scrTimerCnt = 0; Log.d(TAG, "set darkTime:" + darkTime); SharedPreferencesUtil.saveData(MainActivity.this, "darkTime", darkTime); break; case 0x42: message = new Message(); message.what = Msg_ClearLocalFile; myHandler.sendMessage(message); break; case 0x43: message = new Message(); message.what = Msg_EnterAdmin; myHandler.sendMessage(message); break; case 0x66: message = new Message(); message.what = Msg_SynchronBrowser; myHandler.sendMessage(message); break; default: break; } } } private byte[] tmpMulResultBuffer; @Override public void onMultiPackageData(byte[] data, int len) { XPadApi.printDataBuf(data, len, "onMultiPackageData:"); byte[] buf = new byte[len]; Arrays.fill(buf, (byte) 0x0); try { System.arraycopy(data, 0, buf, 0, len); }catch (Exception e){ LogUtil.d(TAG,e.getMessage()); e.printStackTrace(); } if ((data[0] & 0xff) == 0xF2 && data[1] == 20) { if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) { Log.e(TAG , "onMultiPackageData same data,abort"); return; } tmpMulResultBuffer = buf; Message message = new Message(); message.what = Msg_ShowMultiVoteResult; message.obj = buf; myHandler.sendMessage(message); return; } //选举结果 if ((data[0] & 0xff) == 0xF2 && data[1] == 22) { if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) { Log.e(TAG , "onMultiPackageData same data,abort"); return; } tmpMulResultBuffer = buf; Message message = new Message(); message.what = Msg_ShowElectionVoteResult; message.obj = buf; myHandler.sendMessage(message); return; } //自定义表决结果 if ((data[0] & 0xff) == 0xF2 && data[1] == 101) { if (tmpMulResultBuffer != null && Arrays.equals(buf, tmpMulResultBuffer)) { Log.e(TAG , "onMultiPackageData same data,abort"); return; } tmpMulResultBuffer = buf; Message message = new Message(); message.what = Msg_ShowCustomTitleResult; message.obj = buf; myHandler.sendMessage(message); return; } if ((data[0] & 0xff) == 0xF4 && (data[1] & 0xff) == 0xF5) { //规则表 int downType = data[2]; int downId = data[3]; byte[] dt = Arrays.copyOfRange(data, 4, data.length - 4);// 从len开始,和文档下标统一 int itemNum = ((dt[2] & 0xff) << 8) | (dt[3] & 0xff); int scoreMode = dt[4]; if (downType == 1 && downId == 1) { Log.d(TAG, "固定编号项目名称表:" + len); List scoreNameInfoLs = new ArrayList(); for (int i = 0; i < itemNum * 2; i += 2) { int index = ((dt[16 + i] & 0xff) << 8) | (dt[16 + i + 1] & 0xff); int nextIndex = ((dt[16 + i + 2] & 0xff) << 8) | (dt[16 + i + 3] & 0xff); int sPos = index * 16; int ePos = nextIndex * 16; int attr = dt[sPos]; int rule = dt[sPos + 1]; String strName = ""; try { byte[] nameBuf = Arrays.copyOfRange(dt, sPos + 2, ePos + 1); strName = new String(nameBuf, "GB2312").trim(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } Log.i(TAG, "itemNum:" + i / 2 + " attr:" + attr + " rule:" + rule + " itemName:" + strName); ScoreNameInfo scoreNameInfo=new ScoreNameInfo(); scoreNameInfo.setScoreNum((i / 2)+1); scoreNameInfo.setScoreName(strName); scoreNameInfoLs.add(scoreNameInfo); } Message message = new Message(); message.what = Msg_DownloadFile; message.obj = scoreNameInfoLs; message.arg1= DownloadType.MultipleAssessItem.getIndex(); myHandler.sendMessage(message); } if (downType == 1 && downId == 3) {// Log.d(TAG, "二维评测指标名称表(评分规则表):" + len); List scoreNameRuleInfoLs = new ArrayList(); for (int i = 0; i < itemNum * 2; i += 2) { int index = ((dt[16 + i] & 0xff) << 8) | (dt[16 + i + 1] & 0xff); int nextIndex = ((dt[16 + i + 2] & 0xff) << 8) | (dt[16 + i + 3] & 0xff); int sPos = index * 16; int ePos = nextIndex * 16; int attr = dt[sPos]; int rule = dt[sPos + 1]; String strName = ""; try { byte[] nameBuf = Arrays.copyOfRange(dt, sPos + 2, ePos + 1); strName = new String(nameBuf, "GB2312").trim(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } Log.i(TAG, "itemNum:" + i / 2 + " attr:" + attr + " rule:" + rule + " itemName:" + strName); ScoreNameRuleInfo scoreNameRuleInfo = new ScoreNameRuleInfo(); scoreNameRuleInfo.setScoreNum((i / 2)+1); scoreNameRuleInfo.setScoreName(strName); scoreNameRuleInfo.setScoreRule(rule); scoreNameRuleInfo.setScoreRuleType(attr); scoreNameRuleInfoLs.add(scoreNameRuleInfo); } Message message = new Message(); message.what = Msg_DownloadFile; message.obj = scoreNameRuleInfoLs; message.arg1= DownloadType.MultipleAssessRule.getIndex(); myHandler.sendMessage(message); } else if (downType == 2 && downId == 1) { Log.d(TAG, "评议规则表:" + len); List evaluationRuleInfoLs = new ArrayList(); int i = 0; while (i < len) { if ((dt[i] & 0xff) == 0xF5) { //表头 int roleIndex = dt[i + 1]; //第几个规则字段表 int greadNum = dt[i + 2]; //等级个数 int defaultNum = dt[i + 3]; //默认值 ArrayList greadList = new ArrayList(); String strName = ""; for (int j = 1; j <= greadNum; j++) { try { byte[] nameBuf = Arrays.copyOfRange(dt, i + j * 16, i + j * 16 + 16); strName = strName + "," + new String(nameBuf, "GB2312").trim(); greadList.add(strName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } } Log.i(TAG, "评议规则" + roleIndex + " 等级个数:" + greadNum + " 默认值:" + defaultNum + " 等级:" + strName); EvaluationRuleInfo evaluationRuleInfo =new EvaluationRuleInfo(); evaluationRuleInfo.setItemNum(roleIndex); evaluationRuleInfo.setItemName(strName); evaluationRuleInfo.setDefaultValue(defaultNum); evaluationRuleInfoLs.add(evaluationRuleInfo); i += (greadNum + 1) * 16; } else { i+=16; } } Message message = new Message(); message.what = Msg_DownloadFile; message.obj = evaluationRuleInfoLs; message.arg1= DownloadType.EvaluationRule.getIndex(); myHandler.sendMessage(message); } else if (downType == 3 && downId == 1) { Log.d(TAG, "评分规则表:" + len); List scoreRuleInfoLs = new ArrayList(); itemNum = len / 32; for (int i = 0; i < itemNum; i += 1) { String unitName = ""; try { byte[] unitBuf = Arrays.copyOfRange(dt, i * 32 + 1, i * 32 + 5); unitName = new String(unitBuf, "GB2312").trim(); } catch (Exception e) { e.printStackTrace(); } int intNum = dt[i * 32 + 5]; int decNum = dt[i * 32 + 6]; byte[] bBuf = Arrays.copyOfRange(dt, i * 32 + 8, i * 32 + 8 + 8); String defaultVal = XPadApi.util_decodeBCD(bBuf, 4); bBuf = Arrays.copyOfRange(dt, i * 32 + 16, i * 32 + 16 + 8); String minVal = XPadApi.util_decodeBCD(bBuf, 4); bBuf = Arrays.copyOfRange(dt, i * 32 + 24, i * 32 + 24 + 8); String maxVal = XPadApi.util_decodeBCD(bBuf, 4); Log.i(TAG, "itemNum:" + i + " unitName:" + unitName + " intNum:" + intNum + " decNum:" + decNum + " defaultVal:" + defaultVal + " minVal:" + minVal + " maxVal:" + maxVal); ScoreRuleInfo scoreRuleInfo=new ScoreRuleInfo(); scoreRuleInfo.setRuleNum(i+1); scoreRuleInfo.setUnit(unitName); scoreRuleInfo.setIntNum(intNum); scoreRuleInfo.setDecNum(decNum); scoreRuleInfo.setDefaultValue(defaultVal); scoreRuleInfo.setMin(minVal); scoreRuleInfo.setMax(maxVal); scoreRuleInfoLs.add(scoreRuleInfo); } Message message = new Message(); message.what = Msg_DownloadFile; message.obj = scoreRuleInfoLs; message.arg1= DownloadType.ScoreRule.getIndex(); myHandler.sendMessage(message); } else if (downType == 3 && downId == 2) { Log.d(TAG, "评分规则说明信息表:" + len); List scoreRuleExplainInfoLs = new ArrayList(); for (int i = 0; i < itemNum * 2; i += 2) { int index = ((dt[16 + i] & 0xff) << 8) | (dt[16 + i + 1] & 0xff); int nextIndex = ((dt[16 + i + 2] & 0xff) << 8) | (dt[16 + i + 3] & 0xff); int sPos = index * 16; int ePos = nextIndex * 16; int attr = dt[sPos]; int rule = dt[sPos + 1]; String strName = ""; try { byte[] nameBuf = Arrays.copyOfRange(dt, sPos + 2, ePos + 1); strName = new String(nameBuf, "GB2312").trim(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); }catch (Exception e){ e.printStackTrace(); } Log.i(TAG, "itemNum:" + i / 2 + " attr:" + attr + " rule:" + rule + " itemName:" + strName); ScoreRuleExplainInfo scoreRuleExplainInfo=new ScoreRuleExplainInfo(); scoreRuleExplainInfo.setRuleNum((i / 2)+1); scoreRuleExplainInfo.setScoreExplain(strName); scoreRuleExplainInfoLs.add(scoreRuleExplainInfo); } Message message = new Message(); message.what = Msg_DownloadFile; message.obj = scoreRuleExplainInfoLs; message.arg1= DownloadType.ScoreRuleExplain.getIndex(); myHandler.sendMessage(message); } return; } String str; try { str = new String(buf, "GB2312").trim(); Log.d(TAG, "onMultiPackageInfo:" + str); Message message = new Message(); message.what = Msg_onMultiPackageData; message.arg1 = len; message.obj = str; myHandler.sendMessage(message); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } private void processRoleTable(byte[] data,int len){ int downType = data[2]; int downId = data[3]; byte[] dt = Arrays.copyOfRange(data, 4, data.length - 4);// 从len开始,和文档下标统一 int itemNum = ((dt[2] & 0xff)<< 8) | (dt[3]& 0xff); int scoreMode = dt[4]; if(downType == 1 && downId == 1){ Log.d(TAG, "固定编号项目名称表:"+ len); for(int i= 0;i greadList = new ArrayList(); String strName = ""; for(int j=1;j<=greadNum;j++){ byte[] nameBuf = Arrays.copyOfRange(dt, i+j*16, i+j*16 + 16); try { strName = strName + "," + new String(nameBuf, "GB2312").trim(); greadList.add(strName); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } } Log.i(TAG, "评议规则" +roleIndex + " 等级个数:"+ greadNum + " 默认值:"+ defaultNum + " 等级:"+ strName); i += (greadNum+1) * 16; }else{ i+=16; } } }else if(downType == 3 && downId == 1){ Log.d(TAG, "评分规则表:"+ len); itemNum = len/32; for(int i=0 ; i < itemNum ; i += 1){ byte[] unitBuf = Arrays.copyOfRange(dt, i*32+1, i*32 + 5); String unitName = ""; try { unitName = new String(unitBuf,"GB2312").trim() ; } catch (Exception e) { e.printStackTrace(); } int intNum = dt[i*32+5]; int decNum = dt[i*32+6]; byte[] bBuf = Arrays.copyOfRange(dt, i*32+8, i*32+8+8); String defaultVal = XPadApi.util_decodeBCD(bBuf,4); bBuf = Arrays.copyOfRange(dt, i*32+16, i*32 + 16 + 8); String minVal = XPadApi.util_decodeBCD(bBuf,4); bBuf = Arrays.copyOfRange(dt, i*32+24, i*32 + 24 +8); String maxVal = XPadApi.util_decodeBCD(bBuf,4); Log.i(TAG, "itemNum:" + i + " unitName:"+ unitName +" intNum:" + intNum + " decNum:" + decNum + " defaultVal:" + defaultVal + " minVal:" +minVal +" maxVal:"+maxVal); } }else if(downType == 3 && downId == 2){ Log.d(TAG, "评分规则说明信息表:"+ len); for(int i= 0;i