ServiceLocationFragment.java 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. package com.usai.apex;
  2. //
  3. //import com.google.android.gms.maps.GoogleMap;
  4. //import com.google.android.gms.maps.MapFragment;
  5. //import com.google.android.gms.maps.SupportMapFragment;
  6. //import com.google.android.gms.maps.model.LatLng;
  7. //import com.google.android.gms.maps.model.MarkerOptions;
  8. import com.google.android.gms.maps.GoogleMap;
  9. import com.google.android.gms.maps.GoogleMap.OnInfoWindowClickListener;
  10. import com.google.android.gms.maps.GoogleMap.OnMarkerClickListener;
  11. import com.google.android.gms.maps.CameraUpdateFactory;
  12. import com.google.android.gms.maps.MapFragment;
  13. import com.google.android.gms.maps.SupportMapFragment;
  14. import com.google.android.gms.maps.model.CameraPosition;
  15. import com.google.android.gms.maps.model.LatLng;
  16. import com.google.android.gms.maps.model.LatLngBounds;
  17. import com.google.android.gms.maps.model.Marker;
  18. import com.google.android.gms.maps.model.MarkerOptions;
  19. import com.usai.util.Network;
  20. import android.annotation.SuppressLint;
  21. import android.content.Intent;
  22. import android.os.Build;
  23. //import android.app.Fragment;
  24. //import android.app.FragmentManager;
  25. //import android.app.FragmentManager;
  26. //import android.app.Fragment;
  27. //import android.app.FragmentManager;
  28. //import android.app.FragmentManager;
  29. import android.os.Bundle;
  30. import android.support.v4.app.Fragment;
  31. import android.support.v4.app.FragmentManager;
  32. //import android.support.v4.app.FragmentManager;
  33. import android.view.LayoutInflater;
  34. import android.view.View;
  35. import android.view.ViewGroup;
  36. import android.widget.Toast;
  37. public class ServiceLocationFragment extends Fragment implements
  38. OnMarkerClickListener, OnInfoWindowClickListener
  39. {
  40. static final CameraPosition US =
  41. new CameraPosition.Builder().target(new LatLng(37.646374,
  42. -122.398847))
  43. .zoom(2.5f)
  44. .bearing(0)
  45. .tilt(0)
  46. .build();
  47. private SupportMapFragment fragment;
  48. private GoogleMap map;
  49. //
  50. @Override
  51. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  52. Bundle savedInstanceState)
  53. {
  54. return inflater.inflate(R.layout.fragment_service_location, container,
  55. false);
  56. }
  57. @Override
  58. public void onActivityCreated(Bundle savedInstanceState)
  59. {
  60. super.onActivityCreated(savedInstanceState);
  61. FragmentManager fm = getChildFragmentManager();
  62. fragment = (SupportMapFragment) fm.findFragmentById(R.id.map);
  63. if (fragment == null)
  64. {
  65. fragment = new SupportMapFragment();// .newInstance();
  66. fm.beginTransaction().replace(R.id.map, fragment).commit();
  67. }
  68. }
  69. @Override
  70. public void onResume()
  71. {
  72. super.onResume();
  73. if (map == null)
  74. {
  75. map = fragment.getMap();
  76. map.addMarker(new MarkerOptions().position(new LatLng(37.646374,
  77. -122.398847)).title("Apex Maritime Co., Inc.").snippet("Click for more info."));
  78. }
  79. if(map!=null)
  80. setUpMap();
  81. }
  82. private void setUpMap()
  83. {
  84. // // Hide the zoom controls as the button panel will cover it.
  85. // map.getUiSettings().setZoomControlsEnabled(false);
  86. //
  87. // // Add lots of markers to the map.
  88. // addMarkersToMap();
  89. //
  90. // // Setting an info window adapter allows us to change the both the
  91. // contents and look of the
  92. // // info window.
  93. // map.setInfoWindowAdapter(new CustomInfoWindowAdapter());
  94. // Set listeners for marker events. See the bottom of this class for
  95. // their behavior.
  96. map.moveCamera(CameraUpdateFactory.newCameraPosition(US));
  97. map.setOnMarkerClickListener(this);
  98. map.setOnInfoWindowClickListener(this);
  99. // map.setOnMarkerDragListener(this);
  100. // Pan to see all markers in view.
  101. // Cannot zoom to bounds until the map has a size.
  102. // final View mapView = getChildFragmentManager().findFragmentById(
  103. // R.id.map).getView();
  104. // if (mapView.getViewTreeObserver().isAlive())
  105. // {
  106. // mapView.getViewTreeObserver().addOnGlobalLayoutListener(
  107. // new OnGlobalLayoutListener()
  108. // {
  109. // @SuppressWarnings("deprecation")
  110. // // We use the new method when supported
  111. // @SuppressLint("NewApi")
  112. // // We check which build version we are using.
  113. // @Override
  114. // public void onGlobalLayout()
  115. // {
  116. // LatLngBounds bounds = new LatLngBounds.Builder()
  117. // .include(PERTH).include(SYDNEY)
  118. // .include(ADELAIDE).include(BRISBANE)
  119. // .include(MELBOURNE).build();
  120. // if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN)
  121. // {
  122. // mapView.getViewTreeObserver()
  123. // .removeGlobalOnLayoutListener(this);
  124. // }
  125. // else
  126. // {
  127. // mapView.getViewTreeObserver()
  128. // .removeOnGlobalLayoutListener(this);
  129. // }
  130. // map.moveCamera(CameraUpdateFactory.newLatLngBounds(
  131. // bounds, 50));
  132. // }
  133. // });
  134. // }
  135. }
  136. @Override
  137. public void onInfoWindowClick(Marker marker) {
  138. // Toast.makeText(getActivity(), "Click Info Window", Toast.LENGTH_SHORT).show();
  139. Intent intent = new Intent();
  140. intent.setClass(getActivity(), LocationDetailActivity.class);
  141. // intent.putExtra("user", user);
  142. // // intent.putExtra("password", password);
  143. // intent.putExtra("function_name", function_name);
  144. // intent.putExtra("behavior", Network.BEHAVIOR_SEARCH);
  145. startActivity(intent);
  146. }
  147. @Override
  148. public boolean onMarkerClick(Marker arg0)
  149. {
  150. // TODO Auto-generated method stub
  151. return false;
  152. }
  153. }