-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
universal pip initial implementation
- Loading branch information
1 parent
00f869c
commit 5df671e
Showing
12 changed files
with
256 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
128 changes: 128 additions & 0 deletions
128
app/src/main/java/com/legendsayantan/adbtools/PipStarterActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,128 @@ | ||
package com.legendsayantan.adbtools | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.KeyEvent | ||
import androidx.activity.enableEdgeToEdge | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.legendsayantan.adbtools.lib.ShizukuRunner | ||
import java.util.Timer | ||
import kotlin.concurrent.timerTask | ||
|
||
class PipStarterActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
enableEdgeToEdge() | ||
intent.getStringExtra("package") | ||
?.let { | ||
startActivity(packageManager.getLaunchIntentForPackage(it)) | ||
playVideo() | ||
} | ||
finish() | ||
} | ||
|
||
companion object { | ||
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() | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
fun Context.enablePip(){ | ||
Timer().schedule(timerTask { | ||
ShizukuRunner.runAdbCommand( | ||
"dumpsys window displays | grep -E 'mCurrentFocus'", | ||
object : ShizukuRunner.CommandResultListener { | ||
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", | ||
object : ShizukuRunner.CommandResultListener { | ||
override fun onCommandResult( | ||
output: String, | ||
done: Boolean | ||
) { | ||
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) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
override fun onCommandError(error: String) { | ||
disablePip() | ||
println(error) | ||
} | ||
}) | ||
}, 500) | ||
} | ||
} | ||
}) | ||
} | ||
} | ||
}) | ||
}, 1500) | ||
} | ||
|
||
fun disablePip() { | ||
ShizukuRunner.runAdbCommand("settings put global overlay_display_devices null", | ||
object : ShizukuRunner.CommandResultListener { | ||
override fun onCommandResult(output: String, done: Boolean) { | ||
playVideo() | ||
} | ||
}) | ||
} | ||
|
||
fun playVideo() { | ||
Timer().schedule(timerTask { | ||
ShizukuRunner.runAdbCommand("input keyevent ${KeyEvent.KEYCODE_MEDIA_PLAY}", | ||
object : ShizukuRunner.CommandResultListener {}) | ||
}, 1500) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
app/src/main/java/com/legendsayantan/adbtools/receivers/PipReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.legendsayantan.adbtools.receivers | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import com.legendsayantan.adbtools.PipStarterActivity.Companion.handlePip | ||
|
||
class PipReceiver : BroadcastReceiver() { | ||
|
||
override fun onReceive(context: Context, intent: Intent) { | ||
context.handlePip() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:app="http://schemas.android.com/apk/res-auto" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/main" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".PipStarterActivity"> | ||
|
||
</androidx.constraintlayout.widget.ConstraintLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters