Android Open Source - Android_Yellow_Pages_App_TDD Google Map Fragment






From Project

Back to project page Android_Yellow_Pages_App_TDD.

License

The source code is released under:

Apache License

If you think the Android project Android_Yellow_Pages_App_TDD listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.tddrampup.fragments;
//from  w  ww.  j  a  v  a2s.com
import android.location.Location;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.inject.Inject;
import com.tddrampup.R;
import com.tddrampup.factories.CameraUpdateFactoryWrapperInterface;
import com.tddrampup.factories.MarkerOptionsFactoryWrapperInterface;
import com.tddrampup.models.Listing;
import com.tddrampup.singletons.ListingsInterface;

import roboguice.activity.RoboFragmentActivity;
import roboguice.fragment.RoboFragment;

/**
 * Created by WX009-PC on 2/19/14.
 */
public class GoogleMapFragment extends RoboFragment {

    public GoogleMap map;
    public GoogleMap.OnMyLocationChangeListener mListener;
    // TODO: ^ this is shit

    @Inject
    CameraUpdateFactoryWrapperInterface cameraUpdateFactory;

    @Inject
    MarkerOptionsFactoryWrapperInterface markerOptionsFactory;

    @Inject
    ListingsInterface mListings;

    public GoogleMapFragment() {}

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.google_map_fragment, container, false);
        return rootView;
    }

    @Override
    public void onResume() {
        super.onResume();

        if (map == null) {
            RoboFragmentActivity activity = (RoboFragmentActivity) getActivity();
            FragmentManager fragmentManager = activity.getSupportFragmentManager();
            map = ((SupportMapFragment) fragmentManager.findFragmentById(R.id.google_map)).getMap();
            if (map != null) {
                setupMap();
            }
        }
    }

    public void setupMap() {
        map.setMyLocationEnabled(true);
        addMarkers();
        mListener = new GoogleMap.OnMyLocationChangeListener() {
            @Override
            public void onMyLocationChange(Location location) {
                if (location != null) {
                    LatLng myLatLng = new LatLng(location.getLatitude(), location.getLongitude());
                    map.animateCamera(cameraUpdateFactory.newLatLngZoom(myLatLng, 15.f));
                    map.setOnMyLocationChangeListener(null);
                }
            }
        };
        map.setOnMyLocationChangeListener(mListener);
    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        Fragment fragment = getFragmentManager().findFragmentById(R.id.google_map);
        if (fragment != null)
            getFragmentManager().beginTransaction().remove(fragment).commit();
    }

    public void addMarkers() {
        for(Listing tempListing : mListings.getListings()) {
            if (tempListing.getGeoCode() != null) {
                LatLng coordinates = new LatLng(Double.parseDouble(tempListing.getGeoCode().getLatitude()), Double.parseDouble(tempListing.getGeoCode().getLongitude()));
                map.addMarker(markerOptionsFactory.getOptions(tempListing.getName(), coordinates));
            }
        }
    }
}




Java Source Code List

android.UnusedStub.java
com.tddrampup.ApplicationModule.java
com.tddrampup.YellowApplication.java
com.tddrampup.activities.MainActivity.java
com.tddrampup.adapters.ListingAdapter.java
com.tddrampup.factories.CameraUpdateFactoryWrapperInterface.java
com.tddrampup.factories.CameraUpdateFactoryWrapper.java
com.tddrampup.factories.MarkerOptionsFactoryWrapperInterface.java
com.tddrampup.factories.MarkerOptionsFactoryWrapper.java
com.tddrampup.fragments.DetailFragment.java
com.tddrampup.fragments.GoogleMapFragment.java
com.tddrampup.fragments.HomeFragment.java
com.tddrampup.fragments.ListFragment.java
com.tddrampup.models.Address.java
com.tddrampup.models.GeoCode.java
com.tddrampup.models.Keywords.java
com.tddrampup.models.Listing.java
com.tddrampup.models.Phone.java
com.tddrampup.models.Products.java
com.tddrampup.models.Profile.java
com.tddrampup.models.Summary.java
com.tddrampup.models.YellowResponse.java
com.tddrampup.serviceLayers.VolleyServiceLayerCallback.java
com.tddrampup.serviceLayers.VolleyServiceLayer.java
com.tddrampup.singletons.ListingsInterface.java
com.tddrampup.singletons.Listings.java
com.tddrampup.views.MapView.java