List of usage examples for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID
String EXTRA_APPWIDGET_ID
To view the source code for android.appwidget AppWidgetManager EXTRA_APPWIDGET_ID.
Click Source Link
From source file:name.gumartinm.weather.information.widget.WidgetIntentService.java
@Override protected void onHandleIntent(final Intent intent) { final int appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); final boolean isRefreshAppWidget = intent.getBooleanExtra("refreshAppWidget", false); if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { // Nothing to do. Something went wrong. return;/*ww w .j a v a2 s .co m*/ } final DatabaseQueries query = new DatabaseQueries(this.getApplicationContext()); final WeatherLocation weatherLocation = query.queryDataBase(); if (weatherLocation == null) { // Nothing to do. Show error. final RemoteViews view = this.makeViewOnError(appWidgetId); this.updateWidget(view, appWidgetId); return; } if (!isRefreshAppWidget) { final RemoteViews view = this.makeViewOnNotRefresh(weatherLocation, appWidgetId); this.updateWidget(view, appWidgetId); } else { final RemoteViews view = this.makeViewOnRefresh(weatherLocation, appWidgetId); this.updateWidget(view, appWidgetId); } }
From source file:com.gadelkareem.serverload.ServerLoadConfig.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); // 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);//from w w w .j av a2 s. c om // Set the view layout resource to use. setContentView(R.layout.serverload_config); // Find the EditText URL_Input = (EditText) findViewById(R.id.URL); servername_Input = (EditText) findViewById(R.id.servername); // Bind the action for the save button. findViewById(R.id.save_button).setOnClickListener(mOnClickListener); // Find the widget id from the intent. Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } // If they gave us an intent without the widget id, just bail. if (appWidgetId == AppWidgetManager.INVALID_APPWIDGET_ID) { Log.d(TAG, "Widget id is invalid"); finish(); } URL_Input.setText(loadPref(ServerLoadConfig.this, appWidgetId, "URL")); servername_Input.setText(loadPref(ServerLoadConfig.this, appWidgetId, "servername")); }
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);// w w w . ja v a 2 s . co 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:au.com.wallaceit.reddinator.Rservice.java
public ListRemoteViewsFactory(Context context, Intent intent) { this.mContext = context; appWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); global = ((GlobalObjects) context.getApplicationContext()); mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); //System.out.println("New view factory created for widget ID:"+appWidgetId); // Set thread network policy to prevent network on main thread exceptions. StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build(); StrictMode.setThreadPolicy(policy);/*www . j a va 2s.c o m*/ // if this is a user request (apart from 'loadmore') or an auto update, do not attempt to load cache. // when a user clicks load more and a new view factory needs to be created we don't want to bypass cache, we want to load the cached items int loadType = global.getLoadType(); if (!global.getBypassCache() || loadType == GlobalObjects.LOADTYPE_LOADMORE) { // load cached data data = global.getFeed(mSharedPreferences, appWidgetId); if (data.length() != 0) { titleFontSize = mSharedPreferences.getString(context.getString(R.string.widget_theme_pref), "16"); try { lastItemId = data.getJSONObject(data.length() - 1).getJSONObject("data").getString("name"); } catch (JSONException e) { lastItemId = "0"; // Could not get last item ID; perform a reload next time and show error view :( e.printStackTrace(); } if (loadType == GlobalObjects.LOADTYPE_LOAD) { loadCached = true; // this isn't a loadmore request, the cache is loaded and we're done //System.out.println("Cache loaded, no user request received."); } } else { loadReddits(false); // No feed items; do a reload. } } else { data = new JSONArray(); // set empty data to prevent any NPE } }
From source file:org.openbitcoinwidget.WidgetProvider.java
private static void updateAppWidget(final Context context, AppWidgetManager appWidgetManager, int appWidgetId) { WidgetPreferences preferences = PreferencesActivity.getWidgetPreferences(context, appWidgetId); if (preferences == null) { // Don't do anything unless the rate service has been chosen. // Show a "please remove this widget and add a new one" appWidgetManager.updateAppWidget(appWidgetId, new RemoteViews(context.getPackageName(), R.layout.appwidget_replace_me)); return;/*from w w w.j a v a2 s .c o m*/ } boolean isOnLockScreen = isWidgetShownOnLockScreen(appWidgetManager, appWidgetId); RemoteViews views; if (isOnLockScreen) { views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider_lock_screen); } else { views = new RemoteViews(context.getPackageName(), R.layout.appwidget_provider); } Intent clickIntent = new Intent(context, GraphPopupActivity.class); clickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); clickIntent.setAction("dummyAction"); // Needed to get the extra variables included in the call // Note: the appWidgetId needs to be sent in the pendingIntent as request code, otherwise only ONE // cached intent will be used for all widget instances! PendingIntent pendingIntent = PendingIntent.getActivity(context, appWidgetId, clickIntent, 0); views.setOnClickPendingIntent(R.id.appwidget_box, pendingIntent); views.setTextViewText(R.id.appwidget_service_name, preferences.getRateService().getName()); DataOpenHelper dbHelper = new DataOpenHelper(context); TickerData prevData = dbHelper.getLastTickerData(preferences); TickerData newData; String latestQuote = getLatestQuote(preferences); if (latestQuote != null && !latestQuote.equals("")) { newData = preferences.getRateService().parseJSON(latestQuote); newData.setCurrencyConversion(preferences.getCurrencyConversion()); storeLastValueIfNotNull(dbHelper, newData); updateViews(views, prevData, newData, preferences); } else if (prevData != null) { newData = prevData; updateViews(views, prevData, newData, preferences); } else { updateViewsWithError(views, preferences); } appWidgetManager.updateAppWidget(appWidgetId, views); }
From source file:com.granita.tasks.homescreen.TaskListWidgetSettingsActivity.java
private void finishWithResult(boolean ok) { Bundle bundle = new Bundle(); bundle.putInt(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); Intent intent = new Intent(); intent.putExtras(bundle);/*from www.jav a2 s .c om*/ if (ok) { setResult(RESULT_OK, intent); } else { setResult(RESULT_CANCELED, intent); } finish(); }
From source file:com.android.gallery3d.gadget.WidgetConfigure.java
@Override protected void onCreate(Bundle savedState) { super.onCreate(savedState); mAppWidgetId = getIntent().getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1); if (mAppWidgetId == -1) { setResult(Activity.RESULT_CANCELED); finish();/*from w w w. jav a 2 s . c o m*/ return; } if (savedState == null) { if (ApiHelper.HAS_REMOTE_VIEWS_SERVICE) { Intent intent = new Intent(this, WidgetTypeChooser.class); startActivityForResult(intent, REQUEST_WIDGET_TYPE); } else { // Choose the photo type widget setWidgetType(new Intent().putExtra(KEY_WIDGET_TYPE, R.id.widget_type_photo)); } } else { mPickedItem = savedState.getParcelable(KEY_PICKED_ITEM); } }
From source file:com.gaze.webpaser.StackWidgetService.java
public StackRemoteViewsFactory(Context context, Intent intent) { mContext = context; mAppWidgetId = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); }
From source file:ru.kaefik.isaifutdinov.an_weather_widget.ConfigActivity.java
@Override protected void onStart() { super.onStart(); Log.i(TAG_SERVICE, "onStart ConfigActivity"); //----------------------- mAppWidgetId = AppWidgetManager.INVALID_APPWIDGET_ID; Intent intent = getIntent();/*from w ww.j av a 2 s. com*/ Bundle extras = intent.getExtras(); if (extras != null) { mAppWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID); } final Context context = this; //----------------------- // ?? ? ?? mNameCity.setOnItemClickListener(new AdapterView.OnItemClickListener() { public void onItemClick(AdapterView<?> parent, View view, int position, long id) { String cityNameString = adapter.getCityModel(position); Log.i(TAG_SERVICE, " OnItemClick ConfigActivity -> " + cityNameString + " id : " + String.valueOf(mAppWidgetId)); saveStringParametersToCfg(context, String.valueOf(mAppWidgetId), cityNameString); Intent resulValue = new Intent(AnWeatherWidget.CLICK_WIDGET_BUTTON); resulValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId); // ? ConfigActivity try { AnWeatherWidget.updateAppWidget(context, AppWidgetManager.getInstance(context), mAppWidgetId); } catch (JSONException e) { e.printStackTrace(); } setResult(RESULT_OK, resulValue); finish(); } }); }
From source file:com.heneryh.aquanotes.ui.DashboardFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_dashboard, container); // Attach event handlers root.findViewById(R.id.home_btn_controllers).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { fireTrackerEvent("Controllers"); // Launch list of sessions and vendors the user has starred startActivity(new Intent(getActivity(), ControllersActivity.class)); }/* w w w . j a v a 2s. c om*/ }); // root.findViewById(R.id.home_btn_livestock).setOnClickListener(new View.OnClickListener() { // public void onClick(View view) { // fireTrackerEvent("Livestock"); // // Launch list of sessions and vendors the user has starred // startActivity(new Intent(getActivity(), LivestockActivity.class)); // } // }); root.findViewById(R.id.home_btn_feed).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { fireTrackerEvent("Feed"); // Launch list of sessions and vendors the user has starred startActivity(new Intent(getActivity(), FeedActivity.class)); } }); root.findViewById(R.id.home_btn_prefs).setOnClickListener(new View.OnClickListener() { public void onClick(View view) { Intent i = new Intent(getActivity(), ConfigurePrefs.class); int controllerId = 999; // use the special case of widget=999 , this is not a good solution <-- no longer used! i.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, controllerId); startActivity(i); } }); return root; }