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


Java Weather类代码示例

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


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

示例1: getWeather

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
/**
 * Get the current weather condition at current location.
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
private void getWeather() {
    //noinspection MissingPermission
    Awareness.SnapshotApi.getWeather(mGoogleApiClient)
            .setResultCallback(new ResultCallback<WeatherResult>() {
                @Override
                public void onResult(@NonNull WeatherResult weatherResult) {
                    if (!weatherResult.getStatus().isSuccess()) {
                        Toast.makeText(SnapshotApiActivity.this, "Could not get weather.", Toast.LENGTH_LONG).show();
                        return;
                    }

                    //parse and display current weather status
                    Weather weather = weatherResult.getWeather();
                    String weatherReport = "Temperature: " + weather.getTemperature(Weather.CELSIUS)
                            + "\nHumidity: " + weather.getHumidity();
                    ((TextView) findViewById(R.id.weather_status)).setText(weatherReport);
                }
            });
}
 
开发者ID:kevalpatel2106,项目名称:android-samples,代码行数:24,代码来源:SnapshotApiActivity.java

示例2: getWeatherSnapshot

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
/**
 * Helper method to retrieve weather data using the Snapshot API.  Since Weather is protected
 * by a runtime permission, this snapshot code is going to be called in multiple places:
 * {@link #printSnapshot()} when the permission has already been accepted, and
 * {@link #onRequestPermissionsResult(int, String[], int[])} when the permission is requested
 * and has been granted.
 */
private void getWeatherSnapshot() {
    if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION)
            == PackageManager.PERMISSION_GRANTED) {
        Awareness.getSnapshotClient(this).getWeather()
                .addOnSuccessListener(new OnSuccessListener<WeatherResponse>() {
                    @Override
                    public void onSuccess(WeatherResponse weatherResponse) {
                        Weather weather = weatherResponse.getWeather();
                        weather.getConditions();
                        mLogFragment.getLogView().println("Weather: " + weather);
                    }
                })
                .addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception e) {
                        Log.e(TAG, "Could not get weather: " + e);
                    }
                });
    }
}
 
开发者ID:googlesamples,项目名称:android-play-awareness,代码行数:28,代码来源:MainActivity.java

示例3: getWeatherConditions

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
/**
 * Provides the current weather conditions at the devices current location
 *
 * @return Single event of the current weather conditions
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
public Single<List<Integer>> getWeatherConditions() {
    return getWeather()
            .map(Weather::getConditions)
            .map(conditions -> {
                List<Integer> list = new ArrayList<>(conditions.length);
                for (int condition : conditions) {
                    list.add(condition);
                }
                return list;
            });
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:18,代码来源:ReactiveSnapshot.java

示例4: setWeather

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
private void setWeather(Weather weather) {
    String weatherText = String.format(Locale.US, "%sC - %s", weather.getTemperature(Weather.CELSIUS), weather.getConditions()[0]);
    ((TextView) findViewById(R.id.weather)).setText(weatherText);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:5,代码来源:MainActivity.java

示例5: create

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
public static Single<Weather> create(Context context) {
    return Single.create(new WeatherSingle(context));
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:5,代码来源:WeatherSingle.java

示例6: unwrap

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
@Override
protected Weather unwrap(WeatherResult result) {
    return result.getWeather();
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:5,代码来源:WeatherSingle.java

示例7: getWeather

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
/**
 * Returns the current weather information at the devices current location
 *
 * @return Single event of weather information
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
public Single<Weather> getWeather() {
    guardWithApiKey(context, API_KEY_AWARENESS_API);
    return WeatherSingle.create(context);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:11,代码来源:ReactiveSnapshot.java

示例8: getHumidity

import com.google.android.gms.awareness.state.Weather; //导入依赖的package包/类
/**
 * Provides the current humidity at the devices current location
 *
 * @return Single event of the current humidity
 */
@RequiresPermission("android.permission.ACCESS_FINE_LOCATION")
public Single<Integer> getHumidity() {
    return getWeather()
            .map(Weather::getHumidity);
}
 
开发者ID:Mauin,项目名称:ReactiveAwareness,代码行数:11,代码来源:ReactiveSnapshot.java


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