Java Code Examples for android.widget.RemoteViews#setChronometer()
The following examples show how to use
android.widget.RemoteViews#setChronometer() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TrackWidgetProvider.java From mytracks with Apache License 2.0 | 6 votes |
/** * Updates total time. * * @param context the context * @param remoteViews the remote views * @param ids the item's ids * @param tripStatistics the trip statistics */ private static void updateTotalTime(Context context, RemoteViews remoteViews, int[] ids, TripStatistics tripStatistics, boolean isRecording, boolean isPaused) { if (isRecording && !isPaused && tripStatistics != null) { long time = tripStatistics.getTotalTime() + System.currentTimeMillis() - tripStatistics.getStopTime(); remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime() - time, null, true); remoteViews.setViewVisibility(ids[1], View.GONE); remoteViews.setViewVisibility(ids[2], View.GONE); remoteViews.setViewVisibility(ids[3], View.VISIBLE); } else { remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime(), null, false); remoteViews.setViewVisibility(ids[1], View.VISIBLE); remoteViews.setViewVisibility(ids[2], View.GONE); remoteViews.setViewVisibility(ids[3], View.GONE); String totalTime = tripStatistics == null ? context.getString(R.string.value_unknown) : StringUtils.formatElapsedTime(tripStatistics.getTotalTime()); remoteViews.setTextViewText(ids[0], context.getString(R.string.stats_total_time)); remoteViews.setTextViewText(ids[1], totalTime); } }
Example 2
Source File: TrackWidgetProvider.java From mytracks with Apache License 2.0 | 5 votes |
/** * Sets a widget item. * * @param context the context * @param remoteViews the remote view * @param ids the item's ids * @param value the item value * @param tripStatistics the trip statistics * @param metricUnits true to use metric units * @param reportSpeed try to report speed */ private static void setItem(Context context, RemoteViews remoteViews, int[] ids, int value, TripStatistics tripStatistics, boolean isRecording, boolean isPaused, boolean metricUnits, boolean reportSpeed) { switch (value) { case 0: updateDistance(context, remoteViews, ids, tripStatistics, metricUnits); break; case 1: updateTotalTime(context, remoteViews, ids, tripStatistics, isRecording, isPaused); break; case 2: updateAverageSpeed(context, remoteViews, ids, tripStatistics, metricUnits, reportSpeed); break; case 3: updateMovingTime(context, remoteViews, ids, tripStatistics); break; case 4: updateAverageMovingSpeed( context, remoteViews, ids, tripStatistics, metricUnits, reportSpeed); break; default: updateDistance(context, remoteViews, ids, tripStatistics, metricUnits); break; } if (value != 1) { remoteViews.setViewVisibility(ids[1], View.VISIBLE); remoteViews.setViewVisibility(ids[2], View.VISIBLE); remoteViews.setViewVisibility(ids[3], View.GONE); remoteViews.setChronometer(ids[3], SystemClock.elapsedRealtime(), null, false); } }
Example 3
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update2x2(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 130f / 160f); int w = size.width; int h = size.height; if (w <= 0 || h <= 0) return; float scale = w / 10.5f; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_2x2); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, w / 2, h / 2, w / 2, h / 2); LocalDate date = LocalDate.now(); LocalDateTime[] daytimes = {times.getTime(date, Vakit.FAJR.ordinal()), times.getTime(date, Vakit.SUN.ordinal()), times.getTime(date, Vakit.DHUHR.ordinal()), times.getTime(date, Vakit.ASR.ordinal()), times.getTime(date, Vakit.MAGHRIB.ordinal()), times.getTime(date, Vakit.ISHAA.ordinal())}; remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times)); remoteViews.setTextViewText(R.id.city, times.getName()); remoteViews.setTextColor(R.id.city, theme.textcolor); int current = times.getCurrentTime(); int next = current + 1; int indicator = current; if ("next".equals(Preferences.VAKIT_INDICATOR_TYPE.get())) indicator = indicator + 1; int[] idsText = {R.id.fajrText, R.id.sunText, R.id.zuhrText, R.id.asrText, R.id.maghribText, R.id.ishaaText}; int[] ids = {R.id.fajr, R.id.sun, R.id.zuhr, R.id.asr, R.id.maghrib, R.id.ishaa}; boolean rtl = Utils.isRTL(context); for (Vakit v : Vakit.values()) { int i = v.ordinal(); remoteViews.setTextViewTextSize(idsText[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f); remoteViews.setTextViewTextSize(ids[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f); remoteViews.setTextColor(idsText[i], theme.textcolor); remoteViews.setTextColor(ids[i], theme.textcolor); String name = Vakit.getByIndex(i).getString(); String time = LocaleUtils.formatTime(daytimes[i].toLocalTime()); if (Preferences.CLOCK_12H.get()) { time = time.replace(" ", "<sup><small>") + "</small></sup>"; } if (Preferences.SHOW_ALT_WIDGET_HIGHLIGHT.get()) { if (v.ordinal() == indicator) { name = "<b><i>" + name + "</i></b>"; time = "<b><i>" + time + "</i></b>"; } remoteViews.setInt(idsText[i], "setBackgroundColor", 0); remoteViews.setInt(ids[i], "setBackgroundColor", 0); } else { if (v.ordinal() == indicator) { remoteViews.setInt(idsText[i], "setBackgroundColor", theme.hovercolor); remoteViews.setInt(ids[i], "setBackgroundColor", theme.hovercolor); } else { remoteViews.setInt(idsText[i], "setBackgroundColor", 0); remoteViews.setInt(ids[i], "setBackgroundColor", 0); } } remoteViews.setTextViewText(idsText[i], Html.fromHtml(!rtl ? name : time)); remoteViews.setTextViewText(ids[i], Html.fromHtml(!rtl ? time : name)); remoteViews.setViewPadding(idsText[i], (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0, (int) scale / 4, 0); remoteViews.setViewPadding(ids[i], 0, 0, (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0); } remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f); remoteViews.setTextColor(R.id.countdown, theme.textcolor); remoteViews.setViewPadding(R.id.city, (int) scale / 2, 0, (int) scale / 2, (int) scale / 4); if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS)) remoteViews .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true); else { String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false); remoteViews.setString(R.id.countdown, "setFormat", txt); remoteViews.setChronometer(R.id.countdown, 0, txt, false); } remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f); appWidgetManager.updateAppWidget(widgetId, remoteViews); }
Example 4
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1); int s = size.width; if (s <= 0) return; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_1x1); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, s / 2, s / 2, s / 2, s / 2); int next = times.getNextTime(); String name = times.getName(); remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times)); if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS)) remoteViews .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true); else { String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false); remoteViews.setString(R.id.countdown, "setFormat", txt); remoteViews.setChronometer(R.id.countdown, 0, txt, false); } remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, s / 4f); remoteViews.setTextViewText(R.id.city, name); remoteViews.setTextViewText(R.id.time, Vakit.getByIndex(next - 1).getString()); remoteViews.setTextColor(R.id.city, theme.textcolor); remoteViews.setTextColor(R.id.countdown, theme.textcolor); remoteViews.setTextColor(R.id.time, theme.textcolor); remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, (float) Math.min(s / 5f, 1.5 * s / name.length())); remoteViews.setTextViewTextSize(R.id.time, TypedValue.COMPLEX_UNIT_PX, s / 5f); remoteViews.setViewPadding(R.id.countdown, 0, -s / 16, 0, -s / 16); appWidgetManager.updateAppWidget(widgetId, remoteViews); }
Example 5
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update2x2(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 130f / 160f); int w = size.width; int h = size.height; if (w <= 0 || h <= 0) return; float scale = w / 10.5f; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_2x2); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, w / 2, h / 2, w / 2, h / 2); LocalDate date = LocalDate.now(); LocalDateTime[] daytimes = {times.getTime(date, Vakit.FAJR.ordinal()), times.getTime(date, Vakit.SUN.ordinal()), times.getTime(date, Vakit.DHUHR.ordinal()), times.getTime(date, Vakit.ASR.ordinal()), times.getTime(date, Vakit.MAGHRIB.ordinal()), times.getTime(date, Vakit.ISHAA.ordinal())}; remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times)); remoteViews.setTextViewText(R.id.city, times.getName()); remoteViews.setTextColor(R.id.city, theme.textcolor); int current = times.getCurrentTime(); int next = current + 1; int indicator = current; if ("next".equals(Preferences.VAKIT_INDICATOR_TYPE.get())) indicator = indicator + 1; int[] idsText = {R.id.fajrText, R.id.sunText, R.id.zuhrText, R.id.asrText, R.id.maghribText, R.id.ishaaText}; int[] ids = {R.id.fajr, R.id.sun, R.id.zuhr, R.id.asr, R.id.maghrib, R.id.ishaa}; boolean rtl = Utils.isRTL(context); for (Vakit v : Vakit.values()) { int i = v.ordinal(); remoteViews.setTextViewTextSize(idsText[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f); remoteViews.setTextViewTextSize(ids[i], TypedValue.COMPLEX_UNIT_PX, scale * 1f); remoteViews.setTextColor(idsText[i], theme.textcolor); remoteViews.setTextColor(ids[i], theme.textcolor); String name = Vakit.getByIndex(i).getString(); String time = LocaleUtils.formatTime(daytimes[i].toLocalTime()); if (Preferences.CLOCK_12H.get()) { time = time.replace(" ", "<sup><small>") + "</small></sup>"; } if (Preferences.SHOW_ALT_WIDGET_HIGHLIGHT.get()) { if (v.ordinal() == indicator) { name = "<b><i>" + name + "</i></b>"; time = "<b><i>" + time + "</i></b>"; } remoteViews.setInt(idsText[i], "setBackgroundColor", 0); remoteViews.setInt(ids[i], "setBackgroundColor", 0); } else { if (v.ordinal() == indicator) { remoteViews.setInt(idsText[i], "setBackgroundColor", theme.hovercolor); remoteViews.setInt(ids[i], "setBackgroundColor", theme.hovercolor); } else { remoteViews.setInt(idsText[i], "setBackgroundColor", 0); remoteViews.setInt(ids[i], "setBackgroundColor", 0); } } remoteViews.setTextViewText(idsText[i], Html.fromHtml(!rtl ? name : time)); remoteViews.setTextViewText(ids[i], Html.fromHtml(!rtl ? time : name)); remoteViews.setViewPadding(idsText[i], (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0, (int) scale / 4, 0); remoteViews.setViewPadding(ids[i], 0, 0, (int) ((Preferences.CLOCK_12H.get() ? 1.25 : 1.75) * scale), 0); } remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f); remoteViews.setTextColor(R.id.countdown, theme.textcolor); remoteViews.setViewPadding(R.id.city, (int) scale / 2, 0, (int) scale / 2, (int) scale / 4); if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS)) remoteViews .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true); else { String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false); remoteViews.setString(R.id.countdown, "setFormat", txt); remoteViews.setChronometer(R.id.countdown, 0, txt, false); } remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, scale * 1.3f); appWidgetManager.updateAppWidget(widgetId, remoteViews); }
Example 6
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 4 votes |
static void update1x1(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); Times times = WidgetUtils.getTimes(widgetId); if (times == null) { WidgetUtils.showNoCityWidget(context, appWidgetManager, widgetId); return; } WidgetUtils.Size size = WidgetUtils.getSize(context, appWidgetManager, widgetId, 1); int s = size.width; if (s <= 0) return; RemoteViews remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget_1x1); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, s / 2, s / 2, s / 2, s / 2); int next = times.getNextTime(); String name = times.getName(); remoteViews.setOnClickPendingIntent(R.id.widget_layout, TimesFragment.getPendingIntent(times)); if (Preferences.COUNTDOWN_TYPE.get().equals(Preferences.COUNTDOWN_TYPE_SHOW_SECONDS)) remoteViews .setChronometer(R.id.countdown, times.getTime(LocalDate.now(), next).toDateTime().getMillis() - (System.currentTimeMillis() - SystemClock.elapsedRealtime()), null, true); else { String txt = LocaleUtils.formatPeriod(LocalDateTime.now(), times.getTime(LocalDate.now(), next), false); remoteViews.setString(R.id.countdown, "setFormat", txt); remoteViews.setChronometer(R.id.countdown, 0, txt, false); } remoteViews.setTextViewTextSize(R.id.countdown, TypedValue.COMPLEX_UNIT_PX, s / 4f); remoteViews.setTextViewText(R.id.city, name); remoteViews.setTextViewText(R.id.time, Vakit.getByIndex(next - 1).getString()); remoteViews.setTextColor(R.id.city, theme.textcolor); remoteViews.setTextColor(R.id.countdown, theme.textcolor); remoteViews.setTextColor(R.id.time, theme.textcolor); remoteViews.setTextViewTextSize(R.id.city, TypedValue.COMPLEX_UNIT_PX, (float) Math.min(s / 5f, 1.5 * s / name.length())); remoteViews.setTextViewTextSize(R.id.time, TypedValue.COMPLEX_UNIT_PX, s / 5f); remoteViews.setViewPadding(R.id.countdown, 0, -s / 16, 0, -s / 16); appWidgetManager.updateAppWidget(widgetId, remoteViews); }