@ -5,11 +5,11 @@
package acr.browser.lightning.activity ;
package acr.browser.lightning.activity ;
import android.animation.ArgbEvaluator ;
import android.animation.ArgbEvaluator ;
import android.animation.LayoutTransition ;
import android.animation.ValueAnimator ;
import android.animation.ValueAnimator ;
import android.animation.ValueAnimator.AnimatorUpdateListener ;
import android.animation.ValueAnimator.AnimatorUpdateListener ;
import android.annotation.SuppressLint ;
import android.annotation.SuppressLint ;
import android.app.Activity ;
import android.app.Activity ;
import android.app.AlertDialog ;
import android.content.ClipData ;
import android.content.ClipData ;
import android.content.ClipboardManager ;
import android.content.ClipboardManager ;
import android.content.Context ;
import android.content.Context ;
@ -36,11 +36,13 @@ import android.os.Handler;
import android.os.Message ;
import android.os.Message ;
import android.provider.Browser ;
import android.provider.Browser ;
import android.provider.MediaStore ;
import android.provider.MediaStore ;
import android.support.annotation.NonNull ;
import android.support.v4.view.GravityCompat ;
import android.support.v4.view.GravityCompat ;
import android.support.v4.view.ViewCompat ;
import android.support.v4.view.ViewCompat ;
import android.support.v4.widget.DrawerLayout ;
import android.support.v4.widget.DrawerLayout ;
import android.support.v4.widget.DrawerLayout.DrawerListener ;
import android.support.v4.widget.DrawerLayout.DrawerListener ;
import android.support.v7.app.ActionBar ;
import android.support.v7.app.ActionBar ;
import android.support.v7.app.AlertDialog ;
import android.support.v7.graphics.Palette ;
import android.support.v7.graphics.Palette ;
import android.support.v7.widget.Toolbar ;
import android.support.v7.widget.Toolbar ;
import android.text.TextUtils ;
import android.text.TextUtils ;
@ -62,7 +64,6 @@ import android.view.Window;
import android.view.WindowManager ;
import android.view.WindowManager ;
import android.view.animation.Animation ;
import android.view.animation.Animation ;
import android.view.animation.Animation.AnimationListener ;
import android.view.animation.Animation.AnimationListener ;
import android.view.animation.AnimationUtils ;
import android.view.animation.DecelerateInterpolator ;
import android.view.animation.DecelerateInterpolator ;
import android.view.animation.Transformation ;
import android.view.animation.Transformation ;
import android.view.inputmethod.EditorInfo ;
import android.view.inputmethod.EditorInfo ;
@ -138,9 +139,10 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
private RelativeLayout mSearchBar ;
private RelativeLayout mSearchBar ;
// List
// List
private final List < LightningView > mWebViews = new ArrayList < > ( ) ;
private final List < LightningView > mWebViewLi st = new ArrayList < > ( ) ;
private List < HistoryItem > mBookmarkList ;
private List < HistoryItem > mBookmarkList ;
private LightningView mCurrentView ;
private LightningView mCurrentView ;
private WebView mWebView ;
private AnimatedProgressBar mProgressBar ;
private AnimatedProgressBar mProgressBar ;
private AutoCompleteTextView mSearch ;
private AutoCompleteTextView mSearch ;
@ -207,7 +209,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
//TODO make sure dark theme flag gets set correctly
//TODO make sure dark theme flag gets set correctly
mDarkTheme = mPreferences . getUseTheme ( ) ! = 0 | | isIncognito ( ) ;
mDarkTheme = mPreferences . getUseTheme ( ) ! = 0 | | isIncognito ( ) ;
mActivity = this ;
mActivity = this ;
mWebViews . clear ( ) ;
mWebViewList . clear ( ) ;
mClickHandler = new ClickHandler ( this ) ;
mClickHandler = new ClickHandler ( this ) ;
mBrowserFrame = ( FrameLayout ) findViewById ( R . id . content_frame ) ;
mBrowserFrame = ( FrameLayout ) findViewById ( R . id . content_frame ) ;
@ -234,7 +236,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mHomepage = mPreferences . getHomepage ( ) ;
mHomepage = mPreferences . getHomepage ( ) ;
mTitleAdapter = new LightningViewAdapter ( this , R . layout . tab_list_item , mWebViews ) ;
mTitleAdapter = new LightningViewAdapter ( this , R . layout . tab_list_item , mWebViewLi st ) ;
mDrawerListLeft . setAdapter ( mTitleAdapter ) ;
mDrawerListLeft . setAdapter ( mTitleAdapter ) ;
mDrawerListLeft . setOnItemClickListener ( new DrawerItemClickListener ( ) ) ;
mDrawerListLeft . setOnItemClickListener ( new DrawerItemClickListener ( ) ) ;
mDrawerListLeft . setOnItemLongClickListener ( new DrawerItemLongClickListener ( ) ) ;
mDrawerListLeft . setOnItemLongClickListener ( new DrawerItemLongClickListener ( ) ) ;
@ -244,6 +246,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mHistoryDatabase = HistoryDatabase . getInstance ( getApplicationContext ( ) ) ;
mHistoryDatabase = HistoryDatabase . getInstance ( getApplicationContext ( ) ) ;
if ( actionBar = = null )
return ;
// set display options of the ActionBar
// set display options of the ActionBar
actionBar . setDisplayShowTitleEnabled ( false ) ;
actionBar . setDisplayShowTitleEnabled ( false ) ;
actionBar . setDisplayShowHomeEnabled ( false ) ;
actionBar . setDisplayShowHomeEnabled ( false ) ;
@ -410,7 +415,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
updateUrl ( mCurrentView . getUrl ( ) , true ) ;
updateUrl ( mCurrentView . getUrl ( ) , true ) ;
} else if ( hasFocus ) {
} else if ( hasFocus ) {
String url = mCurrentView . getUrl ( ) ;
String url = mCurrentView . getUrl ( ) ;
if ( url = = null | | url . startsWith ( Constants . FILE ) ) {
if ( url . startsWith ( Constants . FILE ) ) {
mSearch . setText ( "" ) ;
mSearch . setText ( "" ) ;
} else {
} else {
mSearch . setText ( url ) ;
mSearch . setText ( url ) ;
@ -578,11 +583,11 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/ *
/ *
* Override this class
* Override this class
* /
* /
public synchronized void initializeTabs ( ) {
synchronized void initializeTabs ( ) {
}
}
public void restoreOrNewTab ( ) {
void restoreOrNewTab ( ) {
mIdGenerator = 0 ;
mIdGenerator = 0 ;
String url = null ;
String url = null ;
@ -633,14 +638,31 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
changeToolbarBackground ( mCurrentView . getFavicon ( ) ) ;
changeToolbarBackground ( mCurrentView . getFavicon ( ) ) ;
}
}
if ( mFullScreen & & mBrowserFrame . findViewById ( R . id . toolbar_layout ) = = null ) {
if ( mFullScreen ) {
mToolbarLayout . setTranslationY ( 0 ) ;
int height = mToolbarLayout . getHeight ( ) ;
if ( height = = 0 ) {
mToolbarLayout . measure ( View . MeasureSpec . UNSPECIFIED , View . MeasureSpec . UNSPECIFIED ) ;
height = mToolbarLayout . getMeasuredHeight ( ) ;
}
if ( mWebView ! = null )
mWebView . setTranslationY ( height ) ;
mBrowserFrame . setLayoutTransition ( null ) ;
if ( mBrowserFrame . findViewById ( R . id . toolbar_layout ) = = null ) {
mUiLayout . removeView ( mToolbarLayout ) ;
mUiLayout . removeView ( mToolbarLayout ) ;
mBrowserFrame . addView ( mToolbarLayout ) ;
mBrowserFrame . addView ( mToolbarLayout ) ;
mToolbarLayout . bringToFront ( ) ;
mToolbarLayout . bringToFront ( ) ;
} else if ( mBrowserFrame . findViewById ( R . id . toolbar_layout ) ! = null ) {
}
} else {
mToolbarLayout . setTranslationY ( 0 ) ;
if ( mBrowserFrame . findViewById ( R . id . toolbar_layout ) ! = null ) {
mBrowserFrame . removeView ( mToolbarLayout ) ;
mBrowserFrame . removeView ( mToolbarLayout ) ;
mUiLayout . addView ( mToolbarLayout , 0 ) ;
mUiLayout . addView ( mToolbarLayout , 0 ) ;
}
}
mBrowserFrame . setLayoutTransition ( new LayoutTransition ( ) ) ;
if ( mWebView ! = null )
mWebView . setTranslationY ( 0 ) ;
}
if ( mPreferences . getHideStatusBarEnabled ( ) ) {
if ( mPreferences . getHideStatusBarEnabled ( ) ) {
getWindow ( ) . setFlags ( WindowManager . LayoutParams . FLAG_FULLSCREEN ,
getWindow ( ) . setFlags ( WindowManager . LayoutParams . FLAG_FULLSCREEN ,
WindowManager . LayoutParams . FLAG_FULLSCREEN ) ;
WindowManager . LayoutParams . FLAG_FULLSCREEN ) ;
@ -695,7 +717,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/ *
/ *
* Override this if class overrides BrowserActivity
* Override this if class overrides BrowserActivity
* /
* /
public void updateCookiePreference ( ) {
void updateCookiePreference ( ) {
}
}
@ -714,7 +736,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
@Override
@Override
public boolean onKeyUp ( int keyCode , KeyEvent event ) {
public boolean onKeyUp ( int keyCode , @NonNull KeyEvent event ) {
if ( ( keyCode = = KeyEvent . KEYCODE_MENU ) & & ( Build . VERSION . SDK_INT < = 16 )
if ( ( keyCode = = KeyEvent . KEYCODE_MENU ) & & ( Build . VERSION . SDK_INT < = 16 )
& & ( Build . MANUFACTURER . compareTo ( "LGE" ) = = 0 ) ) {
& & ( Build . MANUFACTURER . compareTo ( "LGE" ) = = 0 ) ) {
// Workaround for stupid LG devices that crash
// Workaround for stupid LG devices that crash
@ -739,18 +761,14 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
return true ;
return true ;
case R . id . action_back :
case R . id . action_back :
if ( mCurrentView ! = null ) {
if ( mCurrentView ! = null & & mCurrentView . canGoBack ( ) ) {
if ( mCurrentView . canGoBack ( ) ) {
mCurrentView . goBack ( ) ;
mCurrentView . goBack ( ) ;
}
}
}
return true ;
return true ;
case R . id . action_forward :
case R . id . action_forward :
if ( mCurrentView ! = null ) {
if ( mCurrentView ! = null & & mCurrentView . canGoForward ( ) ) {
if ( mCurrentView . canGoForward ( ) ) {
mCurrentView . goForward ( ) ;
mCurrentView . goForward ( ) ;
}
}
}
return true ;
return true ;
case R . id . action_new_tab :
case R . id . action_new_tab :
newTab ( null , true ) ;
newTab ( null , true ) ;
@ -759,7 +777,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
startActivity ( new Intent ( this , IncognitoActivity . class ) ) ;
startActivity ( new Intent ( this , IncognitoActivity . class ) ) ;
return true ;
return true ;
case R . id . action_share :
case R . id . action_share :
if ( ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
if ( mCurrentView ! = null & & ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
Intent shareIntent = new Intent ( android . content . Intent . ACTION_SEND ) ;
Intent shareIntent = new Intent ( android . content . Intent . ACTION_SEND ) ;
shareIntent . setType ( "text/plain" ) ;
shareIntent . setType ( "text/plain" ) ;
shareIntent . putExtra ( android . content . Intent . EXTRA_SUBJECT ,
shareIntent . putExtra ( android . content . Intent . EXTRA_SUBJECT ,
@ -774,15 +792,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
openBookmarks ( ) ;
openBookmarks ( ) ;
return true ;
return true ;
case R . id . action_copy :
case R . id . action_copy :
if ( mCurrentView ! = null ) {
if ( mCurrentView ! = null & & ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
if ( ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
ClipboardManager clipboard = ( ClipboardManager ) getSystemService ( CLIPBOARD_SERVICE ) ;
ClipboardManager clipboard = ( ClipboardManager ) getSystemService ( CLIPBOARD_SERVICE ) ;
ClipData clip = ClipData . newPlainText ( "label" , mCurrentView . getUrl ( ) ) ;
ClipData clip = ClipData . newPlainText ( "label" , mCurrentView . getUrl ( ) ) ;
clipboard . setPrimaryClip ( clip ) ;
clipboard . setPrimaryClip ( clip ) ;
Utils . showToast ( mActivity ,
Utils . showToast ( mActivity ,
mActivity . getResources ( ) . getString ( R . string . message_link_copied ) ) ;
mActivity . getResources ( ) . getString ( R . string . message_link_copied ) ) ;
}
}
}
return true ;
return true ;
case R . id . action_settings :
case R . id . action_settings :
startActivity ( new Intent ( this , SettingsActivity . class ) ) ;
startActivity ( new Intent ( this , SettingsActivity . class ) ) ;
@ -791,10 +807,10 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
openHistory ( ) ;
openHistory ( ) ;
return true ;
return true ;
case R . id . action_add_bookmark :
case R . id . action_add_bookmark :
if ( ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
if ( mCurrentView ! = null & & ! mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) ) {
HistoryItem bookmark = new HistoryItem ( mCurrentView . getUrl ( ) ,
HistoryItem bookmark = new HistoryItem ( mCurrentView . getUrl ( ) ,
mCurrentView . getTitle ( ) ) ;
mCurrentView . getTitle ( ) ) ;
if ( mBookmarkManager . addBookmark ( bookmark ) ) {
if ( mBookmarkManager . addBookmark ( bookmark ) & & mBookmarkList ! = null ) {
mBookmarkList . add ( bookmark ) ;
mBookmarkList . add ( bookmark ) ;
Collections . sort ( mBookmarkList , new SortIgnoreCase ( ) ) ;
Collections . sort ( mBookmarkList , new SortIgnoreCase ( ) ) ;
notifyBookmarkDataSetChanged ( ) ;
notifyBookmarkDataSetChanged ( ) ;
@ -901,7 +917,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
@Override
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
public void onItemClick ( AdapterView < ? > parent , View view , int position , long id ) {
mIsNewIntent = false ;
mIsNewIntent = false ;
showTab ( mWebViews . get ( position ) ) ;
showTab ( mWebViewLi st . get ( position ) ) ;
}
}
}
}
@ -985,8 +1001,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* Takes in the id of which bookmark was selected and shows a dialog that
* Takes in the id of which bookmark was selected and shows a dialog that
* allows the user to rename and change the url of the bookmark
* allows the user to rename and change the url of the bookmark
*
*
* @param id
* @param id which id in the list was chosen
* which id in the list was chosen
* /
* /
private synchronized void editBookmark ( final int id ) {
private synchronized void editBookmark ( final int id ) {
final AlertDialog . Builder homePicker = new AlertDialog . Builder ( mActivity ) ;
final AlertDialog . Builder homePicker = new AlertDialog . Builder ( mActivity ) ;
@ -1014,11 +1029,9 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mBookmarkManager . overwriteBookmarks ( mBookmarkList ) ;
mBookmarkManager . overwriteBookmarks ( mBookmarkList ) ;
Collections . sort ( mBookmarkList , new SortIgnoreCase ( ) ) ;
Collections . sort ( mBookmarkList , new SortIgnoreCase ( ) ) ;
notifyBookmarkDataSetChanged ( ) ;
notifyBookmarkDataSetChanged ( ) ;
if ( mCurrentView ! = null ) {
if ( mCurrentView ! = null & & mCurrentView . getUrl ( ) . startsWith ( Constants . FILE )
if ( mCurrentView . getUrl ( ) . startsWith ( Constants . FILE )
& & mCurrentView . getUrl ( ) . endsWith ( "bookmarks.html" ) ) {
& & mCurrentView . getUrl ( ) . endsWith ( "bookmarks.html" ) ) {
openBookmarkPage ( mCurrentView . getWebView ( ) ) ;
openBookmarkPage ( mWebView ) ;
}
}
}
}
}
} ) ;
} ) ;
@ -1029,8 +1042,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* displays the WebView contained in the LightningView Also handles the
* displays the WebView contained in the LightningView Also handles the
* removal of previous views
* removal of previous views
*
*
* @param view
* @param view the LightningView to show
* the LightningView to show
* /
* /
private synchronized void showTab ( LightningView view ) {
private synchronized void showTab ( LightningView view ) {
// 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
@ -1038,14 +1050,16 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
if ( view = = null ) {
if ( view = = null ) {
return ;
return ;
}
}
final float translation = mToolbarLayout . getTranslationY ( ) ;
mBrowserFrame . removeAllViews ( ) ;
mBrowserFrame . removeAllViews ( ) ;
if ( mCurrentView ! = null ) {
if ( mCurrentView ! = null ) {
mCurrentView . setForegroundTab ( false ) ;
mCurrentView . setForegroundTab ( false ) ;
mCurrentView . onPause ( ) ;
mCurrentView . onPause ( ) ;
}
}
mCurrentView = view ;
mCurrentView = view ;
mWebView = view . getWebView ( ) ;
mCurrentView . setForegroundTab ( true ) ;
mCurrentView . setForegroundTab ( true ) ;
if ( mCurrentView . get WebView ( ) ! = null ) {
if ( mWebView ! = null ) {
updateUrl ( mCurrentView . getUrl ( ) , true ) ;
updateUrl ( mCurrentView . getUrl ( ) , true ) ;
updateProgress ( mCurrentView . getProgress ( ) ) ;
updateProgress ( mCurrentView . getProgress ( ) ) ;
} else {
} else {
@ -1053,22 +1067,48 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
updateProgress ( 0 ) ;
updateProgress ( 0 ) ;
}
}
mBrowserFrame . addView ( mCurrentView . getWebView ( ) , MATCH_PARENT ) ;
mBrowserFrame . addView ( mWebView , MATCH_PARENT ) ;
// Remove browser frame background to reduce overdraw
mBrowserFrame . setBackgroundColor ( 0 ) ;
mCurrentView . requestFocus ( ) ;
mCurrentView . requestFocus ( ) ;
mCurrentView . onResume ( ) ;
mCurrentView . onResume ( ) ;
if ( mFullScreen ) {
// mToolbarLayout has already been removed
mBrowserFrame . addView ( mToolbarLayout ) ;
mToolbarLayout . bringToFront ( ) ;
Log . d ( Constants . TAG , "Move view to browser frame" ) ;
int height = mToolbarLayout . getHeight ( ) ;
if ( height = = 0 ) {
mToolbarLayout . measure ( View . MeasureSpec . UNSPECIFIED , View . MeasureSpec . UNSPECIFIED ) ;
height = mToolbarLayout . getMeasuredHeight ( ) ;
}
mWebView . setTranslationY ( translation + height ) ;
mToolbarLayout . setTranslationY ( translation ) ;
} else {
mWebView . setTranslationY ( 0 ) ;
}
showActionBar ( ) ;
// Use a delayed handler to make the transition smooth
// Use a delayed handler to make the transition smooth
// otherwise it will get caught up with the showTab code
// otherwise it will get caught up with the showTab code
// and cause a janky motion
// and cause a janky motion
final Handler handler = new Handler ( ) ;
new Handler ( ) . postDelayed ( new Runnable ( ) {
handler . postDelayed ( new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
mDrawerLayout . closeDrawers ( ) ;
mDrawerLayout . closeDrawers ( ) ;
}
}
} , 150 ) ;
} , 150 ) ;
// new Handler().postDelayed(new Runnable() {
// @Override
// public void run() {
// // Remove browser frame background to reduce overdraw
// //TODO evaluate performance
// mBrowserFrame.setBackgroundColor(0);
// }
// }, 300);
}
}
/ * *
/ * *
@ -1079,7 +1119,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
super . onNewIntent ( intent ) ;
super . onNewIntent ( intent ) ;
}
}
public void handleNewIntent ( Intent intent ) {
void handleNewIntent ( Intent intent ) {
String url = null ;
String url = null ;
if ( intent ! = null ) {
if ( intent ! = null ) {
@ -1103,7 +1143,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
@Override
public void closeEmptyTab ( ) {
public void closeEmptyTab ( ) {
if ( mCurrent View ! = null & & mCurrentView . get WebView ( ) . copyBackForwardList ( ) . getSize ( ) = = 0 ) {
if ( mWeb View ! = null & & mWebView . copyBackForwardList ( ) . getSize ( ) = = 0 ) {
closeCurrentTab ( ) ;
closeCurrentTab ( ) ;
}
}
}
}
@ -1117,15 +1157,15 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
public void onTrimMemory ( int level ) {
public void onTrimMemory ( int level ) {
if ( level > TRIM_MEMORY_MODERATE & & Build . VERSION . SDK_INT < Build . VERSION_CODES . KITKAT ) {
if ( level > TRIM_MEMORY_MODERATE & & Build . VERSION . SDK_INT < Build . VERSION_CODES . KITKAT ) {
Log . d ( Constants . TAG , "Low Memory, Free Memory" ) ;
Log . d ( Constants . TAG , "Low Memory, Free Memory" ) ;
for ( LightningView view : mWebViews ) {
for ( int n = 0 ; n < mWebViewList . size ( ) ; n + + ) {
view . getWebView ( ) . freeMemory ( ) ;
mWebViewList . get ( n ) . freeMemory ( ) ;
}
}
}
}
}
}
protected synchronized boolean newTab ( String url , boolean show ) {
synchronized boolean newTab ( String url , boolean show ) {
// Limit number of tabs for limited version of app
// Limit number of tabs for limited version of app
if ( ! Constants . FULL_VERSION & & mWebViews . size ( ) > = 10 ) {
if ( ! Constants . FULL_VERSION & & mWebViewLi st . size ( ) > = 10 ) {
Utils . showToast ( this , this . getString ( R . string . max_tabs ) ) ;
Utils . showToast ( this , this . getString ( R . string . max_tabs ) ) ;
return false ;
return false ;
}
}
@ -1135,28 +1175,27 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
startingTab . resumeTimers ( ) ;
startingTab . resumeTimers ( ) ;
}
}
mIdGenerator + + ;
mIdGenerator + + ;
mWebViews . add ( startingTab ) ;
mWebViewList . add ( startingTab ) ;
mTitleAdapter . notifyDataSetChanged ( ) ;
mTitleAdapter . notifyDataSetChanged ( ) ;
if ( show ) {
if ( show ) {
mDrawerListLeft . setItemChecked ( mWebViews . size ( ) - 1 , true ) ;
mDrawerListLeft . setItemChecked ( mWebViewLi st . size ( ) - 1 , true ) ;
showTab ( startingTab ) ;
showTab ( startingTab ) ;
}
}
return true ;
return true ;
}
}
private synchronized void deleteTab ( int position ) {
private synchronized void deleteTab ( int position ) {
if ( position > = mWebViews . size ( ) ) {
if ( position > = mWebViewLi st . size ( ) ) {
return ;
return ;
}
}
int current = mDrawerListLeft . getCheckedItemPosition ( ) ;
int current = mDrawerListLeft . getCheckedItemPosition ( ) ;
LightningView reference = mWebViews . get ( position ) ;
LightningView reference = mWebViewLi st . get ( position ) ;
if ( reference = = null ) {
if ( reference = = null ) {
return ;
return ;
}
}
if ( reference . getUrl ( ) ! = null & & ! reference . getUrl ( ) . startsWith ( Constants . FILE )
if ( ! reference . getUrl ( ) . startsWith ( Constants . FILE ) & & ! isIncognito ( ) ) {
& & ! isIncognito ( ) ) {
mPreferences . setSavedUrl ( reference . getUrl ( ) ) ;
mPreferences . setSavedUrl ( reference . getUrl ( ) ) ;
}
}
boolean isShown = reference . isShown ( ) ;
boolean isShown = reference . isShown ( ) ;
@ -1164,35 +1203,34 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mBrowserFrame . setBackgroundColor ( mBackgroundColor ) ;
mBrowserFrame . setBackgroundColor ( mBackgroundColor ) ;
}
}
if ( current > position ) {
if ( current > position ) {
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
mDrawerListLeft . setItemChecked ( current - 1 , true ) ;
mDrawerListLeft . setItemChecked ( current - 1 , true ) ;
reference . onDestroy ( ) ;
reference . onDestroy ( ) ;
} else if ( mWebViews . size ( ) > position + 1 ) {
} else if ( mWebViewLi st . size ( ) > position + 1 ) {
if ( current = = position ) {
if ( current = = position ) {
showTab ( mWebViews . get ( position + 1 ) ) ;
showTab ( mWebViewLi st . get ( position + 1 ) ) ;
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
mDrawerListLeft . setItemChecked ( position , true ) ;
mDrawerListLeft . setItemChecked ( position , true ) ;
} else {
} else {
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
}
}
reference . onDestroy ( ) ;
reference . onDestroy ( ) ;
} else if ( mWebViews . size ( ) > 1 ) {
} else if ( mWebViewLi st . size ( ) > 1 ) {
if ( current = = position ) {
if ( current = = position ) {
showTab ( mWebViews . get ( position - 1 ) ) ;
showTab ( mWebViewLi st . get ( position - 1 ) ) ;
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
mDrawerListLeft . setItemChecked ( position - 1 , true ) ;
mDrawerListLeft . setItemChecked ( position - 1 , true ) ;
} else {
} else {
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
}
}
reference . onDestroy ( ) ;
reference . onDestroy ( ) ;
} else {
} else {
if ( mCurrentView . getUrl ( ) = = null | | mCurrentView . getUrl ( ) . startsWith ( Constants . FILE )
if ( mCurrentView . getUrl ( ) . startsWith ( Constants . FILE ) | | mCurrentView . getUrl ( ) . equals ( mHomepage ) ) {
| | mCurrentView . getUrl ( ) . equals ( mHomepage ) ) {
closeActivity ( ) ;
closeActivity ( ) ;
} else {
} else {
mWebViews . remove ( position ) ;
mWebViewList . remove ( position ) ;
if ( mPreferences . getClearCacheExit ( ) & & mCurrentView ! = null & & ! isIncognito ( ) ) {
if ( mPreferences . getClearCacheExit ( ) & & mCurrentView ! = null & & ! isIncognito ( ) ) {
mCurrentView . clearCache ( true ) ;
mCurrentView . clearCache ( true ) ;
Log . d ( Constants . TAG , "Cache Cleared" ) ;
Log . d ( Constants . TAG , "Cache Cleared" ) ;
@ -1211,6 +1249,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
reference . pauseTimers ( ) ;
reference . pauseTimers ( ) ;
reference . onDestroy ( ) ;
reference . onDestroy ( ) ;
mCurrentView = null ;
mCurrentView = null ;
mWebView = null ;
mTitleAdapter . notifyDataSetChanged ( ) ;
mTitleAdapter . notifyDataSetChanged ( ) ;
finish ( ) ;
finish ( ) ;
@ -1252,12 +1291,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
mCurrentView = null ;
mCurrentView = null ;
for ( int n = 0 ; n < mWebViews . size ( ) ; n + + ) {
mWebView = null ;
if ( mWebViews . get ( n ) ! = null ) {
for ( int n = 0 ; n < mWebViewList . size ( ) ; n + + ) {
mWebViews . get ( n ) . onDestroy ( ) ;
if ( mWebViewList . get ( n ) ! = null ) {
mWebViewList . get ( n ) . onDestroy ( ) ;
}
}
}
}
mWebViews . clear ( ) ;
mWebViewList . clear ( ) ;
mTitleAdapter . notifyDataSetChanged ( ) ;
mTitleAdapter . notifyDataSetChanged ( ) ;
finish ( ) ;
finish ( ) ;
}
}
@ -1334,12 +1374,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
}
}
public void saveOpenTabs ( ) {
void saveOpenTabs ( ) {
if ( mPreferences . getRestoreLostTabsEnabled ( ) ) {
if ( mPreferences . getRestoreLostTabsEnabled ( ) ) {
String s = "" ;
String s = "" ;
for ( int n = 0 ; n < mWebViews . size ( ) ; n + + ) {
for ( int n = 0 ; n < mWebViewLi st . size ( ) ; n + + ) {
if ( mWebViews . get ( n ) . getUrl ( ) ! = null ) {
if ( mWebViewLi st . get ( n ) . getUrl ( ) . length ( ) > 0 ) {
s = s + mWebViews . get ( n ) . getUrl ( ) + "|$|SEPARATOR|$|" ;
s = s + mWebViewLi st . get ( n ) . getUrl ( ) + "|$|SEPARATOR|$|" ;
}
}
}
}
mPreferences . setMemoryUrl ( s ) ;
mPreferences . setMemoryUrl ( s ) ;
@ -1384,12 +1424,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
notifyBookmarkDataSetChanged ( ) ;
notifyBookmarkDataSetChanged ( ) ;
}
}
initializePreferences ( ) ;
initializePreferences ( ) ;
if ( mWebViews ! = null ) {
if ( mWebViewLi st ! = null ) {
for ( int n = 0 ; n < mWebViews . size ( ) ; n + + ) {
for ( int n = 0 ; n < mWebViewLi st . size ( ) ; n + + ) {
if ( mWebViews . get ( n ) ! = null ) {
if ( mWebViewLi st . get ( n ) ! = null ) {
mWebViews . get ( n ) . initializePreferences ( this ) ;
mWebViewList . get ( n ) . initializePreferences ( this ) ;
} else {
} else {
mWebViews . remove ( n ) ;
mWebViewList . remove ( n ) ;
}
}
}
}
}
}
@ -1773,7 +1813,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
public void addItemToHistory ( final String title , final String url ) {
void addItemToHistory ( final String title , final String url ) {
Runnable update = new Runnable ( ) {
Runnable update = new Runnable ( ) {
@Override
@Override
public void run ( ) {
public void run ( ) {
@ -1908,7 +1948,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mDrawerLayout . openDrawer ( mDrawerRight ) ;
mDrawerLayout . openDrawer ( mDrawerRight ) ;
}
}
public void closeDrawers ( ) {
void closeDrawers ( ) {
mDrawerLayout . closeDrawers ( ) ;
mDrawerLayout . closeDrawers ( ) ;
}
}
@ -2066,12 +2106,12 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
Message click = mClickHandler . obtainMessage ( ) ;
Message click = mClickHandler . obtainMessage ( ) ;
if ( click ! = null ) {
if ( click ! = null ) {
click . setTarget ( mClickHandler ) ;
click . setTarget ( mClickHandler ) ;
mCurrentView . getWebView ( ) . requestFocusNodeHref ( click ) ;
mWebView . requestFocusNodeHref ( click ) ;
}
}
}
}
@Override
@Override
public void onShowCustomView ( View view , int requestedOrientation , CustomViewCallback callback ) {
public void onShowCustomView ( View view , CustomViewCallback callback ) {
if ( view = = null ) {
if ( view = = null ) {
return ;
return ;
}
}
@ -2155,8 +2195,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/ * *
/ * *
* turns on fullscreen mode in the app
* turns on fullscreen mode in the app
*
*
* @param enabled
* @param enabled whether to enable fullscreen or not
* whether to enable fullscreen or not
* /
* /
private void setFullscreen ( boolean enabled ) {
private void setFullscreen ( boolean enabled ) {
Window win = getWindow ( ) ;
Window win = getWindow ( ) ;
@ -2187,7 +2226,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@SuppressLint ( "ClickableViewAccessibility" )
@SuppressLint ( "ClickableViewAccessibility" )
@Override
@Override
public boolean onTouchEvent ( MotionEvent evt ) {
public boolean onTouchEvent ( @NonNull MotionEvent evt ) {
return true ;
return true ;
}
}
@ -2223,13 +2262,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/ * *
/ * *
* handles javascript requests to create a new window in the browser
* handles javascript requests to create a new window in the browser
* /
* /
public void onCreateWindow ( boolean isUserGesture , Message resultMsg ) {
public void onCreateWindow ( Message resultMsg ) {
if ( resultMsg = = null ) {
if ( resultMsg = = null ) {
return ;
return ;
}
}
if ( newTab ( "" , true ) ) {
if ( newTab ( "" , true ) ) {
WebView . WebViewTransport transport = ( WebView . WebViewTransport ) resultMsg . obj ;
WebView . WebViewTransport transport = ( WebView . WebViewTransport ) resultMsg . obj ;
transport . setWebView ( mCurrentView . get WebView ( ) ) ;
transport . setWebView ( mWebView ) ;
resultMsg . sendToTarget ( ) ;
resultMsg . sendToTarget ( ) ;
}
}
}
}
@ -2243,6 +2282,10 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
return mActivity ;
return mActivity ;
}
}
private boolean isToolbarVisible ( ) {
return mToolbarLayout . getTranslationY ( ) > - 0 . 01f ;
}
/ * *
/ * *
* it hides the action bar , seriously what else were you expecting
* it hides the action bar , seriously what else were you expecting
* /
* /
@ -2254,28 +2297,28 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
mBrowserFrame . addView ( mToolbarLayout ) ;
mBrowserFrame . addView ( mToolbarLayout ) ;
mToolbarLayout . bringToFront ( ) ;
mToolbarLayout . bringToFront ( ) ;
Log . d ( Constants . TAG , "Move view to browser frame" ) ;
Log . d ( Constants . TAG , "Move view to browser frame" ) ;
mToolbarLayout . setTranslationY ( 0 ) ;
mWebView . setTranslationY ( mToolbarLayout . getHeight ( ) ) ;
}
}
if ( mToolbarLayout . getVisibility ( ) ! = View . GONE ) {
if ( mToolbarLayout = = null | | mCurrentView = = null )
return ;
Animation hide = AnimationUtils . loadAnimation ( mActivity , R . anim . slide_up ) ;
hide . setAnimationListener ( new AnimationListener ( ) {
@Override
public void onAnimationStart ( Animation animation ) {
}
@Override
public void onAnimationEnd ( Animation animation ) {
mToolbarLayout . setVisibility ( View . GONE ) ;
}
final int height = mToolbarLayout . getHeight ( ) ;
final WebView view = mWebView ;
if ( mToolbarLayout . getTranslationY ( ) > - 0 . 01f ) {
Animation show = new Animation ( ) {
@Override
@Override
public void onAnimationRepeat ( Animation animation ) {
protected void applyTransformation ( float interpolatedTime , Transformation t ) {
float trans = ( 1 . 0f - interpolatedTime ) * height ;
mToolbarLayout . setTranslationY ( trans - height ) ;
if ( view ! = null )
view . setTranslationY ( trans ) ;
}
}
} ;
} ) ;
show . setDuration ( 250 ) ;
mToolbarLayout . startAnimation ( hide ) ;
show . setInterpolator ( new DecelerateInterpolator ( ) ) ;
Log . d ( Constants . TAG , "Hide" ) ;
// show.setFillAfter(true);
mWebView . startAnimation ( show ) ;
}
}
}
}
}
}
@ -2283,7 +2326,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
@Override
@Override
public void toggleActionBar ( ) {
public void toggleActionBar ( ) {
if ( mFullScreen ) {
if ( mFullScreen ) {
if ( mToolbarLayout . getVisibility ( ) ! = View . VISIBLE ) {
if ( ! isToolbarVisible ( ) ) {
showActionBar ( ) ;
showActionBar ( ) ;
} else {
} else {
hideActionBar ( ) ;
hideActionBar ( ) ;
@ -2297,36 +2340,46 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* /
* /
public void showActionBar ( ) {
public void showActionBar ( ) {
if ( mFullScreen ) {
if ( mFullScreen ) {
if ( mToolbarLayout = = null )
return ;
int height = mToolbarLayout . getHeight ( ) ;
if ( height = = 0 ) {
mToolbarLayout . measure ( View . MeasureSpec . UNSPECIFIED , View . MeasureSpec . UNSPECIFIED ) ;
height = mToolbarLayout . getMeasuredHeight ( ) ;
}
if ( mBrowserFrame . findViewById ( R . id . toolbar_layout ) = = null ) {
if ( mBrowserFrame . findViewById ( R . id . toolbar_layout ) = = null ) {
mUiLayout . removeView ( mToolbarLayout ) ;
mUiLayout . removeView ( mToolbarLayout ) ;
mBrowserFrame . addView ( mToolbarLayout ) ;
mBrowserFrame . addView ( mToolbarLayout ) ;
mToolbarLayout . bringToFront ( ) ;
mToolbarLayout . bringToFront ( ) ;
Log . d ( Constants . TAG , "Move view to browser frame" ) ;
Log . d ( Constants . TAG , "Move view to browser frame" ) ;
mToolbarLayout . setTranslationY ( 0 ) ;
mWebView . setTranslationY ( height ) ;
}
}
if ( mToolbarLayout . getVisibility ( ) ! = View . VISIBLE ) {
if ( mCurrentView = = null )
Animation show = AnimationUtils . loadAnimation ( mActivity , R . anim . slide_down ) ;
return ;
show . setAnimationListener ( new AnimationListener ( ) {
@Override
public void onAnimationStart ( Animation animation ) {
}
@Override
public void onAnimationEnd ( Animation animation ) {
mToolbarLayout . setVisibility ( View . VISIBLE ) ;
}
final WebView view = mWebView ;
final int totalHeight = height ;
if ( mToolbarLayout . getTranslationY ( ) < - ( height - 0 . 01f ) ) {
Animation show = new Animation ( ) {
@Override
@Override
public void onAnimationRepeat ( Animation animation ) {
protected void applyTransformation ( float interpolatedTime , Transformation t ) {
float trans = interpolatedTime * totalHeight ;
mToolbarLayout . setTranslationY ( trans - totalHeight ) ;
// null pointer here on close
if ( view ! = null )
view . setTranslationY ( trans ) ;
}
}
} ;
} ) ;
show . setDuration ( 250 ) ;
mToolbarLayout . startAnimation ( show ) ;
show . setInterpolator ( new DecelerateInterpolator ( ) ) ;
Log . d ( Constants . TAG , "Show" ) ;
// show.setFillAfter(true);
mWebView . startAnimation ( show ) ;
}
}
}
}
}
}
@Override
@Override
@ -2337,8 +2390,8 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
* /
* /
public void longClickPage ( final String url ) {
public void longClickPage ( final String url ) {
HitTestResult result = null ;
HitTestResult result = null ;
if ( mCurrentView . get WebView ( ) ! = null ) {
if ( mWebView ! = null ) {
result = mCurrentView . get WebView ( ) . getHitTestResult ( ) ;
result = mWebView . getHitTestResult ( ) ;
}
}
if ( url ! = null ) {
if ( url ! = null ) {
if ( result ! = null ) {
if ( result ! = null ) {
@ -2359,7 +2412,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
case DialogInterface . BUTTON_NEUTRAL :
case DialogInterface . BUTTON_NEUTRAL :
if ( API > 8 ) {
if ( API > 8 ) {
Utils . downloadFile ( mActivity , url ,
Utils . downloadFile ( mActivity , url ,
mCurrentView . getUserAgent ( ) , "attachment" , false ) ;
mCurrentView . getUserAgent ( ) , "attachment" ) ;
}
}
break ;
break ;
}
}
@ -2461,7 +2514,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
case DialogInterface . BUTTON_NEUTRAL :
case DialogInterface . BUTTON_NEUTRAL :
if ( API > 8 ) {
if ( API > 8 ) {
Utils . downloadFile ( mActivity , newUrl ,
Utils . downloadFile ( mActivity , newUrl ,
mCurrentView . getUserAgent ( ) , "attachment" , false ) ;
mCurrentView . getUserAgent ( ) , "attachment" ) ;
}
}
break ;
break ;
}
}
@ -2544,7 +2597,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
/ * *
/ * *
* handle presses on the refresh icon in the search bar , if the page is
* handle presses on the refresh icon in the search bar , if the page is
* loading , stop the page , if it is done loading refresh the page .
* loading , stop the page , if it is done loading refresh the page .
*
* < p / >
* See setIsFinishedLoading and setIsLoading for displaying the correct icon
* See setIsFinishedLoading and setIsLoading for displaying the correct icon
* /
* /
private void refreshOrStop ( ) {
private void refreshOrStop ( ) {
@ -2558,7 +2611,7 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
}
}
// Override this, use finish() for Incognito, moveTaskToBack for Main
// Override this, use finish() for Incognito, moveTaskToBack for Main
public void closeActivity ( ) {
void closeActivity ( ) {
finish ( ) ;
finish ( ) ;
}
}
@ -2606,13 +2659,13 @@ public class BrowserActivity extends ThemableActivity implements BrowserControll
newTab ( null , true ) ;
newTab ( null , true ) ;
break ;
break ;
case R . id . button_next :
case R . id . button_next :
mCurrentView . getWebView ( ) . findNext ( false ) ;
mWebView . findNext ( false ) ;
break ;
break ;
case R . id . button_back :
case R . id . button_back :
mCurrentView . getWebView ( ) . findNext ( true ) ;
mWebView . findNext ( true ) ;
break ;
break ;
case R . id . button_quit :
case R . id . button_quit :
mCurrentView . getWebView ( ) . clearMatches ( ) ;
mWebView . clearMatches ( ) ;
mSearchBar . setVisibility ( View . GONE ) ;
mSearchBar . setVisibility ( View . GONE ) ;
break ;
break ;
}
}