Search in sources :

Example 16 with LightningView

use of acr.browser.lightning.view.LightningView 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)

Example 17 with LightningView

use of acr.browser.lightning.view.LightningView in project Lightning-Browser by anthonycr.

the class BrowserActivity method onShowCustomView.

@Override
public synchronized void onShowCustomView(final View view, CustomViewCallback callback, int requestedOrientation) {
    final LightningView currentTab = mTabsManager.getCurrentTab();
    if (view == null || mCustomView != null) {
        if (callback != null) {
            try {
                callback.onCustomViewHidden();
            } catch (Exception e) {
                Log.e(TAG, "Error hiding custom view", e);
            }
        }
        return;
    }
    try {
        view.setKeepScreenOn(true);
    } catch (SecurityException e) {
        Log.e(TAG, "WebView is not allowed to keep the screen on");
    }
    mOriginalOrientation = getRequestedOrientation();
    mCustomViewCallback = callback;
    mCustomView = view;
    setRequestedOrientation(requestedOrientation);
    final FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
    mFullscreenContainer = new FrameLayout(this);
    mFullscreenContainer.setBackgroundColor(ContextCompat.getColor(this, android.R.color.black));
    if (view instanceof FrameLayout) {
        if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
            mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
            mVideoView.setOnErrorListener(new VideoCompletionListener());
            mVideoView.setOnCompletionListener(new VideoCompletionListener());
        }
    } else if (view instanceof VideoView) {
        mVideoView = (VideoView) view;
        mVideoView.setOnErrorListener(new VideoCompletionListener());
        mVideoView.setOnCompletionListener(new VideoCompletionListener());
    }
    decorView.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
    mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
    decorView.requestLayout();
    setFullscreen(true, true);
    if (currentTab != null) {
        currentTab.setVisibility(View.INVISIBLE);
    }
}
Also used : VideoView(android.widget.VideoView) FrameLayout(android.widget.FrameLayout) LightningView(acr.browser.lightning.view.LightningView) IOException(java.io.IOException)

Example 18 with LightningView

use of acr.browser.lightning.view.LightningView in project Lightning-Browser by anthonycr.

the class BrowserActivity method onHideCustomView.

@Override
public void onHideCustomView() {
    final LightningView currentTab = mTabsManager.getCurrentTab();
    if (mCustomView == null || mCustomViewCallback == null || currentTab == null) {
        if (mCustomViewCallback != null) {
            try {
                mCustomViewCallback.onCustomViewHidden();
            } catch (Exception e) {
                Log.e(TAG, "Error hiding custom view", e);
            }
            mCustomViewCallback = null;
        }
        return;
    }
    Log.d(TAG, "onHideCustomView");
    currentTab.setVisibility(View.VISIBLE);
    try {
        mCustomView.setKeepScreenOn(false);
    } catch (SecurityException e) {
        Log.e(TAG, "WebView is not allowed to keep the screen on");
    }
    setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
    if (mFullscreenContainer != null) {
        ViewGroup parent = (ViewGroup) mFullscreenContainer.getParent();
        if (parent != null) {
            parent.removeView(mFullscreenContainer);
        }
        mFullscreenContainer.removeAllViews();
    }
    mFullscreenContainer = null;
    mCustomView = null;
    if (mVideoView != null) {
        Log.d(TAG, "VideoView is being stopped");
        mVideoView.stopPlayback();
        mVideoView.setOnErrorListener(null);
        mVideoView.setOnCompletionListener(null);
        mVideoView = null;
    }
    if (mCustomViewCallback != null) {
        try {
            mCustomViewCallback.onCustomViewHidden();
        } catch (Exception e) {
            Log.e(TAG, "Error hiding custom view", e);
        }
    }
    mCustomViewCallback = null;
    setRequestedOrientation(mOriginalOrientation);
}
Also used : ViewGroup(android.view.ViewGroup) LightningView(acr.browser.lightning.view.LightningView) IOException(java.io.IOException)

Example 19 with LightningView

use of acr.browser.lightning.view.LightningView in project Lightning-Browser by anthonycr.

the class TabsManager method restoreLostTabs.

