Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions android/app/src/main/kotlin/dev/so1ve/bitree/TimetableWidget.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.AlarmManager
import android.app.PendingIntent
import android.appwidget.AppWidgetManager
import android.appwidget.AppWidgetProvider
import android.appwidget.AppWidgetProviderInfo
import android.content.ComponentName
import android.content.Context
import android.content.Intent
Expand Down Expand Up @@ -76,7 +77,26 @@ open class TimetableWidget : AppWidgetProvider() {
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
widgets.forEach { (id, columns) ->
val views = RemoteViews(context.packageName, R.layout.timetable_widget)
val options = manager.getAppWidgetOptions(id)
val hostCategory = options.getInt(
AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY,
AppWidgetProviderInfo.WIDGET_CATEGORY_HOME_SCREEN,
)
// The lock-screen host controls the slot width independently of targetCellWidth.
val compactKeyguard = columns == 1 &&
(hostCategory and AppWidgetProviderInfo.WIDGET_CATEGORY_KEYGUARD) != 0
val hostWidthPx = widgetWidthPx(context, manager, id)
val widthPx = if (compactKeyguard) {
hostWidthPx * 0.6f
} else {
hostWidthPx
}
val layout = if (compactKeyguard) {
R.layout.timetable_widget_compact_keyguard
} else {
R.layout.timetable_widget
}
val views = RemoteViews(context.packageName, layout)
views.setInt(
R.id.widget_content, "setBackgroundColor", WidgetColors.background(context),
)
Expand All @@ -102,7 +122,6 @@ open class TimetableWidget : AppWidgetProvider() {
)
}

val widthPx = widgetWidthPx(context, manager, id)
val heightPx = widgetContentMinHeightPx(context, manager, id)
val items = entryItems(context, content.entries, widthPx, heightPx, columns)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<!-- Weights keep the lock-screen slot split into 20% / 60% / 20%. -->
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
<include
layout="@layout/timetable_widget"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3" />
<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1" />
</LinearLayout>
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="146dp"
android:layout_width="@dimen/widget_compact_width"
android:layout_height="146dp">
<include
layout="@layout/timetable_widget"
Expand Down
1 change: 1 addition & 0 deletions android/app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<dimen name="widget_compact_width">146dp</dimen>
<dimen name="widget_background_radius">14dp</dimen>
<dimen name="widget_course_radius">6dp</dimen>
<dimen name="widget_padding">10dp</dimen>
Expand Down
3 changes: 2 additions & 1 deletion android/app/src/main/res/xml/timetable_widget_info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
android:targetCellWidth="2"
android:targetCellHeight="2"
android:initialLayout="@layout/timetable_widget"
android:initialKeyguardLayout="@layout/timetable_widget_compact_keyguard"
android:previewLayout="@layout/timetable_widget_preview"
android:description="@string/widget_description"
android:updatePeriodMillis="0"
android:resizeMode="vertical"
android:widgetCategory="home_screen" />
android:widgetCategory="home_screen|keyguard" />
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@
android:description="@string/widget_description"
android:updatePeriodMillis="0"
android:resizeMode="vertical"
android:widgetCategory="home_screen" />
android:widgetCategory="home_screen|keyguard" />
Loading