Android Open Source - android-appwidget-cirrus Pressure Formatter






From Project

Back to project page android-appwidget-cirrus.

License

The source code is released under:

MIT License

If you think the Android project android-appwidget-cirrus listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

/* Copyright 2014 Wayne D Grant (www.waynedgrant.com)
   Licensed under the MIT License */
//  ww w. j a  va2  s . co m
package com.waynedgrant.cirrus.presentation.formatters;

import static com.waynedgrant.cirrus.units.PressureUnit.HECTOPASCALS;
import static com.waynedgrant.cirrus.units.PressureUnit.INCHES_OF_MERCURY;
import static com.waynedgrant.cirrus.units.PressureUnit.KILIOPASCALS;
import static com.waynedgrant.cirrus.units.PressureUnit.MILLIBARS;

import java.math.RoundingMode;
import java.util.Locale;

import com.waynedgrant.cirrus.measures.Pressure;
import com.waynedgrant.cirrus.units.PressureUnit;

public class PressureFormatter
{
    private Pressure pressure;
    
    public PressureFormatter(Pressure pressure)
    {
        this.pressure = pressure;
    }

    public String format(PressureUnit unit)
    {
        String formatted = null;
        
        if (pressure != null)
        {
            String formatString = null;
            int scale;
            
            if (unit == HECTOPASCALS)
            {
                formatString = "%1.1f hPa";
                scale = 1;
            }
            else if (unit == MILLIBARS)
            {
                formatString = "%1.1f mb";
                scale = 1;
            }
            else if (unit == KILIOPASCALS)
            {
                formatString = "%1.2f kPa";
                scale = 2;
            }
            else if (unit == INCHES_OF_MERCURY)
            {
                formatString = "%1.2f inHg";
                scale = 2;
            }
            else
            {
                formatString = "%1.1f mmHg";
                scale = 1;
            }
            
            formatted = String.format(Locale.US, formatString, pressure.getValue(unit).setScale(scale, RoundingMode.HALF_DOWN));
        }
        else
        {
            if (unit == HECTOPASCALS)
            {
                formatted = "----.- hPa";
            }
            else if (unit == MILLIBARS)
            {
                formatted = "----.- mb";
            }
            else if (unit == KILIOPASCALS)
            {
                formatted = "---.-- kPa";
            }
            else if (unit == INCHES_OF_MERCURY)
            {
                formatted = "--.-- inHg";
            }
            else
            {
                formatted = "---.- mmHg";
            }
        }
        
        return formatted;
    }
}




Java Source Code List

com.waynedgrant.cirrus.UpdateWidgetService.java
com.waynedgrant.cirrus.WidgetConfigActivity.java
com.waynedgrant.cirrus.WidgetProvider.java
com.waynedgrant.cirrus.clientraw.ClientRawCache.java
com.waynedgrant.cirrus.clientraw.ClientRawRequest.java
com.waynedgrant.cirrus.clientraw.ClientRawResponse.java
com.waynedgrant.cirrus.clientraw.ClientRawUrl.java
com.waynedgrant.cirrus.clientraw.ClientRaw.java
com.waynedgrant.cirrus.clientraw.RetrieveClientRawTask.java
com.waynedgrant.cirrus.measures.Conditions.java
com.waynedgrant.cirrus.measures.Pressure.java
com.waynedgrant.cirrus.measures.Rainfall.java
com.waynedgrant.cirrus.measures.Temperature.java
com.waynedgrant.cirrus.measures.Trend.java
com.waynedgrant.cirrus.measures.WeatherItem.java
com.waynedgrant.cirrus.measures.WindDirection.java
com.waynedgrant.cirrus.measures.WindSpeed.java
com.waynedgrant.cirrus.preferences.Preferences.java
com.waynedgrant.cirrus.presentation.colorizers.TemperatureColorizer.java
com.waynedgrant.cirrus.presentation.colorizers.UvIndexColorizer.java
com.waynedgrant.cirrus.presentation.colorizers.WeatherItemColorizer.java
com.waynedgrant.cirrus.presentation.formatters.ConditionsFormatter.java
com.waynedgrant.cirrus.presentation.formatters.DateFormat.java
com.waynedgrant.cirrus.presentation.formatters.DateFormatter.java
com.waynedgrant.cirrus.presentation.formatters.FormattedWeatherItem.java
com.waynedgrant.cirrus.presentation.formatters.HumidityFormatter.java
com.waynedgrant.cirrus.presentation.formatters.PressureFormatter.java
com.waynedgrant.cirrus.presentation.formatters.RainfallFormatter.java
com.waynedgrant.cirrus.presentation.formatters.RainfallRateFormatter.java
com.waynedgrant.cirrus.presentation.formatters.SolarPercentageFormatter.java
com.waynedgrant.cirrus.presentation.formatters.SolarRadiationFormatter.java
com.waynedgrant.cirrus.presentation.formatters.StringFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TemperatureFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TimeFormat.java
com.waynedgrant.cirrus.presentation.formatters.TimeFormatter.java
com.waynedgrant.cirrus.presentation.formatters.TrendFormatter.java
com.waynedgrant.cirrus.presentation.formatters.UvIndexFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WeatherItemFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WindDirectionFormatter.java
com.waynedgrant.cirrus.presentation.formatters.WindSpeedFormatter.java
com.waynedgrant.cirrus.units.CardinalDirection.java
com.waynedgrant.cirrus.units.PressureUnit.java
com.waynedgrant.cirrus.units.RainfallUnit.java
com.waynedgrant.cirrus.units.TemperatureUnit.java
com.waynedgrant.cirrus.units.WindDirectionUnit.java
com.waynedgrant.cirrus.units.WindSpeedUnit.java
com.waynedgrant.cirrus.update.Timeout.java