implement basic webview context menu for images
This commit is contained in:
parent
2a268f6c6a
commit
cea68d6b54
@ -1,7 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.fox.ttrss"
|
package="org.fox.ttrss"
|
||||||
android:versionCode="151"
|
android:versionCode="152"
|
||||||
android:versionName="1.4.3" >
|
android:versionName="1.4.3" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
|
18
res/menu/article_content_img_context_menu.xml
Normal file
18
res/menu/article_content_img_context_menu.xml
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/article_img_open"
|
||||||
|
android:showAsAction=""
|
||||||
|
android:title="@string/article_img_open"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/article_img_share"
|
||||||
|
android:showAsAction=""
|
||||||
|
android:title="@string/article_img_share"/>
|
||||||
|
|
||||||
|
<!-- <item
|
||||||
|
android:id="@+id/article_img_save"
|
||||||
|
android:showAsAction=""
|
||||||
|
android:title="Save image to file"/> -->
|
||||||
|
|
||||||
|
</menu>
|
@ -186,4 +186,6 @@
|
|||||||
<string name="headlines_starred">Starred</string>
|
<string name="headlines_starred">Starred</string>
|
||||||
<string name="headlines_published">Published</string>
|
<string name="headlines_published">Published</string>
|
||||||
<string name="headlines_unread">Unread</string>
|
<string name="headlines_unread">Unread</string>
|
||||||
|
<string name="article_img_open">Open image</string>
|
||||||
|
<string name="article_img_share">Share image</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -21,11 +21,13 @@ import android.os.Bundle;
|
|||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
import android.view.ContextMenu;
|
import android.view.ContextMenu;
|
||||||
import android.view.ContextMenu.ContextMenuInfo;
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.view.GestureDetector;
|
import android.view.GestureDetector;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.MenuItem;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
@ -34,7 +36,9 @@ import android.webkit.WebChromeClient;
|
|||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebSettings.LayoutAlgorithm;
|
import android.webkit.WebSettings.LayoutAlgorithm;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebView.HitTestResult;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
|
||||||
public class ArticleFragment extends Fragment implements GestureDetector.OnDoubleTapListener {
|
public class ArticleFragment extends Fragment implements GestureDetector.OnDoubleTapListener {
|
||||||
private final String TAG = this.getClass().getSimpleName();
|
private final String TAG = this.getClass().getSimpleName();
|
||||||
@ -59,9 +63,26 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v,
|
public void onCreateContextMenu(ContextMenu menu, View v,
|
||||||
ContextMenuInfo menuInfo) {
|
ContextMenuInfo menuInfo) {
|
||||||
|
|
||||||
getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu);
|
if (v.getId() == R.id.content) {
|
||||||
menu.setHeaderTitle(m_article.title);
|
HitTestResult result = ((WebView)v).getHitTestResult();
|
||||||
|
|
||||||
|
if (result.getType() == HitTestResult.IMAGE_TYPE || result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE) {
|
||||||
|
menu.setHeaderTitle(result.getExtra());
|
||||||
|
getActivity().getMenuInflater().inflate(R.menu.article_content_img_context_menu, menu);
|
||||||
|
|
||||||
|
/* FIXME I have no idea how to do this correctly ;( */
|
||||||
|
|
||||||
|
m_activity.setLastContentImageHitTestUrl(result.getExtra());
|
||||||
|
|
||||||
|
} else {
|
||||||
|
menu.setHeaderTitle(m_article.title);
|
||||||
|
getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
menu.setHeaderTitle(m_article.title);
|
||||||
|
getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu);
|
||||||
|
}
|
||||||
|
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
|
|
||||||
@ -143,6 +164,8 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
WebView web = (WebView)view.findViewById(R.id.content);
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
|
||||||
if (web != null) {
|
if (web != null) {
|
||||||
|
registerForContextMenu(web);
|
||||||
|
|
||||||
web.setWebChromeClient(new WebChromeClient() {
|
web.setWebChromeClient(new WebChromeClient() {
|
||||||
@Override
|
@Override
|
||||||
public void onProgressChanged(WebView view, int progress) {
|
public void onProgressChanged(WebView view, int progress) {
|
||||||
@ -319,7 +342,6 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
out.putParcelable("article", m_article);
|
out.putParcelable("article", m_article);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Activity activity) {
|
public void onAttach(Activity activity) {
|
||||||
super.onAttach(activity);
|
super.onAttach(activity);
|
||||||
@ -350,8 +372,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public void onLongPress(MotionEvent e) {
|
||||||
// TODO Auto-generated method stub
|
m_activity.openContextMenu(getView());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -39,6 +39,8 @@ import android.view.MenuInflater;
|
|||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
|
import android.webkit.WebView;
|
||||||
|
import android.webkit.WebView.HitTestResult;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.ShareActionProvider;
|
import android.widget.ShareActionProvider;
|
||||||
@ -61,6 +63,8 @@ public class OnlineActivity extends CommonActivity {
|
|||||||
private ActionMode m_headlinesActionMode;
|
private ActionMode m_headlinesActionMode;
|
||||||
private HeadlinesActionModeCallback m_headlinesActionModeCallback;
|
private HeadlinesActionModeCallback m_headlinesActionModeCallback;
|
||||||
|
|
||||||
|
private String m_lastImageHitTestUrl;
|
||||||
|
|
||||||
private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context content, Intent intent) {
|
public void onReceive(Context content, Intent intent) {
|
||||||
@ -536,6 +540,29 @@ public class OnlineActivity extends CommonActivity {
|
|||||||
final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
|
case R.id.article_img_open:
|
||||||
|
if (getLastContentImageHitTestUrl() != null) {
|
||||||
|
try {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW,
|
||||||
|
Uri.parse(getLastContentImageHitTestUrl()));
|
||||||
|
startActivity(intent);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
toast(R.string.error_other_error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
case R.id.article_img_share:
|
||||||
|
if (getLastContentImageHitTestUrl() != null) {
|
||||||
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
|
|
||||||
|
intent.setType("image/png");
|
||||||
|
intent.putExtra(Intent.EXTRA_SUBJECT, getLastContentImageHitTestUrl());
|
||||||
|
intent.putExtra(Intent.EXTRA_TEXT, getLastContentImageHitTestUrl());
|
||||||
|
|
||||||
|
startActivity(Intent.createChooser(intent, getLastContentImageHitTestUrl()));
|
||||||
|
}
|
||||||
|
return true;
|
||||||
case R.id.article_link_share:
|
case R.id.article_link_share:
|
||||||
if (ap != null && ap.getSelectedArticle() != null) {
|
if (ap != null && ap.getSelectedArticle() != null) {
|
||||||
shareArticle(ap.getSelectedArticle());
|
shareArticle(ap.getSelectedArticle());
|
||||||
@ -1570,4 +1597,12 @@ public class OnlineActivity extends CommonActivity {
|
|||||||
public String getViewMode() {
|
public String getViewMode() {
|
||||||
return m_prefs.getString("view_mode", "adaptive");
|
return m_prefs.getString("view_mode", "adaptive");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setLastContentImageHitTestUrl(String url) {
|
||||||
|
m_lastImageHitTestUrl = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastContentImageHitTestUrl() {
|
||||||
|
return m_lastImageHitTestUrl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user