diff --git a/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawAction.kt b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawAction.kt new file mode 100644 index 0000000..178fa70 --- /dev/null +++ b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawAction.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawContract.kt b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawContract.kt new file mode 100644 index 0000000..c46886d --- /dev/null +++ b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawContract.kt @@ -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) + } +} \ No newline at end of file diff --git a/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawPresenter.kt b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawPresenter.kt new file mode 100644 index 0000000..f545d68 --- /dev/null +++ b/src/main/kotlin/kr/co/finda/androidtemplate/feature/showOverdraw/ShowOverdrawPresenter.kt @@ -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) + } + } +} \ No newline at end of file diff --git a/src/main/kotlin/kr/co/finda/androidtemplate/util/DeviceHelper.kt b/src/main/kotlin/kr/co/finda/androidtemplate/util/DeviceHelper.kt index 1b05d8f..1337d84 100644 --- a/src/main/kotlin/kr/co/finda/androidtemplate/util/DeviceHelper.kt +++ b/src/main/kotlin/kr/co/finda/androidtemplate/util/DeviceHelper.kt @@ -12,6 +12,10 @@ interface DeviceHelper { fun setDebugLayoutBoundsEnabled(devices: List, isEnabled: Boolean) + fun getShowOverdrawEnabled(device: IDevice, on: (isEnabled: Boolean) -> Unit) + + fun setShowOverdrawEnabled(devices: List, isEnabled: Boolean) + fun getDebugDevices(project: Project): List? fun clearFindaAppCache(device: IDevice) @@ -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?) { + val firstLine = lines?.firstOrNull() + on(firstLine?.contains("show") == true) + cancelled = true + } + } + ) + } + + override fun setShowOverdrawEnabled(devices: List, 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? { return AndroidSdkUtils.getDebugBridge(project)?.devices?.toList() } diff --git a/src/main/resources/META-INF/plugin.xml b/src/main/resources/META-INF/plugin.xml index fc19771..1c3f4c4 100644 --- a/src/main/resources/META-INF/plugin.xml +++ b/src/main/resources/META-INF/plugin.xml @@ -42,6 +42,12 @@ icon="Icons.FindaLogo"> + + +