Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Update Screenshot Functionality + Screenshot Automation #272

Merged
merged 21 commits into from
Nov 28, 2024
Merged
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
- disable automation test;
MykhailoNester committed Nov 15, 2024
commit e668eafe07917dedfce6738cc52be753e2b5ae60
Original file line number Diff line number Diff line change
@@ -1,55 +1,55 @@
package com.crowdin.platform.example

import android.app.Activity
import android.graphics.Bitmap
import androidx.test.core.app.ActivityScenario
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.crowdin.crowdin_controls.showToast
import com.crowdin.platform.Crowdin
import com.crowdin.platform.screenshot.ScreenshotCallback
import org.junit.Test
import org.junit.runner.RunWith
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit

@RunWith(AndroidJUnit4ClassRunner::class)
class ScreenshotAutomationTest {

@Test
fun automateScreenshotCaptureAndUpload() {
val activityScenario = ActivityScenario.launch(MainActivity::class.java)
val latch = CountDownLatch(1)

activityScenario.onActivity { activity ->
captureAndSendScreenshot(activity, latch)
}

// Wait for the latch to be decremented, or timeout after 5 seconds
latch.await(30, TimeUnit.SECONDS)
activityScenario.close()
}

private fun captureAndSendScreenshot(activity: Activity, latch: CountDownLatch) {
// Capture the screenshot as a Bitmap
val rootView = activity.window.decorView.rootView
rootView.isDrawingCacheEnabled = true
val bitmap = Bitmap.createBitmap(rootView.drawingCache)
rootView.isDrawingCacheEnabled = false

// Upload the screenshot to Crowdin using Crowdin SDK
Crowdin.sendScreenshot(
bitmap = bitmap,
screenshotName = "dashboard",
screenshotCallback = object : ScreenshotCallback {
override fun onSuccess() {
activity.showToast("Screenshot uploaded")
latch.countDown()
}

override fun onFailure(throwable: Throwable) {
activity.showToast("Screenshot upload failed")
latch.countDown()
}
})
}
}
//package com.crowdin.platform.example
andrii-bodnar marked this conversation as resolved.
Show resolved Hide resolved
//
//import android.app.Activity
//import android.graphics.Bitmap
//import androidx.test.core.app.ActivityScenario
//import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
//import com.crowdin.crowdin_controls.showToast
//import com.crowdin.platform.Crowdin
//import com.crowdin.platform.screenshot.ScreenshotCallback
//import org.junit.Test
//import org.junit.runner.RunWith
//import java.util.concurrent.CountDownLatch
//import java.util.concurrent.TimeUnit
//
//@RunWith(AndroidJUnit4ClassRunner::class)
//class ScreenshotAutomationTest {
//
// @Test
// fun automateScreenshotCaptureAndUpload() {
// val activityScenario = ActivityScenario.launch(MainActivity::class.java)
// val latch = CountDownLatch(1)
//
// activityScenario.onActivity { activity ->
// captureAndSendScreenshot(activity, latch)
// }
//
// // Wait for the latch to be decremented, or timeout after 5 seconds
// latch.await(30, TimeUnit.SECONDS)
// activityScenario.close()
// }
//
// private fun captureAndSendScreenshot(activity: Activity, latch: CountDownLatch) {
// // Capture the screenshot as a Bitmap
// val rootView = activity.window.decorView.rootView
// rootView.isDrawingCacheEnabled = true
// val bitmap = Bitmap.createBitmap(rootView.drawingCache)
// rootView.isDrawingCacheEnabled = false
//
// // Upload the screenshot to Crowdin using Crowdin SDK
// Crowdin.sendScreenshot(
// bitmap = bitmap,
// screenshotName = "dashboard",
// screenshotCallback = object : ScreenshotCallback {
// override fun onSuccess() {
// activity.showToast("Screenshot uploaded")
// latch.countDown()
// }
//
// override fun onFailure(throwable: Throwable) {
// activity.showToast("Screenshot upload failed")
// latch.countDown()
// }
// })
// }
//}
Loading