Search in sources :

Example 1 with IntentUtils

use of acr.browser.lightning.utils.IntentUtils in project Lightning-Browser by anthonycr.

the class BrowserActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final LightningView currentView = mTabsManager.getCurrentTab();
    final String currentUrl = currentView != null ? currentView.getUrl() : null;
    // Handle action buttons
    switch(item.getItemId()) {
        case android.R.id.home:
            if (mDrawerLayout.isDrawerOpen(getBookmarkDrawer())) {
                mDrawerLayout.closeDrawer(getBookmarkDrawer());
            }
            return true;
        case R.id.action_back:
            if (currentView != null && currentView.canGoBack()) {
                currentView.goBack();
            }
            return true;
        case R.id.action_forward:
            if (currentView != null && currentView.canGoForward()) {
                currentView.goForward();
            }
            return true;
        case R.id.action_add_to_homescreen:
            if (currentView != null) {
                HistoryItem shortcut = new HistoryItem(currentView.getUrl(), currentView.getTitle());
                shortcut.setBitmap(currentView.getFavicon());
                Utils.createShortcut(this, shortcut);
            }
            return true;
        case R.id.action_new_tab:
            newTab(null, true);
            return true;
        case R.id.action_incognito:
            startActivity(new Intent(this, IncognitoActivity.class));
            overridePendingTransition(R.anim.slide_up_in, R.anim.fade_out_scale);
            return true;
        case R.id.action_share:
            new IntentUtils(this).shareUrl(currentUrl, currentView != null ? currentView.getTitle() : null);
            return true;
        case R.id.action_bookmarks:
            openBookmarks();
            return true;
        case R.id.action_copy:
            if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) {
                ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
                ClipData clip = ClipData.newPlainText("label", currentUrl);
                clipboard.setPrimaryClip(clip);
                Utils.showSnackbar(this, R.string.message_link_copied);
            }
            return true;
        case R.id.action_settings:
            startActivity(new Intent(this, SettingsActivity.class));
            return true;
        case R.id.action_history:
            openHistory();
            return true;
        case R.id.action_downloads:
            openDownloads();
            return true;
        case R.id.action_add_bookmark:
            if (currentUrl != null && !UrlUtils.isSpecialUrl(currentUrl)) {
                addBookmark(currentView.getTitle(), currentUrl);
            }
            return true;
        case R.id.action_find:
            findInPage();
            return true;
        case R.id.action_reading_mode:
            if (currentUrl != null) {
                Intent read = new Intent(this, ReadingActivity.class);
                read.putExtra(Constants.LOAD_READING_URL, currentUrl);
                startActivity(read);
            }
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
Also used : ClipboardManager(android.content.ClipboardManager) HistoryItem(acr.browser.lightning.database.HistoryItem) IntentUtils(acr.browser.lightning.utils.IntentUtils) LightningView(acr.browser.lightning.view.LightningView) Intent(android.content.Intent) ClipData(android.content.ClipData)

Aggregations

HistoryItem (acr.browser.lightning.database.HistoryItem)1 IntentUtils (acr.browser.lightning.utils.IntentUtils)1 LightningView (acr.browser.lightning.view.LightningView)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 Intent (android.content.Intent)1