use of org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordException in project LibreraReader by foobnix.
the class HorizontalViewActivity method onCreate.
@Override
protected void onCreate(final Bundle savedInstanceState) {
intetrstialTimeoutSec = ADS.FULL_SCREEN_TIMEOUT_SEC;
LOG.d("getRequestedOrientation", AppState.get().orientation, getRequestedOrientation());
handler = new Handler();
handlerTimer = new Handler();
flippingHandler = new Handler();
flippingTimer = 0;
long crateBegin = System.currentTimeMillis();
requestWindowFeature(Window.FEATURE_NO_TITLE);
BrightnessHelper.applyBrigtness(this);
if (AppState.get().isDayNotInvert) {
setTheme(R.style.StyledIndicatorsWhite);
} else {
setTheme(R.style.StyledIndicatorsBlack);
}
DocumentController.doRotation(this);
clickUtils = new ClickUtils();
super.onCreate(savedInstanceState);
if (PasswordDialog.isNeedPasswordDialog(this)) {
return;
}
boolean isTextFomat = ExtUtils.isTextFomat(getIntent());
AppState.get().load(this);
// AppState.get().isCut = false;
PageImageState.get().isShowCuttingLine = false;
PageImageState.get().cleanSelectedWords();
setContentView(R.layout.activity_horiziontal_view);
Android6.checkPermissions(this);
viewPager = (VerticalViewPager) findViewById(R.id.pager);
overlay = findViewById(R.id.overlay);
overlay.setVisibility(View.VISIBLE);
progressDraw = (ProgressDraw) findViewById(R.id.progressDraw);
actionBar = (LinearLayout) findViewById(R.id.actionBar);
bottomBar = findViewById(R.id.bottomBar);
bottomIndicators = findViewById(R.id.bottomIndicators);
adFrame = findViewById(R.id.adFrame);
anchor = (FrameLayout) findViewById(R.id.anchor);
moveCenter = findViewById(R.id.moveCenter);
currentSeek = (TextView) findViewById(R.id.currentSeek);
maxSeek = (TextView) findViewById(R.id.maxSeek);
toastBrightnessText = (TextView) findViewById(R.id.toastBrightnessText);
toastBrightnessText.setVisibility(View.GONE);
TintUtil.setDrawableTint(toastBrightnessText.getCompoundDrawables()[0], Color.WHITE);
modeName = (TextView) findViewById(R.id.modeName);
modeName.setText(AppState.get().nameHorizontalMode);
pagesCountIndicator = (TextView) findViewById(R.id.pagesCountIndicator);
flippingIntervalView = (TextView) findViewById(R.id.flippingIntervalView);
pagesTime = (TextView) findViewById(R.id.pagesTime);
pagesPower = (TextView) findViewById(R.id.pagesPower);
linkHistory = (ImageView) findViewById(R.id.linkHistory);
onMove = (ImageView) findViewById(R.id.onMove);
onMove.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DragingDialogs.onMoveDialog(anchor, dc, onRefresh, reloadDoc);
}
});
currentSeek.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showDeltaPage(anchor, dc, dc.getCurentPageFirst1(), onRefresh);
return true;
}
});
maxSeek.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Dialogs.showDeltaPage(anchor, dc, dc.getCurentPageFirst1(), onRefresh);
return true;
}
});
updateSeekBarColorAndSize();
titleTxt = (TextView) findViewById(R.id.title);
chapterView = (TextView) findViewById(R.id.chapter);
linkHistory.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
dc.onLinkHistory();
showHideHistory();
}
});
linkHistory.setVisibility(View.GONE);
seekBar = (SeekBar) findViewById(R.id.seekBar);
if (AppState.get().isRTL) {
if (Build.VERSION.SDK_INT >= 11) {
seekBar.setRotation(180);
}
}
onPageFlip1 = findViewById(R.id.autoScroll);
onPageFlip1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
DragingDialogs.pageFlippingDialog(anchor, dc, onRefresh);
}
});
final ImageView onFullScreen = (ImageView) findViewById(R.id.onFullScreen);
onFullScreen.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isFullScreen = !AppState.get().isFullScreen;
onFullScreen.setImageResource(AppState.get().isFullScreen ? R.drawable.glyphicons_487_fit_frame_to_image : R.drawable.glyphicons_488_fit_image_to_frame);
DocumentController.chooseFullScreen(HorizontalViewActivity.this, AppState.get().isFullScreen);
if (dc.isTextFormat()) {
if (onRefresh != null) {
onRefresh.run();
}
nullAdapter();
dc.restartActivity();
}
}
});
onFullScreen.setImageResource(AppState.get().isFullScreen ? R.drawable.glyphicons_487_fit_frame_to_image : R.drawable.glyphicons_488_fit_image_to_frame);
ImageView dayNightButton = (ImageView) findViewById(R.id.bookNight);
dayNightButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
v.setEnabled(false);
AppState.get().isDayNotInvert = !AppState.get().isDayNotInvert;
nullAdapter();
dc.restartActivity();
}
});
if (Dips.isEInk(this)) {
dayNightButton.setVisibility(View.GONE);
AppState.get().isDayNotInvert = true;
}
onBC = (UnderlineImageView) findViewById(R.id.onBC);
onBC.underline(AppState.get().isEnableBC);
onBC.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.contrastAndBrigtness(anchor, dc, reloadDocBrigntness, reloadDoc);
}
});
dayNightButton.setImageResource(!AppState.get().isDayNotInvert ? R.drawable.glyphicons_232_sun : R.drawable.glyphicons_2_moon);
moveCenter.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
authoFit();
}
});
onBC.setVisibility(isTextFomat ? View.GONE : View.VISIBLE);
if (DocumentController.isEinkOrMode(this)) {
onBC.setVisibility(View.VISIBLE);
}
onMove.setVisibility(DocumentController.isEinkOrMode(this) && !isTextFomat ? View.VISIBLE : View.GONE);
findViewById(R.id.thumbnail).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.thumbnailDialog(anchor, dc);
}
});
findViewById(R.id.onShowSearch).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
showSearchDialog();
}
});
outline = (ImageView) findViewById(R.id.onDocDontext);
outline.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.showContent(anchor, dc);
}
});
findViewById(R.id.onBookmarks).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.addBookmarks(anchor, dc, new Runnable() {
@Override
public void run() {
showHideHistory();
}
});
}
});
findViewById(R.id.onBookmarks).setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(final View arg0) {
DragingDialogs.addBookmarksLong(anchor, dc);
return true;
}
});
findViewById(R.id.onRecent).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.recentBooks(anchor, dc);
}
});
textToSpeach = (ImageView) findViewById(R.id.textToSpeach);
textToSpeach.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
LOG.d("bookTTS", AppState.get().isDoubleCoverAlone, AppState.get().isDouble, AppState.get().isCut);
if (AppState.get().isDouble || AppState.get().isCut) {
modeOnePage();
return;
}
DragingDialogs.textToSpeachDialog(anchor, dc);
}
});
ttsActive = (ImageView) findViewById(R.id.ttsActive);
onTTSStatus(null);
ttsActive.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.textToSpeachDialog(anchor, dc);
}
});
ttsActive.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
Vibro.vibrate();
TTSEngine.get().stop();
ttsActive.setVisibility(View.GONE);
return true;
}
});
onModeChange = (ImageView) findViewById(R.id.onModeChange);
onModeChange.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
MyPopupMenu p = new MyPopupMenu(v.getContext(), v);
p.getMenu().add(R.string.one_page).setIcon(R.drawable.glyphicons_two_page_one).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_page_one);
AppState.get().isDouble = false;
AppState.get().isDoubleCoverAlone = false;
AppState.get().isCut = false;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
p.getMenu().add(R.string.two_pages).setIcon(R.drawable.glyphicons_two_pages_12).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_pages_12);
AppState.get().isDouble = true;
AppState.get().isCut = false;
AppState.get().isDoubleCoverAlone = false;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
if (!dc.isTextFormat()) {
p.getMenu().add(R.string.two_pages_cover).setIcon(R.drawable.glyphicons_two_pages_23).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_two_pages_23);
AppState.get().isDouble = true;
AppState.get().isCut = false;
AppState.get().isDoubleCoverAlone = true;
SettingsManager.getBookSettings().updateFromAppState();
if (dc.isTextFormat()) {
nullAdapter();
dc.restartActivity();
dc.cleanImageMatrix();
} else {
TTSEngine.get().stop();
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
}
return false;
}
});
}
if (!dc.isTextFormat()) {
p.getMenu().add(R.string.half_page).setIcon(R.drawable.glyphicons_page_split).setOnMenuItemClickListener(new OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
closeDialogs();
onModeChange.setImageResource(R.drawable.glyphicons_page_split);
AppState.get().isDouble = false;
AppState.get().isCut = true;
// AppState.get().isCrop = false;
SettingsManager.getBookSettings().updateFromAppState();
TTSEngine.get().stop();
// onCrop.underline(AppState.get().isCrop);
dc.cleanImageMatrix();
reloadDoc.run();
authoFit();
return false;
}
});
}
p.show();
Keyboards.hideNavigation(HorizontalViewActivity.this);
}
});
onCrop = (UnderlineImageView) findViewById(R.id.onCrop);
onCrop.setVisibility(isTextFomat ? View.GONE : View.VISIBLE);
onCrop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isCrop = !AppState.get().isCrop;
SettingsManager.getBookSettings().cropPages = AppState.get().isCrop;
reloadDoc.run();
onCrop.underline(AppState.get().isCrop);
PageImageState.get().isAutoFit = true;
EventBus.getDefault().post(new MessageAutoFit(viewPager.getCurrentItem()));
}
});
final View bookMenu = findViewById(R.id.bookMenu);
bookMenu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
ShareDialog.show(HorizontalViewActivity.this, dc.getCurrentBook(), new Runnable() {
@Override
public void run() {
if (dc.getCurrentBook().delete()) {
TempHolder.listHash++;
AppDB.get().deleteBy(dc.getCurrentBook().getPath());
dc.getActivity().finish();
}
}
}, dc.getCurentPage(), null, dc);
Keyboards.hideNavigation(HorizontalViewActivity.this);
}
});
modeName.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
bookMenu.performClick();
}
});
modeName.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(View v) {
dc.onChangeTextSelection();
AppState.get().isEditMode = false;
hideShow();
return true;
}
});
findViewById(R.id.bookPref).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DragingDialogs.preferences(anchor, dc, onRefresh, reloadDoc);
}
});
onClose = findViewById(R.id.bookClose);
onClose.setVisibility(View.INVISIBLE);
onClose.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
nullAdapter();
closeDialogs();
showInterstial();
}
});
onClose.setOnLongClickListener(new OnLongClickListener() {
@Override
public boolean onLongClick(final View v) {
Vibro.vibrate();
CloseAppDialog.showOnLongClickDialog(HorizontalViewActivity.this, v, dc);
return true;
}
});
findViewById(R.id.editTop2).setVisibility(View.GONE);
findViewById(R.id.nextTypeBootom).setVisibility(View.GONE);
lockModelImage = (ImageView) findViewById(R.id.lockUnlock);
lockModelImage.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
AppState.get().isLocked = !AppState.get().isLocked;
updateLockMode();
}
});
updateLockMode();
Keyboards.hideNavigationOnCreate(HorizontalViewActivity.this);
currentSeek.setVisibility(View.GONE);
maxSeek.setVisibility(View.GONE);
seekBar.setVisibility(View.INVISIBLE);
bottomIndicators.setVisibility(View.GONE);
titleTxt.setText(HorizontalModeController.getTempTitle(this));
loadinAsyncTask = new CopyAsyncTask() {
AlertDialog dialog;
private boolean isCancelled = false;
long start = 0;
@Override
protected void onPreExecute() {
start = System.currentTimeMillis();
TempHolder.get().loadingCancelled = false;
dialog = Dialogs.loadingBook(HorizontalViewActivity.this, new Runnable() {
@Override
public void run() {
isCancelled = true;
TempHolder.get().loadingCancelled = true;
CacheZipUtils.removeFiles(CacheZipUtils.CACHE_BOOK_DIR.listFiles());
finish();
}
});
}
@Override
protected Object doInBackground(Object... params) {
try {
LOG.d("doRotation(this)", AppState.get().orientation, HorizontalViewActivity.this.getRequestedOrientation());
try {
while (viewPager.getHeight() == 0) {
Thread.sleep(250);
}
int count = 0;
if (AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE || AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE) {
while (viewPager.getHeight() > viewPager.getWidth() && count < 20) {
Thread.sleep(250);
count++;
}
} else if (AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_PORTRAIT || AppState.get().orientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
while (viewPager.getWidth() > viewPager.getHeight() && count < 20) {
Thread.sleep(250);
count++;
}
}
} catch (InterruptedException e) {
}
LOG.d("viewPager", viewPager.getHeight() + "x" + viewPager.getWidth());
initAsync(viewPager.getWidth(), viewPager.getHeight());
} catch (MuPdfPasswordException e) {
return -1;
} catch (RuntimeException e) {
LOG.e(e);
return -2;
}
return 0;
}
@Override
protected void onCancelled() {
try {
if (dialog != null) {
dialog.dismiss();
}
} catch (Exception e) {
}
isCancelled = true;
}
@Override
protected void onPostExecute(Object result) {
if (LOG.isEnable) {
long time = System.currentTimeMillis() - start;
// modeName.setText("" + time / 1000);
}
try {
// onClose.setVisibility(View.VISIBLE);
LOG.d("RESULT", result);
if (dialog != null) {
dialog.dismiss();
}
} catch (Exception e) {
}
if (isCancelled) {
LOG.d("Cancelled");
finish();
return;
}
if ((Integer) result == -2) {
Toast.makeText(HorizontalViewActivity.this, R.string.msg_unexpected_error, Toast.LENGTH_SHORT).show();
AppState.get().isEditMode = true;
hideShow();
return;
}
if ((Integer) result == -1) {
final EditText input = new EditText(HorizontalViewActivity.this);
input.setSingleLine(true);
input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
AlertDialog.Builder dialog = new AlertDialog.Builder(HorizontalViewActivity.this);
dialog.setTitle(R.string.enter_password);
dialog.setView(input);
dialog.setCancelable(false);
dialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
dc.onCloseActivityFinal(null);
}
});
dialog.setPositiveButton(R.string.open_file, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
final String txt = input.getText().toString();
if (TxtUtils.isNotEmpty(txt)) {
dialog.dismiss();
dc.onCloseActivityFinal(new Runnable() {
@Override
public void run() {
getIntent().putExtra(HorizontalModeController.EXTRA_PASSWORD, txt);
startActivity(getIntent());
}
});
} else {
dc.onCloseActivityFinal(null);
}
}
});
AlertDialog show = dialog.show();
} else {
currentSeek.setVisibility(View.VISIBLE);
maxSeek.setVisibility(View.VISIBLE);
seekBar.setVisibility(View.VISIBLE);
bottomIndicators.setVisibility(View.VISIBLE);
onModeChange.setVisibility(View.VISIBLE);
dc.initHandler();
AppState.get().lastClosedActivity = HorizontalViewActivity.class.getSimpleName();
AppState.get().lastMode = HorizontalViewActivity.class.getSimpleName();
LOG.d("lasta save", AppState.get().lastClosedActivity);
PageImageState.get().isAutoFit = PageImageState.get().needAutoFit;
if (ExtUtils.isTextFomat(getIntent())) {
PageImageState.get().isAutoFit = true;
// moveCenter.setVisibility(View.GONE);
} else if (AppState.get().isLockPDF) {
// moveCenter.setVisibility(View.VISIBLE);
AppState.get().isLocked = true;
}
if (ExtUtils.isNoTextLayerForamt(dc.getCurrentBook().getPath())) {
TintUtil.setTintImageWithAlpha(textToSpeach, Color.LTGRAY);
}
if (dc.isTextFormat()) {
// TintUtil.setTintImage(lockModelImage, Color.LTGRAY);
}
loadUI();
// AppState.get().isEditMode = false; //remember last
updateUI(dc.getPageFromUri());
hideShow();
EventBus.getDefault().post(new MessageAutoFit(dc.getPageFromUri()));
seekBar.setOnSeekBarChangeListener(onSeek);
showHideInfoToolBar();
testScreenshots();
isInitPosistion = Dips.screenHeight() > Dips.screenWidth();
isInitOrientation = AppState.get().orientation;
updateIconMode();
onCrop.setVisibility(dc.isTextFormat() ? View.GONE : View.VISIBLE);
onMove.setVisibility(DocumentController.isEinkOrMode(HorizontalViewActivity.this) && !dc.isTextFormat() ? View.VISIBLE : View.GONE);
onBC.setVisibility(dc.isTextFormat() ? View.GONE : View.VISIBLE);
if (Dips.isEInk(dc.getActivity()) || AppState.get().isInkMode) {
onBC.setVisibility(View.VISIBLE);
}
onCrop.underline(AppState.get().isCrop);
onCrop.invalidate();
// RecentUpates.updateAll(HorizontalViewActivity.this);
}
}
};
loadinAsyncTask.executeOnExecutor(Executors.newSingleThreadExecutor());
updateIconMode();
BrightnessHelper.updateOverlay(overlay);
//
tinUI();
LOG.d("INIT end", (float) (System.currentTimeMillis() - crateBegin) / 1000);
anchor.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override
public void onGlobalLayout() {
if (anchor.getVisibility() == View.VISIBLE) {
adFrame.setVisibility(View.GONE);
adFrame.setClickable(false);
} else {
if (AppState.get().isEditMode) {
adFrame.setVisibility(View.VISIBLE);
adFrame.setClickable(true);
} else {
adFrame.setVisibility(View.GONE);
adFrame.setClickable(false);
}
}
if (Build.VERSION.SDK_INT >= 11) {
if (anchor.getX() < 0) {
anchor.setX(0);
}
if (anchor.getY() < 0) {
anchor.setY(0);
}
}
}
});
}
use of org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordException in project LibreraReader by foobnix.
the class AbstractCodecContext method openDocument.
@Override
public CodecDocument openDocument(String fileNameOriginal, String password) {
LOG.d("Open-Document", fileNameOriginal);
// TempHolder.get().loadingCancelled = false;
if (ExtUtils.isZip(fileNameOriginal)) {
LOG.d("Open-Document ZIP", fileNameOriginal);
return openDocumentInnerCanceled(fileNameOriginal, password);
}
LOG.d("Open-Document 2 LANG:", BookCSS.get().hypenLang, fileNameOriginal);
File cacheFileName = getCacheFileName(fileNameOriginal);
CacheZipUtils.removeFiles(CacheZipUtils.CACHE_BOOK_DIR.listFiles(), cacheFileName);
if (cacheFileName != null && cacheFileName.isFile()) {
LOG.d("Open-Document from cache", fileNameOriginal);
return openDocumentInnerCanceled(fileNameOriginal, password);
}
CacheZipUtils.cacheLock.lock();
CacheZipUtils.createAllCacheDirs();
try {
String fileName = CacheZipUtils.extracIfNeed(fileNameOriginal, CacheDir.ZipApp).unZipPath;
LOG.d("Open-Document extract", fileName);
if (!ExtUtils.isValidFile(fileName)) {
return null;
}
try {
return openDocumentInnerCanceled(fileName, password);
} catch (MuPdfPasswordException e) {
throw new MuPdfPasswordRequiredException();
} catch (Throwable e) {
LOG.e(e);
return null;
}
} finally {
CacheZipUtils.cacheLock.unlock();
}
}
use of org.ebookdroid.droids.mupdf.codec.exceptions.MuPdfPasswordException in project LibreraReader by foobnix.
the class ImageExtractor method getStreamInner.
public synchronized InputStream getStreamInner(final String imageUri) throws IOException {
LOG.d("TEST", "url: " + imageUri);
if (imageUri.startsWith(Safe.TXT_SAFE_RUN)) {
LOG.d("MUPDF!", Safe.TXT_SAFE_RUN, "begin", imageUri);
// }
return baseImage.getStream("assets://opds/web.png", null);
}
if (imageUri.startsWith("https")) {
Request request = //
new Request.Builder().header("User-Agent", OPDS.USER_AGENT).url(//
imageUri).build();
LOG.d("https!!!", imageUri);
return OPDS.client.newCall(request).execute().body().byteStream();
}
if (imageUri.startsWith("data:")) {
String uri = imageUri;
// uri = uri.replace("data:image/png;base64,", "");
// uri = uri.replace("data:image/jpeg;base64,", "");
// uri = uri.replace("data:image/jpg;base64,", "");
// uri = uri.replace("data:image/gif;base64,", "");
uri = uri.substring(uri.indexOf(",") + 1);
LOG.d("Load image data ", uri);
return new ByteArrayInputStream(Base64.decode(uri, Base64.DEFAULT));
}
if (!imageUri.startsWith("{")) {
return baseImage.getStream(imageUri, null);
}
if (sp.contains("" + imageUri.hashCode())) {
LOG.d("Error FILE", imageUri);
return messageFile("#crash", "");
}
final PageUrl pageUrl = PageUrl.fromString(imageUri);
String path = pageUrl.getPath();
if (ExtUtils.isExteralSD(path)) {
if (ExtUtils.isImagePath(path)) {
return c.getContentResolver().openInputStream(Uri.parse(path));
}
return messageFile("", "");
}
File file = new File(path);
try {
if (ExtUtils.isImageFile(file)) {
FileMeta fileMeta = AppDB.get().getOrCreate(path);
FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
AppDB.get().update(fileMeta);
return BaseExtractor.decodeImage(path, IMG.getImageSize());
}
if (path.endsWith("json")) {
FileMeta fileMeta = AppDB.get().getOrCreate(path);
FileMetaCore.get().upadteBasicMeta(fileMeta, new File(path));
AppDB.get().update(fileMeta);
return messageFile("#json", "");
}
if (!file.isFile()) {
return messageFile("#no file", "");
}
sp.edit().putBoolean("" + imageUri.hashCode(), true).commit();
int page = pageUrl.getPage();
if (pageUrl.getHeight() == 0) {
pageUrl.setHeight((int) (pageUrl.getWidth() * 1.5));
}
if (page == COVER_PAGE || page == COVER_PAGE_WITH_EFFECT) {
try {
MagicHelper.isNeedBC = false;
Bitmap proccessCoverPage = proccessCoverPage(pageUrl);
return generalCoverWithEffect(pageUrl, proccessCoverPage);
} finally {
MagicHelper.isNeedBC = true;
}
} else if (page == COVER_PAGE_NO_EFFECT) {
ByteArrayInputStream bitmapToStream = bitmapToStream(proccessCoverPage(pageUrl));
return bitmapToStream;
} else {
if (pageUrl.isDouble()) {
LOG.d("isDouble", pageUrl.getHeight(), pageUrl.getWidth());
if (AppState.get().isDoubleCoverAlone) {
pageUrl.setPage(pageUrl.getPage() - 1);
}
Bitmap bitmap1 = proccessOtherPage(pageUrl, null);
pageUrl.setPage(pageUrl.getPage() + 1);
Bitmap bitmap2 = null;
if (pageUrl.getPage() < pageCount) {
bitmap2 = proccessOtherPage(pageUrl, null);
} else {
bitmap2 = Bitmap.createBitmap(bitmap1);
Canvas canvas = new Canvas(bitmap2);
canvas.drawColor(Color.WHITE);
}
int maxH = Math.max(bitmap1.getHeight(), bitmap2.getHeight());
Bitmap bitmap = Bitmap.createBitmap(bitmap1.getWidth() + bitmap2.getWidth(), maxH, Bitmap.Config.RGB_565);
Canvas canvas = new Canvas(bitmap);
canvas.drawColor(MagicHelper.getBgColor());
if (AppState.get().isCutRTL) {
canvas.drawBitmap(bitmap2, 0, (maxH - bitmap2.getHeight()) / 2, null);
canvas.drawBitmap(bitmap1, bitmap2.getWidth(), (maxH - bitmap1.getHeight()) / 2, null);
} else {
canvas.drawBitmap(bitmap1, 0, (maxH - bitmap1.getHeight()) / 2, null);
canvas.drawBitmap(bitmap2, bitmap1.getWidth(), (maxH - bitmap2.getHeight()) / 2, null);
}
bitmap1.recycle();
bitmap2.recycle();
return bitmapToStreamRAW(bitmap);
}
return bitmapToStreamRAW(proccessOtherPage(pageUrl, null));
}
} catch (MuPdfPasswordException e) {
return messageFile("#password", file.getName());
} catch (final Exception e) {
LOG.e(e);
return messageFile("#error", "");
} catch (OutOfMemoryError e2) {
AppState.get().pagesInMemory = 1;
return messageFile("#error", "");
} finally {
sp.edit().remove("" + imageUri.hashCode()).commit();
}
}
Aggregations