Skip to content

Commit

Permalink
[UPDATE] Show overdraw 기능 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
kimdohun0104 committed May 6, 2021
1 parent 64984a5 commit fc517fe
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kr.co.finda.androidtemplate.feature.showOverdraw

import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.project.Project
import kr.co.finda.androidtemplate.ext.showMessageDialog
import kr.co.finda.androidtemplate.util.DeviceHelperImpl

class ShowOverdrawAction : AnAction(), ShowOverdrawContract.View {

private val presenter: ShowOverdrawContract.Presenter by lazy {
ShowOverdrawPresenter(this, DeviceHelperImpl())
}

override fun actionPerformed(e: AnActionEvent) {
presenter.onShowOverdrawActionPerformed(e.project!!)
}

override fun showDialog(project: Project, title: String, description: String) {
project.showMessageDialog(title, description)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package kr.co.finda.androidtemplate.feature.showOverdraw

import com.intellij.openapi.project.Project

interface ShowOverdrawContract {

interface View {
fun showDialog(project: Project, title: String, description: String)
}

interface Presenter {
fun onShowOverdrawActionPerformed(project: Project)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package kr.co.finda.androidtemplate.feature.showOverdraw

import com.intellij.openapi.project.Project
import kr.co.finda.androidtemplate.util.DeviceHelper

class ShowOverdrawPresenter(
private val view: ShowOverdrawContract.View,
private val deviceHelper: DeviceHelper
) : ShowOverdrawContract.Presenter {
override fun onShowOverdrawActionPerformed(project: Project) {
val devices = deviceHelper.getDebugDevices(project)

if (devices.isNullOrEmpty()) {
view.showDialog(project, "연결된 디바이스가 없습니다", "디바이스 연결 상태를 확인해주세요")
return
}

deviceHelper.getShowOverdrawEnabled(devices[0]) { prevEnabled ->
deviceHelper.setShowOverdrawEnabled(devices, !prevEnabled)
}
}
}
32 changes: 32 additions & 0 deletions src/main/kotlin/kr/co/finda/androidtemplate/util/DeviceHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ interface DeviceHelper {

fun setDebugLayoutBoundsEnabled(devices: List<IDevice>, isEnabled: Boolean)

fun getShowOverdrawEnabled(device: IDevice, on: (isEnabled: Boolean) -> Unit)

fun setShowOverdrawEnabled(devices: List<IDevice>, isEnabled: Boolean)

fun getDebugDevices(project: Project): List<IDevice>?

fun clearFindaAppCache(device: IDevice)
Expand Down Expand Up @@ -46,6 +50,34 @@ class DeviceHelperImpl : DeviceHelper {
}
}

override fun getShowOverdrawEnabled(device: IDevice, on: (isEnabled: Boolean) -> Unit) {
device.executeShellCommand(
"getprop debug.hwui.overdraw",
object: MultiLineReceiver() {
var cancelled = false

override fun isCancelled(): Boolean {
return cancelled
}

override fun processNewLines(lines: Array<out String>?) {
val firstLine = lines?.firstOrNull()
on(firstLine?.contains("show") == true)
cancelled = true
}
}
)
}

override fun setShowOverdrawEnabled(devices: List<IDevice>, isEnabled: Boolean) {
devices.forEach { device ->
device.executeShellCommand(
"setprop debug.hwui.overdraw ${if (isEnabled) "show" else "false"} ; service call activity 1599295570",
NullOutputReceiver()
)
}
}

override fun getDebugDevices(project: Project): List<IDevice>? {
return AndroidSdkUtils.getDebugBridge(project)?.devices?.toList()
}
Expand Down
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 @@ -42,6 +42,12 @@
icon="Icons.FindaLogo">
<add-to-group group-id="NewGroup" anchor="first"/>
</action>
<action id="kr.co.finda.androidtemplate.feature.showOverdraw.ShowOverdrawAction"
class="kr.co.finda.androidtemplate.feature.showOverdraw.ShowOverdrawAction" text="Show/Hide Overdraw"
description="Show or hide overdraw"
icon="Icons.FindaLogo">
<add-to-group group-id="ToolsMenu" anchor="last"/>
</action>
</actions>

<extensions defaultExtensionNs="com.intellij">
Expand Down

0 comments on commit fc517fe

Please sign in to comment.