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;
}
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;
}
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);
}
}
}
}
});
}
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");
}
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;
}
Aggregations