Android Open Source - AerisAndroidLibrary Observation Fragment






From Project

Back to project page AerisAndroidLibrary.

License

The source code is released under:

Apache License

If you think the Android project AerisAndroidLibrary listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.fragment;
//from  ww  w. jav a 2s.  c  o m
import java.util.Locale;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.demoaerisproject.R;
import com.example.view.DayNightView;
import com.example.view.SmallForecastView;
import com.example.view.TwoPartView;
import com.hamweather.aeris.communication.EndpointType;
import com.hamweather.aeris.model.AerisBatchResponse;
import com.hamweather.aeris.model.ForecastPeriod;
import com.hamweather.aeris.model.Observation;
import com.hamweather.aeris.model.Place;
import com.hamweather.aeris.response.ForecastsResponse;
import com.hamweather.aeris.response.ObservationResponse;
import com.hamweather.aeris.response.PlacesResponse;
import com.hamweather.aeris.util.FileUtil;
import com.hamweather.aeris.util.WeatherUtil;

public class ObservationFragment extends AerisFragment {

  private static final String N_A = "N/A";
  private TextView placeTextView;
  private TextView tempTextView;
  private ImageView iconImageView;
  private TextView weatherShortTextView;
  private TextView feelslikeTextView;

  private TwoPartView humidityView;
  private TwoPartView windsView;
  private TwoPartView dewPointView;
  private TwoPartView pressureView;

  private DayNightView todayView;
  private DayNightView nightView;

  private LinearLayout forecastsLayout;

  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
      Bundle savedInstanceState) {

    View rootView = inflater.inflate(R.layout.fragment_observation,
        container, false);

    placeTextView = (TextView) rootView.findViewById(R.id.tvPlace);
    tempTextView = (TextView) rootView.findViewById(R.id.tvTemperature);
    iconImageView = (ImageView) rootView.findViewById(R.id.ivWeatherIcon);
    weatherShortTextView = (TextView) rootView
        .findViewById(R.id.tvWeatherShort);
    feelslikeTextView = (TextView) rootView.findViewById(R.id.tvFeelsLike);
    humidityView = (TwoPartView) rootView.findViewById(R.id.viewHumidity);
    windsView = (TwoPartView) rootView.findViewById(R.id.viewWinds);
    dewPointView = (TwoPartView) rootView.findViewById(R.id.viewDewPoint);
    pressureView = (TwoPartView) rootView.findViewById(R.id.viewPressure);
    todayView = (DayNightView) rootView.findViewById(R.id.viewToday);
    nightView = (DayNightView) rootView.findViewById(R.id.viewTonight);
    forecastsLayout = (LinearLayout) rootView
        .findViewById(R.id.llObservationForecasts);
    return rootView;
  }

  @Override
  public void showProgress() {
    super.showProgress();

  }

  @Override
  public void hideProgress() {
    super.hideProgress();

  }

  private void setObservation(Observation ob) {
    tempTextView.setText(WeatherUtil.appendDegree(ob.tempF));
    weatherShortTextView.setText(ob.weatherShort);
    feelslikeTextView.setText("Feels like "
        + WeatherUtil.appendDegree(ob.feelslikeF));
    iconImageView.setImageResource(FileUtil.getDrawableByName(ob.icon,
        getActivity()));

    if (ob.humidity != null) {
      humidityView.setText("Humidity", ob.humidity.intValue() + "%");
    } else {
      humidityView.setText("Humidity", N_A);
    }

    dewPointView.setText("Dew Point",
        WeatherUtil.appendDegree(ob.dewpointF));

    if (ob.pressureIN != null) {
      pressureView.setText("Pressure", ob.pressureIN.doubleValue()
          + " IN");
    } else {
      pressureView.setText("Pressure", N_A);
    }

    if (ob.windDir != null) {
      windsView.setText("Winds", String.format(Locale.ENGLISH,
          "%s %d mph", ob.windDir, ob.windSpeedMPH.intValue()));
    } else {
      windsView.setText("Winds", N_A);
    }

  }

  private void setPlace(Place place) {
    String temp = String.format("%s, %s, %s", place.name, place.state,
        place.country);
    placeTextView.setText(temp);

  }

  @Override
  public void onBatchResponse(AerisBatchResponse response) {
    if (todayView == null) {
      return;
    }
    if (response.isSuccessful() && response.getError() == null) {
      ObservationResponse obResponse = new ObservationResponse(
          response.responses.get(0).getFirstResponse());
      Observation ob = obResponse.getObservation();
      setObservation(ob);

      PlacesResponse pResponse = new PlacesResponse(response.responses
          .get(1).getFirstResponse());
      setPlace(pResponse.getPlace());

      ForecastsResponse fResponse = new ForecastsResponse(
          response.responses.get(2).getFirstResponse());

      String dayTitle1 = "Today";
      String dayTitle2 = "Tonight";
      if (fResponse.getPeriod(0).isDay == false) {
        dayTitle1 = "Tonight";
        dayTitle2 = "Tomorrow";
      }
      todayView.setPeriod(fResponse.getPeriod(0), dayTitle1);
      nightView.setPeriod(fResponse.getPeriod(1), dayTitle2);

      ForecastsResponse hoursResponse = new ForecastsResponse(
          response.responses.get(3).getFirstResponse());

      forecastsLayout.removeAllViews();
      for (ForecastPeriod p : hoursResponse.getPeriods()) {
        SmallForecastView view = new SmallForecastView(getActivity());
        view.setForecast(p);
        forecastsLayout.addView(view);
      }

      HeadlessFragment headless = HeadlessFragment
          .getFragment(getActivity());
      headless.storeResponse(HeadlessFragment.DETAILED_OBSERVATION,
          response);
    } else {
      handleError(response.getError());
    }
  }

  @Override
  void performRequest() {
    headlessFragment.performDetailedObservation(this);

  }

  @Override
  EndpointType getEndpointType() {
    return null;
  }

  @Override
  String getKey() {
    return HeadlessFragment.DETAILED_OBSERVATION;
  }
}




