Exemplo n.º 1
0
  @Override
  protected void initListeners() {
    ibSettings.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            // NavigationService.navigate(ForecastPageActivity.this, TestActivity.class);
            NavigationService.navigate(ForecastPageActivity.this, SettingsActivity.class);
            finish();
          }
        });

    ibNext.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            int pos = viewPager.getCurrentItem() + 1;
            viewPager.setCurrentItem(pos);
          }
        });

    ibPrevious.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            int pos = viewPager.getCurrentItem() - 1;
            viewPager.setCurrentItem(pos);
          }
        });

    ibRefresh.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            runWeatherUpdate();
          }
        });
  }
Exemplo n.º 2
0
  private void updateUI(final int position) {
    if (!weatherForecast.isSuccessed() || weatherForecast == WeatherForecast.NULL) return;

    swipeIndicatorPresenter.setCurrentActivePosition(position);
    int size = weatherForecast.getForecastList().size();

    if (position == 0) ibPrevious.setAlpha(128);
    else if (position == size - 1) ibNext.setAlpha(128);
    else {
      ibPrevious.setAlpha(255);
      ibNext.setAlpha(255);
    }

    WeatherModel model = weatherForecast.getForecastList().get(position);

    DateUtils utils = new DateUtils();
    String nameOfDay = utils.getDayName(model.getDate());

    tvDate.setText(nameOfDay);

    int currentTemp = Integer.parseInt(model.getMaxTemperature());

    if (currentTemp < 0) tvMinus.setVisibility(View.VISIBLE);
    else {
      int invis = mConfiguration.isTablet() ? View.GONE : View.INVISIBLE;
      tvMinus.setVisibility(invis);
    }
    currentTemp = Math.abs(currentTemp);
    // int margin = resolveMargin(currentTemp);

    tvCurrentTemp.setText("" + currentTemp);

    // setMarginParams(margin, tvCurrentTemp);

    if (mConfiguration.isTablet()) {
      String locationName = mConfiguration.getLocationName();
      locationName = (locationName == null) ? "" : locationName;
      tvLocation.setText(locationName);
    }

    tvNightTemp.setText(model.getMinTemperature());
    if (position == 0) {
      tvHumidity.setText(model.getHumidity() + " %");
      ivHumidity.setImageResource(getHumidityResource((model.getHumidity())));
    } else {
      tvHumidity.setText(model.getPrecipitation());
      ivHumidity.setImageResource(R.drawable.precipmm);
    }

    tvWindSpeed.setText(model.getWindSpeed());
    tvWindDirection.setText(model.getWindDirection().getDisplayName());
    ivLunarState.setImageResource(
        ResourcesCodeUtils.getLunarStateImageResource(model.getLunarState()));

    WeatherState weatherState = model.getState();
    tvWeatherDescription.setText(weatherState.getDisplayName());
    int backgroundColor = ResourcesCodeUtils.getWeatherBackgroundColor(weatherState);

    OWAnimationUtils.rotate(ivWindDirection, Float.parseFloat(model.getWindDegree()) + 180);
    weatherContainer.setBackgroundColor(getResources().getColor(backgroundColor));
  }