当前位置: 首页>>代码示例>>Java>>正文


Java Utility.formatTemperature方法代码示例

本文整理汇总了Java中com.example.android.sunshine.app.Utility.formatTemperature方法的典型用法代码示例。如果您正苦于以下问题:Java Utility.formatTemperature方法的具体用法?Java Utility.formatTemperature怎么用?Java Utility.formatTemperature使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.example.android.sunshine.app.Utility的用法示例。


在下文中一共展示了Utility.formatTemperature方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: sendTodayForecast

import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
private void sendTodayForecast(double maxTemp, double minTemp, int weatherId) {

        PutDataMapRequest dataMap = PutDataMapRequest.create(FORECAST_PATH).setUrgent();
        String lowString = Utility.formatTemperature(getContext(), minTemp);
        String highString = Utility.formatTemperature(getContext(), maxTemp);
        dataMap.getDataMap().putString(MAX_TEMP_KEY, highString);
        dataMap.getDataMap().putString(MIN_TEMP_KEY, lowString);

        int artResource = Utility.getArtResourceForWeatherCondition(weatherId);
        Asset weatherIcon = Utility.toAsset(artResource, getContext());
        dataMap.getDataMap().putAsset(WEATHER_ICON_KEY, weatherIcon);
        dataMap.getDataMap().putLong(TIMESTAMP_KEY, System.currentTimeMillis());
        PutDataRequest request = dataMap.asPutDataRequest();

        Wearable.DataApi.putDataItem(mGoogleApiClient, request)
                .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                    @Override
                    public void onResult(DataApi.DataItemResult dataItemResult) {
                        if (!dataItemResult.getStatus().isSuccess()) {
                            Log.e(LOG_TAG, "ERROR: failed to putDataItem, status code: "
                                    + dataItemResult.getStatus().getStatusCode());
                        }
                    }
                });
    }
 
开发者ID:jainkamini,项目名称:Sunshinewear,代码行数:26,代码来源:SunshineSyncAdapter.java

示例2: onHandleIntent

import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this,
            TodayWidgetProvider.class));

    // Get today's data from the ContentProvider
    String location = Utility.getPreferredLocation(this);
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
            location, System.currentTimeMillis());
    Cursor data = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
            null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
    if (data == null) {
        return;
    }
    if (!data.moveToFirst()) {
        data.close();
        return;
    }

    // Extract the weather data from the Cursor
    int weatherId = data.getInt(INDEX_WEATHER_ID);
    int weatherArtResourceId = Utility.getArtResourceForWeatherCondition(weatherId);
    String description = data.getString(INDEX_SHORT_DESC);
    double maxTemp = data.getDouble(INDEX_MAX_TEMP);
    double minTemp = data.getDouble(INDEX_MIN_TEMP);
    String formattedMaxTemperature = Utility.formatTemperature(this, maxTemp);
    String formattedMinTemperature = Utility.formatTemperature(this, minTemp);
    data.close();

    // Perform this loop procedure for each Today widget
    for (int appWidgetId : appWidgetIds) {
        // Find the correct layout based on the widget's width
        int widgetWidth = getWidgetWidth(appWidgetManager, appWidgetId);
        int defaultWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
        int largeWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_large_width);
        int layoutId;
        if (widgetWidth >= largeWidth) {
            layoutId = R.layout.widget_today_large;
        } else if (widgetWidth >= defaultWidth) {
            layoutId = R.layout.widget_today;
        } else {
            layoutId = R.layout.widget_today_small;
        }
        RemoteViews views = new RemoteViews(getPackageName(), layoutId);

        // Add the data to the RemoteViews
        views.setImageViewResource(R.id.widget_icon, weatherArtResourceId);
        // Content Descriptions for RemoteViews were only added in ICS MR1
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            setRemoteContentDescription(views, description);
        }
        views.setTextViewText(R.id.widget_description, description);
        views.setTextViewText(R.id.widget_high_temperature, formattedMaxTemperature);
        views.setTextViewText(R.id.widget_low_temperature, formattedMinTemperature);

        // Create an Intent to launch MainActivity
        Intent launchIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:67,代码来源:TodayWidgetIntentService.java

