Example #1
0
  private void ChangeFragmentsDisplay() {
    FrameLayout frame1 = (FrameLayout) findViewById(R.id.fragment);
    FrameLayout frame2 = (FrameLayout) findViewById(R.id.fragment2);
    // get Display size
    int width = getDisplayWidth();
    /*          LANDSCAPE           */
    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
      if (width >= 800) {
        int widthNew = width / 3;
        frame1.getLayoutParams().width = widthNew;
        frame2.setVisibility(View.VISIBLE);
        frame2.getLayoutParams().width = width - widthNew;

        if (weatherFragment != null) {
          if (weatherFragment.isAdded()) {
            long id = weatherFragment.getCityID();
            String city = weatherFragment.getCityName();

            if (!isBigDisplay) this.onBackPressed();

            weatherFragment = WeatherFragment.newInstance(city, id);
          } else {
            weatherFragment = WeatherFragment.newInstance(null, 0);
          }
        } else {
          weatherFragment = WeatherFragment.newInstance(null, 0);
        }
        getSupportFragmentManager()
            .beginTransaction()
            .add(R.id.fragment2, weatherFragment)
            .commit();
        menuFragment.changeOrientationToLandscape();
        isBigDisplay = true;
      }
      /*          PORTRAIT           */
    } else {
      if (isBigDisplay) {
        if (isFullScreenWeather) onMenuClick();

        frame1.setLayoutParams(
            new FrameLayout.LayoutParams(
                FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
        frame2.setVisibility(View.GONE);
        if (weatherFragment != null) {
          weatherFragment.setArgs(null, 0);
          getSupportFragmentManager().beginTransaction().remove(weatherFragment).commit();
        }
        menuFragment.changeOrientationToPortrait();
        isBigDisplay = false;
      }
    }
  }
Example #2
0
 @Override
 public void onCitySelected(City city) {
   if (isBigDisplay) {
     weatherFragment.setArgs(city.getName(), city.getId());
   } else {
     weatherFragment = WeatherFragment.newInstance(city.getName(), city.getId());
     getSupportFragmentManager()
         .beginTransaction()
         .replace(R.id.fragment, weatherFragment)
         .addToBackStack(null)
         .commit();
   }
 }