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


Java Utility类代码示例

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


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

示例1: onUpdate

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
@Override
protected void onUpdate(int reason) {
    String location = Utility.getPreferredLocation(this);
    Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
            location, System.currentTimeMillis());
    Cursor cursor = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
            null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
    if (cursor.moveToFirst()) {
        int weatherId = cursor.getInt(INDEX_WEATHER_ID);
        String desc = cursor.getString(INDEX_SHORT_DESC);

        String imageUrl = Utility.getImageUrlForWeatherCondition(weatherId);
        // Only publish a new wallpaper if we have a valid image
        if (imageUrl != null) {
            publishArtwork(new Artwork.Builder()
                    .imageUri(Uri.parse(imageUrl))
                    .title(desc)
                    .byline(location)
                    .viewIntent(new Intent(this, MainActivity.class))
                    .build());
        }
    }
    cursor.close();
}
 
开发者ID:changja88,项目名称:Udacity_Sunshine,代码行数:25,代码来源:WeatherMuzeiSource.java

示例2: fromCursorRow

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
public static Forecast fromCursorRow(Context context, Cursor cursor) {
    Forecast forecast = new Forecast();
    // NOTE: The constant lookup of the column index for each field in this query is not optimal
    // If this were being done for more than a few rows you would want to cache the lookups.
    forecast.mWeatherId = cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID));
    forecast.mHigh = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP));
    forecast.mLow = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));
    forecast.mDescription = cursor.getString(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC));
    String date = cursor.getString(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_DATE));
    forecast.mMillisecondsSincEpoch = Long.parseLong(date);

    // Generate an ID to uniquely identify the notifications.
    forecast.mDaysSinceEpoch = (int)(Long.parseLong(date) / MILLISECONDS_IN_A_DAY);

    // Define the text of the forecast.
    forecast.mNotificationContentText = String.format(context.getString(
            R.string.format_notification),
            forecast.mDescription,
            Utility.formatTemperature(context, forecast.mHigh),
            Utility.formatTemperature(context, forecast.mLow));

    forecast.mNotificationTitle = context.getString(R.string.app_name);

    return forecast;
}
 
开发者ID:googlecodelabs,项目名称:getting-ready-for-android-n,代码行数:26,代码来源:Forecast.java

示例3: getWeather

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private ForecastWear getWeather(){
    ForecastWear fw=new ForecastWear();
    String locationSetting = Utility.getPreferredLocation(this);
    Uri weather= WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(locationSetting,System.currentTimeMillis());
    Cursor cursor=getContentResolver().query(weather,FORECAST_COLUMNS,null,null, WeatherContract.WeatherEntry.COLUMN_DATE+" ASC");
    if(cursor!=null){
        if(!cursor.moveToFirst()){
            cursor.close();
        }else{
            fw.max_temp=String.valueOf((int) cursor.getDouble(MAX_TEMP));
            fw.min_temp=String.valueOf((int) cursor.getDouble(MIN_TEMP));
            fw.weather_id =cursor.getInt(WEATHER_ID);
            return fw;
        }
    }

    return null;
}
 
开发者ID:oscarbujinkan,项目名称:Go-Ubiquitous,代码行数:19,代码来源:WearListenerService.java

示例4: 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

示例5: onHandleIntent

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

        final String action = intent.getAction();
        if (SunshineSyncAdapter.ACTION_DATA_UPDATED.equals(action)) {
            String location = Utility.getPreferredLocation(this);
            Uri weatherForLocationUri = WeatherContract.WeatherEntry.buildWeatherLocationWithStartDate(
                    location, System.currentTimeMillis());
            Cursor cursor = getContentResolver().query(weatherForLocationUri, FORECAST_COLUMNS, null,
                    null, WeatherContract.WeatherEntry.COLUMN_DATE + " ASC");
            if (cursor.moveToFirst()) {
                int weatherId = cursor.getInt(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_WEATHER_ID));
                String desc = cursor.getString(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC));
                double high = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP));
                double low = cursor.getDouble(cursor.getColumnIndex(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));

                handleWatchfaceUpdate(weatherId, desc, high, low);
            }
            cursor.close();

        }
    }
}
 
开发者ID:josemontiel,项目名称:SunshineWatchFace,代码行数:25,代码来源:SunshineWatchfaceService.java

示例6: sendWeatherIconToDevices

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private static void sendWeatherIconToDevices(Bitmap weatherIcon) {
        PutDataMapRequest dataMap = PutDataMapRequest.create("/image");
        dataMap.getDataMap().putAsset(TodayWeatherAsyncTask.KEY_WEATHER_ICON, Utility.createAssetFromBitmap(weatherIcon));
        PutDataRequest request = dataMap.asPutDataRequest();
        PendingResult<DataApi.DataItemResult> pendingResult = Wearable.DataApi.putDataItem(mGoogleApiClient, request);
        pendingResult.setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
            @Override
            public void onResult(DataApi.DataItemResult dataItemResult) {
                // something
            }
        });
//        Asset asset =  Utility.createAssetFromBitmap(weatherIcon);
//        PutDataRequest request = PutDataRequest.create("/image");
//        request.putAsset(TodayWeatherAsyncTask.KEY_WEATHER_ICON, asset);
//        Wearable.DataApi.putDataItem(mGoogleApiClient, request);
    }
 
开发者ID:PedroCarrillo,项目名称:sunshine-wear-watchface,代码行数:17,代码来源:WeatherWearableListener.java

示例7: 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) {
//
//                    }
//                });

    }
 
开发者ID:PedroCarrillo,项目名称:sunshine-wear-watchface,代码行数:24,代码来源:TodayWeatherAsyncTask.java

示例8: sendDataToWear

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private void sendDataToWear() {

        Log.d(TAG, "sendDataToWear: ");

        String locationQuery = Utility.getPreferredLocation(this);

        Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis());

        Cursor cursor = getBaseContext().getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);
        DataMap dataMap = new DataMap();

        if (cursor.moveToFirst()) {
            int weatherId = cursor.getInt(INDEX_WEATHER_ID);
            double high = cursor.getDouble(INDEX_MAX_TEMP);
            double low = cursor.getDouble(INDEX_MIN_TEMP);

            high  = Utility.getFormattedTemperature(this, high);
            low = Utility.getFormattedTemperature(this, low);

            Log.d(TAG, "sendDataToWear: high temp: " + high);
            Log.d(TAG, "sendDataToWear: low temp: " + low);

            BigDecimal highBD = new BigDecimal(high);
            highBD = highBD.setScale(2, BigDecimal.ROUND_UP);
            BigDecimal lowBD = new BigDecimal(low);
            lowBD = lowBD.setScale(2, BigDecimal.ROUND_UP);

            dataMap.putLong("time", new Date().getTime());
            dataMap.putInt(Constants.KEY_WEATHER_TEMP_MAX, highBD.intValue());
            dataMap.putInt(Constants.KEY_WEATHER_TEMP_MIN, lowBD.intValue());
            dataMap.putInt(Constants.KEY_WEATHER_ID, weatherId);
            dataMap.putString(Constants.KEY_WEATHER_UNIT, Utility.isMetric(this) ? "C" : "F");
        }

        DataManager.getInstance().syncDataMap(mGoogleApiClient, dataMap, Constants.PATH_WEATHER_DATA, this);

    }
 
开发者ID:mladenbabic,项目名称:Advanced_Android_Development_Wear,代码行数:38,代码来源:WearableWeatherService.java

示例9: createSummaryNotificationBuilder

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private static NotificationCompat.Builder createSummaryNotificationBuilder(
        @NonNull Context context, @NonNull String notificationContentText,
        @NonNull String notificationTitle) {
    int iconId = R.mipmap.ic_launcher;
    Resources resources = context.getResources();

    // Normally when loading resources you should utilize a library like Glide, since this is a
    // sample we keep it simple.
    Bitmap largeIcon = BitmapFactory.decodeResource(resources,
            Utility.getArtResourceForWeatherCondition(iconId));

    // NotificationCompatBuilder is a very convenient way to build
    // backward-compatible notifications; just input data.
    NotificationCompat.Builder builder =
            new NotificationCompat.Builder(context)
                    .setColor(resources.getColor(R.color.sunshine_light_blue))
                    .setSmallIcon(iconId)
                    .setLargeIcon(largeIcon)
                    .setContentTitle(notificationContentText)
                    .setContentText(notificationTitle);

    // Make something interesting happen when the user clicks on the
    // notification. In this case, opening the app is sufficient.
    Intent resultIntent = new Intent(context, MainActivity.class);

    // The stack builder object will contain an artificial back stack for the
    // started Activity. This ensures that navigating backward from the
    // Activity leads out of your application to the Home screen.
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(context);
    stackBuilder.addNextIntent(resultIntent);
    PendingIntent resultPendingIntent =
            stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
            );
    builder.setContentIntent(resultPendingIntent);

    return builder;
}
 
开发者ID:googlecodelabs,项目名称:getting-ready-for-android-n,代码行数:40,代码来源:SunshineSyncEngine.java

示例10: notifyWear

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private void notifyWear() {
    String locationQuery = Utility.getPreferredLocation(getContext());
    Uri weatherUri = WeatherContract.WeatherEntry
            .buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis());
    Cursor cursor = getContext().getContentResolver()
            .query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);
    if (cursor.moveToFirst()) {
        int weatherId = cursor.getInt(INDEX_WEATHER_ID);
        double high = cursor.getDouble(INDEX_MAX_TEMP);
        double low = cursor.getDouble(INDEX_MIN_TEMP);

        Log.d(LOG_TAG, "Sending weather information to android wear");

        PutDataMapRequest dataMap = PutDataMapRequest.create(WEATHER_DATA_PATH);
        dataMap.getDataMap().putDouble(WEATHER_DATA_HIGH, high);
        dataMap.getDataMap().putDouble(WEATHER_DATA_LOW, low);
        dataMap.getDataMap().putLong(WEATHER_DATA_ID, weatherId);
        PutDataRequest request = dataMap.asPutDataRequest();

        Log.d(LOG_TAG, "GoogleApiClient " + MainActivity.mGoogleApiClient.isConnected());

        Wearable.DataApi.putDataItem(MainActivity.mGoogleApiClient, request)
                .setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                    @Override
                    public void onResult(DataApi.DataItemResult result) {
                        if (!result.getStatus().isSuccess()) {
                            Log.d(LOG_TAG, "Cannot send weather information, status code: "
                                    + result.getStatus().getStatusCode());
                        } else {
                            Log.d(LOG_TAG, "Weather information was sent successfully "
                                    + result.getDataItem().getUri());
                        }
                    }
                });
    }
}
 
开发者ID:DmitryMalkovich,项目名称:go-ubiquitous,代码行数:37,代码来源:SunshineSyncAdapter.java

示例11: updateWatchFace

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private void updateWatchFace(){
    Log.d(LOG_TAG, "Update WatchFace ");
    String locationQuery = Utility.getPreferredLocation(getContext());

    Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis());

    // we'll query our contentProvider, as always
    Cursor cursor = getContext().getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);

    if (cursor.moveToFirst()) {
        int weatherId = cursor.getInt(INDEX_WEATHER_ID);
        double mMaxTemp = cursor.getDouble(INDEX_MAX_TEMP);
        double mMinTemp = cursor.getDouble(INDEX_MIN_TEMP);

        if (mGoogleApiClient != null) {
            mGoogleApiClient.connect();
            String id = UUID.randomUUID().toString();

            Log.d(LOG_TAG, "id = " + id + ",mMaxTemp " + mMaxTemp + ", mMinTemp " + mMinTemp + ", weatherId "+ weatherId);

            PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(KEY_PATH);
            putDataMapRequest.getDataMap().putString(KEY_UUID, id);
            putDataMapRequest.getDataMap().putString(KEY_MAX_TEMP, Utility.formatTemperature(getContext(), mMaxTemp));
            putDataMapRequest.getDataMap().putString(KEY_MIN_TEMP, Utility.formatTemperature(getContext(), mMinTemp));
            putDataMapRequest.getDataMap().putInt(KEY_WEATHER_ID, weatherId);

            PutDataRequest request = putDataMapRequest.asPutDataRequest();
            Wearable.DataApi.putDataItem(mGoogleApiClient, request).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
                @Override
                public void onResult(DataApi.DataItemResult dataItemResult) {
                    if (!dataItemResult.getStatus().isSuccess()) {
                        Log.d(LOG_TAG, "updateWatchFace failed");
                    }
                }
            });
        }
    }

}
 
