Example usage for android.appwidget AppWidgetManager getInstance

List of usage examples for android.appwidget AppWidgetManager getInstance

Introduction

In this page you can find the example usage for android.appwidget AppWidgetManager getInstance.

Prototype

public static AppWidgetManager getInstance(Context context) 

Source Link

Document

Get the AppWidgetManager instance to use for the supplied android.content.Context Context object.

Usage

From source file:com.kubotaku.android.code4kyoto5374.fragments.HomeSelectFragment.java

private void updateAppWidget() {
    Context context = getContext();
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    ComponentName componentName = new ComponentName(context, GarbageCollectDayWidget.class);
    appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetManager.getAppWidgetIds(componentName),
            R.id.list_collect_days);/*from  w  w  w.j  a  va2 s. c  o  m*/
}

From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java

private void updateWidget(final RemoteViews remoteView, final int appWidgetId) {

    final AppWidgetManager manager = AppWidgetManager.getInstance(this.getApplicationContext());
    manager.updateAppWidget(appWidgetId, remoteView);
}

From source file:leoisasmendi.android.com.suricatepodcast.services.MediaPlayerService.java

private void updateWidgets(PlaybackStatus playbackStatus) {

    final RemoteViews view = new RemoteViews(getPackageName(), R.layout.podcast_widget_player);

    if (playbackStatus == PlaybackStatus.PLAYING) {
        view.setImageViewResource(R.id.widget_play, R.drawable.media_player_pause_24x24);
    } else if (playbackStatus == PlaybackStatus.PAUSED) {
        view.setImageViewResource(R.id.widget_play, R.drawable.media_player_play_24x24);
    }/*from w ww.  j a  v  a 2  s . co m*/

    view.setTextViewText(R.id.widget_title, activeAudio.getTitle());
    view.setTextViewText(R.id.widget_length, activeAudio.getDuration());

    Picasso.with(getBaseContext()).setLoggingEnabled(true);

    Target target = new Target() {
        @Override
        public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
            view.setImageViewBitmap(R.id.widget_thumbail, bitmap);
        }

        @Override
        public void onBitmapFailed(Drawable errorDrawable) {
            view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture);
        }

        @Override
        public void onPrepareLoad(Drawable placeHolderDrawable) {
            view.setImageViewResource(R.id.widget_thumbail, R.drawable.picture);
        }
    };

    Picasso.with(getBaseContext()).load(activeAudio.getPoster()).into(target);

    // Push update for this widget to the home screen
    ComponentName thisWidget = new ComponentName(this, PodcastWidgetProvider.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(this);
    manager.updateAppWidget(thisWidget, view);
}

From source file:cn.studyjams.s2.sj0132.bowenyan.mygirlfriend.nononsenseapps.notepad.ui.widget.ListWidgetConfig.java

void setupActionBar() {
    final WidgetPrefs widgetPrefs = new WidgetPrefs(this, appWidgetId);

    LayoutInflater inflater = (LayoutInflater) getActionBar().getThemedContext()
            .getSystemService(LAYOUT_INFLATER_SERVICE);
    final View customActionBarView = inflater.inflate(R.layout.actionbar_custom_view_done, null);
    customActionBarView.findViewById(R.id.actionbar_done).setOnClickListener(new View.OnClickListener() {
        @Override/*from w w w  . ja  v  a  2 s.  co m*/
        public void onClick(View v) {
            // "Done"
            // // Set success
            widgetPrefs.setPresent();
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
            setResult(RESULT_OK, resultValue);
            // Build/Update widget
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
            // Log.d(TAG, "finishing WidgetId " + appWidgetId);
            appWidgetManager.updateAppWidget(appWidgetId, ListWidgetProvider
                    .buildRemoteViews(getApplicationContext(), appWidgetManager, appWidgetId, widgetPrefs));
            // Update list items
            appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.notesList);
            // Destroy activity
            finish();
        }
    });
    // Show the custom action bar view and hide the normal Home icon and
    // title.
    final ActionBar actionBar = getActionBar();
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM,
            ActionBar.DISPLAY_SHOW_CUSTOM | ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE);
    actionBar.setCustomView(customActionBarView);
}