示例3: onHandleIntent

import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {

    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this,
            TodayWidgetProvider.class));

    // Get today's data from the ContentProvider
    String location = Utility.getPreferredLocation(this);
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
            location, System.currentTimeMillis());
    Cursor data = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
            null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
    if (data == null) {
        return;
    }
    if (!data.moveToFirst()) {
        data.close();
        return;
    }

    // Extract the weather data from the Cursor
    int weatherId = data.getInt(INDEX_WEATHER_ID);
    int weatherArtResourceId = Utility.getArtResourceForWeatherCondition(weatherId);
    String description = data.getString(INDEX_SHORT_DESC);
    double maxTemp = data.getDouble(INDEX_MAX_TEMP);
    double minTemp = data.getDouble(INDEX_MIN_TEMP);
    String formattedMaxTemperature = Utility.formatTemperature(this, maxTemp);
    String formattedMinTemperature = Utility.formatTemperature(this, minTemp);
    data.close();

    // Perform this loop procedure for each Today widget
    for (int appWidgetId : appWidgetIds) {

        // Find the correct layout based on the widget's width
        int widgetWidth = getWidgetWidth(appWidgetManager, appWidgetId);
        int defaultWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
       int largeWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_large_width);
        int layoutId;
        if (widgetWidth >= largeWidth) {
                 layoutId = R.layout.widget_today_large;
            } else if (widgetWidth >= defaultWidth) {
                   layoutId = R.layout.widget_today;
           } else {
                 layoutId = R.layout.widget_today_small;
            }
        RemoteViews views = new RemoteViews(getPackageName(), layoutId);
        // Add the data to the RemoteViews
        views.setImageViewResource(R.id.widget_icon, weatherArtResourceId);
        // Content Descriptions for RemoteViews were only added in ICS MR1
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            setRemoteContentDescription(views, description);
        }
        views.setTextViewText(R.id.widget_description, description);
        views.setTextViewText(R.id.widget_high_temperature, formattedMaxTemperature);
        views.setTextViewText(R.id.widget_low_temperature, formattedMinTemperature);

        // Create an Intent to launch MainActivity
        Intent launchIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
开发者ID:anoo-radha,项目名称:Sunshine_WeatherApp,代码行数:68,代码来源:TodayWidgetIntentService.java

示例4: onHandleIntent

