Android Open Source - myglob Widget Provider

From Project

Back to project page myglob.


The source code is released under:

GNU General Public License

If you think the Android project myglob listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

 * MyGlob Android Application/*from  ww w  .  j ava2 s.c o  m*/
 * Copyright (C) 2012 Petar Petrov
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <>.
package net.vexelon.myglob;

import java.util.Arrays;

import net.vexelon.myglob.configuration.Defs;

import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.view.View;
import android.widget.RemoteViews;

public class WidgetProvider extends AppWidgetProvider {

  public void onReceive(Context context, Intent intent) {
    if (Defs.LOG_ENABLED)
      Log.d(Defs.LOG_TAG, "onReceive() called");
    int widgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
    if (AppWidgetManager.INVALID_APPWIDGET_ID == widgetId) {
      super.onReceive(context, intent);
    } else {
      this.onUpdate(context, AppWidgetManager.getInstance(context), new int[] {widgetId});
  public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
    if (Defs.LOG_ENABLED)
      Log.d(Defs.LOG_TAG, "onUpdate() called - " + Arrays.toString(appWidgetIds));
    // get all widgets ids
//    ComponentName thisWidget = new ComponentName(context, WidgetProvider.class);
//    int[] allWidgetIds = appWidgetManager.getAppWidgetIds(thisWidget);
    // build intent and call service
    Intent serviceIntent = new Intent(context.getApplicationContext(), UpdateWidgetService.class);
    serviceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
    // update widgets via the service
    // show animation
    for (int widgetId : appWidgetIds) {
      RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout);
      remoteViews.setTextViewText(, context.getString(R.string.dlg_progress_message));
      // prevent multiple clicks
      remoteViews.setViewVisibility(, View.INVISIBLE);
//      ImageView imageView = new ImageView(context);
//      imageView.setImageResource(R.drawable.loading);
//      AnimationDrawable loadingAnimation = (AnimationDrawable)imageView.getDrawable();
//      remoteViews.addView(imageView.getId(), imageView);
//      remoteViews.setImageViewResource(viewId, srcId)
      appWidgetManager.updateAppWidget(widgetId, remoteViews);


Java Source Code List