MainActivity.java
3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
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();
        }
    }
}