use of android.widget.RemoteViews in project cw-advandroid by commonsguy.
the class Plugin method onReceive.
@Override
public void onReceive(Context ctxt, Intent i) {
if (ACTION_CALL_FOR_PLUGINS.equals(i.getAction())) {
Intent registration = new Intent(ACTION_REGISTER_PLUGIN);
registration.setPackage(HOST_PACKAGE);
registration.putExtra(EXTRA_COMPONENT, new ComponentName(ctxt, getClass()));
ctxt.sendBroadcast(registration);
} else if (ACTION_CALL_FOR_CONTENT.equals(i.getAction())) {
RemoteViews rv = new RemoteViews(ctxt.getPackageName(), R.layout.plugin);
Intent update = new Intent(ACTION_DELIVER_CONTENT);
update.setPackage(HOST_PACKAGE);
update.putExtra(EXTRA_CONTENT, rv);
ctxt.sendBroadcast(update);
}
}
use of android.widget.RemoteViews in project android_frameworks_base by AOSPA.
the class AppWidgetHost method createView.
/**
* Create the AppWidgetHostView for the given widget.
* The AppWidgetHost retains a pointer to the newly-created View.
*/
public final AppWidgetHostView createView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
AppWidgetHostView view = onCreateView(context, appWidgetId, appWidget);
view.setOnClickHandler(mOnClickHandler);
view.setAppWidget(appWidgetId, appWidget);
synchronized (mViews) {
mViews.put(appWidgetId, view);
}
RemoteViews views;
try {
views = sService.getAppWidgetViews(mContextOpPackageName, appWidgetId);
} catch (RemoteException e) {
throw new RuntimeException("system server dead?", e);
}
view.updateAppWidget(views);
return view;
}
use of android.widget.RemoteViews in project NetGuard by M66B.
the class WidgetLockdown method update.
private static void update(int[] appWidgetIds, AppWidgetManager appWidgetManager, Context context) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
boolean lockdown = prefs.getBoolean("lockdown", false);
try {
try {
PendingIntent pi = PendingIntent.getBroadcast(context, 0, new Intent(lockdown ? WidgetAdmin.INTENT_LOCKDOWN_OFF : WidgetAdmin.INTENT_LOCKDOWN_ON), PendingIntent.FLAG_UPDATE_CURRENT);
for (int id : appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widgetlockdown);
views.setOnClickPendingIntent(R.id.ivEnabled, pi);
views.setImageViewResource(R.id.ivEnabled, lockdown ? R.drawable.ic_lock_outline_white_24dp : R.drawable.ic_lock_open_white_24dp);
appWidgetManager.updateAppWidget(id, views);
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
} catch (Throwable ex) {
Log.e(TAG, ex.toString() + "\n" + Log.getStackTraceString(ex));
}
}
use of android.widget.RemoteViews 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;
}
use of android.widget.RemoteViews in project android_frameworks_base by crdroidandroid.
the class RemoteViewsTest method clone_repeatedly.
@Test
public void clone_repeatedly() {
RemoteViews original = new RemoteViews(mPackage, R.layout.remote_views_test);
original.clone();
original.clone();
original.apply(mContext, mContainer);
}
Aggregations