Search in sources :

Example 11 with AppWidgetManager

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();
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent)

Example 12 with AppWidgetManager

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);
}
Also used : AppWidgetManager(android.appwidget.AppWidgetManager) ComponentName(android.content.ComponentName)

Example 13 with AppWidgetManager

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();
}
Also used : RemoteViews(android.widget.RemoteViews) AppWidgetManager(android.appwidget.AppWidgetManager) Intent(android.content.Intent)

Example 14 with AppWidgetManager

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);
    }));
}
Also used : RemoteViews(android.widget.RemoteViews) R(io.reark.rxgithubapp.R) UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings) Log(io.reark.reark.utils.Log) Service(android.app.Service) AndroidSchedulers(rx.android.schedulers.AndroidSchedulers) Intent(android.content.Intent) IBinder(android.os.IBinder) AppWidgetManager(android.appwidget.AppWidgetManager) Inject(javax.inject.Inject) CompositeSubscription(rx.subscriptions.CompositeSubscription) Glide(com.bumptech.glide.Glide) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) RxGitHubApp(io.reark.rxgithubapp.advanced.RxGitHubApp) Schedulers(rx.schedulers.Schedulers) DataFunctions(io.reark.rxgithubapp.shared.data.DataFunctions) RemoteViews(android.widget.RemoteViews) AppWidgetTarget(com.bumptech.glide.request.target.AppWidgetTarget) UserSettings(io.reark.rxgithubapp.shared.pojo.UserSettings) AppWidgetManager(android.appwidget.AppWidgetManager)

Example 15 with AppWidgetManager

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;
}
Also used : Bundle(android.os.Bundle) AppWidgetManager(android.appwidget.AppWidgetManager) FileNotFoundException(java.io.FileNotFoundException) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Cursor(android.database.Cursor) Uri(android.net.Uri) DisplayMetrics(android.util.DisplayMetrics) ContentResolver(android.content.ContentResolver) Bitmap(android.graphics.Bitmap) RemoteViews(android.widget.RemoteViews) LayoutRes(android.support.annotation.LayoutRes) PackageManager(android.content.pm.PackageManager) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent) BitmapFactory(android.graphics.BitmapFactory)

Aggregations

AppWidgetManager (android.appwidget.AppWidgetManager)51 ComponentName (android.content.ComponentName)32 RemoteViews (android.widget.RemoteViews)25 Intent (android.content.Intent)20 PendingIntent (android.app.PendingIntent)12 Bundle (android.os.Bundle)12 SharedPreferences (android.content.SharedPreferences)7 Context (android.content.Context)5 View (android.view.View)4 Uri (android.net.Uri)3 AppWidgetProvider (android.appwidget.AppWidgetProvider)2 PackageManager (android.content.pm.PackageManager)2 Cursor (android.database.Cursor)2 Button (android.widget.Button)2 EditText (android.widget.EditText)2 TextView (android.widget.TextView)2 Account (android.accounts.Account)1 Service (android.app.Service)1 AppWidgetProviderInfo (android.appwidget.AppWidgetProviderInfo)1 ContentResolver (android.content.ContentResolver)1