Skip to content

Commit

Permalink
Merge pull request #203 from GuoXiCheng/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
GuoXiCheng authored Aug 21, 2024
2 parents 64b0f1e + 1c3c356 commit aab5cf2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,18 @@ import android.media.ImageReader
import android.media.projection.MediaProjection
import android.media.projection.MediaProjectionManager
import android.os.Build
import android.os.Environment
import android.os.Handler
import android.os.IBinder
import android.os.Looper
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
import com.android.skip.NewMainActivity
import com.android.skip.R
import com.android.skip.SKIPApp
import com.android.skip.SKIP_LAYOUT_INSPECT
import com.android.skip.manager.ToastManager
import com.android.skip.utils.Constants
import com.android.skip.utils.DataStoreUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import java.io.File
import java.io.FileOutputStream
Expand All @@ -43,10 +42,12 @@ class LayoutInspectService: Service() {
private var mProjectionManager:MediaProjectionManager? = null
private var virtualDisplay: VirtualDisplay? = null
private var isProcessingImage = false
private var filename: String? = null
private val keyEventVolumeDownReceiver = object: BroadcastReceiver() {
override fun onReceive(p0: Context?, p1: Intent?) {
if (p1?.action == Constants.SKIP_KEY_EVENT_VOLUME_DOWN) {
isProcessingImage = true
filename = p1.getStringExtra("filename")
}
}
}
Expand Down Expand Up @@ -154,8 +155,7 @@ class LayoutInspectService: Service() {
}

private fun getOutputFile(): File {
val picturesDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
return File(picturesDir, "screenshot_${System.currentTimeMillis()}.png")
return File(SKIPApp.context.filesDir, "$filename.png")
}

private fun saveBitmapToFile(bitmap: Bitmap, file: File): Boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ import com.android.skip.utils.DataStoreUtils
import com.blankj.utilcode.util.LogUtils
import com.blankj.utilcode.util.ScreenUtils
import com.blankj.utilcode.util.ServiceUtils
import com.blankj.utilcode.util.ZipUtils
import com.google.gson.Gson
import com.google.gson.GsonBuilder
import java.io.File

data class MyWindow(val packageName: String, val className: String, val screenHeight: Int, val screenWidth: Int, val nodes: MutableList<MyNodeChild>)
Expand All @@ -44,10 +44,14 @@ class MyAccessibilityService : AccessibilityService() {
private val boundsHandler = BoundsHandler()
private var isLayoutInspect = false
private var layoutInspectClassName: String? = null
private var filename: String? = null
private val foregroundAccessibilityReceiver = object : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
if (intent?.action == Constants.FOREGROUND_ACCESSIBILITY_RECEIVER_ACTION) {
val enabled = intent.getBooleanExtra(Constants.FOREGROUND_ACCESSIBILITY_RECEIVER_ENABLED, false)
val enabled = intent.getBooleanExtra(
Constants.FOREGROUND_ACCESSIBILITY_RECEIVER_ENABLED,
false
)
if (enabled) {
ServiceUtils.startService(MyForegroundService::class.java)
} else {
Expand Down Expand Up @@ -134,7 +138,10 @@ class MyAccessibilityService : AccessibilityService() {
&& event.keyCode == KeyEvent.KEYCODE_VOLUME_DOWN
&& DataStoreUtils.getSyncData(SKIP_LAYOUT_INSPECT, false)
) {
filename = System.currentTimeMillis().toString()

val intent = Intent(Constants.SKIP_KEY_EVENT_VOLUME_DOWN)
intent.putExtra("filename", filename)
intent.setPackage(packageName)
sendBroadcast(intent)

Expand Down Expand Up @@ -162,8 +169,16 @@ class MyAccessibilityService : AccessibilityService() {
val window = MyWindow(root.packageName.toString(), layoutInspectClassName.toString(), ScreenUtils.getScreenHeight(), ScreenUtils.getScreenWidth(),temp)
val gson = Gson()
val jsonStr = gson.toJson(window)
val file = File(SKIPApp.context.filesDir, "temp.json")
val file = File(SKIPApp.context.filesDir, "$filename.json")
file.writeText(jsonStr)

ZipUtils.zipFiles(
listOf(
File(SKIPApp.context.filesDir, "$filename.json"),
File(SKIPApp.context.filesDir, "$filename.png")
),
File(SKIPApp.context.filesDir, "$filename.zip")
)
}

private fun processNode(node: AccessibilityNodeInfo, temp: MutableList<MyNodeChild>, depth: Int, parentId: Int, nodeId: Int) {
Expand All @@ -187,7 +202,6 @@ class MyAccessibilityService : AccessibilityService() {
}



@RequiresApi(Build.VERSION_CODES.TIRAMISU)
override fun onServiceConnected() {
super.onServiceConnected()
Expand Down
2 changes: 2 additions & 0 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ layout: home
hero:
name: SKIP
text: 基于 Android 无障碍服务的自动跳过开屏广告 App
image:
src: /images/logo.png
actions:
- theme: brand
text: Get Started
Expand Down
Binary file added docs/public/images/logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit aab5cf2

Please sign in to comment.