package com.github.pkunk.progressquest.widget;

import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.widget.RemoteViews;
import com.github.pkunk.progressquest.R;
import com.github.pkunk.progressquest.service.GameplayService;
import com.github.pkunk.progressquest.ui.PhoneGameplayActivity;

/**
 * User: pkunk
 * Date: 2012-02-16
 */
public class WidgetProvider extends AppWidgetProvider {

    @Override
    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
        // Start service
        Intent serviceIntent = new Intent(context, GameplayService.class);
        context.startService(serviceIntent);

        // Set OnClickListener
        RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
        Intent activityIntent = new Intent(context, PhoneGameplayActivity.class);
        activityIntent.setPackage(context.getPackageName());
        activityIntent.setAction(Intent.ACTION_MAIN);
        activityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        PendingIntent actionPendingIntent = PendingIntent.getActivity(context, 0, activityIntent, 0);
        remoteViews.setOnClickPendingIntent(R.id.wg_main, actionPendingIntent);
        appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
    }

    @Override
    public void onDisabled(Context context) {
        Intent intent = new Intent(context, GameplayService.class);
        context.stopService(intent);
        super.onDisabled(context);
    }
}

@@ -565,14 +565,15 @@
 d on
-Update
+Enabled
 (Con
@@ -588,91 +588,45 @@
 text
-, AppWidgetManager appWidgetManager, int%5B%5D appWidgetIds) %7B%0A        // Start service
+) %7B%0A        super.onEnabled(context);
 %0A   
@@ -742,16 +742,135 @@
 ntent);%0A
+    %7D%0A%0A    @Override%0A    public void onUpdate(Context context, AppWidgetManager appWidgetManager, int%5B%5D appWidgetIds) %7B
 %0A       
@@ -1002,25 +1002,17 @@
  Intent 
-activityI
+i
 ntent = 
@@ -1065,33 +1065,25 @@
 s);%0A        
-activityI
+i
 ntent.setPac
@@ -1118,33 +1118,25 @@
 ));%0A        
-activityI
+i
 ntent.setAct
@@ -1168,25 +1168,17 @@
         
-activityI
+i
 ntent.se
@@ -1239,23 +1239,17 @@
 gIntent 
-actionP
+p
 endingIn
@@ -1297,93 +1297,236 @@
  0, 
-activityIntent, 0);%0A        remoteViews.setOnClickPendingIntent(R.id.wg_main, actionP
+intent, 0);%0A        remoteViews.setOnClickPendingIntent(R.id.wg_status1, pendingIntent);%0A        remoteViews.setOnClickPendingIntent(R.id.wg_status2, pendingIntent);%0A        remoteViews.setOnClickPendingIntent(R.id.wg_status3, p
 endi

rework widget