Skip to content

Commit

Permalink
Implemented multiple positions, alignment, and text sizes
Browse files Browse the repository at this point in the history
  • Loading branch information
francoiscampbell committed Apr 11, 2016
1 parent 85b4c28 commit 3a244e6
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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)
}
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.github.francoiscampbell.xposeddatausage.widget

/**
* Created by francois on 16-04-10.
*/
enum class Alignment {
LEFT,
CENTER,
RIGHT
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

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

Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
}
Original file line number Diff line number Diff line change
@@ -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
}
124 changes: 80 additions & 44 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="entry_smart_si">Smart SI</string>
<string name="entry_smart_metric">Smart Metric</string>
<string name="entry_b">B</string>
<string name="entry_kb">KB</string>
<string name="entry_mb">MB</string>
<string name="entry_gb">GB</string>
<string name="entry_kib">KiB</string>
<string name="entry_mib">MiB</string>
<string name="entry_gib">GiB</string>
<string name="entry_pct_limit">% of limit</string>
<string name="entry_pct_warning">% of warning</string>
<string name="entry_unit_smart_si">Smart SI</string>
<string name="entry_unit_smart_metric">Smart Metric</string>
<string name="entry_unit_b">B</string>
<string name="entry_unit_kb">KB</string>
<string name="entry_unit_mb">MB</string>
<string name="entry_unit_gb">GB</string>
<string name="entry_unit_kib">KiB</string>
<string name="entry_unit_mib">MiB</string>
<string name="entry_unit_gib">GiB</string>
<string name="entry_unit_pct_limit">% of limit</string>
<string name="entry_unit_pct_warning">% of warning</string>
<string-array name="units_entries">
<item>@string/entry_smart_si</item>
<item>@string/entry_smart_metric</item>
<item>@string/entry_b</item>
<item>@string/entry_kb</item>
<item>@string/entry_mb</item>
<item>@string/entry_gb</item>
<item>@string/entry_kib</item>
<item>@string/entry_mib</item>
<item>@string/entry_gib</item>
<item>@string/entry_pct_warning</item>
<item>@string/entry_pct_limit</item>
<item>@string/entry_unit_smart_si</item>
<item>@string/entry_unit_smart_metric</item>
<item>@string/entry_unit_b</item>
<item>@string/entry_unit_kb</item>
<item>@string/entry_unit_mb</item>
<item>@string/entry_unit_gb</item>
<item>@string/entry_unit_kib</item>
<item>@string/entry_unit_mib</item>
<item>@string/entry_unit_gib</item>
<item>@string/entry_unit_pct_warning</item>
<item>@string/entry_unit_pct_limit</item>
</string-array>

<string name="val_smart_si">SMART_SI</string>
<string name="val_smart_metric">SMART_METRIC</string>
<string name="val_b">BYTE</string>
<string name="val_kb">KILO</string>
<string name="val_mb">MEGA</string>
<string name="val_gb">GIGA</string>
<string name="val_kib">KIBI</string>
<string name="val_mib">MEBI</string>
<string name="val_gib">GIBI</string>
<string name="val_pct_limit">PCT_WARNING</string>
<string name="val_pct_warning">PCT_LIMIT</string>
<string name="val_unit_smart_si">SMART_SI</string>
<string name="val_unit_smart_metric">SMART_METRIC</string>
<string name="val_unit_b">BYTE</string>
<string name="val_unit_kb">KILO</string>
<string name="val_unit_mb">MEGA</string>
<string name="val_unit_gb">GIGA</string>
<string name="val_unit_kib">KIBI</string>
<string name="val_unit_mib">MEBI</string>
<string name="val_unit_gib">GIBI</string>
<string name="val_unit_pct_limit">PCT_WARNING</string>
<string name="val_unit_pct_warning">PCT_LIMIT</string>
<string-array name="units_entries_values">
<item>@string/val_smart_si</item>
<item>@string/val_smart_metric</item>
<item>@string/val_b</item>
<item>@string/val_kb</item>
<item>@string/val_mb</item>
<item>@string/val_gb</item>
<item>@string/val_kib</item>
<item>@string/val_mib</item>
<item>@string/val_gib</item>
<item>@string/val_pct_warning</item>
<item>@string/val_pct_limit</item>
<item>@string/val_unit_smart_si</item>
<item>@string/val_unit_smart_metric</item>
<item>@string/val_unit_b</item>
<item>@string/val_unit_kb</item>
<item>@string/val_unit_mb</item>
<item>@string/val_unit_gb</item>
<item>@string/val_unit_kib</item>
<item>@string/val_unit_mib</item>
<item>@string/val_unit_gib</item>
<item>@string/val_unit_pct_warning</item>
<item>@string/val_unit_pct_limit</item>
</string-array>

<string-array name="decimal_places_entries">
Expand All @@ -57,4 +57,40 @@
<item>3</item>
</string-array>

<string name="entry_align_left">Left</string>
<string name="entry_align_center">Center</string>
<string name="entry_align_right">Right</string>
<string-array name="alignment_entries">
<item>@string/entry_align_left</item>
<item>@string/entry_align_center</item>
<item>@string/entry_align_right</item>
</string-array>

<string name="val_align_left">LEFT</string>
<string name="val_align_center">CENTER</string>
<string name="val_align_right">RIGHT</string>
<string-array name="alignment_entries_values">
<item>@string/val_align_left</item>
<item>@string/val_align_center</item>
<item>@string/val_align_right</item>
</string-array>

<string name="entry_position_far_left">Left of notification icons</string>
<string name="entry_position_right">Left of system icons</string>
<string name="entry_position_far_right">Right of clock</string>
<string-array name="position_entries">
<item>@string/entry_position_far_left</item>
<item>@string/entry_position_right</item>
<item>@string/entry_position_far_right</item>
</string-array>

<string name="val_position_far_left">FAR_LEFT</string>
<string name="val_position_right">RIGHT</string>
<string name="val_position_far_right">FAR_RIGHT</string>
<string-array name="position_entries_values">
<item>@string/val_position_far_left</item>
<item>@string/val_position_right</item>
<item>@string/val_position_far_right</item>
</string-array>

</resources>
12 changes: 12 additions & 0 deletions app/src/main/res/values/prefs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,18 @@
<string name="pref_two_lines_title">Show on two lines</string>
<string name="pref_two_lines_summary">Show the usage meter on two lines at a smaller font size</string>

<string name="pref_alignment_key">alignment</string>
<string name="pref_alignment_title">Text alignment</string>
<string name="pref_alignment_summary">Change the horizontal text alignment when in two-line mode</string>

<string name="pref_position_key">position</string>
<string name="pref_position_title">Position</string>
<string name="pref_position_summary">Change the horizontal position in the status bar</string>

<string name="pref_text_size_key">text_size</string>
<string name="pref_text_size_title">Text size</string>
<string name="pref_text_size_summary">Change the text size. In two-line mode, this value will be halved</string>

<string name="pref_category_dev">Developer</string>

<string name="pref_debug_logging_key">debug_logging</string>
Expand Down
Loading

0 comments on commit 3a244e6

Please sign in to comment.