import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
@Override
protected void onHandleIntent(Intent intent) {
    // Retrieve all of the Today widget ids: these are the widgets we need to update
    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
    int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this,
            TodayWidgetProvider.class));

    // Get today's data from the ContentProvider
    String location = Utility.getPreferredLocation(this);
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
            location, System.currentTimeMillis());
    Cursor data = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
            null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
    if (data == null) {
        return;
    }
    if (!data.moveToFirst()) {
        data.close();
        return;
    }

    // Extract the weather data from the Cursor
    int weatherId = data.getInt(INDEX_WEATHER_ID);
    int weatherArtResourceId = Utility.getArtResourceForWeatherCondition(weatherId);
    String description = data.getString(INDEX_SHORT_DESC);
    double maxTemp = data.getDouble(INDEX_MAX_TEMP);
    String formattedMaxTemperature = Utility.formatTemperature(this, maxTemp);
    double minTemp = data.getDouble(INDEX_MIN_TEMP);
    String formattedMinTemperature = Utility.formatTemperature(this, minTemp);
    data.close();

    // Perform this loop procedure for each Today widget
    for (int appWidgetId : appWidgetIds) {
        // Find the correct layout based on the widget's width
        int widgetWidth = getWidgetWidth(appWidgetManager, appWidgetId);
        int defaultWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_default_width);
        int largeWidth = getResources().getDimensionPixelSize(R.dimen.widget_today_large_width);
        int layoutId;
        if (widgetWidth >= largeWidth) {
            layoutId = R.layout.widget_today_large;
        } else if (widgetWidth >= defaultWidth) {
            layoutId = R.layout.widget_today;
        } else {
            layoutId = R.layout.widget_today_small;
        }

        RemoteViews views = new RemoteViews(getPackageName(), layoutId);

        // Add the data to the RemoteViews
        views.setImageViewResource(R.id.widget_icon, weatherArtResourceId);
        // Content Descriptions for RemoteViews were only added in ICS MR1
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) {
            setRemoteContentDescription(views, description);
        }
        views.setTextViewText(R.id.widget_description, description);
        views.setTextViewText(R.id.widget_high_temperature, formattedMaxTemperature);
        views.setTextViewText(R.id.widget_low_temperature, formattedMinTemperature);

        // Create an Intent to launch MainActivity
        Intent launchIntent = new Intent(this, MainActivity.class);
        PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, launchIntent, 0);
        views.setOnClickPendingIntent(R.id.widget, pendingIntent);

        // Tell the AppWidgetManager to perform an update on the current app widget
        appWidgetManager.updateAppWidget(appWidgetId, views);
    }
}
 
开发者ID:pmatushkin,项目名称:Sunshine.Advanced,代码行数:68,代码来源:TodayWidgetIntentService.java

示例5: getWeatherDataFromJson

import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
private Weather getWeatherDataFromJson(String forecastJsonStr)
        throws JSONException {
    final String OWM_COORD = "coord";

    // Location coordinate
    final String OWM_LATITUDE = "lat";
    final String OWM_LONGITUDE = "lon";

    // All temperatures are children of the "temp" object.
    final String OWM_TEMPERATURE = "main";
    final String OWM_MAX = "temp_max";
    final String OWM_MIN = "temp_min";

    final String OWM_WEATHER = "weather";
    final String OWM_DESCRIPTION = "main";
    final String OWM_WEATHER_ID = "id";

    final String OWM_MESSAGE_CODE = "cod";

    try {
        JSONObject forecastJson = new JSONObject(forecastJsonStr);

        if ( forecastJson.has(OWM_MESSAGE_CODE) ) {
            int errorCode = forecastJson.getInt(OWM_MESSAGE_CODE);

            switch (errorCode) {
                case HttpURLConnection.HTTP_OK:
                    break;
                case HttpURLConnection.HTTP_NOT_FOUND:
                    return null;
                default:
                    return null;
            }
        }

        JSONObject cityCoord = forecastJson.getJSONObject(OWM_COORD);
        double cityLatitude = cityCoord.getDouble(OWM_LATITUDE);
        double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE);

        double high;
        double low;

        String description;
        int weatherId;

        JSONObject weatherObject = forecastJson.getJSONArray(OWM_WEATHER).getJSONObject(0);
        description = weatherObject.getString(OWM_DESCRIPTION);
        weatherId = weatherObject.getInt(OWM_WEATHER_ID);

        JSONObject temperatureObject = forecastJson.getJSONObject(OWM_TEMPERATURE);
        high = temperatureObject.getDouble(OWM_MAX);
        low = temperatureObject.getDouble(OWM_MIN);

        Weather weather = new Weather(weatherId, cityLatitude, cityLongitude, Utility.formatTemperature(SunshineApp.getContext(), high), Utility.formatTemperature(SunshineApp.getContext(), low));
        return weather;
    } catch (JSONException e) {
        Log.e(LOG_TAG, e.getMessage(), e);
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:PedroCarrillo,项目名称:sunshine-wear-watchface,代码行数:62,代码来源:TodayWeatherAsyncTask.java


注:本文中的com.example.android.sunshine.app.Utility.formatTemperature方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。