Search in sources :

Example 1 with BookSettings

use of org.ebookdroid.common.settings.books.BookSettings in project LibreraReader by foobnix.

the class DragingDialogs method sliceDialog.

public static void sliceDialog(final FrameLayout anchor, final DocumentController controller, final Runnable onRefreshDoc, final ResultResponse<Integer> onMoveCut) {
    new DragingPopup(anchor.getContext().getString(R.string.split_pages_in_two), anchor, 300, 200) {

        SeekBar seek;

        EditText editPercent;

        Runnable updateUI = new Runnable() {

            @Override
            public void run() {
                seek.setProgress(AppState.get().cutP);
                editPercent.setText(AppState.get().cutP + "%");
                if (onMoveCut != null) {
                    onMoveCut.onResultRecive(AppState.get().cutP);
                }
                PageImageState.get().isShowCuttingLine = true;
            }
        };

        @Override
        public View getContentView(LayoutInflater inflater) {
            PageImageState.get().isShowCuttingLine = false;
            View view = inflater.inflate(R.layout.slice_dialog, null, false);
            editPercent = (EditText) view.findViewById(R.id.editPercent);
            seek = (SeekBar) view.findViewById(R.id.seekBar);
            seek.setMax(100);
            view.findViewById(R.id.imagePlus).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (AppState.get().cutP < 80) {
                        AppState.get().cutP += 1;
                    }
                    updateUI.run();
                }
            });
            view.findViewById(R.id.imageMinus).setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    if (AppState.get().cutP > 20) {
                        AppState.get().cutP -= 1;
                    }
                    updateUI.run();
                }
            });
            seek.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

                @Override
                public void onStopTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onStartTrackingTouch(SeekBar seekBar) {
                }

                @Override
                public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                    if (progress <= 20) {
                        progress = 20;
                    }
                    if (progress >= 80) {
                        progress = 80;
                    }
                    AppState.get().cutP = progress;
                    updateUI.run();
                }
            });
            Button buttonCancel = (Button) view.findViewById(R.id.buttonCancel);
            buttonCancel.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PageImageState.get().isShowCuttingLine = false;
                    AppState.get().isCut = false;
                    BookSettings bookSettings = SettingsManager.getBookSettings(controller.getCurrentBook().getPath());
                    boolean wasSplit = bookSettings.splitPages;
                    bookSettings.splitPages = false;
                    onRefreshDoc.run();
                    closeDialog();
                    if (wasSplit) {
                        controller.onGoToPage(controller.getCurentPage() / 2 + 1);
                    }
                }
            });
            Button buttonApply = (Button) view.findViewById(R.id.buttonApply);
            buttonApply.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    PageImageState.get().isShowCuttingLine = false;
                    AppState.get().isCut = true;
                    AppState.get().isCrop = false;
                    boolean init = SettingsManager.getBookSettings().splitPages;
                    SettingsManager.getBookSettings().updateFromAppState();
                    onRefreshDoc.run();
                    closeDialog();
                    if (!init) {
                        controller.onGoToPage(controller.getCurentPage() * 2 + 1);
                    }
                }
            });
            updateUI.run();
            return view;
        }
    }.show("cutDialog").setOnCloseListener(new Runnable() {

        @Override
        public void run() {
            PageImageState.get().isShowCuttingLine = false;
            EventBus.getDefault().post(new InvalidateMessage());
        }
    });
}
Also used : EditText(android.widget.EditText) SeekBar(android.widget.SeekBar) BookSettings(org.ebookdroid.common.settings.books.BookSettings) OnSeekBarChangeListener(android.widget.SeekBar.OnSeekBarChangeListener) ImageView(android.widget.ImageView) RecyclerView(android.support.v7.widget.RecyclerView) GridView(android.widget.GridView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) AbsListView(android.widget.AbsListView) SuppressLint(android.annotation.SuppressLint) Button(android.widget.Button) CompoundButton(android.widget.CompoundButton) LayoutInflater(android.view.LayoutInflater) OnClickListener(android.view.View.OnClickListener) InvalidateMessage(com.foobnix.pdf.search.activity.msg.InvalidateMessage)

