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:org.codecyprus.android_client.ui.ActivityCurrentQuestion.java
@Override protected void onResume() { super.onResume(); registerReceiver(progressReceiver, intentFilter); if (actionBar != null) actionBar.setDisplayHomeAsUpEnabled(true); mcqButtonsContainer.setVisibility(View.GONE); textButtonsContainer.setVisibility(View.GONE); final SerializableSession serializableSession = Preferences.getActiveSession(this); if (serializableSession == null) { Toast.makeText(this, R.string.Invalid_session, Toast.LENGTH_SHORT).show(); finish();//from w w w .j a va 2 s .c om } else { sessionUUID = serializableSession.getSessionUUID(); requestCurrentQuestion(); // locationUUID = serializableSession.getLocationUUID(); // request normal (i.e. android-based) location updates locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 30000, 0, locationUpdater); locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 30000, 0, locationUpdater); } }
From source file:com.jmstudios.redmoon.fragment.ShadesFragment.java
private void updateFilterTimesFromSun() { String location = locationPref.getLocation(); if (location.equals("not set")) { automaticTurnOnPref.setToSunTime("19:30"); automaticTurnOffPref.setToSunTime("06:30"); } else {// ww w .ja v a2 s . c o m Location androidLocation = new Location(LocationManager.NETWORK_PROVIDER); androidLocation.setLatitude(Double.parseDouble(location.split(",")[0])); androidLocation.setLongitude(Double.parseDouble(location.split(",")[1])); String sunsetTime = FilterTimePreference.getSunTimeFromLocation(androidLocation, true); automaticTurnOnPref.setToSunTime(sunsetTime); String sunriseTime = FilterTimePreference.getSunTimeFromLocation(androidLocation, false); automaticTurnOffPref.setToSunTime(sunriseTime); } }
From source file:com.caju.uheer.app.services.infrastructure.ContactablesLoaderCallbacks.java
@Override public void onLoadFinished(Loader<Cursor> arg0, Cursor cursor) { final ArrayList<String> infoAndName = new ArrayList<String>(); try {// w w w . j a va 2 s .c om for (int i = 0; i < usersFound.length(); i++) { infoAndName.add(usersFound.getJSONObject(i).getString("name")); } } catch (JSONException e) { e.printStackTrace(); } LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); LocationListener locationListener = new LocationListener() { @Override public void onLocationChanged(Location location) { Location geoPointLocation = new Location("geoPoint"); try { infoAndName.clear(); for (int i = 0; i < usersFound.length(); i++) { String appendedText = ""; if (!usersFound.getJSONObject(i).has("channel")) { geoPointLocation.setLongitude(usersFound.getJSONObject(i).getDouble("lon")); geoPointLocation.setLatitude(usersFound.getJSONObject(i).getDouble("lat")); float distance = location.distanceTo(geoPointLocation) / 1000; appendedText = String.format("%.1f", distance) + "Km"; } else { appendedText = usersFound.getJSONObject(i).getString("channel"); } infoAndName.add(appendedText + usersFound.getJSONObject(i).getString("name")); Log.e("infoandname", infoAndName.toString() + infoAndName.get(0) + infoAndName.get(1)); Toast.makeText(mContext, infoAndName.toString() + infoAndName.get(0) + infoAndName.get(1), Toast.LENGTH_LONG).show(); // infoAndName tem a informacao de distancia ou canal e o nome. Precisa editar //essa parte de baixo pra usar o infoAndName. ArrayList<String> friendsEmails = new ArrayList<>(); friendsEmails.addAll(infoAndName); friendsEmails = new ArrayList<>(); for (ArrayList<String> array : ServerInformation.getAllActiveListeners()) { friendsEmails.addAll(array); while (friendsEmails.contains(connectedEmail)) friendsEmails.remove(connectedEmail); } EmailListAdapter listAdapter = new EmailListAdapter(mContext, R.layout.adapter_email_list, friendsEmails); ListView emails = (ListView) ((Activity) mContext) .findViewById(R.id.gps_friends_from_drawer); emails.setAdapter(listAdapter); } } catch (JSONException e) { e.printStackTrace(); } } @Override public void onStatusChanged(String provider, int status, Bundle extras) { } @Override public void onProviderEnabled(String provider) { } @Override public void onProviderDisabled(String provider) { } }; // Minimum of 2 minutes between checks (120000 milisecs). locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 120000, 0, locationListener); }
From source file:com.cmput301w17t07.moody.CreateMoodActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_create_mood); UserController userController = new UserController(); userName = userController.readUsername(CreateMoodActivity.this).toString(); setUpMenuBar(this); location = null;/*from ww w.ja v a 2 s. c o m*/ date = new Date(); Intent intent = getIntent(); locationText = (TextView) findViewById(R.id.locationText); Description = (EditText) findViewById(R.id.Description); mImageView = (ImageView) findViewById(R.id.editImageView); //try to get picklocation, if it is equal to 1 that means, user just back from map not //other activities try { pickLocation = (int) intent.getExtras().getInt("pickLocation"); } catch (Exception e) { e.printStackTrace(); } if (pickLocation == 1) { tempMood = (Mood) intent.getSerializableExtra("editMood"); bitmap = (Bitmap) intent.getParcelableExtra("bitmapback"); latitude = tempMood.getLatitude(); longitude = tempMood.getLongitude(); address = tempMood.getDisplayLocation(); locationText.setText(address); Description.setText(tempMood.getMoodMessage()); mImageView.setImageBitmap(bitmap); date = tempMood.getDate(); displayAttributes(); } /** * Spinner dropdown logic taken from http://stackoverflow.com/questions/13377361/how-to-create-a-drop-down-list <br> * Author: Nicolas Tyler, 2013/07/15 8:47 <br> * taken by Xin Huang 2017/03/10 <br> */ //Spinner for emotion and socialsituatuion if (pickLocation == 0) { Spinner dropdown = (Spinner) findViewById(R.id.Emotion); String[] items = new String[] { "anger", "confusion", "disgust", "fear", "happiness", "sadness", "shame", "surprise" }; ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, items); dropdown.setAdapter(adapter); dropdown.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { EmotionText = parent.getItemAtPosition(position).toString(); } @Override public void onNothingSelected(AdapterView<?> parent) { Toast.makeText(CreateMoodActivity.this, "Please pick a feeling!", Toast.LENGTH_SHORT).show(); } }); Spinner dropdown_SocialSituation = (Spinner) findViewById(R.id.SocialSituation); String[] item_SocialSituation = new String[] { "", "alone", "with one other person", "with two people", "with several people", "with a crowd" }; ArrayAdapter<String> adapter_SocialSituation = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_dropdown_item, item_SocialSituation); dropdown_SocialSituation.setAdapter(adapter_SocialSituation); dropdown_SocialSituation.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { SocialSituation = parent.getItemAtPosition(position).toString(); TextView sizeView = (TextView) findViewById(R.id.SocialText); sizeView.setText(" " + SocialSituation); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); } ImageButton chooseButton = (ImageButton) findViewById(R.id.Camera); ImageButton locationButton = (ImageButton) findViewById(R.id.location); ImageButton PickerButton = (ImageButton) findViewById(R.id.Picker); //click on PickerButton, call the datetimePicker PickerButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { innit(); TimeDialog.show(); } }); chooseButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { Intent intent = new Intent("android.media.action.IMAGE_CAPTURE"); startActivityForResult(intent, 1); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class); startActivity(intent); } } }); chooseButton.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { try { Intent intent = new Intent("android.intent.action.PICK"); intent.setType("image/*"); startActivityForResult(intent, 0); } catch (Exception e) { Intent intent = new Intent(getApplicationContext(), CreateMoodActivity.class); startActivity(intent); } return true; } }); locationButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //check available tools List<String> locationList = locationManager.getProviders(true); if (locationList.contains(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(getApplicationContext(), "Please check application permissions", Toast.LENGTH_LONG).show(); } //check the permission if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(getApplicationContext(), "Get location failed, Please check the Permission", Toast.LENGTH_SHORT).show(); return; } location = locationManager.getLastKnownLocation(provider); if (location == null) { latitude = 0; longitude = 0; } else { latitude = location.getLatitude(); longitude = location.getLongitude(); } Geocoder gcd = new Geocoder(CreateMoodActivity.this, Locale.getDefault()); try { List<Address> addresses = gcd.getFromLocation(latitude, longitude, 1); if (addresses.size() > 0) address = " " + addresses.get(0).getFeatureName() + " " + addresses.get(0).getThoroughfare() + ", " + addresses.get(0).getLocality() + ", " + addresses.get(0).getAdminArea() + ", " + addresses.get(0).getCountryCode(); locationText.setText(address); } catch (Exception e) { e.printStackTrace(); } } }); //pass users' changes to map, will be passed back locationButton.setOnLongClickListener(new View.OnLongClickListener() { public boolean onLongClick(View view) { int fromCreate = 123; moodMessage_text = Description.getText().toString(); tempMood = new Mood(EmotionText, userName, moodMessage_text, latitude, longitude, null, SocialSituation, date, address); Intent editLocation = new Intent(CreateMoodActivity.this, EditLocation.class); editLocation.putExtra("EditMood", tempMood); editLocation.putExtra("fromCreate", fromCreate); editLocation.putExtra("bitmap", compress(bitmap)); startActivity(editLocation); return true; } }); Button submitButton = (Button) findViewById(R.id.button5); submitButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { moodMessage_text = Description.getText().toString(); MoodController moodController = new MoodController(); // --------------------------- achievements ------------------------------------- AchievementManager.initManager(CreateMoodActivity.this); AchievementController achievementController = new AchievementController(); achievements = achievementController.getAchievements(); achievements.moodCount += 1; achievementController.incrementMoodCounter(EmotionText); achievementController.saveAchievements(); // ------------------------------------------------------------------------------ if (location != null || pickLocation == 1) { //todo can remove these if/else statements that toast message too long. They could // be handled in the controller if (!MoodController.createMood(EmotionText, userName, moodMessage_text, latitude, longitude, bitmap, SocialSituation, date, address, CreateMoodActivity.this)) { Toast.makeText(CreateMoodActivity.this, "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show(); } else { Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class); startActivity(intent); finish(); } } else { if (!MoodController.createMood(EmotionText, userName, moodMessage_text, 0, 0, bitmap, SocialSituation, date, address, CreateMoodActivity.this)) { Toast.makeText(CreateMoodActivity.this, "Mood message length is too long. Please try again.", Toast.LENGTH_SHORT).show(); } else { Intent intent = new Intent(CreateMoodActivity.this, TimelineActivity.class); startActivity(intent); finish(); } } } }); }
From source file:com.prey.activities.CheckPasswordActivity.java
@Override protected void onResume() { super.onResume(); bindPasswordControls();//www . j a v a2s . co m TextView device_ready_h2_text = (TextView) findViewById(R.id.device_ready_h2_text); final TextView textForgotPassword = (TextView) findViewById(R.id.link_forgot_password); Button password_btn_login = (Button) findViewById(R.id.password_btn_login); EditText password_pass_txt = (EditText) findViewById(R.id.password_pass_txt); TextView textView1 = (TextView) findViewById(R.id.textView1); TextView textView2 = (TextView) findViewById(R.id.textView2); Typeface titilliumWebRegular = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Regular.ttf"); Typeface titilliumWebBold = Typeface.createFromAsset(getAssets(), "fonts/Titillium_Web/TitilliumWeb-Bold.ttf"); Typeface magdacleanmonoRegular = Typeface.createFromAsset(getAssets(), "fonts/MagdaClean/magdacleanmono-regular.ttf"); textView1.setTypeface(magdacleanmonoRegular); textView2.setTypeface(magdacleanmonoRegular); device_ready_h2_text.setTypeface(titilliumWebRegular); textForgotPassword.setTypeface(titilliumWebBold); password_btn_login.setTypeface(titilliumWebBold); password_pass_txt.setTypeface(magdacleanmonoRegular); try { textForgotPassword.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { try { String url = PreyConfig.getPreyConfig(getApplicationContext()).getPreyPanelUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); } catch (Exception e) { } } }); } catch (Exception e) { } TextView textView5_1 = (TextView) findViewById(R.id.textView5_1); TextView textView5_2 = (TextView) findViewById(R.id.textView5_2); textView5_1.setTypeface(magdacleanmonoRegular); textView5_2.setTypeface(titilliumWebBold); TextView textViewUninstall = (TextView) findViewById(R.id.textViewUninstall); LinearLayout linearLayoutTour = (LinearLayout) findViewById(R.id.linearLayoutTour); textViewUninstall.setTypeface(titilliumWebBold); if (PreyConfig.getPreyConfig(getApplication()).getProtectTour()) { linearLayoutTour.setVisibility(View.GONE); textViewUninstall.setVisibility(View.VISIBLE); textViewUninstall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String url = PreyConfig.getPreyConfig(getApplication()).getPreyUninstallUrl(); Intent browserIntent = new Intent("android.intent.action.VIEW", Uri.parse(url)); startActivity(browserIntent); finish(); } }); } else { linearLayoutTour.setVisibility(View.VISIBLE); textViewUninstall.setVisibility(View.GONE); try { linearLayoutTour.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getApplication(), TourActivity1.class); Bundle b = new Bundle(); b.putInt("id", 1); intent.putExtras(b); startActivity(intent); finish(); } }); } catch (Exception e) { } } boolean showLocation = false; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { boolean canAccessFineLocation = PreyPermission.canAccessFineLocation(this); boolean canAccessCoarseLocation = PreyPermission.canAccessCoarseLocation(this); boolean canAccessCamera = PreyPermission.canAccessCamera(this); boolean canAccessReadPhoneState = PreyPermission.canAccessReadPhoneState(this); boolean canAccessReadExternalStorage = PreyPermission.canAccessReadExternalStorage(this); if (!canAccessFineLocation || !canAccessCoarseLocation || !canAccessCamera || !canAccessReadPhoneState || !canAccessReadExternalStorage) { AlertDialog.Builder builder = new AlertDialog.Builder(this); final FrameLayout frameView = new FrameLayout(this); builder.setView(frameView); final AlertDialog alertDialog = builder.create(); LayoutInflater inflater = alertDialog.getLayoutInflater(); View dialoglayout = inflater.inflate(R.layout.warning, frameView); TextView warning_title = (TextView) dialoglayout.findViewById(R.id.warning_title); TextView warning_body = (TextView) dialoglayout.findViewById(R.id.warning_body); warning_title.setTypeface(magdacleanmonoRegular); warning_body.setTypeface(titilliumWebBold); Button button_ok = (Button) dialoglayout.findViewById(R.id.button_ok); Button button_close = (Button) dialoglayout.findViewById(R.id.button_close); button_ok.setTypeface(titilliumWebBold); button_close.setTypeface(titilliumWebBold); final Activity thisActivity = this; button_ok.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("askForPermission"); askForPermission(); alertDialog.dismiss(); } }); button_close.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { PreyLogger.d("close ask"); alertDialog.dismiss(); } }); alertDialog.show(); showLocation = false; } else { showLocation = true; } } else { showLocation = true; } if (showLocation) { LocationManager mlocManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE); boolean isGpsEnabled = mlocManager.isProviderEnabled(LocationManager.GPS_PROVIDER); boolean isNetworkEnabled = mlocManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); if (isGpsEnabled || isNetworkEnabled) { PreyLogger.d("isGpsEnabled || isNetworkEnabled"); } else { PreyLogger.d("no gps ni red"); AlertDialog.Builder builder = new AlertDialog.Builder(this); final AlertDialog alertDialog = builder.create(); TextView textview = new TextView(this); textview.setText(getString(R.string.location_settings)); textview.setMaxLines(10); textview.setTextSize(18F); textview.setPadding(20, 0, 20, 20); textview.setTextColor(Color.BLACK); builder.setView(textview); builder.setPositiveButton(getString(R.string.go_to_settings), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); startActivityForResult(intent, 0); return; } }); builder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialoginterface, int i) { dialoginterface.dismiss(); } }); builder.create().show(); } } }
From source file:name.gumartinm.weather.information.activity.MapActivity.java
public void onClickGetLocation(final View v) { // TODO: Somehow I should show a progress dialog. // If Google Play Services is available if (this.mLocationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) { // TODO: Hopefully there will be results even if location did not change... final Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAltitudeRequired(false); criteria.setBearingAccuracy(Criteria.NO_REQUIREMENT); criteria.setBearingRequired(false); criteria.setCostAllowed(false);//from w w w. j ava 2s .c o m criteria.setHorizontalAccuracy(Criteria.ACCURACY_HIGH); criteria.setPowerRequirement(Criteria.POWER_MEDIUM); criteria.setSpeedAccuracy(Criteria.NO_REQUIREMENT); criteria.setSpeedRequired(false); criteria.setVerticalAccuracy(Criteria.ACCURACY_HIGH); this.mLocationManager.requestSingleUpdate(criteria, this, null); } else { Toast.makeText(this, this.getString(R.string.weather_map_not_enabled_location), Toast.LENGTH_LONG) .show(); } // Trying to use the synchronous calls. Problems: mGoogleApiClient read/store from different threads. // new GetLocationTask(this).execute(); }
From source file:com.mibr.android.intelligentreminder.INeedToo.java
public void startListening() { if (mLocationManager != null) { mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this); mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this); } else {/*from www .j ava2 s . co m*/ try { getLocationManager().requestLocationUpdates(LocationManager.GPS_PROVIDER, 20000, 10, this); getLocationManager().requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 20000, 10, this); } catch (Exception e44) { } } }
From source file:com.mendhak.gpslogger.GpsMainActivity.java
private void loadVersionSpecificProperties() { PackageInfo packageInfo;//w w w . j av a2s .c o m try { packageInfo = getPackageManager().getPackageInfo(getPackageName(), 0); int versionCode = packageInfo.versionCode; if (preferenceHelper.getLastVersionSeen() <= 71) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); //Specifically disable passive provider... just once if (preferenceHelper.getChosenListeners().contains("passive")) { Set<String> listeners = new HashSet<>(); if (preferenceHelper.getChosenListeners().contains(LocationManager.GPS_PROVIDER)) { listeners.add(LocationManager.GPS_PROVIDER); } if (preferenceHelper.getChosenListeners().contains(LocationManager.NETWORK_PROVIDER)) { listeners.add(LocationManager.NETWORK_PROVIDER); } preferenceHelper.setChosenListeners(listeners); } } if (preferenceHelper.getLastVersionSeen() <= 74) { LOG.debug("preferenceHelper.getLastVersionSeen() " + preferenceHelper.getLastVersionSeen()); LOG.debug("Overriding minimum accuracy to 40"); if (preferenceHelper.getMinimumAccuracy() == 0) { preferenceHelper.setMinimumAccuracy(40); } } preferenceHelper.setLastVersionSeen(versionCode); } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } }
From source file:net.frakbot.FWeather.util.LocationHelper.java
private static boolean isLowPowerLocationProviderEnabled() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { try {//from w w w .j a v a 2s . c om int activeMode = Settings.Secure.getInt(mContext.getContentResolver(), Settings.Secure.LOCATION_MODE); return (activeMode & Settings.Secure.LOCATION_MODE_BATTERY_SAVING) != 0; } catch (Settings.SettingNotFoundException e) { FLog.w(TAG, "Unable to detect the location mode using the new 4.4+ APIs, " + "falling back on the old ones."); return false; } } @SuppressWarnings("deprecation") String availProviders = Settings.Secure.getString(mContext.getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); return availProviders != null && (availProviders.contains(LocationManager.NETWORK_PROVIDER) || availProviders.contains(LocationManager.PASSIVE_PROVIDER)); }
From source file:com.cmput301w17t07.moody.MapsActivity.java
/** * Manipulates the map once available.//from ww w. j a v a 2 s .co m * This callback is triggered when the map is ready to be used. * This is where we can add markers or lines, add listeners or move the camera. In this case, * we just add a marker near Sydney, Australia. * If Google Play services is not installed on the device, the user will be prompted to install * it inside the SupportMapFragment. This method will only be triggered once the user has * installed Google Play services and returned to the app. */ @Override public void onMapReady(GoogleMap googleMap) { mMap = googleMap; //check the permission if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) { // TODO: Consider calling Toast.makeText(getApplicationContext(), "Unable to access location." + " Please check your permissions", Toast.LENGTH_SHORT).show(); return; } filterFeeling = intent.getStringExtra("feelingFilter"); //------------------------- MAP FILTERS FOR USER'S MOODS ----------------------------------- if (user == 0) { if (filterFeeling.equals("all")) { try { moodArrayList = MoodController.getUserMoods(username, String.valueOf(0), MapsActivity.this, false, String.valueOf(100)); } catch (Exception e) { System.out.println("Error when trying to retrieve user's " + "location based mood history for all feelings" + e); } } else { ElasticMoodController.GetFeelingFilterMoods getFeelingFilterMoods = new ElasticMoodController.GetFeelingFilterMoods(); getFeelingFilterMoods.execute(username, filterFeeling); try { moodArrayList = getFeelingFilterMoods.get(); } catch (Exception e) { Log.i("error", "failed to get filtered feeling moods in map activity"); } } // Plotting of location based points on map for (int i = 0; i < moodArrayList.size(); i++) { Mood mood = moodArrayList.get(i); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = moodArrayList.get(i).getLongitude(); latitude = moodArrayList.get(i).getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); mMap.moveCamera(CameraUpdateFactory.newLatLng(tmp)); } } } //--------------------- MAP FILTERS FOR USER'S TIMELINE'S MOODS ---------------------------- else if (user == 1) { FollowController followController = new FollowController(); FollowingList followingList = followController.getFollowingList(username); if (filterFeeling.equals("all")) { try { moodArrayList = MoodController.getTimelineMoods(username, String.valueOf(0), MapsActivity.this); } catch (Exception e) { System.out.println("Error with getting timeline mood in MapsActivity" + e); } } else { nameList.addAll(followingList.getFollowingList()); try { for (int i = 0; i < nameList.size(); i++) { ElasticMoodController.GetFeelingFilterMoods getFeelingFilterMoods = new ElasticMoodController.GetFeelingFilterMoods(); getFeelingFilterMoods.execute(nameList.get(i).toString(), filterFeeling); try { moodArrayList.addAll(getFeelingFilterMoods.get()); } catch (Exception e) { System.out .println("Error with getting filtered" + " timeline moods in MapsActivity" + e); } } } catch (Exception e) { } } for (int j = 0; j < moodArrayList.size(); j++) { Mood mood = moodArrayList.get(j); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = mood.getLongitude(); latitude = mood.getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getDisplayUsername()) .snippet(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); mMap.moveCamera(CameraUpdateFactory.newLatLng(tmp)); } } } //--------------------------- ALL MOODS WITHIN 5KM OF THE USER ----------------------------- else if (user == 2) { locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); //check available tools List<String> locationList = locationManager.getProviders(true); if (locationList.contains(LocationManager.GPS_PROVIDER)) { provider = LocationManager.GPS_PROVIDER; } else if (locationList.contains(LocationManager.NETWORK_PROVIDER)) { provider = LocationManager.NETWORK_PROVIDER; } else { Toast.makeText(getApplicationContext(), "No map to use", Toast.LENGTH_LONG).show(); } location = locationManager.getLastKnownLocation(provider); if (location == null) { latitude = 0; longitude = 0; } else { latitude = location.getLatitude(); longitude = location.getLongitude(); } UserController userController = new UserController(); username = userController.readUsername(MapsActivity.this).toString(); ElasticMoodController.FilterMapByLocation filterMapByLocation = new ElasticMoodController.FilterMapByLocation(); filterMapByLocation.execute(location); try { currLocationArrayList.addAll(filterMapByLocation.get()); } catch (Exception e) { System.out.println("this is fff" + e); } for (int p = 0; p < currLocationArrayList.size(); p++) { Location locationNear = new Location("near"); locationNear.setLatitude(currLocationArrayList.get(p).getLatitude()); locationNear.setLongitude(currLocationArrayList.get(p).getLongitude()); float distance = location.distanceTo(locationNear); if (distance <= 5000.0) { currLocationArrayListWith5Km.add(currLocationArrayList.get(p)); } } for (int j = 0; j < currLocationArrayListWith5Km.size(); j++) { Mood mood = currLocationArrayListWith5Km.get(j); if (mood.getLongitude() == 0 && mood.getLatitude() == 0) { break; } else { double longitude; double latitude; longitude = mood.getLongitude(); latitude = mood.getLatitude(); LatLng tmp = new LatLng(latitude, longitude); mMap.addMarker(new MarkerOptions().position(tmp).title(mood.getDisplayUsername()) .snippet(mood.getFeeling()) .icon(BitmapDescriptorFactory.defaultMarker(setMarkerColor(mood.getFeeling())))); float zoomLevel = 12.0f; mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(tmp, zoomLevel)); } } } }