|
| 1 | +package com.sickmartian.quickalarmwidget; |
| 2 | + |
| 3 | +import android.appwidget.AppWidgetManager; |
| 4 | +import android.appwidget.AppWidgetProvider; |
| 5 | +import android.content.Context; |
| 6 | +import android.content.Intent; |
| 7 | +import android.content.SharedPreferences; |
| 8 | +import android.net.Uri; |
| 9 | +import android.os.Bundle; |
| 10 | +import android.preference.PreferenceManager; |
| 11 | +import android.util.Log; |
| 12 | +import android.widget.RemoteViews; |
| 13 | + |
| 14 | +/** |
| 15 | + * Created by ***REMOVED*** on 8/9/16. |
| 16 | + */ |
| 17 | +public class QuickAlarmWidgetProvider extends AppWidgetProvider { |
| 18 | + @Override |
| 19 | + public void onAppWidgetOptionsChanged(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { |
| 20 | + super.onAppWidgetOptionsChanged(context, appWidgetManager, appWidgetId, newOptions); |
| 21 | + Log.d("QAWP", "onAppWidgetOptionsChanged"); |
| 22 | + } |
| 23 | + |
| 24 | + @Override |
| 25 | + public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { |
| 26 | + Log.d("QAWP", "onUpdate"); |
| 27 | + for (int i=0; i<appWidgetIds.length; i++) { |
| 28 | + |
| 29 | + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); |
| 30 | + |
| 31 | + Intent svcIntent = new Intent(context, QuickAlarmWidgetService.class); |
| 32 | + svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); |
| 33 | + svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); |
| 34 | + |
| 35 | + RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.quick_widget_layout); |
| 36 | + |
| 37 | + widget.setRemoteAdapter(appWidgetIds[i], R.id.quick_widget_list, svcIntent); |
| 38 | + appWidgetManager.updateAppWidget(appWidgetIds[i], widget); |
| 39 | + } |
| 40 | + |
| 41 | + super.onUpdate(context, appWidgetManager, appWidgetIds); |
| 42 | + } |
| 43 | +} |
0 commit comments