List of usage examples for android.appwidget AppWidgetManager getInstance
public static AppWidgetManager getInstance(Context context)
From source file:dk.cafeanalog.AnalogWidget.java
private void handleError(Context mContext) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext); RemoteViews views = new RemoteViews(mContext.getPackageName(), R.layout.analog_widget); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(mContext, AnalogWidget.class)); views.setTextViewText(R.id.appwidget_text, "Error"); views.setOnClickPendingIntent(R.id.appwidget_text, getPendingSelfIntent(mContext)); // Instruct the widget manager to update the widget for (int appWidgetId : appWidgetIds) { appWidgetManager.updateAppWidget(appWidgetId, views); }/*w ww. j av a2 s.c o m*/ }
From source file:com.abhijitvalluri.android.fitnotifications.widget.ServiceToggle.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if (TOGGLE_CLICKED.equals(intent.getAction())) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.service_toggle_widget); if (NLService.isEnabled()) { NLService.setEnabled(false); views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_off_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_red); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_off_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.red)); } else {//from w w w.j a va 2s . c o m NLService.setEnabled(true); views.setImageViewResource(R.id.widgetToggleButton, R.drawable.ic_speaker_notes_white_48dp); views.setInt(R.id.widgetToggleButton, "setBackgroundResource", R.drawable.round_rectangle_green); views.setTextViewText(R.id.widgetToggleText, context.getString(R.string.widget_on_text)); views.setTextColor(R.id.widgetToggleText, ContextCompat.getColor(context, R.color.green)); } views.setOnClickPendingIntent(R.id.widgetToggleButton, getPendingSelfIntent(context, 0, TOGGLE_CLICKED)); ComponentName componentName = new ComponentName(context, ServiceToggle.class); appWidgetManager.updateAppWidget(componentName, views); } }
From source file:com.meiste.greg.ptw.WidgetProvider.java
@Override public void onReceive(final Context context, final Intent intent) { if (intent.hasExtra(Intent.EXTRA_ALARM_COUNT)) { Util.log("WidgetProvider.onReceive: Widget alarm"); new UpdateWidgetThread(context).start(); setAlarm(context);//from w w w. ja va2 s . c o m } else if (intent.getAction().equals(Intent.ACTION_TIME_CHANGED)) { Util.log("WidgetProvider.onReceive: Time change"); setAlarm(context); } else if (intent.getAction().equals(PTW.INTENT_ACTION_SCHEDULE)) { Util.log("WidgetProvider.onReceive: Schedule Updated"); final int[] appWidgetIds = getInstalledWidgets(context); if (appWidgetIds.length > 0) { /* Force full widget update */ sRace = null; onUpdate(context, AppWidgetManager.getInstance(context), appWidgetIds); } } else if (intent.getAction().equals(PTW.INTENT_ACTION_ANSWERS)) { Util.log("WidgetProvider.onReceive: Answers submitted"); final int[] appWidgetIds = getInstalledWidgets(context); if (appWidgetIds.length > 0) { new UpdateWidgetThread(context).start(); } } else super.onReceive(context, intent); }
From source file:com.udacity.stockhawk.widget.StockAppWidgetProvider.java
@Override public void onReceive(Context context, Intent intent) { super.onReceive(context, intent); if (QuoteSyncJob.ACTION_DATA_UPDATED.equals(intent.getAction())) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context, getClass())); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.lv_stock_list); }//from w w w .j a v a2s . c om }
From source file:com.johan.vertretungsplan.SettingsActivity.java
@Override public void onPause() { super.onPause(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); SharedPreferences.Editor prefEditor = prefs.edit(); prefEditor.putBoolean("isInForeground", false); prefEditor.commit();// ww w .j av a2 s. c o m AppWidgetManager mgr = AppWidgetManager.getInstance(this); int[] ids = mgr.getAppWidgetIds(new ComponentName(this, VertretungsplanWidgetProvider.class)); new VertretungsplanWidgetProvider().onUpdate(this, mgr, ids); }
From source file:com.xengar.android.stocktracker.widget.ListWidgetProvider.java
@Override public void onReceive(@NonNull Context context, @NonNull Intent intent) { super.onReceive(context, intent); if (QuoteSyncJob.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); }//from ww w .jav a2 s . com }
From source file:com.ultrafunk.network_info.receiver.WifiStatusReceiver.java
@Override public void onReceive(Context context, Intent intent) { final String action = intent.getAction(); // Log.e(this.getClass().getSimpleName(), "onReceive(): " + action); updateWifiViews = true;//w w w.ja va 2 s . c o m wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE); wifiState = wifiManager.getWifiState(); wifiInfo = wifiManager.getConnectionInfo(); if ((wifiState == WifiManager.WIFI_STATE_ENABLED) && (wifiInfo.getIpAddress() == 0)) detailedState = WifiInfo.getDetailedStateOf(wifiInfo.getSupplicantState()); if (WifiManager.NETWORK_STATE_CHANGED_ACTION.equals(action)) { if (isConnectionReady(intent)) { String securityString = WifiUtils.getSecurityString(context, wifiManager, wifiInfo.getBSSID()); NetworkStateService.setWifiSecurityString(securityString); detailsString = context.getString(R.string.security) + ": " + securityString; Intent serviceIntent = new Intent(context, NetworkStateService.class); serviceIntent.setAction(Constants.ACTION_WIFI_CONNECTED); context.startService(serviceIntent); } partiallyUpdateWidgets(context); } else if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(action) || Constants.ACTION_WIFI_SCANNING.equals(action)) { partiallyUpdateWidgets(context); } else if (Intent.ACTION_SCREEN_ON.equals(action) || Constants.ACTION_WIFI_LINK_SPEED.equals(action)) { if (isConnected()) { setDetailsString(context); partiallyUpdateWidgets(context); } } else if (Constants.ACTION_UPDATE_WIDGET.equals(action)) { if (isConnected()) setDetailsString(context); partiallyUpdateWidget(context, AppWidgetManager.getInstance(context), intent.getIntExtra(Constants.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)); } }
From source file:net.sourceforge.servestream.service.AppWidgetOneProvider.java
private void pushUpdate(Context context, int[] appWidgetIds, RemoteViews views) { // Update specific list of appWidgetIds if given, otherwise default to all final AppWidgetManager gm = AppWidgetManager.getInstance(context); if (appWidgetIds != null) { gm.updateAppWidget(appWidgetIds, views); } else {//from w ww .j av a 2s . c o m gm.updateAppWidget(new ComponentName(context, this.getClass()), views); } }
From source file:mmpud.project.daycountwidget.DayCountMainActivity.java
private void updateAdapter() { mAdapter.clear();/*from w w w . j a v a 2 s . co m*/ // query from database if (mDbHelper == null) { mDbHelper = new DayCountDbHelper(this); } SQLiteDatabase db = mDbHelper.getReadableDatabase(); // get all available day count widget ids AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this); ComponentName component = new ComponentName(this, DayCountWidgetProvider.class); int[] appWidgetIds = appWidgetManager.getAppWidgetIds(component); for (int appWidgetId : appWidgetIds) { Cursor cursor = db.query(Contract.Widget.TABLE_NAME, null, Contract.Widget.WIDGET_ID + "=?", new String[] { String.valueOf(appWidgetId) }, null, null, null); long targetDateMillis; String title; String bodyStyle; int countBy; if (cursor.moveToFirst()) { targetDateMillis = cursor.getLong(cursor.getColumnIndexOrThrow(TARGET_DATE)); title = cursor.getString(cursor.getColumnIndexOrThrow(EVENT_TITLE)); bodyStyle = cursor.getString(cursor.getColumnIndexOrThrow(BODY_STYLE)); countBy = cursor.getInt(cursor.getColumnIndexOrThrow(COUNT_BY)); } else { targetDateMillis = LocalDate.now().atStartOfDay().atZone(ZoneOffset.UTC).toInstant().toEpochMilli(); title = ""; bodyStyle = String.valueOf(ContextCompat.getColor(this, R.color.body_black)); countBy = COUNT_BY_DAY; } mAdapter.add(new DayCountWidget(appWidgetId, title, null, targetDateMillis, countBy, null, bodyStyle)); cursor.close(); } db.close(); }
From source file:com.launcher.silverfish.HomeScreenFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { sqlHelper = new LauncherSQLiteHelper(getActivity().getBaseContext()); // Initiate global variables mAppWidgetManager = AppWidgetManager.getInstance(getActivity().getBaseContext()); mAppWidgetHost = new LauncherAppWidgetHost(getActivity().getApplicationContext(), WIDGET_HOST_ID); mAppWidgetHost.startListening();/*from w w w .j av a 2 s. c o m*/ mPacMan = getActivity().getPackageManager(); appsList = new ArrayList<AppDetail>(); rootView = inflater.inflate(R.layout.activity_home, container, false); // Set touch slop and listen for touch events, such as swipe touchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop(); rootView.setOnTouchListener(onRootTouchListener); shortcutLayout = (SquareGridLayout) rootView.findViewById(R.id.shortcut_area); // Start listening for shortcut additions ((LauncherActivity) getActivity()).setFragShortcutAddListenerRefreshListener(new ShortcutAddListener() { @Override public void OnShortcutAdd(String appName) { // Insert it into the database and get the row id // TODO: Check if an error has occurred while inserting into database. long appId = sqlHelper.addShortcut(appName); // Create shortcut and add it ShortcutDetail shortcut = new ShortcutDetail(); shortcut.name = appName; shortcut.id = appId; if (addAppToView(shortcut)) { updateShortcuts(); } } }); addWidgetOnClickListener(); setOnDragListener(); loadWidget(); loadApps(); updateShortcuts(); return rootView; }