Java Code Examples for android.widget.RemoteViews#setPendingIntentTemplate()
The following examples show how to use
android.widget.RemoteViews#setPendingIntentTemplate() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProfileWidget.java From KA27 with Apache License 2.0 | 7 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int appWidgetId: appWidgetIds) { Intent svcIntent = new Intent(context, WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.profile_widget_layout); widget.setRemoteAdapter(R.id.profile_list, svcIntent); widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK)); appWidgetManager.updateAppWidget(appWidgetId, widget); } }
Example 2
Source File: AppWidgetProvider.java From WanAndroid with Apache License 2.0 | 6 votes |
private RemoteViews updateWidgetListView(Context context, int id) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.list_app_widget); Intent intent = new Intent(context, AppWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, id); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.list_view_widget, intent); remoteViews.setEmptyView(R.id.list_view_widget, R.id.empty_view); Intent tempIntent = new Intent(context, DetailActivity.class); tempIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); remoteViews.setPendingIntentTemplate(R.id.list_view_widget, PendingIntent.getActivity(context, 0, tempIntent, PendingIntent.FLAG_CANCEL_CURRENT)); return remoteViews; }
Example 3
Source File: WidgetProvider.java From Birdays with Apache License 2.0 | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int i : appWidgetIds) { RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_layout); Intent serviceIntent = new Intent(context, WidgetService.class); serviceIntent.setData(Uri.parse(serviceIntent.toUri(Intent.URI_INTENT_SCHEME))); remoteViews.setRemoteAdapter(R.id.listview_widget, serviceIntent); remoteViews.setTextViewText(R.id.textview_widget_header_date, Utils.getDateWithoutYear(Calendar.getInstance().getTimeInMillis())); Intent clickIntent = new Intent(context, WidgetProvider.class); clickIntent.setAction(ACTION_ON_CLICK); PendingIntent clickPendingIntent = PendingIntent.getBroadcast(context, 0, clickIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.listview_widget, clickPendingIntent); appWidgetManager.updateAppWidget(i, remoteViews); appWidgetManager.notifyAppWidgetViewDataChanged(i, R.id.listview_widget); } }
Example 4
Source File: CheckListWidgetProvider.java From Travel-Mate with MIT License | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; /*int[] appWidgetIds holds ids of multiple instance of your widget * meaning you are placing more than one widgets on your homescreen*/ for (int appWidgetId : appWidgetIds) { RemoteViews remoteViews = updateWidgetListView(context, appWidgetId); Intent startActivityIntent = new Intent(context, ChecklistActivity.class); PendingIntent startActivityPendingIntent = PendingIntent.getActivity(context, 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.check_list_view, startActivityPendingIntent); remoteViews.setOnClickPendingIntent(R.id.image_checkbox, getPendingSelfIntent(context, MyOnClick)); // initialization of Image button appWidgetManager.updateAppWidget(appWidgetId, remoteViews); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 5
Source File: PlacesWidgetProvider.java From protrip with MIT License | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int i = 0; i < appWidgetIds.length; i++) { RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_collection); Intent intent = new Intent(context, PlacesWidgetRemoteViewsService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); views.setRemoteAdapter(R.id.widget_list, intent); Intent toastIntent = new Intent(context, PlacesWidgetRemoteViewsService.class); toastIntent.setAction(PlacesWidgetProvider.TOAST_ACTION); toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent toastPendingIntent = PendingIntent.getBroadcast(context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_list, toastPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], views); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 6
Source File: Widget.java From MTweaks-KernelAdiutorMOD with GNU General Public License v3.0 | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int appWidgetId : appWidgetIds) { Intent svcIntent = new Intent(context, WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile); widget.setRemoteAdapter(R.id.profile_list, svcIntent); widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK)); appWidgetManager.updateAppWidget(appWidgetId, widget); } }
Example 7
Source File: Widget.java From KernelAdiutor with GNU General Public License v3.0 | 6 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { super.onUpdate(context, appWidgetManager, appWidgetIds); for (int appWidgetId : appWidgetIds) { Intent svcIntent = new Intent(context, WidgetService.class); svcIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); svcIntent.setData(Uri.parse(svcIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.widget_profile); widget.setRemoteAdapter(R.id.profile_list, svcIntent); widget.setPendingIntentTemplate(R.id.profile_list, getPendingIntent(context, LIST_ITEM_CLICK)); appWidgetManager.updateAppWidget(appWidgetId, widget); } }
Example 8
Source File: MyWidget.java From ClassSchedule with Apache License 2.0 | 5 votes |
private void updateAction(Context context) { AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context); int[] appWidgetId = appWidgetManager.getAppWidgetIds(new ComponentName(context, MyWidget.class)); thisWidget = new ComponentName(context, MyWidget.class); remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_all); int month = TimeUtils.getNowMonth(); remoteViews.setTextViewText(R.id.tv_month,month+"\n月"); Intent intent = new Intent(context, UpdateService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); //配置适配器 remoteViews.setRemoteAdapter(R.id.widget_list, intent); Intent intent1 = new Intent(context, CourseActivity.class); PendingIntent pendingIntentTemplate = PendingIntent.getActivity( context, 1, intent1, PendingIntent.FLAG_UPDATE_CURRENT); ////拼接PendingIntent remoteViews.setPendingIntentTemplate(R.id.widget_list, pendingIntentTemplate); //更新remoteViews appWidgetManager.updateAppWidget(thisWidget, remoteViews); appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list); AppWidgetManager manager = AppWidgetManager.getInstance(context); manager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.widget_list); }
Example 9
Source File: NoteListWidgetProvider.java From nono-android with GNU General Public License v3.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for(int i=0;i<appWidgetIds.length;i++){ Intent intent = new Intent(context, NoteListWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.layout_widget_note_list); rv.setRemoteAdapter(appWidgetIds[i], R.id.note_list, intent); rv.setEmptyView(R.id.note_list, R.layout.empty_view); //新建笔记 Intent editIntent = new Intent(context, NoteEditActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,editIntent, 0); rv.setOnClickPendingIntent(R.id.add_new_note, pendingIntent); //启动应用 Intent launchIntent = new Intent(context, MainActivity.class); PendingIntent launchPendingIntent = PendingIntent.getActivity(context, 0,launchIntent, 0); rv.setOnClickPendingIntent(R.id.title_bar, launchPendingIntent); //快速打开笔记 Intent noteListIntent = new Intent(); noteListIntent.setAction(COLLECTION_VIEW_ACTION); noteListIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); PendingIntent noteListPendingIntent = PendingIntent.getBroadcast(context, 0, noteListIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.note_list, noteListPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 10
Source File: PredatorPostsWidgetProvider.java From Capstone-Project with MIT License | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { int numberOfWidgetsAvail = appWidgetIds.length; for (int i = 0; i < numberOfWidgetsAvail; i++) { int appWidgetId = appWidgetIds[i]; Intent widgetServiceIntent = new Intent(context, PredatorPostsWidgetService.class); widgetServiceIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); widgetServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); widgetServiceIntent.setData(Uri.parse(widgetServiceIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_posts); views.setRemoteAdapter(R.id.list_view_posts, widgetServiceIntent); views.setEmptyView(R.id.list_view_posts, R.id.text_view_posts_unavailable); Intent clickIntentMyStocks = new Intent(context, SplashActivity.class); PendingIntent clickPendingIntentMyStocks = PendingIntent .getActivity(context, 0, clickIntentMyStocks, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.text_view_posts_unavailable, clickPendingIntentMyStocks); Intent clickIntentMyStockDetails = new Intent(context, PostDetailsActivity.class); PendingIntent clickPendingIntentMyStockDetails = PendingIntent .getActivity(context, 0, clickIntentMyStockDetails, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.list_view_posts, clickPendingIntentMyStockDetails); appWidgetManager.updateAppWidget(appWidgetIds[i], views); Logger.d(TAG, "onUpdate: widgetId: " + appWidgetId); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 11
Source File: RssfeedWidgetProvider.java From codeexamples-android with Eclipse Public License 1.0 | 5 votes |
private static RemoteViews createWidgetLayout(Context context, int appWidgetId) { // create layout Intent intent = new Intent(context, RssfeedWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); views.setRemoteAdapter(R.id.feeds_list, intent); views.setEmptyView(R.id.feeds_list, R.layout.widget_empty_layout); // set last update time String time = DateFormat.getTimeFormat(context).format(new Date()); String date = DateFormat.getDateFormat(context).format(new Date()); views.setTextViewText(R.id.last_update, String.format("%1$s, %2$s", time, date)); // assign onRefresh handler Intent onRefreshIntent = new Intent(context, RssfeedWidgetProvider.class); onRefreshIntent.setAction(ACTION_REFRESH); PendingIntent onRefreshPending = PendingIntent.getBroadcast( context, 0, onRefreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setOnClickPendingIntent(R.id.refresh, onRefreshPending); // assign onItemClick handler Intent onItemClickIntent = new Intent(context, RssfeedWidgetProvider.class); onItemClickIntent.setAction(ACTION_SHOW_LINK); onItemClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onItemClickIntent.setData(Uri.parse(onItemClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onItemClickPending = PendingIntent.getBroadcast(context, 0, onItemClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.feeds_list, onItemClickPending); return views; }
Example 12
Source File: UpcomingWidgetProvider.java From cathode with Apache License 2.0 | 5 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { for (int appWidgetId : appWidgetIds) { Intent remoteViewsIntent = new Intent(context, UpcomingWidgetService.class); remoteViewsIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); remoteViewsIntent.setData(Uri.parse(remoteViewsIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.appwidget_upcoming); rv.setRemoteAdapter(android.R.id.list, remoteViewsIntent); rv.setEmptyView(android.R.id.list, android.R.id.empty); Intent homeIntent = new Intent(context, HomeActivity.class); homeIntent.setAction(HomeActivity.ACTION_SHOW_START_PAGE); homeIntent.putExtra(HomeActivity.EXTRA_START_PAGE, StartPage.SHOWS_UPCOMING); PendingIntent homePI = PendingIntent.getActivity(context, 0, homeIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.header, homePI); Intent rowClickTemplate = new Intent(context, EpisodeDetailsActivity.class); rowClickTemplate.setData(Uri.parse(rowClickTemplate.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent piTemplate = PendingIntent.getActivity(context, 0, rowClickTemplate, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(android.R.id.list, piTemplate); appWidgetManager.updateAppWidget(appWidgetId, rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 13
Source File: UpcomingMovieUpdateService.java From Movie-Check with Apache License 2.0 | 5 votes |
@Override protected void onHandleIntent(Intent intent) { final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext()); int[] allWidgetIds = intent.getIntArrayExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS); for (final int widgetId : allWidgetIds) { final RemoteViews remoteViews = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget_upcomingmovies); try { Response<List<Movie>> response = new ApiModule().provideMovieResource(this).listUpComing(getString(R.string.themoviedbapi_key), 1).execute(); switch (response.code()) { case HTTP_OK: remoteViews.setViewVisibility(R.id.linearlayout_loadfailed, View.GONE); remoteViews.setViewVisibility(R.id.listview_movies, View.VISIBLE); remoteViews.setRemoteAdapter(R.id.listview_movies, UpcomingMovieWidgetRemoteViewsService.newIntent(getApplicationContext(), widgetId, response.body())); appWidgetManager.updateAppWidget(widgetId, remoteViews); break; } } catch (Exception e) { remoteViews.setViewVisibility(R.id.listview_movies, View.GONE); remoteViews.setViewVisibility(R.id.linearlayout_loadfailed, View.VISIBLE); } remoteViews.setViewVisibility(R.id.linearlayout_loading, View.GONE); remoteViews.setEmptyView(R.id.listview_movies, R.id.linearlayout_anyfounded); Intent startActivityIntent = new Intent(getApplicationContext(), MovieProfileActivity.class); PendingIntent startActivityPendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, startActivityIntent, PendingIntent.FLAG_UPDATE_CURRENT); remoteViews.setPendingIntentTemplate(R.id.listview_movies, startActivityPendingIntent); appWidgetManager.updateAppWidget(widgetId, remoteViews); } }
Example 14
Source File: WriteilyWidgetProvider.java From writeily-pro with MIT License | 4 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { final int N = appWidgetIds.length; // Perform this loop procedure for each App Widget that belongs to this provider for (int i = 0; i < N; i++) { int appWidgetId = appWidgetIds[i]; // Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); SharedPreferences sharedPreferences = context.getSharedPreferences( "" + appWidgetIds[i], Context.MODE_PRIVATE); String directory = sharedPreferences.getString(Constants.WIDGET_PATH, PreferenceManager.getDefaultSharedPreferences(context) .getString(context.getResources().getString(R.string.pref_root_directory), Constants.DEFAULT_WRITEILY_STORAGE_FOLDER)); Intent newNoteIntent = new Intent(context, NoteActivity.class) .putExtra(Constants.TARGET_DIR, directory); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, newNoteIntent, 0); views.setOnClickPendingIntent(R.id.widget_new_note, pendingIntent); Intent goToMain = new Intent(context, MainActivity.class); PendingIntent goToMainPendingIntent = PendingIntent.getActivity(context, 0, goToMain, 0); views.setOnClickPendingIntent(R.id.widget_header, goToMainPendingIntent); // ListView Intent notesListIntent = new Intent(context, FilesWidgetService.class); notesListIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); notesListIntent.putExtra(Constants.FOLDER_NAME, directory); notesListIntent.setData(Uri.parse(notesListIntent.toUri(Intent.URI_INTENT_SCHEME))); views.setEmptyView(R.id.widget_list_container, R.id.widget_empty_hint); views.setRemoteAdapter(R.id.widget_notes_list, notesListIntent); Intent openNoteIntent = new Intent(context, NoteActivity.class).setAction(Intent.ACTION_EDIT); PendingIntent openNotePendingIntent = PendingIntent.getActivity(context, 0, openNoteIntent, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.widget_notes_list, openNotePendingIntent); // Tell the AppWidgetManager to perform an update on the current app widget appWidgetManager.updateAppWidget(appWidgetId, views); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 15
Source File: StackWidgetProvider.java From codeexamples-android with Eclipse Public License 1.0 | 4 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { // update each of the widgets with the remote adapter for (int i = 0; i < appWidgetIds.length; ++i) { // Here we setup the intent which points to the StackViewService // which will // provide the views for this collection. Intent intent = new Intent(context, StackWidgetService.class); intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); // When intents are compared, the extras are ignored, so we need to // embed the extras // into the data so that the extras will not be ignored. intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.widget_layout); rv.setRemoteAdapter(appWidgetIds[i], R.id.stack_view, intent); // The empty view is displayed when the collection has no items. It // should be a sibling // of the collection view. rv.setEmptyView(R.id.stack_view, R.id.empty_view); // Here we setup the a pending intent template. Individuals items of // a collection // cannot setup their own pending intents, instead, the collection // as a whole can // setup a pending intent template, and the individual items can set // a fillInIntent // to create unique before on an item to item basis. Intent toastIntent = new Intent(context, StackWidgetProvider.class); toastIntent.setAction(StackWidgetProvider.TOAST_ACTION); toastIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); PendingIntent toastPendingIntent = PendingIntent.getBroadcast( context, 0, toastIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.stack_view, toastPendingIntent); appWidgetManager.updateAppWidget(appWidgetIds[i], rv); } super.onUpdate(context, appWidgetManager, appWidgetIds); }
Example 16
Source File: TaskListWidgetProvider.java From opentasks with Apache License 2.0 | 4 votes |
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { /* * Iterate over all the widgets of this type and update them individually. */ for (int i = 0; i < appWidgetIds.length; i++) { Log.d(TAG, "updating widget " + i); /** Create an Intent with the {@link RemoteViewsService } and pass it the Widget Id */ Intent remoteServiceIntent = new Intent(context, TaskListWidgetUpdaterService.class); remoteServiceIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); remoteServiceIntent.setData(Uri.parse(remoteServiceIntent.toUri(Intent.URI_INTENT_SCHEME))); RemoteViews widget = new RemoteViews(context.getPackageName(), R.layout.task_list_widget); /** Add pending Intent to start the Tasks app when the title is clicked */ Intent tasksAppIntent = new Intent(context, TaskListActivity.class); tasksAppIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent taskAppPI = PendingIntent.getActivity(context, 0, tasksAppIntent, PendingIntent.FLAG_UPDATE_CURRENT); widget.setOnClickPendingIntent(android.R.id.button1, taskAppPI); /** Add a pending Intent to start new Task Activity on the new Task Button */ Intent editTaskIntent = new Intent(context, TaskListWidgetProvider.class); editTaskIntent.setAction(ACTION_CREATE_TASK); editTaskIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetIds[i]); PendingIntent newTaskPI = PendingIntent.getBroadcast(context, appWidgetIds[i], editTaskIntent, PendingIntent.FLAG_UPDATE_CURRENT); widget.setOnClickPendingIntent(android.R.id.button2, newTaskPI); /** Set the {@link RemoteViewsService } subclass as the adapter for the {@link ListView} in the widget. */ widget.setRemoteAdapter(R.id.task_list_widget_lv, remoteServiceIntent); Intent detailIntent = new Intent(Intent.ACTION_VIEW); detailIntent.putExtra(TaskListActivity.EXTRA_FORCE_LIST_SELECTION, true); PendingIntent clickPI = PendingIntent.getActivity(context, 0, detailIntent, PendingIntent.FLAG_UPDATE_CURRENT); widget.setPendingIntentTemplate(R.id.task_list_widget_lv, clickPI); /* Finally update the widget */ appWidgetManager.updateAppWidget(appWidgetIds[i], widget); } }
Example 17
Source File: AppWidget.java From Clip-Stack with MIT License | 4 votes |
private static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { SharedPreferences preference = PreferenceManager.getDefaultSharedPreferences(context); boolean isStarred = preference.getBoolean(WIDGET_IS_STARRED, false); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.app_widget); //set title views.setImageViewResource( R.id.widget_title_star, isStarred ? R.drawable.ic_action_star_white : R.drawable.ic_action_star_outline_white ); //bind title PendingIntent pMainIntent = PendingIntent.getActivity( context, 0, new Intent(context, ActivityMain.class), PendingIntent.FLAG_UPDATE_CURRENT ); views.setOnClickPendingIntent(R.id.widget_title_text, pMainIntent); PendingIntent pStarIntent = PendingIntent.getService( context, 1, new Intent(context, ClipObjectActionBridge.class) .putExtra(ClipObjectActionBridge.ACTION_CODE, ClipObjectActionBridge.ACTION_CHANGE_WIDGET_STAR), PendingIntent.FLAG_UPDATE_CURRENT ); views.setOnClickPendingIntent(R.id.widget_title_star, pStarIntent); PendingIntent pAddIntent = PendingIntent.getActivity( context, 2, new Intent(context, ActivityEditor.class) .putExtra(ClipObjectActionBridge.STATUE_IS_STARRED, isStarred) .putExtra(Intent.EXTRA_TEXT, ""), PendingIntent.FLAG_UPDATE_CURRENT ); views.setOnClickPendingIntent(R.id.widget_title_add, pAddIntent); //set main view Intent intent = new Intent(context, AppWidgetService.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId) .putExtra(WIDGET_IS_STARRED, isStarred) .putExtra("TIME", new Date().getTime()); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); views.setRemoteAdapter(R.id.widget_main_view, intent); views.setEmptyView(R.id.widget_main_view, R.layout.app_widget_card_empty); views.setPendingIntentTemplate( R.id.widget_main_view, PendingIntent.getService( context, 8, new Intent(context, ClipObjectActionBridge.class), PendingIntent.FLAG_UPDATE_CURRENT )); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, views); }
Example 18
Source File: WidgetUnified.java From FairEmail with GNU General Public License v3.0 | 4 votes |
@Override public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) { SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); for (int appWidgetId : appWidgetIds) { String name = prefs.getString("widget." + appWidgetId + ".name", null); long account = prefs.getLong("widget." + appWidgetId + ".account", -1L); long folder = prefs.getLong("widget." + appWidgetId + ".folder", -1L); String type = prefs.getString("widget." + appWidgetId + ".type", null); boolean semi = prefs.getBoolean("widget." + appWidgetId + ".semi", true); int font = prefs.getInt("widget." + appWidgetId + ".font", 0); int padding = prefs.getInt("widget." + appWidgetId + ".padding", 0); Intent view = new Intent(context, ActivityView.class); view.setAction("folder:" + folder); view.putExtra("account", account); view.putExtra("type", type); view.putExtra("refresh", true); view.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); PendingIntent pi = PendingIntent.getActivity(context, appWidgetId, view, PendingIntent.FLAG_UPDATE_CURRENT); RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_unified); if (!semi) views.setInt(R.id.widget, "setBackgroundColor", Color.TRANSPARENT); if (font > 0) views.setTextViewTextSize(R.id.title, TypedValue.COMPLEX_UNIT_SP, getFontSizeSp(font)); if (padding > 0) { int px = getPaddingPx(padding, context); views.setViewPadding(R.id.title, px, px, px, px); } if (name == null) views.setTextViewText(R.id.title, context.getString(R.string.title_folder_unified)); else views.setTextViewText(R.id.title, name); views.setOnClickPendingIntent(R.id.title, pi); Intent service = new Intent(context, WidgetUnifiedService.class); service.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); service.setData(Uri.parse(service.toUri(Intent.URI_INTENT_SCHEME))); views.setRemoteAdapter(R.id.lv, service); Intent thread = new Intent(context, ActivityView.class); thread.setAction("widget"); thread.putExtra("filter_archive", !EntityFolder.ARCHIVE.equals(type)); thread.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent piItem = PendingIntent.getActivity( context, ActivityView.REQUEST_WIDGET, thread, PendingIntent.FLAG_UPDATE_CURRENT); views.setPendingIntentTemplate(R.id.lv, piItem); appWidgetManager.updateAppWidget(appWidgetId, views); } }
Example 19
Source File: ShotAppWidgetProvider.java From droidddle with Apache License 2.0 | 4 votes |
public static void setupWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, boolean refreshing) { boolean oauthed = OAuthUtils.haveToken(context); // Set up the intent that starts the StackViewService, which will // provide the views for this collection. Resources res = context.getResources(); Intent intent = new Intent(context, ShotWidgetService.class); // Add the app widget ID to the intent extras. intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); // Instantiate the RemoteViews object for the app widget layout. RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.shot_appwidget); // Set up the RemoteViews object to use a RemoteViews adapter. // This adapter connects // to a RemoteViewsService through the specified intent. // This is how you populate the data. rv.setImageViewResource(R.id.shot_widget_update, R.drawable.ic_refresh_grey); // rv.setImageViewResource(R.id.shot_widget_icon, R.drawable.ic_launcher); rv.setTextViewText(R.id.shot_widget_title, res.getString(R.string.shot_widget_title)); rv.setViewVisibility(R.id.shot_widget_progress, refreshing ? View.VISIBLE : View.INVISIBLE); rv.setViewVisibility(R.id.shot_widget_update, refreshing ? View.INVISIBLE : View.VISIBLE); // The empty view is displayed when the collection has no items. // It should be in the same layout used to instantiate the RemoteViews // object above. rv.setEmptyView(R.id.shot_stack_view, R.id.shot_widget_empty_view); rv.setTextViewText(R.id.shot_widget_empty_view, res.getString(R.string.shot_widget_empty)); if (oauthed) { rv.setRemoteAdapter(R.id.shot_stack_view, intent); rv.setViewVisibility(R.id.shot_widget_tips_view, View.GONE); } else { rv.setTextViewText(R.id.shot_widget_tips_view, res.getString(R.string.not_login)); rv.setViewVisibility(R.id.shot_widget_tips_view, View.VISIBLE); } final Intent onClickIntent = new Intent(context, ShotAppWidgetProvider.class); onClickIntent.setAction(ShotAppWidgetProvider.CLICK_ACTION); onClickIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); onClickIntent.setData(Uri.parse(onClickIntent.toUri(Intent.URI_INTENT_SCHEME))); final PendingIntent onClickPendingIntent = PendingIntent.getBroadcast(context, 0, onClickIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.shot_stack_view, onClickPendingIntent); final Intent refreshIntent = new Intent(context, ShotAppWidgetProvider.class); refreshIntent.setAction(ShotAppWidgetProvider.REFRESH_ACTION); final PendingIntent refreshPendingIntent = PendingIntent.getBroadcast(context, 0, refreshIntent, PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.shot_widget_update, refreshPendingIntent); appWidgetManager.updateAppWidget(appWidgetId, rv); final ComponentName cn = new ComponentName(context, ShotAppWidgetProvider.class); // appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetManager.getAppWidgetIds(cn), R.id.shot_stack_view); }
Example 20
Source File: ListWidget.java From kolabnotes-android with GNU Lesser General Public License v3.0 | 4 votes |
static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId) { String account = ListWidgetConfigureActivity.loadListWidgetAccountPref(context, appWidgetId); String notebook = ListWidgetConfigureActivity.loadListWidgetNotebookPref(context, appWidgetId); String tag = ListWidgetConfigureActivity.loadListWidgetTagPref(context, appWidgetId); // Set up the intent that starts the StackViewService, which will // provide the views for this collection. Intent intent = new Intent(context, ListWidgetService.class); // Add the app widget ID to the intent extras. intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId); intent.setData(Uri.parse(intent.toUri(Intent.URI_INTENT_SCHEME))); // Instantiate the RemoteViews object for the app widget layout. RemoteViews rv = new RemoteViews(context.getPackageName(), R.layout.list_widget); // Set up the RemoteViews object to use a RemoteViews adapter. // This adapter connects // to a RemoteViewsService through the specified intent. // This is how you populate the data. rv.setRemoteAdapter(appWidgetId,R.id.widget_list_notes, intent); // The empty view is displayed when the collection has no items. // It should be in the same layout used to instantiate the RemoteViews // object above. //rv.setEmptyView(R.id.stack_view, R.id.empty_view); String correctAccountName = account; if("local".equals(account)){ correctAccountName = context.getResources().getString(R.string.drawer_account_local); } rv.setTextViewText(R.id.widget_text, correctAccountName); Intent intentCreate = new Intent(context, DetailActivity.class); Intent intentMainActivity = new Intent(context, MainActivity.class); AccountIdentifier accId = Utils.getAccountIdentifierWithName(context, account); StringBuilder sb = new StringBuilder(); if(!TextUtils.isEmpty(notebook)){ sb.append(notebook); Notebook bySummary = new NotebookRepository(context).getBySummary(accId.getAccount(), accId.getRootFolder(), notebook); intent.putExtra(Utils.NOTEBOOK_UID, bySummary.getIdentification().getUid()); intentCreate.putExtra(Utils.NOTEBOOK_UID, bySummary.getIdentification().getUid()); intentMainActivity.putExtra(Utils.SELECTED_NOTEBOOK_NAME, notebook); } intentCreate.putExtra(Utils.INTENT_ACCOUNT_EMAIL, accId.getAccount()); intentCreate.putExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER, accId.getRootFolder()); PendingIntent pendingIntentCreate = PendingIntent.getActivity(context, appWidgetId, intentCreate,PendingIntent.FLAG_UPDATE_CURRENT); if(!TextUtils.isEmpty(tag)){ if(sb.length() > 0){ sb.append(" / "); } sb.append(tag); intentMainActivity.putExtra(Utils.SELECTED_TAG_NAME, tag); } if(sb.length() > 0){ rv.setTextViewText(R.id.widget_text_detail, sb.toString()); } intentMainActivity.putExtra(Utils.INTENT_ACCOUNT_EMAIL, accId.getAccount()); intentMainActivity.putExtra(Utils.INTENT_ACCOUNT_ROOT_FOLDER, accId.getRootFolder()); PendingIntent pendingIntentMainActivity = PendingIntent.getActivity(context, appWidgetId, intentMainActivity,PendingIntent.FLAG_UPDATE_CURRENT); rv.setOnClickPendingIntent(R.id.imageButton_icon,pendingIntentMainActivity); rv.setOnClickPendingIntent(R.id.imageButton_add,pendingIntentCreate); Intent clickIntent=new Intent(context, DetailActivity.class); PendingIntent clickPI=PendingIntent.getActivity(context, 0, clickIntent,PendingIntent.FLAG_UPDATE_CURRENT); rv.setPendingIntentTemplate(R.id.widget_list_notes, clickPI); // Instruct the widget manager to update the widget appWidgetManager.updateAppWidget(appWidgetId, rv); }