@ -2,7 +2,9 @@ package acr.browser.barebones.customwebview;
@@ -2,7 +2,9 @@ package acr.browser.barebones.customwebview;
import acr.browser.barebones.activities.IncognitoModeActivity ;
import acr.browser.barebones.utilities.FinalVariables ;
import android.annotation.SuppressLint ;
import android.content.Context ;
import android.content.SharedPreferences ;
import android.graphics.Point ;
import android.util.DisplayMetrics ;
import android.view.Display ;
@ -14,50 +16,63 @@ import android.view.WindowManager;
@@ -14,50 +16,63 @@ import android.view.WindowManager;
import android.view.animation.Animation ;
import android.webkit.WebSettings ;
import android.webkit.WebView ;
import android.webkit.WebSettings.LayoutAlgorithm ;
import android.webkit.WebSettings.PluginState ;
import android.webkit.WebSettings.RenderPriority ;
public final class IncognitoWebView extends WebView {
private float location ;
private boolean first = false ;
final int API = FinalVariables . API ;
final boolean showFullScreen = IncognitoModeActivity . showFullScreen ;
final View uBar = IncognitoModeActivity . url Bar ;
static final int API = FinalVariables . API ;
public static boolean showFullScreen ; ;
final View uBar = IncognitoModeActivity . uBar ;
final Animation slideUp = IncognitoModeActivity . slideUp ;
final Animation slideDown = IncognitoModeActivity . slideDown ;
static Context CONTEXT ;
static String defaultUser ;
public WebSettings settings ;
public IncognitoWebView ( Context context ) {
super ( context ) ;
defaultUser = IncognitoModeActivity . defaultUser ;
showFullScreen = IncognitoModeActivity . showFullScreen ;
mGestureDetector = new GestureDetector ( context ,
new CustomGestureListener ( ) ) ;
CONTEXT = context ;
WebSettings settings = this . getSettings ( ) ;
settings = getSettings ( ) ;
browserInitialization ( context ) ;
settingsInitialization ( context , settings ) ;
settingsInitialization ( context ) ;
}
@SuppressWarnings ( "deprecation" )
public void browserInitialization ( Context context ) {
this . setDrawingCacheBackgroundColor ( 0x00000000 ) ;
this . setFocusableInTouchMode ( true ) ;
this . setFocusable ( true ) ;
this . setAnimationCacheEnabled ( false ) ;
this . setDrawingCacheEnabled ( true ) ;
this . setBackgroundColor ( context . getResources ( ) . getColor (
setDrawingCacheBackgroundColor ( 0x00000000 ) ;
setFocusableInTouchMode ( true ) ;
setFocusable ( true ) ;
setAnimationCacheEnabled ( false ) ;
setDrawingCacheEnabled ( true ) ;
setBackgroundColor ( context . getResources ( ) . getColor (
android . R . color . white ) ) ;
this . setWillNotCacheDrawing ( false ) ;
this . setAlwaysDrawnWithCacheEnabled ( true ) ;
this . setScrollbarFadingEnabled ( true ) ;
this . setSaveEnabled ( true ) ;
if ( API > = 16 ) {
getRootView ( ) . setBackground ( null ) ;
} else {
getRootView ( ) . setBackgroundDrawable ( null ) ;
}
setWillNotCacheDrawing ( false ) ;
setAlwaysDrawnWithCacheEnabled ( true ) ;
setScrollbarFadingEnabled ( true ) ;
setSaveEnabled ( true ) ;
}
@SuppressLint ( "SetJavaScriptEnabled" )
@SuppressWarnings ( "deprecation" )
public void settingsInitialization ( Context context , WebSettings settings ) {
public void settingsInitialization ( Context context ) {
SharedPreferences preferences = context . getSharedPreferences (
"settings" , 0 ) ;
settings . setDomStorageEnabled ( true ) ;
settings . setAppCacheEnabled ( true ) ;
settings . setAppCachePath ( context . getFilesDir ( ) . getAbsolutePath ( )
+ "/cache" ) ;
if ( API < 18 ) {
settings . setLightTouchEnabled ( true ) ;
}
settings . setAllowFileAccess ( true ) ;
settings . setDatabaseEnabled ( true ) ;
settings . setDatabasePath ( context . getFilesDir ( ) . getAbsolutePath ( )
@ -68,54 +83,168 @@ public final class IncognitoWebView extends WebView {
@@ -68,54 +83,168 @@ public final class IncognitoWebView extends WebView {
settings . setDisplayZoomControls ( false ) ;
settings . setAllowContentAccess ( true ) ;
}
}
@Override
public boolean onTouchEvent ( MotionEvent event ) {
if ( preferences . getBoolean ( "java" , true ) ) {
settings . setJavaScriptEnabled ( true ) ;
settings . setJavaScriptCanOpenWindowsAutomatically ( true ) ;
}
switch ( event . getAction ( ) ) {
case MotionEvent . ACTION_DOWN : {
first = true ;
if ( API < = 10 & & ! hasFocus ( ) ) {
requestFocus ( ) ;
if ( API < 14 ) {
switch ( preferences . getInt ( "textsize" , 3 ) ) {
case 1 :
settings . setTextSize ( WebSettings . TextSize . LARGEST ) ;
break ;
case 2 :
settings . setTextSize ( WebSettings . TextSize . LARGER ) ;
break ;
case 3 :
settings . setTextSize ( WebSettings . TextSize . NORMAL ) ;
break ;
case 4 :
settings . setTextSize ( WebSettings . TextSize . SMALLER ) ;
break ;
case 5 :
settings . setTextSize ( WebSettings . TextSize . SMALLEST ) ;
break ;
}
} else {
switch ( preferences . getInt ( "textsize" , 3 ) ) {
case 1 :
settings . setTextZoom ( 200 ) ;
break ;
case 2 :
settings . setTextZoom ( 150 ) ;
break ;
case 3 :
settings . setTextZoom ( 100 ) ;
break ;
case 4 :
settings . setTextZoom ( 75 ) ;
break ;
case 5 :
settings . setTextZoom ( 50 ) ;
break ;
}
location = event . getY ( ) ;
}
settings . setSupportMultipleWindows ( preferences . getBoolean ( "newwindow" ,
true ) ) ;
switch ( preferences . getInt ( "enableflash" , 0 ) ) {
case 0 :
break ;
case 1 : {
settings . setPluginState ( PluginState . ON_DEMAND ) ;
break ;
}
case MotionEvent . ACTION_UP : {
case 2 : {
settings . setPluginState ( PluginState . ON ) ;
break ;
}
default :
break ;
}
if ( preferences . getBoolean ( "passwords" , false ) ) {
if ( API < 18 ) {
settings . setSavePassword ( true ) ;
}
settings . setSaveFormData ( true ) ;
}
if ( API < 18 ) {
try {
settings . setRenderPriority ( RenderPriority . HIGH ) ;
} catch ( SecurityException ignored ) {
if ( showFullScreen & & first ) {
if ( uBar . isShown ( ) & & getScrollY ( ) < 5 ) {
uBar . startAnimation ( slideUp ) ;
} else if ( ( event . getY ( ) - location ) > 20 . 0 & & ! uBar . isShown ( ) ) {
uBar . startAnimation ( slideDown ) ;
} else if ( ( event . getY ( ) - location ) < - 20 . 0 & & uBar . isShown ( ) ) {
uBar . startAnimation ( slideUp ) ;
}
first = false ;
}
break ;
}
settings . setGeolocationEnabled ( preferences
. getBoolean ( "location" , false ) ) ;
settings . setGeolocationDatabasePath ( context . getFilesDir ( )
. getAbsolutePath ( ) ) ;
settings . setUseWideViewPort ( preferences
. getBoolean ( "wideviewport" , true ) ) ;
settings . setLoadWithOverviewMode ( preferences . getBoolean ( "overviewmode" ,
true ) ) ;
if ( preferences . getBoolean ( "textreflow" , false ) ) {
settings . setLayoutAlgorithm ( LayoutAlgorithm . NARROW_COLUMNS ) ;
} else {
settings . setLayoutAlgorithm ( LayoutAlgorithm . NORMAL ) ;
}
return mGestureDetector . onTouchEvent ( event )
| | super . onTouchEvent ( event ) ;
settings . setBlockNetworkImage ( preferences . getBoolean ( "blockimages" ,
false ) ) ;
settings . setLoadsImagesAutomatically ( true ) ;
switch ( preferences . getInt ( "agentchoose" , 1 ) ) {
case 1 :
getSettings ( ) . setUserAgentString ( defaultUser ) ;
break ;
case 2 :
getSettings ( ) . setUserAgentString (
FinalVariables . DESKTOP_USER_AGENT ) ;
break ;
case 3 :
getSettings ( ) . setUserAgentString (
FinalVariables . MOBILE_USER_AGENT ) ;
break ;
case 4 :
getSettings ( ) . setUserAgentString (
preferences . getString ( "userAgentString" , defaultUser ) ) ;
break ;
}
}
@Override
public boolean onTouchEvent ( MotionEvent event ) {
mGestureDetector . onTouchEvent ( event ) ;
return super . onTouchEvent ( event ) ;
}
@Override
protected void onWindowVisibilityChanged ( int visibility ) {
if ( API > = 11 ) {
this . setActivated ( visibility = = View . VISIBLE ) ;
setActivated ( visibility = = View . VISIBLE ) ;
}
this . setEnabled ( visibility = = View . VISIBLE ) ;
setEnabled ( visibility = = View . VISIBLE ) ;
super . onWindowVisibilityChanged ( visibility ) ;
}
private final GestureDetector mGestureDetector ;
private class CustomGestureListener extends SimpleOnGestureListener {
private final int SWIPE_THRESHOLD = 100 ;
private final int SWIPE_VELOCITY_THRESHOLD = 100 ;
final int SWIPE_THRESHOLD = 100 ;
final int SWIPE_VELOCITY_THRESHOLD = 100 ;
@Override
public boolean onDown ( MotionEvent e ) {
first = true ;
return super . onDown ( e ) ;
}
@Override
public void onLongPress ( MotionEvent e ) {
if ( IncognitoModeActivity . currentId ! = - 1 ) {
IncognitoModeActivity . onLongClick ( ) ;
}
super . onLongPress ( e ) ;
}
@Override
public boolean onScroll ( MotionEvent e1 , MotionEvent e2 ,
float distanceX , float distanceY ) {
if ( showFullScreen & & first ) {
if ( uBar . isShown ( ) & & getScrollY ( ) < 5 ) {
uBar . startAnimation ( slideUp ) ;
} else if ( distanceY < - 5 & & ! uBar . isShown ( ) ) {
uBar . startAnimation ( slideDown ) ;
} else if ( distanceY > 5 & & uBar . isShown ( ) ) {
uBar . startAnimation ( slideUp ) ;
}
first = false ;
}
return super . onScroll ( e1 , e2 , distanceX , distanceY ) ;
}
@Override
public boolean onFling ( MotionEvent e1 , MotionEvent e2 , float velocityX ,
@ -136,18 +265,17 @@ public final class IncognitoWebView extends WebView {
@@ -136,18 +265,17 @@ public final class IncognitoWebView extends WebView {
width = size . x ;
}
if ( ( width - e1 . getX ( ) < width / 12 ) | | ( e1 . getX ( ) < width / 12 ) ) {
if ( ( width - e1 . getX ( ) < width / 12 )
| | ( e1 . getX ( ) < width / 12 ) ) {
float diffY = e2 . getY ( ) - e1 . getY ( ) ;
float diffX = e2 . getX ( ) - e1 . getX ( ) ;
if ( Math . abs ( diffX ) > Math . abs ( diffY ) ) {
if ( Math . abs ( diffX ) > SWIPE_THRESHOLD
& & Math . abs ( velocityX ) > SWIPE_VELOCITY_THRESHOLD ) {
if ( diffX > 0 ) {
IncognitoModeActivity . goBack ( ) ;
return false ;
IncognitoModeActivity . goBack ( IncognitoWebView . this ) ;
} else {
IncognitoModeActivity . goForward ( ) ;
return false ;
IncognitoModeActivity . goForward ( IncognitoWebView . this ) ;
}
}
}
@ -156,7 +284,7 @@ public final class IncognitoWebView extends WebView {
@@ -156,7 +284,7 @@ public final class IncognitoWebView extends WebView {
} catch ( Exception exception ) {
exception . printStackTrace ( ) ;
}
return false ;
return super . onFling ( e1 , e2 , velocityX , velocityY ) ;
}
}