Browse Source

Improving the #296 pull request

master
Stefano Pacifici 9 years ago
parent
commit
a3f3fbd401
  1. 55
      app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java
  2. 13
      app/src/main/java/acr/browser/lightning/activity/TabsManager.java
  3. 4
      app/src/main/java/acr/browser/lightning/controller/BrowserController.java
  4. 2
      app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java
  5. 58
      app/src/main/java/acr/browser/lightning/download/DownloadHandler.java
  6. 16
      app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java
  7. 18
      app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java
  8. 28
      app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java
  9. 1
      app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java
  10. 10
      app/src/main/java/acr/browser/lightning/utils/IntentUtils.java
  11. 24
      app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java
  12. 3
      app/src/main/java/acr/browser/lightning/view/LightningView.java
  13. 10
      app/src/main/res/layout/activity_main.xml

55
app/src/main/java/acr/browser/lightning/activity/BrowserActivity.java

@ -11,6 +11,7 @@ import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity; import android.app.Activity;
import android.content.ClipData; import android.content.ClipData;
import android.content.ClipboardManager; import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
@ -32,6 +33,7 @@ import android.provider.MediaStore;
import android.support.annotation.IdRes; import android.support.annotation.IdRes;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat; import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat; import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout; import android.support.v4.widget.DrawerLayout;
@ -104,6 +106,7 @@ import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.database.BookmarkManager; import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryDatabase; import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.dialog.LightningDialogBuilder; import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.TabsFragment; import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter; import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
@ -267,13 +270,21 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final TabsFragment tabsFragment = new TabsFragment(); final TabsFragment tabsFragment = new TabsFragment();
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container; final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
final Bundle arguments = new Bundle(); final Bundle tabsFragmentArguments = new Bundle();
arguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito()); tabsFragmentArguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
arguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer); tabsFragmentArguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
tabsFragment.setArguments(arguments); tabsFragment.setArguments(tabsFragmentArguments);
getSupportFragmentManager()
final BookmarksFragment bookmarksFragment = new BookmarksFragment();
final Bundle bookmarksFragmentArguments = new Bundle();
bookmarksFragmentArguments.putBoolean(BookmarksFragment.INCOGNITO_MODE, isIncognito());
bookmarksFragment.setArguments(bookmarksFragmentArguments);
final FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager
.beginTransaction() .beginTransaction()
.add(containerId, tabsFragment) .add(containerId, tabsFragment)
.add(R.id.right_drawer, bookmarksFragment)
.commit(); .commit();
if (mShowTabsInDrawer) { if (mShowTabsInDrawer) {
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container)); mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
@ -981,7 +992,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
// What? // What?
int current = tabsManager.getPositionForTab(currentTab); int current = tabsManager.positionOf(currentTab);
if (current < 0) { if (current < 0) {
return; return;
} }
@ -996,7 +1007,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
tabsManager.deleteTab(position); tabsManager.deleteTab(position);
showTab(current - 1); showTab(current - 1);
mEventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
tabToDelete.onDestroy();
} else if (tabsManager.size() > position + 1) { } else if (tabsManager.size() > position + 1) {
if (current == position) { if (current == position) {
showTab(position + 1); showTab(position + 1);
@ -1006,8 +1016,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} else { } else {
tabsManager.deleteTab(position); tabsManager.deleteTab(position);
} }
tabToDelete.onDestroy();
} else if (tabsManager.size() > 1) { } else if (tabsManager.size() > 1) {
if (current == position) { if (current == position) {
showTab(position - 1); showTab(position - 1);
@ -1016,8 +1024,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mEventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
} else { } else {
} }
tabToDelete.onDestroy();
} else { } else {
if (currentTab.getUrl().startsWith(Constants.FILE) || currentTab.getUrl().equals(mHomepage)) { if (currentTab.getUrl().startsWith(Constants.FILE) || currentTab.getUrl().equals(mHomepage)) {
closeActivity(); closeActivity();
@ -1025,7 +1031,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
tabsManager.deleteTab(position); tabsManager.deleteTab(position);
performExitCleanUp(); performExitCleanUp();
tabToDelete.pauseTimers(); tabToDelete.pauseTimers();
tabToDelete.onDestroy();
mEventBus.post(new BrowserEvents.TabsChanged()); mEventBus.post(new BrowserEvents.TabsChanged());
finish(); finish();
} }
@ -1626,32 +1631,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} }
} }
/**
* This interface method is used by the LightningView to obtain an
* image that is displayed as a placeholder on a video until the video
* has initialized and can begin loading.
*
* @return a Bitmap that can be used as a place holder for videos.
*/
@Override
public Bitmap getDefaultVideoPoster() {
return BitmapFactory.decodeResource(getResources(), android.R.drawable.spinner_background);
}
/**
* An interface method so that we can inflate a view to send to
* a LightningView when it needs to display a video and has to
* show a loading dialog. Inflates a progress view and returns it.
*
* @return A view that should be used to display the state
* of a video's loading progress.
*/
@Override
public View getVideoLoadingProgressView() {
LayoutInflater inflater = LayoutInflater.from(this);
return inflater.inflate(R.layout.video_loading_progress, null);
}
/** /**
* This method handles the JavaScript callback to create a new tab. * This method handles the JavaScript callback to create a new tab.
* Basically this handles the event that JavaScript needs to create * Basically this handles the event that JavaScript needs to create

13
app/src/main/java/acr/browser/lightning/activity/TabsManager.java

@ -158,13 +158,11 @@ public class TabsManager {
return null; return null;
} }
final LightningView tab = mWebViewList.remove(position); final LightningView tab = mWebViewList.remove(position);
// TODO This should not be done outside this call tab.onDestroy();
// tab.onDestroy();
return tab; return tab;
} }
/** /**
* TODO I think it should be removed
* Return the position of the given tab * Return the position of the given tab
* @param tab * @param tab
* @return * @return
@ -187,15 +185,6 @@ public class TabsManager {
return builder.toString(); return builder.toString();
} }
/**
* TODO Remove this, temporary workaround
* @param tab
* @return
*/
public int getPositionForTab(final LightningView tab) {
return mWebViewList.indexOf(tab);
}
/** /**
* Return the {@link WebView} associated to the current tab, or null if there is no current tab * Return the {@link WebView} associated to the current tab, or null if there is no current tab
* @return a {@link WebView} or null * @return a {@link WebView} or null

4
app/src/main/java/acr/browser/lightning/controller/BrowserController.java

@ -29,10 +29,6 @@ public interface BrowserController {
void onHideCustomView(); void onHideCustomView();
Bitmap getDefaultVideoPoster();
View getVideoLoadingProgressView();
void onCreateWindow(Message resultMsg); void onCreateWindow(Message resultMsg);
void onCloseWindow(LightningView view); void onCloseWindow(LightningView view);

2
app/src/main/java/acr/browser/lightning/database/HistoryDatabase.java

@ -89,7 +89,7 @@ public class HistoryDatabase extends SQLiteOpenHelper {
} }
private void openIfNecessary() { private void openIfNecessary() {
if (mDatabase == null) { if (isClosed()) {
mDatabase = this.getWritableDatabase(); mDatabase = this.getWritableDatabase();
} }
} }

58
app/src/main/java/acr/browser/lightning/download/DownloadHandler.java

@ -3,10 +3,8 @@
*/ */
package acr.browser.lightning.download; package acr.browser.lightning.download;
import android.app.Activity;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.ActivityNotFoundException; import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
@ -19,14 +17,17 @@ import android.util.Log;
import android.webkit.CookieManager; import android.webkit.CookieManager;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import com.squareup.otto.Bus;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.activity.MainActivity;
import acr.browser.lightning.app.BrowserApp; import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
/** /**
* Handle download requests * Handle download requests
@ -45,13 +46,13 @@ public class DownloadHandler {
* Notify the host application a download should be done, or that the data * Notify the host application a download should be done, or that the data
* should be streamed if a streaming viewer is available. * should be streamed if a streaming viewer is available.
* *
* @param activity Activity requesting the download. * @param context The context in which the download was requested.
* @param url The full url to the content that should be downloaded * @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application. * @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present. * @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server * @param mimetype The mimetype of the content reported by the server
*/ */
public static void onDownloadStart(Activity activity, String url, String userAgent, public static void onDownloadStart(Context context, String url, String userAgent,
String contentDisposition, String mimetype) { String contentDisposition, String mimetype) {
// if we're dealing wih A/V content that's not explicitly marked // if we're dealing wih A/V content that's not explicitly marked
// for download, check if it's streamable. // for download, check if it's streamable.
@ -62,18 +63,17 @@ public class DownloadHandler {
Intent intent = new Intent(Intent.ACTION_VIEW); Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype); intent.setDataAndType(Uri.parse(url), mimetype);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ResolveInfo info = activity.getPackageManager().resolveActivity(intent, ResolveInfo info = context.getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY); PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) { if (info != null) {
ComponentName myName = activity.getComponentName();
// If we resolved to ourselves, we don't want to attempt to // If we resolved to ourselves, we don't want to attempt to
// load the url only to try and download it again. // load the url only to try and download it again.
if (!myName.getPackageName().equals(info.activityInfo.packageName) if (BuildConfig.APPLICATION_ID.equals(info.activityInfo.packageName)
|| !myName.getClassName().equals(info.activityInfo.name)) { || MainActivity.class.getName().equals(info.activityInfo.name)) {
// someone (other than us) knows how to handle this mime // someone (other than us) knows how to handle this mime
// type with this scheme, don't download. // type with this scheme, don't download.
try { try {
activity.startActivity(intent); context.startActivity(intent);
return; return;
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
// Best behavior is to fall back to a download in this // Best behavior is to fall back to a download in this
@ -82,8 +82,7 @@ public class DownloadHandler {
} }
} }
} }
onDownloadStartNoStream(activity, url, userAgent, contentDisposition, mimetype onDownloadStartNoStream(context, url, userAgent, contentDisposition, mimetype);
);
} }
// This is to work around the fact that java.net.URI throws Exceptions // This is to work around the fact that java.net.URI throws Exceptions
@ -120,17 +119,17 @@ public class DownloadHandler {
* Notify the host application a download should be done, even if there is a * Notify the host application a download should be done, even if there is a
* streaming viewer available for thise type. * streaming viewer available for thise type.
* *
* @param activity Activity requesting the download. * @param context The context in which the download is requested.
* @param url The full url to the content that should be downloaded * @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application. * @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present. * @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server * @param mimetype The mimetype of the content reported by the server
*/ */
/* package */ /* package */
private static void onDownloadStartNoStream(final Activity activity, String url, String userAgent, private static void onDownloadStartNoStream(final Context context, String url, String userAgent,
String contentDisposition, String mimetype) { String contentDisposition, String mimetype) {
final Bus eventBus = BrowserApp.getAppComponent().getBus();
String filename = URLUtil.guessFileName(url, contentDisposition, mimetype); final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
// Check to see if we have an SDCard // Check to see if we have an SDCard
String status = Environment.getExternalStorageState(); String status = Environment.getExternalStorageState();
@ -140,14 +139,14 @@ public class DownloadHandler {
// Check to see if the SDCard is busy, same as the music app // Check to see if the SDCard is busy, same as the music app
if (status.equals(Environment.MEDIA_SHARED)) { if (status.equals(Environment.MEDIA_SHARED)) {
msg = activity.getString(R.string.download_sdcard_busy_dlg_msg); msg = context.getString(R.string.download_sdcard_busy_dlg_msg);
title = R.string.download_sdcard_busy_dlg_title; title = R.string.download_sdcard_busy_dlg_title;
} else { } else {
msg = activity.getString(R.string.download_no_sdcard_dlg_msg, filename); msg = context.getString(R.string.download_no_sdcard_dlg_msg, filename);
title = R.string.download_no_sdcard_dlg_title; title = R.string.download_no_sdcard_dlg_title;
} }
new AlertDialog.Builder(activity).setTitle(title) new AlertDialog.Builder(context).setTitle(title)
.setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg) .setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg)
.setPositiveButton(R.string.action_ok, null).show(); .setPositiveButton(R.string.action_ok, null).show();
return; return;
@ -163,7 +162,7 @@ public class DownloadHandler {
// This only happens for very bad urls, we want to catch the // This only happens for very bad urls, we want to catch the
// exception here // exception here
Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e); Log.e(TAG, "Exception while trying to parse url '" + url + '\'', e);
Utils.showSnackbar(activity, R.string.problem_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_download));
return; return;
} }
@ -173,7 +172,7 @@ public class DownloadHandler {
try { try {
request = new DownloadManager.Request(uri); request = new DownloadManager.Request(uri);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
Utils.showSnackbar(activity, R.string.cannot_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
return; return;
} }
request.setMimeType(mimetype); request.setMimeType(mimetype);
@ -195,12 +194,12 @@ public class DownloadHandler {
File dir = new File(downloadFolder.getPath()); File dir = new File(downloadFolder.getPath());
if (!dir.isDirectory() && !dir.mkdirs()) { if (!dir.isDirectory() && !dir.mkdirs()) {
// Cannot make the directory // Cannot make the directory
Utils.showSnackbar(activity, R.string.problem_location_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
return; return;
} }
if (!isWriteAccessAvailable(downloadFolder)) { if (!isWriteAccessAvailable(downloadFolder)) {
Utils.showSnackbar(activity, R.string.problem_location_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
return; return;
} }
request.setDestinationUri(Uri.parse(Constants.FILE + location + filename)); request.setDestinationUri(Uri.parse(Constants.FILE + location + filename));
@ -220,9 +219,9 @@ public class DownloadHandler {
} }
// We must have long pressed on a link or image to download it. We // We must have long pressed on a link or image to download it. We
// are not sure of the mimetype in this case, so do a head request // are not sure of the mimetype in this case, so do a head request
new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start(); new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
} else { } else {
final DownloadManager manager = (DownloadManager) activity final DownloadManager manager = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE); .getSystemService(Context.DOWNLOAD_SERVICE);
new Thread() { new Thread() {
@Override @Override
@ -232,15 +231,16 @@ public class DownloadHandler {
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// Probably got a bad URL or something // Probably got a bad URL or something
e.printStackTrace(); e.printStackTrace();
Utils.showSnackbar(activity, R.string.cannot_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
} catch (SecurityException e) { } catch (SecurityException e) {
// TODO write a download utility that downloads files rather than rely on the system // TODO write a download utility that downloads files rather than rely on the system
// because the system can only handle Environment.getExternal... as a path // because the system can only handle Environment.getExternal... as a path
Utils.showSnackbar(activity, R.string.problem_location_download); eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
} }
} }
}.start(); }.start();
Utils.showSnackbar(activity, activity.getString(R.string.download_pending) + ' ' + filename); eventBus.post(new BrowserEvents.ShowSnackBarMessage(
context.getString(R.string.download_pending) + ' ' + filename));
} }
} }

