Created
February 10, 2017 08:36
-
-
Save pamartineza/c281946cb83b83412735b192c4bf2b2e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.appwidget.AppWidgetProvider; | |
import android.content.Context; | |
import android.content.Intent; | |
import android.widget.RemoteViews; | |
import com.greenlionsoft.cercaniaslib.R; | |
import com.greenlionsoft.sharedlib.logs.Logx; | |
import java.util.Arrays; | |
public class CercaniasRealTimeWidget extends AppWidgetProvider { | |
@Override | |
public void onEnabled(Context context) { | |
//Called when first isntance is created | |
Logx.d("onEnabled"); | |
} | |
@Override | |
public void onDeleted(Context context, int[] appWidgetIds) { | |
Logx.d("onDeleted " + Arrays.toString(appWidgetIds)); | |
//Called every time an instance is deleted | |
} | |
@Override | |
public void onDisabled(Context context) { | |
Logx.d("onDisabled"); | |
//Called when last existing instance is deleted | |
} | |
@Override | |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { | |
Logx.d("onUpdate " + Arrays.toString(appWidgetIds)); | |
for (int i=0; i<appWidgetIds.length; i++) { | |
int appWidgetId = appWidgetIds[i]; | |
Intent intent = new Intent(context, CercaniasRealTimeWidgetIntentService.class); | |
PendingIntent pi = PendingIntent.getBroadcast(context, appWidgetId, intent, PendingIntent.FLAG_UPDATE_CURRENT); | |
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_cercanias_real_time); | |
views.setOnClickPendingIntent(R.id.bt_widget, pi); | |
appWidgetManager.updateAppWidget(appWidgetId, views); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment