add context menu for article link

This commit is contained in:
Andrew Dolgov 2012-03-12 11:51:57 +03:00
parent a8040597c1
commit bca4979935
6 changed files with 92 additions and 1 deletions

View 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>

View File

@ -127,4 +127,6 @@
<string name="donate_select">Please select the donation</string>
<string name="donate_do">Donate!</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>

View File

@ -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("<a href=\""+m_article.link.trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
registerForContextMenu(title);
}
WebView web = (WebView)view.findViewById(R.id.content);

View File

@ -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);

View File

@ -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;

View File

@ -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("<a href=\""+m_cursor.getString(m_cursor.getColumnIndex("link")).trim().replace("\"", "\\\"")+"\">" + titleStr + "</a>"));
registerForContextMenu(title);
}
WebView web = (WebView)view.findViewById(R.id.content);