16
app/src/main/java/acr/browser/lightning/download/FetchUrlMimeType.java

@ -3,18 +3,21 @@
*/ */
package acr.browser.lightning.download; package acr.browser.lightning.download;
import android.app.Activity;
import android.app.DownloadManager; import android.app.DownloadManager;
import android.content.Context; import android.content.Context;
import android.os.Environment; import android.os.Environment;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import android.webkit.URLUtil; import android.webkit.URLUtil;
import com.squareup.otto.Bus;
import java.io.IOException; import java.io.IOException;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import acr.browser.lightning.R; import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
/** /**
@ -27,7 +30,7 @@ import acr.browser.lightning.utils.Utils;
*/ */
class FetchUrlMimeType extends Thread { class FetchUrlMimeType extends Thread {
private final Activity mActivity; private final Context mContext;
private final DownloadManager.Request mRequest; private final DownloadManager.Request mRequest;
@ -37,9 +40,9 @@ class FetchUrlMimeType extends Thread {
private final String mUserAgent; private final String mUserAgent;
public FetchUrlMimeType(Activity activity, DownloadManager.Request request, String uri, public FetchUrlMimeType(Context context, DownloadManager.Request request, String uri,
String cookies, String userAgent) { String cookies, String userAgent) {
mActivity = activity; mContext = context;
mRequest = request; mRequest = request;
mUri = uri; mUri = uri;
mCookies = cookies; mCookies = cookies;
@ -50,6 +53,7 @@ class FetchUrlMimeType extends Thread {
public void run() { public void run() {
// User agent is likely to be null, though the AndroidHttpClient // User agent is likely to be null, though the AndroidHttpClient
// seems ok with that. // seems ok with that.
final Bus evenBus = BrowserApp.getAppComponent().getBus();
String mimeType = null; String mimeType = null;
String contentDisposition = null; String contentDisposition = null;
HttpURLConnection connection = null; HttpURLConnection connection = null;
@ -101,9 +105,9 @@ class FetchUrlMimeType extends Thread {
} }
// Start the download // Start the download
DownloadManager manager = (DownloadManager) mActivity DownloadManager manager = (DownloadManager) mContext
.getSystemService(Context.DOWNLOAD_SERVICE); .getSystemService(Context.DOWNLOAD_SERVICE);
manager.enqueue(mRequest); manager.enqueue(mRequest);
Utils.showSnackbar(mActivity, mActivity.getString(R.string.download_pending) + ' ' + filename); evenBus.post(new BrowserEvents.ShowSnackBarMessage(mContext.getString(R.string.download_pending) + ' ' + filename));
} }
} }

18
app/src/main/java/acr/browser/lightning/download/LightningDownloadListener.java

@ -3,7 +3,7 @@
*/ */
package acr.browser.lightning.download; package acr.browser.lightning.download;
import android.app.Activity; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
@ -15,10 +15,10 @@ import acr.browser.lightning.constant.Constants;
public class LightningDownloadListener implements DownloadListener { public class LightningDownloadListener implements DownloadListener {
private final Activity mActivity; private final Context mContext;
public LightningDownloadListener(Activity activity) { public LightningDownloadListener(Context context) {
mActivity = activity; mContext = context;
} }
@Override @Override
@ -30,7 +30,7 @@ public class LightningDownloadListener implements DownloadListener {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
switch (which) { switch (which) {
case DialogInterface.BUTTON_POSITIVE: case DialogInterface.BUTTON_POSITIVE:
DownloadHandler.onDownloadStart(mActivity, url, userAgent, DownloadHandler.onDownloadStart(mContext, url, userAgent,
contentDisposition, mimetype); contentDisposition, mimetype);
break; break;
@ -40,12 +40,12 @@ public class LightningDownloadListener implements DownloadListener {
} }
}; };
AlertDialog.Builder builder = new AlertDialog.Builder(mActivity); // dialog AlertDialog.Builder builder = new AlertDialog.Builder(mContext); // dialog
builder.setTitle(fileName) builder.setTitle(fileName)
.setMessage(mActivity.getResources().getString(R.string.dialog_download)) .setMessage(mContext.getResources().getString(R.string.dialog_download))
.setPositiveButton(mActivity.getResources().getString(R.string.action_download), .setPositiveButton(mContext.getResources().getString(R.string.action_download),
dialogClickListener) dialogClickListener)
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel), .setNegativeButton(mContext.getResources().getString(R.string.action_cancel),
dialogClickListener).show(); dialogClickListener).show();
Log.i(Constants.TAG, "Downloading" + fileName); Log.i(Constants.TAG, "Downloading" + fileName);

28
app/src/main/java/acr/browser/lightning/fragment/BookmarksFragment.java

@ -52,6 +52,10 @@ import acr.browser.lightning.utils.ThemeUtils;
*/ */
public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener { public class BookmarksFragment extends Fragment implements View.OnClickListener, View.OnLongClickListener {
private final static String TAG = BookmarksFragment.class.getSimpleName();
public final static String INCOGNITO_MODE = TAG + ".INCOGNITO_MODE";
// Managers // Managers
@Inject @Inject
BookmarkManager mBookmarkManager; BookmarkManager mBookmarkManager;
@ -83,6 +87,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// Colors // Colors
private int mIconColor, mScrollIndex; private int mIconColor, mScrollIndex;
private boolean mIsIncognito;
// Init asynchronously the bookmark manager // Init asynchronously the bookmark manager
private final Runnable mInitBookmarkManager = new Runnable() { private final Runnable mInitBookmarkManager = new Runnable() {
@Override @Override
@ -98,6 +104,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
public void onCreate(@Nullable Bundle savedInstanceState) { public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
BrowserApp.getAppComponent().inject(this); BrowserApp.getAppComponent().inject(this);
final Bundle arguments = getArguments();
final Context context = getContext();
mIsIncognito = arguments.getBoolean(INCOGNITO_MODE, false);
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || mIsIncognito;
mWebpageBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_webpage, darkTheme);
mFolderBitmap = ThemeUtils.getThemedBitmap(context, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(context) :
ThemeUtils.getIconLightThemeColor(context);
} }
// Handle bookmark click // Handle bookmark click
@ -137,6 +151,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mBookmarksListView.setOnItemClickListener(mItemClickListener); mBookmarksListView.setOnItemClickListener(mItemClickListener);
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener); mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon); mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star); mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
final View backView = view.findViewById(R.id.bookmark_back_button); final View backView = view.findViewById(R.id.bookmark_back_button);
backView.setOnClickListener(new View.OnClickListener() { backView.setOnClickListener(new View.OnClickListener() {
@ -156,19 +171,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
return view; return view;
} }
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
// TODO remove dependency on BrowserActivity
super.onActivityCreated(savedInstanceState);
final BrowserActivity activity = (BrowserActivity) getActivity();
boolean darkTheme = mPreferenceManager.getUseTheme() != 0 || ((BrowserActivity) activity).isIncognito();
mWebpageBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_webpage, darkTheme);
mFolderBitmap = ThemeUtils.getThemedBitmap(activity, R.drawable.ic_folder, darkTheme);
mIconColor = darkTheme ? ThemeUtils.getIconDarkThemeColor(activity) :
ThemeUtils.getIconLightThemeColor(activity);
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
}
@Override @Override
public void onStart() { public void onStart() {
super.onStart(); super.onStart();

1
app/src/main/java/acr/browser/lightning/fragment/TabsFragment.java

@ -114,7 +114,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
if (mShowInNavigationDrawer) { if (mShowInNavigationDrawer) {
view = inflater.inflate(R.layout.tab_drawer, container, false); view = inflater.inflate(R.layout.tab_drawer, container, false);
layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false); layoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.VERTICAL, false);
// TODO Handle also long press
setupFrameLayoutButton(view, R.id.new_tab_button, R.id.icon_plus); setupFrameLayoutButton(view, R.id.new_tab_button, R.id.icon_plus);
setupFrameLayoutButton(view, R.id.action_back, R.id.icon_back); setupFrameLayoutButton(view, R.id.action_back, R.id.icon_back);
setupFrameLayoutButton(view, R.id.action_forward, R.id.icon_forward); setupFrameLayoutButton(view, R.id.action_forward, R.id.icon_forward);

10
app/src/main/java/acr/browser/lightning/utils/IntentUtils.java

@ -18,7 +18,7 @@ import java.util.regex.Pattern;
public class IntentUtils { public class IntentUtils {
private final Context mActivity; private final Activity mActivity;
private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)" private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching + // switch on case insensitive matching
@ -63,11 +63,9 @@ public class IntentUtils {
return false; return false;
} }
try { try {
// TODO Restore this if (mActivity.startActivityIfNeeded(intent, -1)) {
// if (mActivity.startActivityIfNeeded(intent, -1)) { return true;
// return true; }
// }
mActivity.startActivity(intent);
} catch (ActivityNotFoundException ex) { } catch (ActivityNotFoundException ex) {
ex.printStackTrace(); ex.printStackTrace();
} }

24
app/src/main/java/acr/browser/lightning/view/LightningChromeClient.java

@ -3,11 +3,14 @@ package acr.browser.lightning.view;
import android.Manifest; import android.Manifest;
import android.app.Activity; import android.app.Activity;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri; import android.net.Uri;
import android.os.Message; import android.os.Message;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.util.Log; import android.util.Log;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.webkit.GeolocationPermissions; import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback; import android.webkit.ValueCallback;
@ -170,16 +173,29 @@ class LightningChromeClient extends WebChromeClient {
return true; return true;
} }
/**
* Obtain an image that is displayed as a placeholder on a video until the video has initialized
* and can begin loading.
*
* @return a Bitmap that can be used as a place holder for videos.
*/
@Override @Override
public Bitmap getDefaultVideoPoster() { public Bitmap getDefaultVideoPoster() {
// TODO Simplify the method can be moved here final Resources resources = mActivity.getResources();
return mActivity.getDefaultVideoPoster(); return BitmapFactory.decodeResource(resources, android.R.drawable.spinner_background);
} }
/**
* Inflate a view to send to a LightningView when it needs to display a video and has to
* show a loading dialog. Inflates a progress view and returns it.
*
* @return A view that should be used to display the state
* of a video's loading progress.
*/
@Override @Override
public View getVideoLoadingProgressView() { public View getVideoLoadingProgressView() {
// TODO Simplify the method can be moved here LayoutInflater inflater = LayoutInflater.from(mActivity);
return mActivity.getVideoLoadingProgressView(); return inflater.inflate(R.layout.video_loading_progress, null);
} }
@Override @Override

3
app/src/main/java/acr/browser/lightning/view/LightningView.java

@ -99,7 +99,6 @@ public class LightningView {
mWebView = new WebView(activity); mWebView = new WebView(activity);
mIsIncognitoTab = isIncognito; mIsIncognitoTab = isIncognito;
mTitle = new LightningViewTitle(activity, darkTheme); mTitle = new LightningViewTitle(activity, darkTheme);
// mAdBlock = AdBlock.getInstance(activity.getApplicationContext());
mPermissionsManager = PermissionsManager.getInstance(); mPermissionsManager = PermissionsManager.getInstance();
mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity(); mMaxFling = ViewConfiguration.get(activity).getScaledMaximumFlingVelocity();
@ -195,8 +194,6 @@ public class LightningView {
settings.setDefaultTextEncodingName(mPreferences.getTextEncoding()); settings.setDefaultTextEncodingName(mPreferences.getTextEncoding());
mHomepage = mPreferences.getHomepage(); mHomepage = mPreferences.getHomepage();
// mAdBlock.updatePreference();
setColorMode(mPreferences.getRenderingMode()); setColorMode(mPreferences.getRenderingMode());
if (!mIsIncognitoTab) { if (!mIsIncognitoTab) {

10
app/src/main/res/layout/activity_main.xml

@ -41,14 +41,8 @@
android:id="@+id/right_drawer" android:id="@+id/right_drawer"
android:background="?attr/drawerBackground" android:background="?attr/drawerBackground"
android:layout_width="@dimen/navigation_width" android:layout_width="@dimen/navigation_width"
android:layout_height="match_parent"> android:layout_height="match_parent" />
<fragment
android:id="@+id/bookmark_fragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
class="acr.browser.lightning.fragment.BookmarksFragment" />
</FrameLayout>
<!-- include layout="@layout/bookmark_drawer" / -->
</android.support.v4.widget.DrawerLayout> </android.support.v4.widget.DrawerLayout>
</LinearLayout> </LinearLayout>
Loading…
Cancel
Save