团队冲刺第二十二天

今天完善了一下天气方面的相关内容。在显示天气的情况的时候。

在下边提供相关的运动建议。给使用这款跑步软件的使用者们作为参考。

然后在背景图方面。自己设置的是自己每天从网上进行照片的更新。每天的背景都不一样。防止用户出现视觉疲劳。

具体的程序代码如下以及程序运行截图:

复制代码
 //接下去几天的天气的显示
        //时间:2017-4-19  天气状况描述:  天气状况图标    最低温-最高温
        String filename;
        dailyForecastLayout = (LinearLayout) currentView.findViewById(R.id.daily_forecast_layout);
        dailyForecastLayout.removeAllViews();
        LayoutInflater layoutInflater = getLayoutInflater();
        for (HeWeather5.DailyForecastBean dailyForecast : heWeather5.dailyForecastList) {
            View view = layoutInflater.from(this).inflate(R.layout.daily_forecast_item, dailyForecastLayout, false);
            dailyDate = (TextView) view.findViewById(R.id.daily_date);
            dailyWeather = (TextView) view.findViewById(R.id.daily_weather);
            dailyWeatherImage = (ImageView) view.findViewById(R.id.daily_weather_image);
            dailyTemperature = (TextView) view.findViewById(R.id.daily_temperature);

            dailyDate.setText(dailyForecast.date);
            dailyWeather.setText(dailyForecast.cond.dayWeather);
            try {
                filename = dailyForecast.cond.code_d + ".png";
                dailyWeatherImage.setImageBitmap(BitmapFactory.decodeStream(this.getAssets().open(filename)));
            } catch (IOException e) {
                e.printStackTrace();
                LogUtil.d(TAG, "showWeatherInfo: getAssets error");
            }
            dailyTemperature.setText(dailyForecast.tmp.min + "º  " + dailyForecast.tmp.max + "º");
            dailyForecastLayout.addView(view);
        }

        //生活指数
        //体感温度
        weatherSendibleTemperatureTv = (TextView) currentView.findViewById(R.id.weather_sendible_temperature_tv);
        weatherSendibleTemperatureTv.setText("体感温度" + heWeather5.now.fl + "");
        //湿度
        weatherHumitidyTv = (TextView) currentView.findViewById(R.id.weather_humitidy_tv);
        weatherHumitidyTv.setText("湿度" + heWeather5.now.hum + "%");
        //能见度
        weatherVisibilityTv = (TextView) viewList.get(currentPosition).findViewById(R.id.weather_visibility_tv);
        weatherVisibilityTv.setText("能见度" + heWeather5.now.vis + "千米");
        //风向等级
        weatherRiskLevelTv = (TextView) currentView.findViewById(R.id.weather_risk_level_tv);
        weatherRiskLevelTv.setText(heWeather5.now.wind.dir + heWeather5.now.wind.sc + "级");
        //降水量
        weatherPrecipitationTv = (TextView) currentView.findViewById(R.id.weather_precipitation_tv);
        weatherPrecipitationTv.setText("降水量" + heWeather5.now.pcpn + "mm");
        //气压
        weatherPressureTv = (TextView) currentView.findViewById(R.id.weather_pressure_tv);
        weatherPressureTv.setText("气压" + heWeather5.now.pres + "百帕");

        //生活建议
        suggestionComfort = (TextView) currentView.findViewById(R.id.suggesstion_comfort);
        suggestionCarwash = (TextView) currentView.findViewById(R.id.suggesstion_carWash);
        suggestionSport = (TextView) currentView.findViewById(R.id.suggesstion_sport);
        suggestionDressingIndex = (TextView) currentView.findViewById(R.id.suggesstion_hot);

        if (heWeather5.suggestion != null) {
            suggestionComfort.setText("舒适度:" + heWeather5.suggestion.comfort.txt);
            suggestionCarwash.setText("洗车指数:" + heWeather5.suggestion.carWash.txt);
            suggestionSport.setText("运动指数:" + heWeather5.suggestion.sport.txt);
            suggestionDressingIndex.setText("穿衣指数:" + heWeather5.suggestion.hot.txt);
        }
        
        if (null == locationCountyWeatherId && attentionTimes < 3) {
            ++attentionTimes;
            Toast.makeText(WeatherActivity.this, "定位失败,请检查手机设置", Toast.LENGTH_SHORT).show();
        }
    }

    /**
     * 用于判断是否有网络连接
     *
     * @param context 当前上下文
     * @return true 有连接 false 无连接
     */
    public boolean isNetworkConnected(Context context) {
        if (context != null) {
            ConnectivityManager mConnectivityManager = (ConnectivityManager) context
                    .getSystemService(Context.CONNECTIVITY_SERVICE);
            NetworkInfo mNetworkInfo = mConnectivityManager.getActiveNetworkInfo();
            if (mNetworkInfo != null) {
                return mNetworkInfo.isAvailable();
            }
        }
        return false;
    }

    /**
     * 更新背景图片
     */
    public void updateBingPic() {
        String requestBingPic = "http://guolin.tech/api/bing_pic";
        OkHttp.sendRequestOkHttpForGet(requestBingPic, new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
                e.printStackTrace();
            }

            @Override
            public void onResponse(Call call, Response response) throws IOException {
                String bingPic = response.body().string();
                SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(WeatherActivity.this).edit();
                editor.putString("bing_pic", bingPic);
                editor.apply();
            }
        });
    }
复制代码

原文地址:https://www.cnblogs.com/dazhi151/p/13031204.html