Курсовая работа (т): Разработка информационного приложения для прогноза погоды на платформе Android

Внимание! Если размещение файла нарушает Ваши авторские права, то обязательно сообщите нам

.        }

.        @Override

.        public boolean onCreateOptionsMenu(Menu menu) {

.        getMenuInflater().inflate(R.menu.main, menu);

.        return true;

.        }

.        private class JSONWeatherTask extends AsyncTask<String, Void,

.        Weather> {

.        @Override

.        protected Weather doInBackground(String... params) {Weather weather = new Weather();

.        String data = ( (new WeatherHttpClient()).getWeatherData(params[0],params[1]));

.        try {

.        weather = JSONWeatherParser.getWeather(data);

.        System.out.println("Weather ["+weather+"]");

.        weather.iconData = ( (newWeatherHttpClient()).getImage(weather.currentCondition.getIcon()));

.        } catch (JSONException e) {e.printStackTrace();

.        }

.        return weather;

.        }

.        @Override

.        protected void onPostExecute(Weather weather) {

.        super.onPostExecute(weather);

.        if (weather.iconData != null && weather.iconData.length > 0) {

.        Bitmap img = BitmapFactory.decodeByteArray(weather.iconData, 0,weather.iconData.length);

.        imgView.setImageBitmap(img);

.        }

.        cityText.setText(weather.location.getCity() + "," +weather.location.getCountry());

.        temp.setText("" + Math.round((weather.temperature.getTemp() - 275.15)));

.        condDescr.setText(weather.currentCondition.getCondition() + "(" +weather.currentCondition.getDescr() + ")");

.        temp.setText("" + Math.round((weather.temperature.getTemp() - 275.5)) + "°C");

.        hum.setText("" + weather.currentCondition.getHumidity() + "%");

.        press.setText("" + weather.currentCondition.getPressure() + " hPa");

.        windSpeed.setText("" + weather.wind.getSpeed() + " mps");

.        windDeg.setText("" + weather.wind.getDeg() + "°");

.        }}

.        private class JSONForecastWeatherTask extends AsyncTask<String, Void,WeatherForecast> {

.        @Override

.        protected WeatherForecast doInBackground(String... params) {String data = ( (new WeaterHttpClient()).getForecastWeatherData(params[0], params[1], paras[2]));

.        WeatherForecast forecast = new WeatherForecast();

.        try {

.        forecast = JSONWeatherParser.getForecastWeather(data);

.        System.out.println("Weather ["+forecast+"]");

.        weather.iconData = ( (new WeaterHttpClient()).getImage(weather.currentCondition.getIcon()));

.        } catch (JSONException e) {e.printStackTrace();

.        }return forecast;}

.        @Override

.        protected void onPostExecute(WeatherForecast forecastWeather) {

.        super.onPostExecute(forecastWeather);

.        DailyForecastPageAdapter adapter = new DailForecastPageAdapter(Integer.parseInt(forecastDaysNum), getSpportFragmentManager(), forecastWeather);

.        pager.setAdapter(adapter);}}}

Код интерфейса

.        <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

.        xmlns:tools="http://schemas.android.com/tools"

3.      android:layout_width="match_parent"

.        android:layout_height="wrap_content"

.        android:paddingBottom="@dimen/activity_vertical_margin"

.        android:paddingLeft="@dimen/activity_horizontal_margin"

.        android:paddingRight="@dimen/activity_horizontal_margin"

.        android:paddingTop="@dimen/activity_vertical_margin"

.        tools:context=".MainActivity"

.        android:orientation="vertical" >

.        <RelativeLayout

.        android:layout_width="match_parent"

.        android:layout_height="match_parent"

.        android:paddingBottom="@dimen/activity_vertical_margin"

.        android:paddingRight="@dimen/activity_horizontal_margin"

.        android:paddingTop="@dimen/activity_vertical_margin"

.        tools:context=".MainActivity"

.        android:layout_weight="1" >

.        <TextView

.        android:id="@+id/cityText"

.        style="?android:attr/textAppearanceMedium"

.        android:layout_width="wrap_content"

.        android:layout_height="wrap_content"

.        android:layout_alignParentLeft="true">

.        </TextView>

.        <TextView

.        android:id="@+id/temp"

.        style="@style/tempStyle"

.        android:layout_width="wrap_content"

.        android:layout_height="wrap_content"

.        android:layout_below="@id/cityText"

.        android:layout_centerHorizontal="true">

.        </TextView>

.        <TextView

.        android:id="@+id/unittemp"

.        android:layout_width="wrap_content"

.        style="?android:attr/textAppearanceMedium"

.        android:layout_height="wrap_content"

.        android:layout_below="@id/cityText"

.        android:layout_toRightOf="@id/temp"

.        android:layout_alignBaseline="@id/temp">

.        </TextView>

.        <TextView

.        android:id="@+id/skydesc"

.        android:layout_width="wrap_content"

.        style="?android:attr/textAppearanceMedium"

.        android:layout_height="wrap_content"

.        android:layout_below="@id/temp"

.        android:layout_alignStart="@id/temp"

.        android:layout_toRightOf="@id/temp">

.        </TextView>

.        <!-- Image weather condition -->

.        <ImageView android:id="@+id/condIcon"

.        android:layout_height="wrap_content"

.        android:layout_width="wrap_content"

.        android:layout_alignTop="@id/temp"

.        android:layout_toRightOf="@id/temp"/>

.        </RelativeLayout>

.        <android.support.v4.view.ViewPager

.        android:id="@+id/pager"

.        android:layout_width="match_parent"

.        android:layout_height="match_parent"

.        android:layout_weight="6" >

.        <android.support.v4.view.PagerTitleStrip

.        android:id="@+id/pager_title_strip"

.        android:layout_width="match_parent"

.        android:layout_height="wrap_content"

.        android:layout_gravity="top"

.        android:background="#E6E6E6"

.        android:paddingBottom="4dp"

.        android:paddingTop="4dp"

.        android:textColor="#fff" />

.        </android.support.v4.view.ViewPager>

.        </LinearLayout>

Источник: https://www.bibliofond.ru/detail.aspx?id=723975