public void UpdateNotification(boolean pause_or_play_only){ if (Aki_isPlaying()) { remoteViews.setImageViewBitmap(R.id.notification_iv_play, BitmapFactory.decodeResource(getResources(),R.drawable.iv_pause_grey)); }else remoteViews.setImageViewBitmap(R.id.notification_iv_play, BitmapFactory.decodeResource(getResources(),R.drawable.iv_play_grey)); if (!pause_or_play_only) { remoteViews.setTextViewText(R.id.notification_top_song, AkiCurTitle); remoteViews.setTextViewText(R.id.notification_top_singer, AkiCurArtist); mAkiModel.AkiAlbBitmap(bitmapCallBack,AkiCurAlbumPath); Log.d(TAG, "UpdateNotification: 更新通知栏当前专辑封面"+AkiCurAlbumPath); }else { //AkiBuilder.setCustomBigContentView(remoteViews); AkiBuilder.setCustomContentView(remoteViews); AkiNotification = AkiBuilder.build(); AkiNotificationManager.notify(NOTIFICATION_ID,AkiNotification); } }用上面的方法改写这段代码
时间: 2024-02-07 07:01:52 浏览: 205
我可以看到这段代码是 Java 语言编写的 Android 应用程序的通知栏更新方法。根据您的要求,我将对其进行修改,但是需要您提供更多上下文和明确的需求。
以下是一种可能的修改方式,该方式将此方法作为类的一部分,并将方法参数更改为更清晰的名称:
```java
public class AkiNotificationManager {
private static final String TAG = "AkiNotificationManager";
private static final int NOTIFICATION_ID = 1;
private NotificationManager mAkiNotificationManager;
private Notification.Builder mAkiBuilder;
private RemoteViews mAkiRemoteViews;
private AkiModel mAkiModel;
private String mAkiCurTitle;
private String mAkiCurArtist;
private String mAkiCurAlbumPath;
public AkiNotificationManager(Context context, AkiModel akiModel) {
mAkiModel = akiModel;
mAkiNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
mAkiBuilder = new Notification.Builder(context);
mAkiRemoteViews = new RemoteViews(context.getPackageName(), R.layout.notification_layout);
mAkiBuilder.setCustomContentView(mAkiRemoteViews);
mAkiBuilder.setSmallIcon(R.drawable.ic_music_note);
mAkiBuilder.setAutoCancel(false);
}
public void updateNotification(boolean isPlaying, boolean updateAlbum) {
if (isPlaying) {
mAkiRemoteViews.setImageViewBitmap(R.id.notification_iv_play, BitmapFactory.decodeResource(getResources(), R.drawable.iv_pause_grey));
} else {
mAkiRemoteViews.setImageViewBitmap(R.id.notification_iv_play, BitmapFactory.decodeResource(getResources(), R.drawable.iv_play_grey));
}
if (updateAlbum) {
mAkiRemoteViews.setTextViewText(R.id.notification_top_song, mAkiCurTitle);
mAkiRemoteViews.setTextViewText(R.id.notification_top_singer, mAkiCurArtist);
mAkiModel.getAlbumBitmap(bitmapCallBack, mAkiCurAlbumPath);
Log.d(TAG, "updateNotification: Updating Album Art: " + mAkiCurAlbumPath);
}
mAkiBuilder.setCustomContentView(mAkiRemoteViews);
mAkiNotificationManager.notify(NOTIFICATION_ID, mAkiBuilder.build());
}
private final BitmapCallBack bitmapCallBack = new BitmapCallBack() {
@Override
public void setBitmap(Bitmap bitmap) {
mAkiRemoteViews.setImageViewBitmap(R.id.notification_iv_album, bitmap);
mAkiBuilder.setCustomContentView(mAkiRemoteViews);
mAkiNotificationManager.notify(NOTIFICATION_ID, mAkiBuilder.build());
}
};
public void setCurSong(String title, String artist, String albumPath) {
mAkiCurTitle = title;
mAkiCurArtist = artist;
mAkiCurAlbumPath = albumPath;
}
}
```
以上代码包含了一个名为 `AkiNotificationManager` 的类,该类包含了一个在构造函数中初始化的 `NotificationManager`,并且该类包含了一个 `updateNotification` 方法,该方法接受两个参数:一个布尔值,用于指示当前是否正在播放,以及另一个布尔值,用于指示是否需要更新专辑封面。此外,该类还包含一个 `setCurSong` 方法,用于设置当前播放的歌曲信息。
请注意,此代码仅用于演示目的,并且可能需要进一步修改,以符合您的具体需求。
阅读全文