罗明文
2024-06-19 481723ce3c05d74fec53b8567b9c79d77bdcc155
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
package com.dollearn.student.ui.game
 
import android.util.TypedValue
import androidx.fragment.app.Fragment
import androidx.viewpager.widget.ViewPager
import cn.sinata.xldutils.utils.myToast
import com.flyco.tablayout.listener.OnTabSelectListener
import com.dollearn.student.R
import com.dollearn.student.ui.TransparentStatusBarActivity
import com.dollearn.student.ui.home.PayResultActivity
import com.dollearn.student.utils.Const
import com.dollearn.student.utils.event.EmptyEvent
import com.dollearn.student.utils.pay.PayListener
import com.dollearn.student.utils.pay.PayUtil
import kotlinx.android.synthetic.main.game_layout_activity.*
import org.greenrobot.eventbus.EventBus
import org.jetbrains.anko.startActivity
 
class GameActivity  : TransparentStatusBarActivity(), PayListener {
    private val frags = arrayListOf<Fragment>()
    override fun setContentView(): Int {
      return R.layout.game_layout_activity
    }
 
    val siteId by lazy { intent.getIntExtra("siteId",0) } //场地id
    val deviceId by lazy { intent.getIntExtra("deviceId",0) } //设备id
 
    override fun initClick() {
 
    }
 
    override fun initView() {
//        frags.add(GameFragment())
        tab_top.setViewPager(view_pager, arrayOf("单机游戏"
//            ,"互联游戏"
        ),this,frags)
        view_pager.addOnPageChangeListener(object :ViewPager.OnPageChangeListener{
            override fun onPageScrolled(
                position: Int,
                positionOffset: Float,
                positionOffsetPixels: Int
            ) {
 
            }
 
            override fun onPageSelected(position: Int) {
                (0 until frags.size).forEach {
                    tab_top.getTitleView(it).setTextSize(TypedValue.COMPLEX_UNIT_SP,18f)
                }
                tab_top.getTitleView(position).setTextSize(TypedValue.COMPLEX_UNIT_SP,22f)
            }
 
            override fun onPageScrollStateChanged(state: Int) {
            }
        })
        tab_top.getTitleView(0).setTextSize(TypedValue.COMPLEX_UNIT_SP,22f)
        PayUtil.addPayListener(this)
    }
 
    override fun onPaySuccess() {
        startActivity<PayResultActivity>("type" to PayResultActivity.TYPE_GAME_SUCCESS)
        finish()
    }
 
    override fun onPayCancel() {
    }
 
    override fun onPayError(msg: String) {
 
    }
 
    override fun onDestroy() {
        super.onDestroy()
        PayUtil.removePayListener(this)
        PayUtil.unregisterApp()
    }
 
    override fun onPause() {
        EventBus.getDefault().post(EmptyEvent(Const.EventCode.GAME_PAUSE))
        super.onPause()
    }
}