Advertisement
minafaw3

CrimesMapFragment

Jan 28th, 2016
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.71 KB | None | 0 0
  1. package org.aidmaid;
  2.  
  3. import android.app.Activity;
  4. import android.net.Uri;
  5. import android.os.Bundle;
  6. import android.support.v4.app.Fragment;
  7. import android.view.LayoutInflater;
  8. import android.view.View;
  9. import android.view.ViewGroup;
  10. import android.webkit.WebSettings;
  11. import android.webkit.WebView;
  12.  
  13. import com.google.android.gms.maps.GoogleMap;
  14. import com.google.android.gms.maps.MapView;
  15. import com.google.android.gms.maps.MapsInitializer;
  16. import com.google.android.gms.maps.SupportMapFragment;
  17. import com.google.android.gms.maps.model.BitmapDescriptorFactory;
  18. import com.google.android.gms.maps.model.GroundOverlayOptions;
  19. import com.google.android.gms.maps.model.LatLng;
  20. import com.google.android.gms.maps.model.LatLngBounds;
  21. import com.google.android.gms.maps.model.MarkerOptions;
  22.  
  23.  
  24. /**
  25. * A simple {@link Fragment} subclass.
  26. * Use the {@link CrimesMapFragment#newInstance} factory method to
  27. * create an instance of this fragment.
  28. */
  29. public class CrimesMapFragment extends Fragment {
  30.  
  31. /**
  32. * Use this factory method to create a new instance of
  33. * this fragment using the provided parameters.
  34. *
  35. * @return A new instance of fragment CrimesMapFragment.
  36. */
  37. // TODO: Rename and change types and number of parameters
  38. public static CrimesMapFragment newInstance() {
  39. CrimesMapFragment fragment = new CrimesMapFragment();
  40. return fragment;
  41. }
  42.  
  43. @Override
  44. public void onViewCreated(View view, Bundle savedInstanceState)
  45. {
  46. //Image view to rotate as a compass
  47. //setUpMapIfNeeded();
  48. }
  49.  
  50. @Override
  51. public void onResume()
  52. {
  53. super.onResume();
  54. }
  55.  
  56. public CrimesMapFragment() {
  57. // Required empty public constructor
  58. }
  59.  
  60. @Override
  61. public void onCreate(Bundle savedInstanceState) {
  62. super.onCreate(savedInstanceState);
  63.  
  64. //setUpMapIfNeeded();
  65. }
  66.  
  67. private GoogleMap mMap; // Might be null if Google Play services APK is not available.
  68. private MapView mMapView; // Might be null if Google Play services APK is not available.
  69.  
  70. @Override
  71. public View onCreateView(LayoutInflater inflater, ViewGroup container,
  72. Bundle savedInstanceState) {
  73. // Inflate the layout for this fragment
  74. View view = inflater.inflate(R.layout.fragment_crimes_map, container,
  75. false);
  76.  
  77. WebView myBrowser = (WebView)view.findViewById(R.id.crimeMapWebView);
  78.  
  79.  
  80. WebSettings settings = myBrowser.getSettings();//.setJavaScriptEnabled(true);
  81. settings.setJavaScriptEnabled(true);
  82. settings.setAllowFileAccessFromFileURLs(true); //Maybe you don't need this rule
  83. settings.setAllowUniversalAccessFromFileURLs(true);
  84. myBrowser.loadUrl("file:///android_asset/crime.html");
  85. // mMapView = (MapView) view.findViewById(R.id.mapView);
  86. // mMapView.onCreate(savedInstanceState);
  87. //
  88. // mMapView.onResume();// needed to get the map to display immediately
  89. //
  90. // try {
  91. // MapsInitializer.initialize(getActivity().getApplicationContext());
  92. // } catch (Exception e) {
  93. // e.printStackTrace();
  94. // }
  95. //
  96. // mMap = mMapView.getMap();
  97. //
  98. // if(mMap == null)
  99. // return view;
  100. //
  101. // LatLngBounds leftNewarkBounds = new LatLngBounds(
  102. // new LatLng(-85, -180), // top left corner of map
  103. // new LatLng(85, 0)); // North east corner
  104. //
  105. // GroundOverlayOptions leftNewarkMap = new GroundOverlayOptions()
  106. // .image(BitmapDescriptorFactory.fromResource(R.drawable.crimes_map_left))
  107. // .positionFromBounds(leftNewarkBounds);
  108. // mMap.addGroundOverlay(leftNewarkMap);
  109. //
  110. // LatLngBounds rightNewarkBounds = new LatLngBounds(
  111. // new LatLng(-85, 0), // top left corner of map
  112. // new LatLng(85, 180)); // North east corner
  113. //
  114. // GroundOverlayOptions rightNewarkMap = new GroundOverlayOptions()
  115. // .image(BitmapDescriptorFactory.fromResource(R.drawable.crimes_map_right))
  116. // .positionFromBounds(rightNewarkBounds);
  117. // mMap.addGroundOverlay(rightNewarkMap);
  118.  
  119. return view;
  120. }
  121.  
  122. // TODO: Rename method, update argument and hook method into UI event
  123. public void onButtonPressed(Uri uri) {
  124. //if (mListener != null) {
  125. // mListener.onFragmentInteraction(uri);
  126. //}
  127. }
  128.  
  129. @Override
  130. public void onAttach(Activity activity) {
  131. super.onAttach(activity);
  132.  
  133. }
  134.  
  135. @Override
  136. public void onDetach() {
  137.  
  138. mMap = null;
  139. mMapView = null;
  140. super.onDetach();
  141. }
  142.  
  143.  
  144. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement