Search in sources :

Example 1 with ActivityNetworkContext

use of org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext 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();
}
Also used : ZLNetworkException(org.geometerplus.zlibrary.core.network.ZLNetworkException) ActivityNotFoundException(android.content.ActivityNotFoundException) Intent(android.content.Intent) ActivityNetworkContext(org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext) NetworkLibrary(org.geometerplus.fbreader.network.NetworkLibrary)

Aggregations

ActivityNotFoundException (android.content.ActivityNotFoundException)1 Intent (android.content.Intent)1 ActivityNetworkContext (org.geometerplus.android.fbreader.network.auth.ActivityNetworkContext)1 NetworkLibrary (org.geometerplus.fbreader.network.NetworkLibrary)1 ZLNetworkException (org.geometerplus.zlibrary.core.network.ZLNetworkException)1