Performance improvments, fixed bug with find in page in full-screen mode
This commit is contained in:
parent
c8d06f8ce6
commit
a8956e9cd3
@ -4,7 +4,6 @@
|
|||||||
|
|
||||||
package acr.browser.lightning.activity;
|
package acr.browser.lightning.activity;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.ClipData;
|
import android.content.ClipData;
|
||||||
import android.content.ClipboardManager;
|
import android.content.ClipboardManager;
|
||||||
@ -17,7 +16,6 @@ import android.database.sqlite.SQLiteException;
|
|||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.PorterDuff;
|
import android.graphics.PorterDuff;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.ColorDrawable;
|
import android.graphics.drawable.ColorDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.media.MediaPlayer;
|
import android.media.MediaPlayer;
|
||||||
@ -26,7 +24,6 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.os.StrictMode;
|
|
||||||
import android.provider.MediaStore;
|
import android.provider.MediaStore;
|
||||||
import android.support.annotation.ColorInt;
|
import android.support.annotation.ColorInt;
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
@ -56,9 +53,9 @@ import android.view.View.OnLongClickListener;
|
|||||||
import android.view.View.OnTouchListener;
|
import android.view.View.OnTouchListener;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.view.ViewGroup.LayoutParams;
|
import android.view.ViewGroup.LayoutParams;
|
||||||
|
import android.view.ViewParent;
|
||||||
import android.view.ViewTreeObserver;
|
import android.view.ViewTreeObserver;
|
||||||
import android.view.Window;
|
import android.view.Window;
|
||||||
import android.view.WindowInsets;
|
|
||||||
import android.view.WindowManager;
|
import android.view.WindowManager;
|
||||||
import android.view.animation.Animation;
|
import android.view.animation.Animation;
|
||||||
import android.view.animation.DecelerateInterpolator;
|
import android.view.animation.DecelerateInterpolator;
|
||||||
@ -83,6 +80,8 @@ import android.widget.TextView;
|
|||||||
import android.widget.TextView.OnEditorActionListener;
|
import android.widget.TextView.OnEditorActionListener;
|
||||||
import android.widget.VideoView;
|
import android.widget.VideoView;
|
||||||
|
|
||||||
|
import com.anthonycr.bonsai.Observable;
|
||||||
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.anthonycr.grant.PermissionsManager;
|
import com.anthonycr.grant.PermissionsManager;
|
||||||
import com.anthonycr.progress.AnimatedProgressBar;
|
import com.anthonycr.progress.AnimatedProgressBar;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
@ -93,7 +92,6 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import acr.browser.lightning.BuildConfig;
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.browser.BrowserPresenter;
|
import acr.browser.lightning.browser.BrowserPresenter;
|
||||||
@ -113,15 +111,9 @@ import acr.browser.lightning.database.HistoryItem;
|
|||||||
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
import acr.browser.lightning.dialog.LightningDialogBuilder;
|
||||||
import acr.browser.lightning.fragment.BookmarksFragment;
|
import acr.browser.lightning.fragment.BookmarksFragment;
|
||||||
import acr.browser.lightning.fragment.TabsFragment;
|
import acr.browser.lightning.fragment.TabsFragment;
|
||||||
import acr.browser.lightning.search.Suggestions;
|
|
||||||
import acr.browser.lightning.search.SuggestionsAdapter;
|
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Observable;
|
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
|
||||||
|
|
||||||
import acr.browser.lightning.receiver.NetworkReceiver;
|
import acr.browser.lightning.receiver.NetworkReceiver;
|
||||||
|
import acr.browser.lightning.search.Suggestions;
|
||||||
import acr.browser.lightning.utils.DrawableUtils;
|
import acr.browser.lightning.utils.DrawableUtils;
|
||||||
import acr.browser.lightning.utils.KeyboardHelper;
|
|
||||||
import acr.browser.lightning.utils.ProxyUtils;
|
import acr.browser.lightning.utils.ProxyUtils;
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
import acr.browser.lightning.utils.UrlUtils;
|
import acr.browser.lightning.utils.UrlUtils;
|
||||||
@ -233,18 +225,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
|
||||||
if (BuildConfig.DEBUG) {
|
|
||||||
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
|
||||||
.detectAll()
|
|
||||||
.penaltyLog()
|
|
||||||
.build());
|
|
||||||
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
|
||||||
.detectAll()
|
|
||||||
.penaltyLog()
|
|
||||||
.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
BrowserApp.getAppComponent().inject(this);
|
BrowserApp.getAppComponent().inject(this);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
@ -254,18 +234,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mPresenter = new BrowserPresenter(this, isIncognito());
|
mPresenter = new BrowserPresenter(this, isIncognito());
|
||||||
|
|
||||||
initialize(savedInstanceState);
|
initialize(savedInstanceState);
|
||||||
|
|
||||||
KeyboardHelper keyboardHelper = new KeyboardHelper(mRoot);
|
|
||||||
keyboardHelper.registerKeyboardListener(new KeyboardHelper.KeyboardListener() {
|
|
||||||
@Override
|
|
||||||
public void keyboardVisibilityChanged(boolean visible) {
|
|
||||||
if (visible) {
|
|
||||||
setTabHeightForKeyboard();
|
|
||||||
} else {
|
|
||||||
setTabHeight();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private synchronized void initialize(Bundle savedInstanceState) {
|
private synchronized void initialize(Bundle savedInstanceState) {
|
||||||
@ -630,21 +598,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
|
setFullscreen(mPreferences.getHideStatusBarEnabled(), false);
|
||||||
|
|
||||||
initializeTabHeight();
|
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.KITKAT_WATCH) {
|
|
||||||
// Sets the tab height correctly if the status bar is hidden
|
|
||||||
// Also ensures that tab is correct height on rotation
|
|
||||||
mRoot.setOnApplyWindowInsetsListener(new View.OnApplyWindowInsetsListener() {
|
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT_WATCH)
|
|
||||||
@Override
|
|
||||||
public WindowInsets onApplyWindowInsets(View v, WindowInsets insets) {
|
|
||||||
initializeTabHeight();
|
|
||||||
return mRoot.onApplyWindowInsets(insets);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (mPreferences.getSearchChoice()) {
|
switch (mPreferences.getSearchChoice()) {
|
||||||
case 0:
|
case 0:
|
||||||
mSearchText = mPreferences.getSearchUrl();
|
mSearchText = mPreferences.getSearchUrl();
|
||||||
@ -693,7 +646,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
public void onWindowVisibleToUserAfterResume() {
|
public void onWindowVisibleToUserAfterResume() {
|
||||||
super.onWindowVisibleToUserAfterResume();
|
super.onWindowVisibleToUserAfterResume();
|
||||||
mToolbarLayout.setTranslationY(0);
|
mToolbarLayout.setTranslationY(0);
|
||||||
mBrowserFrame.setTranslationY(0);
|
setWebViewTranslation(mToolbarLayout.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -825,6 +778,38 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void putToolbarInRoot() {
|
||||||
|
if (mToolbarLayout.getParent() != mUiLayout) {
|
||||||
|
if (mToolbarLayout.getParent() != null) {
|
||||||
|
((ViewGroup) mToolbarLayout.getParent()).removeView(mToolbarLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
mUiLayout.addView(mToolbarLayout, 0);
|
||||||
|
mUiLayout.requestLayout();
|
||||||
|
}
|
||||||
|
setWebViewTranslation(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void overlayToolbarOnWebView() {
|
||||||
|
if (mToolbarLayout.getParent() != mBrowserFrame) {
|
||||||
|
if (mToolbarLayout.getParent() != null) {
|
||||||
|
((ViewGroup) mToolbarLayout.getParent()).removeView(mToolbarLayout);
|
||||||
|
}
|
||||||
|
|
||||||
|
mBrowserFrame.addView(mToolbarLayout);
|
||||||
|
mBrowserFrame.requestLayout();
|
||||||
|
}
|
||||||
|
setWebViewTranslation(mToolbarLayout.getHeight());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setWebViewTranslation(float translation) {
|
||||||
|
if (mFullScreen && mCurrentView != null) {
|
||||||
|
mCurrentView.setTranslationY(translation);
|
||||||
|
} else if (mCurrentView != null) {
|
||||||
|
mCurrentView.setTranslationY(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* method that shows a dialog asking what string the user wishes to search
|
* method that shows a dialog asking what string the user wishes to search
|
||||||
* for. It highlights the text entered.
|
* for. It highlights the text entered.
|
||||||
@ -937,8 +922,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// Set the background color so the color mode color doesn't show through
|
// Set the background color so the color mode color doesn't show through
|
||||||
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||||||
|
|
||||||
mBrowserFrame.removeAllViews();
|
|
||||||
|
|
||||||
removeViewFromParent(mCurrentView);
|
removeViewFromParent(mCurrentView);
|
||||||
|
|
||||||
mCurrentView = null;
|
mCurrentView = null;
|
||||||
@ -966,12 +949,15 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
// Set the background color so the color mode color doesn't show through
|
// Set the background color so the color mode color doesn't show through
|
||||||
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||||||
|
|
||||||
mBrowserFrame.removeAllViews();
|
|
||||||
|
|
||||||
removeViewFromParent(view);
|
removeViewFromParent(view);
|
||||||
removeViewFromParent(mCurrentView);
|
removeViewFromParent(mCurrentView);
|
||||||
|
|
||||||
mBrowserFrame.addView(view, MATCH_PARENT);
|
mBrowserFrame.addView(view, 0, MATCH_PARENT);
|
||||||
|
if (mFullScreen) {
|
||||||
|
view.setTranslationY(mToolbarLayout.getHeight() + mToolbarLayout.getTranslationY());
|
||||||
|
} else {
|
||||||
|
view.setTranslationY(0);
|
||||||
|
}
|
||||||
|
|
||||||
view.requestFocus();
|
view.requestFocus();
|
||||||
|
|
||||||
@ -1030,9 +1016,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
if (view == null) {
|
if (view == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
ViewGroup parent = ((ViewGroup) view.getParent());
|
ViewParent parent = view.getParent();
|
||||||
if (parent != null) {
|
if (parent instanceof ViewGroup) {
|
||||||
parent.removeView(view);
|
((ViewGroup) parent).removeView(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1095,6 +1081,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
} else if (isIncognito()) {
|
} else if (isIncognito()) {
|
||||||
WebUtils.clearWebStorage(); // We want to make sure incognito mode is secure
|
WebUtils.clearWebStorage(); // We want to make sure incognito mode is secure
|
||||||
}
|
}
|
||||||
|
mSuggestionsAdapter.clearCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -1114,11 +1101,10 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
if (mFullScreen) {
|
if (mFullScreen) {
|
||||||
showActionBar();
|
showActionBar();
|
||||||
mBrowserFrame.setTranslationY(0);
|
|
||||||
mToolbarLayout.setTranslationY(0);
|
mToolbarLayout.setTranslationY(0);
|
||||||
|
setWebViewTranslation(mToolbarLayout.getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeTabHeight();
|
|
||||||
supportInvalidateOptionsMenu();
|
supportInvalidateOptionsMenu();
|
||||||
initializeToolbarHeight(newConfig);
|
initializeToolbarHeight(newConfig);
|
||||||
}
|
}
|
||||||
@ -1138,15 +1124,22 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
mToolbar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, toolbarSize));
|
mToolbar.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, toolbarSize));
|
||||||
mToolbar.setMinimumHeight(toolbarSize);
|
mToolbar.setMinimumHeight(toolbarSize);
|
||||||
|
doOnLayout(mToolbar, new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
setWebViewTranslation(mToolbarLayout.getHeight());
|
||||||
|
}
|
||||||
|
});
|
||||||
mToolbar.requestLayout();
|
mToolbar.requestLayout();
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closeBrowser() {
|
public void closeBrowser() {
|
||||||
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
mBrowserFrame.setBackgroundColor(mBackgroundColor);
|
||||||
|
removeViewFromParent(mCurrentView);
|
||||||
performExitCleanUp();
|
performExitCleanUp();
|
||||||
mBrowserFrame.removeAllViews();
|
|
||||||
int size = mTabsManager.size();
|
int size = mTabsManager.size();
|
||||||
mTabsManager.shutdown();
|
mTabsManager.shutdown();
|
||||||
mCurrentView = null;
|
mCurrentView = null;
|
||||||
@ -1263,6 +1256,12 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
BrowserApp.get(this).registerReceiver(mNetworkReceiver, filter);
|
BrowserApp.get(this).registerReceiver(mNetworkReceiver, filter);
|
||||||
|
|
||||||
mEventBus.register(mBusEventListener);
|
mEventBus.register(mBusEventListener);
|
||||||
|
|
||||||
|
if (mFullScreen) {
|
||||||
|
overlayToolbarOnWebView();
|
||||||
|
} else {
|
||||||
|
putToolbarInRoot();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1773,7 +1772,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
mCustomViewCallback = null;
|
mCustomViewCallback = null;
|
||||||
setRequestedOrientation(mOriginalOrientation);
|
setRequestedOrientation(mOriginalOrientation);
|
||||||
setTabHeight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private class VideoCompletionListener implements MediaPlayer.OnCompletionListener,
|
private class VideoCompletionListener implements MediaPlayer.OnCompletionListener,
|
||||||
@ -1890,9 +1888,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
Animation show = new Animation() {
|
Animation show = new Animation() {
|
||||||
@Override
|
@Override
|
||||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||||
float trans = (1.0f - interpolatedTime) * height;
|
float trans = interpolatedTime * height;
|
||||||
mToolbarLayout.setTranslationY(trans - height);
|
mToolbarLayout.setTranslationY(-trans);
|
||||||
mBrowserFrame.setTranslationY(trans - height);
|
setWebViewTranslation(height - trans);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
show.setDuration(250);
|
show.setDuration(250);
|
||||||
@ -1931,7 +1929,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||||
float trans = interpolatedTime * totalHeight;
|
float trans = interpolatedTime * totalHeight;
|
||||||
mToolbarLayout.setTranslationY(trans - totalHeight);
|
mToolbarLayout.setTranslationY(trans - totalHeight);
|
||||||
mBrowserFrame.setTranslationY(trans - totalHeight);
|
setWebViewTranslation(trans);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
show.setDuration(250);
|
show.setDuration(250);
|
||||||
@ -1941,23 +1939,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method initializes the height of the
|
|
||||||
* view that holds the current WebView. It waits
|
|
||||||
* for the root layout to be laid out before setting
|
|
||||||
* the height as it needs the root layout to be measured
|
|
||||||
* first.
|
|
||||||
*/
|
|
||||||
private void initializeTabHeight() {
|
|
||||||
Log.d(TAG, "initializeTabHeight");
|
|
||||||
doOnLayout(mUiLayout, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
setTabHeight();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Performs an action when the provided view is laid out.
|
* Performs an action when the provided view is laid out.
|
||||||
*
|
*
|
||||||
@ -1980,46 +1961,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This method sets the height of the browser
|
|
||||||
* frame view that holds the current WebView.
|
|
||||||
* It requires the root layout to be properly
|
|
||||||
* laid out in order to set the correct height.
|
|
||||||
*/
|
|
||||||
private void setTabHeight() {
|
|
||||||
Log.d(TAG, "setTabHeight");
|
|
||||||
if (mRoot.getHeight() == 0) {
|
|
||||||
mRoot.measure(View.MeasureSpec.EXACTLY, View.MeasureSpec.EXACTLY);
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.d(TAG, "UI Layout top: " + mUiLayout.getTop());
|
|
||||||
|
|
||||||
if (mFullScreen) {
|
|
||||||
int height = mRoot.getHeight() - mUiLayout.getTop();
|
|
||||||
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
|
|
||||||
} else {
|
|
||||||
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
|
|
||||||
params.weight = 1;
|
|
||||||
mBrowserFrame.setLayoutParams(params);
|
|
||||||
}
|
|
||||||
|
|
||||||
mBrowserFrame.requestLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void setTabHeightForKeyboard() {
|
|
||||||
doOnLayout(mUiLayout, new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Rect rect = new Rect();
|
|
||||||
mRoot.getWindowVisibleDisplayFrame(rect);
|
|
||||||
|
|
||||||
int height = rect.bottom - mUiLayout.getTop();
|
|
||||||
mBrowserFrame.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT, height));
|
|
||||||
mBrowserFrame.requestLayout();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method lets the search bar know that the page is currently loading
|
* This method lets the search bar know that the page is currently loading
|
||||||
* and that it should display the stop icon to indicate to the user that
|
* and that it should display the stop icon to indicate to the user that
|
||||||
|
@ -4,6 +4,7 @@ import android.app.Activity;
|
|||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.StrictMode;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.webkit.WebView;
|
import android.webkit.WebView;
|
||||||
@ -34,6 +35,17 @@ public class BrowserApp extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onCreate() {
|
public void onCreate() {
|
||||||
super.onCreate();
|
super.onCreate();
|
||||||
|
if (BuildConfig.DEBUG) {
|
||||||
|
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.penaltyLog()
|
||||||
|
.build());
|
||||||
|
StrictMode.setVmPolicy(new StrictMode.VmPolicy.Builder()
|
||||||
|
.detectAll()
|
||||||
|
.penaltyLog()
|
||||||
|
.build());
|
||||||
|
}
|
||||||
|
|
||||||
mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
mAppComponent = DaggerAppComponent.builder().appModule(new AppModule(this)).build();
|
||||||
mAppComponent.inject(this);
|
mAppComponent.inject(this);
|
||||||
|
|
||||||
@ -48,7 +60,7 @@ public class BrowserApp extends Application {
|
|||||||
@Override
|
@Override
|
||||||
public void onActivityDestroyed(Activity activity) {
|
public void onActivityDestroyed(Activity activity) {
|
||||||
Log.d(TAG, "Cleaning up after the Android framework");
|
Log.d(TAG, "Cleaning up after the Android framework");
|
||||||
MemoryLeakUtils.clearNextServedView(BrowserApp.this);
|
MemoryLeakUtils.clearNextServedView(activity, BrowserApp.this);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -34,12 +34,14 @@ import acr.browser.lightning.database.BookmarkManager;
|
|||||||
import acr.browser.lightning.database.HistoryDatabase;
|
import acr.browser.lightning.database.HistoryDatabase;
|
||||||
import acr.browser.lightning.database.HistoryItem;
|
import acr.browser.lightning.database.HistoryItem;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
|
|
||||||
import com.anthonycr.bonsai.Action;
|
import com.anthonycr.bonsai.Action;
|
||||||
import com.anthonycr.bonsai.Observable;
|
import com.anthonycr.bonsai.Observable;
|
||||||
import com.anthonycr.bonsai.OnSubscribe;
|
import com.anthonycr.bonsai.OnSubscribe;
|
||||||
import com.anthonycr.bonsai.Scheduler;
|
import com.anthonycr.bonsai.Scheduler;
|
||||||
import com.anthonycr.bonsai.Schedulers;
|
import com.anthonycr.bonsai.Schedulers;
|
||||||
import com.anthonycr.bonsai.Subscriber;
|
import com.anthonycr.bonsai.Subscriber;
|
||||||
|
|
||||||
import acr.browser.lightning.utils.ThemeUtils;
|
import acr.browser.lightning.utils.ThemeUtils;
|
||||||
|
|
||||||
public class Suggestions extends BaseAdapter implements Filterable {
|
public class Suggestions extends BaseAdapter implements Filterable {
|
||||||
@ -87,16 +89,14 @@ public class Suggestions extends BaseAdapter implements Filterable {
|
|||||||
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
mSearchDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_search, mDarkTheme);
|
||||||
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
mBookmarkDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_bookmark, mDarkTheme);
|
||||||
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
mHistoryDrawable = ThemeUtils.getThemedDrawable(context, R.drawable.ic_history, mDarkTheme);
|
||||||
|
|
||||||
clearCache();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshPreferences() {
|
public void refreshPreferences() {
|
||||||
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
mUseGoogle = mPreferenceManager.getGoogleSearchSuggestionsEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void clearCache() {
|
public void clearCache() {
|
||||||
BrowserApp.getTaskThread().execute(new ClearCacheRunnable(BrowserApp.get(mContext)));
|
Schedulers.io().execute(new ClearCacheRunnable(BrowserApp.get(mContext)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void refreshBookmarks() {
|
public void refreshBookmarks() {
|
||||||
|
@ -7,8 +7,11 @@ import android.os.Build;
|
|||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
public class MemoryLeakUtils {
|
public class MemoryLeakUtils {
|
||||||
@ -25,7 +28,7 @@ public class MemoryLeakUtils {
|
|||||||
* the InputMethodManager that is
|
* the InputMethodManager that is
|
||||||
* leaking the views.
|
* leaking the views.
|
||||||
*/
|
*/
|
||||||
public static void clearNextServedView(@NonNull Application application) {
|
public static void clearNextServedView(Activity activity, @NonNull Application application) {
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
|
||||||
// This shouldn't be a problem on N
|
// This shouldn't be a problem on N
|
||||||
@ -42,7 +45,22 @@ public class MemoryLeakUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sFinishInputLocked != null) {
|
boolean isCurrentActivity = false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
Field servedViewField = InputMethodManager.class.getDeclaredField("mNextServedView");
|
||||||
|
servedViewField.setAccessible(true);
|
||||||
|
Object servedView = servedViewField.get(imm);
|
||||||
|
if (servedView instanceof View) {
|
||||||
|
isCurrentActivity = ((View) servedView).getContext() == activity;
|
||||||
|
}
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
Log.d(TAG, "Unable to get mNextServedView field", e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
Log.d(TAG, "Unable to access mNextServedView field", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (sFinishInputLocked != null && isCurrentActivity) {
|
||||||
sFinishInputLocked.setAccessible(true);
|
sFinishInputLocked.setAccessible(true);
|
||||||
try {
|
try {
|
||||||
sFinishInputLocked.invoke(imm);
|
sFinishInputLocked.invoke(imm);
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/drawerBackground"
|
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:background="?attr/drawerBackground"
|
|
||||||
android:clickable="true"
|
android:clickable="true"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user