bottom navi with 3 fragments, moved mapbox to map fragment and integraded with bottom navbar

This commit is contained in:
Domagalski 2018-09-04 00:01:35 +02:00
parent e36eb8bf0d
commit 7907211934
15 changed files with 357 additions and 72 deletions

View File

@ -1,12 +1,18 @@
package com.uam.wmi.findmytutor.activity;
import android.app.Fragment;
import android.app.FragmentTransaction;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.FloatingActionButton;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import android.view.View;
import android.widget.FrameLayout;
import com.mapbox.mapboxsdk.Mapbox;
import com.mapbox.mapboxsdk.maps.MapView;
@ -19,6 +25,16 @@ import java.util.List;
public class MainActivity extends AppCompatActivity {
private BottomNavigationView mMainNav;
private FrameLayout mMainFrame;
private MapFragment mapFragment;
private NotificationFragment notificationFragment;
private ProfileFragment profileFragment;
private MapView mapView;
public List<Coordinate> getCoordinates() {
@ -36,6 +52,44 @@ public class MainActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
Mapbox.getInstance(this, getString(R.string.access_token));
setContentView(R.layout.activity_main);
mMainFrame = (FrameLayout) findViewById(R.id.main_frame);
mMainNav = (BottomNavigationView) findViewById(R.id.main_nav);
mapFragment = new MapFragment();
notificationFragment = new NotificationFragment();
profileFragment = new ProfileFragment();
// Default frag here
setFragment(mapFragment);
mMainNav.setSelectedItemId(R.id.nav_map);
mMainNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.nav_map:
mMainNav.setItemBackgroundResource(R.color.colorPrimary);
setFragment(mapFragment);
return true;
case R.id.nav_notif:
mMainNav.setItemBackgroundResource(R.color.colorAccent);
setFragment(notificationFragment);
return true;
case R.id.nav_profile:
mMainNav.setItemBackgroundResource(R.color.colorPrimaryDark);
setFragment(profileFragment);
return true;
default:
return false;
}
}
});
// Logout button
final FloatingActionButton button = findViewById(R.id.logoutButton);
button.setOnClickListener(new View.OnClickListener(){
@Override
@ -52,59 +106,16 @@ public class MainActivity extends AppCompatActivity {
}
});
mapView = (MapView) findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
CoordinateService service = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class);
// CoordinateService service = ApiClient.getClient(getApplicationContext())
// .create(CoordinateService.class);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
protected void onDestroy() {
super.onDestroy();
mapView.onDestroy();
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
private void setFragment(Fragment fragment) {
FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.main_frame, fragment);
fragmentTransaction.commit();
}
}

View File

@ -0,0 +1,98 @@
package com.uam.wmi.findmytutor.activity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mapbox.mapboxsdk.maps.MapView;
import com.uam.wmi.findmytutor.R;
import com.uam.wmi.findmytutor.network.ApiClient;
import com.uam.wmi.findmytutor.service.CoordinateService;
import static com.mapbox.mapboxsdk.Mapbox.getApplicationContext;
/**
* A simple {@link Fragment} subclass.
*/
public class MapFragment extends Fragment {
private MapView mapView;
public MapFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_map, container, false);
}
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
mapView = (MapView) view.findViewById(R.id.mapView);
mapView.onCreate(savedInstanceState);
CoordinateService service = ApiClient.getClient(getApplicationContext())
.create(CoordinateService.class);
}
@Override
public void onStart() {
super.onStart();
mapView.onStart();
}
@Override
public void onResume() {
super.onResume();
mapView.onResume();
}
@Override
public void onPause() {
super.onPause();
mapView.onPause();
}
@Override
public void onStop() {
super.onStop();
mapView.onStop();
}
@Override
public void onLowMemory() {
super.onLowMemory();
mapView.onLowMemory();
}
@Override
public void onDestroyView() {
super.onDestroyView();
mapView.onDestroy();
}
// @Override
// public void onDestroy() {
// super.onDestroy();
// mapView.onDestroy();
// }
@Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
mapView.onSaveInstanceState(outState);
}
}

View File

@ -0,0 +1,31 @@
package com.uam.wmi.findmytutor.activity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.uam.wmi.findmytutor.R;
/**
* A simple {@link Fragment} subclass.
*/
public class NotificationFragment extends Fragment {
public NotificationFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_notification, container, false);
}
}

