Search in sources :

Example 11 with LightningView

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

the class BrowserActivity method initializePreferences.

private void initializePreferences() {
    final LightningView currentView = mTabsManager.getCurrentTab();
    mFullScreen = mPreferences.getFullScreenEnabled();
    boolean colorMode = mPreferences.getColorModeEnabled();
    colorMode &= !mDarkTheme;
    if (!isIncognito() && !colorMode && !mDarkTheme && mWebpageBitmap != null) {
        changeToolbarBackground(mWebpageBitmap, null);
    } else if (!isIncognito() && currentView != null && !mDarkTheme) {
        changeToolbarBackground(currentView.getFavicon(), null);
    } else if (!isIncognito() && !mDarkTheme && mWebpageBitmap != null) {
        changeToolbarBackground(mWebpageBitmap, null);
    }
    FragmentManager manager = getSupportFragmentManager();
    Fragment tabsFragment = manager.findFragmentByTag(TAG_TABS_FRAGMENT);
    if (tabsFragment instanceof TabsFragment) {
        ((TabsFragment) tabsFragment).reinitializePreferences();
    }
    Fragment bookmarksFragment = manager.findFragmentByTag(TAG_BOOKMARK_FRAGMENT);
    if (bookmarksFragment instanceof BookmarksFragment) {
        ((BookmarksFragment) bookmarksFragment).reinitializePreferences();
    }
    // TODO layout transition causing memory leak
    //        mBrowserFrame.setLayoutTransition(new LayoutTransition());
    setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
    switch(mPreferences.getSearchChoice()) {
        case 0:
            mSearchText = mPreferences.getSearchUrl();
            if (!mSearchText.startsWith(Constants.HTTP) && !mSearchText.startsWith(Constants.HTTPS)) {
                mSearchText = Constants.GOOGLE_SEARCH;
            }
            break;
        case 1:
            mSearchText = Constants.GOOGLE_SEARCH;
            break;
        case 2:
            mSearchText = Constants.ASK_SEARCH;
            break;
        case 3:
            mSearchText = Constants.BING_SEARCH;
            break;
        case 4:
            mSearchText = Constants.YAHOO_SEARCH;
            break;
        case 5:
            mSearchText = Constants.STARTPAGE_SEARCH;
            break;
        case 6:
            mSearchText = Constants.STARTPAGE_MOBILE_SEARCH;
            break;
        case 7:
            mSearchText = Constants.DUCK_SEARCH;
            break;
        case 8:
            mSearchText = Constants.DUCK_LITE_SEARCH;
            break;
        case 9:
            mSearchText = Constants.BAIDU_SEARCH;
            break;
        case 10:
            mSearchText = Constants.YANDEX_SEARCH;
            break;
    }
    updateCookiePreference().subscribeOn(Schedulers.worker()).subscribe();
    mProxyUtils.updateProxySettings(this);
}
Also used : FragmentManager(android.support.v4.app.FragmentManager) BookmarksFragment(acr.browser.lightning.fragment.BookmarksFragment) TabsFragment(acr.browser.lightning.fragment.TabsFragment) LightningView(acr.browser.lightning.view.LightningView) Fragment(android.support.v4.app.Fragment) BookmarksFragment(acr.browser.lightning.fragment.BookmarksFragment) TabsFragment(acr.browser.lightning.fragment.TabsFragment)

Example 12 with LightningView

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

the class BookmarksFragment method onClick.

@Override
public void onClick(@NonNull View v) {
    switch(v.getId()) {
        case R.id.action_add_bookmark:
            mUiController.bookmarkButtonClicked();
            break;
        case R.id.action_reading:
            LightningView currentTab = getTabsManager().getCurrentTab();
            if (currentTab != null) {
                Intent read = new Intent(getActivity(), ReadingActivity.class);
                read.putExtra(Constants.LOAD_READING_URL, currentTab.getUrl());
                startActivity(read);
            }
            break;
        case R.id.action_toggle_desktop:
            LightningView current = getTabsManager().getCurrentTab();
            if (current != null) {
                current.toggleDesktopUA(getActivity());
                current.reload();
            // TODO add back drawer closing
            }
            break;
        default:
            break;
    }
}
Also used : LightningView(acr.browser.lightning.view.LightningView) Intent(android.content.Intent)

