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:ru.yandex.subtitles.ui.appwidget.AbstractAppWidget.java

@Override
public void onReceive(@NonNull final Context context, @NonNull final Intent intent) {
    super.onReceive(context, intent);

    final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    final ComponentName componentName = new ComponentName(context, getClass());
    final int[] widgetIds = appWidgetManager.getAppWidgetIds(componentName);

    final String action = intent.getAction();
    if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)
            || ACTION_APPWIDGET_DATASET_CHANGED.equals(action)) {
        notifyAppWidgetsViewDataChanged(appWidgetManager, widgetIds);

    } else if (getStartConversationAction().equals(action)) {
        startConversation(context, intent);

    }/*w  ww . j  av  a2s  .  c om*/
}

From source file:com.android.mms.widget.MmsWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
        Log.v(TAG, "onReceive intent: " + intent);
    }/*  w w w. jav  a2s .  co  m*/
    String action = intent.getAction();

    // The base class AppWidgetProvider's onReceive handles the normal widget intents. Here
    // we're looking for an intent sent by the messaging app when it knows a message has
    // been sent or received (or a conversation has been read) and is telling the widget it
    // needs to update.
    if (ACTION_NOTIFY_DATASET_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager
                .getAppWidgetIds(new ComponentName(context, MmsWidgetProvider.class));

        // We need to update all Mms appwidgets on the home screen.
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.conversation_list);
    } else {
        super.onReceive(context, intent);
    }
}

From source file:com.battlelancer.seriesguide.appwidget.ListWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    super.onReceive(context, intent);

    // check if we received our update alarm
    if (UPDATE.equals(intent.getAction())) {
        // trigger refresh of list widgets
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager
                .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.list_view);
    }/*from ww  w.  j a  v  a  2  s.  com*/
}

From source file:com.concentriclivers.mms.com.android.mms.widget.MmsWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    //        if (Log.isLoggable(LogTag.WIDGET, Log.VERBOSE)) {
    Log.v(TAG, "onReceive intent: " + intent);
    //        }/*from w  w  w .ja  v  a2 s.  c o  m*/
    String action = intent.getAction();

    // The base class AppWidgetProvider's onReceive handles the normal widget intents. Here
    // we're looking for an intent sent by the messaging app when it knows a message has
    // been sent or received (or a conversation has been read) and is telling the widget it
    // needs to update.
    if (ACTION_NOTIFY_DATASET_CHANGED.equals(action)) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager
                .getAppWidgetIds(new ComponentName(context, MmsWidgetProvider.class));
        if (appWidgetIds.length > 0) {
            appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds[0], R.id.conversation_list);
        }
    } else {
        super.onReceive(context, intent);
    }
}

From source file:com.ultrafunk.network_info.config.ConfigActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    /*//from  ww  w  .  jav a 2  s .  c om
    ToDo: So we can show the ConfigActivity when started from a lock screen widget
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED);
    */

    // Set the result to CANCELED. This will cause the widget host to cancel out of the widget placement if they press the back button.
    setResult(RESULT_CANCELED);

    setContentView(R.layout.activity_config);

    // Find the widget id from the intent.
    Bundle extras = getIntent().getExtras();

    if (extras != null)
        appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);

    if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID)
        finish();

    appAppWidgetManager = AppWidgetManager.getInstance(this);

    widgetConfig = new WidgetConfig(this);
    widgetConfig.read(appWidgetId);

    // ToDo: Needs to change if/when the ConfigActivity is started from a widget or home screen
    widgetConfig.setBothWidgets(true);

    TextView configurationTextView = (TextView) findViewById(R.id.configurationTextView);
    configurationTextView.setText(
            (isLockscreenWidget(appAppWidgetManager, appWidgetId) ? getString(R.string.lockscreen_configuration)
                    : getString(R.string.homescreen_configuration)));

    initShowWidgetView();
    initMobileSettingsScreenView();
    initLockscreenGravityView();
    initTransparencyView();
    initOkAndCancelButtons();
}

From source file:org.opensilk.fuzzyclock.FuzzyWidgetService.java

@Override
public void onCreate() {
    super.onCreate();
    mContext = this;

    //mFormatChangeObserver = new FormatChangeObserver();
    //mContext.getContentResolver().registerContentObserver(
    //        Settings.System.CONTENT_URI, true, mFormatChangeObserver
    //);//w  w w.  ja  v  a 2s  .com

    mWidgetManager = AppWidgetManager.getInstance(mContext);
    mAlarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    mFuzzyClock = (FuzzyClockView) layoutInflater.inflate(R.layout.fuzzy_clock, null);
}

From source file:com.todotxt.todotxttouch.widget.ListWidgetProvider.java

@Override
public void onReceive(Context context, Intent intent) {
    final String action = intent.getAction();

    if (action.equals(REFRESH_ACTION)) {
        Log.d(TAG, "Widget Refresh button pressed");

        Intent i = new Intent(Constants.INTENT_START_SYNC_WITH_REMOTE);
        context.sendBroadcast(i);//from   www . j  a  va 2  s. c o m
        Bundle extras = intent.getExtras();

        if (extras != null) {
            int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
            AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
            RemoteViews rv = buildLayout(context, appWidgetId, true);
            appWidgetManager.partiallyUpdateAppWidget(appWidgetId, rv);
        }
    } else if (action.equals(Constants.INTENT_WIDGET_UPDATE)) {
        Log.d(TAG, "Update widget intent received ");

        int[] appWidgetIds = null;
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        Bundle extras = intent.getExtras();

        if (extras != null) {
            appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
        }

        if (appWidgetIds == null) {
            appWidgetIds = appWidgetManager
                    .getAppWidgetIds(new ComponentName(context, ListWidgetProvider.class.getName()));
        }

        if (appWidgetIds != null && appWidgetIds.length > 0) {
            this.onUpdate(context, appWidgetManager, appWidgetIds);
        }
    }

    super.onReceive(context, intent);
}

From source file:com.gaba.alex.trafficincidents.Utility.java

public static void updateWidget(Context context) {
    Intent intent = new Intent(context, IncidentsWidgetProvider.class);
    intent.setAction("android.appwidget.action.APPWIDGET_UPDATE");
    ComponentName name = new ComponentName(context, IncidentsWidgetProvider.class);
    int[] ids = AppWidgetManager.getInstance(context).getAppWidgetIds(name);
    intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids);
    context.sendBroadcast(intent);//from ww w . jav a2  s . c o  m
}

From source file:com.example.olivi.maphap.widget.DetailWidgetProvider.java

@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent) {
    super.onReceive(context, intent);
    if (MapHapService.ACTION_DATA_UPDATED.equals(intent.getAction())) {
        AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
        int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass()));
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.widget_list);
    }/*ww w  .j  a va 2  s  .c  om*/
}

From source file:com.ultrafunk.network_info.service.NetworkStateService.java

@Override
public void onCreate() {
    super.onCreate();

    //   Log.e(this.getClass().getSimpleName(), "onCreate()");

    localBroadcastManager = LocalBroadcastManager.getInstance(this);
    telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR1)
        mobileDataSettingUri = Uri.withAppendedPath(Settings.System.CONTENT_URI, "mobile_data");
    else//w  w w. j av a 2  s.  c o  m
        mobileDataSettingUri = Uri.withAppendedPath(Settings.Global.CONTENT_URI, "mobile_data");

    initEnabledWidgets(Utils.getEnabledWidgets(this, AppWidgetManager.getInstance(this)));
}