Android Open Source - YourWiFi Network Map Fragment






From Project

Back to project page YourWiFi.

License

The source code is released under:

MIT License

If you think the Android project YourWiFi 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.akisute.yourwifi.app;
//from ww  w .  ja v  a 2 s  .  c o m
import android.location.Location;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.akisute.android.daggered.DaggeredFragment;
import com.akisute.yourwifi.app.model.LocationScanManager;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.MapView;
import com.google.android.gms.maps.MapsInitializer;
import com.google.android.gms.maps.model.LatLng;

import org.jetbrains.annotations.Nullable;

import javax.inject.Inject;

import butterknife.ButterKnife;
import butterknife.InjectView;

public class NetworkMapFragment extends DaggeredFragment implements GoogleMap.OnMyLocationButtonClickListener {

    @Inject
    LocationScanManager mLocationScanManager;
    @InjectView(R.id.mapView)
    MapView mMapView;

    private GoogleMap mMap;
    private Bundle mOnMemorySavedInstanceState;

    //-------------------------------------------------------------------------
    // Fragment
    //-------------------------------------------------------------------------

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_network_map, container, false);
        ButterKnife.inject(this, view);

        boolean hasSavedInstanceState = (savedInstanceState != null || mOnMemorySavedInstanceState != null);
        if (savedInstanceState == null && mOnMemorySavedInstanceState != null) {
            mMapView.onCreate(mOnMemorySavedInstanceState);
            mOnMemorySavedInstanceState = null;
        } else {
            mMapView.onCreate(savedInstanceState);
        }
        MapsInitializer.initialize(getActivity()); // Required before CameraUpdateFactory usage: http://stackoverflow.com/questions/19541915/google-maps-cameraupdatefactory-not-initalized
        mMap = mMapView.getMap();
        if (mMap != null) {
            // Google Map is available, lets use it
            mMap.setMyLocationEnabled(true);
            mMap.setOnMyLocationButtonClickListener(this);
            if (!hasSavedInstanceState) {
                setMapCameraPositionToCurrentLocation(false);
            }
        } else {
            // Google Map is not available, just hide the map and display labels to explain
            mMapView.setVisibility(View.GONE);
        }

        return view;
    }

    @Override
    public void onDestroy() {
        // Make sure to save current instance state to bundle, even when managing FragmentManager won't.
        mOnMemorySavedInstanceState = new Bundle();
        onSaveInstanceState(mOnMemorySavedInstanceState);

        super.onDestroy();
        mMapView.onDestroy();
    }

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

    @Override
    public void onPause() {
        super.onPause();
        mMapView.onPause();
    }

    @Override
    public void onLowMemory() {
        super.onLowMemory();
        mMapView.onLowMemory();
    }

    @Override
    public void onSaveInstanceState(Bundle outState) {
        super.onSaveInstanceState(outState);
        mMapView.onSaveInstanceState(outState);
    }

    //-------------------------------------------------------------------------
    // GoogleMap Listeners
    //-------------------------------------------------------------------------

    private void setMapCameraPositionToCurrentLocation(boolean animated) {
        Location currentLocation = mLocationScanManager.getCurrentLocation();
        LatLng latlng = new LatLng(currentLocation.getLatitude(), currentLocation.getLongitude());
        if (animated) {
            mMap.animateCamera(CameraUpdateFactory.newLatLng(latlng));
        } else {
            mMap.moveCamera(CameraUpdateFactory.newLatLng(latlng));
        }
    }

    @Override
    public boolean onMyLocationButtonClick() {
        setMapCameraPositionToCurrentLocation(true);
        return true;
    }
}




Java Source Code List

com.akisute.yourwifi.app.Application.java
com.akisute.yourwifi.app.CloudLoginDialogFragment.java
com.akisute.yourwifi.app.EssidDetailActivity.java
com.akisute.yourwifi.app.EssidDetailFragment.java
com.akisute.yourwifi.app.EssidListFragment.java
com.akisute.yourwifi.app.MainActivity.java
com.akisute.yourwifi.app.NetworkMapFragment.java
com.akisute.yourwifi.app.NetworkRecordingService.java
com.akisute.yourwifi.app.RawNetworkListFragment.java
com.akisute.yourwifi.app.SettingsActivity.java
com.akisute.yourwifi.app.SettingsFragment.java
com.akisute.yourwifi.app.cloud.CloudManager.java
com.akisute.yourwifi.app.dagger.AndroidSystemModule.java
com.akisute.yourwifi.app.dagger.ApplicationModule.java
com.akisute.yourwifi.app.intent.Intents.java
com.akisute.yourwifi.app.model.BssidListAdapter.java
com.akisute.yourwifi.app.model.EssidComparators.java
com.akisute.yourwifi.app.model.EssidListAdapter.java
com.akisute.yourwifi.app.model.Essid.java
com.akisute.yourwifi.app.model.LocationScanManager.java
com.akisute.yourwifi.app.model.NetworkCache.java
com.akisute.yourwifi.app.model.NetworkComparators.java
com.akisute.yourwifi.app.model.NetworkScanManager.java
com.akisute.yourwifi.app.model.Network.java
com.akisute.yourwifi.app.model.RawNetworkListAdapter.java
com.akisute.yourwifi.app.util.GlobalEventBus.java
com.akisute.yourwifi.app.util.GlobalResources.java
com.akisute.yourwifi.app.util.GlobalSharedPreferences.java