diff --git a/app/release/app-release.apk b/app/release/app-release.apk index b0997a5..3334ef2 100644 Binary files a/app/release/app-release.apk and b/app/release/app-release.apk differ diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9a3a21b..8c13e6c 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -32,15 +32,14 @@ + android:exported="true" /> - + android:exported="true" + android:label="" + android:theme="@style/DialogActivityTheme" /> outputStream.use { output -> diff --git a/app/src/main/java/com/legendsayantan/adbtools/PipStarterActivity.kt b/app/src/main/java/com/legendsayantan/adbtools/PipStarterActivity.kt index 4559fc3..4a5925b 100644 --- a/app/src/main/java/com/legendsayantan/adbtools/PipStarterActivity.kt +++ b/app/src/main/java/com/legendsayantan/adbtools/PipStarterActivity.kt @@ -5,6 +5,8 @@ import android.os.Bundle import android.view.KeyEvent import androidx.activity.enableEdgeToEdge import androidx.appcompat.app.AppCompatActivity +import androidx.constraintlayout.widget.ConstraintLayout +import com.google.android.material.card.MaterialCardView import com.legendsayantan.adbtools.lib.ShizukuRunner import java.util.Timer import kotlin.concurrent.timerTask @@ -13,30 +15,135 @@ class PipStarterActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) enableEdgeToEdge() - intent.getStringExtra("package") - ?.let { - startActivity(packageManager.getLaunchIntentForPackage(it)) + intent.getStringExtra("package").let { pkg -> + if (pkg == null) { + showing = true + setContentView(R.layout.activity_pip_starter) + val controls = listOf( + findViewById(R.id.skipPrev), + findViewById(R.id.rewind), + findViewById(R.id.playPause), + findViewById(R.id.forward), + findViewById(R.id.skipNext) + ) + val keys = listOf( + arrayOf(KeyEvent.KEYCODE_MEDIA_PREVIOUS), + arrayOf(KeyEvent.KEYCODE_MEDIA_REWIND,KeyEvent.KEYCODE_DPAD_LEFT), + arrayOf(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE), + arrayOf(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD,KeyEvent.KEYCODE_DPAD_RIGHT), + arrayOf(KeyEvent.KEYCODE_MEDIA_NEXT) + ) + controls.forEachIndexed { index, materialCardView -> + materialCardView.setOnClickListener { + keys[index].forEach { key -> + getExternalWindowId { window-> ShizukuRunner.runAdbCommand("input -d $window keyevent $key", + object : ShizukuRunner.CommandResultListener {}) } + interacted() + } + } + } + val extraBtns = listOf( + findViewById(R.id.adSkipButton), + findViewById(R.id.fullScreenButton) + ) + extraBtns[0].setOnClickListener { + interacted() + val metrics = getWindowParams() + getExternalWindowId { + ShizukuRunner.runAdbCommand("input -d $it tap ${(metrics.first * 0.95).toInt()} ${(metrics.second*0.86).toInt()}", + object : ShizukuRunner.CommandResultListener {}) + } + } + extraBtns[1].setOnClickListener { + disablePip() + interacted() + } + + //outside touch + findViewById(R.id.main).setOnClickListener { + finish() + } + + setupAutoHide() + } else { + startActivity(packageManager.getLaunchIntentForPackage(pkg)) playVideo() + finish() } - finish() + } + } + + private fun setupAutoHide() { + Timer().schedule(timerTask { + if (lastInteractionAt >= 0 + && lastInteractionAt + hideTimerInterval < System.currentTimeMillis() + ) { + finish() + cancel() + } + }, hideTimerInterval, hideTimerInterval) } companion object { + var showing = false + private const val hideTimerInterval = 3000L + var lastInteractionAt = 0L + var interacted = { + lastInteractionAt = System.currentTimeMillis() + } + fun Context.getWindowParams():Pair{ + val metrics = resources.displayMetrics + return Pair(metrics.widthPixels,((metrics.widthPixels / (metrics.heightPixels.toFloat() / metrics.widthPixels)) + 100).toInt()) + } + fun getExternalWindowId(callback:(Int)->Unit){ + ShizukuRunner.runAdbCommand("dumpsys display | grep 'Display [0-9][0-9]*'", + object : + ShizukuRunner.CommandResultListener { + override fun onCommandResult( + output: String, + done: Boolean + ) { + if (done) { + callback("\\d+".toRegex() + .findAll(output) + .filter { it.value != "0" } + .map { it.value.toInt() } + .maxOrNull() ?: 0) + } + } + + override fun onCommandError(error: String) { + println(error) + disablePip() + } + }) + } + + fun Context.handlePip() { - ShizukuRunner.runAdbCommand("settings get global overlay_display_devices",object : ShizukuRunner.CommandResultListener{ - override fun onCommandResult(output: String, done: Boolean) { - if(done){ - if(output.trim().contains("null",true)){ - enablePip() - }else{ - disablePip() + ShizukuRunner.runAdbCommand("settings get global overlay_display_devices", + object : ShizukuRunner.CommandResultListener { + override fun onCommandResult(output: String, done: Boolean) { + if (done) { + if (output.trim().contains("null", true)) { + enablePip() + } else { + ShizukuRunner.runAdbCommand("am start -n $packageName/${PipStarterActivity::class.java.canonicalName} --display 0", + object : ShizukuRunner.CommandResultListener { + override fun onCommandError( + error: String + ) { + disablePip() + println(error) + } + }) + } } } - } - }) + }) } - fun Context.enablePip(){ + fun Context.enablePip() { Timer().schedule(timerTask { ShizukuRunner.runAdbCommand( "dumpsys window displays | grep -E 'mCurrentFocus'", @@ -44,9 +151,8 @@ class PipStarterActivity : AppCompatActivity() { override fun onCommandResult(output: String, done: Boolean) { if (done) { val pipPackage = output.split(" ")[4].split("/")[0] - val metrics = resources.displayMetrics - val height = (metrics.widthPixels / (metrics.heightPixels.toFloat() / metrics.widthPixels))+100 - ShizukuRunner.runAdbCommand("settings put global overlay_display_devices ${metrics.widthPixels}x${height.toInt()}/240", + val metrics = getWindowParams() + ShizukuRunner.runAdbCommand("settings put global overlay_display_devices ${metrics.first}x${metrics.second}/240", object : ShizukuRunner.CommandResultListener { override fun onCommandResult( output: String, @@ -54,54 +160,38 @@ class PipStarterActivity : AppCompatActivity() { ) { if (done) { Timer().schedule(timerTask { - ShizukuRunner.runAdbCommand("dumpsys display | grep 'Display [0-9][0-9]*'", - object : ShizukuRunner.CommandResultListener { - override fun onCommandResult( - output: String, - done: Boolean - ) { - if (done) { - val newDisplayId = - "\\d+".toRegex() - .findAll(output) - .filter { it.value != "0" } - .map { it.value.toInt() } - .maxOrNull() ?: 0 - println(output) - println(newDisplayId) - val command = - "am start -n $packageName/${PipStarterActivity::class.java.canonicalName} --es package $pipPackage --display $newDisplayId" - ShizukuRunner.runAdbCommand( - command, - object : - ShizukuRunner.CommandResultListener { - override fun onCommandResult( - output: String, - done: Boolean - ) { - if (done) { - println("PIP started") - } - } - - override fun onCommandError( - error: String - ) { - disablePip() - println(error) - } - }) + getExternalWindowId { newDisplayId-> + val command = + "am start -n $packageName/${PipStarterActivity::class.java.canonicalName} --es package $pipPackage --display $newDisplayId" + ShizukuRunner.runAdbCommand( + command, + object : + ShizukuRunner.CommandResultListener { + override fun onCommandResult( + output: String, + done: Boolean + ) { + if (done) { + println("PIP started") + } } - } - override fun onCommandError(error: String) { - disablePip() - println(error) - } - }) + override fun onCommandError( + error: String + ) { + disablePip() + println(error) + } + }) + } }, 500) } } + + override fun onCommandError(error: String) { + disablePip() + println(error) + } }) } } diff --git a/app/src/main/res/drawable/baseline_fast_forward_24.xml b/app/src/main/res/drawable/baseline_fast_forward_24.xml new file mode 100644 index 0000000..a19b235 --- /dev/null +++ b/app/src/main/res/drawable/baseline_fast_forward_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_fast_rewind_24.xml b/app/src/main/res/drawable/baseline_fast_rewind_24.xml new file mode 100644 index 0000000..0313dac --- /dev/null +++ b/app/src/main/res/drawable/baseline_fast_rewind_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_fullscreen_24.xml b/app/src/main/res/drawable/baseline_fullscreen_24.xml new file mode 100644 index 0000000..860d400 --- /dev/null +++ b/app/src/main/res/drawable/baseline_fullscreen_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_skip_next_24.xml b/app/src/main/res/drawable/baseline_skip_next_24.xml new file mode 100644 index 0000000..5a79f5e --- /dev/null +++ b/app/src/main/res/drawable/baseline_skip_next_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/baseline_skip_previous_24.xml b/app/src/main/res/drawable/baseline_skip_previous_24.xml new file mode 100644 index 0000000..7951d71 --- /dev/null +++ b/app/src/main/res/drawable/baseline_skip_previous_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/drawable/rounded_next_plan_24.xml b/app/src/main/res/drawable/rounded_next_plan_24.xml new file mode 100644 index 0000000..d680868 --- /dev/null +++ b/app/src/main/res/drawable/rounded_next_plan_24.xml @@ -0,0 +1,13 @@ + + + + + diff --git a/app/src/main/res/drawable/rounded_play_pause_24.xml b/app/src/main/res/drawable/rounded_play_pause_24.xml new file mode 100644 index 0000000..b65d336 --- /dev/null +++ b/app/src/main/res/drawable/rounded_play_pause_24.xml @@ -0,0 +1,5 @@ + + + + + diff --git a/app/src/main/res/layout/activity_pip_starter.xml b/app/src/main/res/layout/activity_pip_starter.xml index 89b3411..edc4656 100644 --- a/app/src/main/res/layout/activity_pip_starter.xml +++ b/app/src/main/res/layout/activity_pip_starter.xml @@ -1,10 +1,240 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file