ClickHandler removed, avoid call loop duirng long press on a webview between BrowserActivity and LightningView
This commit is contained in:
parent
030b839aa6
commit
3615018816
@ -117,7 +117,6 @@ import acr.browser.lightning.database.BookmarkManager;
|
|||||||
import acr.browser.lightning.database.HistoryDatabase;
|
import acr.browser.lightning.database.HistoryDatabase;
|
||||||
import acr.browser.lightning.dialog.BookmarksDialogBuilder;
|
import acr.browser.lightning.dialog.BookmarksDialogBuilder;
|
||||||
import acr.browser.lightning.fragment.TabsFragment;
|
import acr.browser.lightning.fragment.TabsFragment;
|
||||||
import acr.browser.lightning.object.ClickHandler;
|
|
||||||
import acr.browser.lightning.object.SearchAdapter;
|
import acr.browser.lightning.object.SearchAdapter;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.receiver.NetworkReceiver;
|
import acr.browser.lightning.receiver.NetworkReceiver;
|
||||||
@ -150,7 +149,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
private SearchAdapter mSearchAdapter;
|
private SearchAdapter mSearchAdapter;
|
||||||
|
|
||||||
// Callback
|
// Callback
|
||||||
private ClickHandler mClickHandler;
|
|
||||||
private CustomViewCallback mCustomViewCallback;
|
private CustomViewCallback mCustomViewCallback;
|
||||||
private ValueCallback<Uri> mUploadMessage;
|
private ValueCallback<Uri> mUploadMessage;
|
||||||
private ValueCallback<Uri[]> mFilePathCallback;
|
private ValueCallback<Uri[]> mFilePathCallback;
|
||||||
@ -240,7 +238,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
|
|
||||||
mActivity = this;
|
mActivity = this;
|
||||||
|
|
||||||
mClickHandler = new ClickHandler(this);
|
|
||||||
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
|
mBrowserFrame = (FrameLayout) findViewById(R.id.content_frame);
|
||||||
mToolbarLayout = (LinearLayout) findViewById(R.id.toolbar_layout);
|
mToolbarLayout = (LinearLayout) findViewById(R.id.toolbar_layout);
|
||||||
// initialize background ColorDrawable
|
// initialize background ColorDrawable
|
||||||
@ -1572,26 +1569,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
mActivity.startActivityForResult(chooserIntent, 1);
|
mActivity.startActivityForResult(chooserIntent, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* handles long presses for the browser, tries to get the
|
|
||||||
* url of the item that was clicked and sends it (it can be null)
|
|
||||||
* to the click handler that does cool stuff with it
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onLongPress() {
|
|
||||||
if (mClickHandler == null) {
|
|
||||||
mClickHandler = new ClickHandler(mActivity);
|
|
||||||
}
|
|
||||||
Message click = mClickHandler.obtainMessage();
|
|
||||||
if (click != null) {
|
|
||||||
click.setTarget(mClickHandler);
|
|
||||||
final WebView currentWebView = tabsManager.getCurrentWebView();
|
|
||||||
if (currentWebView != null) {
|
|
||||||
currentWebView.requestFocusNodeHref(click);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onShowCustomView(View view, CustomViewCallback callback) {
|
public void onShowCustomView(View view, CustomViewCallback callback) {
|
||||||
final LightningView currentTab = tabsManager.getCurrentTab();
|
final LightningView currentTab = tabsManager.getCurrentTab();
|
||||||
@ -1871,58 +1848,6 @@ public abstract class BrowserActivity extends ThemableBrowserActivity implements
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* handles a long click on the page, parameter String url
|
|
||||||
* is the url that should have been obtained from the WebView touch node
|
|
||||||
* thingy, if it is null, this method tries to deal with it and find a workaround
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void longClickPage(final String url) {
|
|
||||||
HitTestResult result = null;
|
|
||||||
String currentUrl = null;
|
|
||||||
final WebView currentWebView = tabsManager.getCurrentWebView();
|
|
||||||
if (currentWebView != null) {
|
|
||||||
result = currentWebView.getHitTestResult();
|
|
||||||
currentUrl = currentWebView.getUrl();
|
|
||||||
}
|
|
||||||
if (currentUrl != null && currentUrl.startsWith(Constants.FILE)) {
|
|
||||||
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
|
||||||
if (url != null) {
|
|
||||||
longPressHistoryLink(url);
|
|
||||||
} else if (result != null && result.getExtra() != null) {
|
|
||||||
final String newUrl = result.getExtra();
|
|
||||||
longPressHistoryLink(newUrl);
|
|
||||||
}
|
|
||||||
} else if (currentUrl.endsWith(Constants.BOOKMARKS_FILENAME)) {
|
|
||||||
if (url != null) {
|
|
||||||
bookmarksDialogBuilder.showLongPressedDialogForUrl(this, url);
|
|
||||||
} else if (result != null && result.getExtra() != null) {
|
|
||||||
final String newUrl = result.getExtra();
|
|
||||||
bookmarksDialogBuilder.showLongPressedDialogForUrl(this, newUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (url != null) {
|
|
||||||
if (result != null) {
|
|
||||||
if (result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == HitTestResult.IMAGE_TYPE) {
|
|
||||||
longPressImage(url);
|
|
||||||
} else {
|
|
||||||
longPressLink(url);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
longPressLink(url);
|
|
||||||
}
|
|
||||||
} else if (result != null && result.getExtra() != null) {
|
|
||||||
final String newUrl = result.getExtra();
|
|
||||||
if (result.getType() == HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == HitTestResult.IMAGE_TYPE) {
|
|
||||||
longPressImage(newUrl);
|
|
||||||
} else {
|
|
||||||
longPressLink(newUrl);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
@ -15,6 +15,7 @@ import acr.browser.lightning.fragment.LightningPreferenceFragment;
|
|||||||
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;
|
||||||
|
import acr.browser.lightning.view.LightningView;
|
||||||
import dagger.Component;
|
import dagger.Component;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,4 +48,6 @@ public interface AppComponent {
|
|||||||
Bus getBus();
|
Bus getBus();
|
||||||
|
|
||||||
Context getApplicationContext();
|
Context getApplicationContext();
|
||||||
|
|
||||||
|
void inject(LightningView lightningView);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package acr.browser.lightning.bus;
|
package acr.browser.lightning.bus;
|
||||||
|
|
||||||
import android.support.annotation.IdRes;
|
import android.support.annotation.IdRes;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.support.annotation.StringRes;
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
|
@ -24,7 +24,7 @@ public interface BrowserController {
|
|||||||
|
|
||||||
void openFileChooser(ValueCallback<Uri> uploadMsg);
|
void openFileChooser(ValueCallback<Uri> uploadMsg);
|
||||||
|
|
||||||
void onLongPress();
|
// void onLongPress();
|
||||||
|
|
||||||
void onShowCustomView(View view, CustomViewCallback callback);
|
void onShowCustomView(View view, CustomViewCallback callback);
|
||||||
|
|
||||||
@ -44,7 +44,7 @@ public interface BrowserController {
|
|||||||
|
|
||||||
void showActionBar();
|
void showActionBar();
|
||||||
|
|
||||||
void longClickPage(String url);
|
// void longClickPage(String url);
|
||||||
|
|
||||||
void showFileChooser(ValueCallback<Uri[]> filePathCallback);
|
void showFileChooser(ValueCallback<Uri[]> filePathCallback);
|
||||||
|
|
||||||
|
@ -1,30 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2014 A.C.R. Development
|
|
||||||
*/
|
|
||||||
package acr.browser.lightning.object;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.os.Message;
|
|
||||||
|
|
||||||
import acr.browser.lightning.controller.BrowserController;
|
|
||||||
|
|
||||||
public class ClickHandler extends Handler {
|
|
||||||
|
|
||||||
private BrowserController mBrowserController;
|
|
||||||
|
|
||||||
public ClickHandler(Context context) {
|
|
||||||
try {
|
|
||||||
mBrowserController = (BrowserController) context;
|
|
||||||
} catch (ClassCastException e) {
|
|
||||||
throw new ClassCastException(context + " must implement BrowserController");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void handleMessage(Message msg) {
|
|
||||||
super.handleMessage(msg);
|
|
||||||
String url = msg.getData().getString("url");
|
|
||||||
mBrowserController.longClickPage(url);
|
|
||||||
}
|
|
||||||
}
|
|
@ -20,6 +20,7 @@ import android.net.MailTo;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.net.http.SslError;
|
import android.net.http.SslError;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.os.Handler;
|
||||||
import android.os.Message;
|
import android.os.Message;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
@ -63,9 +64,12 @@ import javax.inject.Inject;
|
|||||||
import acr.browser.lightning.R;
|
import acr.browser.lightning.R;
|
||||||
import acr.browser.lightning.app.BrowserApp;
|
import acr.browser.lightning.app.BrowserApp;
|
||||||
import acr.browser.lightning.bus.BrowserEvents;
|
import acr.browser.lightning.bus.BrowserEvents;
|
||||||
|
import acr.browser.lightning.bus.TabEvents;
|
||||||
import acr.browser.lightning.constant.Constants;
|
import acr.browser.lightning.constant.Constants;
|
||||||
|
import acr.browser.lightning.constant.HistoryPage;
|
||||||
import acr.browser.lightning.constant.StartPage;
|
import acr.browser.lightning.constant.StartPage;
|
||||||
import acr.browser.lightning.controller.BrowserController;
|
import acr.browser.lightning.controller.BrowserController;
|
||||||
|
import acr.browser.lightning.dialog.BookmarksDialogBuilder;
|
||||||
import acr.browser.lightning.download.LightningDownloadListener;
|
import acr.browser.lightning.download.LightningDownloadListener;
|
||||||
import acr.browser.lightning.preference.PreferenceManager;
|
import acr.browser.lightning.preference.PreferenceManager;
|
||||||
import acr.browser.lightning.utils.AdBlock;
|
import acr.browser.lightning.utils.AdBlock;
|
||||||
@ -87,7 +91,6 @@ public class LightningView {
|
|||||||
private static String mDefaultUserAgent;
|
private static String mDefaultUserAgent;
|
||||||
// TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light
|
// TODO fix so that mWebpageBitmap can be static - static changes the icon when switching from light to dark and then back to light
|
||||||
private final Bitmap mWebpageBitmap;
|
private final Bitmap mWebpageBitmap;
|
||||||
PreferenceManager mPreferences;
|
|
||||||
private final AdBlock mAdBlock;
|
private final AdBlock mAdBlock;
|
||||||
private final IntentUtils mIntentUtils;
|
private final IntentUtils mIntentUtils;
|
||||||
private final Paint mPaint = new Paint();
|
private final Paint mPaint = new Paint();
|
||||||
@ -106,13 +109,20 @@ public class LightningView {
|
|||||||
};
|
};
|
||||||
private final PermissionsManager mPermissionsManager;
|
private final PermissionsManager mPermissionsManager;
|
||||||
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
|
private static final String[] PERMISSIONS = new String[]{Manifest.permission.ACCESS_FINE_LOCATION};
|
||||||
|
private final WebViewHandler webViewHandler = new WebViewHandler();
|
||||||
|
|
||||||
private final Bus eventBus;
|
@Inject
|
||||||
|
Bus eventBus;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
PreferenceManager mPreferences;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
BookmarksDialogBuilder bookmarksDialogBuilder;
|
||||||
|
|
||||||
@SuppressLint("NewApi")
|
@SuppressLint("NewApi")
|
||||||
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) {
|
public LightningView(Activity activity, String url, boolean darkTheme, boolean isIncognito) {
|
||||||
eventBus = BrowserApp.getAppComponent().getBus();
|
BrowserApp.getAppComponent().inject(this);
|
||||||
mPreferences = BrowserApp.getAppComponent().getPreferenceManager();
|
|
||||||
mActivity = activity;
|
mActivity = activity;
|
||||||
mWebView = new WebView(activity);
|
mWebView = new WebView(activity);
|
||||||
mIsIncognitoTab = isIncognito;
|
mIsIncognitoTab = isIncognito;
|
||||||
@ -613,6 +623,52 @@ public class LightningView {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* handles a long click on the page, parameter String url
|
||||||
|
* is the url that should have been obtained from the WebView touch node
|
||||||
|
* thingy, if it is null, this method tries to deal with it and find a workaround
|
||||||
|
*/
|
||||||
|
private void longClickPage(final String url) {
|
||||||
|
final WebView.HitTestResult result = mWebView.getHitTestResult();
|
||||||
|
String currentUrl = mWebView.getUrl();
|
||||||
|
if (currentUrl != null && currentUrl.startsWith(Constants.FILE)) {
|
||||||
|
if (currentUrl.endsWith(HistoryPage.FILENAME)) {
|
||||||
|
if (url != null) {
|
||||||
|
// TODO longPressHistoryLink(url);
|
||||||
|
} else if (result != null && result.getExtra() != null) {
|
||||||
|
final String newUrl = result.getExtra();
|
||||||
|
// TODO longPressHistoryLink(newUrl);
|
||||||
|
}
|
||||||
|
} else if (currentUrl.endsWith(Constants.BOOKMARKS_FILENAME)) {
|
||||||
|
if (url != null) {
|
||||||
|
bookmarksDialogBuilder.showLongPressedDialogForUrl(mActivity, url);
|
||||||
|
} else if (result != null && result.getExtra() != null) {
|
||||||
|
final String newUrl = result.getExtra();
|
||||||
|
bookmarksDialogBuilder.showLongPressedDialogForUrl(mActivity, newUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (url != null) {
|
||||||
|
if (result != null) {
|
||||||
|
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
||||||
|
// TODO longPressImage(url);
|
||||||
|
} else {
|
||||||
|
// TODO longPressLink(url);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// TODO longPressLink(url);
|
||||||
|
}
|
||||||
|
} else if (result != null && result.getExtra() != null) {
|
||||||
|
final String newUrl = result.getExtra();
|
||||||
|
if (result.getType() == WebView.HitTestResult.SRC_IMAGE_ANCHOR_TYPE || result.getType() == WebView.HitTestResult.IMAGE_TYPE) {
|
||||||
|
// TODO longPressImage(newUrl);
|
||||||
|
} else {
|
||||||
|
// TODO longPressLink(newUrl);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public boolean canGoBack() {
|
public boolean canGoBack() {
|
||||||
return mWebView != null && mWebView.canGoBack();
|
return mWebView != null && mWebView.canGoBack();
|
||||||
}
|
}
|
||||||
@ -1149,8 +1205,13 @@ public class LightningView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLongPress(MotionEvent e) {
|
public void onLongPress(MotionEvent e) {
|
||||||
if (mCanTriggerLongPress)
|
if (mCanTriggerLongPress) {
|
||||||
mBrowserController.onLongPress();
|
Message msg = webViewHandler.obtainMessage();
|
||||||
|
if (msg != null) {
|
||||||
|
msg.setTarget(webViewHandler);
|
||||||
|
mWebView.requestFocusNodeHref(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1172,4 +1233,13 @@ public class LightningView {
|
|||||||
mCanTriggerLongPress = true;
|
mCanTriggerLongPress = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private class WebViewHandler extends Handler {
|
||||||
|
@Override
|
||||||
|
public void handleMessage(Message msg) {
|
||||||
|
super.handleMessage(msg);
|
||||||
|
final String url = msg.getData().getString("url");
|
||||||
|
longClickPage(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user