-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Expand file tree
/
Copy pathAddNoteWidget.kt
More file actions
56 lines (52 loc) · 2.31 KB
/
AddNoteWidget.kt
File metadata and controls
56 lines (52 loc) · 2.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 3 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.ichi2.widget
import android.appwidget.AppWidgetManager
import android.content.Context
import android.widget.RemoteViews
import androidx.core.app.PendingIntentCompat
import com.ichi2.anki.R
import com.ichi2.widget.bridge.WidgetAnalytics
import com.ichi2.widget.bridge.WidgetDependencies
class AddNoteWidget : AnalyticsWidgetProvider() {
override fun performUpdate(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: AppWidgetIds,
usageAnalytics: WidgetAnalytics,
) {
updateWidgets(context, appWidgetManager, appWidgetIds)
}
companion object {
/**
* Updates the widgets displayed in the provided context using the given AppWidgetManager
* and widget IDs, setting up an intent to open the NoteEditor with the caller as the deck picker.
*
* @param context The context in which the widgets are updated.
* @param appWidgetManager The AppWidgetManager instance used to update widgets.
* @param appWidgetIds The array of widget IDs to be updated.
*/
fun updateWidgets(
context: Context,
appWidgetManager: AppWidgetManager,
appWidgetIds: AppWidgetIds,
) {
val remoteViews = RemoteViews(context.packageName, R.layout.widget_add_note)
val intent = WidgetDependencies.intentFactory.intentToOpenNoteEditor(context)
val pendingIntent = PendingIntentCompat.getActivity(context, 0, intent, 0, false)
remoteViews.setOnClickPendingIntent(R.id.widget_add_note_button, pendingIntent)
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews)
}
}
}