use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method newTab.
private KiwixWebView newTab(String url) {
KiwixWebView webView = getWebView(url);
mWebViews.add(webView);
selectTab(mWebViews.size() - 1);
tabDrawerAdapter.notifyDataSetChanged();
setUpWebView();
documentParser.initInterface(webView);
return webView;
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method selectTab.
private void selectTab(int position) {
currentWebViewIndex = position;
tabDrawerAdapter.setSelected(position);
contentFrame.removeAllViews();
KiwixWebView webView = mWebViews.get(position);
contentFrame.addView(webView);
tabDrawerAdapter.setSelected(currentWebViewIndex);
if (drawerLayout.isDrawerOpen(GravityCompat.START)) {
new Handler().postDelayed(() -> drawerLayout.closeDrawers(), 150);
}
loadPrefs();
if (menu != null) {
refreshBookmarkSymbol(menu);
}
updateTableOfContents();
if (!isHideToolbar) {
((ToolbarScrollingKiwixWebView) webView).ensureToolbarDisplayed();
}
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method getWebView.
private KiwixWebView getWebView(String url) {
AttributeSet attrs = StyleUtils.getAttributes(this, R.xml.webview);
KiwixWebView webView;
if (!isHideToolbar) {
webView = new ToolbarScrollingKiwixWebView(KiwixMobileActivity.this, this, toolbarContainer, pageBottomTabLayout, attrs);
((ToolbarScrollingKiwixWebView) webView).setOnToolbarVisibilityChangeListener(new ToolbarScrollingKiwixWebView.OnToolbarVisibilityChangeListener() {
@Override
public void onToolbarDisplayed() {
shrinkDrawers();
}
@Override
public void onToolbarHidden() {
expandDrawers();
}
});
} else {
webView = new ToolbarStaticKiwixWebView(KiwixMobileActivity.this, this, toolbarContainer, attrs);
}
webView.loadUrl(url);
webView.loadPrefs();
return webView;
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Log.i(TAG_KIWIX, "Intent data: " + data);
switch(requestCode) {
case REQUEST_FILE_SELECT:
if (resultCode == RESULT_OK) {
// The URI of the selected file
final Uri uri = data.getData();
File file = null;
if (uri != null) {
String path = uri.getPath();
if (path != null) {
file = new File(path);
}
}
if (file == null) {
Log.i(TAG_KIWIX, "Could not find file");
return;
}
finish();
Intent zimFile = new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class);
zimFile.setData(uri);
startActivity(zimFile);
}
break;
case REQUEST_FILE_SEARCH:
if (resultCode == RESULT_OK) {
String title = data.getStringExtra(TAG_FILE_SEARCHED).replace("<b>", "").replace("</b>", "");
boolean isSearchInText = data.getBooleanExtra(EXTRA_SEARCH_IN_TEXT, false);
if (isSearchInText) {
// if the search is localized trigger find in page UI.
KiwixWebView webView = getCurrentWebView();
compatCallback.setActive();
compatCallback.setWebView(webView);
startSupportActionMode(compatCallback);
compatCallback.setText(title);
compatCallback.findAll();
compatCallback.showSoftInput();
} else {
searchForTitle(title);
}
} else {
// TODO: Inform the User
Log.w(TAG_KIWIX, "Unhandled search failure");
}
break;
case REQUEST_PREFERENCES:
if (resultCode == RESULT_RESTART) {
finish();
startActivity(new Intent(KiwixMobileActivity.this, KiwixMobileActivity.class));
}
if (resultCode == RESULT_HISTORY_CLEARED) {
mWebViews.clear();
newTab();
tabDrawerAdapter.notifyDataSetChanged();
}
loadPrefs();
break;
case BOOKMARK_CHOSEN_REQUEST:
if (resultCode == RESULT_OK) {
boolean itemClicked = data.getBooleanExtra(EXTRA_BOOKMARK_CLICKED, false);
if (ZimContentProvider.getId() == null)
return;
// Bookmarks
bookmarksDao = new BookmarksDao(KiwixDatabase.getInstance(this));
bookmarks = bookmarksDao.getBookmarks(ZimContentProvider.getId(), ZimContentProvider.getName());
if (itemClicked) {
String bookmarkChosen;
if (data.getStringExtra(EXTRA_CHOSE_X_URL) != null) {
bookmarkChosen = data.getStringExtra(EXTRA_CHOSE_X_URL);
newTab();
getCurrentWebView().loadUrl(bookmarkChosen);
} else {
newTab();
bookmarkChosen = data.getStringExtra(EXTRA_CHOSE_X_TITLE);
openArticleFromBookmarkTitle(bookmarkChosen);
}
}
if (menu != null) {
refreshBookmarkSymbol(menu);
}
}
break;
default:
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
Aggregations