本文整理汇总了Java中com.example.android.sunshine.app.Utility.getArtResourceForWeatherCondition方法的典型用法代码示例。如果您正苦于以下问题:Java Utility.getArtResourceForWeatherCondition方法的具体用法?Java Utility.getArtResourceForWeatherCondition怎么用?Java Utility.getArtResourceForWeatherCondition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.example.android.sunshine.app.Utility
的用法示例。
在下文中一共展示了Utility.getArtResourceForWeatherCondition方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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());
}
}
});
}
示例2: onPostExecute
import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
@Override
protected void onPostExecute(final Weather s) {
super.onPostExecute(s);
int weatherId = s.getWeatherId();
String artUrl = Utility.getArtUrlForWeatherCondition(SunshineApp.getContext(), weatherId);
DataMap config = new DataMap();
config.putString(KEY_WEATHER_LOW_TEMP, s.getLow());
config.putString(KEY_WEATHER_MAX_TEMP, s.getHigh());
weatherListener.sendWeatherData(config);
int artResourceId = Utility.getArtResourceForWeatherCondition(weatherId);
weatherListener.sendWeatherIcon(Utility.getResizedBitmap(BitmapFactory.decodeResource(SunshineApp.getContext().getResources(), artResourceId),40,40));
// Glide
// .with(SunshineApp.getContext())
// .load(artUrl)
// .asBitmap()
// .into(new SimpleTarget<Bitmap>(40,40) {
// @Override
// public void onResourceReady(Bitmap weatherBitmap, GlideAnimation glideAnimation) {
//
// }
// });
}
示例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);
}
}
示例4: notifyWearable
import com.example.android.sunshine.app.Utility; //导入方法依赖的package包/类
private void notifyWearable() {
final Context context = getContext();
final String preferredLocation = Utility.getPreferredLocation(getContext());
final Uri uri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(preferredLocation, System.currentTimeMillis());
Cursor query = context.getContentResolver().query(uri, WEARABLE_WEATHER_PROJECTION, null, null, null);
if (null == query) {
return;
}
if(!query.moveToFirst()){
query.close();
return;
}
PutDataMapRequest sendRequest = PutDataMapRequest.create("/SunshineWearListenerService/Data");
double highTemp = query.getDouble(INDEX_MAX_TEMP);
double lowTemp = query.getDouble(INDEX_MIN_TEMP);
int highTempInt = Utility.isMetric(context) ? (int)highTemp : (int)((highTemp * 1.8) + 32);
int lowTempInt = Utility.isMetric(context) ? (int)lowTemp : (int)((lowTemp * 1.8) + 32);
sendRequest.getDataMap().putInt("dataHigh", highTempInt);
sendRequest.getDataMap().putInt("dataLow", lowTempInt);
sendRequest.getDataMap().putLong("dataTime", System.currentTimeMillis());
final ByteArrayOutputStream imageBytes = new ByteArrayOutputStream();
String artUrl = Utility.getArtUrlForWeatherCondition(context, query.getInt(INDEX_WEATHER_ID));
int artResourceId = Utility.getArtResourceForWeatherCondition(query.getInt(INDEX_WEATHER_ID));
int size = context.getResources().getDimensionPixelSize(R.dimen.wearable_large_icon_default);
try {
Bitmap weatherIcon = Glide.with(context)
.load(artUrl)
.asBitmap()
.error(artResourceId)
.fitCenter()
.into(size, size)
.get();
weatherIcon.compress(Bitmap.CompressFormat.PNG, 100, imageBytes);
Asset weatherIconAsset = Asset.createFromBytes(imageBytes.toByteArray());
sendRequest.getDataMap().putAsset("dataIcon", weatherIconAsset);
} catch(Exception ex){
Log.e(LOG_TAG, ex.toString());
}
PutDataRequest putDataRequest = sendRequest.asPutDataRequest();
GoogleApiClient googleApiClient = getGoogleApiClient();
googleApiClient.connect();
Wearable.DataApi.putDataItem(googleApiClient, putDataRequest);
}
示例5: 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);
}
}
示例6: 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);
}
}