use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method saveTabStates.
public void saveTabStates() {
SharedPreferences settings = getSharedPreferences(PREF_KIWIX_MOBILE, 0);
SharedPreferences.Editor editor = settings.edit();
JSONArray urls = new JSONArray();
JSONArray positions = new JSONArray();
for (KiwixWebView view : mWebViews) {
if (view.getUrl() == null)
continue;
urls.put(view.getUrl());
positions.put(view.getScrollY());
}
editor.putString(TAG_CURRENT_FILE, ZimContentProvider.getZimFile());
editor.putString(TAG_CURRENT_ARTICLES, urls.toString());
editor.putString(TAG_CURRENT_POSITIONS, positions.toString());
editor.putInt(TAG_CURRENT_TAB, currentWebViewIndex);
editor.apply();
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
KiwixWebView webView = getCurrentWebView();
switch(item.getItemId()) {
case R.id.menu_home:
case android.R.id.home:
openMainPage();
break;
case R.id.menu_searchintext:
compatCallback.setActive();
compatCallback.setWebView(webView);
startSupportActionMode(compatCallback);
compatCallback.showSoftInput();
break;
case R.id.menu_bookmarks:
toggleBookmark();
break;
case R.id.menu_bookmarks_list:
goToBookmarks();
break;
case R.id.menu_randomarticle:
openRandomArticle();
break;
case R.id.menu_help:
showHelpPage();
break;
case R.id.menu_openfile:
manageZimFiles(0);
break;
case R.id.menu_settings:
selectSettings();
break;
case R.id.menu_read_aloud:
if (TTSControls.getVisibility() == View.GONE) {
if (isBackToTopEnabled) {
backToTopButton.setVisibility(View.INVISIBLE);
}
} else if (TTSControls.getVisibility() == View.VISIBLE) {
if (isBackToTopEnabled) {
backToTopButton.setVisibility(View.VISIBLE);
}
}
readAloud();
break;
case R.id.menu_fullscreen:
if (isFullscreenOpened) {
closeFullScreen();
} else {
openFullScreen();
}
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class TabDrawerAdapter method onBindViewHolder.
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
KiwixWebView webView = webViews.get(position);
holder.title.setText(stripHtml(webView.getTitle()));
holder.exit.setOnClickListener(v -> listener.onCloseTab(v, position));
holder.itemView.setOnClickListener(v -> {
listener.onSelectTab(v, position);
selectedPosition = holder.getAdapterPosition();
notifyDataSetChanged();
holder.itemView.setActivated(true);
});
holder.itemView.setActivated(holder.getAdapterPosition() == selectedPosition);
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method onResume.
@Override
public void onResume() {
super.onResume();
invalidateOptionsMenu();
if (wasHideToolbar != isHideToolbar) {
wasHideToolbar = isHideToolbar;
List<KiwixWebView> newWebViews = new ArrayList<>();
for (int i = 0; i < mWebViews.size(); i++) {
KiwixWebView newView = getWebView(mWebViews.get(i).getUrl());
newWebViews.add(i, newView);
}
mWebViews = newWebViews;
selectTab(currentWebViewIndex);
}
if (refresh) {
refresh = false;
recreate();
}
if (menu != null) {
refreshBookmarkSymbol(menu);
}
if (getResources().getConfiguration().orientation == ORIENTATION_LANDSCAPE) {
if (menu != null) {
menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}
} else {
if (menu != null) {
menu.getItem(4).setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
}
}
if (!mWebViews.isEmpty() && mWebViews.get(currentWebViewIndex).getUrl() != null && mWebViews.get(currentWebViewIndex).getUrl().equals("file:///android_asset/help.html") && mWebViews.get(currentWebViewIndex).findViewById(R.id.get_content_card) != null) {
mWebViews.get(currentWebViewIndex).findViewById(R.id.get_content_card).setEnabled(true);
}
if (sharedPreferenceUtil.getPrefBottomToolbar()) {
pageBottomTabLayout.setVisibility(View.VISIBLE);
if (menuBookmarks != null) {
menuBookmarks.setVisible(false);
}
} else {
pageBottomTabLayout.setVisibility(View.GONE);
if (menuBookmarks != null) {
menuBookmarks.setVisible(true);
}
}
Log.d(TAG_KIWIX, "action" + getIntent().getAction());
Intent intent = getIntent();
if (intent.getAction() != null) {
if (intent.getAction().equals(Intent.ACTION_PROCESS_TEXT)) {
final String zimFile = ZimContentProvider.getZimFile();
saveTabStates();
Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
i.putExtra(EXTRA_ZIM_FILE, zimFile);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
i.putExtra(Intent.EXTRA_PROCESS_TEXT, intent.getStringExtra(Intent.EXTRA_PROCESS_TEXT));
}
intent.setAction("");
startActivityForResult(i, REQUEST_FILE_SEARCH);
} else if (intent.getAction().equals(KiwixSearchWidget.TEXT_CLICKED)) {
intent.setAction("");
goToSearch(false);
} else if (intent.getAction().equals(KiwixSearchWidget.STAR_CLICKED)) {
intent.setAction("");
goToBookmarks();
} else if (intent.getAction().equals(KiwixSearchWidget.MIC_CLICKED)) {
intent.setAction("");
goToSearch(true);
} else if (intent.getAction().equals(Intent.ACTION_VIEW)) {
final String zimFile = ZimContentProvider.getZimFile();
saveTabStates();
Intent i = new Intent(KiwixMobileActivity.this, SearchActivity.class);
i.putExtra(EXTRA_ZIM_FILE, zimFile);
i.putExtra(EXTRA_SEARCH, intent.getData().getLastPathSegment());
intent.setAction("");
startActivityForResult(i, REQUEST_FILE_SEARCH);
}
}
updateWidgets(this);
}
use of org.kiwix.kiwixmobile.views.web.KiwixWebView in project kiwix-android by kiwix.
the class KiwixMobileActivity method newTabInBackground.
private void newTabInBackground(String url) {
KiwixWebView webView = getWebView(url);
mWebViews.add(webView);
tabDrawerAdapter.notifyDataSetChanged();
setUpWebView();
documentParser.initInterface(webView);
}
Aggregations