Пример #1
0
  private void findUI() {

    devDialog = new AlertDialog.Builder(ForecastActivity.this, R.style.AppCompatAlertDialogStyle);
    devDialog.setTitle("Печеньку?");
    devDialog.setMessage("К сожалению раздел находится в разработке...");
    devDialog.setPositiveButton(
        "ОК",
        new DialogInterface.OnClickListener() {
          @Override
          public void onClick(DialogInterface dialogInterface, int i) {
            dialogInterface.dismiss();
          }
        });

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    drawerLayout = (DrawerLayoutWithViewPager) findViewById(R.id.drawer_layout);
    navigationView = (NavigationView) findViewById(R.id.nav_view);
    b_cities = navigationView.getHeaderView(0).findViewById(R.id.b_cities);
    pagerMaterial = (ViewPager) navigationView.getHeaderView(0).findViewById(R.id.pager_material);
    pagerCity = (ViewPager) navigationView.getHeaderView(0).findViewById(R.id.pager_city);

    topbar = (LinearLayout) drawerLayout.findViewById(R.id.topbar);
    summary_box = (LinearLayout) drawerLayout.findViewById(R.id.summary_box);
    summary_city = (TextView) drawerLayout.findViewById(R.id.city);
    summary_daily = (TextView) drawerLayout.findViewById(R.id.summary);
    // summary_hourly = (TextView) drawerLayout.findViewById(R.id.summary_hourly);
    summary_city.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fadein));
    summary_daily.startAnimation(AnimationUtils.loadAnimation(this, R.anim.fadein));

    scroll = (SwipeRefreshLayout) drawerLayout.findViewById(R.id.scroll);
    scroll.setProgressViewOffset(false, -100, 100);
  }
Пример #2
0
 @Override
 public void onBackPressed() {
   if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
     drawerLayout.closeDrawer(GravityCompat.START);
   } else {
     super.onBackPressed();
   }
 }
Пример #3
0
  @SuppressWarnings("StatementWithEmptyBody")
  @Override
  public boolean onNavigationItemSelected(MenuItem item) {
    // Handle navigation view item clicks here.
    if (item.isChecked()) return true;

    int id = item.getItemId();
    final ForecastFragment fragment;

    switch (id) {
      case R.id.review:
        fragment = new CurrentlyFragment();
        break;
      case R.id.daily:
        fragment = new DailyFragment();
        break;
      case R.id.hourly:
        fragment = new HourlyForecast();
        break;
      default:
        devDialog.show();
        return true;
    }

    new Handler()
        .postDelayed(
            new Runnable() {
              @Override
              public void run() {
                getFragmentManager()
                    .beginTransaction()
                    // .setCustomAnimations(R.animator.slide_in_up, R.animator.slide_out_up)
                    .replace(R.id.frame, fragment, FRAGMENT_TAG)
                    .commit();
              }
            },
            300);
    drawerLayout.closeDrawer(GravityCompat.START);
    return true;
  }
Пример #4
0
  @Override
  protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    findUI();

    setSupportActionBar(toolbar);
    getSupportActionBar().setElevation(0);
    ActionBarDrawerToggle drawerToggle =
        new ActionBarDrawerToggle(
            this,
            drawerLayout,
            toolbar,
            R.string.navigation_drawer_open,
            R.string.navigation_drawer_close);
    drawerLayout.setDrawerListener(drawerToggle);
    drawerToggle.syncState();

    navigationView.setNavigationItemSelectedListener(this);

    // Initialise
    drawerLayout.setViewPager(navigationView, R.id.pager_material);
    scroll.setColorSchemeResources(R.color.colorPrimary);
    scroll.setOnRefreshListener(this);

    pagerMaterial.setAdapter(new MaterialPageAdapter(this));
    pagerMaterial.setPageTransformer(true, new MaterialTransformer());
    pagerCity.setAdapter(new CityPageAdapter(this));

    pagerMaterial.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            pagerCity.onTouchEvent(event);
            return false;
          }
        });
    pagerCity.setOnTouchListener(
        new View.OnTouchListener() {
          @Override
          public boolean onTouch(View v, MotionEvent event) {
            pagerMaterial.onTouchEvent(event);
            return false;
          }
        });

    pagerCity.setOnPageChangeListener(
        new ViewPager.OnPageChangeListener() {
          @Override
          public void onPageScrolled(
              int position, float positionOffset, int positionOffsetPixels) {}

          @Override
          public void onPageSelected(int position) {
            WeatherController.getInstance()
                .setCurrentCity(WeatherController.getInstance().getCities().get(position));
            try {
              ((ForecastFragment) getFragmentManager().findFragmentByTag(FRAGMENT_TAG)).update();
            } catch (ClassCastException ignored) {

            }
          }

          @Override
          public void onPageScrollStateChanged(int state) {}
        });
    Log.d(TAG, "Updating forecast for current city");
    pagerCity.setCurrentItem(WeatherController.getInstance().getIDCurrentCity());
    pagerMaterial.setCurrentItem(WeatherController.getInstance().getIDCurrentCity());

    b_cities.setOnClickListener(
        new View.OnClickListener() {
          @Override
          public void onClick(View v) {
            startActivityForResult(new Intent(ForecastActivity.this, CitiesActivity.class), 1);
            drawerLayout.closeDrawer(GravityCompat.START);
          }
        });

    if (savedInstanceState == null) onNavigationItemSelected(navigationView.getMenu().getItem(0));
  }