Search in sources :

Example 81 with LocationManager

use of android.location.LocationManager in project IITB-App by wncc.

the class MapFragment method setupWithData.

private void setupWithData(List<Venue> venues) {
    if (getActivity() == null || getView() == null || getContext() == null)
        return;
    // Setup fade animation for background
    int colorFrom = Utils.getAttrColor(getContext(), R.attr.themeColor);
    int colorTo = getResources().getColor(R.color.colorGray);
    ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
    // milliseconds
    colorAnimation.setDuration(250);
    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animator) {
            if (getActivity() == null || getView() == null)
                return;
            getView().findViewById(R.id.main_container).setBackgroundColor((int) animator.getAnimatedValue());
        }
    });
    colorAnimation.start();
    // Show the location fab
    if (getView() == null)
        return;
    ((FloatingActionButton) getView().findViewById(R.id.locate_fab)).show();
    // Start the setup
    Locations mLocations = new Locations(venues);
    data = mLocations.data;
    markerlist = new ArrayList<>(data.values());
    if (getArguments() != null) {
        setupMap(getArguments().getString(Constants.MAP_INITIAL_MARKER));
    }
    // Setup locate button
    FloatingActionButton fab = getView().findViewById(R.id.locate_fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            locate(true);
        }
    });
    // Setup GPS if already has permission and GPS is on
    String permission = Manifest.permission.ACCESS_FINE_LOCATION;
    int res = getContext().checkCallingOrSelfPermission(permission);
    if (res == PackageManager.PERMISSION_GRANTED) {
        final LocationManager manager = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE);
        if (manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
            locate(false);
            setFollowingUser(false);
        }
    }
}
Also used : LocationManager(android.location.LocationManager) ArgbEvaluator(android.animation.ArgbEvaluator) Locations(com.mrane.data.Locations) FloatingActionButton(com.google.android.material.floatingactionbutton.FloatingActionButton) ValueAnimator(android.animation.ValueAnimator) ImageView(android.widget.ImageView) SubsamplingScaleImageView(com.mrane.zoomview.SubsamplingScaleImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) CampusMapView(com.mrane.zoomview.CampusMapView) ExpandableListView(android.widget.ExpandableListView) TextPaint(android.text.TextPaint)

Example 82 with LocationManager

use of android.location.LocationManager in project AndLang by wugemu.

the class NetUtil method isGpsEnabled.

/**
 * Gps是否打开
 *
 * @param context
 * @return
 */
public static boolean isGpsEnabled(Context context) {
    LocationManager locationManager = ((LocationManager) context.getSystemService(Context.LOCATION_SERVICE));
    List<String> accessibleProviders = locationManager.getProviders(true);
    return accessibleProviders != null && accessibleProviders.size() > 0;
}
Also used : LocationManager(android.location.LocationManager)

Example 83 with LocationManager

use of android.location.LocationManager in project Android-SDK by Backendless.

