Java Code Examples for android.widget.RemoteViews#setImageViewUri()

The following examples show how to use android.widget.RemoteViews#setImageViewUri() . 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: NormalNotificationIMP.java    From GeometricWeather with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static RemoteViews buildBaseView(Context context, RemoteViews views,
                                         ResourceProvider provider, Location location,
                                         TemperatureUnit temperatureUnit,
                                         boolean dayTime, boolean minimalIcon,
                                         NotificationTextColor textColor,
                                         boolean customColor, int backgroundColor,
                                         int mainColor, int subColor) {
    Weather weather = location.getWeather();
    if (weather == null) {
        return views;
    }

    views.setImageViewUri(
            R.id.notification_base_icon,
            ResourceHelper.getWidgetNotificationIconUri(
                    provider, weather.getCurrent().getWeatherCode(), dayTime, minimalIcon, textColor
            )
    );

    views.setTextViewText(
            R.id.notification_base_realtimeTemp,
            Temperature.getShortTemperature(
                    context,
                    weather.getCurrent().getTemperature().getTemperature(),
                    temperatureUnit
            )
    );

    if (weather.getCurrent().getAirQuality().isValid()) {
        views.setTextViewText(
                R.id.notification_base_aqiAndWind,
                context.getString(R.string.air_quality)
                        + " - "
                        + weather.getCurrent().getAirQuality().getAqiText()
        );
    } else {
        views.setTextViewText(
                R.id.notification_base_aqiAndWind,
                context.getString(R.string.wind)
                        + " - "
                        + weather.getCurrent().getWind().getLevel()
        );
    }

    views.setTextViewText(
            R.id.notification_base_weather,
            weather.getCurrent().getWeatherText()
    );

    StringBuilder timeStr = new StringBuilder();
    timeStr.append(location.getCityName(context));
    if (SettingsOptionManager.getInstance(context).getLanguage().isChinese()) {
        timeStr.append(", ")
                .append(LunarHelper.getLunarDate(new Date()));
    } else {
        timeStr.append(", ")
                .append(context.getString(R.string.refresh_at))
                .append(" ")
                .append(Base.getTime(context, weather.getBase().getUpdateDate()));
    }
    views.setTextViewText(R.id.notification_base_time, timeStr.toString());

    if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.P) {
        if (customColor) {
            views.setInt(R.id.notification_base, "setBackgroundColor", backgroundColor);
        } else {
            views.setInt(R.id.notification_base, "setBackgroundColor", Color.TRANSPARENT);
        }

        views.setTextColor(R.id.notification_base_realtimeTemp, mainColor);
        views.setTextColor(R.id.notification_base_weather, mainColor);
        views.setTextColor(R.id.notification_base_aqiAndWind, subColor);
        views.setTextColor(R.id.notification_base_time, subColor);
    }

    return views;
}