package de.thedevstack.conversationsplus.ui.listeners; import android.app.Activity; import android.content.Intent; import android.view.View; import android.widget.Toast; import de.thedevstack.conversationsplus.R; import de.thedevstack.conversationsplus.entities.Message; import de.thedevstack.conversationsplus.utils.GeoHelper; /** */ public class OpenLocationOnClickListener implements View.OnClickListener { private final Activity activity; private final Message message; public OpenLocationOnClickListener(Activity activity, Message message) { this.activity = activity; this.message = message; } @Override public void onClick(View view) { this.showLocation(); } private void showLocation() { for (Intent intent : GeoHelper.createGeoIntentsFromMessage(this.message)) { if (intent.resolveActivity(this.activity.getPackageManager()) != null) { // Only if the intent can be opened this.activity.startActivity(intent); return; } } Toast.makeText(this.activity, R.string.no_application_found_to_display_location, Toast.LENGTH_SHORT).show(); } }