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

Switch layout bounds added as a new command #130

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.developerphil.adbidea.action

import com.developerphil.adbidea.adb.AdbFacade
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project

class SwitchLayoutBounds : AdbAction() {
override fun actionPerformed(e: AnActionEvent, project: Project) = AdbFacade.switchLayoutBounds(project)
}
1 change: 1 addition & 0 deletions src/main/kotlin/com/developerphil/adbidea/adb/AdbFacade.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ object AdbFacade {
fun disableWifi(project: Project) = executeOnDevice(project, ToggleSvcCommand(WIFI, false))
fun enableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, true))
fun disableMobile(project: Project) = executeOnDevice(project, ToggleSvcCommand(MOBILE, false))
fun switchLayoutBounds(project: Project) = executeOnDevice(project, SwitchLayoutBoundsCommand())

private fun executeOnDevice(project: Project, runnable: Command) {
if (AdbUtil.isGradleSyncInProgress(project)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.developerphil.adbidea.adb.command

import com.android.ddmlib.IDevice
import com.developerphil.adbidea.adb.command.receiver.GenericReceiver
import com.developerphil.adbidea.adb.command.receiver.ResponseHolder
import com.developerphil.adbidea.adb.command.receiver.ResponseReceiver
import com.developerphil.adbidea.ui.NotificationHelper.error
import com.developerphil.adbidea.ui.NotificationHelper.info
import com.intellij.openapi.project.Project
import org.jetbrains.android.facet.AndroidFacet
import java.util.concurrent.TimeUnit



class SwitchLayoutBoundsCommand() : Command {


override fun run(project: Project, device: IDevice, facet: AndroidFacet, packageName: String): Boolean {
try {
val receiver = ResponseHolder()
device.executeShellCommand("getprop debug.layout", ResponseReceiver(receiver), 30L, TimeUnit.SECONDS)
val isAlreadyOn = receiver.response.contains("true")
val cmd = if(isAlreadyOn){
"setprop debug.layout false && service call activity 1599295570" //SYSPROPS_TRANSACTION
} else {
"setprop debug.layout true && service call activity 1599295570" //SYSPROPS_TRANSACTION
}
device.executeShellCommand(cmd, ResponseReceiver(receiver), 30L, TimeUnit.SECONDS)

info(String.format("<b>%s</b> on %s", if(isAlreadyOn)"Hide layout bound" else "Show layout bound", device.name))
return true
} catch (e: Exception) {
error("Failure while attempting to switch layout bounds on ${device.name}: " + e.message)
}
return false
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.developerphil.adbidea.adb.command.receiver

import com.android.ddmlib.MultiLineReceiver
import java.util.*
import java.util.regex.Pattern

data class ResponseHolder(var response: String = "")

class ResponseReceiver(val responseHolder: ResponseHolder) : MultiLineReceiver() {

val adbOutputLines: MutableList<String> = ArrayList()

override fun processNewLines(lines: Array<String>) {
adbOutputLines.addAll(listOf(*lines))
for (line in lines) {
if (line.isNotEmpty()) {
responseHolder.response += "$line\n"
}
}
}

override fun isCancelled() = false

}
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,12 @@
description="Disable mobile data on device or emulator">
</action>

<action id="com.developerphil.adbidea.action.SwitchLayoutBounds"
class="com.developerphil.adbidea.action.SwitchLayoutBounds"
text="ADB Switch Layout Bounds"
description="Switches (Developer Tools -> Show Layout Bounds) on device">
</action>

</group>
</actions>

Expand Down