mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-20 22:59:54 +01:00
Show all apps that can open links and dismis dialog after click
This commit is contained in:
@@ -2,6 +2,7 @@ package org.briarproject.android.widget;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.DialogFragment;
|
import android.support.v4.app.DialogFragment;
|
||||||
@@ -14,6 +15,7 @@ import android.widget.TextView;
|
|||||||
|
|
||||||
import org.briarproject.R;
|
import org.briarproject.R;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class LinkDialogFragment extends DialogFragment {
|
public class LinkDialogFragment extends DialogFragment {
|
||||||
|
|
||||||
@@ -50,12 +52,21 @@ public class LinkDialogFragment extends DialogFragment {
|
|||||||
TextView urlView = (TextView) v.findViewById(R.id.urlView);
|
TextView urlView = (TextView) v.findViewById(R.id.urlView);
|
||||||
urlView.setText(url);
|
urlView.setText(url);
|
||||||
|
|
||||||
|
// prepare normal intent or intent chooser
|
||||||
|
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
||||||
|
PackageManager packageManager = getContext().getPackageManager();
|
||||||
|
List activities = packageManager.queryIntentActivities(i,
|
||||||
|
PackageManager.MATCH_DEFAULT_ONLY);
|
||||||
|
boolean choice = activities.size() > 1;
|
||||||
|
final Intent intent = choice ? Intent.createChooser(i,
|
||||||
|
getString(R.string.link_warning_open_link)) : i;
|
||||||
|
|
||||||
Button openButton = (Button) v.findViewById(R.id.openButton);
|
Button openButton = (Button) v.findViewById(R.id.openButton);
|
||||||
openButton.setOnClickListener(new OnClickListener() {
|
openButton.setOnClickListener(new OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
startActivity(intent);
|
||||||
startActivity(i);
|
getDialog().dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user