Last active
July 27, 2017 11:48
-
-
Save mnewlive/123fcc4fe06cb25c1336ec7a57be388c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:orientation="vertical" | |
app:behavior_hideable="true" | |
app:behavior_peekHeight="274dp" | |
app:layout_behavior="android.support.design.widget.BottomSheetBehavior"> | |
<FrameLayout | |
android:id="@+id/bottom_sheet_frame" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:visibility="gone"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" | |
android:layout_marginTop="28dp" | |
android:background="@android:color/white" | |
android:elevation="4dp" | |
android:orientation="vertical" | |
android:paddingTop="@dimen/activity_horizontal_margin"> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="vertical" | |
android:paddingLeft="76dp" | |
android:paddingStart="56dp"> | |
<TextView | |
style="@style/TextAppearance.AppCompat.Headline" | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:text="Super Gym" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:paddingBottom="@dimen/activity_margin_half" | |
android:paddingTop="@dimen/activity_margin_half" | |
android:text="some description" | |
android:textColor="?attr/colorPrimary" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="@dimen/activity_horizontal_margin"> | |
<ImageButton | |
android:layout_width="24dp" | |
android:layout_height="24dp" | |
android:alpha="0.36" | |
android:src="@drawable/ic_location" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="@dimen/activity_horizontal_margin" | |
android:layout_marginStart="@dimen/activity_horizontal_margin" | |
android:text="740, Valencia St, San Francisco, CA" | |
android:textColor="@android:color/primary_text_light" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="@dimen/activity_horizontal_margin"> | |
<ImageButton | |
android:layout_width="24dp" | |
android:layout_height="24dp" | |
android:alpha="0.36" | |
android:src="@drawable/ic_call" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="@dimen/activity_horizontal_margin" | |
android:layout_marginStart="@dimen/activity_horizontal_margin" | |
android:text="(415) 349-0942" | |
android:textColor="@android:color/primary_text_light" /> | |
</LinearLayout> | |
<LinearLayout | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:orientation="horizontal" | |
android:padding="@dimen/activity_horizontal_margin"> | |
<ImageButton | |
android:layout_width="24dp" | |
android:layout_height="24dp" | |
android:alpha="0.36" | |
android:src="@drawable/ic_time" /> | |
<TextView | |
android:layout_width="match_parent" | |
android:layout_height="wrap_content" | |
android:layout_marginLeft="@dimen/activity_horizontal_margin" | |
android:layout_marginStart="@dimen/activity_horizontal_margin" | |
android:text="Wed, 10 AM - 9 PM" | |
android:textColor="@android:color/primary_text_light" /> | |
</LinearLayout> | |
<FrameLayout | |
android:layout_width="match_parent" | |
android:layout_height="320dp" | |
android:background="@android:color/black"> | |
<TextView | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="center" | |
android:text="Your remaining content here" | |
android:textColor="@android:color/white" /> | |
</FrameLayout> | |
</LinearLayout> | |
<android.support.design.widget.FloatingActionButton | |
android:id="@+id/action_button" | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" | |
android:layout_gravity="end" | |
android:layout_marginEnd="@dimen/activity_horizontal_margin" | |
android:layout_marginRight="@dimen/activity_horizontal_margin" | |
android:clickable="true" | |
android:src="@drawable/ic_action_add" | |
android:visibility="gone" /> | |
</FrameLayout> | |
</android.support.v4.widget.NestedScrollView> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BottomSheetFragment extends Fragment { | |
private MapView mapView; | |
private DatabaseReference mFruitRef = FirebaseDatabase.getInstance().getReference("Fruit"); | |
private boolean showFAB = true; | |
private ChildEventListener childEventListener; | |
@Override | |
public void onResume() { | |
super.onResume(); | |
mapView.onResume(); | |
} | |
@Override | |
public void onPause() { | |
super.onPause(); | |
mapView.onPause(); | |
} | |
@Override | |
public void onDestroy() { | |
super.onDestroy(); | |
mapView.onDestroy(); | |
} | |
@Override | |
public void onLowMemory() { | |
super.onLowMemory(); | |
mapView.onLowMemory(); | |
} | |
@Override | |
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { | |
View rootView = inflater.inflate(R.layout.locations, container, false); | |
FrameLayout bottom_sheet_frame = (FrameLayout) rootView.findViewById(R.id.bottom_sheet_frame); | |
setupActionButton((ViewGroup) rootView); | |
mapView = (MapView) rootView.findViewById(R.id.mapView); | |
mapView.onCreate(savedInstanceState); | |
try { | |
MapsInitializer.initialize(getActivity().getApplicationContext()); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
mapView.getMapAsync(new OnMapReadyCallback() { | |
@Override | |
public void onMapReady(GoogleMap googleMap) { | |
googleMap.setOnMarkerClickListener(marker -> false); | |
googleMap.getUiSettings().setZoomControlsEnabled(true); | |
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL); | |
googleMap.getUiSettings().setMapToolbarEnabled(false); | |
setupMarkers(); | |
addMarkersToMap(googleMap); | |
//TODO: check status, refactor | |
googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() { | |
@Override | |
public boolean onMarkerClick(com.google.android.gms.maps.model.Marker marker) { | |
if(marker.getTitle().equals("Orange")) | |
Toast.makeText(getActivity(), marker.getTitle(), Toast.LENGTH_SHORT).show();// display toast | |
bottom_sheet_frame.setVisibility(View.VISIBLE); | |
return false; | |
} | |
}); | |
//TODO: setMyLocationEnabled for fragment | |
if (ContextCompat.checkSelfPermission(getActivity(), | |
android.Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED | |
&& ContextCompat.checkSelfPermission(getActivity(), | |
android.Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { | |
return; | |
} | |
googleMap.setMyLocationEnabled(true); | |
} | |
}); | |
return rootView; | |
} | |
private void setupMarkers() { | |
Marker marker = new Marker("Orange", 47.000327, 28.867950, "some info"); | |
Marker marker2 = new Marker("Bananas", 47.045029, 28.861427, "some info"); | |
Marker marker3 = new Marker("Peaches", 47.024204, 28.889236, "some info"); | |
mFruitRef.push().setValue(marker); | |
mFruitRef.push().setValue(marker2); | |
mFruitRef.push().setValue(marker3); | |
} | |
/** | |
* Setup animation floating button | |
*/ | |
private void setupActionButton(ViewGroup container) { | |
FloatingActionButton actionButton = (FloatingActionButton) container.findViewById(R.id.action_button); | |
CoordinatorLayout coordinatorLayout = (CoordinatorLayout) container.findViewById(R.id.locations); | |
View bottomSheet = coordinatorLayout.findViewById(R.id.bottom_sheet); | |
BottomSheetBehavior behavior = BottomSheetBehavior.from(bottomSheet); | |
final Animation growAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.simple_grow); | |
final Animation shrinkAnimation = AnimationUtils.loadAnimation(getActivity(), R.anim.simple_shrink); | |
actionButton.setVisibility(View.VISIBLE); | |
actionButton.startAnimation(growAnimation); | |
actionButton.setOnClickListener(v -> { | |
Log.d("some", "check Click"); | |
}); | |
shrinkAnimation.setAnimationListener(new Animation.AnimationListener() { | |
@Override | |
public void onAnimationStart(Animation animation) { | |
} | |
@Override | |
public void onAnimationEnd(Animation animation) { | |
actionButton.setVisibility(View.GONE); | |
} | |
@Override | |
public void onAnimationRepeat(Animation animation) { | |
} | |
}); | |
behavior.setBottomSheetCallback(new BottomSheetBehavior.BottomSheetCallback() { | |
@Override | |
public void onStateChanged(@NonNull View bottomSheet, int newState) { | |
switch (newState) { | |
case BottomSheetBehavior.STATE_DRAGGING: | |
if (showFAB) | |
actionButton.startAnimation(shrinkAnimation); | |
break; | |
case BottomSheetBehavior.STATE_COLLAPSED: | |
showFAB = true; | |
actionButton.setVisibility(View.VISIBLE); | |
actionButton.startAnimation(growAnimation); | |
break; | |
case BottomSheetBehavior.STATE_EXPANDED: | |
showFAB = false; | |
break; | |
} | |
} | |
@Override | |
public void onSlide(View bottomSheet, float slideOffset) { | |
} | |
}); | |
} | |
/** | |
* Get marker information from Firebase Database and add it to map | |
*/ | |
private void addMarkersToMap(GoogleMap map) { | |
childEventListener = mFruitRef.addChildEventListener(new ChildEventListener() { | |
@Override | |
public void onChildAdded(DataSnapshot dataSnapshot, String s) { | |
Marker marker = dataSnapshot.getValue(Marker.class); | |
String name = marker.getName(); | |
String description = marker.getDescription(); | |
double latitude = marker.getLatitude(); | |
double longitude = marker.getLongitude(); | |
LatLng location = new LatLng(latitude, longitude); | |
map.addMarker(new MarkerOptions().title(name).snippet(description).position(location)); | |
map.moveCamera(CameraUpdateFactory.newLatLngZoom(location, 13)); | |
} | |
@Override | |
public void onChildChanged(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onChildRemoved(DataSnapshot dataSnapshot) { | |
} | |
@Override | |
public void onChildMoved(DataSnapshot dataSnapshot, String s) { | |
} | |
@Override | |
public void onCancelled(DatabaseError databaseError) { | |
} | |
}); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" > | |
<com.google.android.gms.maps.MapView | |
android:id="@+id/mapView" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent" /> | |
</RelativeLayout> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment