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());
}
});
}
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);
}
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);
}
}
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);
}
}
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;
}
}
}
Aggregations