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. 66
      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; @@ -11,6 +11,7 @@ import android.animation.ValueAnimator.AnimatorUpdateListener;
import android.app.Activity;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
@ -32,6 +33,7 @@ import android.provider.MediaStore; @@ -32,6 +33,7 @@ import android.provider.MediaStore;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
@ -104,6 +106,7 @@ import acr.browser.lightning.controller.BrowserController; @@ -104,6 +106,7 @@ import acr.browser.lightning.controller.BrowserController;
import acr.browser.lightning.database.BookmarkManager;
import acr.browser.lightning.database.HistoryDatabase;
import acr.browser.lightning.dialog.LightningDialogBuilder;
import acr.browser.lightning.fragment.BookmarksFragment;
import acr.browser.lightning.fragment.TabsFragment;
import acr.browser.lightning.object.SearchAdapter;
import acr.browser.lightning.preference.PreferenceManager;
@ -267,13 +270,21 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -267,13 +270,21 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
final TabsFragment tabsFragment = new TabsFragment();
final int containerId = mShowTabsInDrawer ? R.id.left_drawer : R.id.tabs_toolbar_container;
final Bundle arguments = new Bundle();
arguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
arguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
tabsFragment.setArguments(arguments);
getSupportFragmentManager()
final Bundle tabsFragmentArguments = new Bundle();
tabsFragmentArguments.putBoolean(TabsFragment.IS_INCOGNITO, isIncognito());
tabsFragmentArguments.putBoolean(TabsFragment.VERTICAL_MODE, mShowTabsInDrawer);
tabsFragment.setArguments(tabsFragmentArguments);
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()
.add(containerId, tabsFragment)
.add(R.id.right_drawer, bookmarksFragment)
.commit();
if (mShowTabsInDrawer) {
mToolbarLayout.removeView(findViewById(R.id.tabs_toolbar_container));
@ -981,7 +992,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -981,7 +992,7 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
}
// What?
int current = tabsManager.getPositionForTab(currentTab);
int current = tabsManager.positionOf(currentTab);
if (current < 0) {
return;
}
@ -996,7 +1007,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -996,7 +1007,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
tabsManager.deleteTab(position);
showTab(current - 1);
mEventBus.post(new BrowserEvents.TabsChanged());
tabToDelete.onDestroy();
} else if (tabsManager.size() > position + 1) {
if (current == position) {
showTab(position + 1);
@ -1006,8 +1016,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1006,8 +1016,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
} else {
tabsManager.deleteTab(position);
}
tabToDelete.onDestroy();
} else if (tabsManager.size() > 1) {
if (current == position) {
showTab(position - 1);
@ -1016,8 +1024,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1016,8 +1024,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
mEventBus.post(new BrowserEvents.TabsChanged());
} else {
}
tabToDelete.onDestroy();
} else {
if (currentTab.getUrl().startsWith(Constants.FILE) || currentTab.getUrl().equals(mHomepage)) {
closeActivity();
@ -1025,7 +1031,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -1025,7 +1031,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
tabsManager.deleteTab(position);
performExitCleanUp();
tabToDelete.pauseTimers();
tabToDelete.onDestroy();
mEventBus.post(new BrowserEvents.TabsChanged());
finish();
}
@ -1626,32 +1631,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements @@ -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.
* 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 { @@ -158,13 +158,11 @@ public class TabsManager {
return null;
}
final LightningView tab = mWebViewList.remove(position);
// TODO This should not be done outside this call
// tab.onDestroy();
tab.onDestroy();
return tab;
}
/**
* TODO I think it should be removed
* Return the position of the given tab
* @param tab
* @return
@ -187,15 +185,6 @@ public class TabsManager { @@ -187,15 +185,6 @@ public class TabsManager {
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 a {@link WebView} or null

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

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

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

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

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

@ -3,10 +3,8 @@ @@ -3,10 +3,8 @@
*/
package acr.browser.lightning.download;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.ActivityNotFoundException;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@ -19,14 +17,17 @@ import android.util.Log; @@ -19,14 +17,17 @@ import android.util.Log;
import android.webkit.CookieManager;
import android.webkit.URLUtil;
import com.squareup.otto.Bus;
import java.io.File;
import java.io.IOException;
import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R;
import acr.browser.lightning.activity.MainActivity;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.preference.PreferenceManager;
import acr.browser.lightning.utils.Utils;
/**
* Handle download requests
@ -45,13 +46,13 @@ public class DownloadHandler { @@ -45,13 +46,13 @@ public class DownloadHandler {
* Notify the host application a download should be done, or that the data
* should be streamed if a streaming viewer is available.
*
* @param activity Activity requesting the download.
* @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server
* @param context The context in which the download was requested.
* @param url The full url to the content that should be downloaded
* @param userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @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) {
// if we're dealing wih A/V content that's not explicitly marked
// for download, check if it's streamable.
@ -62,18 +63,17 @@ public class DownloadHandler { @@ -62,18 +63,17 @@ public class DownloadHandler {
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse(url), mimetype);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
ResolveInfo info = activity.getPackageManager().resolveActivity(intent,
ResolveInfo info = context.getPackageManager().resolveActivity(intent,
PackageManager.MATCH_DEFAULT_ONLY);
if (info != null) {
ComponentName myName = activity.getComponentName();
// If we resolved to ourselves, we don't want to attempt to
// load the url only to try and download it again.
if (!myName.getPackageName().equals(info.activityInfo.packageName)
|| !myName.getClassName().equals(info.activityInfo.name)) {
if (BuildConfig.APPLICATION_ID.equals(info.activityInfo.packageName)
|| MainActivity.class.getName().equals(info.activityInfo.name)) {
// someone (other than us) knows how to handle this mime
// type with this scheme, don't download.
try {
activity.startActivity(intent);
context.startActivity(intent);
return;
} catch (ActivityNotFoundException ex) {
// Best behavior is to fall back to a download in this
@ -82,8 +82,7 @@ public class DownloadHandler { @@ -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
@ -120,17 +119,17 @@ public class DownloadHandler { @@ -120,17 +119,17 @@ public class DownloadHandler {
* Notify the host application a download should be done, even if there is a
* 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 userAgent User agent of the downloading application.
* @param contentDisposition Content-disposition http header, if present.
* @param mimetype The mimetype of the content reported by the server
*/
/* 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 filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
final Bus eventBus = BrowserApp.getAppComponent().getBus();
final String filename = URLUtil.guessFileName(url, contentDisposition, mimetype);
// Check to see if we have an SDCard
String status = Environment.getExternalStorageState();
@ -140,14 +139,14 @@ public class DownloadHandler { @@ -140,14 +139,14 @@ public class DownloadHandler {
// Check to see if the SDCard is busy, same as the music app
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;
} 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;
}
new AlertDialog.Builder(activity).setTitle(title)
new AlertDialog.Builder(context).setTitle(title)
.setIcon(android.R.drawable.ic_dialog_alert).setMessage(msg)
.setPositiveButton(R.string.action_ok, null).show();
return;
@ -163,7 +162,7 @@ public class DownloadHandler { @@ -163,7 +162,7 @@ public class DownloadHandler {
// This only happens for very bad urls, we want to catch the
// exception here
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;
}
@ -173,7 +172,7 @@ public class DownloadHandler { @@ -173,7 +172,7 @@ public class DownloadHandler {
try {
request = new DownloadManager.Request(uri);
} catch (IllegalArgumentException e) {
Utils.showSnackbar(activity, R.string.cannot_download);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
return;
}
request.setMimeType(mimetype);
@ -195,12 +194,12 @@ public class DownloadHandler { @@ -195,12 +194,12 @@ public class DownloadHandler {
File dir = new File(downloadFolder.getPath());
if (!dir.isDirectory() && !dir.mkdirs()) {
// Cannot make the directory
Utils.showSnackbar(activity, R.string.problem_location_download);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
return;
}
if (!isWriteAccessAvailable(downloadFolder)) {
Utils.showSnackbar(activity, R.string.problem_location_download);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
return;
}
request.setDestinationUri(Uri.parse(Constants.FILE + location + filename));
@ -220,9 +219,9 @@ public class DownloadHandler { @@ -220,9 +219,9 @@ public class DownloadHandler {
}
// 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
new FetchUrlMimeType(activity, request, addressString, cookies, userAgent).start();
new FetchUrlMimeType(context, request, addressString, cookies, userAgent).start();
} else {
final DownloadManager manager = (DownloadManager) activity
final DownloadManager manager = (DownloadManager) context
.getSystemService(Context.DOWNLOAD_SERVICE);
new Thread() {
@Override
@ -232,15 +231,16 @@ public class DownloadHandler { @@ -232,15 +231,16 @@ public class DownloadHandler {
} catch (IllegalArgumentException e) {
// Probably got a bad URL or something
e.printStackTrace();
Utils.showSnackbar(activity, R.string.cannot_download);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.cannot_download));
} catch (SecurityException e) {
// 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
Utils.showSnackbar(activity, R.string.problem_location_download);
eventBus.post(new BrowserEvents.ShowSnackBarMessage(R.string.problem_location_download));
}
}
}.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 @@ @@ -3,18 +3,21 @@
*/
package acr.browser.lightning.download;
import android.app.Activity;
import android.app.DownloadManager;
import android.content.Context;
import android.os.Environment;
import android.webkit.MimeTypeMap;
import android.webkit.URLUtil;
import com.squareup.otto.Bus;
import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import acr.browser.lightning.R;
import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.bus.BrowserEvents;
import acr.browser.lightning.utils.Utils;
/**
@ -27,7 +30,7 @@ import acr.browser.lightning.utils.Utils; @@ -27,7 +30,7 @@ import acr.browser.lightning.utils.Utils;
*/
class FetchUrlMimeType extends Thread {
private final Activity mActivity;
private final Context mContext;
private final DownloadManager.Request mRequest;
@ -37,9 +40,9 @@ class FetchUrlMimeType extends Thread { @@ -37,9 +40,9 @@ class FetchUrlMimeType extends Thread {
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) {
mActivity = activity;
mContext = context;
mRequest = request;
mUri = uri;
mCookies = cookies;
@ -50,6 +53,7 @@ class FetchUrlMimeType extends Thread { @@ -50,6 +53,7 @@ class FetchUrlMimeType extends Thread {
public void run() {
// User agent is likely to be null, though the AndroidHttpClient
// seems ok with that.
final Bus evenBus = BrowserApp.getAppComponent().getBus();
String mimeType = null;
String contentDisposition = null;
HttpURLConnection connection = null;
@ -101,9 +105,9 @@ class FetchUrlMimeType extends Thread { @@ -101,9 +105,9 @@ class FetchUrlMimeType extends Thread {
}
// Start the download
DownloadManager manager = (DownloadManager) mActivity
DownloadManager manager = (DownloadManager) mContext
.getSystemService(Context.DOWNLOAD_SERVICE);
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 @@ @@ -3,7 +3,7 @@
*/
package acr.browser.lightning.download;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.support.v7.app.AlertDialog;
import android.util.Log;
@ -15,10 +15,10 @@ import acr.browser.lightning.constant.Constants; @@ -15,10 +15,10 @@ import acr.browser.lightning.constant.Constants;
public class LightningDownloadListener implements DownloadListener {
private final Activity mActivity;
private final Context mContext;
public LightningDownloadListener(Activity activity) {
mActivity = activity;
public LightningDownloadListener(Context context) {
mContext = context;
}
@Override
@ -30,7 +30,7 @@ public class LightningDownloadListener implements DownloadListener { @@ -30,7 +30,7 @@ public class LightningDownloadListener implements DownloadListener {
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
DownloadHandler.onDownloadStart(mActivity, url, userAgent,
DownloadHandler.onDownloadStart(mContext, url, userAgent,
contentDisposition, mimetype);
break;
@ -40,12 +40,12 @@ public class LightningDownloadListener implements DownloadListener { @@ -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)
.setMessage(mActivity.getResources().getString(R.string.dialog_download))
.setPositiveButton(mActivity.getResources().getString(R.string.action_download),
.setMessage(mContext.getResources().getString(R.string.dialog_download))
.setPositiveButton(mContext.getResources().getString(R.string.action_download),
dialogClickListener)
.setNegativeButton(mActivity.getResources().getString(R.string.action_cancel),
.setNegativeButton(mContext.getResources().getString(R.string.action_cancel),
dialogClickListener).show();
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; @@ -52,6 +52,10 @@ import acr.browser.lightning.utils.ThemeUtils;
*/
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
@Inject
BookmarkManager mBookmarkManager;
@ -83,6 +87,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -83,6 +87,8 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
// Colors
private int mIconColor, mScrollIndex;
private boolean mIsIncognito;
// Init asynchronously the bookmark manager
private final Runnable mInitBookmarkManager = new Runnable() {
@Override
@ -98,6 +104,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -98,6 +104,14 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
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
@ -137,6 +151,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -137,6 +151,7 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
mBookmarksListView.setOnItemClickListener(mItemClickListener);
mBookmarksListView.setOnItemLongClickListener(mItemLongClickListener);
mBookmarkTitleImage = (ImageView) view.findViewById(R.id.starIcon);
mBookmarkTitleImage.setColorFilter(mIconColor, PorterDuff.Mode.SRC_IN);
mBookmarkImage = (ImageView) view.findViewById(R.id.icon_star);
final View backView = view.findViewById(R.id.bookmark_back_button);
backView.setOnClickListener(new View.OnClickListener() {
@ -156,19 +171,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener, @@ -156,19 +171,6 @@ public class BookmarksFragment extends Fragment implements View.OnClickListener,
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
public void 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 @@ -114,7 +114,6 @@ public class TabsFragment extends Fragment implements View.OnClickListener, View
if (mShowInNavigationDrawer) {
view = inflater.inflate(R.layout.tab_drawer, container, 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.action_back, R.id.icon_back);
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; @@ -18,7 +18,7 @@ import java.util.regex.Pattern;
public class IntentUtils {
private final Context mActivity;
private final Activity mActivity;
private static final Pattern ACCEPTED_URI_SCHEMA = Pattern.compile("(?i)"
+ // switch on case insensitive matching
@ -63,11 +63,9 @@ public class IntentUtils { @@ -63,11 +63,9 @@ public class IntentUtils {
return false;
}
try {
// TODO Restore this
// if (mActivity.startActivityIfNeeded(intent, -1)) {
// return true;
// }
mActivity.startActivity(intent);
if (mActivity.startActivityIfNeeded(intent, -1)) {
return true;
}
} catch (ActivityNotFoundException ex) {
ex.printStackTrace();
}

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

@ -3,11 +3,14 @@ package acr.browser.lightning.view; @@ -3,11 +3,14 @@ package acr.browser.lightning.view;
import android.Manifest;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Message;
import android.support.v7.app.AlertDialog;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.webkit.GeolocationPermissions;
import android.webkit.ValueCallback;
@ -170,16 +173,29 @@ class LightningChromeClient extends WebChromeClient { @@ -170,16 +173,29 @@ class LightningChromeClient extends WebChromeClient {
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
public Bitmap getDefaultVideoPoster() {
// TODO Simplify the method can be moved here
return mActivity.getDefaultVideoPoster();
final Resources resources = mActivity.getResources();
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
public View getVideoLoadingProgressView() {
// TODO Simplify the method can be moved here
return mActivity.getVideoLoadingProgressView();
LayoutInflater inflater = LayoutInflater.from(mActivity);
return inflater.inflate(R.layout.video_loading_progress, null);
}
@Override

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

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

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

@ -41,14 +41,8 @@ @@ -41,14 +41,8 @@
android:id="@+id/right_drawer"
android:background="?attr/drawerBackground"
android:layout_width="@dimen/navigation_width"
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:layout_height="match_parent" />
</android.support.v4.widget.DrawerLayout>
</LinearLayout>
Loading…
Cancel
Save