Example 2 with BookSettings

use of org.ebookdroid.common.settings.books.BookSettings in project LibreraReader by foobnix.

the class HorizontalModeController method init.

public void init(final Activity activity) {
    PageImageState.get().cleanSelectedWords();
    PageImageState.get().pagesText.clear();
    LOG.d("DocumentControllerHorizontalView", "init begin");
    bookPath = getBookPathFromActivity(activity);
    AppState.get().lastBookPath = bookPath;
    BookSettings bs = SettingsManager.getBookSettings(bookPath);
    if (bs != null) {
        AppState.get().isCut = bs.splitPages;
        AppState.get().isCrop = bs.cropPages;
        AppState.get().isDouble = bs.doublePages;
        AppState.get().isDoubleCoverAlone = bs.doublePagesCover;
        AppState.get().isLocked = bs.isLocked;
        TempHolder.get().pageDelta = bs.pageDelta;
        if (AppState.get().isCropPDF && !isTextFormat) {
            AppState.get().isCrop = true;
        }
    }
    BookCSS.get().detectLang(bookPath);
    if (false) {
        PageImageState.get().needAutoFit = true;
    } else {
        if (TxtUtils.isNotEmpty(bookPath) && !ExtUtils.isTextFomat(bookPath)) {
            String string = matrixSP.getString(bookPath.hashCode() + "", "");
            LOG.d("MATRIX", "READ STR", string);
            if (TxtUtils.isEmpty(string) || AppState.get().isCut || AppState.get().isCrop) {
                PageImageState.get().needAutoFit = true;
            } else {
                PageImageState.get().needAutoFit = false;
            }
            Matrix matrix = PageImageState.fromString(string);
            PageImageState.get().getMatrix().set(matrix);
            LOG.d("MATRIX", "READ", bookPath.hashCode() + "", PageImageState.get().getMatrixAsString());
        }
    }
    if (AppState.get().isDouble && isTextFormat) {
        imageWidth = Dips.screenWidth() / 2;
    }
    FileMetaCore.checkOrCreateMetaInfo(activity);
    LOG.d("pagesCount", "init", imageWidth, imageHeight);
    String pasw = activity.getIntent().getStringExtra(EXTRA_PASSWORD);
    pasw = TxtUtils.nullToEmpty(pasw);
    codeDocument = ImageExtractor.getNewCodecContext(getBookPath(), pasw, imageWidth, imageHeight);
    if (codeDocument != null) {
        pagesCount = codeDocument.getPageCount();
    } else {
        pagesCount = 0;
    }
    if (pagesCount == -1) {
        throw new IllegalArgumentException("Pages count = -1");
    }
    try {
        if (pagesCount > 0) {
            FileMeta meta = AppDB.get().load(bs.fileName);
            if (meta != null) {
                meta.setPages(pagesCount);
                AppDB.get().update(meta);
            }
        }
    } catch (Exception e) {
        LOG.e(e);
    }
    // int charsCount = 0;
    // for (int i = 0; i <= pagesCount; i++) {
    // CodecPage page2 = codeDocument.getPage(i);
    // charsCount += page2.getCharCount();
    // page2.recycle();
    // }
    // LOG.d("total-chars", charsCount);
    AppDB.get().addRecent(bookPath);
    getPageFromUri();
// loadOutline(null);
}
Also used : Matrix(android.graphics.Matrix) BookSettings(org.ebookdroid.common.settings.books.BookSettings) FileMeta(com.foobnix.dao2.FileMeta)

Example 3 with BookSettings

use of org.ebookdroid.common.settings.books.BookSettings in project LibreraReader by foobnix.

the class TTSService method savePage.

