Added context menu to shownotes view
This commit is contained in:
parent
f387929170
commit
cb82268f7d
@ -2,12 +2,15 @@
|
|||||||
|
|
||||||
<item name="action_bar_refresh" type="id"/>
|
<item name="action_bar_refresh" type="id"/>
|
||||||
<item name="action_bar_add" type="id"/>
|
<item name="action_bar_add" type="id"/>
|
||||||
<item type="id" name="clear_queue_item"/>
|
<item name="clear_queue_item" type="id"/>
|
||||||
<item type="id" name="select_all_item"/>
|
<item name="select_all_item" type="id"/>
|
||||||
<item type="id" name="deselect_all_item"/>
|
<item name="deselect_all_item" type="id"/>
|
||||||
<item type="id" name="search_item"/>
|
<item name="search_item" type="id"/>
|
||||||
<item name="enqueue_all_item" type="id"/>
|
<item name="enqueue_all_item" type="id"/>
|
||||||
<item name="download_all_item" type="id"/>
|
<item name="download_all_item" type="id"/>
|
||||||
<item type="id" name="clear_history_item"/>
|
<item name="clear_history_item" type="id"/>
|
||||||
|
<item name="open_in_browser_item" type="id"/>
|
||||||
|
<item name="copy_url_item" type="id"/>
|
||||||
|
<item name="share_url_item" type="id"/>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
@ -14,6 +14,12 @@
|
|||||||
<string name="download_log_label">Download log</string>
|
<string name="download_log_label">Download log</string>
|
||||||
<string name="playback_history_label">Playback history</string>
|
<string name="playback_history_label">Playback history</string>
|
||||||
|
|
||||||
|
<!-- Webview actions -->
|
||||||
|
<string name="open_in_browser_label">Open in browser</string>
|
||||||
|
<string name="copy_url_label">Copy URL</string>
|
||||||
|
<string name="share_url_label">Share URL</string>
|
||||||
|
<string name="copied_url_msg">Copied URL to clipboard.</string>
|
||||||
|
|
||||||
<!-- Playback history -->
|
<!-- Playback history -->
|
||||||
<string name="clear_history_label">Clear history</string>
|
<string name="clear_history_label">Clear history</string>
|
||||||
|
|
||||||
|
@ -4,19 +4,28 @@ import org.apache.commons.lang3.StringEscapeUtils;
|
|||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
|
import android.content.ClipData;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.Menu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.FrameLayout;
|
import android.widget.FrameLayout;
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.actionbarsherlock.app.SherlockFragment;
|
import com.actionbarsherlock.app.SherlockFragment;
|
||||||
|
|
||||||
@ -26,6 +35,7 @@ import de.danoeh.antennapod.R;
|
|||||||
import de.danoeh.antennapod.feed.Feed;
|
import de.danoeh.antennapod.feed.Feed;
|
||||||
import de.danoeh.antennapod.feed.FeedItem;
|
import de.danoeh.antennapod.feed.FeedItem;
|
||||||
import de.danoeh.antennapod.feed.FeedManager;
|
import de.danoeh.antennapod.feed.FeedManager;
|
||||||
|
import de.danoeh.antennapod.util.ShareUtils;
|
||||||
|
|
||||||
/** Displays the description of a FeedItem in a Webview. */
|
/** Displays the description of a FeedItem in a Webview. */
|
||||||
public class ItemDescriptionFragment extends SherlockFragment {
|
public class ItemDescriptionFragment extends SherlockFragment {
|
||||||
@ -42,6 +52,9 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||||||
private String descriptionRef;
|
private String descriptionRef;
|
||||||
private String contentEncodedRef;
|
private String contentEncodedRef;
|
||||||
|
|
||||||
|
/** URL that was selected via long-press. */
|
||||||
|
private String selectedURL;
|
||||||
|
|
||||||
public static ItemDescriptionFragment newInstance(FeedItem item) {
|
public static ItemDescriptionFragment newInstance(FeedItem item) {
|
||||||
ItemDescriptionFragment f = new ItemDescriptionFragment();
|
ItemDescriptionFragment f = new ItemDescriptionFragment();
|
||||||
Bundle args = new Bundle();
|
Bundle args = new Bundle();
|
||||||
@ -69,6 +82,8 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||||||
webvDescription.getSettings().setUseWideViewPort(false);
|
webvDescription.getSettings().setUseWideViewPort(false);
|
||||||
webvDescription.getSettings().setLayoutAlgorithm(
|
webvDescription.getSettings().setLayoutAlgorithm(
|
||||||
LayoutAlgorithm.SINGLE_COLUMN);
|
LayoutAlgorithm.SINGLE_COLUMN);
|
||||||
|
webvDescription.setOnLongClickListener(webViewLongClickListener);
|
||||||
|
registerForContextMenu(webvDescription);
|
||||||
return webvDescription;
|
return webvDescription;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,6 +210,81 @@ public class ItemDescriptionFragment extends SherlockFragment {
|
|||||||
return String.format(WEBVIEW_STYLE, textColor);
|
return String.format(WEBVIEW_STYLE, textColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private View.OnLongClickListener webViewLongClickListener = new View.OnLongClickListener() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean onLongClick(View v) {
|
||||||
|
WebView.HitTestResult r = webvDescription.getHitTestResult();
|
||||||
|
if (r != null
|
||||||
|
&& r.getType() == WebView.HitTestResult.SRC_ANCHOR_TYPE) {
|
||||||
|
if (AppConfig.DEBUG)
|
||||||
|
Log.d(TAG,
|
||||||
|
"Link of webview was long-pressed. Extra: "
|
||||||
|
+ r.getExtra());
|
||||||
|
selectedURL = r.getExtra();
|
||||||
|
webvDescription.showContextMenu();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
selectedURL = null;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
|
@Override
|
||||||
|
public boolean onContextItemSelected(MenuItem item) {
|
||||||
|
boolean handled = selectedURL != null;
|
||||||
|
if (selectedURL != null) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.id.open_in_browser_item:
|
||||||
|
Uri uri = Uri.parse(selectedURL);
|
||||||
|
getActivity()
|
||||||
|
.startActivity(new Intent(Intent.ACTION_VIEW, uri));
|
||||||
|
break;
|
||||||
|
case R.id.share_url_item:
|
||||||
|
ShareUtils.shareLink(getActivity(), selectedURL);
|
||||||
|
break;
|
||||||
|
case R.id.copy_url_item:
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= 11) {
|
||||||
|
ClipData clipData = ClipData.newPlainText(selectedURL,
|
||||||
|
selectedURL);
|
||||||
|
android.content.ClipboardManager cm = (android.content.ClipboardManager) getActivity()
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setPrimaryClip(clipData);
|
||||||
|
} else {
|
||||||
|
android.text.ClipboardManager cm = (android.text.ClipboardManager) getActivity()
|
||||||
|
.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
|
cm.setText(selectedURL);
|
||||||
|
}
|
||||||
|
Toast t = Toast.makeText(getActivity(), R.string.copied_url_msg, Toast.LENGTH_SHORT);
|
||||||
|
t.show();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
handled = false;
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
selectedURL = null;
|
||||||
|
}
|
||||||
|
return handled;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
|
ContextMenuInfo menuInfo) {
|
||||||
|
if (selectedURL != null) {
|
||||||
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
menu.add(Menu.NONE, R.id.open_in_browser_item, Menu.NONE,
|
||||||
|
R.string.open_in_browser_label);
|
||||||
|
menu.add(Menu.NONE, R.id.copy_url_item, Menu.NONE,
|
||||||
|
R.string.copy_url_label);
|
||||||
|
menu.add(Menu.NONE, R.id.share_url_item, Menu.NONE,
|
||||||
|
R.string.share_url_label);
|
||||||
|
menu.setHeaderTitle(selectedURL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private AsyncTask<Void, Void, Void> createLoader() {
|
private AsyncTask<Void, Void, Void> createLoader() {
|
||||||
return new AsyncTask<Void, Void, Void>() {
|
return new AsyncTask<Void, Void, Void>() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -11,7 +11,7 @@ public class ShareUtils {
|
|||||||
|
|
||||||
private ShareUtils() {}
|
private ShareUtils() {}
|
||||||
|
|
||||||
private static void shareLink(Context context, String link) {
|
public static void shareLink(Context context, String link) {
|
||||||
Intent i = new Intent(Intent.ACTION_SEND);
|
Intent i = new Intent(Intent.ACTION_SEND);
|
||||||
i.setType("text/plain");
|
i.setType("text/plain");
|
||||||
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
|
i.putExtra(Intent.EXTRA_SUBJECT, "Sharing URL");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user