Skip to content

Commit 5268580

Browse files
Add files via upload
1 parent c0cab8a commit 5268580

3 files changed

Lines changed: 371 additions & 136 deletions

File tree

app/src/main/kotlin/com/google/ai/sample/MainActivity.kt

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package com.google.ai.sample
1818

1919
import android.content.Intent
2020
import android.os.Bundle
21+
import android.util.Log
2122
import android.widget.Toast
2223
import androidx.activity.ComponentActivity
2324
import androidx.activity.compose.setContent
@@ -34,12 +35,17 @@ import com.google.ai.sample.feature.text.SummarizeRoute
3435
import com.google.ai.sample.ui.theme.GenerativeAISample
3536

3637
class MainActivity : ComponentActivity() {
38+
companion object {
39+
private const val TAG = "MainActivity"
40+
}
41+
3742
// Add screenshot manager
3843
private lateinit var screenshotManager: ScreenshotManager
3944

4045
override fun onCreate(savedInstanceState: Bundle?) {
4146
super.onCreate(savedInstanceState)
42-
47+
Log.d(TAG, "onCreate")
48+
4349
// Initialize screenshot manager
4450
screenshotManager = ScreenshotManager.getInstance(this)
4551

@@ -73,30 +79,69 @@ class MainActivity : ComponentActivity() {
7379
}
7480

7581
// Request screenshot permission when the app starts
82+
Log.d(TAG, "Requesting screenshot permission")
7683
screenshotManager.requestScreenshotPermission(this)
7784
}
7885

79-
@Deprecated("Deprecated in Java")
8086
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
8187
super.onActivityResult(requestCode, resultCode, data)
88+
Log.d(TAG, "onActivityResult: requestCode=$requestCode, resultCode=$resultCode")
8289

8390
if (requestCode == ScreenshotManager.REQUEST_MEDIA_PROJECTION) {
8491
if (resultCode == RESULT_OK && data != null) {
8592
val success = screenshotManager.handlePermissionResult(resultCode, data)
8693
if (success) {
94+
Log.d(TAG, "Screenshot permission granted")
8795
Toast.makeText(this, "Screenshot permission granted", Toast.LENGTH_SHORT).show()
96+
97+
// Test the screenshot capability after a short delay
98+
/*
99+
Handler(Looper.getMainLooper()).postDelayed({
100+
testScreenshot()
101+
}, 5000)
102+
*/
88103
} else {
89-
Toast.makeText(this, "Failed to get screenshot permission", Toast.LENGTH_SHORT).show()
104+
Log.e(TAG, "Failed to set up screenshot capability")
105+
Toast.makeText(this, "Failed to set up screenshot capability", Toast.LENGTH_SHORT).show()
90106
}
91107
} else {
108+
Log.e(TAG, "Screenshot permission denied by user")
92109
Toast.makeText(this, "Screenshot permission denied", Toast.LENGTH_SHORT).show()
93110
}
94111
}
95112
}
96113

114+
/*
115+
private fun testScreenshot() {
116+
Log.d(TAG, "Testing screenshot capability")
117+
Toast.makeText(this, "Taking test screenshot...", Toast.LENGTH_SHORT).show()
118+
119+
screenshotManager.takeScreenshot { bitmap ->
120+
if (bitmap != null) {
121+
Log.d(TAG, "Test screenshot successful: ${bitmap.width}x${bitmap.height}")
122+
Toast.makeText(this, "Test screenshot successful", Toast.LENGTH_SHORT).show()
123+
124+
// Save the bitmap
125+
val file = screenshotManager.saveBitmapToFile(bitmap)
126+
if (file != null) {
127+
Log.d(TAG, "Screenshot saved to ${file.absolutePath}")
128+
Toast.makeText(this, "Screenshot saved to ${file.name}", Toast.LENGTH_SHORT).show()
129+
} else {
130+
Log.e(TAG, "Failed to save screenshot")
131+
Toast.makeText(this, "Failed to save screenshot", Toast.LENGTH_SHORT).show()
132+
}
133+
} else {
134+
Log.e(TAG, "Test screenshot failed")
135+
Toast.makeText(this, "Test screenshot failed", Toast.LENGTH_SHORT).show()
136+
}
137+
}
138+
}
139+
*/
140+
97141
override fun onDestroy() {
142+
Log.d(TAG, "onDestroy")
98143
// Release screenshot manager resources
99144
screenshotManager.release()
100145
super.onDestroy()
101146
}
102-
}
147+
}

0 commit comments

Comments
 (0)