@ -2,7 +2,9 @@ package acr.browser.barebones.customwebview;
import acr.browser.barebones.activities.IncognitoModeActivity ;
import acr.browser.barebones.activities.IncognitoModeActivity ;
import acr.browser.barebones.utilities.FinalVariables ;
import acr.browser.barebones.utilities.FinalVariables ;
import android.annotation.SuppressLint ;
import android.content.Context ;
import android.content.Context ;
import android.content.SharedPreferences ;
import android.graphics.Point ;
import android.graphics.Point ;
import android.util.DisplayMetrics ;
import android.util.DisplayMetrics ;
import android.view.Display ;
import android.view.Display ;
@ -14,50 +16,63 @@ import android.view.WindowManager;
import android.view.animation.Animation ;
import android.view.animation.Animation ;
import android.webkit.WebSettings ;
import android.webkit.WebSettings ;
import android.webkit.WebView ;
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 {
public final class IncognitoWebView extends WebView {
private float location ;
private boolean first = false ;
private boolean first = false ;
final int API = FinalVariables . API ;
static final int API = FinalVariables . API ;
final boolean showFullScreen = IncognitoModeActivity . showFullScreen ;
public static boolean showFullScreen ; ;
final View uBar = IncognitoModeActivity . url Bar ;
final View uBar = IncognitoModeActivity . uBar ;
final Animation slideUp = IncognitoModeActivity . slideUp ;
final Animation slideUp = IncognitoModeActivity . slideUp ;
final Animation slideDown = IncognitoModeActivity . slideDown ;
final Animation slideDown = IncognitoModeActivity . slideDown ;
static Context CONTEXT ;
static Context CONTEXT ;
static String defaultUser ;
public WebSettings settings ;
public IncognitoWebView ( Context context ) {
public IncognitoWebView ( Context context ) {
super ( context ) ;
super ( context ) ;
defaultUser = IncognitoModeActivity . defaultUser ;
showFullScreen = IncognitoModeActivity . showFullScreen ;
mGestureDetector = new GestureDetector ( context ,
mGestureDetector = new GestureDetector ( context ,
new CustomGestureListener ( ) ) ;
new CustomGestureListener ( ) ) ;
CONTEXT = context ;
CONTEXT = context ;
WebSettings settings = this . getSettings ( ) ;
settings = getSettings ( ) ;
browserInitialization ( context ) ;
browserInitialization ( context ) ;
settingsInitialization ( context , settings ) ;
settingsInitialization ( context ) ;
}
}
@SuppressWarnings ( "deprecation" )
public void browserInitialization ( Context context ) {
public void browserInitialization ( Context context ) {
this . setDrawingCacheBackgroundColor ( 0x00000000 ) ;
setDrawingCacheBackgroundColor ( 0x00000000 ) ;
this . setFocusableInTouchMode ( true ) ;
setFocusableInTouchMode ( true ) ;
this . setFocusable ( true ) ;
setFocusable ( true ) ;
this . setAnimationCacheEnabled ( false ) ;
setAnimationCacheEnabled ( false ) ;
this . setDrawingCacheEnabled ( true ) ;
setDrawingCacheEnabled ( true ) ;
this . setBackgroundColor ( context . getResources ( ) . getColor (
setBackgroundColor ( context . getResources ( ) . getColor (
android . R . color . white ) ) ;
android . R . color . white ) ) ;
this . setWillNotCacheDrawing ( false ) ;
if ( API > = 16 ) {
this . setAlwaysDrawnWithCacheEnabled ( true ) ;
getRootView ( ) . setBackground ( null ) ;
this . setScrollbarFadingEnabled ( true ) ;
} else {
this . setSaveEnabled ( true ) ;
getRootView ( ) . setBackgroundDrawable ( null ) ;
}
setWillNotCacheDrawing ( false ) ;
setAlwaysDrawnWithCacheEnabled ( true ) ;
setScrollbarFadingEnabled ( true ) ;
setSaveEnabled ( true ) ;
}
}
@SuppressLint ( "SetJavaScriptEnabled" )
@SuppressWarnings ( "deprecation" )
@SuppressWarnings ( "deprecation" )
public void settingsInitialization ( Context context , WebSettings settings ) {
public void settingsInitialization ( Context context ) {
SharedPreferences preferences = context . getSharedPreferences (
"settings" , 0 ) ;
settings . setDomStorageEnabled ( true ) ;
settings . setDomStorageEnabled ( true ) ;
settings . setAppCacheEnabled ( true ) ;
settings . setAppCacheEnabled ( true ) ;
settings . setAppCachePath ( context . getFilesDir ( ) . getAbsolutePath ( )
settings . setAppCachePath ( context . getFilesDir ( ) . getAbsolutePath ( )
+ "/cache" ) ;
+ "/cache" ) ;
if ( API < 18 ) {
settings . setLightTouchEnabled ( true ) ;
}
settings . setAllowFileAccess ( true ) ;
settings . setAllowFileAccess ( true ) ;
settings . setDatabaseEnabled ( true ) ;
settings . setDatabaseEnabled ( true ) ;
settings . setDatabasePath ( context . getFilesDir ( ) . getAbsolutePath ( )
settings . setDatabasePath ( context . getFilesDir ( ) . getAbsolutePath ( )
@ -68,54 +83,168 @@ public final class IncognitoWebView extends WebView {
settings . setDisplayZoomControls ( false ) ;
settings . setDisplayZoomControls ( false ) ;
settings . setAllowContentAccess ( true ) ;
settings . setAllowContentAccess ( true ) ;
}
}
if ( preferences . getBoolean ( "java" , true ) ) {
settings . setJavaScriptEnabled ( true ) ;
settings . setJavaScriptCanOpenWindowsAutomatically ( true ) ;
}
}
@Override
if ( API < 14 ) {
public boolean onTouchEvent ( MotionEvent event ) {
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 ;
}
switch ( event . getAction ( ) ) {
} else {
case MotionEvent . ACTION_DOWN : {
switch ( preferences . getInt ( "textsize" , 3 ) ) {
first = true ;
case 1 :
if ( API < = 10 & & ! hasFocus ( ) ) {
settings . setTextZoom ( 200 ) ;
requestFocus ( ) ;
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 ;
}
}
settings . setSupportMultipleWindows ( preferences . getBoolean ( "newwindow" ,
true ) ) ;
switch ( preferences . getInt ( "enableflash" , 0 ) ) {
case 0 :
break ;
case 1 : {
settings . setPluginState ( PluginState . ON_DEMAND ) ;
break ;
}
}
location = event . getY ( ) ;
case 2 : {
settings . setPluginState ( PluginState . ON ) ;
break ;
break ;
}
}
case MotionEvent . ACTION_UP : {
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 ;
}
}
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 ) ;
}
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 ;
break ;
}
}
}
}
return mGestureDetector . onTouchEvent ( event )
| | super . onTouchEvent ( event ) ;
@Override
public boolean onTouchEvent ( MotionEvent event ) {
mGestureDetector . onTouchEvent ( event ) ;
return super . onTouchEvent ( event ) ;
}
}
@Override
@Override
protected void onWindowVisibilityChanged ( int visibility ) {
protected void onWindowVisibilityChanged ( int visibility ) {
if ( API > = 11 ) {
if ( API > = 11 ) {
this . setActivated ( visibility = = View . VISIBLE ) ;
setActivated ( visibility = = View . VISIBLE ) ;
}
}
this . setEnabled ( visibility = = View . VISIBLE ) ;
setEnabled ( visibility = = View . VISIBLE ) ;
super . onWindowVisibilityChanged ( visibility ) ;
super . onWindowVisibilityChanged ( visibility ) ;
}
}
private final GestureDetector mGestureDetector ;
private final GestureDetector mGestureDetector ;
private class CustomGestureListener extends SimpleOnGestureListener {
private class CustomGestureListener extends SimpleOnGestureListener {
private final int SWIPE_THRESHOLD = 100 ;
final int SWIPE_THRESHOLD = 100 ;
private final int SWIPE_VELOCITY_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
@Override
public boolean onFling ( MotionEvent e1 , MotionEvent e2 , float velocityX ,
public boolean onFling ( MotionEvent e1 , MotionEvent e2 , float velocityX ,
@ -136,18 +265,17 @@ public final class IncognitoWebView extends WebView {
width = size . x ;
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 diffY = e2 . getY ( ) - e1 . getY ( ) ;
float diffX = e2 . getX ( ) - e1 . getX ( ) ;
float diffX = e2 . getX ( ) - e1 . getX ( ) ;
if ( Math . abs ( diffX ) > Math . abs ( diffY ) ) {
if ( Math . abs ( diffX ) > Math . abs ( diffY ) ) {
if ( Math . abs ( diffX ) > SWIPE_THRESHOLD
if ( Math . abs ( diffX ) > SWIPE_THRESHOLD
& & Math . abs ( velocityX ) > SWIPE_VELOCITY_THRESHOLD ) {
& & Math . abs ( velocityX ) > SWIPE_VELOCITY_THRESHOLD ) {
if ( diffX > 0 ) {
if ( diffX > 0 ) {
IncognitoModeActivity . goBack ( ) ;
IncognitoModeActivity . goBack ( IncognitoWebView . this ) ;
return false ;
} else {
} else {
IncognitoModeActivity . goForward ( ) ;
IncognitoModeActivity . goForward ( IncognitoWebView . this ) ;
return false ;
}
}
}
}
}
}
@ -156,7 +284,7 @@ public final class IncognitoWebView extends WebView {
} catch ( Exception exception ) {
} catch ( Exception exception ) {
exception . printStackTrace ( ) ;
exception . printStackTrace ( ) ;
}
}
return false ;
return super . onFling ( e1 , e2 , velocityX , velocityY ) ;
}
}
}
}