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