use of android.appwidget.AppWidgetManager in project JamsMusicPlayer by psaravan.
the class LargeWidgetConfigActivity method updateWidgetConfig.
private void updateWidgetConfig() {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.large_widget_layout);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
updateWidget();
finish();
}
use of android.appwidget.AppWidgetManager in project JamsMusicPlayer by psaravan.
the class LargeWidgetProvider method onReceive.
@Override
public void onReceive(Context context, Intent intent) {
super.onReceive(context, intent);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
ComponentName thisAppWidget = new ComponentName(context.getPackageName(), LargeWidgetProvider.class.getName());
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(thisAppWidget);
onUpdate(context, appWidgetManager, appWidgetIds);
}
use of android.appwidget.AppWidgetManager in project JamsMusicPlayer by psaravan.
the class SmallWidgetConfigActivity method updateWidgetConfig.
private void updateWidgetConfig() {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
RemoteViews views = new RemoteViews(getPackageName(), R.layout.small_widget_layout);
appWidgetManager.updateAppWidget(mAppWidgetId, views);
Intent resultValue = new Intent();
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
setResult(RESULT_OK, resultValue);
updateWidget();
finish();
}
use of android.appwidget.AppWidgetManager in project reark by reark.
the class WidgetService method updateWidget.
private void updateWidget(final int widgetId) {
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
RemoteViews remoteViews = new RemoteViews(getApplication().getPackageName(), R.layout.widget_layout);
remoteViews.setTextViewText(R.id.widget_layout_title, "Loading repository..");
appWidgetManager.updateAppWidget(widgetId, remoteViews);
clearSubscriptions();
subscriptions.add(getUserSettings.call().map(UserSettings::getSelectedRepositoryId).doOnNext(repositoryId -> Log.d(TAG, "Changed repository to " + repositoryId)).switchMap(fetchAndGetGitHubRepository::call).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribe(repository -> {
remoteViews.setTextViewText(R.id.widget_layout_title, repository.getName());
remoteViews.setTextViewText(R.id.widget_layout_stargazers, "stars: " + repository.getStargazersCount());
remoteViews.setTextViewText(R.id.widget_layout_forks, "forks: " + repository.getForksCount());
AppWidgetTarget widgetTarget = new AppWidgetTarget(WidgetService.this, remoteViews, R.id.widget_avatar_image_view, widgetId);
Glide.with(WidgetService.this).load(repository.getOwner().getAvatarUrl()).asBitmap().fitCenter().into(widgetTarget);
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}));
}
use of android.appwidget.AppWidgetManager in project muzei by romannurik.
the class AppWidgetUpdateTask method doInBackground.
@Override
protected Boolean doInBackground(Void... params) {
ComponentName widget = new ComponentName(mContext, MuzeiAppWidgetProvider.class);
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(mContext);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(widget);
if (appWidgetIds.length == 0) {
// No app widgets, nothing to do
Log.i(TAG, "No AppWidgets found");
return true;
}
String[] projection = new String[] { BaseColumns._ID, MuzeiContract.Artwork.COLUMN_NAME_TITLE, MuzeiContract.Artwork.COLUMN_NAME_BYLINE, MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND };
ContentResolver contentResolver = mContext.getContentResolver();
Cursor artwork = contentResolver.query(MuzeiContract.Artwork.CONTENT_URI, projection, null, null, null);
if (artwork == null || !artwork.moveToFirst()) {
Log.w(TAG, "No current artwork found");
if (artwork != null) {
artwork.close();
}
return false;
}
String title = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_TITLE));
String byline = artwork.getString(artwork.getColumnIndex(MuzeiContract.Artwork.COLUMN_NAME_BYLINE));
String contentDescription = !TextUtils.isEmpty(title) ? title : byline;
Uri imageUri = ContentUris.withAppendedId(MuzeiContract.Artwork.CONTENT_URI, artwork.getLong(artwork.getColumnIndex(BaseColumns._ID)));
boolean supportsNextArtwork = artwork.getInt(artwork.getColumnIndex(MuzeiContract.Sources.COLUMN_NAME_SUPPORTS_NEXT_ARTWORK_COMMAND)) != 0;
artwork.close();
// Update the widget(s) with the new artwork information
PackageManager packageManager = mContext.getPackageManager();
Intent launchIntent = packageManager.getLaunchIntentForPackage(mContext.getPackageName());
PendingIntent launchPendingIntent = PendingIntent.getActivity(mContext, 0, launchIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Intent nextArtworkIntent = new Intent(mContext, MuzeiAppWidgetProvider.class);
nextArtworkIntent.setAction(MuzeiAppWidgetProvider.ACTION_NEXT_ARTWORK);
PendingIntent nextArtworkPendingIntent = PendingIntent.getBroadcast(mContext, 0, nextArtworkIntent, PendingIntent.FLAG_UPDATE_CURRENT);
DisplayMetrics displayMetrics = mContext.getResources().getDisplayMetrics();
int smallWidgetHeight = mContext.getResources().getDimensionPixelSize(R.dimen.widget_small_height_breakpoint);
for (int widgetId : appWidgetIds) {
Bundle extras = appWidgetManager.getAppWidgetOptions(widgetId);
int widgetWidth = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, extras.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH), displayMetrics);
int widgetHeight = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, extras.getInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT), displayMetrics);
Bitmap image;
try {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeStream(contentResolver.openInputStream(imageUri), null, options);
int width = options.outWidth;
int height = options.outHeight;
options.inJustDecodeBounds = false;
options.inSampleSize = Math.min(ImageUtil.calculateSampleSize(width, widgetWidth), ImageUtil.calculateSampleSize(height, widgetHeight));
image = BitmapFactory.decodeStream(contentResolver.openInputStream(imageUri), null, options);
} catch (FileNotFoundException e) {
Log.e(TAG, "Could not find current artwork image", e);
return false;
}
// Even after using sample size to scale an image down, it might be larger than the
// maximum bitmap memory usage for widgets
Bitmap scaledImage = scaleBitmap(image, widgetWidth, widgetHeight);
@LayoutRes int widgetLayout = widgetHeight < smallWidgetHeight ? R.layout.widget_small : R.layout.widget;
RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), widgetLayout);
remoteViews.setContentDescription(R.id.widget_background, contentDescription);
remoteViews.setImageViewBitmap(R.id.widget_background, scaledImage);
remoteViews.setOnClickPendingIntent(R.id.widget_background, launchPendingIntent);
remoteViews.setOnClickPendingIntent(R.id.widget_next_artwork, nextArtworkPendingIntent);
if (supportsNextArtwork) {
remoteViews.setViewVisibility(R.id.widget_next_artwork, View.VISIBLE);
} else {
remoteViews.setViewVisibility(R.id.widget_next_artwork, View.GONE);
}
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
return true;
}
Aggregations