Example 13 with LightningView

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

the class BrowserActivity method dispatchKeyEvent.

@Override
public boolean dispatchKeyEvent(KeyEvent event) {
    // Keyboard shortcuts
    if (event.isCtrlPressed() && event.getAction() == KeyEvent.ACTION_DOWN) {
        switch(event.getKeyCode()) {
            case KeyEvent.KEYCODE_T:
                // Open new tab
                newTab(null, true);
                return true;
            case KeyEvent.KEYCODE_W:
                // Close current tab
                mPresenter.deleteTab(mTabsManager.indexOfCurrentTab());
                return true;
            case KeyEvent.KEYCODE_Q:
                // Close browser
                closeBrowser();
                return true;
            case KeyEvent.KEYCODE_R:
                // Refresh current tab
                LightningView currentTab = mTabsManager.getCurrentTab();
                if (currentTab != null) {
                    currentTab.reload();
                }
                return true;
            case KeyEvent.KEYCODE_TAB:
                int nextIndex = 0;
                if (event.isShiftPressed()) {
                    // Go back one tab
                    if (mTabsManager.indexOfCurrentTab() > 0) {
                        nextIndex = mTabsManager.indexOfCurrentTab() - 1;
                    } else {
                        nextIndex = mTabsManager.last();
                    }
                } else {
                    // Go forward one tab
                    if (mTabsManager.indexOfCurrentTab() < mTabsManager.last()) {
                        nextIndex = mTabsManager.indexOfCurrentTab() + 1;
                    } else {
                        nextIndex = 0;
                    }
                }
                mPresenter.tabChanged(nextIndex);
                return true;
        }
    } else if (event.getAction() == KeyEvent.ACTION_DOWN && event.getKeyCode() == KeyEvent.KEYCODE_SEARCH) {
        // Highlight search field
        mSearch.requestFocus();
        mSearch.selectAll();
        return true;
    }
    return super.dispatchKeyEvent(event);
}
Also used : LightningView(acr.browser.lightning.view.LightningView)

Example 14 with LightningView

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

the class BrowserActivity method onForwardButtonPressed.

@Override
public void onForwardButtonPressed() {
    final LightningView currentTab = mTabsManager.getCurrentTab();
    if (currentTab != null) {
        if (currentTab.canGoForward()) {
            currentTab.goForward();
            closeDrawers(null);
        }
    }
}
Also used : LightningView(acr.browser.lightning.view.LightningView)

Example 15 with LightningView

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

the class BrowserActivity method updateUrl.

@Override
public void updateUrl(@Nullable String url, boolean shortUrl) {
    if (url == null || mSearch == null || mSearch.hasFocus()) {
        return;
    }
    final LightningView currentTab = mTabsManager.getCurrentTab();
    mBookmarksView.handleUpdatedUrl(url);
    if (shortUrl && !UrlUtils.isSpecialUrl(url)) {
        switch(mPreferences.getUrlBoxContentChoice()) {
            case // Default, show only the domain
            0:
                url = url.replaceFirst(Constants.HTTP, "");
                url = Utils.getDomainName(url);
                mSearch.setText(url);
                break;
            case // URL, show the entire URL
            1:
                mSearch.setText(url);
                break;
            case // Title, show the page's title
            2:
                if (currentTab != null && !currentTab.getTitle().isEmpty()) {
                    mSearch.setText(currentTab.getTitle());
                } else {
                    mSearch.setText(mUntitledTitle);
                }
                break;
        }
    } else {
        if (UrlUtils.isSpecialUrl(url)) {
            url = "";
        }
        mSearch.setText(url);
    }
}
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