加上行事曆Widget
This commit is contained in:
parent
27995305a4
commit
c190d9ac15
@ -16,6 +16,7 @@
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/Theme.IOSClockWidget"
|
||||
tools:targetApi="31">
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:exported="true">
|
||||
@ -43,10 +44,22 @@
|
||||
android:resource="@xml/i_o_s_clock_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receiver.IOSCalendarWidget"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
|
||||
</intent-filter>
|
||||
|
||||
<meta-data
|
||||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/i_o_s_calendar_widget_info" />
|
||||
</receiver>
|
||||
|
||||
<receiver
|
||||
android:name=".receiver.AutoStartReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="true" >
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
|
||||
|
||||
@ -0,0 +1,45 @@
|
||||
package com.ray650128.iosclockwidget.receiver
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.appwidget.AppWidgetProvider
|
||||
import android.content.Context
|
||||
import android.widget.RemoteViews
|
||||
import com.ray650128.iosclockwidget.R
|
||||
|
||||
/**
|
||||
* Implementation of App Widget functionality.
|
||||
*/
|
||||
class IOSCalendarWidget : AppWidgetProvider() {
|
||||
override fun onUpdate(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetIds: IntArray
|
||||
) {
|
||||
// There may be multiple widgets active, so update all of them
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
updateCalendarWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onEnabled(context: Context) {
|
||||
// Enter relevant functionality for when the first widget is created
|
||||
}
|
||||
|
||||
override fun onDisabled(context: Context) {
|
||||
// Enter relevant functionality for when the last widget is disabled
|
||||
}
|
||||
}
|
||||
|
||||
internal fun updateCalendarWidget(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int
|
||||
) {
|
||||
val widgetText = context.getString(R.string.appwidget_text)
|
||||
// Construct the RemoteViews object
|
||||
val views = RemoteViews(context.packageName, R.layout.i_o_s_calendar_widget)
|
||||
views.setTextViewText(R.id.appwidget_text, widgetText)
|
||||
|
||||
// Instruct the widget manager to update the widget
|
||||
appWidgetManager.updateAppWidget(appWidgetId, views)
|
||||
}
|
||||
@ -27,7 +27,7 @@ class IOSClockWidget : AppWidgetProvider() {
|
||||
when (intent?.action) {
|
||||
ClockUpdateService.SECOND_CHANGED -> {
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
updateClockWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -40,7 +40,7 @@ class IOSClockWidget : AppWidgetProvider() {
|
||||
) {
|
||||
// There may be multiple widgets active, so update all of them
|
||||
for (appWidgetId in appWidgetIds) {
|
||||
updateAppWidget(context, appWidgetManager, appWidgetId)
|
||||
updateClockWidget(context, appWidgetManager, appWidgetId)
|
||||
}
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ class IOSClockWidget : AppWidgetProvider() {
|
||||
}
|
||||
}
|
||||
|
||||
internal fun updateAppWidget(
|
||||
internal fun updateClockWidget(
|
||||
context: Context,
|
||||
appWidgetManager: AppWidgetManager,
|
||||
appWidgetId: Int
|
||||
|
||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 3.4 KiB |
BIN
app/src/main/res/drawable-nodpi/ios_clock_widget_preview.png
Normal file
BIN
app/src/main/res/drawable-nodpi/ios_clock_widget_preview.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 41 KiB |
19
app/src/main/res/layout/i_o_s_calendar_widget.xml
Normal file
19
app/src/main/res/layout/i_o_s_calendar_widget.xml
Normal file
@ -0,0 +1,19 @@
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
style="@style/Widget.IOSClockWidget.AppWidget.Container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:theme="@style/Theme.IOSClockWidget.AppWidgetContainer">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/appwidget_text"
|
||||
style="@style/Widget.IOSClockWidget.AppWidget.InnerView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_margin="8dp"
|
||||
android:contentDescription="@string/appwidget_text"
|
||||
android:text="@string/appwidget_text"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold|italic" />
|
||||
</RelativeLayout>
|
||||
14
app/src/main/res/xml/i_o_s_calendar_widget_info.xml
Normal file
14
app/src/main/res/xml/i_o_s_calendar_widget_info.xml
Normal file
@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:description="@string/app_widget_description"
|
||||
android:initialKeyguardLayout="@layout/i_o_s_calendar_widget"
|
||||
android:initialLayout="@layout/i_o_s_calendar_widget"
|
||||
android:minWidth="110dp"
|
||||
android:minHeight="40dp"
|
||||
android:previewImage="@drawable/ios_calendar_widget_preview"
|
||||
android:previewLayout="@layout/i_o_s_calendar_widget"
|
||||
android:resizeMode="horizontal"
|
||||
android:targetCellWidth="2"
|
||||
android:targetCellHeight="1"
|
||||
android:updatePeriodMillis="86400000"
|
||||
android:widgetCategory="home_screen" />
|
||||
@ -5,7 +5,7 @@
|
||||
android:initialLayout="@layout/i_o_s_clock_widget"
|
||||
android:minWidth="40dp"
|
||||
android:minHeight="40dp"
|
||||
android:previewImage="@drawable/example_appwidget_preview"
|
||||
android:previewImage="@drawable/ios_clock_widget_preview"
|
||||
android:previewLayout="@layout/i_o_s_clock_widget"
|
||||
android:resizeMode="none"
|
||||
android:targetCellWidth="1"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user