packageorg.marcinzelent.liberavem;importandroid.content.Intent;importandroid.net.Uri;importandroid.os.Bundle;importandroid.support.annotation.NonNull;importandroid.support.design.widget.FloatingActionButton;importandroid.support.design.widget.Snackbar;importandroid.support.v4.app.Fragment;importandroid.support.v4.app.FragmentManager;importandroid.support.v4.app.FragmentTransaction;importandroid.support.v4.widget.SwipeRefreshLayout;importandroid.view.View;importandroid.support.design.widget.NavigationView;importandroid.support.v4.view.GravityCompat;importandroid.support.v4.widget.DrawerLayout;importandroid.support.v7.app.ActionBarDrawerToggle;importandroid.support.v7.app.AppCompatActivity;importandroid.support.v7.widget.Toolbar;importandroid.view.Menu;importandroid.view.MenuItem;importandroid.widget.AdapterView;importandroid.widget.ListView;importandroid.widget.Toast;importcom.android.volley.Request;importcom.android.volley.Response;importcom.android.volley.VolleyError;importcom.android.volley.toolbox.StringRequest;importcom.google.gson.Gson;importcom.google.gson.GsonBuilder;importjava.util.List;publicclassMainActivityextendsAppCompatActivityimplementsNavigationView.OnNavigationItemSelectedListener,ObservationsFragment.OnFragmentInteractionListener,AtlasFragment.OnFragmentInteractionListener{FragmentobservationsFragment=null;@OverrideprotectedvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);Toolbartoolbar=findViewById(R.id.toolbar);setSupportActionBar(toolbar);if(savedInstanceState==null){ClassfragmentClass=null;fragmentClass=ObservationsFragment.class;try{observationsFragment=(Fragment)fragmentClass.newInstance();}catch(Exceptione){e.printStackTrace();}FragmentManagerfragmentManager=getSupportFragmentManager();fragmentManager.beginTransaction().replace(R.id.flContent,observationsFragment).commit();}DrawerLayoutdrawer=findViewById(R.id.drawer_layout);ActionBarDrawerToggletoggle=newActionBarDrawerToggle(this,drawer,toolbar,R.string.navigation_drawer_open,R.string.navigation_drawer_close);drawer.addDrawerListener(toggle);toggle.syncState();NavigationViewnavigationView=findViewById(R.id.nav_view);navigationView.getMenu().getItem(0).setChecked(true);navigationView.setNavigationItemSelectedListener(this);}@OverridepublicvoidonBackPressed(){DrawerLayoutdrawer=findViewById(R.id.drawer_layout);if(drawer.isDrawerOpen(GravityCompat.START)){drawer.closeDrawer(GravityCompat.START);}else{super.onBackPressed();}}@OverridepublicbooleanonCreateOptionsMenu(Menumenu){// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main,menu);returntrue;}@OverridepublicbooleanonOptionsItemSelected(MenuItemitem){// Handle action bar item clicks here. The action bar will// automatically handle clicks on the Home/Up button, so long// as you specify a parent activity in AndroidManifest.xml.intid=item.getItemId();//noinspection SimplifiableIfStatementif(id==R.id.action_search){returntrue;}returnsuper.onOptionsItemSelected(item);}@SuppressWarnings("StatementWithEmptyBody")@OverridepublicbooleanonNavigationItemSelected(@NonNullMenuItemitem){// Handle navigation view item clicks here.intid=item.getItemId();Fragmentfragment=null;ClassfragmentClass=null;if(id==R.id.nav_observations){fragmentClass=ObservationsFragment.class;}elseif(id==R.id.nav_atlas){fragmentClass=AtlasFragment.class;}elseif(id==R.id.nav_settings){IntentsettingsIntent=newIntent(this,SettingsActivity.class);startActivity(settingsIntent);}elseif(id==R.id.nav_about){}if(fragmentClass!=null){try{fragment=(Fragment)fragmentClass.newInstance();}catch(Exceptione){e.printStackTrace();}FragmentManagerfragmentManager=getSupportFragmentManager();fragmentManager.beginTransaction().replace(R.id.flContent,fragment).commit();}DrawerLayoutdrawer=findViewById(R.id.drawer_layout);drawer.closeDrawer(GravityCompat.START);returntrue;}@OverridepublicvoidonFragmentInteraction(Uriuri){}}