Java Source Code List

aeris.AerisUnusedStub.java
com.example.customendpoint.CustomEndpointAdapter.java
com.example.customendpoint.CustomMoonModel.java
com.example.customendpoint.CustomSunModel.java
com.example.customendpoint.CustomSunmoonFragment.java
com.example.customendpoint.CustomSunmoonHolder.java
com.example.customendpoint.CustomSunmoonModel.java
com.example.customendpoint.CustomSunmoonResponse.java
com.example.db.MyLocLoader.java
com.example.db.MyPlace.java
com.example.db.MyPlacesDb.java
com.example.db.MyPlacesSubject.java
com.example.db.SimpleCursorLoader.java
com.example.demoaerisproject.AerisDialog.java
com.example.demoaerisproject.AerisNotification.java
com.example.demoaerisproject.BaseApplication.java
com.example.demoaerisproject.DrawerActivity.java
com.example.demoaerisproject.LocationSearchActivity.java
com.example.demoaerisproject.MyLocsActivity.java
com.example.demoaerisproject.SettingsActivity.java
com.example.edithelp.EditTextEnterListener.java
com.example.edithelp.EnterPressedDelegate.java
com.example.fragment.AerisFragment.java
com.example.fragment.AerisPrefFragment.java
com.example.fragment.ExtForecastFragment.java
com.example.fragment.HeadlessFragment.java
com.example.fragment.MapFragment.java
com.example.fragment.NearbyObsFragment.java
com.example.fragment.ObservationFragment.java
com.example.fragment.OverviewFragment.java
com.example.fragment.RecentObsFragment.java
com.example.fragment.RefreshInterface.java
com.example.fragment.SplashFragment.java
com.example.fragment.WeekendFragment.java
com.example.listview.AdapterHolder.java
com.example.listview.DayNightPeriod.java
com.example.listview.ForecastAdapter.java
com.example.listview.ForecastItemHolder.java
com.example.listview.IndexMonitorAdapter.java
com.example.listview.ListAdapter.java
com.example.listview.ObservationAdapter.java
com.example.listview.ObservationItemHolder.java
com.example.listview.ObservationPeriodAdapter.java
com.example.listview.PlacesAdapter.java
com.example.listview.PlacesItemHolder.java
com.example.listview.RecentObsHolder.java
com.example.listview.WeekendAdapter.java
com.example.listview.WeekendItemHolder.java
com.example.menudrawer.HomeFragment.java
com.example.menudrawer.NavDrawerItem.java
com.example.menudrawer.NavDrawerListAdapter.java
com.example.preference.PrefManager.java
com.example.service.NotificationService.java
com.example.service.ScreenOnReceiver.java
com.example.service.ScreenOnService.java
com.example.util.FormatUtil.java
com.example.view.DayNightView.java
com.example.view.SmallForecastView.java
com.example.view.TemperatureInfoData.java
com.example.view.TemperatureWindowAdapter.java
com.example.view.TwoPartView.java