Skip to content

Commit

Permalink
Added parent interface to encapsulate actions on the DataUsageView's …
Browse files Browse the repository at this point in the history
…parent
  • Loading branch information
francoiscampbell committed Apr 10, 2016
1 parent 5147bdb commit 85b4c28
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 19 deletions.
16 changes: 13 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -27,19 +28,22 @@ 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

@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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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
}

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 85b4c28

Please sign in to comment.