the class EndlessTaggingActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.act_endless_tagging);
    TextView textEndless = (TextView) findViewById(R.id.textEndless);
    Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
    textEndless.setTypeface(typeface);
    adapter = new PointsAdapter(EndlessTaggingActivity.this);
    MapFragment mapFragment = (MapFragment) getFragmentManager().findFragmentById(R.id.map);
    googleMap = mapFragment.getMap();
    googleMap.setMyLocationEnabled(true);
    LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
    Criteria criteria = new Criteria();
    criteria.setAccuracy(Criteria.ACCURACY_FINE);
    criteria.setPowerRequirement(Criteria.POWER_LOW);
    criteria.setAltitudeRequired(false);
    criteria.setBearingRequired(false);
    criteria.setSpeedRequired(false);
    criteria.setCostAllowed(true);
    boolean enabledGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
    if (!enabledGPS) {
        Toast.makeText(EndlessTaggingActivity.this, "No GPS signal", Toast.LENGTH_LONG).show();
    }
    boolean networkIsEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
    if (!networkIsEnabled) {
        Toast.makeText(EndlessTaggingActivity.this, "No Network signal", Toast.LENGTH_LONG).show();
    }
    String provider = locationManager.getBestProvider(criteria, true);
    LocationListener myLocationListener = new LocationListener() {

        @Override
        public void onLocationChanged(Location location) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void onProviderEnabled(String provider) {
        // To change body of implemented methods use File | Settings | File Templates.
        }

        @Override
        public void onProviderDisabled(String provider) {
        // To change body of implemented methods use File | Settings | File Templates.
        }
    };
    Location location = locationManager.getLastKnownLocation(provider);
    locationManager.requestSingleUpdate(criteria, myLocationListener, null);
    if (location != null) {
        latitude = location.getLatitude();
        longitude = location.getLongitude();
        myPosition = new LatLng(latitude, longitude);
        googleMap.addMarker(new MarkerOptions().position(myPosition).icon(BitmapDescriptorFactory.fromResource(R.drawable.marker_red)));
        googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(myPosition, 11));
        googleMap.animateCamera(CameraUpdateFactory.zoomTo(14), 2000, null);
        getCategory();
    } else
        Toast.makeText(EndlessTaggingActivity.this, "Can't determine your location. Check the settings your device and restart the application.", Toast.LENGTH_LONG).show();
    googleMap.setOnMapLongClickListener(new GoogleMap.OnMapLongClickListener() {

        @Override
        public void onMapLongClick(LatLng latLng) {
            latitudeOnMap = latLng.latitude;
            longitudeOnMap = latLng.longitude;
            onMapClick = true;
            AlertDialog.Builder builder = new AlertDialog.Builder(EndlessTaggingActivity.this);
            builder.setMessage(R.string.new_point);
            builder.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    Intent intent = new Intent(EndlessTaggingActivity.this, MakeChoiceActivity.class);
                    startActivityForResult(intent, Default.ADD_NEW_PHOTO_RESULT);
                }
            });
            builder.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                }
            });
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    });
    googleMap.setOnMarkerClickListener(new GoogleMap.OnMarkerClickListener() {

        @Override
        public boolean onMarkerClick(Marker marker) {
            GeoPoint pointEndless = adapter.getPointByMarker(marker);
            if (pointEndless == null || !pointEndless.getMetadata().containsKey("endlessTagging")) {
                return true;
            }
            if (!bitmapToMarkerMap.containsKey(marker)) {
                String markerPhotoUrl = pointEndless.getMetadata("photoUrl");
                new DownloadImageTask(marker).execute(markerPhotoUrl);
            } else
                marker.showInfoWindow();
            return true;
        }
    });
    googleMap.setInfoWindowAdapter(new GoogleMap.InfoWindowAdapter() {

        @Override
        public View getInfoWindow(Marker marker) {
            return null;
        }

        @Override
        public View getInfoContents(Marker marker) {
            View view = getLayoutInflater().inflate(R.layout.custom_info_window, null);
            ImageView imageView = (ImageView) view.findViewById(R.id.imagePhoto);
            if (bitmapToMarkerMap.containsKey(marker))
                imageView.setImageBitmap(bitmapToMarkerMap.get(marker));
            TextView title = (TextView) view.findViewById(R.id.textTitlePoint);
            title.setText(marker.getTitle());
            TextView sniped = (TextView) view.findViewById(R.id.textSnipedPoint);
            sniped.setText(marker.getSnippet());
            return view;
        }
    });
    googleMap.setOnCameraChangeListener(new GoogleMap.OnCameraChangeListener() {

        @Override
        public void onCameraChange(CameraPosition cameraPosition) {
            LatLngBounds visibleRegion = googleMap.getProjection().getVisibleRegion().latLngBounds;
            LatLng topRight = visibleRegion.northeast;
            LatLng botDown = visibleRegion.southwest;
            SWLat = botDown.latitude;
            SWLon = botDown.longitude;
            NELat = topRight.latitude;
            NELon = topRight.longitude;
            searchRectanglePoints(selectedCategories.isEmpty() ? categoriesNames : selectedCategories);
        }
    });
    googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {

        @Override
        public void onInfoWindowClick(Marker marker) {
            for (int i = 0; i < adapter.pointsList.size(); i++) {
                GeoPoint pointData = adapter.pointsList.get(i);
                Map<String, String> newMetaData = pointData.getMetadata();
                final String geoPointId = pointData.getObjectId();
                String name = null;
                String pointName = newMetaData.get("pointName");
                List<String> categoriesPoint = pointData.getCategories();
                for (String category : categoriesPoint) {
                    name = category.toString();
                }
                if (pointName.equals(marker.getTitle())) {
                    Intent intent = new Intent(EndlessTaggingActivity.this, PointCommentsActivity.class);
                    intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
                    intent.putExtra(Default.GEO_POINT_ID, geoPointId);
                    intent.putExtra(Default.SEND_BITMAP, bitmapToMarkerMap.get(marker));
                    startActivityForResult(intent, Default.ADD_NEW_COMMENT);
                }
            }
        }
    });
    Button tagBtn = (Button) findViewById(R.id.tagBtn);
    tagBtn.setTypeface(typeface);
    tagBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent intent = new Intent(EndlessTaggingActivity.this, MakeChoiceActivity.class);
            startActivityForResult(intent, Default.ADD_NEW_PHOTO_RESULT);
        }
    });
    Button filterBtn = (Button) findViewById(R.id.filterBtn);
    filterBtn.setTypeface(typeface);
    filterBtn.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (selectedCategories.size() == 0) {
                Intent intent = new Intent(EndlessTaggingActivity.this, FilterActivity.class);
                startActivityForResult(intent, Default.CATEGORY_RESULT_SEARCH);
            } else {
                Intent intent = new Intent(EndlessTaggingActivity.this, FilterActivity.class);
                String[] array = new String[selectedCategories.size()];
                array = selectedCategories.toArray(array);
                intent.putExtra(Default.SEARCH_CHECK_BOX, array);
                startActivityForResult(intent, Default.CATEGORY_RESULT_SEARCH);
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) Criteria(android.location.Criteria) GoogleMap(com.google.android.gms.maps.GoogleMap) LocationListener(android.location.LocationListener) LocationManager(android.location.LocationManager) Typeface(android.graphics.Typeface) Bundle(android.os.Bundle) MapFragment(com.google.android.gms.maps.MapFragment) Intent(android.content.Intent) GoogleMap(com.google.android.gms.maps.GoogleMap) Location(android.location.Location)