From source file:org.gaeproxy.GAEProxyService.java

public void handleCommand(Intent intent) {

    if (intent == null) {
        stopSelf();// ww w.  ja va 2 s . c o  m
        return;
    }

    proxyType = settings.getString("proxyType", "GAE");
    sitekey = settings.getString("sitekey", "");
    try {
        port = Integer.valueOf(settings.getString("port", "1984"));
    } catch (NumberFormatException ex) {
        port = 1984;
    }

    isGlobalProxy = settings.getBoolean("isGlobalProxy", false);
    isGFWList = settings.getBoolean("isGFWList", false);
    isBypassApps = settings.getBoolean("isBypassApps", false);

    if (!parseProxyURL(settings.getString("proxy", "proxyofmax.appspot.com"))) {
        stopSelf();
        return;
    }

    if (!"GAE".equals(proxyType) && !"PaaS".equals(proxyType)) {
        proxyType = "GAE";
    }

    if ("fetch.py".equals(appPath))
        appPath = "2";

    Log.e(TAG, "Proxy: " + appId + " " + appPath);
    Log.e(TAG, "Local Port: " + port);

    new Thread(new Runnable() {
        @Override
        public void run() {

            handler.sendEmptyMessage(MSG_CONNECT_START);

            Log.d(TAG, "IPTABLES: " + Utils.getIptables());

            // Test for Redirect Support
            hasRedirectSupport = Utils.getHasRedirectSupport();

            if (handleConnection()) {
                // Connection and forward successful
                notifyAlert(getString(R.string.forward_success), getString(R.string.service_running));

                handler.sendEmptyMessageDelayed(MSG_CONNECT_SUCCESS, 500);

                // for widget, maybe exception here
                try {
                    RemoteViews views = new RemoteViews(getPackageName(), R.layout.gaeproxy_appwidget);
                    views.setImageViewResource(R.id.serviceToggle, R.drawable.on);
                    AppWidgetManager awm = AppWidgetManager.getInstance(GAEProxyService.this);
                    awm.updateAppWidget(
                            awm.getAppWidgetIds(
                                    new ComponentName(GAEProxyService.this, GAEProxyWidgetProvider.class)),
                            views);
                } catch (Exception ignore) {
                    // Nothing
                }
            } else {
                // Connection or forward unsuccessful
                notifyAlert(getString(R.string.forward_fail), getString(R.string.service_failed));

                stopSelf();
                handler.sendEmptyMessageDelayed(MSG_CONNECT_FAIL, 500);
            }

            handler.sendEmptyMessageDelayed(MSG_CONNECT_FINISH, 500);
        }
    }).start();
    markServiceStarted();
}

From source file:com.roymam.android.nilsplus.ui.NiLSActivity.java

private boolean isWidgetPlaced() {
    AppWidgetManager widgetManager = AppWidgetManager.getInstance(this);
    ComponentName widgetComponent = new ComponentName(this, NotificationsWidgetProvider.class);
    int[] widgetIds = widgetManager.getAppWidgetIds(widgetComponent);
    return (widgetIds.length > 0);
}

From source file:org.zoumbox.mh_dla_notifier.Receiver.java

protected void checkForWidgetsUpdate(Context context, Troll troll) {

    try {// w  w  w .  ja  v a  2  s. c o m
        AppWidgetManager widgetManager = AppWidgetManager.getInstance(context);

        ComponentName componentName = new ComponentName(context, HomeScreenWidget.class);
        int[] appWidgetIds = widgetManager.getAppWidgetIds(componentName);

        if (appWidgetIds != null && appWidgetIds.length > 0) {

            // FIXME AThimel 14/02/14 Remove ASAP
            StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
            StrictMode.setThreadPolicy(policy);

            String dlaText = Trolls.getWidgetDlaTextFunction(context).apply(troll);
            Bitmap blason = MhDlaNotifierUtils.loadBlasonForWidget(troll.getBlason(), context.getCacheDir());

            for (int appWidgetId : appWidgetIds) {

                RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.home_screen_widget);
                views.setTextViewText(R.id.widgetDla, dlaText);

                if (blason == null) {
                    views.setImageViewResource(R.id.widgetImage, R.drawable.trarnoll_square_transparent_128);
                } else {
                    views.setImageViewBitmap(R.id.widgetImage, blason);
                }

                // Tell the AppWidgetManager to perform an update on the current app widget
                widgetManager.updateAppWidget(appWidgetId, views);
            }
        }

    } catch (Exception eee) {
        Log.e(TAG, "Unable to update widget(s)", eee);
    }

}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

