• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Weather类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ResourceNamingInterface类代码示例发布时间:2022-05-23
下一篇:
Java ModuleUtils类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap