20
20
public class SingleNoteWidget extends AppWidgetProvider {
21
21
22
22
public static final String WIDGET_KEY = "single_note_widget" ;
23
- public static final String INIT = "INIT" ;
24
23
private static final String TAG = SingleNoteWidget .class .getSimpleName ();
25
24
26
25
@ Override
@@ -35,34 +34,26 @@ public void onDeleted(Context context, int[] appWidgetIds) {
35
34
SharedPreferences .Editor sharedprefs = PreferenceManager .getDefaultSharedPreferences (context ).edit ();
36
35
37
36
for (int appWidgetId : appWidgetIds ) {
38
- Log .d (TAG , "Removing " + WIDGET_KEY + appWidgetId + " from sharedprefs" );
39
- Log .d (TAG , "Removing " + WIDGET_KEY + appWidgetId + INIT + " from sharedprefs" );
40
37
sharedprefs .remove (WIDGET_KEY + appWidgetId );
41
- sharedprefs .remove (WIDGET_KEY + appWidgetId + INIT );
42
38
}
43
39
sharedprefs .apply ();
44
40
}
45
41
46
42
static void updateAppWidget (Context context , AppWidgetManager appWidgetManager , int appWidgetId ) {
47
- NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper .getInstance (context );
48
43
SharedPreferences sharedprefs = PreferenceManager .getDefaultSharedPreferences (context );
49
44
RemoteViews views = new RemoteViews (context .getPackageName (), R .layout .widget_single_note );
50
45
long noteID = sharedprefs .getLong (SingleNoteWidget .WIDGET_KEY + appWidgetId , -1 );
51
- boolean isInitialised = sharedprefs .getBoolean (SingleNoteWidget .WIDGET_KEY + appWidgetId + INIT , false );
52
46
53
47
if (noteID >= 0 ) {
54
- if (isInitialised ) {
55
- DBNote note = db .getNote (noteID );
56
- Intent intent = new Intent (context , EditNoteActivity .class );
57
- intent .putExtra (EditNoteActivity .PARAM_NOTE , note );
58
- intent .putExtra (EditNoteActivity .PARAM_WIDGET_SRC , true );
59
- PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 , intent , PendingIntent .FLAG_UPDATE_CURRENT );
60
- views .setOnClickPendingIntent (R .id .widget_single_note , pendingIntent );
61
- views .setTextViewText (R .id .single_note_content , note .getContent ());
62
- appWidgetManager .updateAppWidget (appWidgetId , views );
63
- } else {
64
- Log .e (TAG , "Widget not initialised" );
65
- }
48
+ NoteSQLiteOpenHelper db = NoteSQLiteOpenHelper .getInstance (context );
49
+ DBNote note = db .getNote (noteID );
50
+ Intent intent = new Intent (context , EditNoteActivity .class );
51
+ intent .putExtra (EditNoteActivity .PARAM_NOTE , note );
52
+ intent .putExtra (EditNoteActivity .PARAM_WIDGET_SRC , true );
53
+ PendingIntent pendingIntent = PendingIntent .getActivity (context , 0 , intent , PendingIntent .FLAG_UPDATE_CURRENT );
54
+ views .setOnClickPendingIntent (R .id .widget_single_note , pendingIntent );
55
+ views .setTextViewText (R .id .single_note_content , note .getContent ());
56
+ appWidgetManager .updateAppWidget (appWidgetId , views );
66
57
} else {
67
58
Log .e (TAG , "Note not found" );
68
59
views .setTextViewText (R .id .single_note_content , "Note not found" );
0 commit comments