From 85b4c28c109fc98d20375de968a007833f165605 Mon Sep 17 00:00:00 2001 From: Francois Campbell Date: Sun, 10 Apr 2016 14:36:59 -0400 Subject: [PATCH] Added parent interface to encapsulate actions on the DataUsageView's parent --- app/build.gradle | 16 +++++++++++--- .../xposeddatausage/Module.kt | 10 +-------- .../xposeddatausage/di/AppModule.kt | 8 +++++-- .../widget/DataUsageViewImpl.kt | 15 ++++++++----- .../widget/DataUsageViewParent.kt | 13 ++++++++++++ .../xposeddatausage/widget/HookedStatusBar.kt | 21 +++++++++++++++++++ .../xposeddatausage/di/MockAppModule.kt | 1 + 7 files changed, 65 insertions(+), 19 deletions(-) create mode 100644 app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewParent.kt create mode 100644 app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt diff --git a/app/build.gradle b/app/build.gradle index 52b991b..12c650f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -30,12 +30,22 @@ kapt { } dependencies { - provided files('libs/XposedBridgeApi-20150213.jar') - testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.2.1' + //Kotlin compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + //Xposed + provided files('libs/XposedBridgeApi-20150213.jar') + + //support lib + compile 'com.android.support:appcompat-v7:23.3.0' + + //Dagger compile 'com.google.dagger:dagger:2.0.2' kapt 'com.google.dagger:dagger-compiler:2.0.2' provided 'org.glassfish:javax.annotation:10.0-b28' + + //test + testCompile 'junit:junit:4.12' + kaptTest 'com.google.dagger:dagger-compiler:2.0.2' + testCompile 'org.mockito:mockito-all:1.10.19' } diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/Module.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/Module.kt index 32de50a..c24d03c 100644 --- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/Module.kt +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/Module.kt @@ -3,18 +3,14 @@ package io.github.francoiscampbell.xposeddatausage import android.content.Intent import android.content.IntentFilter import android.content.pm.PackageManager -import android.view.ViewGroup -import android.widget.TextView import de.robv.android.xposed.* import de.robv.android.xposed.callbacks.XC_InitPackageResources import de.robv.android.xposed.callbacks.XC_LoadPackage import io.github.francoiscampbell.xposeddatausage.di.AppModule import io.github.francoiscampbell.xposeddatausage.di.DaggerAppComponent import io.github.francoiscampbell.xposeddatausage.log.XposedLog -import io.github.francoiscampbell.xposeddatausage.util.findViewById import io.github.francoiscampbell.xposeddatausage.util.hookLayout import io.github.francoiscampbell.xposeddatausage.util.registerReceiver -import io.github.francoiscampbell.xposeddatausage.widget.ClockWrapper /** * Created by francois on 16-03-11. @@ -73,15 +69,11 @@ class Module : IXposedHookZygoteInit, IXposedHookLoadPackage, IXposedHookInitPac resparam.res.hookLayout(PACKAGE_SYSTEM_UI, "layout", "status_bar") { liparam -> val hookedContext = liparam.view.context - val clock = liparam.findViewById("clock") as TextView val dataUsageView = DaggerAppComponent.builder() - .appModule(AppModule(hookedContext, modulePath, ClockWrapper(clock))) + .appModule(AppModule(hookedContext, modulePath, liparam)) .build() .dataUsageView() - val systemIcons = liparam.findViewById("system_icon_area") as ViewGroup - systemIcons.addView(dataUsageView.androidView, 0) - hookedContext.registerReceiver(IntentFilter(Intent.ACTION_TIME_TICK)) { context, intent -> dataUsageView.update() } diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/di/AppModule.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/di/AppModule.kt index e3137b9..f711573 100644 --- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/di/AppModule.kt +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/di/AppModule.kt @@ -10,6 +10,7 @@ import android.telephony.TelephonyManager import dagger.Module import dagger.Provides import de.robv.android.xposed.XposedHelpers +import de.robv.android.xposed.callbacks.XC_LayoutInflated import io.github.francoiscampbell.xposeddatausage.R import io.github.francoiscampbell.xposeddatausage.model.net.NetworkManager import io.github.francoiscampbell.xposeddatausage.model.net.NetworkManagerImpl @@ -27,7 +28,7 @@ import javax.inject.Named @Module open class AppModule(private val hookedContext: Context, private val xposedModulePath: String, - private val clock: ClockWrapper) { + private val liparam: XC_LayoutInflated.LayoutInflatedParam) { @Provides @Named("ui") fun provideUiContext() = hookedContext @@ -35,11 +36,14 @@ open class AppModule(private val hookedContext: Context, @Provides fun provideDataUsageView(impl: DataUsageViewImpl): DataUsageView = impl + @Provides + fun provideDataUsageViewParent(hookedStatusBar: HookedStatusBar): DataUsageViewParent = hookedStatusBar + @Provides fun provideDataUsagePresenter(impl: DataUsagePresenterImpl): DataUsagePresenter = impl @Provides - fun provideClock(): ClockWrapper = clock + fun provideLayoutInflatedParam(): XC_LayoutInflated.LayoutInflatedParam = liparam @Provides fun provideDataUsageFormatter(): DataUsageFormatter = DataUsageFormatter() diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewImpl.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewImpl.kt index 8c47a01..80ce583 100644 --- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewImpl.kt +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewImpl.kt @@ -14,7 +14,7 @@ import javax.inject.Named */ class DataUsageViewImpl @Inject constructor( @Named("ui") context: Context, - val clockWrapper: ClockWrapper, + val parent: DataUsageViewParent, val presenter: DataUsagePresenter ) : DataUsageView { @@ -31,7 +31,7 @@ class DataUsageViewImpl @Inject constructor( set(value) { val lines = if (value) 2 else 1 androidView.setLines(lines) - androidView.textSize = pxToSp(clockWrapper.clock.textSize) / lines + androidView.textSize = pxToSp(parent.clock.textSize) / lines bytesText = bytesText //reset text } @@ -46,14 +46,19 @@ class DataUsageViewImpl @Inject constructor( init { XposedLog.i("Init Xposed-DataUsageView") + attachViewToParent() setupViewParams() trackClockStyleChanges() trackColorOverrideChanges() presenter.attachView(this) } + private fun attachViewToParent() { + parent.systemIconArea.addView(androidView, 0) + } + private fun setupViewParams() { - val clock = clockWrapper.clock + val clock = parent.clock androidView.apply { setPadding(clock.paddingLeft / 2, clock.paddingTop, clock.paddingLeft / 2, clock.paddingBottom) //clock has no right padding, so use left for this view's right layoutParams = LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.MATCH_PARENT) @@ -62,7 +67,7 @@ class DataUsageViewImpl @Inject constructor( } private fun trackClockStyleChanges() { - val clock = clockWrapper.clock + val clock = parent.clock clock.viewTreeObserver.addOnPreDrawListener { androidView.alpha = clock.alpha androidView.typeface = clock.typeface @@ -72,7 +77,7 @@ class DataUsageViewImpl @Inject constructor( private fun trackColorOverrideChanges() { androidView.viewTreeObserver.addOnPreDrawListener { - androidView.setTextColor(colorOverride ?: clockWrapper.clock.currentTextColor) + androidView.setTextColor(colorOverride ?: parent.clock.currentTextColor) return@addOnPreDrawListener true } } diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewParent.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewParent.kt new file mode 100644 index 0000000..069aaf4 --- /dev/null +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageViewParent.kt @@ -0,0 +1,13 @@ +package io.github.francoiscampbell.xposeddatausage.widget + +import android.view.ViewGroup +import android.widget.TextView + +/** + * Created by francois on 16-04-10. + */ +interface DataUsageViewParent { + val clock: TextView + val notificationArea: ViewGroup + val systemIconArea: ViewGroup +} \ No newline at end of file diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt new file mode 100644 index 0000000..972a571 --- /dev/null +++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt @@ -0,0 +1,21 @@ +package io.github.francoiscampbell.xposeddatausage.widget + +import android.view.ViewGroup +import android.widget.TextView +import de.robv.android.xposed.callbacks.XC_LayoutInflated +import io.github.francoiscampbell.xposeddatausage.util.findViewById +import javax.inject.Inject + +/** + * Created by francois on 16-04-10. + */ +class HookedStatusBar @Inject constructor(val liparam: XC_LayoutInflated.LayoutInflatedParam) : DataUsageViewParent { + override val clock: TextView + get() = liparam.findViewById("clock") as TextView + + override val notificationArea: ViewGroup + get() = liparam.findViewById("notification_icon_area_inner") as ViewGroup + + override val systemIconArea: ViewGroup + get() = liparam.findViewById("system_icon_area") as ViewGroup +} \ No newline at end of file diff --git a/app/src/test/kotlin/io/github/francoiscampbell/xposeddatausage/di/MockAppModule.kt b/app/src/test/kotlin/io/github/francoiscampbell/xposeddatausage/di/MockAppModule.kt index 68fb39e..4e59dfb 100644 --- a/app/src/test/kotlin/io/github/francoiscampbell/xposeddatausage/di/MockAppModule.kt +++ b/app/src/test/kotlin/io/github/francoiscampbell/xposeddatausage/di/MockAppModule.kt @@ -7,6 +7,7 @@ import io.github.francoiscampbell.xposeddatausage.model.settings.Settings import io.github.francoiscampbell.xposeddatausage.model.usage.DataUsageFetcher import io.github.francoiscampbell.xposeddatausage.model.usage.DataUsageFormatter import io.github.francoiscampbell.xposeddatausage.widget.DataUsageView +import org.mockito.Mockito @Module class MockAppModule {