diff --git a/res/menu/article_link_context_menu.xml b/res/menu/article_link_context_menu.xml new file mode 100644 index 00000000..c20622a1 --- /dev/null +++ b/res/menu/article_link_context_menu.xml @@ -0,0 +1,13 @@ + + + + + + + \ No newline at end of file diff --git a/res/values/strings.xml b/res/values/strings.xml index 1af925e4..867120a5 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -127,4 +127,6 @@ Please select the donation Donate! Swipe between articles + Copy link to clipboard + Text copied to clipboard \ No newline at end of file diff --git a/src/org/fox/ttrss/ArticleFragment.java b/src/org/fox/ttrss/ArticleFragment.java index 6941cfca..3d803df8 100644 --- a/src/org/fox/ttrss/ArticleFragment.java +++ b/src/org/fox/ttrss/ArticleFragment.java @@ -20,12 +20,15 @@ import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.Log; import android.util.TypedValue; +import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ContextMenu.ContextMenuInfo; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.TextView; +import android.widget.AdapterView.AdapterContextMenuInfo; public class ArticleFragment extends Fragment { @SuppressWarnings("unused") @@ -49,6 +52,17 @@ public class ArticleFragment extends Fragment { private View.OnTouchListener m_gestureListener; + @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); + + super.onCreateContextMenu(menu, v, menuInfo); + + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -92,6 +106,7 @@ public class ArticleFragment extends Fragment { title.setMovementMethod(LinkMovementMethod.getInstance()); title.setText(Html.fromHtml("" + titleStr + "")); + registerForContextMenu(title); } WebView web = (WebView)view.findViewById(R.id.content); diff --git a/src/org/fox/ttrss/MainActivity.java b/src/org/fox/ttrss/MainActivity.java index d8143242..a4da377c 100644 --- a/src/org/fox/ttrss/MainActivity.java +++ b/src/org/fox/ttrss/MainActivity.java @@ -23,7 +23,6 @@ import android.database.sqlite.SQLiteDatabase; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; -import android.os.Handler; import android.preference.PreferenceManager; import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; @@ -1819,6 +1818,26 @@ public class MainActivity extends FragmentActivity implements OnlineServices { .findFragmentById(R.id.cats_fragment); switch (item.getItemId()) { + case R.id.article_link_save: + if (m_selectedArticle != null) { + if (android.os.Build.VERSION.SDK_INT < 11) { + @SuppressWarnings("deprecation") + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clipboard.setText(m_selectedArticle.link); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clipboard.setText(m_selectedArticle.link); + } + + Toast toast = Toast.makeText(MainActivity.this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT); + toast.show(); + } + return true; + case R.id.article_link_share: + if (m_selectedArticle != null) { + shareArticle(m_selectedArticle); + } + return true; case R.id.browse_articles: if (cf != null) { FeedCategory cat = cf.getCategoryAtPosition(info.position); diff --git a/src/org/fox/ttrss/OfflineActivity.java b/src/org/fox/ttrss/OfflineActivity.java index c0a60d14..90299487 100644 --- a/src/org/fox/ttrss/OfflineActivity.java +++ b/src/org/fox/ttrss/OfflineActivity.java @@ -34,6 +34,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo; import android.widget.EditText; import android.widget.SearchView; import android.widget.TextView; +import android.widget.Toast; public class OfflineActivity extends FragmentActivity implements OfflineServices { @@ -853,6 +854,33 @@ public class OfflineActivity extends FragmentActivity implements .findFragmentById(R.id.feeds_fragment); switch (item.getItemId()) { + case R.id.article_link_save: + if (m_selectedArticleId != 0) { + Cursor article = getArticleById(m_selectedArticleId); + + if (article != null) { + if (android.os.Build.VERSION.SDK_INT < 11) { + @SuppressWarnings("deprecation") + android.text.ClipboardManager clipboard = (android.text.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clipboard.setText(article.getString(article.getColumnIndex("link"))); + } else { + android.content.ClipboardManager clipboard = (android.content.ClipboardManager) getSystemService(CLIPBOARD_SERVICE); + clipboard.setText(article.getString(article.getColumnIndex("link"))); + } + + article.close(); + + Toast toast = Toast.makeText(OfflineActivity.this, R.string.text_copied_to_clipboard, Toast.LENGTH_SHORT); + toast.show(); + } + } + return true; + case R.id.article_link_share: + if (m_selectedArticleId != 0) { + shareArticle(m_selectedArticleId); + } + return true; + case R.id.browse_articles: // TODO cat stuff return true; diff --git a/src/org/fox/ttrss/OfflineArticleFragment.java b/src/org/fox/ttrss/OfflineArticleFragment.java index e0d5a7c0..c37c2a45 100644 --- a/src/org/fox/ttrss/OfflineArticleFragment.java +++ b/src/org/fox/ttrss/OfflineArticleFragment.java @@ -18,9 +18,11 @@ import android.support.v4.app.Fragment; import android.text.Html; import android.text.method.LinkMovementMethod; import android.util.TypedValue; +import android.view.ContextMenu; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.view.ContextMenu.ContextMenuInfo; import android.webkit.WebSettings; import android.webkit.WebView; import android.widget.TextView; @@ -43,6 +45,17 @@ public class OfflineArticleFragment extends Fragment { m_articleId = articleId; } + @Override + public void onCreateContextMenu(ContextMenu menu, View v, + ContextMenuInfo menuInfo) { + + getActivity().getMenuInflater().inflate(R.menu.article_link_context_menu, menu); + menu.setHeaderTitle(m_cursor.getString(m_cursor.getColumnIndex("title"))); + + super.onCreateContextMenu(menu, v, menuInfo); + + } + @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { @@ -93,6 +106,7 @@ public class OfflineArticleFragment extends Fragment { title.setMovementMethod(LinkMovementMethod.getInstance()); title.setText(Html.fromHtml("" + titleStr + "")); + registerForContextMenu(title); } WebView web = (WebView)view.findViewById(R.id.content);