Recently Written · git

ink-update

Ink Update: tells you when Rebind, Ink Recents or Ink Dim has a new version. F-Droid, then Google Play, then GitHub.

git clone https://github.com/equwal/ink-update

Log | Files | Refs


app/src/debug/java/dev/equwal/inkupdate/debug/ShotApp.kt (2076 bytes)

1 // SPDX-License-Identifier: GPL-3.0-or-later
2 // Copyright (c) 2026 equwal
3 package dev.equwal.inkupdate.debug
4 
5 import android.app.Activity
6 import android.app.Application
7 import android.graphics.Bitmap
8 import android.graphics.Canvas
9 import android.graphics.Color
10 import android.os.Bundle
11 import android.os.Handler
12 import android.os.Looper
13 import android.util.Log
14 import java.io.File
15 
16 /**
17  * Screenshots for the README, for a device that cannot take them. Debug builds only.
18  *
19  * A second after any screen comes to the front, its view tree is drawn into a
20  * bitmap and written to the app's external files directory:
21  *
22  *   adb pull /sdcard/Android/data/dev.equwal.inkupdate.debug/files/shots
23  */
24 class ShotApp : Application() {
25 
26     override fun onCreate() {
27         super.onCreate()
28         val main = Handler(Looper.getMainLooper())
29         registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
30             override fun onActivityResumed(a: Activity) {
31                 main.postDelayed({ if (!a.isFinishing) shoot(a) }, 2500L)
32             }
33             override fun onActivityCreated(a: Activity, b: Bundle?) = Unit
34             override fun onActivityStarted(a: Activity) = Unit
35             override fun onActivityPaused(a: Activity) = Unit
36             override fun onActivityStopped(a: Activity) = Unit
37             override fun onActivitySaveInstanceState(a: Activity, b: Bundle) = Unit
38             override fun onActivityDestroyed(a: Activity) = Unit
39         })
40     }
41 
42     private fun shoot(a: Activity) {
43         val v = a.window.decorView
44         if (v.width == 0 || v.height == 0) return
45         val bmp = Bitmap.createBitmap(v.width, v.height, Bitmap.Config.ARGB_8888)
46         val canvas = Canvas(bmp)
47         canvas.drawColor(Color.WHITE)
48         v.draw(canvas)
49         val dir = File(getExternalFilesDir(null), "shots").apply { mkdirs() }
50         val out = File(dir, a.javaClass.simpleName + ".png")
51         out.outputStream().use { bmp.compress(Bitmap.CompressFormat.PNG, 100, it) }
52         Log.i("InkUpdate", "shot " + out.absolutePath)
53     }
54 }