diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 98f2730..24cbbac 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -28,6 +28,10 @@ android:name=".InterstitialActivity" android:theme="@style/Theme.Breakingnews"> + + diff --git a/app/src/main/java/io/sixminutes/breakingnews/ClickTrackerActivity.kt b/app/src/main/java/io/sixminutes/breakingnews/ClickTrackerActivity.kt new file mode 100755 index 0000000..c4e9326 --- /dev/null +++ b/app/src/main/java/io/sixminutes/breakingnews/ClickTrackerActivity.kt @@ -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 + ) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/io/sixminutes/breakingnews/MainActivity.kt b/app/src/main/java/io/sixminutes/breakingnews/MainActivity.kt index 503812a..19a6243 100644 --- a/app/src/main/java/io/sixminutes/breakingnews/MainActivity.kt +++ b/app/src/main/java/io/sixminutes/breakingnews/MainActivity.kt @@ -1,8 +1,8 @@ package io.sixminutes.breakingnews +import android.content.Intent import android.os.Build import android.os.Bundle -import android.util.Log import androidx.activity.ComponentActivity import androidx.activity.compose.setContent import androidx.activity.result.contract.ActivityResultContracts @@ -13,9 +13,11 @@ import androidx.compose.material3.Text import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.unit.dp import io.sixminutes.breakingnews.ui.theme.BreakingnewsTheme import kotlin.system.exitProcess + class MainActivity : ComponentActivity() { private val TAG = "breakingNews" @@ -57,7 +59,7 @@ class MainActivity : ComponentActivity() { adStatus = "Ad 1 Loading..." }, onShowAd2 = { - InterstitialAdManager.showAd(this@MainActivity, "be20b7a9d66e8895", interstitialLauncher) + InterstitialAdManager.showAd(this@MainActivity, "be20b7a9d66e8896", interstitialLauncher) adStatus = "Ad 2 Loading..." }, onKillApp = { @@ -125,6 +127,7 @@ fun MainContent( onKillApp: () -> Unit ) { val deviceModel = Build.MODEL + val context = LocalContext.current Column( modifier = Modifier.fillMaxSize(), @@ -152,6 +155,16 @@ fun MainContent( 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) } } \ No newline at end of file