|
|
@ -30,7 +30,6 @@ import android.graphics.drawable.ColorDrawable; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.graphics.drawable.Drawable; |
|
|
|
import android.media.MediaPlayer; |
|
|
|
import android.media.MediaPlayer; |
|
|
|
import android.net.Uri; |
|
|
|
import android.net.Uri; |
|
|
|
import android.os.AsyncTask; |
|
|
|
|
|
|
|
import android.os.Build; |
|
|
|
import android.os.Build; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Bundle; |
|
|
|
import android.os.Handler; |
|
|
|
import android.os.Handler; |
|
|
@ -65,7 +64,6 @@ import android.view.ViewGroup; |
|
|
|
import android.view.ViewGroup.LayoutParams; |
|
|
|
import android.view.ViewGroup.LayoutParams; |
|
|
|
import android.view.Window; |
|
|
|
import android.view.Window; |
|
|
|
import android.view.WindowManager; |
|
|
|
import android.view.WindowManager; |
|
|
|
import android.view.animation.AccelerateInterpolator; |
|
|
|
|
|
|
|
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.DecelerateInterpolator; |
|
|
|
import android.view.animation.DecelerateInterpolator; |
|
|
@ -86,26 +84,26 @@ import android.widget.FrameLayout; |
|
|
|
import android.widget.ImageButton; |
|
|
|
import android.widget.ImageButton; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.ImageView; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.LinearLayout; |
|
|
|
import android.widget.ListView; |
|
|
|
|
|
|
|
import android.widget.RelativeLayout; |
|
|
|
import android.widget.RelativeLayout; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.TextView.OnEditorActionListener; |
|
|
|
import android.widget.TextView.OnEditorActionListener; |
|
|
|
import android.widget.VideoView; |
|
|
|
import android.widget.VideoView; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.squareup.otto.Subscribe; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
import java.io.File; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileNotFoundException; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.FileOutputStream; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.IOException; |
|
|
|
import java.io.InputStream; |
|
|
|
|
|
|
|
import java.net.HttpURLConnection; |
|
|
|
|
|
|
|
import java.net.URI; |
|
|
|
import java.net.URI; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URISyntaxException; |
|
|
|
import java.net.URL; |
|
|
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.ArrayList; |
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
import acr.browser.lightning.R; |
|
|
|
import acr.browser.lightning.R; |
|
|
|
|
|
|
|
import acr.browser.lightning.bus.BookmarkEvents; |
|
|
|
|
|
|
|
import acr.browser.lightning.bus.BrowserEvents; |
|
|
|
|
|
|
|
import acr.browser.lightning.bus.BusProvider; |
|
|
|
import acr.browser.lightning.constant.BookmarkPage; |
|
|
|
import acr.browser.lightning.constant.BookmarkPage; |
|
|
|
import acr.browser.lightning.constant.Constants; |
|
|
|
import acr.browser.lightning.constant.Constants; |
|
|
|
import acr.browser.lightning.constant.HistoryPage; |
|
|
|
import acr.browser.lightning.constant.HistoryPage; |
|
|
@ -133,9 +131,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
private DrawerLayout mDrawerLayout; |
|
|
|
private DrawerLayout mDrawerLayout; |
|
|
|
private FrameLayout mBrowserFrame; |
|
|
|
private FrameLayout mBrowserFrame; |
|
|
|
private FullscreenHolder mFullscreenContainer; |
|
|
|
private FullscreenHolder mFullscreenContainer; |
|
|
|
private ListView mDrawerListRight; |
|
|
|
|
|
|
|
private RecyclerView mDrawerListLeft; |
|
|
|
private RecyclerView mDrawerListLeft; |
|
|
|
private LinearLayout mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout; |
|
|
|
private ViewGroup mDrawerLeft, mDrawerRight, mUiLayout, mToolbarLayout; |
|
|
|
private RelativeLayout mSearchBar; |
|
|
|
private RelativeLayout mSearchBar; |
|
|
|
|
|
|
|
|
|
|
|
// List
|
|
|
|
// List
|
|
|
@ -147,12 +144,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
// Views
|
|
|
|
// Views
|
|
|
|
private AnimatedProgressBar mProgressBar; |
|
|
|
private AnimatedProgressBar mProgressBar; |
|
|
|
private AutoCompleteTextView mSearch; |
|
|
|
private AutoCompleteTextView mSearch; |
|
|
|
private ImageView mArrowImage, mBookmarkTitleImage, mBookmarkImage; |
|
|
|
private ImageView mArrowImage; |
|
|
|
private VideoView mVideoView; |
|
|
|
private VideoView mVideoView; |
|
|
|
private View mCustomView, mVideoProgressView; |
|
|
|
private View mCustomView, mVideoProgressView; |
|
|
|
|
|
|
|
|
|
|
|
// Adapter
|
|
|
|
// Adapter
|
|
|
|
private BookmarkViewAdapter mBookmarkAdapter; |
|
|
|
|
|
|
|
private LightningViewAdapter mTabAdapter; |
|
|
|
private LightningViewAdapter mTabAdapter; |
|
|
|
private SearchAdapter mSearchAdapter; |
|
|
|
private SearchAdapter mSearchAdapter; |
|
|
|
|
|
|
|
|
|
|
@ -180,7 +176,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
private PreferenceManager mPreferences; |
|
|
|
private PreferenceManager mPreferences; |
|
|
|
|
|
|
|
|
|
|
|
// Image
|
|
|
|
// Image
|
|
|
|
private Bitmap mDefaultVideoPoster, mWebpageBitmap, mFolderBitmap; |
|
|
|
private Bitmap mDefaultVideoPoster, mWebpageBitmap; |
|
|
|
private final ColorDrawable mBackground = new ColorDrawable(); |
|
|
|
private final ColorDrawable mBackground = new ColorDrawable(); |
|
|
|
private Drawable mDeleteIcon, mRefreshIcon, mSearchIcon, mIcon; |
|
|
|
private Drawable mDeleteIcon, mRefreshIcon, mSearchIcon, mIcon; |
|
|
|
private DrawerArrowDrawable mArrowDrawable; |
|
|
|
private DrawerArrowDrawable mArrowDrawable; |
|
|
@ -196,7 +192,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams( |
|
|
|
private static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams( |
|
|
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
|
|
|
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); |
|
|
|
|
|
|
|
|
|
|
|
abstract boolean isIncognito(); |
|
|
|
public abstract boolean isIncognito(); |
|
|
|
|
|
|
|
|
|
|
|
abstract void initializeTabs(); |
|
|
|
abstract void initializeTabs(); |
|
|
|
|
|
|
|
|
|
|
@ -241,11 +237,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
// Drawer stutters otherwise
|
|
|
|
// Drawer stutters otherwise
|
|
|
|
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
|
|
|
mDrawerLeft.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
|
|
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
|
|
|
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); |
|
|
|
mDrawerRight = (LinearLayout) findViewById(R.id.right_drawer); |
|
|
|
mDrawerRight = (ViewGroup) findViewById(R.id.right_drawer); |
|
|
|
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
|
|
|
mDrawerRight.setLayerType(View.LAYER_TYPE_HARDWARE, null); |
|
|
|
mDrawerListRight = (ListView) findViewById(R.id.right_drawer_list); |
|
|
|
|
|
|
|
mBookmarkTitleImage = (ImageView) findViewById(R.id.starIcon); |
|
|
|
|
|
|
|
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); |
|
|
|
|
|
|
|
ImageView tabTitleImage = (ImageView) findViewById(R.id.plusIcon); |
|
|
|
ImageView tabTitleImage = (ImageView) findViewById(R.id.plusIcon); |
|
|
|
tabTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); |
|
|
|
tabTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); |
|
|
|
|
|
|
|
|
|
|
@ -257,7 +250,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
mDrawerLayout.setDrawerListener(new DrawerLocker()); |
|
|
|
mDrawerLayout.setDrawerListener(new DrawerLocker()); |
|
|
|
|
|
|
|
|
|
|
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme); |
|
|
|
mWebpageBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_webpage, mDarkTheme); |
|
|
|
mFolderBitmap = ThemeUtils.getThemedBitmap(this, R.drawable.ic_folder, mDarkTheme); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mHomepage = mPreferences.getHomepage(); |
|
|
|
mHomepage = mPreferences.getHomepage(); |
|
|
|
|
|
|
|
|
|
|
@ -283,11 +275,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mDrawerListLeft.setAdapter(mTabAdapter); |
|
|
|
mDrawerListLeft.setAdapter(mTabAdapter); |
|
|
|
// mDrawerListLeft.setOnItemClickListener(new DrawerItemClickListener());
|
|
|
|
|
|
|
|
// mDrawerListLeft.setOnItemLongClickListener(new DrawerItemLongClickListener());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDrawerListRight.setOnItemClickListener(new BookmarkItemClickListener()); |
|
|
|
|
|
|
|
mDrawerListRight.setOnItemLongClickListener(new BookmarkItemLongClickListener()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); |
|
|
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); |
|
|
|
|
|
|
|
|
|
|
@ -324,12 +311,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
|
|
|
|
|
|
|
|
setupFrameLayoutButton(R.id.action_back, R.id.icon_back); |
|
|
|
setupFrameLayoutButton(R.id.action_back, R.id.icon_back); |
|
|
|
setupFrameLayoutButton(R.id.action_forward, R.id.icon_forward); |
|
|
|
setupFrameLayoutButton(R.id.action_forward, R.id.icon_forward); |
|
|
|
setupFrameLayoutButton(R.id.action_add_bookmark, R.id.icon_star); |
|
|
|
|
|
|
|
setupFrameLayoutButton(R.id.action_toggle_desktop, R.id.icon_desktop); |
|
|
|
setupFrameLayoutButton(R.id.action_toggle_desktop, R.id.icon_desktop); |
|
|
|
setupFrameLayoutButton(R.id.action_reading, R.id.icon_reading); |
|
|
|
setupFrameLayoutButton(R.id.action_reading, R.id.icon_reading); |
|
|
|
|
|
|
|
|
|
|
|
mBookmarkImage = (ImageView) findViewById(R.id.icon_star); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create the search EditText in the ToolBar
|
|
|
|
// create the search EditText in the ToolBar
|
|
|
|
mSearch = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.search); |
|
|
|
mSearch = (AutoCompleteTextView) actionBar.getCustomView().findViewById(R.id.search); |
|
|
|
mUntitledTitle = getString(R.string.untitled); |
|
|
|
mUntitledTitle = getString(R.string.untitled); |
|
|
@ -358,38 +342,11 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
mBookmarkManager = BookmarkManager.getInstance(mActivity.getApplicationContext()); |
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); |
|
|
|
|
|
|
|
if (mBookmarkList.isEmpty() && mPreferences.getDefaultBookmarks()) { |
|
|
|
|
|
|
|
for (String[] array : BookmarkManager.DEFAULT_BOOKMARKS) { |
|
|
|
|
|
|
|
HistoryItem bookmark = new HistoryItem(array[0], array[1]); |
|
|
|
|
|
|
|
if (mBookmarkManager.addBookmark(bookmark)) { |
|
|
|
|
|
|
|
mBookmarkList.add(bookmark); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
Collections.sort(mBookmarkList, new BookmarkManager.SortIgnoreCase()); |
|
|
|
|
|
|
|
mPreferences.setDefaultBookmarks(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
mBookmarkAdapter = new BookmarkViewAdapter(mActivity, R.layout.bookmark_list_item, |
|
|
|
|
|
|
|
mBookmarkList); |
|
|
|
|
|
|
|
mDrawerListRight.setAdapter(mBookmarkAdapter); |
|
|
|
|
|
|
|
initializeSearchSuggestions(mSearch); |
|
|
|
initializeSearchSuggestions(mSearch); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
}).run(); |
|
|
|
}).run(); |
|
|
|
|
|
|
|
|
|
|
|
View view = findViewById(R.id.bookmark_back_button); |
|
|
|
|
|
|
|
view.setOnClickListener(new OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(View v) { |
|
|
|
|
|
|
|
if (mBookmarkManager == null) |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
if (!mBookmarkManager.isRootFolder()) { |
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END); |
|
|
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_right_shadow, GravityCompat.END); |
|
|
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START); |
|
|
|
mDrawerLayout.setDrawerShadow(R.drawable.drawer_left_shadow, GravityCompat.START); |
|
|
|
|
|
|
|
|
|
|
@ -811,7 +768,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_add_bookmark: |
|
|
|
case R.id.action_add_bookmark: |
|
|
|
if (mCurrentView != null && !mCurrentView.getUrl().startsWith(Constants.FILE)) { |
|
|
|
if (mCurrentView != null && !mCurrentView.getUrl().startsWith(Constants.FILE)) { |
|
|
|
addBookmark(mCurrentView.getTitle(), mCurrentView.getUrl()); |
|
|
|
BusProvider.getInstance() |
|
|
|
|
|
|
|
.post(new BrowserEvents.AddBookmark(mCurrentView.getTitle(), |
|
|
|
|
|
|
|
mCurrentView.getUrl())); |
|
|
|
} |
|
|
|
} |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
case R.id.action_find: |
|
|
|
case R.id.action_find: |
|
|
@ -827,75 +786,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* refreshes the underlying list of the Bookmark adapter since the bookmark |
|
|
|
|
|
|
|
* adapter doesn't always change when notifyDataChanged gets called. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private void notifyBookmarkDataSetChanged() { |
|
|
|
|
|
|
|
if (mBookmarkAdapter != null) |
|
|
|
|
|
|
|
mBookmarkAdapter.notifyDataSetChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void addBookmark(String title, String url) { |
|
|
|
|
|
|
|
HistoryItem bookmark = new HistoryItem(url, title); |
|
|
|
|
|
|
|
if (mBookmarkManager.addBookmark(bookmark)) { |
|
|
|
|
|
|
|
mBookmarkList.add(bookmark); |
|
|
|
|
|
|
|
Collections.sort(mBookmarkList, new BookmarkManager.SortIgnoreCase()); |
|
|
|
|
|
|
|
notifyBookmarkDataSetChanged(); |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
updateBookmarkIndicator(mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void setBookmarkDataSet(List<HistoryItem> items, boolean animate) { |
|
|
|
|
|
|
|
mBookmarkList.clear(); |
|
|
|
|
|
|
|
mBookmarkList.addAll(items); |
|
|
|
|
|
|
|
notifyBookmarkDataSetChanged(); |
|
|
|
|
|
|
|
final int resource; |
|
|
|
|
|
|
|
if (mBookmarkManager.isRootFolder()) |
|
|
|
|
|
|
|
resource = R.drawable.ic_action_star; |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
resource = R.drawable.ic_action_back; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Animation startRotation = new Animation() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void applyTransformation(float interpolatedTime, Transformation t) { |
|
|
|
|
|
|
|
mBookmarkTitleImage.setRotationY(90 * interpolatedTime); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
final Animation finishRotation = new Animation() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
protected void applyTransformation(float interpolatedTime, Transformation t) { |
|
|
|
|
|
|
|
mBookmarkTitleImage.setRotationY((-90) + (90 * interpolatedTime)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
startRotation.setAnimationListener(new AnimationListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAnimationStart(Animation animation) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAnimationEnd(Animation animation) { |
|
|
|
|
|
|
|
mBookmarkTitleImage.setImageResource(resource); |
|
|
|
|
|
|
|
mBookmarkTitleImage.startAnimation(finishRotation); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onAnimationRepeat(Animation animation) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
startRotation.setInterpolator(new AccelerateInterpolator()); |
|
|
|
|
|
|
|
finishRotation.setInterpolator(new DecelerateInterpolator()); |
|
|
|
|
|
|
|
startRotation.setDuration(250); |
|
|
|
|
|
|
|
finishRotation.setDuration(250); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (animate) { |
|
|
|
|
|
|
|
mBookmarkTitleImage.startAnimation(startRotation); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mBookmarkTitleImage.setImageResource(resource); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 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. |
|
|
@ -995,146 +885,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private class BookmarkItemClickListener implements ListView.OnItemClickListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onItemClick(AdapterView<?> parent, View view, int position, long id) { |
|
|
|
|
|
|
|
if (mBookmarkList.get(position).isFolder()) { |
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(mBookmarkList.get(position).getTitle(), true), true); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mCurrentView != null) { |
|
|
|
|
|
|
|
mCurrentView.loadUrl(mBookmarkList.get(position).getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// keep any jank from happening when the drawer is closed after the
|
|
|
|
|
|
|
|
// URL starts to load
|
|
|
|
|
|
|
|
final Handler handler = new Handler(); |
|
|
|
|
|
|
|
handler.postDelayed(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawer(mDrawerRight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 150); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class BookmarkItemLongClickListener implements ListView.OnItemLongClickListener { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public boolean onItemLongClick(AdapterView<?> arg0, View arg1, final int position, long arg3) { |
|
|
|
|
|
|
|
longPressBookmarkLink(mBookmarkList.get(position).getUrl()); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 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 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param id which id in the list was chosen |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private synchronized void editBookmark(final int id) { |
|
|
|
|
|
|
|
final AlertDialog.Builder editBookmarkDialog = new AlertDialog.Builder(mActivity); |
|
|
|
|
|
|
|
editBookmarkDialog.setTitle(R.string.title_edit_bookmark); |
|
|
|
|
|
|
|
final EditText getTitle = new EditText(mActivity); |
|
|
|
|
|
|
|
getTitle.setHint(R.string.hint_title); |
|
|
|
|
|
|
|
getTitle.setText(mBookmarkList.get(id).getTitle()); |
|
|
|
|
|
|
|
getTitle.setSingleLine(); |
|
|
|
|
|
|
|
final EditText getUrl = new EditText(mActivity); |
|
|
|
|
|
|
|
getUrl.setHint(R.string.hint_url); |
|
|
|
|
|
|
|
getUrl.setText(mBookmarkList.get(id).getUrl()); |
|
|
|
|
|
|
|
getUrl.setSingleLine(); |
|
|
|
|
|
|
|
final AutoCompleteTextView getFolder = new AutoCompleteTextView(mActivity); |
|
|
|
|
|
|
|
getFolder.setHint(R.string.folder); |
|
|
|
|
|
|
|
getFolder.setText(mBookmarkList.get(id).getFolder()); |
|
|
|
|
|
|
|
getFolder.setSingleLine(); |
|
|
|
|
|
|
|
List<String> folders = mBookmarkManager.getFolderTitles(); |
|
|
|
|
|
|
|
ArrayAdapter<String> suggestionsAdapter = new ArrayAdapter<>(this, android.R.layout.simple_dropdown_item_1line, folders); |
|
|
|
|
|
|
|
getFolder.setThreshold(1); |
|
|
|
|
|
|
|
getFolder.setAdapter(suggestionsAdapter); |
|
|
|
|
|
|
|
LinearLayout layout = new LinearLayout(mActivity); |
|
|
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL); |
|
|
|
|
|
|
|
int padding = Utils.dpToPx(10); |
|
|
|
|
|
|
|
layout.setPadding(padding, padding, padding, padding); |
|
|
|
|
|
|
|
layout.addView(getTitle); |
|
|
|
|
|
|
|
layout.addView(getUrl); |
|
|
|
|
|
|
|
layout.addView(getFolder); |
|
|
|
|
|
|
|
editBookmarkDialog.setView(layout); |
|
|
|
|
|
|
|
editBookmarkDialog.setPositiveButton(getResources().getString(R.string.action_ok), |
|
|
|
|
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
|
|
HistoryItem item = new HistoryItem(); |
|
|
|
|
|
|
|
String currentFolder = mBookmarkList.get(id).getFolder(); |
|
|
|
|
|
|
|
item.setTitle(getTitle.getText().toString()); |
|
|
|
|
|
|
|
item.setUrl(getUrl.getText().toString()); |
|
|
|
|
|
|
|
item.setUrl(getUrl.getText().toString()); |
|
|
|
|
|
|
|
item.setFolder(getFolder.getText().toString()); |
|
|
|
|
|
|
|
mBookmarkManager.editBookmark(mBookmarkList.get(id), item); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<HistoryItem> list = mBookmarkManager.getBookmarksFromFolder(currentFolder, true); |
|
|
|
|
|
|
|
if (list.isEmpty()) { |
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
setBookmarkDataSet(list, false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE) |
|
|
|
|
|
|
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) { |
|
|
|
|
|
|
|
openBookmarkPage(mWebView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mCurrentView != null) { |
|
|
|
|
|
|
|
updateBookmarkIndicator(mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
editBookmarkDialog.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Show a dialog to rename a folder |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param id the position of the HistoryItem (folder) in the bookmark list |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private synchronized void renameFolder(final int id) { |
|
|
|
|
|
|
|
final AlertDialog.Builder editFolderDialog = new AlertDialog.Builder(mActivity); |
|
|
|
|
|
|
|
editFolderDialog.setTitle(R.string.title_rename_folder); |
|
|
|
|
|
|
|
final EditText getTitle = new EditText(mActivity); |
|
|
|
|
|
|
|
getTitle.setHint(R.string.hint_title); |
|
|
|
|
|
|
|
getTitle.setText(mBookmarkList.get(id).getTitle()); |
|
|
|
|
|
|
|
getTitle.setSingleLine(); |
|
|
|
|
|
|
|
LinearLayout layout = new LinearLayout(mActivity); |
|
|
|
|
|
|
|
layout.setOrientation(LinearLayout.VERTICAL); |
|
|
|
|
|
|
|
int padding = Utils.dpToPx(10); |
|
|
|
|
|
|
|
layout.setPadding(padding, padding, padding, padding); |
|
|
|
|
|
|
|
layout.addView(getTitle); |
|
|
|
|
|
|
|
editFolderDialog.setView(layout); |
|
|
|
|
|
|
|
editFolderDialog.setPositiveButton(getResources().getString(R.string.action_ok), |
|
|
|
|
|
|
|
new DialogInterface.OnClickListener() { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
|
|
String oldTitle = mBookmarkList.get(id).getTitle(); |
|
|
|
|
|
|
|
String newTitle = getTitle.getText().toString(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mBookmarkManager.renameFolder(oldTitle, newTitle); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE) |
|
|
|
|
|
|
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) { |
|
|
|
|
|
|
|
openBookmarkPage(mWebView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mCurrentView != null) { |
|
|
|
|
|
|
|
updateBookmarkIndicator(mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}); |
|
|
|
|
|
|
|
editFolderDialog.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 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 |
|
|
@ -1196,7 +946,9 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
}, 150); |
|
|
|
}, 150); |
|
|
|
|
|
|
|
|
|
|
|
updateBookmarkIndicator(mWebView.getUrl()); |
|
|
|
// Should update the bookmark status in BookmarksFragment
|
|
|
|
|
|
|
|
BusProvider.getInstance() |
|
|
|
|
|
|
|
.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); |
|
|
|
|
|
|
|
|
|
|
|
// new Handler().postDelayed(new Runnable() {
|
|
|
|
// new Handler().postDelayed(new Runnable() {
|
|
|
|
// @Override
|
|
|
|
// @Override
|
|
|
@ -1222,7 +974,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
source = intent.getExtras().getString("SOURCE"); |
|
|
|
source = intent.getExtras().getString("SOURCE"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (num == 1) { |
|
|
|
if (num == 1) { |
|
|
|
mCurrentView.loadUrl(url); |
|
|
|
loadUrlInCurrentView(url); |
|
|
|
} else if (url != null) { |
|
|
|
} else if (url != null) { |
|
|
|
if (url.startsWith(Constants.FILE)) { |
|
|
|
if (url.startsWith(Constants.FILE)) { |
|
|
|
Utils.showSnackbar(this, R.string.message_blocked_local); |
|
|
|
Utils.showSnackbar(this, R.string.message_blocked_local); |
|
|
@ -1233,6 +985,16 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void loadUrlInCurrentView(final String url) { |
|
|
|
|
|
|
|
if (mCurrentView == null) { |
|
|
|
|
|
|
|
// This is a problem, probably an assert will be better than a return
|
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
mCurrentView.loadUrl(url); |
|
|
|
|
|
|
|
BusProvider.getInstance().post(new BrowserEvents.CurrentPageUrl(url)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void closeEmptyTab() { |
|
|
|
public void closeEmptyTab() { |
|
|
|
if (mWebView != null && mWebView.copyBackForwardList().getSize() == 0) { |
|
|
|
if (mWebView != null && mWebView.copyBackForwardList().getSize() == 0) { |
|
|
@ -1405,11 +1167,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) { |
|
|
|
if (mDrawerLayout.isDrawerOpen(mDrawerLeft)) { |
|
|
|
mDrawerLayout.closeDrawer(mDrawerLeft); |
|
|
|
mDrawerLayout.closeDrawer(mDrawerLeft); |
|
|
|
} else if (mDrawerLayout.isDrawerOpen(mDrawerRight)) { |
|
|
|
} else if (mDrawerLayout.isDrawerOpen(mDrawerRight)) { |
|
|
|
if (!mBookmarkManager.isRootFolder()) { |
|
|
|
BusProvider.getInstance() |
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), true); |
|
|
|
.post(new BrowserEvents.UserPressedBack()); |
|
|
|
} else { |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawer(mDrawerRight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (mCurrentView != null) { |
|
|
|
if (mCurrentView != null) { |
|
|
|
Log.d(Constants.TAG, "onBackPressed"); |
|
|
|
Log.d(Constants.TAG, "onBackPressed"); |
|
|
@ -1444,6 +1203,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
} catch (IllegalArgumentException e) { |
|
|
|
e.printStackTrace(); |
|
|
|
e.printStackTrace(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BusProvider.getInstance().unregister(busEventListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void saveOpenTabs() { |
|
|
|
void saveOpenTabs() { |
|
|
@ -1493,7 +1254,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
mCurrentView.onResume(); |
|
|
|
mCurrentView.onResume(); |
|
|
|
} |
|
|
|
} |
|
|
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); |
|
|
|
mHistoryDatabase = HistoryDatabase.getInstance(getApplicationContext()); |
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); |
|
|
|
|
|
|
|
initializePreferences(); |
|
|
|
initializePreferences(); |
|
|
|
for (int n = 0; n < mWebViewList.size(); n++) { |
|
|
|
for (int n = 0; n < mWebViewList.size(); n++) { |
|
|
|
if (mWebViewList.get(n) != null) { |
|
|
|
if (mWebViewList.get(n) != null) { |
|
|
@ -1508,6 +1268,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
IntentFilter filter = new IntentFilter(); |
|
|
|
IntentFilter filter = new IntentFilter(); |
|
|
|
filter.addAction(NETWORK_BROADCAST_ACTION); |
|
|
|
filter.addAction(NETWORK_BROADCAST_ACTION); |
|
|
|
registerReceiver(mNetworkReceiver, filter); |
|
|
|
registerReceiver(mNetworkReceiver, filter); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BusProvider.getInstance().register(busEventListener); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
@ -1522,7 +1284,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
query = query.trim(); |
|
|
|
query = query.trim(); |
|
|
|
mCurrentView.stopLoading(); |
|
|
|
mCurrentView.stopLoading(); |
|
|
|
if (mCurrentView != null) { |
|
|
|
if (mCurrentView != null) { |
|
|
|
mCurrentView.loadUrl(UrlUtils.smartUrlFilter(query, true, searchUrl)); |
|
|
|
loadUrlInCurrentView(UrlUtils.smartUrlFilter(query, true, searchUrl)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1722,163 +1484,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public class BookmarkViewAdapter extends ArrayAdapter<HistoryItem> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final Context context; |
|
|
|
|
|
|
|
List<HistoryItem> data = null; |
|
|
|
|
|
|
|
final int layoutResourceId; |
|
|
|
|
|
|
|
final Bitmap folderIcon; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public BookmarkViewAdapter(Context context, int layoutResourceId, List<HistoryItem> data) { |
|
|
|
|
|
|
|
super(context, layoutResourceId, data); |
|
|
|
|
|
|
|
this.layoutResourceId = layoutResourceId; |
|
|
|
|
|
|
|
this.context = context; |
|
|
|
|
|
|
|
this.data = data; |
|
|
|
|
|
|
|
this.folderIcon = mFolderBitmap; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public View getView(int position, View convertView, ViewGroup parent) { |
|
|
|
|
|
|
|
View row = convertView; |
|
|
|
|
|
|
|
BookmarkViewHolder holder; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (row == null) { |
|
|
|
|
|
|
|
LayoutInflater inflater = ((Activity) context).getLayoutInflater(); |
|
|
|
|
|
|
|
row = inflater.inflate(layoutResourceId, parent, false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
holder = new BookmarkViewHolder(); |
|
|
|
|
|
|
|
holder.txtTitle = (TextView) row.findViewById(R.id.textBookmark); |
|
|
|
|
|
|
|
holder.favicon = (ImageView) row.findViewById(R.id.faviconBookmark); |
|
|
|
|
|
|
|
row.setTag(holder); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
holder = (BookmarkViewHolder) row.getTag(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ViewCompat.jumpDrawablesToCurrentState(row); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
HistoryItem web = data.get(position); |
|
|
|
|
|
|
|
holder.txtTitle.setText(web.getTitle()); |
|
|
|
|
|
|
|
holder.favicon.setImageBitmap(mWebpageBitmap); |
|
|
|
|
|
|
|
if (web.isFolder()) { |
|
|
|
|
|
|
|
holder.favicon.setImageBitmap(this.folderIcon); |
|
|
|
|
|
|
|
} else if (web.getBitmap() == null) { |
|
|
|
|
|
|
|
getImage(holder.favicon, web); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
holder.favicon.setImageBitmap(web.getBitmap()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return row; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class BookmarkViewHolder { |
|
|
|
|
|
|
|
TextView txtTitle; |
|
|
|
|
|
|
|
ImageView favicon; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void getImage(ImageView image, HistoryItem web) { |
|
|
|
|
|
|
|
new DownloadImageTask(image, web).execute(web.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class DownloadImageTask extends AsyncTask<String, Void, Bitmap> { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
final ImageView bmImage; |
|
|
|
|
|
|
|
final HistoryItem mWeb; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public DownloadImageTask(ImageView bmImage, HistoryItem web) { |
|
|
|
|
|
|
|
this.bmImage = bmImage; |
|
|
|
|
|
|
|
this.mWeb = web; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Bitmap doInBackground(String... urls) { |
|
|
|
|
|
|
|
String url = urls[0]; |
|
|
|
|
|
|
|
Bitmap mIcon = null; |
|
|
|
|
|
|
|
// unique path for each url that is bookmarked.
|
|
|
|
|
|
|
|
String hash = String.valueOf(Utils.getDomainName(url).hashCode()); |
|
|
|
|
|
|
|
File image = new File(mActivity.getCacheDir(), hash + ".png"); |
|
|
|
|
|
|
|
String urldisplay; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
urldisplay = Utils.getProtocol(url) + getDomainName(url) + "/favicon.ico"; |
|
|
|
|
|
|
|
} catch (URISyntaxException e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
urldisplay = "https://www.google.com/s2/favicons?domain_url=" + url; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// checks to see if the image exists
|
|
|
|
|
|
|
|
if (!image.exists()) { |
|
|
|
|
|
|
|
FileOutputStream fos = null; |
|
|
|
|
|
|
|
InputStream in = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// if not, download it...
|
|
|
|
|
|
|
|
URL urlDownload = new URL(urldisplay); |
|
|
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) urlDownload.openConnection(); |
|
|
|
|
|
|
|
connection.setDoInput(true); |
|
|
|
|
|
|
|
connection.connect(); |
|
|
|
|
|
|
|
in = connection.getInputStream(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (in != null) { |
|
|
|
|
|
|
|
mIcon = BitmapFactory.decodeStream(in); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ...and cache it
|
|
|
|
|
|
|
|
if (mIcon != null) { |
|
|
|
|
|
|
|
fos = new FileOutputStream(image); |
|
|
|
|
|
|
|
mIcon.compress(Bitmap.CompressFormat.PNG, 100, fos); |
|
|
|
|
|
|
|
fos.flush(); |
|
|
|
|
|
|
|
Log.d(Constants.TAG, "Downloaded: " + urldisplay); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
Utils.close(in); |
|
|
|
|
|
|
|
Utils.close(fos); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
// if it exists, retrieve it from the cache
|
|
|
|
|
|
|
|
mIcon = BitmapFactory.decodeFile(image.getPath()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mIcon == null) { |
|
|
|
|
|
|
|
InputStream in = null; |
|
|
|
|
|
|
|
FileOutputStream fos = null; |
|
|
|
|
|
|
|
try { |
|
|
|
|
|
|
|
// if not, download it...
|
|
|
|
|
|
|
|
URL urlDownload = new URL("https://www.google.com/s2/favicons?domain_url=" |
|
|
|
|
|
|
|
+ url); |
|
|
|
|
|
|
|
HttpURLConnection connection = (HttpURLConnection) urlDownload.openConnection(); |
|
|
|
|
|
|
|
connection.setDoInput(true); |
|
|
|
|
|
|
|
connection.connect(); |
|
|
|
|
|
|
|
in = connection.getInputStream(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (in != null) { |
|
|
|
|
|
|
|
mIcon = BitmapFactory.decodeStream(in); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// ...and cache it
|
|
|
|
|
|
|
|
if (mIcon != null) { |
|
|
|
|
|
|
|
fos = new FileOutputStream(image); |
|
|
|
|
|
|
|
mIcon.compress(Bitmap.CompressFormat.PNG, 100, fos); |
|
|
|
|
|
|
|
fos.flush(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
|
|
e.printStackTrace(); |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
Utils.close(in); |
|
|
|
|
|
|
|
Utils.close(fos); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mIcon == null) { |
|
|
|
|
|
|
|
return mWebpageBitmap; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
return mIcon; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void onPostExecute(Bitmap result) { |
|
|
|
|
|
|
|
Bitmap fav = Utils.padFavicon(result); |
|
|
|
|
|
|
|
bmImage.setImageBitmap(fav); |
|
|
|
|
|
|
|
mWeb.setBitmap(fav); |
|
|
|
|
|
|
|
notifyBookmarkDataSetChanged(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static String getDomainName(String url) throws URISyntaxException { |
|
|
|
private static String getDomainName(String url) throws URISyntaxException { |
|
|
|
URI uri = new URI(url); |
|
|
|
URI uri = new URI(url); |
|
|
|
String domain = uri.getHost(); |
|
|
|
String domain = uri.getHost(); |
|
|
@ -1893,6 +1498,8 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
if (url == null || mSearch == null || mSearch.hasFocus()) { |
|
|
|
if (url == null || mSearch == null || mSearch.hasFocus()) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
BusProvider.getInstance() |
|
|
|
|
|
|
|
.post(new BrowserEvents.CurrentPageUrl(url)); |
|
|
|
if (shortUrl && !url.startsWith(Constants.FILE)) { |
|
|
|
if (shortUrl && !url.startsWith(Constants.FILE)) { |
|
|
|
switch (mPreferences.getUrlBoxContentChoice()) { |
|
|
|
switch (mPreferences.getUrlBoxContentChoice()) { |
|
|
|
case 0: // Default, show only the domain
|
|
|
|
case 0: // Default, show only the domain
|
|
|
@ -2006,7 +1613,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void run() { |
|
|
|
public void run() { |
|
|
|
mCurrentView.loadUrl(HistoryPage.getHistoryPage(mActivity)); |
|
|
|
loadUrlInCurrentView(HistoryPage.getHistoryPage(mActivity)); |
|
|
|
mSearch.setText(""); |
|
|
|
mSearch.setText(""); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2494,12 +2101,13 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
longPressHistoryLink(newUrl); |
|
|
|
longPressHistoryLink(newUrl); |
|
|
|
} |
|
|
|
} |
|
|
|
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) { |
|
|
|
} else if (currentUrl.endsWith(BookmarkPage.FILENAME)) { |
|
|
|
|
|
|
|
/* TODO Wtf is this? |
|
|
|
if (url != null) { |
|
|
|
if (url != null) { |
|
|
|
longPressBookmarkLink(url); |
|
|
|
longPressBookmarkLink(url); |
|
|
|
} else if (result != null && result.getExtra() != null) { |
|
|
|
} else if (result != null && result.getExtra() != null) { |
|
|
|
final String newUrl = result.getExtra(); |
|
|
|
final String newUrl = result.getExtra(); |
|
|
|
longPressBookmarkLink(newUrl); |
|
|
|
longPressBookmarkLink(newUrl); |
|
|
|
} |
|
|
|
} */ |
|
|
|
} |
|
|
|
} |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
if (url != null) { |
|
|
|
if (url != null) { |
|
|
@ -2523,103 +2131,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void longPressFolder(String url) { |
|
|
|
|
|
|
|
String title; |
|
|
|
|
|
|
|
if (url.startsWith(Constants.FILE)) { |
|
|
|
|
|
|
|
// We are getting the title from the url
|
|
|
|
|
|
|
|
// Strip '-bookmarks.html' from the end of the url
|
|
|
|
|
|
|
|
title = url.substring(0, url.length() - BookmarkPage.FILENAME.length() - 1); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Strip the beginning of the url off and leave only the title
|
|
|
|
|
|
|
|
title = title.substring(Constants.FILE.length() + mActivity.getFilesDir().toString().length() + 1); |
|
|
|
|
|
|
|
} else if (url.startsWith(Constants.FOLDER)) { |
|
|
|
|
|
|
|
title = url.substring(Constants.FOLDER.length()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
title = url; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, Constants.FOLDER + title); |
|
|
|
|
|
|
|
if (position == -1) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
|
|
switch (which) { |
|
|
|
|
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
|
|
|
|
renameFolder(position); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
|
|
|
|
mBookmarkManager.deleteFolder(mBookmarkList.get(position).getTitle()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setBookmarkDataSet(mBookmarkManager.getBookmarksFromFolder(null, true), false); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (mCurrentView != null && mCurrentView.getUrl().startsWith(Constants.FILE) |
|
|
|
|
|
|
|
&& mCurrentView.getUrl().endsWith(BookmarkPage.FILENAME)) { |
|
|
|
|
|
|
|
openBookmarkPage(mWebView); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (mCurrentView != null) { |
|
|
|
|
|
|
|
updateBookmarkIndicator(mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); |
|
|
|
|
|
|
|
builder.setTitle(R.string.action_folder) |
|
|
|
|
|
|
|
.setMessage(R.string.dialog_folder) |
|
|
|
|
|
|
|
.setCancelable(true) |
|
|
|
|
|
|
|
.setPositiveButton(R.string.action_rename, dialogClickListener) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.action_delete, dialogClickListener) |
|
|
|
|
|
|
|
.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void longPressBookmarkLink(final String url) { |
|
|
|
|
|
|
|
if (url.startsWith(Constants.FILE) || url.startsWith(Constants.FOLDER)) { |
|
|
|
|
|
|
|
longPressFolder(url); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
final int position = BookmarkManager.getIndexOfBookmark(mBookmarkList, url); |
|
|
|
|
|
|
|
if (position == -1) { |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void onClick(DialogInterface dialog, int which) { |
|
|
|
|
|
|
|
switch (which) { |
|
|
|
|
|
|
|
case DialogInterface.BUTTON_POSITIVE: |
|
|
|
|
|
|
|
newTab(mBookmarkList.get(position).getUrl(), false); |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawers(); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
|
|
|
|
if (mBookmarkManager.deleteBookmark(mBookmarkList.get(position))) { |
|
|
|
|
|
|
|
mBookmarkList.remove(position); |
|
|
|
|
|
|
|
notifyBookmarkDataSetChanged(); |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
openBookmarks(); |
|
|
|
|
|
|
|
if (mCurrentView != null) { |
|
|
|
|
|
|
|
updateBookmarkIndicator(mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
|
|
|
|
editBookmark(position); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); |
|
|
|
|
|
|
|
builder.setTitle(R.string.action_bookmarks) |
|
|
|
|
|
|
|
.setMessage(R.string.dialog_bookmark) |
|
|
|
|
|
|
|
.setCancelable(true) |
|
|
|
|
|
|
|
.setPositiveButton(R.string.action_new_tab, dialogClickListener) |
|
|
|
|
|
|
|
.setNegativeButton(R.string.action_delete, dialogClickListener) |
|
|
|
|
|
|
|
.setNeutralButton(R.string.action_edit, dialogClickListener) |
|
|
|
|
|
|
|
.show(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void longPressHistoryLink(final String url) { |
|
|
|
private void longPressHistoryLink(final String url) { |
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
DialogInterface.OnClickListener dialogClickListener = new DialogInterface.OnClickListener() { |
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -2637,7 +2148,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
if (mCurrentView != null) { |
|
|
|
if (mCurrentView != null) { |
|
|
|
mCurrentView.loadUrl(url); |
|
|
|
loadUrlInCurrentView(url); |
|
|
|
} |
|
|
|
} |
|
|
|
break; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
@ -2664,7 +2175,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
mCurrentView.loadUrl(url); |
|
|
|
loadUrlInCurrentView(url); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
@ -2697,7 +2208,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
case DialogInterface.BUTTON_NEGATIVE: |
|
|
|
mCurrentView.loadUrl(url); |
|
|
|
loadUrlInCurrentView(url); |
|
|
|
break; |
|
|
|
break; |
|
|
|
|
|
|
|
|
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
|
case DialogInterface.BUTTON_NEUTRAL: |
|
|
@ -2758,17 +2269,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void updateBookmarkIndicator(String url) { |
|
|
|
|
|
|
|
if (url == null || !mBookmarkManager.isBookmark(url)) { |
|
|
|
|
|
|
|
mBookmarkImage.setImageResource(R.drawable.ic_action_star); |
|
|
|
|
|
|
|
mBookmarkImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
mBookmarkImage.setImageResource(R.drawable.ic_bookmark); |
|
|
|
|
|
|
|
mBookmarkImage.setColorFilter(ThemeUtils.getAccentColor(this), PorterDuff.Mode.SRC_IN); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
public void onClick(View v) { |
|
|
|
switch (v.getId()) { |
|
|
|
switch (v.getId()) { |
|
|
@ -2820,11 +2320,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
mCurrentView.reload(); |
|
|
|
mCurrentView.reload(); |
|
|
|
closeDrawers(); |
|
|
|
closeDrawers(); |
|
|
|
break; |
|
|
|
break; |
|
|
|
case R.id.action_add_bookmark: |
|
|
|
|
|
|
|
if (mCurrentView != null && !mCurrentView.getUrl().startsWith(Constants.FILE)) { |
|
|
|
|
|
|
|
addBookmark(mCurrentView.getTitle(), mCurrentView.getUrl()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2870,4 +2365,84 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements |
|
|
|
PermissionsManager.getInstance().notifyPermissionsChange(permissions); |
|
|
|
PermissionsManager.getInstance().notifyPermissionsChange(permissions); |
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private final Object busEventListener = new Object() { |
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Load the given bookmark in the current tab, used by the the |
|
|
|
|
|
|
|
* {@link acr.browser.lightning.fragment.BookmarksFragment} |
|
|
|
|
|
|
|
* @param event The event as it comes from the bus |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void loadBookmarkInCurrentTab(final BookmarkEvents.Clicked event) { |
|
|
|
|
|
|
|
loadUrlInCurrentView(event.bookmark.getUrl()); |
|
|
|
|
|
|
|
// keep any jank from happening when the drawer is closed after the
|
|
|
|
|
|
|
|
// URL starts to load
|
|
|
|
|
|
|
|
final Handler handler = new Handler(); |
|
|
|
|
|
|
|
handler.postDelayed(new Runnable() { |
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public void run() { |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawer(mDrawerRight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, 150); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Load the given bookmark in a new tab, used by the the |
|
|
|
|
|
|
|
* {@link acr.browser.lightning.fragment.BookmarksFragment} |
|
|
|
|
|
|
|
* @param event The event as it comes from the bus |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void loadBookmarkInNewTab(final BookmarkEvents.AsNewTab event) { |
|
|
|
|
|
|
|
newTab(event.bookmark.getUrl(), true); |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawers(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* When receive a {@link acr.browser.lightning.bus.BookmarkEvents.WantToBookmarkCurrentPage} |
|
|
|
|
|
|
|
* message this receiver answer firing the |
|
|
|
|
|
|
|
* {@link acr.browser.lightning.bus.BrowserEvents.AddBookmark} message |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param event basically a marker |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void bookmarkCurrentPage(final BookmarkEvents.WantToBookmarkCurrentPage event) { |
|
|
|
|
|
|
|
BusProvider.getInstance() |
|
|
|
|
|
|
|
.post(new BrowserEvents |
|
|
|
|
|
|
|
.AddBookmark(mCurrentView.getTitle(), mCurrentView.getUrl())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* This message is received when a bookmark was added by the |
|
|
|
|
|
|
|
* {@link acr.browser.lightning.fragment.BookmarksFragment} |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param event a marker |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void bookmarkAdded(final BookmarkEvents.Added event) { |
|
|
|
|
|
|
|
mSearchAdapter.refreshBookmarks(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Notify the browser that a bookmark was deleted |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param event |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void bookmarkDeleted(final BookmarkEvents.Deleted event) { |
|
|
|
|
|
|
|
BusProvider.getInstance() |
|
|
|
|
|
|
|
.post(new BrowserEvents.CurrentPageUrl(mCurrentView.getUrl())); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* The {@link acr.browser.lightning.fragment.BookmarksFragment} send this message on reply |
|
|
|
|
|
|
|
* to {@link acr.browser.lightning.bus.BrowserEvents.UserPressedBack} message if the |
|
|
|
|
|
|
|
* fragement is showing the boomarks root folder. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* @param event a marker |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
@Subscribe |
|
|
|
|
|
|
|
public void closeBookmarks(final BookmarkEvents.CloseBookmarks event) { |
|
|
|
|
|
|
|
mDrawerLayout.closeDrawer(mDrawerRight); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|