View File

@ -0,0 +1,31 @@
package com.uam.wmi.findmytutor.activity;
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.uam.wmi.findmytutor.R;
/**
* A simple {@link Fragment} subclass.
*/
public class ProfileFragment extends Fragment {
public ProfileFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_profile, container, false);
}
}

View File

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorWhite"
android:state_checked="true"/>
<item android:color="@color/colorWhiteTransparent" />
</selector>

Binary file not shown.

After

Width:  |  Height:  |  Size: 370 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 403 B

View File

@ -7,14 +7,20 @@
android:layout_height="match_parent"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
android:layout_height="wrap_content">
</android.support.design.widget.AppBarLayout>
<!--<com.mapbox.mapboxsdk.maps.MapView-->
<!--android:id="@+id/mapView"-->
<!--android:layout_width="match_parent"-->
<!--android:layout_height="match_parent"-->
<!--mapbox:mapbox_cameraTargetLat="52.466799"-->
<!--mapbox:mapbox_cameraTargetLng="16.927002"-->
<!--mapbox:mapbox_cameraZoom="17"-->
<!--mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">-->
<include layout="@layout/content_main" />
<!--</com.mapbox.mapboxsdk.maps.MapView>-->
<android.support.design.widget.FloatingActionButton
android:id="@+id/logoutButton"
@ -25,13 +31,39 @@
app:backgroundTint="@android:color/holo_red_dark"
app:srcCompat="@android:drawable/ic_lock_power_off" />
<include layout="@layout/content_main" />
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLng="16.927002"
mapbox:mapbox_cameraTargetLat="52.466799"
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8"
mapbox:mapbox_cameraZoom="17" />
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
</android.support.design.widget.AppBarLayout>
<include
android:id="@+id/include"
layout="@layout/content_main" />
<FrameLayout
android:id="@+id/main_frame"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</FrameLayout>
<android.support.design.widget.BottomNavigationView
android:id="@+id/main_nav"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
app:itemBackground="@color/colorPrimaryDark"
app:itemIconTint="@color/nav_item_colors"
app:itemTextColor="@color/nav_item_colors"
app:layout_anchor="@+id/include"
app:layout_anchorGravity="bottom|center"
app:menu="@menu/nav_items"
/>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>

View File

@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
tools:context=".activity.MapFragment">
<com.mapbox.mapboxsdk.maps.MapView
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible"
mapbox:mapbox_cameraTargetLat="52.466799"
mapbox:mapbox_cameraTargetLng="16.927002"
mapbox:mapbox_cameraZoom="17"
mapbox:mapbox_styleUrl="mapbox://styles/domagalsky/cjiyzrqjp05l72rmj6ntvv2n8">
</com.mapbox.mapboxsdk.maps.MapView>
</FrameLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.NotificationFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Notification fragment" />
</FrameLayout>

View File

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".activity.ProfileFragment">
<!-- TODO: Update blank fragment layout -->
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Profile Frag" />
</FrameLayout>

View File

@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/nav_profile"
android:icon="@drawable/outline_person_white_24dp"
android:title="@string/nav_profile" />
<item
android:id="@+id/nav_map"
android:icon="@drawable/outline_map_white_24dp"
android:title="@string/nav_map" />
<item
android:id="@+id/nav_notif"
android:icon="@drawable/outline_notifications_white_24dp"
android:title="@string/nav_notif" />
</menu>

View File

@ -7,4 +7,9 @@
<color name="hint_enter_note">#89c3c3c3</color>
<color name="timestamp">#858585</color>
<color name="note_list_text">#232323</color>
<color name="colorWhite">#ffffff</color>
<color name="colorWhiteTransparent">#80ffffff</color>
</resources>

View File

@ -3,6 +3,11 @@
<string name="title_activity_login">Sign in</string>
<string name="title_activity_startup" translatable="false">StartUp Activity</string>
<!-- Menu -->
<string name="nav_map">Map</string>
<string name="nav_notif">Notification</string>
<string name="nav_profile">Profile</string>
<!-- Tutors list -->
<string name="action_settings">Settings</string>
<string name="activity_title_home">Notes</string>