public void savePage() {
    AppState.get().save(getApplicationContext());
    try {
        BookSettings bs = SettingsManager.getBookSettings(AppState.get().lastBookPath);
        bs.currentPageChanged(AppState.get().lastBookPage);
        bs.save();
        LOG.d(TAG, "currentPageChanged ", AppState.get().lastBookPage, AppState.get().lastBookPath);
    } catch (Exception e) {
        LOG.e(e);
    }
}
Also used : BookSettings(org.ebookdroid.common.settings.books.BookSettings)

Example 4 with BookSettings

use of org.ebookdroid.common.settings.books.BookSettings in project LibreraReader by foobnix.

the class SettingsManager method updateTempPage.

public static void updateTempPage(String fileName, int pageNumber) {
    try {
        BookSettings bookSettings = getTempBookSettings(fileName);
        bookSettings.currentPage = new PageIndex(pageNumber, pageNumber);
        db.storeBookSettings(bookSettings);
        LOG.d("updateTempPage", fileName, pageNumber);
    } catch (Exception e) {
        LOG.e(e);
    }
}
Also used : BookSettings(org.ebookdroid.common.settings.books.BookSettings) PageIndex(org.ebookdroid.core.PageIndex)

Example 5 with BookSettings

use of org.ebookdroid.common.settings.books.BookSettings in project LibreraReader by foobnix.

the class VScrollController method invalidatePageSizes.

/**
 * {@inheritDoc}
 *
 * @see org.ebookdroid.ui.viewer.IViewController#invalidatePageSizes(org.ebookdroid.ui.viewer.IViewController.InvalidateSizeReason,
 *      org.ebookdroid.core.Page)
 */
@Override
public final synchronized void invalidatePageSizes(final InvalidateSizeReason reason, final Page changedPage) {
    if (!isInitialized) {
        return;
    }
    if (reason == InvalidateSizeReason.PAGE_ALIGN) {
        return;
    }
    final int width = getWidth();
    final int height = getHeight();
    final BookSettings bookSettings = SettingsManager.getBookSettings();
    final PageAlign pageAlign = DocumentViewMode.getPageAlign(bookSettings);
    if (changedPage == null) {
        float heightAccum = 0;
        for (final Page page : model.getPages()) {
            final RectF pageBounds = calcPageBounds(pageAlign, page.getAspectRatio(), width, height);
            pageBounds.offset(0, heightAccum);
            page.setBounds(pageBounds);
            heightAccum += pageBounds.height() + 3;
        }
    } else {
        float heightAccum = changedPage.getBounds(1.0f).top;
        for (final Page page : model.getPages(changedPage.index.viewIndex)) {
            final RectF pageBounds = calcPageBounds(pageAlign, page.getAspectRatio(), width, height);
            pageBounds.offset(0, heightAccum);
            page.setBounds(pageBounds);
            heightAccum += pageBounds.height() + 3;
        }
    }
}
Also used : PageAlign(org.ebookdroid.common.settings.types.PageAlign) RectF(android.graphics.RectF) BookSettings(org.ebookdroid.common.settings.books.BookSettings)

Aggregations

BookSettings (org.ebookdroid.common.settings.books.BookSettings)15 RectF (android.graphics.RectF)3 PageIndex (org.ebookdroid.core.PageIndex)3 Matrix (android.graphics.Matrix)2 FileMeta (com.foobnix.dao2.FileMeta)2 PageAlign (org.ebookdroid.common.settings.types.PageAlign)2 SuppressLint (android.annotation.SuppressLint)1 Handler (android.os.Handler)1 RecyclerView (android.support.v7.widget.RecyclerView)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 AbsListView (android.widget.AbsListView)1 AdapterView (android.widget.AdapterView)1 Button (android.widget.Button)1 CompoundButton (android.widget.CompoundButton)1 EditText (android.widget.EditText)1 GridView (android.widget.GridView)1 ImageView (android.widget.ImageView)1 ListView (android.widget.ListView)1