Fixed bugs in showTab, attempt to improve full-screen video handling.
This commit is contained in:
parent
9f755aeed7
commit
bf4c90b121
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
package acr.browser.lightning.activity;
|
package acr.browser.lightning.activity;
|
||||||
|
|
||||||
|
import android.animation.Animator;
|
||||||
import android.animation.ArgbEvaluator;
|
import android.animation.ArgbEvaluator;
|
||||||
import android.animation.LayoutTransition;
|
import android.animation.LayoutTransition;
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
@ -996,13 +997,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
if (current > position) {
|
if (current > position) {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(current - 1);
|
|
||||||
mEventBus.post(new BrowserEvents.TabsChanged());
|
mEventBus.post(new BrowserEvents.TabsChanged());
|
||||||
} else if (tabsManager.size() > position + 1) {
|
} else if (tabsManager.size() > position + 1) {
|
||||||
if (current == position) {
|
if (current == position) {
|
||||||
showTab(position + 1);
|
showTab(position + 1);
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(position);
|
|
||||||
mEventBus.post(new BrowserEvents.TabsChanged());
|
mEventBus.post(new BrowserEvents.TabsChanged());
|
||||||
} else {
|
} else {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
@ -1011,7 +1010,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (current == position) {
|
if (current == position) {
|
||||||
showTab(position - 1);
|
showTab(position - 1);
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
showTab(position - 1);
|
|
||||||
mEventBus.post(new BrowserEvents.TabsChanged());
|
mEventBus.post(new BrowserEvents.TabsChanged());
|
||||||
} else {
|
} else {
|
||||||
tabsManager.deleteTab(position);
|
tabsManager.deleteTab(position);
|
||||||
@ -1078,13 +1076,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBackPressed() {
|
public synchronized void onBackPressed() {
|
||||||
final LightningView currentTab = tabsManager.getCurrentTab();
|
final LightningView currentTab = tabsManager.getCurrentTab();
|
||||||
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) {
|
||||||
mDrawerLayout.closeDrawer(mDrawerLeft);
|
mDrawerLayout.closeDrawer(mDrawerLeft);
|
||||||
} else if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
|
} else if (mDrawerLayout.isDrawerOpen(mDrawerRight)) {
|
||||||
mEventBus
|
mEventBus.post(new BrowserEvents.UserPressedBack());
|
||||||
.post(new BrowserEvents.UserPressedBack());
|
|
||||||
} else {
|
} else {
|
||||||
if (currentTab != null) {
|
if (currentTab != null) {
|
||||||
Log.d(Constants.TAG, "onBackPressed");
|
Log.d(Constants.TAG, "onBackPressed");
|
||||||
@ -1097,7 +1094,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
currentTab.goBack();
|
currentTab.goBack();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
deleteTab(tabsManager.positionOf(currentTab));
|
if (mCustomView != null || mCustomViewCallback != null) {
|
||||||
|
onHideCustomView();
|
||||||
|
} else {
|
||||||
|
deleteTab(tabsManager.positionOf(currentTab));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Log.e(Constants.TAG, "This shouldn't happen ever");
|
Log.e(Constants.TAG, "This shouldn't happen ever");
|
||||||
@ -1511,17 +1512,26 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
|
chooserIntent.putExtra(Intent.EXTRA_TITLE, "Image Chooser");
|
||||||
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
|
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, intentArray);
|
||||||
|
|
||||||
this.startActivityForResult(chooserIntent, 1);
|
startActivityForResult(chooserIntent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShowCustomView(View view, CustomViewCallback callback) {
|
public synchronized void onShowCustomView(View view, CustomViewCallback callback) {
|
||||||
|
int requestedOrientation = mOriginalOrientation = getRequestedOrientation();
|
||||||
|
onShowCustomView(view, callback, requestedOrientation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public synchronized void onShowCustomView(final View view, CustomViewCallback callback, int requestedOrientation) {
|
||||||
final LightningView currentTab = tabsManager.getCurrentTab();
|
final LightningView currentTab = tabsManager.getCurrentTab();
|
||||||
if (view == null) {
|
if (view == null || mCustomView != null) {
|
||||||
return;
|
if (callback != null) {
|
||||||
}
|
try {
|
||||||
if (mCustomView != null && callback != null) {
|
callback.onCustomViewHidden();
|
||||||
callback.onCustomViewHidden();
|
} catch (Exception e) {
|
||||||
|
Log.e(Constants.TAG, "Error hiding custom view", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
@ -1530,30 +1540,46 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
||||||
}
|
}
|
||||||
mOriginalOrientation = getRequestedOrientation();
|
mOriginalOrientation = getRequestedOrientation();
|
||||||
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
mCustomViewCallback = callback;
|
||||||
|
mCustomView = view;
|
||||||
|
|
||||||
|
setRequestedOrientation(requestedOrientation);
|
||||||
|
final FrameLayout decorView = (FrameLayout) getWindow().getDecorView();
|
||||||
|
|
||||||
mFullscreenContainer = new FrameLayout(this);
|
mFullscreenContainer = new FrameLayout(this);
|
||||||
mFullscreenContainer.setBackgroundColor(ContextCompat.getColor(this, android.R.color.black));
|
mFullscreenContainer.setBackgroundColor(ContextCompat.getColor(this, android.R.color.black));
|
||||||
mCustomView = view;
|
|
||||||
mFullscreenContainer.addView(mCustomView, COVER_SCREEN_PARAMS);
|
|
||||||
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
|
|
||||||
setFullscreen(true, true);
|
|
||||||
if (currentTab != null) {
|
|
||||||
currentTab.setVisibility(View.GONE);
|
|
||||||
}
|
|
||||||
if (view instanceof FrameLayout) {
|
if (view instanceof FrameLayout) {
|
||||||
if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
|
if (((FrameLayout) view).getFocusedChild() instanceof VideoView) {
|
||||||
mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
|
mVideoView = (VideoView) ((FrameLayout) view).getFocusedChild();
|
||||||
mVideoView.setOnErrorListener(new VideoCompletionListener());
|
mVideoView.setOnErrorListener(new VideoCompletionListener());
|
||||||
mVideoView.setOnCompletionListener(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);
|
||||||
}
|
}
|
||||||
mCustomViewCallback = callback;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onHideCustomView() {
|
public void onHideCustomView() {
|
||||||
final LightningView currentTab = tabsManager.getCurrentTab();
|
final LightningView currentTab = tabsManager.getCurrentTab();
|
||||||
if (mCustomView == null || mCustomViewCallback == null || currentTab == null) {
|
if (mCustomView == null || mCustomViewCallback == null || currentTab == null) {
|
||||||
|
if (mCustomViewCallback != null) {
|
||||||
|
try {
|
||||||
|
mCustomViewCallback.onCustomViewHidden();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(Constants.TAG, "Error hiding custom view", e);
|
||||||
|
}
|
||||||
|
mCustomViewCallback = null;
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Log.d(Constants.TAG, "onHideCustomView");
|
Log.d(Constants.TAG, "onHideCustomView");
|
||||||
@ -1564,25 +1590,31 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
Log.e(Constants.TAG, "WebView is not allowed to keep the screen on");
|
||||||
}
|
}
|
||||||
setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
|
setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
|
||||||
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
if (mFullscreenContainer != null) {
|
||||||
if (decor != null) {
|
ViewGroup parent = (ViewGroup) mFullscreenContainer.getParent();
|
||||||
decor.removeView(mFullscreenContainer);
|
if (parent != null) {
|
||||||
}
|
parent.removeView(mFullscreenContainer);
|
||||||
|
|
||||||
if (API < Build.VERSION_CODES.KITKAT) {
|
|
||||||
try {
|
|
||||||
mCustomViewCallback.onCustomViewHidden();
|
|
||||||
} catch (Throwable ignored) {
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
mFullscreenContainer.removeAllViews();
|
||||||
}
|
}
|
||||||
|
|
||||||
mFullscreenContainer = null;
|
mFullscreenContainer = null;
|
||||||
mCustomView = null;
|
mCustomView = null;
|
||||||
if (mVideoView != null) {
|
if (mVideoView != null) {
|
||||||
|
Log.d(Constants.TAG, "VideoView is being stopped");
|
||||||
|
mVideoView.stopPlayback();
|
||||||
mVideoView.setOnErrorListener(null);
|
mVideoView.setOnErrorListener(null);
|
||||||
mVideoView.setOnCompletionListener(null);
|
mVideoView.setOnCompletionListener(null);
|
||||||
mVideoView = null;
|
mVideoView = null;
|
||||||
}
|
}
|
||||||
|
if (mCustomViewCallback != null) {
|
||||||
|
try {
|
||||||
|
mCustomViewCallback.onCustomViewHidden();
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.e(Constants.TAG, "Error hiding custom view", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mCustomViewCallback = null;
|
||||||
setRequestedOrientation(mOriginalOrientation);
|
setRequestedOrientation(mOriginalOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -165,6 +165,9 @@ public class TabsManager {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
final LightningView tab = mWebViewList.remove(position);
|
final LightningView tab = mWebViewList.remove(position);
|
||||||
|
if (mCurrentTab == tab) {
|
||||||
|
mCurrentTab = null;
|
||||||
|
}
|
||||||
tab.onDestroy();
|
tab.onDestroy();
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
@ -227,8 +230,11 @@ public class TabsManager {
|
|||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
final LightningView tab = mWebViewList.get(position);
|
final LightningView tab = mWebViewList.get(position);
|
||||||
mCurrentTab = tab;
|
if (tab != null) {
|
||||||
|
mCurrentTab = tab;
|
||||||
|
}
|
||||||
return tab;
|
return tab;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -35,6 +35,8 @@ public interface UIController {
|
|||||||
|
|
||||||
void onShowCustomView(View view, CustomViewCallback callback);
|
void onShowCustomView(View view, CustomViewCallback callback);
|
||||||
|
|
||||||
|
void onShowCustomView(View view, CustomViewCallback callback, int requestedOrienation);
|
||||||
|
|
||||||
void onHideCustomView();
|
void onHideCustomView();
|
||||||
|
|
||||||
void onCreateWindow(Message resultMsg);
|
void onCreateWindow(Message resultMsg);
|
||||||
|
@ -193,6 +193,9 @@ class LightningChromeClient extends WebChromeClient {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Bitmap getDefaultVideoPoster() {
|
public Bitmap getDefaultVideoPoster() {
|
||||||
|
if (mActivity == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final Resources resources = mActivity.getResources();
|
final Resources resources = mActivity.getResources();
|
||||||
return BitmapFactory.decodeResource(resources, android.R.drawable.spinner_background);
|
return BitmapFactory.decodeResource(resources, android.R.drawable.spinner_background);
|
||||||
}
|
}
|
||||||
@ -213,50 +216,17 @@ class LightningChromeClient extends WebChromeClient {
|
|||||||
@Override
|
@Override
|
||||||
public void onHideCustomView() {
|
public void onHideCustomView() {
|
||||||
mUIController.onHideCustomView();
|
mUIController.onHideCustomView();
|
||||||
super.onHideCustomView();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShowCustomView(View view, CustomViewCallback callback) {
|
public void onShowCustomView(View view, CustomViewCallback callback) {
|
||||||
// While these lines might look like they work, in practice,
|
|
||||||
// Full-screen videos won't work correctly. I may test this out some
|
|
||||||
// more
|
|
||||||
// if (view instanceof FrameLayout) {
|
|
||||||
// FrameLayout frame = (FrameLayout) view;
|
|
||||||
// if (frame.getFocusedChild() instanceof VideoView) {
|
|
||||||
// VideoView video = (VideoView) frame.getFocusedChild();
|
|
||||||
// video.stopPlayback();
|
|
||||||
// frame.removeView(video);
|
|
||||||
// video.setVisibility(View.GONE);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
mUIController.onShowCustomView(view, callback);
|
mUIController.onShowCustomView(view, callback);
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
super.onShowCustomView(view, callback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
@Override
|
@Override
|
||||||
public void onShowCustomView(View view, int requestedOrientation,
|
public void onShowCustomView(View view, int requestedOrientation,
|
||||||
CustomViewCallback callback) {
|
CustomViewCallback callback) {
|
||||||
// While these lines might look like they work, in practice,
|
mUIController.onShowCustomView(view, callback, requestedOrientation);
|
||||||
// Full-screen videos won't work correctly. I may test this out some
|
|
||||||
// more
|
|
||||||
// if (view instanceof FrameLayout) {
|
|
||||||
// FrameLayout frame = (FrameLayout) view;
|
|
||||||
// if (frame.getFocusedChild() instanceof VideoView) {
|
|
||||||
// VideoView video = (VideoView) frame.getFocusedChild();
|
|
||||||
// video.stopPlayback();
|
|
||||||
// frame.removeView(video);
|
|
||||||
// video.setVisibility(View.GONE);
|
|
||||||
// }
|
|
||||||
// } else {
|
|
||||||
mUIController.onShowCustomView(view, callback);
|
|
||||||
|
|
||||||
// }
|
|
||||||
|
|
||||||
super.onShowCustomView(view, requestedOrientation, callback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package acr.browser.lightning.view;
|
package acr.browser.lightning.view;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.TargetApi;
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ActivityNotFoundException;
|
import android.content.ActivityNotFoundException;
|
||||||
import android.content.DialogInterface;
|
import android.content.DialogInterface;
|
||||||
@ -64,18 +64,18 @@ class LightningWebClient extends WebViewClient {
|
|||||||
mIntentUtils = new IntentUtils(activity);
|
mIntentUtils = new IntentUtils(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (mAdBlock.isAd(request.getUrl().toString())) {
|
||||||
if (mAdBlock.isAd(request.getUrl().toString())) {
|
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
|
||||||
ByteArrayInputStream EMPTY = new ByteArrayInputStream("".getBytes());
|
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
|
||||||
return new WebResourceResponse("text/plain", "utf-8", EMPTY);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return super.shouldInterceptRequest(view, request);
|
return super.shouldInterceptRequest(view, request);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
@SuppressWarnings("deprecation")
|
||||||
|
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
|
||||||
@Override
|
@Override
|
||||||
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
|
||||||
if (mAdBlock.isAd(url)) {
|
if (mAdBlock.isAd(url)) {
|
||||||
@ -85,7 +85,7 @@ class LightningWebClient extends WebViewClient {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||||
@Override
|
@Override
|
||||||
public void onPageFinished(WebView view, String url) {
|
public void onPageFinished(WebView view, String url) {
|
||||||
if (view.isShown()) {
|
if (view.isShown()) {
|
||||||
@ -163,7 +163,7 @@ class LightningWebClient extends WebViewClient {
|
|||||||
private boolean mIsRunning = false;
|
private boolean mIsRunning = false;
|
||||||
private float mZoomScale = 0.0f;
|
private float mZoomScale = 0.0f;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||||
@Override
|
@Override
|
||||||
public void onScaleChanged(final WebView view, final float oldScale, final float newScale) {
|
public void onScaleChanged(final WebView view, final float oldScale, final float newScale) {
|
||||||
if (view.isShown() && mLightningView.mPreferences.getTextReflowEnabled() &&
|
if (view.isShown() && mLightningView.mPreferences.getTextReflowEnabled() &&
|
||||||
|
Loading…
x
Reference in New Issue
Block a user