Search in sources :

Example 1 with VerticalViewActivity

use of org.ebookdroid.ui.viewer.VerticalViewActivity in project LibreraReader by foobnix.

the class ExtUtils method openPDFInTextReflow.

public static void openPDFInTextReflow(final Activity a, final File file, final int page, final DocumentController dc) {
    if (ExtUtils.isNotValidFile(file)) {
        Toast.makeText(a, R.string.file_not_found, Toast.LENGTH_SHORT).show();
        return;
    }
    new AsyncTask() {

        AlertDialog dialog;

        Handler handler;

        @Override
        protected void onPreExecute() {
            TempHolder.get().isConverting = true;
            final AlertDialog.Builder builder = new AlertDialog.Builder(a);
            View view = LayoutInflater.from(a).inflate(R.layout.dialog_loading_book, null, false);
            final TextView text = (TextView) view.findViewById(R.id.text1);
            handler = new Handler() {

                @Override
                public void handleMessage(android.os.Message msg) {
                    text.setText(a.getString(R.string.please_wait) + " " + msg.what + "/100%");
                }
            };
            ImageView image = (ImageView) view.findViewById(R.id.onCancel);
            TintUtil.setTintImageWithAlpha(image);
            image.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LOG.d("loadingBook Cancel");
                    TempHolder.get().isConverting = false;
                    dialog.dismiss();
                }
            });
            builder.setView(view);
            builder.setCancelable(false);
            dialog = builder.show();
            dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }

        @Override
        protected Object doInBackground(Object... params) {
            try {
                return openPDFInTextReflowAsync(a, file, handler);
            } catch (RuntimeException e) {
                LOG.e(e);
                return null;
            }
        }

        @Override
        protected void onPostExecute(final Object result) {
            if (dialog != null) {
                try {
                    dialog.dismiss();
                } catch (Exception e) {
                    LOG.e(e);
                }
            }
            if (!TempHolder.get().isConverting) {
                return;
            }
            if (result != null) {
                Runnable run = new Runnable() {

                    @Override
                    public void run() {
                        if (a instanceof VerticalViewActivity) {
                            AppState.get().isAlwaysOpenAsMagazine = false;
                            AppState.get().isMusicianMode = false;
                            showDocumentWithoutDialog(a, (File) result, page);
                        } else if (a instanceof HorizontalViewActivity) {
                            AppState.get().isAlwaysOpenAsMagazine = true;
                            AppState.get().isMusicianMode = false;
                            showDocumentWithoutDialog(a, (File) result, page);
                        } else {
                            showDocument(a, (File) result);
                        }
                    }
                };
                if (dc != null) {
                    dc.onCloseActivityFinal(run);
                } else {
                    Safe.run(run);
                }
            }
        }
    }.execute();
}
Also used : AlertDialog(android.app.AlertDialog) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) AsyncTask(android.os.AsyncTask) Handler(android.os.Handler) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) OnClickListener(android.view.View.OnClickListener) TextView(android.widget.TextView) JSONObject(org.json.JSONObject) ImageView(android.widget.ImageView) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) File(java.io.File)

Example 2 with VerticalViewActivity

use of org.ebookdroid.ui.viewer.VerticalViewActivity in project LibreraReader by foobnix.

the class ShareDialog method show.

