Guest User

Untitled

a guest
May 28th, 2019
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.29 KB | None | 0 0
  1. public class CarManagementWidget extends AppWidgetProvider {
  2.  
  3.     public static final String TAG = "CarManagementWidget";
  4.  
  5.     public static final String ACTION_COMMAND_LOCK = "action_command_lock";
  6.     public static final String ACTION_COMMAND_UNLOCK = "action_command_unlock";
  7.  
  8.     private PendingIntent mServicePendingIntent;
  9.  
  10.  
  11.     static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) {
  12.  
  13.         RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
  14.         Intent intentActionLock = new Intent(context, CarManagementWidget.class);
  15.         intentActionLock.putExtra("command", "close");
  16.         intentActionLock.setAction(ACTION_COMMAND_LOCK);
  17.  
  18.         Intent intentActionUnlock = new Intent(context, CarManagementWidget.class);
  19.         intentActionUnlock.putExtra("command", "open");
  20.         intentActionUnlock.setAction(ACTION_COMMAND_UNLOCK);
  21.  
  22.         PendingIntent pendingIntentLock = PendingIntent.getService(context, 0, intentActionLock, PendingIntent.FLAG_UPDATE_CURRENT);
  23.         remoteViews.setOnClickPendingIntent(R.id.lockImageButton, pendingIntentLock);
  24.  
  25.         PendingIntent pendingIntentUnlock = PendingIntent.getService(context, 0, intentActionUnlock, PendingIntent.FLAG_UPDATE_CURRENT);
  26.         remoteViews.setOnClickPendingIntent(R.id.unlockImageButton, pendingIntentUnlock);
  27.  
  28.         //PendingIntent pendingIntentLock = PendingIntent.getBroadcast(context, 0, intentActionLock, PendingIntent.FLAG_UPDATE_CURRENT);
  29.         //remoteViews.setOnClickPendingIntent(R.id.lockImageButton, pendingIntentLock);
  30.  
  31.         //PendingIntent pendingIntentUnlock = PendingIntent.getBroadcast(context, 0, intentActionUnlock, PendingIntent.FLAG_UPDATE_CURRENT);
  32.         //remoteViews.setOnClickPendingIntent(R.id.unlockImageButton, pendingIntentUnlock);
  33.  
  34.         appWidgetManager.updateAppWidget(appWidgetId, remoteViews);
  35.     }
  36.  
  37.     @Override
  38.     public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
  39.  
  40.         for (int appWidgetId : appWidgetIds) {
  41.             updateAppWidget(context, appWidgetManager, appWidgetId);
  42.         }
  43.     }
  44.  
  45.  
  46.     @Override
  47.     public void onReceive(Context context, Intent intent) {
  48.         super.onReceive(context, intent);
  49.        
  50.     }
  51.  
  52. }
Add Comment
Please, Sign In to add comment