我工作的实施番茄工作法的应用程序的Android Wear。
I'm working on implementation of Pomodoro app for Android Wear.
我想打类似于标准定时器UI / UX ,我想这是实现使用显示/更新通知与计时器标题,让我展示的通知,并从服务定期更新的:
I want to make similar to standard timer UI/UX, I guess it's implemented using displaying/updating notification with timer as title, so I'm showing notification and updating it periodically from Service:
private void updateNotification() {
Intent stopActionIntent = new Intent(this, PomodoroActivity.class);
stopActionIntent.setAction(PomodoroActivity.ACTION_STOP);
PendingIntent stopActionPendingIntent = PendingIntent.getActivity(this, 0, stopActionIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Action stopAction = new NotificationCompat.Action.Builder(
R.drawable.ic_stop,
getString(R.string.stop_pomodoro),
stopActionPendingIntent)
.build();
Notification notification = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.bg_pomodoro_timer))
.setContentTitle(convertDiffToTimer(System.currentTimeMillis(), timerDeadlineMs))
.setPriority(Notification.PRIORITY_MAX)
.setOngoing(true)
.extend(new NotificationCompat.WearableExtender().addAction(stopAction))
.build();
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
notificationManager.notify(1, notification);
}
不愉快的问题,这样的解决方案闪烁notificaiton的。
Unpleasure problem with such solution is blinking of notificaiton.
任何想法如何逃脱闪烁?或者,也许其他的方式来实现目标的行为呢?
Any ideas how escape blinking? Or maybe other way to achieve target behaviour?
要更新正在进行/现有通知 -
To update ongoing/existing notification -
使用的生成器通知的相同编号
使用 .setOnlyAlertOnce(真)
Use Same Id
of Notification in Builder
Use .setOnlyAlertOnce(true)
NotificationCompat.Builder notificationBuilder;
公共无效generateNotificationForTimer(字符串timeInString,布尔isFirstTime){
如果(isFirstTime){
notificationBuilder =新NotificationCompat.Builder(本)
.setStyle(新NotificationCompat.BigPictureStyle())
.setOnlyAlertOnce(真)
.setContentTitle(计时器通知演示)
.setContentText(时间 - + timeInString)
.setSmallIcon(R.drawable.common_signin_btn_icon_dark);
NotificationManagerCompat.from(本).notify(110,notificationBuilder.build());
} 其他 {
notificationBuilder.setContentText(timeInString);
NotificationManagerCompat.from(本).notify(110,notificationBuilder.build());
}
}
NotificationCompat.Builder notificationBuilder;
public void generateNotificationForTimer(String timeInString, boolean isFirstTime) {
if (isFirstTime) {
notificationBuilder = new NotificationCompat.Builder(this)
.setStyle(new NotificationCompat.BigPictureStyle())
.setOnlyAlertOnce(true)
.setContentTitle("Timer Notification Demo")
.setContentText("Time - " + timeInString)
.setSmallIcon(R.drawable.common_signin_btn_icon_dark);
NotificationManagerCompat.from(this).notify(110, notificationBuilder.build());
} else {
notificationBuilder.setContentText(timeInString);
NotificationManagerCompat.from(this).notify(110, notificationBuilder.build());
}
}