Example 84 with LocationManager

use of android.location.LocationManager in project collect by opendatakit.

the class GoogleFusedLocationClientTest method setUp.

@Before
public void setUp() {
    fusedLocationProviderApi = mock(FusedLocationProviderApi.class);
    googleApiClient = mock(GoogleApiClient.class);
    LocationManager locationManager = mock(LocationManager.class);
    client = new GoogleFusedLocationClient(googleApiClient, fusedLocationProviderApi, locationManager);
}
Also used : LocationManager(android.location.LocationManager) GoogleApiClient(com.google.android.gms.common.api.GoogleApiClient) FusedLocationProviderApi(com.google.android.gms.location.FusedLocationProviderApi) Before(org.junit.Before)

Example 85 with LocationManager

use of android.location.LocationManager in project facebook-android-sdk by facebook.

the class PickerActivity method onStart.

@Override
@SuppressLint("MissingPermission")
protected void onStart() {
    super.onStart();
    if (FRIEND_PICKER.equals(getIntent().getData())) {
        try {
            friendPickerFragment.loadData(false);
        } catch (Exception ex) {
            onError(ex);
        }
    } else if (PLACE_PICKER.equals(getIntent().getData())) {
        try {
            Location location = null;
            Criteria criteria = new Criteria();
            LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
            String bestProvider = locationManager.getBestProvider(criteria, false);
            if (bestProvider != null && checkForLocationPermissionsAndRequest()) {
                location = locationManager.getLastKnownLocation(bestProvider);
                if (locationManager.isProviderEnabled(bestProvider) && locationListener == null) {
                    locationListener = new LocationListener() {

                        @Override
                        public void onLocationChanged(Location location) {
                            boolean updateLocation = true;
                            Location prevLocation = placePickerFragment.getLocation();
                            if (prevLocation != null) {
                                updateLocation = location.distanceTo(prevLocation) >= LOCATION_CHANGE_THRESHOLD;
                            }
                            if (updateLocation) {
                                placePickerFragment.setLocation(location);
                                placePickerFragment.loadData(true);
                            }
                        }

                        @Override
                        public void onStatusChanged(String s, int i, Bundle bundle) {
                        }

                        @Override
                        public void onProviderEnabled(String s) {
                        }

                        @Override
                        public void onProviderDisabled(String s) {
                        }
                    };
                    locationManager.requestLocationUpdates(bestProvider, 1, LOCATION_CHANGE_THRESHOLD, locationListener, Looper.getMainLooper());
                }
            }
            if (location != null) {
                placePickerFragment.setLocation(location);
                placePickerFragment.setRadiusInMeters(SEARCH_RADIUS_METERS);
                placePickerFragment.setSearchText(SEARCH_TEXT);
                placePickerFragment.setResultsLimit(SEARCH_RESULT_LIMIT);
                placePickerFragment.loadData(false);
            }
        } catch (Exception ex) {
            onError(ex);
        }
    }
}
Also used : LocationManager(android.location.LocationManager) Bundle(android.os.Bundle) LocationListener(android.location.LocationListener) Criteria(android.location.Criteria) FacebookException(com.facebook.FacebookException) Location(android.location.Location) SuppressLint(android.annotation.SuppressLint)

Aggregations

LocationManager (android.location.LocationManager)151 Location (android.location.Location)51 Bundle (android.os.Bundle)33 LocationListener (android.location.LocationListener)29 Criteria (android.location.Criteria)21 Intent (android.content.Intent)20 BluetoothAdapter (android.bluetooth.BluetoothAdapter)15 View (android.view.View)10 SuppressLint (android.annotation.SuppressLint)9 IOException (java.io.IOException)9 ConnectivityManager (android.net.ConnectivityManager)7 WifiManager (android.net.wifi.WifiManager)7 TextView (android.widget.TextView)7 DialogInterface (android.content.DialogInterface)6 IntentFilter (android.content.IntentFilter)6 SharedPreferences (android.content.SharedPreferences)6 PendingIntent (android.app.PendingIntent)5 NetworkInfo (android.net.NetworkInfo)5 TelephonyManager (android.telephony.TelephonyManager)5 TrackerDataHelper (com.android.locationtracker.data.TrackerDataHelper)5