Add LongClickListener for opening up links in a new tab

This commit is contained in:
Rashiq 2015-06-07 10:53:43 +02:00
parent 7b9ef9d972
commit aa6e28b581
4 changed files with 38 additions and 5 deletions

View File

@ -25,6 +25,7 @@
<string name="choose_file">Select a ZIM Content File (*.zim)</string>
<string name="add_bookmark">Add bookmark</string>
<string name="remove_bookmark">Remove bookmark</string>
<string name="open_in_new_tab">Open link in new tab?</string>
<string name="error_nozimfilesfound">No ZIM files found on your device.\nTake a look at the Help Page to get directions on how to load content into Kiwix.\nIf you did put a ZIM file on your device/external storage, you might retry in a minute or restart your device.</string>
<string name="error_filenotfound">Error: The selected ZIM file could not be found.</string>
<string name="error_fileinvalid">Error: The selected file is not a valid ZIM file.</string>

View File

@ -23,8 +23,6 @@
<item name="deleteDrawable">@drawable/ic_action_delete</item>
<item name="dividerColor">@color/divider_light</item>
<item name="selectedBackground">@drawable/list_bg_light</item>
</style>
<style name="DrawerArrowStyle" parent="Widget.AppCompat.DrawerArrowToggle">

View File

@ -256,7 +256,7 @@ public class KiwixMobileActivity extends AppCompatActivity
newTab();
manageExternalLaunchAndRestoringViewState(savedInstanceState);
// setUpWebView();
setUpWebView();
setUpExitFullscreenButton();
// setUpArticleSearchTextView(savedInstanceState);
loadPrefs();
@ -840,6 +840,39 @@ public class KiwixMobileActivity extends AppCompatActivity
}
}
});
getCurrentWebView().setOnLongClickListener(new KiwixWebView.OnLongClickListener() {
@Override
public void onLongClick(final String url) {
boolean handleEvent = false;
if (url.startsWith(ZimContentProvider.CONTENT_URI.toString())) {
// This is my web site, so do not override; let my WebView load the page
handleEvent = true;
} else if (url.startsWith("file://")) {
// To handle help page (loaded from resources)
handleEvent = true;
} else if (url.startsWith(ZimContentProvider.UI_URI.toString())) {
handleEvent = true;
}
if (handleEvent) {
AlertDialog.Builder builder = new AlertDialog.Builder(KiwixMobileActivity.this);
builder.setPositiveButton(android.R.string.yes,
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
newTab(url);
}
});
builder.setNegativeButton(android.R.string.no, null);
builder.setMessage(getString(R.string.open_in_new_tab));
AlertDialog dialog = builder.create();
dialog.show();
}
}
});
final Handler saveHandler = new

View File

@ -125,6 +125,7 @@ public class KiwixWebView extends WebView {
}
public void loadPrefs() {
disableZoomControls();
SharedPreferences sharedPreferences = PreferenceManager
.getDefaultSharedPreferences(getContext());
@ -193,10 +194,10 @@ public class KiwixWebView extends WebView {
}
}
public void disableZoomControls(boolean disable) {
public void disableZoomControls() {
getSettings().setBuiltInZoomControls(true);
getSettings().setDisplayZoomControls(true);
getSettings().setDisplayZoomControls(false);
}
public void setOnPageChangedListener(OnPageChangeListener listener) {