-
-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
22 changed files
with
410 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
130 changes: 130 additions & 0 deletions
130
android/app/src/main/kotlin/com/lastgimbus/the/freebuddy/BatteryWidget.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
package com.lastgimbus.the.freebuddy | ||
|
||
import android.content.Context | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.unit.DpSize | ||
import androidx.compose.ui.unit.dp | ||
import androidx.compose.ui.unit.sp | ||
import androidx.glance.* | ||
import androidx.glance.appwidget.* | ||
import androidx.glance.layout.* | ||
import androidx.glance.text.FontWeight | ||
import androidx.glance.text.Text | ||
import androidx.glance.text.TextDefaults | ||
import androidx.glance.unit.ColorProvider | ||
import es.antonborri.home_widget.HomeWidgetPlugin | ||
import kotlin.math.max | ||
|
||
|
||
class BatteryWidget : GlanceAppWidget() { | ||
// TODO: Fuck with this a bit more | ||
companion object { | ||
private val SMALL_SQUARE = DpSize(100.dp, 100.dp) | ||
private val HORIZONTAL_RECTANGLE = DpSize(220.dp, 100.dp) | ||
private val VERTICAL_RECTANGLE = DpSize(100.dp, 180.dp) | ||
private val BIG_SQUARE = DpSize(200.dp, 200.dp) | ||
} | ||
|
||
override val sizeMode = SizeMode.Responsive( | ||
setOf( | ||
SMALL_SQUARE, | ||
HORIZONTAL_RECTANGLE, | ||
VERTICAL_RECTANGLE, | ||
BIG_SQUARE, | ||
) | ||
) | ||
|
||
override suspend fun provideGlance(context: Context, id: GlanceId) { | ||
|
||
provideContent { | ||
GlanceTheme { | ||
val sp = HomeWidgetPlugin.getData(LocalContext.current) | ||
val left = sp.getInt("left", 0) | ||
val right = sp.getInt("right", 0) | ||
val case = sp.getInt("case", 0) | ||
val size = LocalSize.current | ||
val barColor = ColorProvider(R.color.battery_widget_bar_color) | ||
val barBackground = ColorProvider(R.color.battery_widget_bar_background) | ||
val textStyle = TextDefaults.defaultTextStyle.copy( | ||
color = ColorProvider(R.color.battery_widget_text_color), | ||
fontWeight = FontWeight.Medium, fontSize = 16.sp | ||
) | ||
|
||
// TODO: Implement all cases here | ||
|
||
if (size.height < VERTICAL_RECTANGLE.height) { | ||
Row( | ||
modifier = GlanceModifier.fillMaxSize().appWidgetBackground() | ||
.background(GlanceTheme.colors.background) | ||
.cornerRadius(R.dimen.batteryWidgetBackgroundRadius) | ||
) { | ||
@Composable | ||
fun BatteryBox(progress: Float, text: String) { | ||
Box( | ||
modifier = GlanceModifier | ||
.defaultWeight() | ||
.fillMaxHeight() | ||
.padding(R.dimen.batteryWidgetPadding), | ||
contentAlignment = Alignment.Center | ||
) { | ||
LinearProgressIndicator( | ||
modifier = GlanceModifier | ||
.cornerRadius(R.dimen.batteryWidgetInnerRadius) | ||
.fillMaxSize(), | ||
progress = progress, | ||
color = barColor, | ||
backgroundColor = barBackground | ||
) | ||
Text(text, style = textStyle) | ||
} | ||
|
||
} | ||
if (size.width <= SMALL_SQUARE.width) { | ||
val b = max(left, right) | ||
BatteryBox(b / 100f, "Buds • $b%") | ||
} else { | ||
BatteryBox(left / 100f, "Left • $left%") | ||
BatteryBox(right / 100f, "Right • $right%") | ||
BatteryBox(case / 100f, "Case • $case%") | ||
} | ||
|
||
|
||
} | ||
} else { | ||
Column( | ||
modifier = GlanceModifier | ||
.fillMaxSize() | ||
.appWidgetBackground() | ||
.background(GlanceTheme.colors.background) | ||
.cornerRadius(R.dimen.batteryWidgetBackgroundRadius) | ||
) { | ||
@Composable | ||
fun BatteryBox(progress: Float, text: String) { | ||
Box( | ||
modifier = GlanceModifier | ||
.defaultWeight() | ||
.padding(R.dimen.batteryWidgetPadding), | ||
contentAlignment = Alignment.Center | ||
) { | ||
LinearProgressIndicator( | ||
modifier = GlanceModifier | ||
.cornerRadius(R.dimen.batteryWidgetInnerRadius) | ||
.fillMaxSize(), | ||
progress = progress, | ||
color = barColor, | ||
backgroundColor = barBackground | ||
) | ||
Text(text, style = textStyle) | ||
} | ||
|
||
} | ||
BatteryBox(left / 100f, "Left • $left%") | ||
BatteryBox(right / 100f, "Right • $right%") | ||
BatteryBox(case / 100f, "Case • $case%") | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
android/app/src/main/kotlin/com/lastgimbus/the/freebuddy/BatteryWidgetReceiver.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.lastgimbus.the.freebuddy | ||
|
||
import androidx.glance.appwidget.GlanceAppWidget | ||
import androidx.glance.appwidget.GlanceAppWidgetReceiver | ||
|
||
class BatteryWidgetReceiver : GlanceAppWidgetReceiver() { | ||
override val glanceAppWidget: GlanceAppWidget = BatteryWidget() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="960" | ||
android:viewportHeight="960"> | ||
<path | ||
android:fillColor="@android:color/white" | ||
android:pathData="M452,800L652,410L512,410L512,160L312,550L452,550L452,800ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880Z"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<!-- I made this by adding a single line to https://pictogrammers.com/library/mdi/icon/circle-outline/ <3 --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M12,20A8,8 0,0 1,4 12A8,8 0,0 1,12 4A8,8 0,0 1,20 12A8,8 0,0 1,12 20M12,2A10,10 0,0 0,2 12A10,10 0,0 0,12 22A10,10 0,0 0,22 12A10,10 0,0 0,12 2Z"/> | ||
<path | ||
android:pathData="M20.038,8.135H4.199L3.518,10.228H21.166Z" | ||
android:fillColor="#000000"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- I made this by modifying https://pictogrammers.com/library/mdi/icon/earbuds-outline/ a bit <3 --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="m13,3c2,0 3,2 3,3v5c0,1 -1,3 -3,3 -0.61,0 -1.32,-0.28 -2,-0.73V20c0,0.55 -0.45,1 -1,1H9C8.45,21 8,20.55 8,20V8C8,6 11,3 13,3m-3,7.23 l2.09,1.37c0.51,0.33 0.83,0.4 0.91,0.4 0.7,0 1,-0.92 1,-1V6.03C14,5.92 13.7,5 13,5 12.1,5 10,7.1 10,8v2.23"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<!-- I made this by modifying https://pictogrammers.com/library/mdi/icon/earbuds-outline/ a bit <3 --> | ||
<vector xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:width="24dp" | ||
android:height="24dp" | ||
android:viewportWidth="24" | ||
android:viewportHeight="24"> | ||
<path | ||
android:fillColor="#FF000000" | ||
android:pathData="M11,3C9,3 8,5 8,6v5c0,1 1,3 3,3 0.61,0 1.32,-0.28 2,-0.73V20c0,0.55 0.45,1 1,1h1c0.55,0 1,-0.45 1,-1V8C16,6 13,3 11,3m3,7.23 l-2.09,1.37C11.4,11.93 11.08,12 11,12 10.3,12 10,11.08 10,11V6.03C10,5.92 10.3,5 11,5c0.9,0 3,2.1 3,3v2.23"/> | ||
</vector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="battery_widget_text_color">@android:color/system_accent1_100</color> | ||
<color name="battery_widget_bar_color">@android:color/system_accent1_600</color> | ||
<color name="battery_widget_bar_background">@android:color/system_accent1_800</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="battery_widget_text_color">#C1E8FF</color> | ||
<color name="battery_widget_bar_color">#00668B</color> | ||
<color name="battery_widget_bar_background">#003549</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="battery_widget_text_color">@android:color/system_accent1_900</color> | ||
<color name="battery_widget_bar_color">@android:color/system_accent1_200</color> | ||
<color name="battery_widget_bar_background">@android:color/system_accent1_100</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="batteryWidgetBackgroundRadius">@android:dimen/system_app_widget_background_radius</dimen> | ||
<dimen name="batteryWidgetInnerRadius">@android:dimen/system_app_widget_inner_radius</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<color name="ic_launcher_background">#ffefefef</color> | ||
<!-- I was looking for those fucking values for like 1.5 hour --> | ||
<!-- There they were, hidden in some documentation for vendors system implementations?? Or something?? --> | ||
<!-- https://source.android.com/docs/core/display/dynamic-color --> | ||
<color name="battery_widget_text_color">#001E2C</color> | ||
<color name="battery_widget_bar_color">#76D1FF</color> | ||
<color name="battery_widget_bar_background">#C1E8FF</color> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
<dimen name="batteryWidgetPadding">8dp</dimen> | ||
<dimen name="batteryWidgetBackgroundRadius">16dp</dimen> | ||
<dimen name="batteryWidgetInnerRadius">8dp</dimen> | ||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:minWidth="40dp" | ||
android:minHeight="40dp" | ||
android:updatePeriodMillis="86400000" | ||
android:initialLayout="@layout/glance_default_loading_layout" | ||
android:resizeMode="horizontal|vertical" | ||
android:widgetCategory="home_screen" /> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.