Search in sources :

Example 1 with ExternalFormatPlugin

use of org.geometerplus.fbreader.formats.ExternalFormatPlugin in project FBReaderJ by geometer.

the class FBReader method onNewIntent.

@Override
protected void onNewIntent(final Intent intent) {
    final String action = intent.getAction();
    final Uri data = intent.getData();
    if ((intent.getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) != 0) {
        super.onNewIntent(intent);
    } else if (Intent.ACTION_VIEW.equals(action) && data != null && "fbreader-action".equals(data.getScheme())) {
        myFBReaderApp.runAction(data.getEncodedSchemeSpecificPart(), data.getFragment());
    } else if (Intent.ACTION_VIEW.equals(action) || FBReaderIntents.Action.VIEW.equals(action)) {
        myOpenBookIntent = intent;
        if (myFBReaderApp.Model == null && myFBReaderApp.ExternalBook != null) {
            final BookCollectionShadow collection = getCollection();
            final Book b = FBReaderIntents.getBookExtra(intent, collection);
            if (!collection.sameBook(b, myFBReaderApp.ExternalBook)) {
                try {
                    final ExternalFormatPlugin plugin = (ExternalFormatPlugin) BookUtil.getPlugin(PluginCollection.Instance(Paths.systemInfo(this)), myFBReaderApp.ExternalBook);
                    startActivity(PluginUtil.createIntent(plugin, FBReaderIntents.Action.PLUGIN_KILL));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    } else if (FBReaderIntents.Action.PLUGIN.equals(action)) {
        new RunPluginAction(this, myFBReaderApp, data).run();
    } else if (Intent.ACTION_SEARCH.equals(action)) {
        final String pattern = intent.getStringExtra(SearchManager.QUERY);
        final Runnable runnable = new Runnable() {

            public void run() {
                final TextSearchPopup popup = (TextSearchPopup) myFBReaderApp.getPopupById(TextSearchPopup.ID);
                popup.initPosition();
                myFBReaderApp.MiscOptions.TextSearchPattern.setValue(pattern);
                if (myFBReaderApp.getTextView().search(pattern, true, false, false, false) != 0) {
                    runOnUiThread(new Runnable() {

                        public void run() {
                            myFBReaderApp.showPopup(popup.getId());
                        }
                    });
                } else {
                    runOnUiThread(new Runnable() {

                        public void run() {
                            UIMessageUtil.showErrorMessage(FBReader.this, "textNotFound");
                            popup.StartPosition = null;
                        }
                    });
                }
            }
        };
        UIUtil.wait("search", runnable, this);
    } else if (FBReaderIntents.Action.CLOSE.equals(intent.getAction())) {
        myCancelIntent = intent;
        myOpenBookIntent = null;
    } else if (FBReaderIntents.Action.PLUGIN_CRASH.equals(intent.getAction())) {
        final Book book = FBReaderIntents.getBookExtra(intent, myFBReaderApp.Collection);
        myFBReaderApp.ExternalBook = null;
        myOpenBookIntent = null;
        getCollection().bindToService(this, new Runnable() {

            public void run() {
                final BookCollectionShadow collection = getCollection();
                Book b = collection.getRecentBook(0);
                if (collection.sameBook(b, book)) {
                    b = collection.getRecentBook(1);
                }
                myFBReaderApp.openBook(b, null, null, myNotifier);
            }
        });
    } else {
        super.onNewIntent(intent);
    }
}
Also used : ExternalFormatPlugin(org.geometerplus.fbreader.formats.ExternalFormatPlugin) BookCollectionShadow(org.geometerplus.android.fbreader.libraryService.BookCollectionShadow) Uri(android.net.Uri)

Aggregations

Uri (android.net.Uri)1 BookCollectionShadow (org.geometerplus.android.fbreader.libraryService.BookCollectionShadow)1 ExternalFormatPlugin (org.geometerplus.fbreader.formats.ExternalFormatPlugin)1