diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/OnSettingsChangedListener.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/OnSettingsChangedListener.kt
index 938c309..022dd8b 100644
--- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/OnSettingsChangedListener.kt
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/OnSettingsChangedListener.kt
@@ -1,6 +1,8 @@
package io.github.francoiscampbell.xposeddatausage.model.settings
import io.github.francoiscampbell.xposeddatausage.model.usage.DataUsageFormatter
+import io.github.francoiscampbell.xposeddatausage.widget.Alignment
+import io.github.francoiscampbell.xposeddatausage.widget.Position
/**
* Created by francois on 16-03-17.
@@ -11,5 +13,8 @@ interface OnSettingsChangedListener {
fun onUnitChanged(newUnit: DataUsageFormatter.UnitFormat)
fun onDecimalPlacesChanged(newDecimalPlaces: Int)
fun onTwoLinesChanged(newTwoLines: Boolean)
+ fun onPositionChanged(newPosition: Position)
+ fun onAlignmentChanged(newAlignment: Alignment)
+ fun onTextSizeChanged(newTextSize: Float)
fun onDebugLoggingChanged(shouldDebugLog: Boolean)
}
\ No newline at end of file
diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/SettingsImpl.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/SettingsImpl.kt
index d9923e7..94a6402 100644
--- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/SettingsImpl.kt
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/model/settings/SettingsImpl.kt
@@ -9,6 +9,8 @@ import io.github.francoiscampbell.xposeddatausage.log.XposedLog
import io.github.francoiscampbell.xposeddatausage.model.usage.DataUsageFormatter
import io.github.francoiscampbell.xposeddatausage.util.putAny
import io.github.francoiscampbell.xposeddatausage.util.registerReceiver
+import io.github.francoiscampbell.xposeddatausage.widget.Alignment
+import io.github.francoiscampbell.xposeddatausage.widget.Position
import javax.inject.Inject
import javax.inject.Named
@@ -59,6 +61,9 @@ class SettingsImpl
res.getString(R.string.pref_decimal_places_key) -> onDecimalPlacesChanged((newValue as String).toInt())
res.getString(R.string.pref_two_lines_key) -> onTwoLinesChanged(newValue as Boolean)
res.getString(R.string.pref_debug_logging_key) -> onDebugLoggingChanged(newValue as Boolean)
+ res.getString(R.string.pref_position_key) -> onPositionChanged(Position.valueOf(newValue as String))
+ res.getString(R.string.pref_alignment_key) -> onAlignmentChanged(Alignment.valueOf(newValue as String))
+ res.getString(R.string.pref_text_size_key) -> onTextSizeChanged((newValue as String).toFloat())
}
}
diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Alignment.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Alignment.kt
new file mode 100644
index 0000000..7a07926
--- /dev/null
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Alignment.kt
@@ -0,0 +1,10 @@
+package io.github.francoiscampbell.xposeddatausage.widget
+
+/**
+ * Created by francois on 16-04-10.
+ */
+enum class Alignment {
+ LEFT,
+ CENTER,
+ RIGHT
+}
\ No newline at end of file
diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsagePresenterImpl.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsagePresenterImpl.kt
index a5839f3..b9f4e3a 100644
--- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsagePresenterImpl.kt
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsagePresenterImpl.kt
@@ -81,6 +81,18 @@ class DataUsagePresenterImpl @Inject constructor(
view.twoLines = newTwoLines
}
+ override fun onPositionChanged(newPosition: Position) {
+ view.position = newPosition
+ }
+
+ override fun onAlignmentChanged(newAlignment: Alignment) {
+ view.alignment = newAlignment
+ }
+
+ override fun onTextSizeChanged(newTextSize: Float) {
+ view.textSize = newTextSize
+ }
+
override fun onDebugLoggingChanged(shouldDebugLog: Boolean) {
XposedLog.debugLogging = shouldDebugLog
}
diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageView.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageView.kt
index 23da002..dde9ef5 100644
--- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageView.kt
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/DataUsageView.kt
@@ -11,5 +11,9 @@ interface DataUsageView {
var twoLines: Boolean
var visible: Boolean
var colorOverride: Int?
+ var position: Position
+ var alignment: Alignment
+ var textSize: Float
+
fun update()
}
\ No newline at end of file
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 80ce583..108293a 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
@@ -3,6 +3,7 @@ package io.github.francoiscampbell.xposeddatausage.widget
import android.content.Context
import android.view.Gravity
import android.view.View
+import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import io.github.francoiscampbell.xposeddatausage.log.XposedLog
@@ -31,7 +32,7 @@ class DataUsageViewImpl @Inject constructor(
set(value) {
val lines = if (value) 2 else 1
androidView.setLines(lines)
- androidView.textSize = pxToSp(parent.clock.textSize) / lines
+ textSize = textSize //reset text size
bytesText = bytesText //reset text
}
@@ -43,26 +44,54 @@ class DataUsageViewImpl @Inject constructor(
override var colorOverride: Int? = null
+ override var position = Position.RIGHT
+ set(value) {
+ detachViewFromParent()
+ when (value) {
+ Position.FAR_LEFT -> parent.notificationArea.addView(androidView, 0)
+ Position.RIGHT -> parent.systemIconArea.addView(androidView, 0)
+ Position.FAR_RIGHT -> parent.systemIconArea.addView(androidView)
+ }
+ field = value
+ }
+
+ override var alignment: Alignment = Alignment.CENTER
+ set(value) {
+ androidView.gravity = when (value) {
+ Alignment.LEFT -> Gravity.LEFT or Gravity.CENTER_VERTICAL
+ Alignment.CENTER -> Gravity.CENTER_HORIZONTAL or Gravity.CENTER_VERTICAL
+ Alignment.RIGHT -> Gravity.RIGHT or Gravity.CENTER_VERTICAL
+ }
+ field = value
+ }
+
+ override var textSize: Float = pxToSp(parent.clock.textSize)
+ set(value) {
+ val size = when (value) {
+ 0f -> pxToSp(parent.clock.textSize)
+ else -> Math.max(value, 0f)
+ }
+ androidView.textSize = if (twoLines) size / 2 else size
+ field = size
+ }
+
init {
XposedLog.i("Init Xposed-DataUsageView")
- attachViewToParent()
setupViewParams()
trackClockStyleChanges()
trackColorOverrideChanges()
presenter.attachView(this)
}
- private fun attachViewToParent() {
- parent.systemIconArea.addView(androidView, 0)
- }
+ private fun detachViewFromParent() = (androidView.parent as ViewGroup?)?.removeView(androidView)
private fun setupViewParams() {
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)
- gravity = Gravity.RIGHT or Gravity.CENTER_VERTICAL
+ gravity = Gravity.CENTER_HORIZONTAL or Gravity.CENTER_VERTICAL
}
}
@@ -82,11 +111,7 @@ class DataUsageViewImpl @Inject constructor(
}
}
- override fun update() {
- presenter.updateBytes()
- }
+ override fun update() = presenter.updateBytes()
- private fun pxToSp(px: Float): Float {
- return px / androidView.resources.displayMetrics.scaledDensity
- }
+ private fun pxToSp(px: Float): Float = px / androidView.resources.displayMetrics.scaledDensity
}
\ 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
index 972a571..3cb4afd 100644
--- a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/HookedStatusBar.kt
@@ -1,5 +1,6 @@
package io.github.francoiscampbell.xposeddatausage.widget
+import android.os.Build
import android.view.ViewGroup
import android.widget.TextView
import de.robv.android.xposed.callbacks.XC_LayoutInflated
@@ -14,8 +15,14 @@ class HookedStatusBar @Inject constructor(val liparam: XC_LayoutInflated.LayoutI
get() = liparam.findViewById("clock") as TextView
override val notificationArea: ViewGroup
- get() = liparam.findViewById("notification_icon_area_inner") as ViewGroup
+ get() = when (Build.VERSION.SDK_INT) {
+ in Build.VERSION_CODES.JELLY_BEAN..Build.VERSION_CODES.KITKAT -> liparam.findViewById("notification_icon_area")
+ else -> liparam.findViewById("notification_icon_area_inner")
+ } as ViewGroup
override val systemIconArea: ViewGroup
- get() = liparam.findViewById("system_icon_area") as ViewGroup
+ get() = when (Build.VERSION.SDK_INT) {
+ Build.VERSION_CODES.JELLY_BEAN -> liparam.findViewById("system_icon_area") //TODO find solution https://github.com/android/platform_frameworks_base/blob/jb-release/packages/SystemUI/res/layout/status_bar.xml
+ else -> liparam.findViewById("system_icon_area")
+ } as ViewGroup
}
\ No newline at end of file
diff --git a/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Position.kt b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Position.kt
new file mode 100644
index 0000000..09311e7
--- /dev/null
+++ b/app/src/main/kotlin/io/github/francoiscampbell/xposeddatausage/widget/Position.kt
@@ -0,0 +1,10 @@
+package io.github.francoiscampbell.xposeddatausage.widget
+
+/**
+ * Created by francois on 16-04-10.
+ */
+enum class Position {
+ FAR_LEFT,
+ RIGHT,
+ FAR_RIGHT
+}
\ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 5e994c6..634e9e7 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,53 +1,53 @@
- Smart SI
- Smart Metric
- B
- KB
- MB
- GB
- KiB
- MiB
- GiB
- % of limit
- % of warning
+ Smart SI
+ Smart Metric
+ B
+ KB
+ MB
+ GB
+ KiB
+ MiB
+ GiB
+ % of limit
+ % of warning
- - @string/entry_smart_si
- - @string/entry_smart_metric
- - @string/entry_b
- - @string/entry_kb
- - @string/entry_mb
- - @string/entry_gb
- - @string/entry_kib
- - @string/entry_mib
- - @string/entry_gib
- - @string/entry_pct_warning
- - @string/entry_pct_limit
+ - @string/entry_unit_smart_si
+ - @string/entry_unit_smart_metric
+ - @string/entry_unit_b
+ - @string/entry_unit_kb
+ - @string/entry_unit_mb
+ - @string/entry_unit_gb
+ - @string/entry_unit_kib
+ - @string/entry_unit_mib
+ - @string/entry_unit_gib
+ - @string/entry_unit_pct_warning
+ - @string/entry_unit_pct_limit
- SMART_SI
- SMART_METRIC
- BYTE
- KILO
- MEGA
- GIGA
- KIBI
- MEBI
- GIBI
- PCT_WARNING
- PCT_LIMIT
+ SMART_SI
+ SMART_METRIC
+ BYTE
+ KILO
+ MEGA
+ GIGA
+ KIBI
+ MEBI
+ GIBI
+ PCT_WARNING
+ PCT_LIMIT
- - @string/val_smart_si
- - @string/val_smart_metric
- - @string/val_b
- - @string/val_kb
- - @string/val_mb
- - @string/val_gb
- - @string/val_kib
- - @string/val_mib
- - @string/val_gib
- - @string/val_pct_warning
- - @string/val_pct_limit
+ - @string/val_unit_smart_si
+ - @string/val_unit_smart_metric
+ - @string/val_unit_b
+ - @string/val_unit_kb
+ - @string/val_unit_mb
+ - @string/val_unit_gb
+ - @string/val_unit_kib
+ - @string/val_unit_mib
+ - @string/val_unit_gib
+ - @string/val_unit_pct_warning
+ - @string/val_unit_pct_limit
@@ -57,4 +57,40 @@
- 3
+ Left
+ Center
+ Right
+
+ - @string/entry_align_left
+ - @string/entry_align_center
+ - @string/entry_align_right
+
+
+ LEFT
+ CENTER
+ RIGHT
+
+ - @string/val_align_left
+ - @string/val_align_center
+ - @string/val_align_right
+
+
+ Left of notification icons
+ Left of system icons
+ Right of clock
+
+ - @string/entry_position_far_left
+ - @string/entry_position_right
+ - @string/entry_position_far_right
+
+
+ FAR_LEFT
+ RIGHT
+ FAR_RIGHT
+
+ - @string/val_position_far_left
+ - @string/val_position_right
+ - @string/val_position_far_right
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/prefs.xml b/app/src/main/res/values/prefs.xml
index 225fa0e..421aec8 100644
--- a/app/src/main/res/values/prefs.xml
+++ b/app/src/main/res/values/prefs.xml
@@ -28,6 +28,18 @@
Show on two lines
Show the usage meter on two lines at a smaller font size
+ alignment
+ Text alignment
+ Change the horizontal text alignment when in two-line mode
+
+ position
+ Position
+ Change the horizontal position in the status bar
+
+ text_size
+ Text size
+ Change the text size. In two-line mode, this value will be halved
+
Developer
debug_logging
diff --git a/app/src/main/res/xml/prefs.xml b/app/src/main/res/xml/prefs.xml
index 2d3cd06..3fcdbef 100644
--- a/app/src/main/res/xml/prefs.xml
+++ b/app/src/main/res/xml/prefs.xml
@@ -22,7 +22,7 @@
android:title="@string/pref_relative_to_pace_title" />
+
+
+
+
+
+