void requestFolderChange(long folderId) { mContext.sendBroadcast( new Intent(getChangeFolderAction(mContext)) .setClass(mContext, BookmarkWidgetProxy.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId) .putExtra(BookmarkColumns._ID, folderId)); }
void refreshWidget() { mContext.sendBroadcast( new Intent( BookmarkThumbnailWidgetProviderBase.getBookmarkAppWidgetUpdateAction(mContext), null, mContext, BookmarkThumbnailWidgetProvider.class) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)); }
@SuppressFBWarnings("DM_EXIT") @Override public void onCreate() { // Required to be applied here redundantly to prevent crashes in the cases where the // package data is deleted or the Chrome application forced to stop. try { mContext.startBrowserProcessesAndLoadLibrariesSync(true); } catch (ProcessInitException e) { Log.e(TAG, "Failed to start browser process.", e); // Since the library failed to initialize nothing in the application // can work, so kill the whole application not just the activity System.exit(-1); } mUpdateListener = new BookmarkWidgetUpdateListener(mContext, this); }
@Override public RemoteViews getViewAt(int position) { if (mCurrentFolder == null) { Log.w(TAG, "No current folder data available."); return null; } BookmarkNode bookmark = getBookmarkForPosition(position); if (bookmark == null) { Log.w(TAG, "Couldn't get bookmark for position " + position); return null; } if (bookmark == mCurrentFolder && bookmark.parent() == null) { Log.w(TAG, "Invalid bookmark data: loop detected."); return null; } String title = bookmark.name(); String url = bookmark.url(); long id = (bookmark == mCurrentFolder) ? bookmark.parent().id() : bookmark.id(); // Two layouts are needed because RemoteView does not supporting changing the scale type // of an ImageView: boomarks crop their thumbnails, while folders stretch their icon. RemoteViews views = !bookmark.isUrl() ? new RemoteViews( mContext.getPackageName(), R.layout.bookmark_thumbnail_widget_item_folder) : new RemoteViews(mContext.getPackageName(), R.layout.bookmark_thumbnail_widget_item); // Set the title of the bookmark. Use the url as a backup. views.setTextViewText(R.id.label, TextUtils.isEmpty(title) ? url : title); if (!bookmark.isUrl()) { int thumbId = (bookmark == mCurrentFolder) ? R.drawable.thumb_bookmark_widget_folder_back_holo : R.drawable.thumb_bookmark_widget_folder_holo; views.setImageViewResource(R.id.thumb, thumbId); views.setImageViewResource(R.id.favicon, R.drawable.ic_bookmark_widget_bookmark_holo_dark); } else { // RemoteViews require a valid bitmap config. Options options = new Options(); options.inPreferredConfig = Config.ARGB_8888; byte[] favicon = bookmark.favicon(); if (favicon != null && favicon.length > 0) { views.setImageViewBitmap( R.id.favicon, BitmapFactory.decodeByteArray(favicon, 0, favicon.length, options)); } else { views.setImageViewResource(R.id.favicon, org.chromium.chrome.R.drawable.globe_favicon); } byte[] thumbnail = bookmark.thumbnail(); if (thumbnail != null && thumbnail.length > 0) { views.setImageViewBitmap( R.id.thumb, BitmapFactory.decodeByteArray(thumbnail, 0, thumbnail.length, options)); } else { views.setImageViewResource(R.id.thumb, R.drawable.browser_thumbnail); } } Intent fillIn; if (!bookmark.isUrl()) { fillIn = new Intent(getChangeFolderAction(mContext)) .putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId) .putExtra(BookmarkColumns._ID, id); } else { fillIn = new Intent(Intent.ACTION_VIEW); if (!TextUtils.isEmpty(url)) { fillIn = fillIn.addCategory(Intent.CATEGORY_BROWSABLE).setData(Uri.parse(url)); } else { fillIn = fillIn.addCategory(Intent.CATEGORY_LAUNCHER); } } views.setOnClickFillInIntent(R.id.list_item, fillIn); return views; }
@Override public RemoteViews getLoadingView() { return new RemoteViews(mContext.getPackageName(), R.layout.bookmark_thumbnail_widget_item); }