MainActivity.java 3.32 KB
package com.sunvote.xpadapp;

import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.widget.TextView;

import com.sunvote.xpadapi.service.XpadApiService;
import com.sunvote.xpadapi.service.logic.XpadApiServiceInfoProxyManager;
import com.sunvote.xpadapi.service.bean.BaseInfo;
import com.sunvote.xpadapi.service.bean.BaseVoteInfo;
import com.sunvote.xpadapi.service.bean.OnLineInfo;
import com.sunvote.xpadapi.service.listener.BaseInfoChanageListener;
import com.sunvote.xpadapi.service.listener.BaseVoteInfoChanageListener;
import com.sunvote.xpadapi.service.listener.OnlineInfoChanageListener;
import com.sunvote.xpadapp.base.BaseActivity;

public class MainActivity extends BaseActivity {

    private Handler handler;
    private TextView terminalId;
    private Fragment fragment;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        Intent intent = new Intent(this, XpadApiService.class);
        startService(intent);
        setContentView(R.layout.activity_main);
        terminalId = findViewById(R.id.terminal_id);
        handler = new Handler();
        XpadApiServiceInfoProxyManager.getInstance().setOnlineInfoChanageListener(onlineInfoChanageListener);
        XpadApiServiceInfoProxyManager.getInstance().setBaseInfoListener(onBaseInfoListener);
        XpadApiServiceInfoProxyManager.getInstance().setBaseVoteInfoListener(baseVoteInfoChanageListener);
    }

    private BaseVoteInfoChanageListener baseVoteInfoChanageListener = new BaseVoteInfoChanageListener() {
        @Override
        public void onBaseVoteInfoListener(BaseVoteInfo newBaseVoteInfo) {

        }
    };

    private BaseInfoChanageListener onBaseInfoListener = new BaseInfoChanageListener() {

        @Override
        public void onBaseInfoChange(BaseInfo newBaseInfo) {

        }
    };

    private OnlineInfoChanageListener onlineInfoChanageListener = new OnlineInfoChanageListener() {

        @Override
        public void onOnlineInfoChanage(OnLineInfo newOnlineInfo) {
            showEvent();
        }
    };

    private void showEvent(){
        if (XpadApiServiceInfoProxyManager.getInstance().getOnLineInfo().getOnLine() == 2) {
            // 离线界面
        } else if (XpadApiServiceInfoProxyManager.getInstance().getBaseVoteInfo().getMode() > 0) {
            // 显示对应的投票界面
        } else if (XpadApiServiceInfoProxyManager.getInstance().getBaseInfo() != null) {// 修改
            // 自由浏览
        } else if (XpadApiServiceInfoProxyManager.getInstance().getBaseInfo() != null) {//修改
            // 欢迎界面
        } else {
            // 在线界面
        }
    }

    private void showFragment(Fragment frag){
        if(!(frag != null && fragment != null && frag.getClass().getSimpleName().equals(fragment.getClass().getSimpleName()))){
            fragment = frag;
            FragmentManager fm = getFragmentManager();
            FragmentTransaction transaction = fm.beginTransaction();
            transaction.setCustomAnimations(android.R.animator.fade_in, android.R.animator.fade_out);
            transaction.replace(R.id.frame_content, fragment);
            transaction.commitAllowingStateLoss();
        }
    }
}