Search in sources :

Example 21 with LightningView

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

the class TabsManager method shutdown.

/**
     * Shutdown the manager. This destroys
     * all tabs and clears the references
     * to those tabs. Current tab is also
     * released for garbage collection.
     */
public synchronized void shutdown() {
    for (LightningView tab : mTabList) {
        tab.onDestroy();
    }
    mTabList.clear();
    mIsInitialized = false;
    mCurrentTab = null;
}
Also used : LightningView(acr.browser.lightning.view.LightningView)

Example 22 with LightningView

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

the class TabsManager method newTab.

/**
     * Create and return a new tab. The tab is
     * automatically added to the tabs list.
     *
     * @param activity    the activity needed to create the tab.
     * @param url         the URL to initialize the tab with.
     * @param isIncognito whether the tab is an incognito
     *                    tab or not.
     * @return a valid initialized tab.
     */
@NonNull
public synchronized LightningView newTab(@NonNull final Activity activity, @Nullable final String url, final boolean isIncognito) {
    Log.d(TAG, "New tab");
    final LightningView tab = new LightningView(activity, url, isIncognito);
    mTabList.add(tab);
    if (mTabNumberListener != null) {
        mTabNumberListener.tabNumberChanged(size());
    }
    return tab;
}
Also used : LightningView(acr.browser.lightning.view.LightningView) NonNull(android.support.annotation.NonNull)

Example 23 with LightningView

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

the class BrowserPresenter method onNewIntent.

/**
     * Handle a new intent from the the main
     * BrowserActivity.
     *
     * @param intent the intent to handle,
     *               may be null.
     */
public void onNewIntent(@Nullable final Intent intent) {
    mTabsModel.doAfterInitialization(new Runnable() {

        @Override
        public void run() {
            final String url;
            if (intent != null) {
                url = intent.getDataString();
            } else {
                url = null;
            }
            int tabHashCode = 0;
            if (intent != null && intent.getExtras() != null) {
                tabHashCode = intent.getExtras().getInt(Constants.INTENT_ORIGIN);
            }
            if (tabHashCode != 0) {
                LightningView tab = mTabsModel.getTabForHashCode(tabHashCode);
                if (tab != null) {
                    tab.loadUrl(url);
                }
            } else if (url != null) {
                if (url.startsWith(Constants.FILE)) {
                    mView.showBlockedLocalFileDialog(new DialogInterface.OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            newTab(url, true);
                            mShouldClose = true;
                            LightningView tab = mTabsModel.lastTab();
                            if (tab != null) {
                                tab.setIsNewTab(true);
                            }
                        }
                    });
                } else {
                    newTab(url, true);
                    mShouldClose = true;
                    LightningView tab = mTabsModel.lastTab();
                    if (tab != null) {
                        tab.setIsNewTab(true);
                    }
                }
            }
        }
    });
}
Also used : DialogInterface(android.content.DialogInterface) LightningView(acr.browser.lightning.view.LightningView)

Example 24 with LightningView

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

the class BrowserPresenter method deleteTab.

/**
     * Deletes the tab at the specified position.
     *
     * @param position the position at which to
     *                 delete the tab.
     */
public void deleteTab(int position) {
    Log.d(TAG, "delete Tab");
    final LightningView tabToDelete = mTabsModel.getTabAtPosition(position);
    if (tabToDelete == null) {
        return;
    }
    if (!UrlUtils.isSpecialUrl(tabToDelete.getUrl()) && !mIsIncognito) {
        mPreferences.setSavedUrl(tabToDelete.getUrl());
    }
    final boolean isShown = tabToDelete.isShown();
    boolean shouldClose = mShouldClose && isShown && tabToDelete.isNewTab();
    final LightningView currentTab = mTabsModel.getCurrentTab();
    if (mTabsModel.size() == 1 && currentTab != null && (UrlUtils.isStartPageUrl(currentTab.getUrl()) || currentTab.getUrl().equals(mPreferences.getHomepage()))) {
        mView.closeActivity();
        return;
    } else {
        if (isShown) {
            mView.removeTabView();
        }
        boolean currentDeleted = mTabsModel.deleteTab(position);
        if (currentDeleted) {
            tabChanged(mTabsModel.indexOfCurrentTab());
        }
    }
    final LightningView afterTab = mTabsModel.getCurrentTab();
    mView.notifyTabViewRemoved(position);
    if (afterTab == null) {
        mView.closeBrowser();
        return;
    } else if (afterTab != currentTab) {
        //TODO remove this?
        //            switchTabs(currentTab, afterTab);
        //            if (currentTab != null) {
        //                currentTab.pauseTimers();
        //            }
        mView.notifyTabViewChanged(mTabsModel.indexOfCurrentTab());
    }
    if (shouldClose) {
        mShouldClose = false;
        mView.closeActivity();
    }
    mView.updateTabNumber(mTabsModel.size());
    Log.d(TAG, "deleted tab");
}
Also used : LightningView(acr.browser.lightning.view.LightningView)

Example 25 with LightningView

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

the class BrowserPresenter method newTab.

/**
     * Open a new tab with the specified URL. You
     * can choose to show the tab or load it in the
     * background.
     *
     * @param url  the URL to load, may be null if you
     *             don't wish to load anything.
     * @param show whether or not to switch to this
     *             tab after opening it.
     * @return true if we successfully created the tab,
     * false if we have hit max tabs.
     */
public synchronized boolean newTab(@Nullable String url, boolean show) {
    // Limit number of tabs for limited version of app
    if (!BuildConfig.FULL_VERSION && mTabsModel.size() >= 10) {
        mView.showSnackbar(R.string.max_tabs);
        return false;
    }
    Log.d(TAG, "New tab, show: " + show);
    LightningView startingTab = mTabsModel.newTab((Activity) mView, url, mIsIncognito);
    if (mTabsModel.size() == 1) {
        startingTab.resumeTimers();
    }
    mView.notifyTabViewAdded();
    if (show) {
        LightningView tab = mTabsModel.switchToTab(mTabsModel.last());
        onTabChanged(tab);
    }
    mView.updateTabNumber(mTabsModel.size());
    return true;
}
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