开发者ID:jenniferlimtan,项目名称:UdacityProject6,代码行数:40,代码来源:SunshineSyncAdapter.java

示例12: getWeatherAsset

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private Asset getWeatherAsset(int weatherId) {
    int iconId = Utility.getIconResourceForWeatherCondition(weatherId);
    Bitmap weatherIcon = BitmapFactory.decodeResource(getContext().getResources(), iconId);
    ByteArrayOutputStream weatherIconByteStream = new ByteArrayOutputStream();
    weatherIcon.compress(Bitmap.CompressFormat.PNG, 100, weatherIconByteStream);
    return Asset.createFromBytes(weatherIconByteStream.toByteArray());
}
 
开发者ID:chi6rag,项目名称:SunshineWear,代码行数:8,代码来源:SunshineSyncAdapter.java

示例13: 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

示例14: syncWithWear

import com.example.android.sunshine.app.Utility; //导入依赖的package包/类
private void syncWithWear(Bitmap largeIcon, double high, double low) {
    Context context = getContext();
    final GoogleApiClient mGoogleApiClient;
    boolean mResolvingError = false;


    final String WEATHER_PATH = "/weather";
    final String WEATHER_TEMP_HIGH_KEY = "weather_temp_high_key";
    final String WEATHER_TEMP_LOW_KEY = "weather_temp_low_key";
    final String WEATHER_TEMP_ICON_KEY = "weather_temp_icon_key";

    mGoogleApiClient = new GoogleApiClient.Builder(context)
            .addApi(Wearable.API)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(Bundle bundle) {
                    Log.v("Watch log", "Google API Client was connected");
                }

                @Override
                public void onConnectionSuspended(int i) {
                    Log.v("Watch Log", "Connection to Google API client was suspended");
                }
            })
            .addOnConnectionFailedListener(new GoogleApiClient.OnConnectionFailedListener() {
                @Override
                public void onConnectionFailed(ConnectionResult result) {
                    Log.e("Watch Log", "Connection to Google API client has failed");
                }
            })
            .build();

    mGoogleApiClient.connect();


    Asset asset = toAsset(Bitmap.createScaledBitmap(largeIcon, 52, 52, true));

    PutDataMapRequest putDataMapRequest = PutDataMapRequest.create(WEATHER_PATH);
    putDataMapRequest.getDataMap().putString(WEATHER_TEMP_HIGH_KEY, Utility.formatTemperature(context, high));
    putDataMapRequest.getDataMap().putString(WEATHER_TEMP_LOW_KEY, Utility.formatTemperature(context, low));
    putDataMapRequest.getDataMap().putAsset(WEATHER_TEMP_ICON_KEY, asset);
    putDataMapRequest.getDataMap().putLong("timestamp", System.currentTimeMillis());


    PutDataRequest request = putDataMapRequest.asPutDataRequest();
    Wearable.DataApi.putDataItem(mGoogleApiClient, request).setResultCallback(new ResultCallback<DataApi.DataItemResult>() {
        @Override
        public void onResult(DataApi.DataItemResult dataItemResult) {
            if (dataItemResult.getStatus().isSuccess()) {
                Log.e("Watch Log", "Successfully send weather info");
            } else {
                Log.e("Watch Log", "Failed to send weather info ");
            }
            mGoogleApiClient.disconnect();
        }
    });
}
 
开发者ID:Hitesh880443,项目名称:SunshineWithWear,代码行数:58,代码来源:SunshineSyncAdapter.java

示例15: 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);
}
 
开发者ID:hieple7985,项目名称:nano-go-ubiquitous,代码行数:58,代码来源:SunshineSyncAdapter.java


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