Java Code Examples for android.widget.RemoteViews#setTextViewTextSize()
The following examples show how to use
android.widget.RemoteViews#setTextViewTextSize() .
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: SunPosLayout_3X1_0.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); themeViewsAzimuthElevationText(context, views, theme); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.info_sun_azimuth_rising, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.info_sun_elevation_atnoon, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.info_sun_azimuth_setting, TypedValue.COMPLEX_UNIT_DIP, timeSize); } colors = new LightMapView.LightMapColors(); if (theme.getBackground() == SuntimesTheme.ThemeBackground.LIGHT) colors.initDefaultLight(context); else colors.initDefaultDark(context); colors.colorDay = theme.getDayColor(); colors.colorCivil = theme.getCivilColor(); colors.colorNautical = theme.getNauticalColor(); colors.colorAstro = theme.getAstroColor(); colors.colorNight = theme.getNightColor(); }
Example 2
Source File: SunPosLayout.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
protected void themeViewsRightAscDeclinationText(Context context, @NonNull RemoteViews views, @NonNull SuntimesTheme theme) { int textColor = theme.getTextColor(); views.setTextColor(R.id.info_sun_rightascension_current_label, textColor); views.setTextColor(R.id.info_sun_declination_current_label, textColor); views.setTextColor(R.id.info_sun_rightascension_current, textColor); views.setTextColor(R.id.info_sun_declination_current, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.info_sun_rightascension_current_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.info_sun_declination_current_label, TypedValue.COMPLEX_UNIT_DIP, textSize); float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.info_sun_rightascension_current, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.info_sun_declination_current, TypedValue.COMPLEX_UNIT_DIP, timeSize); } }
Example 3
Source File: MoonLayout_1x1_7.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); highlightColor = theme.getTimeColor(); suffixColor = theme.getTimeSuffixColor(); int textColor = theme.getTextColor(); views.setTextColor(R.id.info_moon_distance_current_label, textColor); views.setTextColor(R.id.info_moon_distance_current, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.info_moon_distance_current_label, TypedValue.COMPLEX_UNIT_DIP, textSize); float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.info_moon_distance_current, TypedValue.COMPLEX_UNIT_DIP, timeSize); } }
Example 4
Source File: MoonLayout.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
protected void themeViewsMoonRiseSetText(Context context, RemoteViews views, SuntimesTheme theme) { int moonriseColor = theme.getMoonriseTextColor(); int suffixColor = theme.getTimeSuffixColor(); views.setTextColor(R.id.text_time_moonrise_suffix, suffixColor); views.setTextColor(R.id.text_time_moonrise, moonriseColor); int moonsetColor = theme.getMoonsetTextColor(); views.setTextColor(R.id.text_time_moonset_suffix, suffixColor); views.setTextColor(R.id.text_time_moonset, moonsetColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float timeSize = theme.getTimeSizeSp(); float suffSize = theme.getTimeSuffixSizeSp(); views.setTextViewTextSize(R.id.text_time_moonrise_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize); views.setTextViewTextSize(R.id.text_time_moonrise, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.text_time_moonset, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.text_time_moonset_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize); } }
Example 5
Source File: MoonLayout_1x1_4.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); themeViewsMoonPhase(context, views, theme); themeViewsMoonPhaseIcons(context, views, theme); int timeColor = theme.getTimeColor(); views.setTextColor(R.id.moonphase_major_date, timeColor); int textColor = theme.getTextColor(); views.setTextColor(R.id.moonphase_major_label, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.moonphase_major_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.moonphase_major_label, TypedValue.COMPLEX_UNIT_DIP, textSize); } }
Example 6
Source File: WidgetV24.java From prayer-times-android with Apache License 2.0 | 6 votes |
static void updateSilenter(Context context, AppWidgetManager appWidgetManager, int widgetId) { Theme theme = WidgetUtils.getTheme(widgetId); 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_silenter); remoteViews.setInt(R.id.widget_layout, "setBackgroundResource", theme.background); remoteViews.setViewPadding(R.id.padder, s / 2, s / 2, s / 2, s / 2); Intent i = new Intent(context, SilenterPrompt.class); remoteViews.setOnClickPendingIntent(R.id.widget, PendingIntent.getActivity(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT)); remoteViews.setTextViewText(R.id.text, context.getString(R.string.silent)); remoteViews.setTextViewTextSize(R.id.text, TypedValue.COMPLEX_UNIT_PX, s / 4f); remoteViews.setTextColor(R.id.text, theme.textcolor); appWidgetManager.updateAppWidget(widgetId, remoteViews); }
Example 7
Source File: ClockLayout_1x1_0.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); timeColor = theme.getTimeColor(); textColor = theme.getTextColor(); suffixColor = theme.getTimeSuffixColor(); boldTime = theme.getTimeBold(); paddingDp = theme.getPadding(); views.setTextColor(R.id.text_time, timeColor); views.setTextColor(R.id.text_time_suffix, suffixColor); views.setTextColor(R.id.text_time_extras, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { timeSizeSp = theme.getTimeSizeSp(); suffixSizeSp = theme.getTimeSuffixSizeSp(); views.setTextViewTextSize(R.id.text_time, TypedValue.COMPLEX_UNIT_DIP, timeSizeSp); views.setTextViewTextSize(R.id.text_time_suffix, TypedValue.COMPLEX_UNIT_DIP, suffixSizeSp); views.setTextViewTextSize(R.id.text_time_extras, TypedValue.COMPLEX_UNIT_DIP, theme.getTextSizeSp()); } }
Example 8
Source File: SunLayout_1x1_4.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); int noonColor = theme.getNoonTextColor(); int suffixColor = theme.getTimeSuffixColor(); views.setTextColor(R.id.text_time_noon_suffix, suffixColor); views.setTextColor(R.id.text_time_noon, noonColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { views.setTextViewTextSize(R.id.text_time_noon_suffix, TypedValue.COMPLEX_UNIT_DIP, theme.getTimeSuffixSizeSp()); views.setTextViewTextSize(R.id.text_time_noon, TypedValue.COMPLEX_UNIT_DIP, theme.getTimeSizeSp()); } Bitmap noonIcon = SuntimesUtils.gradientDrawableToBitmap(context, R.drawable.ic_noon_large0, theme.getNoonIconColor(), theme.getNoonIconStrokeColor(), theme.getNoonIconStrokePixels(context)); views.setImageViewBitmap(R.id.icon_time_noon, noonIcon); }
Example 9
Source File: MoonLayout_1x1_6.java From SuntimesWidget with GNU General Public License v3.0 | 6 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); highlightColor = theme.getTimeColor(); suffixColor = theme.getTimeSuffixColor(); int textColor = theme.getTextColor(); views.setTextColor(R.id.info_moon_rightascension_current_label, textColor); views.setTextColor(R.id.info_moon_declination_current_label, textColor); views.setTextColor(R.id.info_moon_rightascension_current, textColor); views.setTextColor(R.id.info_moon_declination_current, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.info_moon_rightascension_current_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.info_moon_declination_current_label, TypedValue.COMPLEX_UNIT_DIP, textSize); float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.info_moon_rightascension_current, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.info_moon_declination_current, TypedValue.COMPLEX_UNIT_DIP, timeSize); } }
Example 10
Source File: SuntimesLayout.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
/** * Apply the provided theme to the RemoteViews this layout knows about. * @param context the android application context * @param views the RemoteViews to apply the theme to * @param theme the theme object to apply to the views */ @TargetApi(Build.VERSION_CODES.JELLY_BEAN) public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { SuntimesUtils.initDisplayStrings(context); // theme background SuntimesTheme.ThemeBackground background = theme.getBackground(); if (background.supportsCustomColors()) { views.setInt(R.id.widgetframe_inner, "setBackgroundColor", theme.getBackgroundColor()); } else { views.setInt(R.id.widgetframe_inner, "setBackgroundResource", background.getResID()); // BUG: setting background screws up padding; pre jellybean versions can't correct for it! // either live w/ it, or move this call into if statement below .. however then the background // doesn't update for pre jellybean versions, confusing users into thinking themes don't work // at all (and they really don't considering the background is 90% of the theme). } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // fix theme padding (setting background resets padding to 0 for some reason) int[] padding = theme.getPaddingPixels(context); views.setViewPadding(R.id.widgetframe_inner, padding[0], padding[1], padding[2], padding[3]); // theme title text size views.setTextViewTextSize(R.id.text_title, TypedValue.COMPLEX_UNIT_DIP, theme.getTitleSizeSp()); } // theme title and text int titleColor = theme.getTitleColor(); views.setTextColor(R.id.text_title, titleColor); boldTitle = theme.getTitleBold(); boldTime = theme.getTimeBold(); }
Example 11
Source File: NewsListRemoteViewsFactory.java From opencdk-appwidget with Apache License 2.0 | 5 votes |
/** * 设置字体大小 * * @param views * @param viewId * @param textSize */ @SuppressLint("NewApi") private void setRemoteViewsTextSize(RemoteViews views, int viewId, int textSize) { if (android.os.Build.VERSION.SDK_INT >= 16) { // 低版本不支持字体适配 views.setTextViewTextSize(viewId, TypedValue.COMPLEX_UNIT_SP, textSize / 2); } }
Example 12
Source File: SunLayout_1x1_0.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); int sunriseColor = theme.getSunriseTextColor(); int suffixColor = theme.getTimeSuffixColor(); views.setTextColor(R.id.text_time_rise_suffix, suffixColor); views.setTextColor(R.id.text_time_rise, sunriseColor); int sunsetColor = theme.getSunsetTextColor(); views.setTextColor(R.id.text_time_set_suffix, suffixColor); views.setTextColor(R.id.text_time_set, sunsetColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float timeSize = theme.getTimeSizeSp(); float suffSize = theme.getTimeSuffixSizeSp(); views.setTextViewTextSize(R.id.text_time_rise_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize); views.setTextViewTextSize(R.id.text_time_rise, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.text_time_set, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.text_time_set_suffix, TypedValue.COMPLEX_UNIT_DIP, suffSize); } Bitmap sunriseIcon = SuntimesUtils.layerDrawableToBitmap(context, R.drawable.ic_sunrise0, theme.getSunriseIconColor(), theme.getSunriseIconStrokeColor(), theme.getSunriseIconStrokePixels(context)); views.setImageViewBitmap(R.id.icon_time_sunrise, sunriseIcon); Bitmap sunsetIcon = SuntimesUtils.layerDrawableToBitmap(context, R.drawable.ic_sunset0, theme.getSunsetIconColor(), theme.getSunsetIconStrokeColor(), theme.getSunsetIconStrokePixels(context)); views.setImageViewBitmap(R.id.icon_time_sunset, sunsetIcon); }
Example 13
Source File: LeanplumNotificationHelper.java From Leanplum-Android-SDK with Apache License 2.0 | 5 votes |
/** * Gets Notification.BigPictureStyle with 2 lines text. * * @param message Push notification Bundle. * @param bigPicture Bitmap for BigPictureStyle notification. * @param title String with title for push notification. * @param messageText String with text for push notification. * @return Notification.BigPictureStyle or null. */ @TargetApi(16) static Notification.BigPictureStyle getBigPictureStyle(Bundle message, Bitmap bigPicture, String title, final String messageText) { if (Build.VERSION.SDK_INT < 16 || message == null || bigPicture == null) { return null; } Notification.BigPictureStyle bigPictureStyle = new Notification.BigPictureStyle() { @Override protected RemoteViews getStandardView(int layoutId) { RemoteViews remoteViews = super.getStandardView(layoutId); if (messageText != null && messageText.length() >= MAX_ONE_LINE_TEXT_LENGTH) { // Modifications of standard push RemoteView. try { int id = Resources.getSystem().getIdentifier("text", "id", "android"); remoteViews.setBoolean(id, "setSingleLine", false); remoteViews.setInt(id, "setLines", 2); if (Build.VERSION.SDK_INT < 23) { // Make text smaller. remoteViews.setViewPadding(id, 0, BIGPICTURE_TEXT_TOP_PADDING, 0, 0); remoteViews.setTextViewTextSize(id, TypedValue.COMPLEX_UNIT_SP, BIGPICTURE_TEXT_SIZE); } } catch (Throwable throwable) { Log.e("Cannot modify push notification layout."); } } return remoteViews; } }; bigPictureStyle.bigPicture(bigPicture) .setBigContentTitle(title) .setSummaryText(message.getString(Constants.Keys.PUSH_MESSAGE_TEXT)); return bigPictureStyle; }
Example 14
Source File: MoonLayout.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
protected void themeViewsMoonPhaseText(Context context, RemoteViews views, SuntimesTheme theme) { int textColor = theme.getTextColor(); views.setTextColor(R.id.text_info_moonillum, textColor); views.setTextColor(R.id.text_info_moonphase, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.text_info_moonphase, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.text_info_moonillum, TypedValue.COMPLEX_UNIT_DIP, textSize); } }
Example 15
Source File: MoonLayout_1x1_8.java From SuntimesWidget with GNU General Public License v3.0 | 5 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); timeColor = theme.getTimeColor(); suffixColor = theme.getTimeSuffixColor(); int textColor = theme.getTextColor(); risingColor = theme.getMoonriseTextColor(); settingColor = theme.getMoonsetTextColor(); views.setTextColor(R.id.moonapsis_apogee_label, textColor); views.setTextColor(R.id.moonapsis_apogee_date, timeColor); views.setTextColor(R.id.moonapsis_apogee_note, textColor); views.setTextColor(R.id.moonapsis_apogee_distance, textColor); views.setTextColor(R.id.moonapsis_perigee_label, textColor); views.setTextColor(R.id.moonapsis_perigee_date, timeColor); views.setTextColor(R.id.moonapsis_perigee_note, textColor); views.setTextColor(R.id.moonapsis_perigee_distance, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.moonapsis_apogee_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonapsis_apogee_note, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonapsis_apogee_distance, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonapsis_perigee_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonapsis_perigee_note, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonapsis_perigee_distance, TypedValue.COMPLEX_UNIT_DIP, textSize); float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.moonapsis_apogee_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.moonapsis_perigee_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); } }
Example 16
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 17
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 18
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 19
Source File: WidgetProvider.java From openScale with GNU General Public License v3.0 | 4 votes |
private void updateWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Bundle newOptions) { // Make sure we use the correct language context = MainActivity.createBaseContext(context); final int minWidth = newOptions.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); int userId = prefs.getInt(getUserIdPreferenceName(appWidgetId), -1); String key = prefs.getString(getMeasurementPreferenceName(appWidgetId), ""); Timber.d("Update widget %d (%s) for user %d, min width %ddp", appWidgetId, key, userId, minWidth); if (measurementViews == null) { measurementViews = MeasurementView.getMeasurementList( context, MeasurementView.DateTimeOrder.NONE); } MeasurementView measurementView = measurementViews.get(0); for (MeasurementView view : measurementViews) { if (view.getKey().equals(key)) { measurementView = view; break; } } OpenScale openScale = OpenScale.getInstance(); ScaleMeasurement latest = openScale.getLastScaleMeasurement(userId); if (latest != null) { ScaleMeasurement previous = openScale.getTupleOfScaleMeasurement(latest.getId())[0]; measurementView.loadFrom(latest, previous); } // From https://developer.android.com/guide/practices/ui_guidelines/widget_design final int twoCellsMinWidth = 110; final int thirdCellsMinWidth = 180; final int fourCellsMinWidth = 250; RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget); // Add some transparency to make the corners appear rounded int indicatorColor = measurementView.getIndicatorColor(); indicatorColor = (180 << 24) | (indicatorColor & 0xffffff); views.setInt(R.id.indicator_view, "setBackgroundColor", indicatorColor); // Show icon in >= two cell mode if (minWidth >= twoCellsMinWidth) { views.setImageViewResource(R.id.widget_icon, measurementView.getIconResource()); views.setViewVisibility(R.id.widget_icon, View.VISIBLE); views.setViewVisibility(R.id.widget_icon_vertical, View.GONE); } else { views.setImageViewResource(R.id.widget_icon_vertical, measurementView.getIconResource()); views.setViewVisibility(R.id.widget_icon_vertical, View.VISIBLE); views.setViewVisibility(R.id.widget_icon, View.GONE); } // Show measurement name in >= four cell mode if (minWidth >= fourCellsMinWidth) { views.setTextViewText(R.id.widget_name, measurementView.getName()); views.setTextViewText(R.id.widget_date, latest != null ? DateFormat.getDateTimeInstance( DateFormat.LONG, DateFormat.SHORT).format(latest.getDateTime()) : ""); views.setViewVisibility(R.id.widget_name_date_layout, View.VISIBLE); } else { views.setViewVisibility(R.id.widget_name_date_layout, View.GONE); } // Always show value and delta, but adjust font size based on widget width views.setTextViewText(R.id.widget_value, measurementView.getValueAsString(true)); SpannableStringBuilder delta = new SpannableStringBuilder(); measurementView.appendDiffValue(delta, false); views.setTextViewText(R.id.widget_delta, delta); int textSize; if (minWidth >= thirdCellsMinWidth) { textSize = 18; } else if (minWidth >= twoCellsMinWidth) { textSize = 17; } else { textSize = 12; } views.setTextViewTextSize(R.id.widget_value, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.widget_delta, TypedValue.COMPLEX_UNIT_DIP, textSize); // Start main activity when widget is clicked Intent intent = new Intent(context, MainActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); views.setOnClickPendingIntent(R.id.widget_layout, pendingIntent); appWidgetManager.updateAppWidget(appWidgetId, views); }
Example 20
Source File: MoonLayout_3x1_0.java From SuntimesWidget with GNU General Public License v3.0 | 4 votes |
@Override public void themeViews(Context context, RemoteViews views, SuntimesTheme theme) { super.themeViews(context, views, theme); int timeColor = theme.getTimeColor(); views.setTextColor(R.id.moonphase_new_date, timeColor); views.setTextColor(R.id.moonphase_firstquarter_date, timeColor); views.setTextColor(R.id.moonphase_full_date, timeColor); views.setTextColor(R.id.moonphase_thirdquarter_date, timeColor); int textColor = theme.getTextColor(); views.setTextColor(R.id.moonphase_new_label, textColor); views.setTextColor(R.id.moonphase_firstquarter_label, textColor); views.setTextColor(R.id.moonphase_full_label, textColor); views.setTextColor(R.id.moonphase_thirdquarter_label, textColor); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { float timeSize = theme.getTimeSizeSp(); views.setTextViewTextSize(R.id.moonphase_new_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.moonphase_firstquarter_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.moonphase_full_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); views.setTextViewTextSize(R.id.moonphase_thirdquarter_date, TypedValue.COMPLEX_UNIT_DIP, timeSize); float textSize = theme.getTextSizeSp(); views.setTextViewTextSize(R.id.moonphase_new_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonphase_firstquarter_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonphase_full_label, TypedValue.COMPLEX_UNIT_DIP, textSize); views.setTextViewTextSize(R.id.moonphase_thirdquarter_label, TypedValue.COMPLEX_UNIT_DIP, textSize); } int colorWaxing = theme.getMoonWaxingColor(); int colorWaning = theme.getMoonWaningColor(); int colorFull = theme.getMoonFullColor(); int colorNew = theme.getMoonNewColor(); Bitmap fullMoon = SuntimesUtils.gradientDrawableToBitmap(context, MoonPhaseDisplay.FULL.getIcon(), colorFull, colorWaning, theme.getMoonFullStrokePixels(context)); views.setImageViewBitmap(R.id.moonphase_full_icon, fullMoon); Bitmap newMoon = SuntimesUtils.gradientDrawableToBitmap(context, MoonPhaseDisplay.NEW.getIcon(), colorNew, colorWaxing, theme.getMoonNewStrokePixels(context)); views.setImageViewBitmap(R.id.moonphase_new_icon, newMoon); Bitmap waxingQuarter = SuntimesUtils.layerDrawableToBitmap(context, MoonPhaseDisplay.FIRST_QUARTER.getIcon(), colorWaxing, colorWaxing, 0); views.setImageViewBitmap(R.id.moonphase_firstquarter_icon, waxingQuarter); Bitmap waningQuarter = SuntimesUtils.layerDrawableToBitmap(context, MoonPhaseDisplay.THIRD_QUARTER.getIcon(), colorWaning, colorWaning, 0); views.setImageViewBitmap(R.id.moonphase_thirdquarter_icon, waningQuarter); }