Search in sources :

Example 6 with KiwixWebView

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;
}
Also used : ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView)

Example 7 with KiwixWebView

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();
    }
}
Also used : ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) Handler(android.os.Handler)

Example 8 with KiwixWebView

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;
}
Also used : ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) AttributeSet(android.util.AttributeSet) ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView)

Example 9 with KiwixWebView

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);
}
Also used : ToolbarScrollingKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView) KiwixWebView(org.kiwix.kiwixmobile.views.web.KiwixWebView) ToolbarStaticKiwixWebView(org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView) BookmarksDao(org.kiwix.kiwixmobile.database.BookmarksDao) Intent(android.content.Intent) SpannableString(android.text.SpannableString) Uri(android.net.Uri) File(java.io.File)

Aggregations

KiwixWebView (org.kiwix.kiwixmobile.views.web.KiwixWebView)9 ToolbarScrollingKiwixWebView (org.kiwix.kiwixmobile.views.web.ToolbarScrollingKiwixWebView)8 ToolbarStaticKiwixWebView (org.kiwix.kiwixmobile.views.web.ToolbarStaticKiwixWebView)8 Intent (android.content.Intent)2 SpannableString (android.text.SpannableString)2 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 AttributeSet (android.util.AttributeSet)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 JSONArray (org.json.JSONArray)1 BookmarksDao (org.kiwix.kiwixmobile.database.BookmarksDao)1