|
@@ -1,25 +1,35 @@
|
|
|
package com.eyuangame.demo
|
|
|
|
|
|
-import android.app.Activity
|
|
|
import android.content.Intent
|
|
|
import android.os.Bundle
|
|
|
import android.os.Handler
|
|
|
import android.os.Looper
|
|
|
import android.os.Message
|
|
|
-import android.view.Gravity
|
|
|
import android.view.KeyEvent
|
|
|
-import android.view.View
|
|
|
import android.widget.*
|
|
|
+import androidx.activity.compose.setContent
|
|
|
+import androidx.appcompat.app.AppCompatActivity
|
|
|
+import androidx.compose.foundation.layout.Column
|
|
|
+import androidx.compose.foundation.layout.fillMaxSize
|
|
|
+import androidx.compose.foundation.layout.padding
|
|
|
+import androidx.compose.foundation.rememberScrollState
|
|
|
+import androidx.compose.foundation.verticalScroll
|
|
|
+import androidx.compose.material.Button
|
|
|
+import androidx.compose.material.MaterialTheme
|
|
|
+import androidx.compose.material.Surface
|
|
|
+import androidx.compose.material.Text
|
|
|
+import androidx.compose.runtime.*
|
|
|
+import androidx.compose.ui.Modifier
|
|
|
+import androidx.compose.ui.tooling.preview.Preview
|
|
|
+import androidx.compose.ui.unit.dp
|
|
|
import cn.yyxx.eyuangame.base.EYuanGame
|
|
|
import cn.yyxx.eyuangame.base.entity.SdkChargeInfo
|
|
|
import cn.yyxx.eyuangame.base.entity.SdkEvent
|
|
|
import cn.yyxx.eyuangame.base.entity.SdkRoleInfo
|
|
|
import cn.yyxx.eyuangame.base.internal.ICallback
|
|
|
-import cn.yyxx.support.DensityUtils
|
|
|
-import cn.yyxx.support.ResUtils
|
|
|
import cn.yyxx.support.hawkeye.LogUtils
|
|
|
import cn.yyxx.support.hawkeye.ToastUtils
|
|
|
-import cn.yyxx.support.ui.GifView
|
|
|
+import com.eyuangame.demo.ui.theme.EYuanGameSdkKTXTheme
|
|
|
import kotlin.system.exitProcess
|
|
|
|
|
|
|
|
@@ -27,7 +37,7 @@ import kotlin.system.exitProcess
|
|
|
* @author #Suyghur.
|
|
|
* Created on 2021/06/09
|
|
|
*/
|
|
|
-class DemoActivity : Activity(), View.OnClickListener {
|
|
|
+class DemoActivity : AppCompatActivity() {
|
|
|
|
|
|
private val events = mutableListOf(
|
|
|
Item(0, "00 接口环境切换"),
|
|
@@ -41,23 +51,21 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
Item(8, "08 模拟CP打点(玩家首次完成新手引导)"),
|
|
|
Item(0, "09 模拟CP打点(玩家首次完成结缘)"),
|
|
|
Item(10, "10 crashlytics崩溃测试"),
|
|
|
- Item(11, "11 Facebook分享测试")
|
|
|
+ Item(11, "11 Facebook分享测试"),
|
|
|
+ Item(12, "12 sdk日志上报测试")
|
|
|
)
|
|
|
|
|
|
-
|
|
|
- private lateinit var layout: LinearLayout
|
|
|
- private lateinit var mTextView: TextView
|
|
|
- private lateinit var gifView: GifView
|
|
|
-
|
|
|
private var cacheRoleInfo: CacheRoleInfo.RoleInfo? = null
|
|
|
-
|
|
|
+ private val messageBuffer by lazy {
|
|
|
+ StringBuilder()
|
|
|
+ }
|
|
|
+ private var message by mutableStateOf("")
|
|
|
private val handler = object : Handler(Looper.getMainLooper()) {
|
|
|
override fun handleMessage(msg: Message) {
|
|
|
when (msg.what) {
|
|
|
10001 -> {
|
|
|
- with(mTextView) {
|
|
|
- text = text.toString() + msg.obj.toString()
|
|
|
- }
|
|
|
+ messageBuffer.append(msg.obj.toString())
|
|
|
+ message = messageBuffer.toString()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -65,7 +73,14 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
override fun onCreate(savedInstanceState: Bundle?) {
|
|
|
super.onCreate(savedInstanceState)
|
|
|
- initView()
|
|
|
+
|
|
|
+ setContent {
|
|
|
+ EYuanGameSdkKTXTheme {
|
|
|
+ Surface(color = MaterialTheme.colors.background) {
|
|
|
+ DemoPage()
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
LogUtils.handler = handler
|
|
|
EYuanGame.getInstance().initialize(this, true, object : ICallback {
|
|
|
override fun onResult(code: Int, result: String) {
|
|
@@ -74,112 +89,112 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
})
|
|
|
}
|
|
|
|
|
|
- private fun initView() {
|
|
|
- layout = LinearLayout(this)
|
|
|
- layout.orientation = LinearLayout.VERTICAL
|
|
|
|
|
|
- val gifLayoutParams = LinearLayout.LayoutParams(DensityUtils.dip2px(this, 100f), DensityUtils.dip2px(this, 100f))
|
|
|
- gifLayoutParams.gravity = Gravity.CENTER
|
|
|
- gifView = GifView(this)
|
|
|
- gifView.setGifResource(ResUtils.getResId(this, "cpp", "drawable"))
|
|
|
- gifView.layoutParams = gifLayoutParams
|
|
|
- layout.addView(gifView)
|
|
|
-
|
|
|
- initButton()
|
|
|
- mTextView = TextView(this)
|
|
|
- with(mTextView) {
|
|
|
- text = ""
|
|
|
- this@DemoActivity.layout.addView(this)
|
|
|
+ @Composable
|
|
|
+ fun DemoPage() {
|
|
|
+ Column(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxSize()
|
|
|
+ .verticalScroll(rememberScrollState()),
|
|
|
+ ) {
|
|
|
+ events.forEach {
|
|
|
+ Button(
|
|
|
+ modifier = Modifier
|
|
|
+ .fillMaxSize()
|
|
|
+ .padding(start = 10.dp, end = 10.dp),
|
|
|
+ onClick = { onClick(it.id) }
|
|
|
+ ) {
|
|
|
+ Text(text = it.name)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Text(text = message)
|
|
|
}
|
|
|
- val scrollView = ScrollView(this)
|
|
|
- scrollView.addView(layout)
|
|
|
- setContentView(scrollView)
|
|
|
}
|
|
|
|
|
|
- private fun initButton() {
|
|
|
- for (event in events) {
|
|
|
- with(Button(this)) {
|
|
|
- text = event.name
|
|
|
- tag = event.id
|
|
|
- id = event.id
|
|
|
- setOnClickListener(this@DemoActivity)
|
|
|
- this@DemoActivity.layout.addView(this)
|
|
|
+ @Preview
|
|
|
+ @Composable
|
|
|
+ fun PreviewDemoPage() {
|
|
|
+ EYuanGameSdkKTXTheme {
|
|
|
+ Surface(color = MaterialTheme.colors.background) {
|
|
|
+ DemoPage()
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- override fun onClick(v: View?) {
|
|
|
- v?.apply {
|
|
|
- mTextView.text = ""
|
|
|
- when (tag as Int) {
|
|
|
- 0 -> EnvActivity.start(this@DemoActivity)
|
|
|
- 1 -> {
|
|
|
- EYuanGame.getInstance().login(this@DemoActivity, true, object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
- if (code == 0) {
|
|
|
- cacheRoleInfo = CacheRoleInfo.getDemoRoleInfo(this@DemoActivity, EYuanGame.getInstance().getCurrentUserId())
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- 2 -> {
|
|
|
- EYuanGame.getInstance().logout(this@DemoActivity, object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- if (code == 0) {
|
|
|
- EYuanGame.getInstance().login(this@DemoActivity, false, object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- }
|
|
|
- })
|
|
|
- }
|
|
|
- 3 -> {
|
|
|
- cacheRoleInfo = null
|
|
|
- cacheRoleInfo = CacheRoleInfo.setDemoRoleInfo(this@DemoActivity, EYuanGame.getInstance().getCurrentUserId())
|
|
|
- EYuanGame.getInstance().roleCreate(this@DemoActivity, getGameRoleInfo())
|
|
|
- }
|
|
|
- 4 -> EYuanGame.getInstance().roleLauncher(this@DemoActivity, getGameRoleInfo())
|
|
|
- 5 -> EYuanGame.getInstance().roleLevelUp(this@DemoActivity, getGameRoleInfo())
|
|
|
- 6 -> {
|
|
|
- EYuanGame.getInstance().charge(this@DemoActivity, getGameChargeInfo(), true, object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
+ private fun onClick(action: Int) {
|
|
|
+ messageBuffer.clear()
|
|
|
+ when (action) {
|
|
|
+ 0 -> EnvActivity.start(this@DemoActivity)
|
|
|
+ 1 -> {
|
|
|
+ EYuanGame.getInstance().login(this@DemoActivity, true, object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+ ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
+ if (code == 0) {
|
|
|
+ cacheRoleInfo = CacheRoleInfo.getDemoRoleInfo(this@DemoActivity, EYuanGame.getInstance().getCurrentUserId())
|
|
|
}
|
|
|
-
|
|
|
- })
|
|
|
- }
|
|
|
- 7 -> {
|
|
|
- EYuanGame.getInstance().charge(this@DemoActivity, getGameChargeInfo(), false, object : ICallback {
|
|
|
- override fun onResult(code: Int, result: String) {
|
|
|
- ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ 2 -> {
|
|
|
+ EYuanGame.getInstance().logout(this@DemoActivity, object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+ if (code == 0) {
|
|
|
+ EYuanGame.getInstance().login(this@DemoActivity, false, object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+ ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
-
|
|
|
- })
|
|
|
- }
|
|
|
- 8 -> {
|
|
|
- val sdkEvent = SdkEvent()
|
|
|
- sdkEvent.eventName = "tutorial"
|
|
|
- sdkEvent.standard = true
|
|
|
- sdkEvent.fbAliasName = "fb_mobile_tutorial_completion"
|
|
|
- EYuanGame.getInstance().linkingEvent(this@DemoActivity, sdkEvent)
|
|
|
- }
|
|
|
- 9 -> {
|
|
|
- val sdkEvent = SdkEvent()
|
|
|
- sdkEvent.eventName = "finish_marry"
|
|
|
- sdkEvent.standard = false
|
|
|
- EYuanGame.getInstance().linkingEvent(this@DemoActivity, sdkEvent)
|
|
|
- }
|
|
|
- 10 -> throw RuntimeException("Test Crashlytics Feature")
|
|
|
- 11 -> EYuanGame.getInstance().share(this@DemoActivity, "https://www.baidu.com", "#测试标签", "测试引文", object : ICallback {
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
+ 3 -> {
|
|
|
+ cacheRoleInfo = null
|
|
|
+ cacheRoleInfo = CacheRoleInfo.setDemoRoleInfo(this@DemoActivity, EYuanGame.getInstance().getCurrentUserId())
|
|
|
+ EYuanGame.getInstance().roleCreate(this@DemoActivity, getGameRoleInfo())
|
|
|
+ }
|
|
|
+ 4 -> EYuanGame.getInstance().roleLauncher(this@DemoActivity, getGameRoleInfo())
|
|
|
+ 5 -> EYuanGame.getInstance().roleLevelUp(this@DemoActivity, getGameRoleInfo())
|
|
|
+ 6 -> {
|
|
|
+ EYuanGame.getInstance().charge(this@DemoActivity, getGameChargeInfo(), true, object : ICallback {
|
|
|
override fun onResult(code: Int, result: String) {
|
|
|
+ ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
+ }
|
|
|
|
|
|
+ })
|
|
|
+ }
|
|
|
+ 7 -> {
|
|
|
+ EYuanGame.getInstance().charge(this@DemoActivity, getGameChargeInfo(), false, object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+ ToastUtils.toastInfo(this@DemoActivity, "---- demo提示不做翻译 ----\ncode : $code\n msg : $result\n ---- demo提示不做翻译 ----")
|
|
|
}
|
|
|
|
|
|
})
|
|
|
}
|
|
|
+ 8 -> {
|
|
|
+ val sdkEvent = SdkEvent()
|
|
|
+ sdkEvent.eventName = "tutorial"
|
|
|
+ sdkEvent.standard = true
|
|
|
+ sdkEvent.fbAliasName = "fb_mobile_tutorial_completion"
|
|
|
+ EYuanGame.getInstance().linkingEvent(this@DemoActivity, sdkEvent)
|
|
|
+ }
|
|
|
+ 9 -> {
|
|
|
+ val sdkEvent = SdkEvent()
|
|
|
+ sdkEvent.eventName = "finish_marry"
|
|
|
+ sdkEvent.standard = false
|
|
|
+ EYuanGame.getInstance().linkingEvent(this@DemoActivity, sdkEvent)
|
|
|
+ }
|
|
|
+ 10 -> throw RuntimeException("Test Crashlytics Feature")
|
|
|
+ 11 -> EYuanGame.getInstance().share(this@DemoActivity, "https://www.baidu.com", "#测试标签", "测试引文", object : ICallback {
|
|
|
+ override fun onResult(code: Int, result: String) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ })
|
|
|
+ 12 -> {
|
|
|
+ val zapPath = getExternalFilesDir("dolin/zap")!!.absolutePath
|
|
|
+ ZipUtils.zipAll(zapPath, "$zapPath/test.zip")
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -266,13 +281,11 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
|
|
|
override fun onResume() {
|
|
|
super.onResume()
|
|
|
- gifView.setPaused(false)
|
|
|
EYuanGame.getInstance().onResume(this)
|
|
|
}
|
|
|
|
|
|
override fun onRestart() {
|
|
|
super.onRestart()
|
|
|
- gifView.setPaused(true)
|
|
|
EYuanGame.getInstance().onRestart(this)
|
|
|
}
|
|
|
|
|
@@ -292,7 +305,8 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
exitProcess(0)
|
|
|
}
|
|
|
|
|
|
- override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent) {
|
|
|
+
|
|
|
+ override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
|
|
super.onActivityResult(requestCode, resultCode, data)
|
|
|
EYuanGame.getInstance().onActivityResult(this, requestCode, resultCode, data)
|
|
|
}
|
|
@@ -301,5 +315,7 @@ class DemoActivity : Activity(), View.OnClickListener {
|
|
|
super.onNewIntent(intent)
|
|
|
EYuanGame.getInstance().onNewIntent(this, intent)
|
|
|
}
|
|
|
+}
|
|
|
+
|
|
|
+data class Item(val id: Int, val name: String)
|
|
|
|
|
|
-}
|