List of usage examples for android.location LocationManager NETWORK_PROVIDER
String NETWORK_PROVIDER
To view the source code for android.location LocationManager NETWORK_PROVIDER.
Click Source Link
From source file:com.andrew67.ddrfinder.activity.MapViewer.java
/** * Zooms and moves the map to the user's last known current location, typically on app startup. *//*from w ww . j ava 2s. co m*/ private void zoomToCurrentLocation() { final LocationManager locationManager = (LocationManager) this.getSystemService(LOCATION_SERVICE); Location lastKnown = null; try { lastKnown = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); } catch (SecurityException e) { showMessage(R.string.error_perm_loc); } if (lastKnown != null) { mMap.animateCamera(CameraUpdateFactory .newLatLngZoom(new LatLng(lastKnown.getLatitude(), lastKnown.getLongitude()), BASE_ZOOM)); } }
From source file:com.androzic.location.LocationService.java
private void connect() { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (locationManager != null) { lastLocationMillis = 0;/* w w w . j a v a 2 s . co m*/ pause = 1; isContinous = false; justStarted = true; smoothSpeed = 0.0f; avgSpeed = 0.0f; locationManager.addGpsStatusListener(this); if (useNetwork) { try { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); Log.d(TAG, "Network provider set"); } catch (IllegalArgumentException e) { Toast.makeText(this, getString(R.string.err_no_network_provider), Toast.LENGTH_LONG).show(); } } try { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); locationManager.addNmeaListener(this); Log.d(TAG, "Gps provider set"); } catch (IllegalArgumentException e) { Log.d(TAG, "Cannot set gps provider, likely no gps on device"); } startForeground(NOTIFICATION_ID, getNotification()); } }
From source file:net.movelab.cmlibrary.MapMyData.java
@Override protected void onResume() { Context context = getApplicationContext(); Log.e("TAPMAP", "selectPZ=" + selectNewPrivacyZone); if (Util.trafficCop(this)) finish();//from w w w. ja v a 2 s. com dateRangeText.setBackgroundResource(R.drawable.red_border); if (reloadData) { mPoints.clear(); lastRecId = 0; } isServiceOn = PropertyHolder.isServiceOn(); shareData = PropertyHolder.getShareData(); drawConfidenceCircles = PropertyHolder.getMapAcc(); drawIcons = PropertyHolder.getMapIcons(); satToggle = PropertyHolder.getMapSat(); mapView.setSatellite(satToggle); if (PropertyHolder.getLimitEndDate()) dateRangeText.setText(Util.userDate(PropertyHolder.getMapStartDate()) + " - " + Util.userDate(PropertyHolder.getMapEndDate())); else dateRangeText.setText(Util.userDate(PropertyHolder.getMapStartDate()) + " - " + getResources().getString(R.string.present)); if (Util.needDatabaseUpdate) { progressbarText.setText(getResources().getString(R.string.database_updating_text)); if (updatingDatabase == false) { updatingDatabase = true; new DatabaseUpdateTask().execute(context); } } else { progressNotificationArea.setVisibility(View.VISIBLE); progressbarText.setText(getResources().getString(R.string.mapdata_loading_text)); if (loadingData == false) { loadingData = true; new DataGrabberTask().execute(context); } } receiverNotificationArea.setVisibility(View.INVISIBLE); if (isServiceOn) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { receiverNotificationArea.setVisibility(View.VISIBLE); mReceiversOffWarning.setText(getResources().getString(R.string.noGPSnoNet)); } else { receiverNotificationArea.setVisibility(View.VISIBLE); mReceiversOffWarning.setText(getResources().getString(R.string.noGPS)); } mReceiversOffWarning.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { startActivity(new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS)); } }); } } else { receiverNotificationArea.setVisibility(View.VISIBLE); mReceiversOffWarning.setText(getResources().getString(R.string.main_text_off)); mReceiversOffWarning.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent e) { if (e.getAction() == MotionEvent.ACTION_DOWN) { receiverNotificationArea .setBackgroundColor(getResources().getColor(R.color.push_button_color)); } if (e.getAction() == MotionEvent.ACTION_UP) { receiverNotificationArea.setBackgroundColor(getResources().getColor(R.color.dark_grey)); } return false; } }); mReceiversOffWarning.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE); sendBroadcast(intent); receiverNotificationArea.setVisibility(View.INVISIBLE); } }); } IntentFilter fixFilter; fixFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); fixReceiver = new FixReceiver(); registerReceiver(fixReceiver, fixFilter); super.onResume(); }
From source file:org.koboc.collect.android.activities.GeoPointMapNotDraggableActivity.java
@Override protected void onResume() { super.onResume(); if (mMap == null) { mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); if (mMap == null) { Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured), Toast.LENGTH_SHORT).show(); finish();/*from w w w . j av a 2 s .c o m*/ return; } // clear-value action is handled by widget. /*Zoom only if there's a previous location*/ if (mLatLng != null) { mMarkerOption.position(mLatLng); mMarker = mMap.addMarker(mMarkerOption); mMarker.setDraggable(mCaptureLocation); mZoomed = true; mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } mShowLocation.setClickable(mMarker != null); } if (mRefreshLocation) { mLocationStatus.setVisibility(View.VISIBLE); if (mGPSOn) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } if (mNetworkOn) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } } }
From source file:org.hfoss.posit.android.api.fragment.FindFragment.java
/** * Request Updates whenever the activity is paused. *//*from w w w . ja va 2s . co m*/ @Override public void onResume() { super.onResume(); LocaleManager.setDefaultLocale(getActivity()); // Locale Manager should if (mGeoTagEnabled) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 60000, 0, this); mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 60000, 0, this); Location netLocation = mLocationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); Location gpsLocation = mLocationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); if (gpsLocation != null) { mCurrentLocation = gpsLocation; } else { mCurrentLocation = netLocation; } if (mCurrentLocation == null) { Toast.makeText(getActivity(), "Unable to retrieve GPS info." + " Please make sure your Data or Wi-Fi is enabled.", Toast.LENGTH_SHORT).show(); Log.i(TAG, "Cannot request location updates; Data or Wifi might not be enabled."); } } }
From source file:org.odk.collect.android.activities.GeoPointMapNotDraggableActivity.java
@Override protected void onResume() { super.onResume(); if (mMap == null) { mMap = ((SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map)).getMap(); mHelper = new MapHelper(this, mMap); mHelper.setBasemap();// w w w. j ava 2s . c om if (mMap == null) { Toast.makeText(getBaseContext(), getString(R.string.google_play_services_error_occured), Toast.LENGTH_SHORT).show(); finish(); return; } // clear-value action is handled by widget. /*Zoom only if there's a previous location*/ if (mLatLng != null) { mMarkerOption.position(mLatLng); mMarker = mMap.addMarker(mMarkerOption); mMarker.setDraggable(mCaptureLocation); mZoomed = true; mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(mLatLng, 16)); } mShowLocation.setClickable(mMarker != null); } if (mRefreshLocation) { mLocationStatus.setVisibility(View.VISIBLE); if (mGPSOn) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } if (mNetworkOn) { mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } } }
From source file:edu.princeton.jrpalmer.asmlibrary.Settings.java
@Override protected void onResume() { if (Util.trafficCop(this)) finish();/*from w w w .j a v a 2 s. c o m*/ IntentFilter uploadFilter; uploadFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_UPLOADED); uploadReceiver = new UploadReceiver(); registerReceiver(uploadReceiver, uploadFilter); IntentFilter fixFilter; fixFilter = new IntentFilter( getResources().getString(R.string.internal_message_id) + Util.MESSAGE_FIX_RECORDED); fixReceiver = new FixReceiver(); registerReceiver(fixReceiver, fixFilter); shareMyData = PropertyHolder.getShareData(); toggleParticipationViews(shareMyData); int nUploads = PropertyHolder.getNUploads(); final long participationTime = PropertyHolder.ptCheck(); participationTimeText.setBase(SystemClock.elapsedRealtime() - participationTime); // service button boolean isServiceOn = PropertyHolder.isServiceOn(); mServiceButton.setChecked(isServiceOn); mServiceButton.setOnClickListener(new ToggleButton.OnClickListener() { public void onClick(View view) { if (view.getId() != R.id.service_button) return; Context context = view.getContext(); boolean on = ((ToggleButton) view).isChecked(); String schedule = on ? Util.MESSAGE_SCHEDULE : Util.MESSAGE_UNSCHEDULE; // Log.e(TAG, schedule + on); // now schedule or unschedule Intent intent = new Intent(getString(R.string.internal_message_id) + schedule); context.sendBroadcast(intent); showSpinner(on, storeMyData); if (on && shareMyData) { final long ptNow = PropertyHolder.ptStart(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.start(); ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "on," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } else { final long ptNow = PropertyHolder.ptStop(); participationTimeText.setBase(SystemClock.elapsedRealtime() - ptNow); participationTimeText.stop(); // stop uploader Intent stopUploaderIntent = new Intent(Settings.this, FileUploader.class); // Stop service if it is currently running stopService(stopUploaderIntent); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("ONF", "off," + Util.iso8601(System.currentTimeMillis()) + "," + ptNow)); } } // If user turns CountdownDisplay on but GPS is not on, remind // user to turn // GPS on if (on) { final LocationManager manager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); if (!manager.isProviderEnabled(LocationManager.GPS_PROVIDER)) { if (!manager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { buildAlertMessageNoGpsNoNet(); } else buildAlertMessageNoGps(); } } return; } }); // interval spinner int intspinner_item = android.R.layout.simple_spinner_item; int dropdown_item = android.R.layout.simple_spinner_dropdown_item; ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.interval_array, intspinner_item); adapter.setDropDownViewResource(dropdown_item); mIntervalSpinner.setAdapter(adapter); mIntervalSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_interval) return; if (pos > mInterval.length) return; if (!PropertyHolder.isServiceOn()) { PropertyHolder.setAlarmInterval(mInterval[pos]); return; } PropertyHolder.setAlarmInterval(mInterval[pos]); mServiceButton.setChecked(true); Intent intent = new Intent(getString(R.string.internal_message_id) + Util.MESSAGE_SCHEDULE); Context context = getApplicationContext(); context.sendBroadcast(intent); showSpinner(true, storeMyData); if (shareMyData) { ContentResolver ucr = getContentResolver(); ucr.insert(Util.getUploadQueueUri(context), UploadContentValues.createUpload("INT", Util.iso8601(System.currentTimeMillis()) + "," + mInterval[pos])); } } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int pos = ai2pos(PropertyHolder.getAlarmInterval()); mIntervalSpinner.setSelection(pos); showSpinner(isServiceOn, storeMyData); // mydata buttons // storage spinner storageDays = PropertyHolder.getStorageDays(); mStorageSpinner.setOnItemSelectedListener(new Spinner.OnItemSelectedListener() { public void onItemSelected(AdapterView<?> parent, View v, int pos, long id) { int parentId = parent.getId(); if (parentId != R.id.spinner_mydata) return; if (pos > MAX_STORAGE - MIN_STORAGE) return; PropertyHolder.setStorageDays(pos + MIN_STORAGE); PropertyHolder.setStoreMyData((pos + MIN_STORAGE) > 0); } public void onNothingSelected(AdapterView<?> parent) { // do nothing } }); int storagepos = storageDays - MIN_STORAGE; mStorageSpinner.setSelection(storagepos); // NEW STUFF mToggleSatRadioGroup = (RadioGroup) findViewById(R.id.toggleSatRadioGroup); mToggleIconsRadioGroup = (RadioGroup) findViewById(R.id.toggleIconsRadioGroup); mToggleAccRadioGroup = (RadioGroup) findViewById(R.id.toggleAccRadioGroup); mLimitStartDateRadioGroup = (RadioGroup) findViewById(R.id.limitStartDateRadioGroup); mLimitEndDateRadioGroup = (RadioGroup) findViewById(R.id.limitEndDateRadioGroup); Intent i = getIntent(); if (i.getBooleanExtra(MapMyData.DATES_BUTTON_MESSAGE, false)) { RelativeLayout dateSettingsArea = (RelativeLayout) findViewById(R.id.dateSettingsArea); dateSettingsArea.setFocusable(true); dateSettingsArea.setFocusableInTouchMode(true); dateSettingsArea.requestFocus(); } if (shareMyData && isServiceOn) { participationTimeText.setBase(SystemClock.elapsedRealtime() - PropertyHolder.ptStart()); participationTimeText.start(); } nUploadsText.setText(String.valueOf(nUploads)); if (nUploads >= Util.UPLOADS_TO_PRO && !PropertyHolder.getProVersion() && participationTime >= Util.TIME_TO_PRO) { Util.createProNotification(context); PropertyHolder.setProVersion(true); PropertyHolder.setNeedsDebriefingSurvey(true); } boolean proV = PropertyHolder.getProVersion(); // 19 December 2013: end of research changes mShareDataRadioGroup.check(R.id.sharedataNo); mShareDataRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { if (checkedId == R.id.sharedataYes) { buildSharingOverAnnouncement(); } mShareDataRadioGroup.check(R.id.sharedataNo); } }); /* * if (proV) { * * if (shareMyData) { mShareDataRadioGroup.check(R.id.sharedataYes); if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); } } * else { mShareDataRadioGroup.check(R.id.sharedataNo); } * * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { shareMyData = (checkedId == R.id.sharedataYes); * PropertyHolder.setShareData(shareMyData); * toggleParticipationViews(shareMyData); final boolean on = * PropertyHolder.isServiceOn(); if (shareMyData) { if * (PropertyHolder.isRegistered() == false || * PropertyHolder.hasConsented() == false) { send2Intro(context); * * } if (on) { * * final long ptNow = PropertyHolder.ptStart(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); * * participationTimeText.start(); * * ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "on," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } } else { * * final long ptNow = PropertyHolder.ptStop(); * participationTimeText.setBase(SystemClock .elapsedRealtime() - * ptNow); participationTimeText.stop(); // stop uploader Intent i = new * Intent(Settings.this, FileUploader.class); // Stop service if it is * currently running stopService(i); * * if (on) { ContentResolver ucr = getContentResolver(); * * ucr.insert( Util.getUploadQueueUri(context), * UploadContentValues.createUpload( "ONF", "off," + Util.iso8601(System * .currentTimeMillis()) + "," + ptNow)); * * } * * } * * } }); } else { mShareDataRadioGroup.check(R.id.sharedataYes); * mShareDataRadioGroup .setOnCheckedChangeListener(new * OnCheckedChangeListener() { * * @Override public void onCheckedChanged(RadioGroup group, int * checkedId) { if (checkedId == R.id.sharedataNo) { * mShareDataRadioGroup.check(R.id.sharedataYes); * showCurrentlySharingDialog(); } } }); * * } */ new CheckPendingUploadsSizeTask().execute(context); new CheckUserDbSizeTask().execute(context); deletePendingUploadsButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getUploadQueueUri(context), "1", null); // Log.i("Settings", "number of rows deleted=" + nDeleted); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); deleteUserDbButton = (ImageButton) findViewById(R.id.deleteMyDbButton); deleteUserDbButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { ContentResolver cr = getContentResolver(); final int nDeleted = cr.delete(Util.getFixesUri(context), "1", null); Util.toast(context, String.valueOf(nDeleted) + " " + getResources().getString(R.string.locations_deleted) + "."); updateStorageSizes(); } }); uploadButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (Util.isOnline(context)) { Intent i = new Intent(Settings.this, FileUploader.class); startService(i); new UploadMessageTask().execute(context); } else { Util.toast(context, getResources().getString(R.string.offline_warning)); } } }); mToggleSatRadioGroup.check(PropertyHolder.getMapSat() ? R.id.toggleSatYes : R.id.toggleSatNo); mToggleSatRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapSat(checkedId == R.id.toggleSatYes); } }); mToggleIconsRadioGroup.check(PropertyHolder.getMapIcons() ? R.id.toggleIconsYes : R.id.toggleIconsNo); mToggleIconsRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapIcons(checkedId == R.id.toggleIconsYes); } }); mToggleAccRadioGroup.check(PropertyHolder.getMapAcc() ? R.id.toggleAccYes : R.id.toggleAccNo); mToggleAccRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setMapAcc(checkedId == R.id.toggleAccYes); } }); mStartDateButton = (Button) findViewById(R.id.startDateButton); mEndDateButton = (Button) findViewById(R.id.endDateButton); boolean limitStartDate = PropertyHolder.getLimitStartDate(); boolean limitEndDate = PropertyHolder.getLimitEndDate(); if (!limitStartDate) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } if (!limitEndDate) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } mLimitStartDateRadioGroup.check(limitStartDate ? R.id.limitStartDateYes : R.id.limitStartDateNo); mLimitStartDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitStartDate(checkedId == R.id.limitStartDateYes); if (checkedId != R.id.limitStartDateYes) mStartDateButton.setVisibility(View.GONE); else { mStartDateButton.setVisibility(View.VISIBLE); } } }); mLimitEndDateRadioGroup.check(limitEndDate ? R.id.limitEndDateYes : R.id.limitEndDateNo); mLimitEndDateRadioGroup.setOnCheckedChangeListener(new OnCheckedChangeListener() { @Override public void onCheckedChanged(RadioGroup group, int checkedId) { PropertyHolder.setLimitEndDate(checkedId == R.id.limitEndDateYes); if (checkedId != R.id.limitEndDateYes) mEndDateButton.setVisibility(View.GONE); else { mEndDateButton.setVisibility(View.VISIBLE); } } }); mStartDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapStartDate())); mStartDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new StartDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); mEndDateButton.setText(Util.userDateNoTime(PropertyHolder.getMapEndDate())); mEndDateButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { DialogFragment newFragment = new EndDatePickerFragment(); newFragment.show(getSupportFragmentManager(), "datePicker"); } }); if (PropertyHolder.getNeedsDebriefingSurvey()) { buildProAnnouncement(); PropertyHolder.setNeedsDebriefingSurvey(false); } super.onResume(); }
From source file:com.ternup.caddisfly.fragment.LocationFragment.java
/** * Invoked by the "Start Updates" button * Sends a request to start location updates * * @param v The view object associated with this method, in this case a Button. *//*from w w w.j a va 2s . co m*/ public void startUpdates(View v) { // Get Location Manager and check for GPS & Network location services LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); if (!lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || !lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // Build the alert dialog AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle("Location Services Not Active"); builder.setMessage("Please enable Location Services and GPS"); builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialogInterface, int i) { // Show location settings when the user acknowledges the alert dialog Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivity(intent); } }); Dialog alertDialog = builder.create(); alertDialog.setCanceledOnTouchOutside(false); alertDialog.show(); } else { mUpdatesRequested = true; if (servicesConnected()) { // Turn the indefinite activity indicator on mActivityIndicator.setVisibility(View.VISIBLE); mLocationButton.setVisibility(View.GONE); startPeriodicUpdates(); } } }
From source file:org.odk.collect.android.activities.GeoTraceOsmMapActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.geotrace_osm_layout); setTitle(getString(R.string.geotrace_title)); // Setting title of the action mapView = (MapView) findViewById(R.id.geotrace_mapview); helper = new MapHelper(this, mapView, GeoTraceOsmMapActivity.this); mapView.setMultiTouchControls(true); mapView.setBuiltInZoomControls(true); mapView.getController().setZoom(zoomLevel); myLocationOverlay = new MyLocationNewOverlay(mapView); inflater = this.getLayoutInflater(); traceSettingsView = inflater.inflate(R.layout.geotrace_dialog, null); polygonPolylineView = inflater.inflate(R.layout.polygon_polyline_dialog, null); timeDelay = (Spinner) traceSettingsView.findViewById(R.id.trace_delay); timeDelay.setSelection(3);/*from w ww . jav a2 s. c o m*/ timeUnits = (Spinner) traceSettingsView.findViewById(R.id.trace_scale); layersButton = (ImageButton) findViewById(R.id.layers); layersButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { helper.showLayersDialog(GeoTraceOsmMapActivity.this); } }); locationButton = (ImageButton) findViewById(R.id.show_location); locationButton.setEnabled(false); locationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { reset_trace_settings(); showZoomDialog(); } }); clearButton = (ImageButton) findViewById(R.id.clear); clearButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showClearDialog(); } }); ImageButton saveButton = (ImageButton) findViewById(R.id.geotrace_save); saveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mapMarkers.size() != 0) { alertDialog.show(); } else { saveGeoTrace(); } } }); if (mapMarkers == null || mapMarkers.size() == 0) { clearButton.setEnabled(false); } manualCaptureButton = (Button) findViewById(R.id.manual_button); manualCaptureButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { addLocationMarker(); } }); pauseButton = (ImageButton) findViewById(R.id.pause); playButton = (ImageButton) findViewById(R.id.play); playButton.setEnabled(false); beenPaused = false; traceMode = 1; playButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { if (!playCheck) { if (!beenPaused) { alert.show(); } else { RadioGroup rb = (RadioGroup) traceSettingsView.findViewById(R.id.radio_group); int radioButtonID = rb.getCheckedRadioButtonId(); View radioButton = rb.findViewById(radioButtonID); traceMode = rb.indexOfChild(radioButton); if (traceMode == 0) { setupManualMode(); } else if (traceMode == 1) { setupAutomaticMode(); } else { reset_trace_settings(); } } playCheck = true; } else { playCheck = false; startGeoTrace(); } } }); pauseButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(final View v) { playButton.setVisibility(View.VISIBLE); if (mapMarkers != null && mapMarkers.size() > 0) { clearButton.setEnabled(true); } pauseButton.setVisibility(View.GONE); manualCaptureButton.setVisibility(View.GONE); playCheck = true; modeActive = false; myLocationOverlay.disableFollowLocation(); try { schedulerHandler.cancel(true); } catch (Exception e) { // Do nothing } } }); overlayMapLayerListener(); buildDialogs(); Intent intent = getIntent(); if (intent != null && intent.getExtras() != null) { if (intent.hasExtra(GeoTraceWidget.TRACE_LOCATION)) { String s = intent.getStringExtra(GeoTraceWidget.TRACE_LOCATION); playButton.setEnabled(false); clearButton.setEnabled(true); overlayIntentTrace(s); locationButton.setEnabled(true); //zoomToCentroid(); zoomToBounds(); } } else { myLocationOverlay.runOnFirstFix(centerAroundFix); } Button polygonSaveButton = (Button) polygonPolylineView.findViewById(R.id.polygon_save); polygonSaveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mapMarkers.size() > 2) { createPolygon(); alertDialog.dismiss(); saveGeoTrace(); } else { alertDialog.dismiss(); showPolygonErrorDialog(); } } }); Button polylineSaveButton = (Button) polygonPolylineView.findViewById(R.id.polyline_save); polylineSaveButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { alertDialog.dismiss(); saveGeoTrace(); } }); zoomDialogView = getLayoutInflater().inflate(R.layout.geoshape_zoom_dialog, null); zoomLocationButton = (Button) zoomDialogView.findViewById(R.id.zoom_location); zoomLocationButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { zoomToMyLocation(); mapView.invalidate(); zoomDialog.dismiss(); } }); zoomPointButton = (Button) zoomDialogView.findViewById(R.id.zoom_shape); zoomPointButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { //zoomToCentroid(); zoomToBounds(); mapView.invalidate(); zoomDialog.dismiss(); } }); mapView.invalidate(); LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); List<String> providers = locationManager.getProviders(true); for (String provider : providers) { if (provider.equalsIgnoreCase(LocationManager.GPS_PROVIDER)) { locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); gpsOn = true; } if (provider.equalsIgnoreCase(LocationManager.NETWORK_PROVIDER)) { locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER); networkOn = true; } } if (gpsOn) { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); } if (networkOn) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } }
From source file:eu.geopaparazzi.library.gps.GpsService.java
/** * Starts listening to the gps provider. *///from www.ja v a 2 s . co m private void registerForLocationUpdates() { try { if (isMockMode) { log("Gps started using Mock locations"); TestMock.startMocking(locationManager, this); isListeningForUpdates = true; } else { float minDistance = 0.2f; long waitForSecs = WAITSECONDS; if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { throw new SecurityException(); } if (useNetworkPositions) { locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, waitForSecs * 1000l, minDistance, this); } else { locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, waitForSecs * 1000l, minDistance, this); } isListeningForUpdates = true; log("registered for updates."); } broadcast("triggered by registerForLocationUpdates"); } catch (Exception e) { GPLog.error(this, null, e); isListeningForUpdates = false; } }