Adding share option to context menu
This commit is contained in:
parent
776c9af611
commit
b0d07298dd
@ -110,6 +110,7 @@ import acr.browser.lightning.interpolator.BezierDecelerateInterpolator;
|
|||||||
import acr.browser.lightning.receiver.NetworkReceiver;
|
import acr.browser.lightning.receiver.NetworkReceiver;
|
||||||
import acr.browser.lightning.search.SuggestionsAdapter;
|
import acr.browser.lightning.search.SuggestionsAdapter;
|
||||||
import acr.browser.lightning.utils.DrawableUtils;
|
import acr.browser.lightning.utils.DrawableUtils;
|
||||||
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.Preconditions;
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
import acr.browser.lightning.utils.ProxyUtils;
|
import acr.browser.lightning.utils.ProxyUtils;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
@ -780,13 +781,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
|
overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_share:
|
case R.id.action_share:
|
||||||
if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) {
|
new IntentUtils(this).shareUrl(currentUrl, currentView != null ? currentView.getTitle() : null);
|
||||||
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
|
||||||
shareIntent.setType("text/plain");
|
|
||||||
shareIntent.putExtra(Intent.EXTRA_SUBJECT, currentView.getTitle());
|
|
||||||
shareIntent.putExtra(Intent.EXTRA_TEXT, currentUrl);
|
|
||||||
startActivity(Intent.createChooser(shareIntent, getResources().getString(R.string.dialog_title_share)));
|
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
case R.id.action_bookmarks:
|
case R.id.action_bookmarks:
|
||||||
openBookmarks();
|
openBookmarks();
|
||||||
|
@ -31,6 +31,7 @@ import acr.browser.lightning.database.HistoryItem;
|
|||||||
import acr.browser.lightning.database.bookmark.BookmarkModel;
|
import acr.browser.lightning.database.bookmark.BookmarkModel;
|
||||||
import acr.browser.lightning.database.history.HistoryModel;
|
import acr.browser.lightning.database.history.HistoryModel;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
import acr.browser.lightning.utils.IntentUtils;
|
||||||
import acr.browser.lightning.utils.Preconditions;
|
import acr.browser.lightning.utils.Preconditions;
|
||||||
import acr.browser.lightning.utils.Utils;
|
import acr.browser.lightning.utils.Utils;
|
||||||
|
|
||||||
@ -114,6 +115,12 @@ public class LightningDialogBuilder {
|
|||||||
uiController.handleNewTab(NewTab.INCOGNITO, item.getUrl());
|
uiController.handleNewTab(NewTab.INCOGNITO, item.getUrl());
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
new BrowserDialog.Item(R.string.action_share) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
new IntentUtils(activity).shareUrl(item.getUrl(), item.getTitle());
|
||||||
|
}
|
||||||
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
@ -277,6 +284,12 @@ public class LightningDialogBuilder {
|
|||||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
new BrowserDialog.Item(R.string.action_share) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
new IntentUtils(activity).shareUrl(url, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
@ -323,6 +336,12 @@ public class LightningDialogBuilder {
|
|||||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
new BrowserDialog.Item(R.string.action_share) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
new IntentUtils(activity).shareUrl(url, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
@ -359,6 +378,12 @@ public class LightningDialogBuilder {
|
|||||||
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
uiController.handleNewTab(NewTab.INCOGNITO, url);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
new BrowserDialog.Item(R.string.action_share) {
|
||||||
|
@Override
|
||||||
|
public void onClick() {
|
||||||
|
new IntentUtils(activity).shareUrl(url, null);
|
||||||
|
}
|
||||||
|
},
|
||||||
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
new BrowserDialog.Item(R.string.dialog_copy_link) {
|
||||||
@Override
|
@Override
|
||||||
public void onClick() {
|
public void onClick() {
|
||||||
|
@ -18,7 +18,9 @@ import java.util.List;
|
|||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
import acr.browser.lightning.controller.UIController;
|
||||||
|
|
||||||
public class IntentUtils {
|
public class IntentUtils {
|
||||||
|
|
||||||
@ -112,4 +114,24 @@ public class IntentUtils {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shares a URL to the system.
|
||||||
|
*
|
||||||
|
* @param url the URL to share. If the URL is null
|
||||||
|
* or a special URL, no sharing will occur.
|
||||||
|
* @param title the title of the URL to share. This
|
||||||
|
* is optional.
|
||||||
|
*/
|
||||||
|
public void shareUrl(@Nullable String url, @Nullable String title) {
|
||||||
|
if (url != null && !UrlUtils.isSpecialUrl(url)) {
|
||||||
|
Intent shareIntent = new Intent(Intent.ACTION_SEND);
|
||||||
|
shareIntent.setType("text/plain");
|
||||||
|
if (title != null) {
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
|
||||||
|
}
|
||||||
|
shareIntent.putExtra(Intent.EXTRA_TEXT, url);
|
||||||
|
mActivity.startActivity(Intent.createChooser(shareIntent, mActivity.getString(R.string.dialog_title_share)));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user