diff --git a/AndroidManifest.xml b/AndroidManifest.xml index ccc44067..a64179bc 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -1,7 +1,7 @@ + + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 5e96736a..fb03519c 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -186,4 +186,6 @@ Starred Published Unread + Open image + Share image diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index cb2c94f4..0967ee9c 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -21,11 +21,13 @@ import android.os.Bundle; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.text.Html; +import android.util.Log; import android.util.TypedValue; import android.view.ContextMenu; import android.view.ContextMenu.ContextMenuInfo; import android.view.GestureDetector; import android.view.LayoutInflater; +import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; @@ -34,7 +36,9 @@ import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebSettings.LayoutAlgorithm; import android.webkit.WebView; +import android.webkit.WebView.HitTestResult; import android.widget.TextView; +import android.widget.AdapterView.AdapterContextMenuInfo; public class ArticleFragment extends Fragment implements GestureDetector.OnDoubleTapListener { private final String TAG = this.getClass().getSimpleName(); @@ -59,9 +63,26 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl @Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { - - getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu); - menu.setHeaderTitle(m_article.title); + + if (v.getId() == R.id.content) { + 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); @@ -143,6 +164,8 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl WebView web = (WebView)view.findViewById(R.id.content); if (web != null) { + registerForContextMenu(web); + web.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int progress) { @@ -319,7 +342,6 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl out.putParcelable("article", m_article); } - @Override public void onAttach(Activity activity) { super.onAttach(activity); @@ -350,8 +372,7 @@ public class ArticleFragment extends Fragment implements GestureDetector.OnDoubl @Override public void onLongPress(MotionEvent e) { - // TODO Auto-generated method stub - + m_activity.openContextMenu(getView()); } @Override diff --git a/src/org/fox/ttrss/OnlineActivity.java b/src/org/fox/ttrss/OnlineActivity.java index 7530ff1e..b33082e0 100644 --- a/src/org/fox/ttrss/OnlineActivity.java +++ b/src/org/fox/ttrss/OnlineActivity.java @@ -39,6 +39,8 @@ import android.view.MenuInflater; import android.view.MenuItem; import android.view.View; import android.view.Window; +import android.webkit.WebView; +import android.webkit.WebView.HitTestResult; import android.widget.EditText; import android.widget.SearchView; import android.widget.ShareActionProvider; @@ -61,6 +63,8 @@ public class OnlineActivity extends CommonActivity { private ActionMode m_headlinesActionMode; private HeadlinesActionModeCallback m_headlinesActionModeCallback; + private String m_lastImageHitTestUrl; + private BroadcastReceiver m_broadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context content, Intent intent) { @@ -536,6 +540,29 @@ public class OnlineActivity extends CommonActivity { final ArticlePager ap = (ArticlePager)getSupportFragmentManager().findFragmentByTag(FRAG_ARTICLE); 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: if (ap != null && ap.getSelectedArticle() != null) { shareArticle(ap.getSelectedArticle()); @@ -1570,4 +1597,12 @@ public class OnlineActivity extends CommonActivity { public String getViewMode() { return m_prefs.getString("view_mode", "adaptive"); } + + public void setLastContentImageHitTestUrl(String url) { + m_lastImageHitTestUrl = url; + } + + public String getLastContentImageHitTestUrl() { + return m_lastImageHitTestUrl; + } }