add context menu for article link
This commit is contained in:
parent
a8040597c1
commit
bca4979935
13
res/menu/article_link_context_menu.xml
Normal file
13
res/menu/article_link_context_menu.xml
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/article_link_share"
|
||||||
|
android:showAsAction=""
|
||||||
|
android:title="@string/share_article"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/article_link_save"
|
||||||
|
android:showAsAction=""
|
||||||
|
android:title="@string/article_link_copy"/>
|
||||||
|
|
||||||
|
</menu>
|
@ -127,4 +127,6 @@
|
|||||||
<string name="donate_select">Please select the donation</string>
|
<string name="donate_select">Please select the donation</string>
|
||||||
<string name="donate_do">Donate!</string>
|
<string name="donate_do">Donate!</string>
|
||||||
<string name="tablet_article_swipe">Swipe between articles</string>
|
<string name="tablet_article_swipe">Swipe between articles</string>
|
||||||
|
<string name="article_link_copy">Copy link to clipboard</string>
|
||||||
|
<string name="text_copied_to_clipboard">Text copied to clipboard</string>
|
||||||
</resources>
|
</resources>
|
@ -20,12 +20,15 @@ import android.text.Html;
|
|||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.AdapterView.AdapterContextMenuInfo;
|
||||||
|
|
||||||
public class ArticleFragment extends Fragment {
|
public class ArticleFragment extends Fragment {
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -49,6 +52,17 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
private View.OnTouchListener m_gestureListener;
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
@ -92,6 +106,7 @@ public class ArticleFragment extends Fragment {
|
|||||||
|
|
||||||
title.setMovementMethod(LinkMovementMethod.getInstance());
|
title.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
title.setText(Html.fromHtml("<a href=\""+m_article.link.trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
|
title.setText(Html.fromHtml("<a href=\""+m_article.link.trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
|
||||||
|
registerForContextMenu(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebView web = (WebView)view.findViewById(R.id.content);
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
@ -23,7 +23,6 @@ import android.database.sqlite.SQLiteDatabase;
|
|||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
@ -1819,6 +1818,26 @@ public class MainActivity extends FragmentActivity implements OnlineServices {
|
|||||||
.findFragmentById(R.id.cats_fragment);
|
.findFragmentById(R.id.cats_fragment);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
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:
|
case R.id.browse_articles:
|
||||||
if (cf != null) {
|
if (cf != null) {
|
||||||
FeedCategory cat = cf.getCategoryAtPosition(info.position);
|
FeedCategory cat = cf.getCategoryAtPosition(info.position);
|
||||||
|
@ -34,6 +34,7 @@ import android.widget.AdapterView.AdapterContextMenuInfo;
|
|||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.SearchView;
|
import android.widget.SearchView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
public class OfflineActivity extends FragmentActivity implements
|
public class OfflineActivity extends FragmentActivity implements
|
||||||
OfflineServices {
|
OfflineServices {
|
||||||
@ -853,6 +854,33 @@ public class OfflineActivity extends FragmentActivity implements
|
|||||||
.findFragmentById(R.id.feeds_fragment);
|
.findFragmentById(R.id.feeds_fragment);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
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:
|
case R.id.browse_articles:
|
||||||
// TODO cat stuff
|
// TODO cat stuff
|
||||||
return true;
|
return true;
|
||||||
|
@ -18,9 +18,11 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
import android.text.method.LinkMovementMethod;
|
import android.text.method.LinkMovementMethod;
|
||||||
import android.util.TypedValue;
|
import android.util.TypedValue;
|
||||||
|
import android.view.ContextMenu;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.view.ContextMenu.ContextMenuInfo;
|
||||||
import android.webkit.WebSettings;
|
import android.webkit.WebSettings;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
@ -43,6 +45,17 @@ public class OfflineArticleFragment extends Fragment {
|
|||||||
m_articleId = articleId;
|
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
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
|
|
||||||
@ -93,6 +106,7 @@ public class OfflineArticleFragment extends Fragment {
|
|||||||
|
|
||||||
title.setMovementMethod(LinkMovementMethod.getInstance());
|
title.setMovementMethod(LinkMovementMethod.getInstance());
|
||||||
title.setText(Html.fromHtml("<a href=\""+m_cursor.getString(m_cursor.getColumnIndex("link")).trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
|
title.setText(Html.fromHtml("<a href=\""+m_cursor.getString(m_cursor.getColumnIndex("link")).trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
|
||||||
|
registerForContextMenu(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
WebView web = (WebView)view.findViewById(R.id.content);
|
WebView web = (WebView)view.findViewById(R.id.content);
|
||||||
|
Loading…
Reference in New Issue
Block a user