GIT 提交信息:

添加 ClickTrackerActivity 并增强 MainActivity 功能

- 引入一个新活动,以便在应用程序中实现点击追踪功能。
- 使用 Jetpack Compose 增强用户界面,以支持交互式点击检测。
- 更新广告配置,并提供从 MainActivity 启动新 ClickTrackerActivity 的直接方式。
This commit is contained in:
lvlisong 2025-02-14 13:11:04 +08:00
parent 7f6734670e
commit abece2ebfc
3 changed files with 89 additions and 2 deletions

View File

@ -28,6 +28,10 @@
android:name=".InterstitialActivity" android:name=".InterstitialActivity"
android:theme="@style/Theme.Breakingnews"> android:theme="@style/Theme.Breakingnews">
</activity> </activity>
<activity
android:name=".ClickTrackerActivity"
android:theme="@style/Theme.Breakingnews">
</activity>
</application> </application>

View File

@ -0,0 +1,70 @@
package io.sixminutes.breakingnews
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.gestures.detectTapGestures
import androidx.compose.foundation.layout.*
import androidx.compose.material3.Text
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.geometry.Offset
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.input.pointer.pointerInput
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
class ClickTrackerActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ClickTrackerScreen()
}
}
}
@Composable
fun ClickTrackerScreen() {
var clickCount by remember { mutableStateOf(0) }
var lastClickPosition by remember { mutableStateOf("No clicks yet") }
val context = LocalContext.current // 获取当前 Context
Box(
modifier = Modifier
.fillMaxSize()
.pointerInput(Unit) {
detectTapGestures { offset ->
// 更新点击坐标
lastClickPosition = "Last click: (${offset.x.toInt()}, ${offset.y.toInt()})"
clickCount++
// 如果点击次数达到 10 次,打开系统浏览器
if (clickCount >= 10) {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse("https://www.google.com"))
context.startActivity(intent) // 使用 context 启动 Activity
}
}
},
contentAlignment = Alignment.Center
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
verticalArrangement = Arrangement.Center
) {
Text(
text = lastClickPosition,
fontSize = 20.sp,
color = Color.Black
)
Spacer(modifier = Modifier.height(16.dp))
Text(
text = "Click count: $clickCount",
fontSize = 20.sp,
color = Color.Black
)
}
}
}

View File

@ -1,8 +1,8 @@
package io.sixminutes.breakingnews package io.sixminutes.breakingnews
import android.content.Intent
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.util.Log
import androidx.activity.ComponentActivity import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent import androidx.activity.compose.setContent
import androidx.activity.result.contract.ActivityResultContracts import androidx.activity.result.contract.ActivityResultContracts
@ -13,9 +13,11 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.* import androidx.compose.runtime.*
import androidx.compose.ui.Alignment import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.unit.dp import androidx.compose.ui.unit.dp
import io.sixminutes.breakingnews.ui.theme.BreakingnewsTheme import io.sixminutes.breakingnews.ui.theme.BreakingnewsTheme
import kotlin.system.exitProcess import kotlin.system.exitProcess
class MainActivity : ComponentActivity() { class MainActivity : ComponentActivity() {
private val TAG = "breakingNews" private val TAG = "breakingNews"
@ -57,7 +59,7 @@ class MainActivity : ComponentActivity() {
adStatus = "Ad 1 Loading..." adStatus = "Ad 1 Loading..."
}, },
onShowAd2 = { onShowAd2 = {
InterstitialAdManager.showAd(this@MainActivity, "be20b7a9d66e8895", interstitialLauncher) InterstitialAdManager.showAd(this@MainActivity, "be20b7a9d66e8896", interstitialLauncher)
adStatus = "Ad 2 Loading..." adStatus = "Ad 2 Loading..."
}, },
onKillApp = { onKillApp = {
@ -125,6 +127,7 @@ fun MainContent(
onKillApp: () -> Unit onKillApp: () -> Unit
) { ) {
val deviceModel = Build.MODEL val deviceModel = Build.MODEL
val context = LocalContext.current
Column( Column(
modifier = Modifier.fillMaxSize(), modifier = Modifier.fillMaxSize(),
@ -152,6 +155,16 @@ fun MainContent(
Spacer(modifier = Modifier.height(16.dp)) Spacer(modifier = Modifier.height(16.dp))
// 添加 Test 按钮
Button(onClick = {
val intent = Intent(context, ClickTrackerActivity::class.java)
context.startActivity(intent)
}) {
Text(text = "Test")
}
Spacer(modifier = Modifier.height(16.dp))
Text(text = adStatus) Text(text = adStatus)
} }
} }