private void updateFeedAndFinish() {
    if (widgetFirstTimeSetup) {
        finishWidgetSetup();//w  w w. j a  va  2  s  .c o m
        return;
    }
    if (mAppWidgetId != 0) {
        // refresh widget and close activity (NOTE: put in function)
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
        RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
        views.setTextViewText(R.id.subreddittxt, global.getSubredditManager().getCurrentFeedName(mAppWidgetId));
        views.setViewVisibility(R.id.srloader, View.VISIBLE);
        views.setViewVisibility(R.id.erroricon, View.INVISIBLE);
        // bypass cache if service not loaded
        global.setBypassCache(true);
        appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views);
        appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview);
    } else {
        Intent intent = new Intent();
        intent.putExtra("themeupdate", needsThemeUpdate);
        setResult(2, intent); // update feed prefs + reload feed
    }
    finish();
}

From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java

public void onBackPressed() {
    if (widgetFirstTimeSetup) {
        finishWidgetSetup();//from w  w  w.j  a v  a  2 s .  c  om
        return;
    }
    // check if sort has changed
    if (needsFeedUpdate || needsFeedViewUpdate || needsThemeUpdate) {
        if (mAppWidgetId != 0) {
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
            RemoteViews views = new RemoteViews(getPackageName(), R.layout.widget);
            views.setViewVisibility(R.id.srloader, View.VISIBLE);
            views.setViewVisibility(R.id.erroricon, View.INVISIBLE);
            // bypass the cached entrys only if the sorting preference has changed
            if (needsFeedUpdate) {
                global.setBypassCache(true);
            } else {
                global.setRefreshView();
            }
            if (needsThemeUpdate) {
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager,
                        new int[] { mAppWidgetId }, false);
            } else {
                appWidgetManager.partiallyUpdateAppWidget(mAppWidgetId, views);
            }
            appWidgetManager.notifyAppWidgetViewDataChanged(mAppWidgetId, R.id.listview);
        } else {
            Intent intent = new Intent();
            intent.putExtra("themeupdate", needsThemeUpdate);
            if (needsFeedUpdate) {
                setResult(2, intent); // reload feed and prefs
            } else {
                setResult(1, intent); // tells main activity to update feed prefs
            }
            if (needsThemeUpdate) {
                global.setRefreshView();
                AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(SubredditSelectActivity.this);
                int[] widgetIds = appWidgetManager
                        .getAppWidgetIds(new ComponentName(SubredditSelectActivity.this, WidgetProvider.class));
                WidgetProvider.updateAppWidgets(SubredditSelectActivity.this, appWidgetManager, widgetIds,
                        false);
                appWidgetManager.notifyAppWidgetViewDataChanged(widgetIds, R.id.listview);
            }
        }
    } else {
        setResult(0);
    }
    finish();
}

From source file:com.android.launcher3.widget.DigitalAppWidgetProvider.java

private void refreshCityOrWeather(Context context, String what, int which) {
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    if (appWidgetManager != null) {
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(getComponentName(context));
        for (int appWidgetId : appWidgetIds) {
            RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.digital_appwidget);
            if (1 == which) {
                widget.setTextViewText(R.id.city, what);
            } else if (2 == which) {
                if (what.equals("")) {
                    //widget.setTextViewText(R.id.temperature, context.getString(R.string.weather_network_error));
                } else if (what.contains(",")) {
                    String weather = what.split(",")[0];
                    String temperature = what.split(",")[1];
                    String image = what.split(",")[2];
                    widget.setTextViewText(R.id.temperature, temperature);
                    widget.setImageViewResource(R.id.weather, getWeatherImageId(image));
                }/*from   w w w. j a v  a  2s .c o  m*/
            }
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, widget);
        }
    }
}