How to Implement Fused Location in Firebase Recycler Adapter Database UI?

I have a problem for implementing fused location which method is used to get current location for the device on Firebase Database UI but It doesn’t work because there was a red line that noticed

Cannot resolve method 'addOnSuccessListener(anonymous com.firebase.ui.database.FirebaseRecyclerAdapter<co.id.roningrum.dolanapptugasakhir.item.CategoryItem,co.id.roningrum.dolanapptugasakhir.adapter.CategoryViewHolder>, anonymous com.google.android.gms.tasks.OnSuccessListener<android.location.Location>)

There are three classes wheter I’ve already made, CategoryItem, CategoryViewHolder and CategoryMenuActivity. CategoryItem is a model class, CategoryViewHolder is a ViewHolder class and CategoryMenuActivity is an activity class which used to show the list of items.

  1. CategoryItem.java
 public class CategoryItem {     private String name_tourism;     private String location_tourism;     private String info_tourism;     private String telepon;     private String url_photo;     private double lat_location_tourism;     private double lng_location_tourism;      public CategoryItem() {         //constructor untuk panggilan ke DataSnapshot.getValue     }      public CategoryItem(String name_tourism, String location_tourism, String info_tourism, String telepon, String url_photo, double lat_location_tourism, double lng_location_tourism) {         this.name_tourism = name_tourism;         this.location_tourism = location_tourism;         this.info_tourism = info_tourism;         this.telepon = telepon;         this.url_photo = url_photo;         this.lat_location_tourism = lat_location_tourism;         this.lng_location_tourism = lng_location_tourism;     }      public String getName_tourism() {         return name_tourism;     }      public void setName_tourism(String name_tourism) {         this.name_tourism = name_tourism;     }      public String getLocation_tourism() {         return location_tourism;     }      public void setLocation_tourism(String location_tourism) {         this.location_tourism = location_tourism;     }      public String getInfo_tourism() {         return info_tourism;     }      public void setInfo_tourism(String info_tourism) {         this.info_tourism = info_tourism;     }      public String getTelepon() {         return telepon;     }      public void setTelepon(String telepon) {         this.telepon = telepon;     }      public String getUrl_photo() {         return url_photo;     }      public void setUrl_photo(String url_photo) {         this.url_photo = url_photo;     }      public double getLat_location_tourism() {         return lat_location_tourism;     }      public void setLat_location_tourism(double lat_location_tourism) {         this.lat_location_tourism = lat_location_tourism;     }      public double getLng_location_tourism() {         return lng_location_tourism;     }      public void setLng_location_tourism(double lng_location_tourism) {         this.lng_location_tourism = lng_location_tourism;     } } 
  1. CategoryViewHolder.java
package co.id.roningrum.dolanapptugasakhir.adapter;  import android.location.Location; import android.support.annotation.NonNull; import android.support.v7.widget.RecyclerView; import android.view.View; import android.widget.ImageView; import android.widget.TextView;  import com.bumptech.glide.Glide;  import java.text.DecimalFormat;  import co.id.roningrum.dolanapptugasakhir.R; import co.id.roningrum.dolanapptugasakhir.item.CategoryItem;   public class CategoryViewHolder extends RecyclerView.ViewHolder {     private TextView name_tourisms, location_tourism, distance_tourism;     private ImageView tourism_pic;        public CategoryViewHolder(@NonNull View itemView) {         super(itemView);         name_tourisms = itemView.findViewById(R.id.tv_name_tourism);         location_tourism = itemView.findViewById(R.id.tv_location_tourism);         distance_tourism= itemView.findViewById(R.id.tv_distance_tourism);         tourism_pic = itemView.findViewById(R.id.tourism_pic);         itemView.setOnClickListener(new View.OnClickListener() {             @Override             public void onClick(View v) {                 categoryOnClick.onItemClick(v, getAdapterPosition());             }         });      }      public void showTourismData(CategoryItem categoryItem, double longitude, double latitude) {         Location loc1 = new Location("");         loc1.setLatitude(latitude);         loc1.setLongitude(longitude);         Location loc2 = new Location("");         loc2.setLatitude(categoryItem.getLat_location_tourism());         loc2.setLongitude(categoryItem.getLng_location_tourism());          float jarakMeter = loc1.distanceTo(loc2);         float jarakKM = jarakMeter/1000;          DecimalFormat df = new DecimalFormat();         df.setMaximumFractionDigits(2);          name_tourisms.setText(categoryItem.getName_tourism());         location_tourism.setText(categoryItem.getLocation_tourism());         distance_tourism.setText(""+df.format(jarakKM)+" KM");         Glide.with(itemView.getContext()).load(categoryItem.getUrl_photo()).into(tourism_pic);     }      //interface     private CategoryViewHolder.ClickListener categoryOnClick;     public interface ClickListener{         void onItemClick (View view, int position);     }     public void setOnClickListener(CategoryViewHolder.ClickListener clickListener){         categoryOnClick = clickListener;     }   } //} 
  1. CategoryMenuActivity.java
import com.firebase.ui.database.FirebaseRecyclerOptions; import com.google.android.gms.location.FusedLocationProviderClient; import com.google.android.gms.location.LocationServices; import com.google.android.gms.tasks.OnSuccessListener; import com.google.firebase.database.DatabaseReference; import com.google.firebase.database.FirebaseDatabase; import com.google.firebase.database.Query;  import java.util.ArrayList;  import co.id.roningrum.dolanapptugasakhir.adapter.CategoryViewHolder; import co.id.roningrum.dolanapptugasakhir.item.CategoryItem;  public class CategoryMenuActivity extends AppCompatActivity {     Toolbar mToolbar;     DatabaseReference tourismDBRef;     RecyclerView rvTourismList;     ArrayList<CategoryItem> categoryItemList;     FirebaseRecyclerAdapter<CategoryItem, CategoryViewHolder> firebaseAdapter;      LocationManager locationManagers;     String[] perms = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_NETWORK_STATE};      @Override     protected void onCreate(Bundle savedInstanceState) {         super.onCreate(savedInstanceState);         setContentView(R.layout.activity_category_menu);         mToolbar = findViewById(R.id.toolbar_top);         rvTourismList = findViewById(R.id.tourism_list);         rvTourismList.setLayoutManager(new LinearLayoutManager(this));         categoryItemList = new ArrayList<>();          setSupportActionBar(mToolbar);          locationManagers = (LocationManager)   getSystemService(Context.LOCATION_SERVICE);          tourismDBRef = FirebaseDatabase.getInstance().getReference();         Query query = tourismDBRef.child("Tourism");          FirebaseRecyclerOptions<CategoryItem> options = new FirebaseRecyclerOptions.Builder<CategoryItem>()                 .setQuery(query, CategoryItem.class)                 .build();         firebaseAdapter = new FirebaseRecyclerAdapter<CategoryItem, CategoryViewHolder>(options) {              @NonNull             @Override             public CategoryViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {                 View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_category_menu, viewGroup, false);                 return new CategoryViewHolder(view);             }              @Override             public void onBindViewHolder(@NonNull final CategoryViewHolder holder, int position, @NonNull final CategoryItem model) {                 final DatabaseReference touristRef = getRef(position);                 final String wiskey = touristRef.getKey();                  FusedLocationProviderClient mFusedLocation = LocationServices.getFusedLocationProviderClient(getApplicationContext());                  if (ActivityCompat.checkSelfPermission(getApplicationContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {                     // TODO: Consider calling                     //    ActivityCompat#requestPermissions                     // here to request the missing permissions, and then overriding                     //   public void onRequestPermissionsResult(int requestCode, String[] permissions,                     //                                          int[] grantResults)                     // to handle the case where the user grants the permission. See the documentation                     // for ActivityCompat#requestPermissions for more details.                     verifyPermission();                     return;                 }                 mFusedLocation.getLastLocation().addOnSuccessListener(this, new OnSuccessListener<Location>() {                     @Override                     public void onSuccess(Location location) {                         if (location != null) {                             // Do it all with location                             Log.d("My Current location", "Lat : " + location.getLatitude() + " Long : " + location.getLongitude());                             double latitude = location.getLatitude();                             double longitude = location.getLongitude();                             holder.showTourismData(model, latitude,longitude);                             holder.setOnClickListener(new CategoryViewHolder.ClickListener() {                                 @Override                                 public void onItemClick(View view, int position) {                                     Intent intent = new Intent(getApplicationContext(), DetailCategoryActivity.class);                                     intent.putExtra(DetailCategoryActivity.EXTRA_WISATA_KEY, wiskey);                                     startActivity(intent);                                 }                             });                         }                     }                 });               }         };         firebaseAdapter.notifyDataSetChanged();         rvTourismList.setAdapter(firebaseAdapter);     }       private void verifyPermission() {         if (!hasPermission(this, perms)) {             ActivityCompat.requestPermissions(this, perms, 1);         }     }      private boolean hasPermission(Context context, String[] perms) {         if (context != null && perms != null) {             for (String permission : perms) {                 if (ActivityCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) {                     return false;                 }             }         }         return true;     }      @Override     public boolean onCreateOptionsMenu(Menu menu) {         getMenuInflater().inflate(R.menu.toolbar_menu, menu);         MenuItem mSearch = menu.findItem(R.id.searchMenu);         SearchView mSearchView = (SearchView) mSearch.getActionView();         mSearchView.setQueryHint("Search");         mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {             @Override             public boolean onQueryTextSubmit(String query) {                 return false;             }              @Override             public boolean onQueryTextChange(String searchText) {                 rvTourismList.removeAllViews();                 firebaseSearch(searchText); return super.onCreateOptionsMenu(menu);     }      private void firebaseSearch(String searchText) {         Query firebaseSearchquery = tourismDBRef.child("Tourism").orderByKey().startAt(searchText).endAt(searchText + "\uf8ff");         FirebaseRecyclerOptions<CategoryItem> options = new FirebaseRecyclerOptions.Builder<CategoryItem>()                 .setQuery(firebaseSearchquery, CategoryItem.class)                 .setLifecycleOwner(this)                 .build();         firebaseAdapter = new FirebaseRecyclerAdapter<CategoryItem, CategoryViewHolder>(options) {              @NonNull             @Override             public CategoryViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {                 View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_category_menu, viewGroup, false);                 return new CategoryViewHolder(view);             }              @Override             public void onBindViewHolder(@NonNull CategoryViewHolder holder, int position, @NonNull CategoryItem model) {                 final DatabaseReference touristRef = getRef(position);                 final String wiskey = touristRef.getKey();                  holder.showTourismData(model);                 holder.setOnClickListener(new CategoryViewHolder.ClickListener() {                     @Override                     public void onItemClick(View view, int position) {                         Intent intent = new Intent(getApplicationContext(), DetailCategoryActivity.class);                         intent.putExtra(DetailCategoryActivity.EXTRA_WISATA_KEY, wiskey);                         startActivity(intent);                     }                 });             }         };         rvTourismList.setAdapter(firebaseAdapter);      }     @Override     protected void onStart() {         super.onStart();         firebaseAdapter.startListening();     }      @Override     protected void onStop() {         super.onStop();         if (firebaseAdapter != null) {             firebaseAdapter.stopListening();         }      } } 

I exepect the method fused location can work because my expectation to show distance which is the result of calculating distance between current location and the destination place. Thank you 🙂

How do I change the location of iCloud drive on Windows?

Recently I’ve been using iCloud with my windows machine. With the older version of iCloud I was able to change the location using the mklink command; however, this does not seem to work with the new iCloud version downloaded from the windows store, as I cannot move the iCloud folder even when all iCloud processes are closed (it says I don’t have enough space on drive C even though that’s not the drive I’m moving to). Is there another method for moving the iCloud folder that I’m missing?

How can I save a file to a specific “keyed” location? [duplicate]

This question already has an answer here:

  • Navigate folder structure in Open/Save File Dialog with keyboard? 3 answers
  • save a file to /usr using Mac's Save As dialogue 3 answers

In Finder to go to a specific location I can do Cmd-Shift-G

But what if I want to save to a specific location? That is, I don’t want to click through a folder hierarchy in the save dialogue box.

For example I would like to save the current file to ~/.ssh

enter image description here

The Where drop down allows you to select a location, but I want to be able to enter the location using the keyboard.

Save doc to same location it was opened

I am looking for an Android word processor that does one thing ( aside from the usual editing and formatting).

When I go to save a document, I want that document saved exactly in the same spot that I opened it from. If that was a cloud account on sugarsync then that’s where I wanted to be saved.

Too often, or maybe always, it seems the word processor wants to save it in some cloud or other. For example the Android Ms word app wants to save it to the Microsoft Cloud.

It’s really annoying. Who can point me to a android word processing app that actually saves the file you working on to the exactly the same location where it opened it from?

Thanks.

nginx nested location fallthrough

I need to enforce trailing slashes on a particular set of URIs on my site.

The URIs take the following format: /foo/bar1/bar2/bar3/?abc, where /foo/ is common across all dynamic and also a valid URI on it’s own.

All and only dynamic URIs will match the regex ^(.*[^/])$ assuming a prefix check on /foo/ was performed.

My code currently looks like this:

location /foo/ {   location ~* ^(.*[^/])$   {     return 302 $  baseUrl/$  1/$  is_args$  args;   } } 

This, however, causes 404s on all /foo/.*, though it does successfully insert the slash as intended.

Clearly, if it matches the outer location, but not the inner one, it fails.

What I’m looking for then, is a statement that causes the execution to step back out of outer location.

Note:

I realize I could just say

location ~* ^(/foo/.*[^/])$   {   return 302 $  baseUrl/$  1/$  is_args$  args; } 

but I’d like to avoid it because of the performance hit of regex. Don’t want to deal with that on non-candidate pages.

Why Is There A ‘Windows’ Location On My PC?

So, I’ve just installed Ubuntu on my PC and I’m really liking it so far(It’s also my first time using Linux).

During the Installation-Process, I’m 100% sure that I did click “Erase Windows” during Installation.

Then when I went into the Terminal, put in “whereis gcc” and it gave me the Location of GCC, I went on a trip to it’s Location. But during my way to find the GCC Files, I stumbled upon this:

Image

I don’t understand why that’s there. I’ll reiterate, I’m 100% sure that I clicked “Erase Windows” during the Installation.

Does anybody know why it’s there?

algorithm for grouping elements (defined by time range, weight, location) based on time range overlap (groups are constrained by params)?

Let each element be an individual. Consider that an individual is defined such that each individual has a time range, weight, and location.

The goal is to group together individuals whose time ranges overlap while ensuring that, within the group, the sum of the weights of the individuals do not exceed a certain threshold. At the same time, it is desirable to minimize the total distance between the individuals in the group. As many individuals as necessary can be placed into a group as long as the weight constraint is met.

The goal is to have as many individuals grouped (that is at minimum paired) as possible while minimizing the total distance between individuals in groups.

For example, consider an example in the discrete time case where there are ten time intervals. [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]. The weight threshold is 4 and the location of the individuals are points on the 1-D line of integers. Say that we have the following individuals:

A: time range: [1, 2, 3] | weight: 1 | location: 1 B: time range: [2, 3, 4] | weight: 2 | location: 2 C: time range: [4, 5, 6] | weight: 2 | location: -3 D: time range: [4, 5, 6] | weight: 3 | location: -3 

Note:

  • A and C cannot be grouped because they do not have overlapping time ranges.
  • grouping together A and B gives is preferable to grouping together B and C because A and B are closer together.
  • C and D cannot be grouped because the sum of their weights exceed 4. Does any one have a recommended algorithm for solving a problem like this?

I’ve looked at the examples in (Studies in Computational Intelligence 666) Michael Mutingi, Charles Mbohwa (auth.) – Grouping Genetic Algorithms_ Advances and Applications-Springer International Publishing (2017). However, none of the grouping algorithms seem very fitting.