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
  protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    try {
      dataBase = new DataBaseHelper(getApplicationContext());
    } catch (Exception e) {
      deleteDatabase(DataBaseHelper.DATABASE_NAME); // delete DataBase
    }

    // Check that the activity is using the layout version with
    // the fragment_container FrameLayout
    if (findViewById(R.id.fragment) != null) {
      if (savedInstanceState != null) {
        return;
      }
      // Create a new Fragment to be placed in the activity layout
      menuFragment = new MenuFragment();

      // In case this activity was started with special instructions from an
      // Intent, pass the Intent's extras to the fragment as arguments
      menuFragment.setArguments(getIntent().getExtras());

      // Add the fragment to the 'fragment_container' FrameLayout
      getSupportFragmentManager().beginTransaction().add(R.id.fragment, menuFragment).commit();
    }

    if (getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE)
      isAppLoadingAsLandScape = true;
    // Orientation must be PORTRAIT while app loading
    setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  }
Example #3
0
 @Override
 public void displayCities(List<City> cities) {
   if (!cities.isEmpty()) {
     for (City city : cities) {
       menuFragment.addCity(city);
     }
   }
 }
Example #4
0
 @Override
 public void CitySaved(City city) {
   if (city != null) {
     if (city.getName() != null) {
       menuFragment.addCity(city);
       dialogFragment.dismiss();
     }
   } else {
     Toast.makeText(
             this.getApplicationContext(),
             "This city already is in your Favourites",
             Toast.LENGTH_SHORT)
         .show();
   }
 }