Reputation: 935
I have home screen widget which have one chronometer as RemoteViews item. I need this chronometer to countdown from some time in the future. Chronometer works, but I have noticed some strange time formatings on some devices. For example, if there is 10 minutes and 5 seconds remaining, I have following outputs:
Huawei Mate 10 Lite (Android Oreo - API 26)
-10:05
Huawei G7, with Lollipop (API 22)
00:-605
- total remaining time here is displayed as number of seconds.
My question: is there any way that I can provide my formating, so that result be same on all devices.
NOTE: I need this for chronometer in homescreen widget, not inside of an activity or a fragment.
Edit: Widget is refreshed from AlarmManager. On BroadcastReceiver I have following code to update widget.
protected void updateCountdownTimer(RemoteViews remoteViews, int index) {
Calendar calendar = Calendar.getInstance();
List<Time> timeList;
if (index == -1) {
calendar.add(Calendar.DATE, 1);
TimesProvider.getProvider().setCurrentDate(calendar);
index = 0;
}
timeList = TimesProvider.getProvider().getTimes();
Time time = timeList.get(index);
calendar.set(Calendar.HOUR_OF_DAY, time.getHour());
calendar.set(Calendar.MINUTE, time.getMinute());
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
remoteViews.setChronometer(R.id.chronometer, SystemClock.elapsedRealtime() + calendar.getTimeInMillis() - System.currentTimeMillis(), null, true);
remoteViews.setTextColor(R.id.chronometer, Color.CYAN);
}
Upvotes: 0
Views: 176