static void initLibrary(final Activity activity) { final NetworkLibrary library = NetworkLibrary.Instance(); if (library.isInitialized()) { return; } Config.Instance() .runOnStart( new Runnable() { public void run() { UIUtil.wait( "loadingNetworkLibrary", new Runnable() { public void run() { if (SQLiteNetworkDatabase.Instance() == null) { new SQLiteNetworkDatabase(activity.getApplication()); } library.initialize(); } }, activity); } }); }
ZLNetworkRequest createNetworkData(String url, final OPDSCatalogItem.State result) { if (url == null) { return null; } final NetworkLibrary library = NetworkLibrary.Instance(); final NetworkCatalogItem catalogItem = result.Loader.getTree().Item; library.startLoading(catalogItem); url = rewriteUrl(url, false); return new ZLNetworkRequest(url) { @Override public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException { if (result.Loader.confirmInterruption()) { return; } new OPDSXMLReader(new OPDSFeedHandler(getURL(), result), false).read(inputStream); if (result.Loader.confirmInterruption() && result.LastLoadedId != null) { // reset state to load current page from the beginning result.LastLoadedId = null; } else { result.Loader.getTree().confirmAllItems(); } } @Override public void doAfter(boolean success) { library.stopLoading(catalogItem); } }; }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Thread.setDefaultUncaughtExceptionHandler( new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)); final Intent intent = getIntent(); if (Intent.ACTION_SEARCH.equals(intent.getAction())) { final Bundle data = intent.getBundleExtra(SearchManager.APP_DATA); if (data != null) { final NetworkLibrary library = NetworkLibrary.Instance(); final NetworkTree.Key key = (NetworkTree.Key) data.getSerializable(NetworkLibraryActivity.TREE_KEY_KEY); final NetworkTree tree = library.getTreeByKey(key); if (tree instanceof SearchCatalogTree) { final SearchCatalogTree searchTree = (SearchCatalogTree) tree; final String pattern = intent.getStringExtra(SearchManager.QUERY); final MimeType mime = searchTree.getMimeType(); if (MimeType.APP_ATOM_XML.weakEquals(mime)) { searchTree.startItemsLoader(new QuietNetworkContext(), pattern); } else if (MimeType.TEXT_HTML.weakEquals(mime)) { Util.openInBrowser(this, searchTree.getUrl(pattern)); } } } } finish(); }
private void openInBrowser(final String urlString) { final Intent intent = new Intent(Intent.ACTION_VIEW); final boolean externalUrl; if (BookDownloader.acceptsUri(Uri.parse(urlString))) { intent.setClass(BaseActivity, BookDownloader.class); intent.putExtra( BookDownloaderService.SHOW_NOTIFICATIONS_KEY, BookDownloaderService.Notifications.ALL); externalUrl = false; } else { externalUrl = true; } final NetworkLibrary nLibrary = NetworkLibrary.Instance(); new Thread( new Runnable() { public void run() { if (!urlString.startsWith("fbreader-action:")) { nLibrary.initialize(); } intent.setData(Uri.parse(nLibrary.rewriteUrl(urlString, externalUrl))); BaseActivity.runOnUiThread( new Runnable() { public void run() { try { BaseActivity.startActivity(intent); } catch (ActivityNotFoundException e) { e.printStackTrace(); } } }); } }) .start(); }
void prepareView() { if (myTree == null) { myTree = NetworkLibrary.Instance().getRootTree(); setListAdapter(new LibraryAdapter()); getListView().invalidateViews(); } }
public class AddCatalogMenuActivity extends MenuActivity { private final ZLResource myResource = NetworkLibrary.Instance().resource().getResource("addCatalog"); private void addItem(String id, int weight) { myInfos.add( new PluginApi.MenuActionInfo( Uri.parse("http://data.fbreader.org/add_catalog/" + id), myResource.getResource(id).getValue(), weight)); } @Override protected void init() { setTitle(myResource.getResource("title").getValue()); addItem("editUrl", 1); // addItem("scanLocalNetwork", 2); } @Override protected String getAction() { return Util.ADD_CATALOG_ACTION; } @Override protected void runItem(final PluginApi.MenuActionInfo info) { try { startActivity(FBReaderIntents.defaultIntent(getAction()).setData(info.getId())); } catch (ActivityNotFoundException e) { } finish(); } }
private void runLanguageFilterDialog() { final NetworkLibrary library = NetworkLibrary.Instance(); final List<String> allLanguageCodes = library.languageCodes(); Collections.sort(allLanguageCodes, new ZLLanguageUtil.CodeComparator()); final Collection<String> activeLanguageCodes = library.activeLanguageCodes(); final CharSequence[] languageNames = new CharSequence[allLanguageCodes.size()]; final boolean[] checked = new boolean[allLanguageCodes.size()]; for (int i = 0; i < allLanguageCodes.size(); ++i) { final String code = allLanguageCodes.get(i); languageNames[i] = ZLLanguageUtil.languageName(code); checked[i] = activeLanguageCodes.contains(code); } final DialogInterface.OnMultiChoiceClickListener listener = new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { checked[which] = isChecked; } }; final ZLResource dialogResource = ZLResource.resource("dialog"); final AlertDialog dialog = new AlertDialog.Builder(this) .setMultiChoiceItems(languageNames, checked, listener) .setTitle( dialogResource.getResource("languageFilterDialog").getResource("title").getValue()) .setPositiveButton( dialogResource.getResource("button").getResource("ok").getValue(), new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { final TreeSet<String> newActiveCodes = new TreeSet<String>(new ZLLanguageUtil.CodeComparator()); for (int i = 0; i < checked.length; ++i) { if (checked[i]) { newActiveCodes.add(allLanguageCodes.get(i)); } } library.setActiveLanguageCodes(newActiveCodes); library.synchronize(); NetworkView.Instance().fireModelChanged(); } }) .create(); dialog.show(); }
@Override public boolean onSearchRequested() { if (searchIsInProgress()) { return false; } final NetworkLibrary library = NetworkLibrary.Instance(); startSearch(library.NetworkSearchPatternOption.getValue(), true, null, false); return true; }
private void openInBrowser(String urlString) { final Intent intent = new Intent(Intent.ACTION_VIEW); boolean externalUrl = true; if (BookDownloader.acceptsUri(Uri.parse(urlString))) { intent.setClass(myBaseActivity, BookDownloader.class); intent.putExtra( BookDownloaderService.SHOW_NOTIFICATIONS_KEY, BookDownloaderService.Notifications.ALL); externalUrl = false; } final NetworkLibrary nLibrary = NetworkLibrary.Instance(); try { nLibrary.initialize(); } catch (ZLNetworkException e) { } intent.setData(Uri.parse(NetworkLibrary.Instance().rewriteUrl(urlString, externalUrl))); try { myBaseActivity.startActivity(intent); } catch (ActivityNotFoundException e) { // TODO: show an error message } }
@Override protected void onStart() { super.onStart(); myAllItems.clear(); final Intent intent = getIntent(); myAllItems.add(new SectionItem("enabled")); final List<String> enabledIds = intent.getStringArrayListExtra(NetworkLibraryActivity.ENABLED_CATALOG_IDS_KEY); if (enabledIds.size() > 0) { final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>(); for (String id : enabledIds) { final NetworkTree tree = NetworkLibrary.Instance().getCatalogTreeByUrlAll(id); if (tree != null && tree.getLink() != null) { cItems.add(new CatalogItem(id, true, tree)); } } myAllItems.addAll(cItems); mySelectedItems.addAll(cItems); } myAllItems.add(new SectionItem("disabled")); final List<String> disabledIds = intent.getStringArrayListExtra(NetworkLibraryActivity.DISABLED_CATALOG_IDS_KEY); if (disabledIds.size() > 0) { final TreeSet<CatalogItem> cItems = new TreeSet<CatalogItem>(); for (String id : disabledIds) { cItems.add( new CatalogItem(id, false, NetworkLibrary.Instance().getCatalogTreeByUrlAll(id))); } myAllItems.addAll(cItems); } setListAdapter(new CatalogsListAdapter()); }
private void doExpandCatalog(final NetworkCatalogTree tree) { final NetworkItemsLoader loader = NetworkLibrary.Instance().getStoredLoader(tree); if (loader != null && loader.canResumeLoading()) { doOpenTree(tree); } else if (loader != null) { loader.setPostRunnable( new Runnable() { public void run() { doLoadCatalog(tree); } }); } else { doLoadCatalog(tree); } }
private static boolean runActionStatic(Activity activity, NetworkBookTree tree, int actionCode) { final NetworkBookItem book = tree.Book; switch (actionCode) { case ActionCode.DOWNLOAD_BOOK: Util.doDownloadBook(activity, book, false); return true; case ActionCode.DOWNLOAD_DEMO: Util.doDownloadBook(activity, book, true); return true; case ActionCode.READ_BOOK: doReadBook(activity, book, false); return true; case ActionCode.READ_DEMO: doReadBook(activity, book, true); return true; case ActionCode.DELETE_BOOK: tryToDeleteBook(activity, book, false); return true; case ActionCode.DELETE_DEMO: tryToDeleteBook(activity, book, true); return true; case ActionCode.BUY_DIRECTLY: doBuyDirectly(activity, tree); return true; case ActionCode.BUY_IN_BROWSER: doBuyInBrowser(activity, book); return true; case ActionCode.ADD_BOOK_TO_BASKET: book.Link.getBasketItem().add(book); return true; case ActionCode.REMOVE_BOOK_FROM_BASKET: book.Link.getBasketItem().remove(book); return true; case ActionCode.OPEN_BASKET: new OpenCatalogAction(activity) .run(NetworkLibrary.Instance().getFakeBasketTree(book.Link.getBasketItem())); return true; } return false; }
@Override protected void onFinish(ZLNetworkException exception, boolean interrupted) { if (interrupted && (!getTree().Item.supportsResumeLoading() || exception != null)) { getTree().clearCatalog(); } else { getTree().removeUnconfirmedItems(); if (!interrupted) { if (exception != null) { NetworkLibrary.Instance() .fireModelChangedEvent( NetworkLibrary.ChangeListener.Code.NetworkError, exception.getMessage()); } else { getTree().updateLoadedTime(); if (getTree().subtrees().isEmpty()) { NetworkLibrary.Instance() .fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.EmptyCatalog); } } } final NetworkLibrary library = NetworkLibrary.Instance(); library.invalidateVisibility(); library.synchronize(); } }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); Thread.setDefaultUncaughtExceptionHandler( new org.geometerplus.zlibrary.ui.android.library.UncaughtExceptionHandler(this)); setContentView(R.layout.authentication); final Intent intent = getIntent(); final String host = intent.getStringExtra(HOST_KEY); final String area = intent.getStringExtra(AREA_KEY); final String username = intent.getStringExtra(USERNAME_KEY); final String error = intent.getStringExtra(ERROR_KEY); myCustomAuthentication = intent.getBooleanExtra(CUSTOM_AUTH_KEY, false); if (myCustomAuthentication) { myLink = NetworkLibrary.Instance().getLinkByUrl(String.valueOf(intent.getData())); if (myLink == null) { finish(); return; } setResult(RESULT_CANCELED, Util.intentByLink(new Intent(), myLink)); } else { myLink = null; setResult(RESULT_CANCELED); } myOnSuccessRunnable = ourOnSuccessRunnableMap.remove(intent.getLongExtra(RUNNABLE_KEY, -1)); myResource = ZLResource.resource("dialog").getResource("AuthenticationDialog"); setTitle(host != null ? host : myResource.getResource("title").getValue()); if (area != null && !"".equals(area)) { findTextView(R.id.authentication_subtitle).setText(area); } else { findTextView(R.id.authentication_subtitle).setVisibility(View.GONE); } final TextView warningView = findTextView(R.id.authentication_unencrypted_warning); if ("https".equalsIgnoreCase(intent.getStringExtra(SCHEME_KEY))) { warningView.setVisibility(View.GONE); } else { warningView.setText(myResource.getResource("unencryptedWarning").getValue()); } findTextView(R.id.authentication_username_label) .setText(myResource.getResource("login").getValue()); findTextView(R.id.authentication_password_label) .setText(myResource.getResource("password").getValue()); myUsernameView = findTextView(R.id.authentication_username); myUsernameView.setText(username); setError(error); final ZLResource buttonResource = ZLResource.resource("dialog").getResource("button"); final View buttonsView = findViewById(R.id.authentication_buttons); myOkButton = (Button) buttonsView.findViewById(R.id.ok_button); myOkButton.setText(buttonResource.getResource("ok").getValue()); myOkButton.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { final String username = myUsernameView.getText().toString(); final String password = findTextView(R.id.authentication_password).getText().toString(); if (myCustomAuthentication) { runCustomAuthentication(username, password); } else { finishOk(username, password); } } }); final Button cancelButton = (Button) buttonsView.findViewById(R.id.cancel_button); cancelButton.setText(buttonResource.getResource("cancel").getValue()); cancelButton.setOnClickListener( new Button.OnClickListener() { public void onClick(View v) { runOnUiThread( new Runnable() { public void run() { if (myLink != null) { final NetworkAuthenticationManager mgr = myLink.authenticationManager(); if (mgr.mayBeAuthorised(false)) { mgr.logOut(); } } final NetworkLibrary library = NetworkLibrary.Instance(); library.invalidateVisibility(); library.synchronize(); } }); finish(); } }); }
private static boolean searchIsInProgress() { return ItemsLoadingService.getRunnable(NetworkLibrary.Instance().getSearchItemTree()) != null; }
public SectionItem(String key) { Title = NetworkLibrary.resource().getResource("manageCatalogs").getResource(key).getValue(); }
public static void openInBrowser(Activity activity, String url) { if (url != null) { url = NetworkLibrary.Instance().rewriteUrl(url, true); activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url))); } }