本文整理匯總了Java中android.widget.RemoteViews.setImageViewBitmap方法的典型用法代碼示例。如果您正苦於以下問題:Java RemoteViews.setImageViewBitmap方法的具體用法?Java RemoteViews.setImageViewBitmap怎麽用?Java RemoteViews.setImageViewBitmap使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.widget.RemoteViews
的用法示例。
在下文中一共展示了RemoteViews.setImageViewBitmap方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: updateWidget
import android.widget.RemoteViews; //導入方法依賴的package包/類
private void updateWidget() {
//獲取WidgetManager對象
AppWidgetManager awm = AppWidgetManager.getInstance(this);
//使用RemoteViews遠程更新控件
RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.process_widget);
if (mBitmap_icon != null) {
remoteViews.setImageViewBitmap(R.id.iv_icon, mBitmap_icon);
}
remoteViews.setTextViewText(R.id.tv_publis_time, mPublishTime);
remoteViews.setTextViewText(R.id.tv_temp, mCurrentTemp);
remoteViews.setTextViewText(R.id.tv_city, mCurrentCity);
//點擊小部件的進程總數和剩餘控件總數的textview處,跳轉到應用的主界麵處
Intent i = new Intent("android.intent.action.HOME");
i.addCategory("android.intent.category.DEFAULT");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.fl_icon, pendingIntent);
// 讓AppWidgetManager更新小部件的內容
ComponentName componentName = new ComponentName(this, MyAppWidgetProvider.class);
awm.updateAppWidget(componentName, remoteViews);
}
示例2: updateRemoteViews
import android.widget.RemoteViews; //導入方法依賴的package包/類
private void updateRemoteViews(RemoteViews remoteView) {
Song currentSong = mPlayer.getPlayingSong();
if (currentSong != null) {
remoteView.setTextViewText(R.id.text_view_name, currentSong.getDisplayName());
remoteView.setTextViewText(R.id.text_view_artist, currentSong.getArtist());
}
remoteView.setImageViewResource(R.id.image_view_play_toggle, isPlaying()
? R.drawable.ic_remote_view_pause : R.drawable.ic_remote_view_play);
Bitmap album = AlbumUtils.parseAlbum(getPlayingSong());
if (album == null) {
remoteView.setImageViewResource(R.id.image_view_album, R.mipmap.ic_launcher);
} else {
remoteView.setImageViewBitmap(R.id.image_view_album, album);
}
}
示例3: addWorkProfileBadge
import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
* Shows the work profile badge if it is needed.
*/
private void addWorkProfileBadge(RemoteViews view) {
Resources resources = mContext.getResources();
DisplayMetrics metrics = resources.getDisplayMetrics();
int size = dpToPx(WORK_PROFILE_BADGE_SIZE_DP, metrics);
int[] colors = new int[size * size];
// Create an immutable bitmap, so that it can not be reused for painting a badge into it.
Bitmap bitmap = Bitmap.createBitmap(colors, size, size, Bitmap.Config.ARGB_8888);
Drawable inputDrawable = new BitmapDrawable(resources, bitmap);
Drawable outputDrawable = ApiCompatibilityUtils.getUserBadgedDrawableForDensity(
mContext, inputDrawable, null /* badgeLocation */, metrics.densityDpi);
// The input bitmap is immutable, so the output drawable will be a different instance from
// the input drawable if the work profile badge was applied.
if (inputDrawable != outputDrawable && outputDrawable instanceof BitmapDrawable) {
view.setImageViewBitmap(
R.id.work_profile_badge, ((BitmapDrawable) outputDrawable).getBitmap());
view.setViewVisibility(R.id.work_profile_badge, View.VISIBLE);
}
}
示例4: fixIconImage
import android.widget.RemoteViews; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
if (remoteViews == null || notification.icon == 0) return;
if (!mNotificationCompat.isSystemLayout(remoteViews)) {
return;
}
try {
//noinspection deprecation
int id = R_Hide.id.icon.get();
//only fake small icon
if (!hasIconBitmap && notification.largeIcon == null) {
Drawable drawable = resources.getDrawable(notification.icon);
drawable.setLevel(notification.iconLevel);
Bitmap bitmap = drawableToBitMap(drawable);
remoteViews.setImageViewBitmap(id, bitmap);
//emui
if(OSUtils.getInstance().isEmui()) {
if (notification.largeIcon == null) {
notification.largeIcon = bitmap;
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: fixIconImage
import android.widget.RemoteViews; //導入方法依賴的package包/類
void fixIconImage(Resources resources, RemoteViews remoteViews, boolean hasIconBitmap, Notification notification) {
if (remoteViews == null) return;
if (!mNotificationCompat.isSystemLayout(remoteViews)) {
return;
}
try {
//noinspection deprecation
int id = R_Hide.id.icon.get();
//only fake small icon
if (!hasIconBitmap && notification.largeIcon == null) {
Drawable drawable = resources.getDrawable(notification.icon);
drawable.setLevel(notification.iconLevel);
Bitmap bitmap = drawableToBitMap(drawable);
remoteViews.setImageViewBitmap(id, bitmap);
}
if (Build.VERSION.SDK_INT >= 21) {
remoteViews.setInt(id, "setBackgroundColor", Color.TRANSPARENT);
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
remoteViews.setViewPadding(id, 0, 0, 0, 0);
}
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: getViewAt
import android.widget.RemoteViews; //導入方法依賴的package包/類
public RemoteViews getViewAt(int position) {
File file = new File(Environment.getExternalStoragePublicDirectory("/"+mContext.getResources().getString(R.string.app_name)), mWidgetItems.get(position).getId() +mContext.getResources().getString(R.string.jpg) );
BitmapFactory.Options options = new BitmapFactory.Options();
options.inPreferredConfig = Bitmap.Config.ARGB_8888;
Bitmap bitmap = BitmapFactory.decodeFile(file.getPath(), options);
RemoteViews rv = new RemoteViews(mContext.getPackageName(), R.layout.widget_item);
rv.setImageViewBitmap(R.id.widget_item,Bitmap.createScaledBitmap(bitmap, 450,300, false));
Bundle extras = new Bundle();
extras.putInt(StackWidgetProvider.EXTRA_ITEM, position);
Intent fillInIntent = new Intent();
fillInIntent.putExtras(extras);
rv.setOnClickFillInIntent(R.id.widget_item, fillInIntent);
try {
System.out.println(mContext.getResources().getString(R.string.Loading_view) + position);
Thread.sleep(500);
} catch (InterruptedException e) {
MyApplication.getInstance().trackException(e);
e.printStackTrace();
}
return rv;
}
示例7: defaultAppWidget
import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
* Initialize given widgets to default state, where we launch Music on
* default click and hide actions if service not running.
*/
private void defaultAppWidget(final Context context, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_big);
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false)), 1f));
linkButtons(context, appWidgetView);
pushUpdate(context, appWidgetIds, appWidgetView);
}
示例8: defaultAppWidget
import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
* Initialize given widgets to default state, where we launch Music on
* default click and hide actions if service not running.
*/
private void defaultAppWidget(final Context context, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic);
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, false)), 1f));
linkButtons(context, appWidgetView);
pushUpdate(context, appWidgetIds, appWidgetView);
}
示例9: createViews
import android.widget.RemoteViews; //導入方法依賴的package包/類
public RemoteViews createViews(Context context, Context pluginContext, RemoteViews contentView, boolean isBig) {
if (contentView == null) {
return null;
}
final boolean systemId = !NotificationUtils.isSystemLayout(contentView);
final PendIntentCompat pendIntentCompat = new PendIntentCompat(contentView);
// 根據點擊時間選擇布局(優化)
final int layoutId;
if (pendIntentCompat.findPendIntents() <= 0) {
// 如果就一個點擊事件,沒必要用複雜view
layoutId = R.layout.custom_notification_lite;
} else {
layoutId = R.layout.custom_notification;
}
// 代理view創建
RemoteViews remoteViews = new RemoteViews(context.getPackageName(), layoutId);
// 目標顯示的內容繪製成bitmap
final Bitmap bmp = RemoteViewsUtils.getInstance().createBitmap(pluginContext, contentView, isBig, systemId);
if (bmp == null) {
VLog.e(TAG, "bmp is null,contentView=" + contentView);
// 出錯也顯示空白的,要不改為係統布局?
// return null;
}
remoteViews.setImageViewBitmap(R.id.im_main, bmp);
// 點擊事件
if (layoutId == R.layout.custom_notification) {
// 根據舊view的點擊事件,設置區域點擊事件
pendIntentCompat.setPendIntent(remoteViews,
RemoteViewsUtils.getInstance().createView(context, remoteViews, isBig, systemId),
RemoteViewsUtils.getInstance().createView(pluginContext, contentView, isBig, systemId));
}
return remoteViews;
}
示例10: defaultAppWidget
import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
* Initialize given widgets to default state, where we launch Music on
* default click and hide actions if service not running.
*/
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_card);
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
linkButtons(context, appWidgetView);
pushUpdate(context, appWidgetIds, appWidgetView);
}
示例11: getViewAt
import android.widget.RemoteViews; //導入方法依賴的package包/類
@Override
public RemoteViews getViewAt(int position) {
RemoteViews remoteViews = new RemoteViews(mContext.getPackageName(), R.layout.queue_widget_listview_layout);
if (position <= getCount()) {
String songTitle = songs.get(position)._title;
ImageSize imageSize = new ImageSize(75, 75);
long songDurationInMillis = 0;
try {
songDurationInMillis = songs.get(position)._duration;
} catch (Exception e) {
}
remoteViews.setTextViewText(R.id.listViewSubText, songTitle);
remoteViews.setTextViewText(R.id.listViewRightSubText, MusicUtils.convertMillisToMinsSecs(songDurationInMillis));
Bitmap bitmap = ImageLoader.getInstance().loadImageSync(String.valueOf(MusicUtils.getAlbumArtUri(mApp.getService().getSongList().get(position)._albumId)), imageSize);
if (bitmap != null) {
remoteViews.setImageViewBitmap(R.id.listViewLeftIcon, bitmap);
} else {
remoteViews.setImageViewResource(R.id.listViewLeftIcon, R.mipmap.ic_launcher);
}
}
/* This intent latches itself onto the pendingIntentTemplate from
* LargeWidgetProvider.java and adds the extra "INDEX" argument to it. */
Intent fillInIntent = new Intent();
fillInIntent.putExtra("INDEX", position);
remoteViews.setOnClickFillInIntent(R.id.listViewParent, fillInIntent);
return remoteViews;
}
示例12: createBigRemoteViews
import android.widget.RemoteViews; //導入方法依賴的package包/類
private RemoteViews createBigRemoteViews(Bitmap bitmapBig, String title, String subtitle) {
if (bitmapBig == null) {
return null;
}
RemoteViews bigView = new RemoteViews(getPackageName(), R.layout.push_layout_3);
bigView.setImageViewBitmap(R.id.push_big_img, bitmapBig);
bigView.setTextViewText(R.id.push_big_img_title, title);
bigView.setTextViewText(R.id.push_big_img_title_subtitle, subtitle);
return bigView;
}
示例13: setCommonView
import android.widget.RemoteViews; //導入方法依賴的package包/類
private void setCommonView(RemoteViews view) {
final String name = currentSong.getTitle();
final String arts = currentSong.getArtist();
final Bitmap cover = createCover(currentSong.getAlbum_path());
view.setImageViewBitmap(R.id.play_notify_cover, cover);
view.setTextViewText(R.id.play_notify_name, name);
view.setTextViewText(R.id.play_notify_arts, arts + " - " + name);
view.setImageViewResource(R.id.play_notify_play,
play ? R.drawable.ic_pause
: R.drawable.ic_play_arrow);
}
示例14: performUpdate
import android.widget.RemoteViews; //導入方法依賴的package包/類
/**
* Update all active widget instances by pushing changes
*/
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_small);
final boolean isPlaying = service.isPlaying();
final Song song = service.getCurrentSong();
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
} else {
if (TextUtils.isEmpty(song.title) || TextUtils.isEmpty(song.artistName)) {
appWidgetView.setTextViewText(R.id.text_separator, "");
} else {
appWidgetView.setTextViewText(R.id.text_separator, "•");
}
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
appWidgetView.setTextViewText(R.id.title, song.title);
appWidgetView.setTextViewText(R.id.text, song.artistName);
}
// Set correct drawable for pause state
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// Link actions buttons to intents
linkButtons(service, appWidgetView);
// Load the album cover async and push the update on completion
final Context appContext = service.getApplicationContext();
final int widgetImageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_small_image_size);
service.runOnUiThread(new Runnable() {
@Override
public void run() {
if (target != null) {
Glide.clear(target);
}
target = SongGlideRequest.Builder.from(Glide.with(appContext), song)
.checkIgnoreMediaStore(appContext)
.asBitmap().build()
.into(new SimpleTarget<Bitmap>(widgetImageSize, widgetImageSize) {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
update(resource);
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
update(null);
}
private void update(@Nullable Bitmap bitmap) {
appWidgetView.setViewVisibility(R.id.image, View.VISIBLE);
if (bitmap == null) {
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
} else {
appWidgetView.setImageViewBitmap(R.id.image, bitmap);
}
pushUpdate(appContext, appWidgetIds, appWidgetView);
}
});
}
});
}
示例15: onUpdate
import android.widget.RemoteViews; //導入方法依賴的package包/類
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
for (int widgetId : appWidgetIds) {
RemoteViews remoteViews = new RemoteViews(context.getPackageName(),
R.layout.extensive_widget);
Intent intent = new Intent(context, AlarmReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context,
0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setOnClickPendingIntent(R.id.widgetButtonRefresh, pendingIntent);
Intent intent2 = new Intent(context, MainActivity.class);
PendingIntent pendingIntent2 = PendingIntent.getActivity(context, 0, intent2, 0);
remoteViews.setOnClickPendingIntent(R.id.widgetRoot, pendingIntent2);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
Weather widgetWeather = new Weather();
if(!sp.getString("lastToday", "").equals("")) {
widgetWeather = parseWidgetJson(sp.getString("lastToday", ""), context);
}
else {
try {
pendingIntent2.send();
} catch (PendingIntent.CanceledException e) {
e.printStackTrace();
}
return;
}
DateFormat timeFormat = android.text.format.DateFormat.getTimeFormat(context);
remoteViews.setTextViewText(R.id.widgetCity, widgetWeather.getCity() + ", " + widgetWeather.getCountry());
remoteViews.setTextViewText(R.id.widgetTemperature, widgetWeather.getTemperature());
remoteViews.setTextViewText(R.id.widgetDescription, widgetWeather.getDescription());
remoteViews.setTextViewText(R.id.widgetWind, widgetWeather.getWind());
remoteViews.setTextViewText(R.id.widgetPressure, widgetWeather.getPressure());
remoteViews.setTextViewText(R.id.widgetHumidity, context.getString(R.string.humidity) + ": " + widgetWeather.getHumidity() + " %");
remoteViews.setTextViewText(R.id.widgetSunrise, context.getString(R.string.sunrise) + ": " + timeFormat.format(widgetWeather.getSunrise())); //
remoteViews.setTextViewText(R.id.widgetSunset, context.getString(R.string.sunset) + ": " + timeFormat.format(widgetWeather.getSunset()));
remoteViews.setTextViewText(R.id.widgetLastUpdate, widgetWeather.getLastUpdated());
remoteViews.setImageViewBitmap(R.id.widgetIcon, getWeatherIcon(widgetWeather.getIcon(), context));
appWidgetManager.updateAppWidget(widgetId, remoteViews);
}
}