use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class NetworkItemsLoader method run.
public final void run() {
final NetworkLibrary library = Tree.Library;
synchronized (library) {
if (library.isLoadingInProgress(Tree)) {
return;
}
library.storeLoader(Tree, this);
}
try {
library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
try {
doBefore();
} catch (ZLNetworkException e) {
onFinish(e, false);
return;
}
try {
load();
onFinish(null, isLoadingInterrupted());
} catch (ZLNetworkException e) {
onFinish(e, isLoadingInterrupted());
}
} finally {
library.removeStoredLoader(Tree);
library.fireModelChangedEvent(NetworkLibrary.ChangeListener.Code.SomeCode);
synchronized (this) {
if (myPostRunnable != null) {
myPostRunnable.run();
myFinishedFlag = true;
}
}
}
}
use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class ProcessHyperlinkAction method openInBrowser.
private void openInBrowser(final String url) {
final Intent intent = new Intent(Intent.ACTION_VIEW);
final boolean externalUrl;
if (BookDownloader.acceptsUri(Uri.parse(url), null)) {
intent.setClass(BaseActivity, BookDownloader.class);
intent.putExtra(BookDownloaderService.Key.SHOW_NOTIFICATIONS, BookDownloaderService.Notifications.ALL);
externalUrl = false;
} else {
externalUrl = true;
}
final NetworkLibrary nLibrary = NetworkLibrary.Instance(Paths.systemInfo(BaseActivity));
new Thread(new Runnable() {
public void run() {
if (!url.startsWith("fbreader-action:")) {
try {
nLibrary.initialize(new ActivityNetworkContext(BaseActivity));
} catch (ZLNetworkException e) {
e.printStackTrace();
UIMessageUtil.showMessageText(BaseActivity, e.getMessage());
return;
}
}
intent.setData(Util.rewriteUri(Uri.parse(nLibrary.rewriteUrl(url, externalUrl))));
BaseActivity.runOnUiThread(new Runnable() {
public void run() {
try {
OrientationUtil.startActivity(BaseActivity, intent);
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
}
});
}
}).start();
}
use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class NetworkSearchActivity method onCreate.
@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 = Util.networkLibrary(this);
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(myNetworkContext, pattern);
} else if (MimeType.TEXT_HTML.weakEquals(mime)) {
Util.openInBrowser(this, searchTree.getUrl(pattern));
}
}
}
}
finish();
}
use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class RunSearchAction method run.
@Override
public void run(NetworkTree tree) {
final Bundle bundle = new Bundle();
bundle.putSerializable(NetworkLibraryActivity.TREE_KEY_KEY, getSearchTree(tree).getUniqueKey());
final NetworkLibrary library = myLibrary;
if (DeviceType.Instance().hasStandardSearchDialog()) {
myActivity.startSearch(library.NetworkSearchPatternOption.getValue(), true, bundle, false);
} else {
SearchDialogUtil.showDialog(myActivity, NetworkSearchActivity.class, library.NetworkSearchPatternOption.getValue(), null, bundle);
}
}
use of org.geometerplus.fbreader.network.NetworkLibrary in project FBReaderJ by geometer.
the class BookElementManager method startLoading.
private void startLoading(final String url, final List<BookElement> elements) {
final NetworkLibrary library = NetworkLibrary.Instance(myView.Application.SystemInfo);
new Thread() {
public void run() {
final SimpleOPDSFeedHandler handler = new SimpleOPDSFeedHandler(library, url);
try {
new QuietNetworkContext().perform(new ZLNetworkRequest.Get(url, true) {
@Override
public void handleStream(InputStream inputStream, int length) throws IOException, ZLNetworkException {
new OPDSXMLReader(library, handler, false).read(inputStream);
}
});
if (handler.books().isEmpty()) {
throw new RuntimeException();
}
myTimer = null;
final List<OPDSBookItem> items = handler.books();
int index = 0;
for (BookElement book : elements) {
book.setData(items.get(index));
index = (index + 1) % items.size();
myScreenRefresher.run();
}
} catch (Exception e) {
if (myTimer == null) {
myTimer = new Timer();
}
myTimer.schedule(new TimerTask() {
@Override
public void run() {
startLoading(url, elements);
}
}, 10000);
e.printStackTrace();
}
}
}.start();
}
Aggregations