public static void show(final Activity a, final File file, final Runnable onDeleteAction, final int page, final DocumentWrapperUI ui, final DocumentController dc) {
    if (!ExtUtils.isExteralSD(file.getPath()) && ExtUtils.isNotValidFile(file)) {
        Toast.makeText(a, R.string.file_not_found, Toast.LENGTH_LONG).show();
        return;
    }
    final boolean isPDF = BookType.PDF.is(file.getPath());
    // a instanceof MainTabs2 ? false :
    final boolean isLibrary = false;
    // true;
    final boolean isMainTabs = a instanceof MainTabs2;
    List<String> items = new ArrayList<String>();
    if (isLibrary) {
        items.add(a.getString(R.string.library));
    }
    if (dc != null) {
        if (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameHorizontalMode);
        }
        if (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) {
            items.add(AppState.get().nameVerticalMode);
        }
        if (AppState.get().isMusicianMode == false) {
            items.add(AppState.get().nameMusicianMode);
        }
    }
    if (isPDF) {
        items.add(a.getString(R.string.make_text_reflow));
    }
    items.add(a.getString(R.string.open_with));
    items.add(a.getString(R.string.send_file));
    items.add(a.getString(R.string.export_bookmarks));
    final boolean canDelete = ExtUtils.isExteralSD(file.getPath()) ? true : file.canWrite();
    final boolean isShowInfo = !ExtUtils.isExteralSD(file.getPath());
    if (isMainTabs) {
        if (canDelete) {
            items.add(a.getString(R.string.delete));
        }
        items.add(a.getString(R.string.remove_from_library));
    }
    if (!isMainTabs) {
        items.add(a.getString(R.string.send_snapshot_of_the_page) + " " + (Math.max(page, 0) + 1) + "");
    }
    items.add(a.getString(R.string.tags));
    if (isShowInfo) {
        items.add(a.getString(R.string.file_info));
    }
    final AlertDialog.Builder builder = new AlertDialog.Builder(a);
    // builder.setTitle(R.string.choose_)//
    builder.setItems(items.toArray(new String[items.size()]), new DialogInterface.OnClickListener() {

        @Override
        public void onClick(final DialogInterface dialog, final int which) {
            int i = 0;
            if (isLibrary && which == i++) {
                a.finish();
                MainTabs2.startActivity(a, UITab.getCurrentTabIndex(UITab.SearchFragment));
            }
            if (dc != null && (a instanceof HorizontalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        if (AppState.get().isMusicianMode) {
                            AppState.get().isAlwaysOpenAsMagazine = true;
                        } else {
                            AppState.get().isAlwaysOpenAsMagazine = false;
                        }
                        AppState.get().isMusicianMode = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (dc != null && (a instanceof VerticalViewActivity || AppState.get().isMusicianMode) && which == i++) {
                if (dc != null) {
                    dc.onCloseActivityFinal(new Runnable() {

                        @Override
                        public void run() {
                            if (AppState.get().isMusicianMode) {
                                AppState.get().isAlwaysOpenAsMagazine = false;
                            } else {
                                AppState.get().isAlwaysOpenAsMagazine = true;
                            }
                            AppState.get().isMusicianMode = false;
                            ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                        }
                    });
                }
            }
            if (dc != null && AppState.get().isMusicianMode == false && which == i++) {
                dc.onCloseActivityFinal(new Runnable() {

                    @Override
                    public void run() {
                        AppState.get().isMusicianMode = true;
                        AppState.get().isAlwaysOpenAsMagazine = false;
                        ExtUtils.showDocumentWithoutDialog(a, file, page + 1);
                    }
                });
            }
            if (isPDF && which == i++) {
                ExtUtils.openPDFInTextReflow(a, file, page + 1, dc);
            }
            if (which == i++) {
                ExtUtils.openWith(a, file);
            } else if (which == i++) {
                ExtUtils.sendFileTo(a, file);
            } else if (which == i++) {
                ExtUtils.sendBookmarksTo(a, file);
            } else if (isMainTabs && canDelete && which == i++) {
                FileInformationDialog.dialogDelete(a, file, onDeleteAction);
            } else if (isMainTabs && which == i++) {
                FileMeta load = AppDB.get().load(file.getPath());
                if (load != null) {
                    load.setIsSearchBook(false);
                    AppDB.get().update(load);
                }
                EventBus.getDefault().post(new UpdateAllFragments());
            } else if (!isMainTabs && which == i++) {
                if (dc != null) {
                    ExtUtils.sharePage(a, file, page, dc.getPageUrl(page).toString());
                } else {
                    ExtUtils.sharePage(a, file, page, null);
                }
            } else if (which == i++) {
                Dialogs.showTagsDialog(a, file, null);
            } else if (isShowInfo && which == i++) {
                FileInformationDialog.showFileInfoDialog(a, file, onDeleteAction);
            }
        }
    });
    AlertDialog create = builder.create();
    create.setOnDismissListener(new OnDismissListener() {

        @Override
        public void onDismiss(DialogInterface dialog) {
            Keyboards.hideNavigation(a);
        }
    });
    create.show();
}
Also used : AlertDialog(android.app.AlertDialog) MainTabs2(com.foobnix.ui2.MainTabs2) VerticalViewActivity(org.ebookdroid.ui.viewer.VerticalViewActivity) DialogInterface(android.content.DialogInterface) UpdateAllFragments(com.foobnix.pdf.search.activity.msg.UpdateAllFragments) OnDismissListener(android.content.DialogInterface.OnDismissListener) ArrayList(java.util.ArrayList) HorizontalViewActivity(com.foobnix.pdf.search.activity.HorizontalViewActivity) FileMeta(com.foobnix.dao2.FileMeta)

Aggregations

AlertDialog (android.app.AlertDialog)2 HorizontalViewActivity (com.foobnix.pdf.search.activity.HorizontalViewActivity)2 VerticalViewActivity (org.ebookdroid.ui.viewer.VerticalViewActivity)2 DialogInterface (android.content.DialogInterface)1 OnDismissListener (android.content.DialogInterface.OnDismissListener)1 AsyncTask (android.os.AsyncTask)1 Handler (android.os.Handler)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 FileMeta (com.foobnix.dao2.FileMeta)1 UpdateAllFragments (com.foobnix.pdf.search.activity.msg.UpdateAllFragments)1 MainTabs2 (com.foobnix.ui2.MainTabs2)1 File (java.io.File)1 ArrayList (java.util.ArrayList)1 JSONObject (org.json.JSONObject)1