Advertisement
realanton12345

TestFragment

Oct 8th, 2018
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.10 KB | None | 0 0
  1. package antonmatveyenka.testapp;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.support.annotation.Nullable;
  6. import android.support.v4.app.Fragment;
  7. import android.support.v4.app.FragmentActivity;
  8. import android.view.LayoutInflater;
  9. import android.view.View;
  10. import android.view.ViewGroup;
  11. import android.widget.Button;
  12.  
  13. import com.google.android.gms.maps.CameraUpdateFactory;
  14. import com.google.android.gms.maps.GoogleMap;
  15. import com.google.android.gms.maps.MapView;
  16. import com.google.android.gms.maps.MapsInitializer;
  17. import com.google.android.gms.maps.OnMapReadyCallback;
  18. import com.google.android.gms.maps.SupportMapFragment;
  19. import com.google.android.gms.maps.model.LatLng;
  20. import com.google.android.gms.maps.model.MarkerOptions;
  21.  
  22. public class TestFragment extends Fragment implements OnMapReadyCallback, View.OnClickListener {
  23.  
  24.  
  25.     private MainActivity MA;
  26.     private MapView mMapView;
  27.     private GoogleMap googleMap;
  28.     private Button buttonToSwitch;
  29.  
  30.     public TestFragment() {};
  31.  
  32.     public void setMainActivity(MainActivity MA) {
  33.         this.MA = MA;
  34.     }
  35.  
  36.     @Nullable
  37.     @Override
  38.     public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
  39.         return inflater.inflate(R.layout.fragment_layout, container, false);
  40.     }
  41.  
  42.     @Override
  43.     public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
  44.         super.onViewCreated(view, savedInstanceState);
  45.         this.getActivity().setTitle("Мероприятия");
  46.  
  47.         this.buttonToSwitch = (Button) view.findViewById(R.id.button);
  48.         this.buttonToSwitch.setOnClickListener(this);
  49.  
  50.         mMapView = (MapView) view.findViewById(R.id.mapView);
  51.         mMapView.onCreate(savedInstanceState);
  52.         mMapView.onResume();
  53.         try {
  54.             MapsInitializer.initialize(getActivity().getApplicationContext());
  55.         } catch (Exception e) {
  56.             e.printStackTrace();
  57.         }
  58.         mMapView.getMapAsync(this);
  59.     }
  60.  
  61.     @Override
  62.     public void onResume() {
  63.         super.onResume();
  64.         mMapView.onResume();
  65.     }
  66.  
  67.     @Override
  68.     public void onPause() {
  69.         super.onPause();
  70.         mMapView.onPause();
  71.     }
  72.  
  73.     @Override
  74.     public void onDestroy() {
  75.         super.onDestroy();
  76.         mMapView.onDestroy();
  77.     }
  78.  
  79.     @Override
  80.     public void onLowMemory() {
  81.         super.onLowMemory();
  82.         mMapView.onLowMemory();
  83.     }
  84.  
  85.     @Override
  86.     public void onCreate(@Nullable Bundle savedInstanceState) {
  87.         super.onCreate(savedInstanceState);
  88.     }
  89.  
  90.     @Override
  91.     public void onMapReady(GoogleMap googleMap) {
  92.         this.googleMap = googleMap;
  93.         LatLng Pinsk = new LatLng(52.1313878, 26.1099338);
  94.         this.googleMap.addMarker(new MarkerOptions()
  95.                 .position(Pinsk)
  96.                 .title("Пинск, стадион ДОСААФ"));
  97.         this.googleMap.moveCamera(CameraUpdateFactory.newLatLng(Pinsk));
  98.     }
  99.  
  100.     @Override
  101.     public void onClick(View view) {
  102.         this.MA.replaceFragment();
  103.     }
  104. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement