fix menu navigation
This commit is contained in:
parent
4e813613ed
commit
6b4b69ad1d
|
@ -1,10 +1,6 @@
|
|||
package at.fhj.swd.dailyhelper.ui.activity;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.FloatingActionButton;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.FragmentTransaction;
|
||||
import android.view.View;
|
||||
import android.support.v4.view.GravityCompat;
|
||||
import android.support.v7.app.ActionBarDrawerToggle;
|
||||
import android.view.MenuItem;
|
||||
|
@ -17,65 +13,38 @@ import android.view.Menu;
|
|||
|
||||
import at.fhj.swd.dailyhelper.R;
|
||||
import at.fhj.swd.dailyhelper.ui.fragemnt.HomeFragment;
|
||||
import at.fhj.swd.dailyhelper.ui.fragemnt.LevelFragment;
|
||||
import at.fhj.swd.dailyhelper.ui.fragemnt.MapFragment;
|
||||
import at.fhj.swd.dailyhelper.ui.fragemnt.WeatherFragment;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener {
|
||||
|
||||
private DrawerLayout drawer;
|
||||
|
||||
private static final String HOME = "home";
|
||||
private static final String WEATHER = "weather";
|
||||
private static final String MAP = "map";
|
||||
private static final String LEVEL = "level";
|
||||
|
||||
|
||||
private HomeFragment homeFragment;
|
||||
private LevelFragment levelFragment;
|
||||
private MapFragment mapFragment;
|
||||
private WeatherFragment weatherFragment;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
homeFragment = new HomeFragment();
|
||||
levelFragment = new LevelFragment();
|
||||
mapFragment = new MapFragment();
|
||||
weatherFragment = new WeatherFragment();
|
||||
|
||||
FloatingActionButton fab = findViewById(R.id.fab);
|
||||
fab.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
|
||||
.setAction("Action", null).show();
|
||||
}
|
||||
});
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
drawer = findViewById(R.id.drawer_layout);
|
||||
NavigationView navigationView = findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||
drawer.addDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
transaction.add(R.id.flFragmentContainer, homeFragment);
|
||||
transaction.add(R.id.flFragmentContainer, levelFragment);
|
||||
transaction.add(R.id.flFragmentContainer, mapFragment);
|
||||
transaction.add(R.id.flFragmentContainer, weatherFragment);
|
||||
if(savedInstanceState == null) {
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
|
||||
navigationView.setCheckedItem(R.id.nav_home);
|
||||
}
|
||||
|
||||
transaction.commit();
|
||||
|
||||
setSelectedFragment(HOME);
|
||||
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -110,49 +79,23 @@ public class MainActivity extends AppCompatActivity
|
|||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(MenuItem item) {
|
||||
// Handle navigation view item clicks here.
|
||||
int id = item.getItemId();
|
||||
|
||||
if (id == R.id.nav_home) {
|
||||
setSelectedFragment(HOME);
|
||||
} else if (id == R.id.nav_weather) {
|
||||
setSelectedFragment(WEATHER);
|
||||
} else if (id == R.id.nav_map) {
|
||||
setSelectedFragment(MAP);
|
||||
// } else if (id == R.id.nav_level) {
|
||||
// setSelectedFragment(LEVEL);
|
||||
switch (item.getItemId()){
|
||||
case R.id.nav_home:
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_map:
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new MapFragment()).commit();
|
||||
break;
|
||||
case R.id.nav_weather:
|
||||
getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new WeatherFragment()).commit();
|
||||
break;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void setSelectedFragment (String fragmentName) {
|
||||
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
|
||||
|
||||
transaction.hide(homeFragment);
|
||||
transaction.hide(levelFragment);
|
||||
transaction.hide(mapFragment);
|
||||
transaction.hide(weatherFragment);
|
||||
System.out.println(fragmentName);
|
||||
switch (fragmentName) {
|
||||
case HOME:
|
||||
transaction.show(homeFragment);
|
||||
break;
|
||||
case LEVEL:
|
||||
transaction.show(levelFragment);
|
||||
break;
|
||||
case MAP:
|
||||
transaction.show(mapFragment);
|
||||
break;
|
||||
case WEATHER:
|
||||
transaction.show(weatherFragment);
|
||||
break;
|
||||
}
|
||||
transaction.commit();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,21 +6,37 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:fitsSystemWindows="true"
|
||||
android:background="@color/cardview_dark_background"
|
||||
tools:context=".ui.activity.MainActivity"
|
||||
tools:openDrawer="start">
|
||||
|
||||
<include
|
||||
layout="@layout/app_bar_main"
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="@color/colorPrimary"
|
||||
android:elevation="4dp"
|
||||
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
|
||||
app:popupTheme="@style/Theme.AppCompat.Light"></android.support.v7.widget.Toolbar>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/fragment_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"></FrameLayout>
|
||||
</LinearLayout>
|
||||
|
||||
<android.support.design.widget.NavigationView
|
||||
android:id="@+id/nav_view"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
android:fitsSystemWindows="true"
|
||||
app:headerLayout="@layout/nav_header_main"
|
||||
app:menu="@menu/activity_main_drawer" />
|
||||
app:headerLayout="@layout/nav_header"
|
||||
app:menu="@menu/drawer_menu">
|
||||
|
||||
</android.support.design.widget.NavigationView>
|
||||
|
||||
</android.support.v4.widget.DrawerLayout>
|
||||
|
|
|
@ -1,39 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activity.MainActivity">
|
||||
|
||||
<android.support.design.widget.AppBarLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:theme="@style/AppTheme.AppBarOverlay">
|
||||
|
||||
<android.support.v7.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="?attr/actionBarSize"
|
||||
android:background="?attr/colorPrimary"
|
||||
app:popupTheme="@style/AppTheme.PopupOverlay" />
|
||||
|
||||
</android.support.design.widget.AppBarLayout>
|
||||
|
||||
<!-- <include layout="@layout/content_main" /> -->
|
||||
<FrameLayout
|
||||
android:id="@+id/flFragmentContainer"
|
||||
android:layout_marginTop="200px"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
</FrameLayout>
|
||||
|
||||
<android.support.design.widget.FloatingActionButton
|
||||
android:id="@+id/fab"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|end"
|
||||
android:layout_margin="@dimen/fab_margin"
|
||||
app:srcCompat="@android:drawable/ic_dialog_email" />
|
||||
|
||||
</android.support.design.widget.CoordinatorLayout>
|
|
@ -1,20 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
tools:context=".ui.activity.MainActivity"
|
||||
tools:showIn="@layout/app_bar_main">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Hello World!"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</android.support.constraint.ConstraintLayout>
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/holo_blue_light">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
@ -9,4 +10,4 @@ android:layout_height="match_parent">
|
|||
android:text="Übersicht, Tempertur, Position, Geschwindigkeit, Wetter"
|
||||
android:textSize="80px"/>
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -1,20 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/holo_green_light">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Wasserwagge"
|
||||
android:textSize="80px"/>
|
||||
<!--
|
||||
<com.google.android.gms.maps.MapView
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</com.google.android.gms.maps.MapView>
|
||||
-->
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -1,20 +1,14 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/holo_orange_light">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="Karte, Aktuelle Position, GPS Koordinaten"
|
||||
android:textSize="80px"/>
|
||||
<!--
|
||||
<com.google.android.gms.maps.MapView
|
||||
android:id="@+id/map"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
||||
</com.google.android.gms.maps.MapView>
|
||||
-->
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -1,7 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/holo_red_light">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
|
@ -10,4 +11,4 @@ android:layout_height="match_parent">
|
|||
android:textSize="80px"/>
|
||||
|
||||
|
||||
</LinearLayout>
|
||||
</RelativeLayout>
|
|
@ -1,3 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="AppTheme.NoActionBar">
|
||||
|
@ -5,4 +6,5 @@
|
|||
<item name="windowNoTitle">true</item>
|
||||
<item name="android:statusBarColor">@android:color/transparent</item>
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
</resources>
|
|
@ -13,8 +13,5 @@
|
|||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.AppBarOverlay" parent="ThemeOverlay.AppCompat.Dark.ActionBar" />
|
||||
|
||||
<style name="AppTheme.PopupOverlay" parent="ThemeOverlay.AppCompat.Light" />
|
||||
|
||||
</resources>
|
||||
|
|
Loading…
Reference in New Issue