private void restoreLostTabs(@Nullable final String url, @NonNull final Activity activity, @NonNull final CompletableSubscriber subscriber) {
    restoreState().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new StreamOnSubscribe<Bundle>() {

        @Override
        public void onNext(@Nullable Bundle item) {
            final LightningView tab = newTab(activity, "", false);
            Preconditions.checkNonNull(item);
            String url = item.getString(URL_KEY);
            if (url != null && tab.getWebView() != null) {
                if (UrlUtils.isBookmarkUrl(url)) {
                    new BookmarkPage(activity).getBookmarkPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isDownloadsUrl(url)) {
                    new DownloadsPage().getDownloadsPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isStartPageUrl(url)) {
                    new StartPage().getHomepage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                } else if (UrlUtils.isHistoryUrl(url)) {
                    new HistoryPage().getHistoryPage().subscribeOn(Schedulers.io()).observeOn(Schedulers.main()).subscribe(new SingleOnSubscribe<String>() {

                        @Override
                        public void onItem(@Nullable String item) {
                            Preconditions.checkNonNull(item);
                            tab.loadUrl(item);
                        }
                    });
                }
            } else if (tab.getWebView() != null) {
                tab.getWebView().restoreState(item);
            }
        }

        @Override
        public void onComplete() {
            if (url != null) {
                if (url.startsWith(Constants.FILE)) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(activity);
                    Dialog dialog = builder.setCancelable(true).setTitle(R.string.title_warning).setMessage(R.string.message_blocked_local).setOnDismissListener(new DialogInterface.OnDismissListener() {

                        @Override
                        public void onDismiss(DialogInterface dialog) {
                            if (mTabList.isEmpty()) {
                                newTab(activity, null, false);
                            }
                            finishInitialization();
                            subscriber.onComplete();
                        }
                    }).setNegativeButton(android.R.string.cancel, null).setPositiveButton(R.string.action_open, new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            newTab(activity, url, false);
                        }
                    }).show();
                    BrowserDialog.setDialogSize(activity, dialog);
                } else {
                    newTab(activity, url, false);
                    if (mTabList.isEmpty()) {
                        newTab(activity, null, false);
                    }
                    finishInitialization();
                    subscriber.onComplete();
                }
            } else {
                if (mTabList.isEmpty()) {
                    newTab(activity, null, false);
                }
                finishInitialization();
                subscriber.onComplete();
            }
        }
    });
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) HistoryPage(acr.browser.lightning.constant.HistoryPage) DialogInterface(android.content.DialogInterface) Bundle(android.os.Bundle) SingleOnSubscribe(com.anthonycr.bonsai.SingleOnSubscribe) BookmarkPage(acr.browser.lightning.constant.BookmarkPage) DownloadsPage(acr.browser.lightning.constant.DownloadsPage) StartPage(acr.browser.lightning.constant.StartPage) Dialog(android.app.Dialog) BrowserDialog(acr.browser.lightning.dialog.BrowserDialog) AlertDialog(android.support.v7.app.AlertDialog) LightningView(acr.browser.lightning.view.LightningView) Nullable(android.support.annotation.Nullable)

Example 20 with LightningView

use of acr.browser.lightning.view.LightningView in project Lightning-Browser by anthonycr.

the class TabsManager method deleteTab.

/**
     * Deletes a tab from the manager. If the tab
     * being deleted is the current tab, this method
     * will switch the current tab to a new valid tab.
     *
     * @param position the position of the tab to delete.
     * @return returns true if the current tab
     * was deleted, false otherwise.
     */
public synchronized boolean deleteTab(int position) {
    Log.d(TAG, "Delete tab: " + position);
    final LightningView currentTab = getCurrentTab();
    int current = positionOf(currentTab);
    if (current == position) {
        if (size() == 1) {
            mCurrentTab = null;
        } else if (current < size() - 1) {
            // There is another tab after this one
            switchToTab(current + 1);
        } else {
            switchToTab(current - 1);
        }
    }
    removeTab(position);
    if (mTabNumberListener != null) {
        mTabNumberListener.tabNumberChanged(size());
    }
    return current == position;
}
Also used : LightningView(acr.browser.lightning.view.LightningView)

Aggregations

LightningView (acr.browser.lightning.view.LightningView)27 Intent (android.content.Intent)3 DialogInterface (android.content.DialogInterface)2 Bundle (android.os.Bundle)2 IOException (java.io.IOException)2 BookmarkPage (acr.browser.lightning.constant.BookmarkPage)1 DownloadsPage (acr.browser.lightning.constant.DownloadsPage)1 HistoryPage (acr.browser.lightning.constant.HistoryPage)1 StartPage (acr.browser.lightning.constant.StartPage)1 HistoryItem (acr.browser.lightning.database.HistoryItem)1 BrowserDialog (acr.browser.lightning.dialog.BrowserDialog)1 BookmarksFragment (acr.browser.lightning.fragment.BookmarksFragment)1 TabsFragment (acr.browser.lightning.fragment.TabsFragment)1 IntentUtils (acr.browser.lightning.utils.IntentUtils)1 Dialog (android.app.Dialog)1 ClipData (android.content.ClipData)1 ClipboardManager (android.content.ClipboardManager)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 Fragment (android.support.v4.app.Fragment)1