private void handleHighlightAyah(int sura, int ayah, HighlightType type, boolean scrollToAyah) { mImageView.highlightAyah(sura, ayah, type); if (scrollToAyah && mQuranPageLayout.canScroll()) { final RectF highlightBounds = ImageAyahUtils.getYBoundsForHighlight(mCoordinatesData, sura, ayah); if (highlightBounds != null) { int screenHeight = QuranScreenInfo.getInstance().getHeight(); Matrix matrix = mImageView.getImageMatrix(); matrix.mapRect(highlightBounds); int currentScrollY = mQuranPageLayout.getCurrentScrollY(); final boolean topOnScreen = highlightBounds.top > currentScrollY && highlightBounds.top < currentScrollY + screenHeight; final boolean bottomOnScreen = highlightBounds.bottom > currentScrollY && highlightBounds.bottom < currentScrollY + screenHeight; if (!topOnScreen || !bottomOnScreen) { int y = (int) highlightBounds.top - (int) (0.05 * screenHeight); mQuranPageLayout.smoothScrollLayoutTo(y); } } } mImageView.invalidate(); }
@Override public void onLoadImageResponse(BitmapDrawable drawable, Response response) { pageLoadTask = null; if (mQuranPageLayout == null || !isAdded()) { return; } if (drawable != null) { mImageView.setImageDrawable(drawable); // TODO we should toast a warning if we couldn't save the image // (which would likely happen if we can't write to the sdcard, // but just got the page from the web). } else if (response != null) { // failed to get the image... let's notify the user final int errorCode = response.getErrorCode(); final int errorRes; switch (errorCode) { case Response.ERROR_SD_CARD_NOT_FOUND: errorRes = R.string.sdcard_error; break; case Response.ERROR_DOWNLOADING_ERROR: errorRes = R.string.download_error_network; break; default: errorRes = R.string.download_error_general; } mQuranPageLayout.showError(errorRes); mQuranPageLayout.setOnClickListener( v -> { if (ayahSelectedListener != null) { ayahSelectedListener.onClick(EventType.SINGLE_TAP); } }); } }
@Override public View onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final Context context = getActivity(); mQuranPageLayout = new QuranImagePageLayout(context); mQuranPageLayout.setPageController(this, pageNumber); mImageView = mQuranPageLayout.getImageView(); if (mCoordinatesData != null) { mImageView.setCoordinateData(mCoordinatesData); } updateView(); justCreated = true; return mQuranPageLayout; }
@Override public void updateView() { Context context = getActivity(); if (context == null || !isAdded()) { return; } final QuranSettings settings = QuranSettings.getInstance(context); final boolean useNewBackground = settings.useNewBackground(); final boolean isNightMode = settings.isNightMode(); overlayText = settings.shouldOverlayPageInfo(); mQuranPageLayout.updateView(isNightMode, useNewBackground, 1); if (!settings.highlightBookmarks()) { mImageView.unHighlight(HighlightType.BOOKMARK); } }
@Override public AyahToolBar.AyahToolBarPosition getToolBarPosition( int sura, int ayah, int toolBarWidth, int toolBarHeight) { final List<AyahBounds> bounds = mCoordinatesData == null ? null : mCoordinatesData.get(sura + ":" + ayah); final int screenWidth = mImageView == null ? 0 : mImageView.getWidth(); if (bounds != null && screenWidth > 0) { final int screenHeight = QuranScreenInfo.getInstance().getHeight(); AyahToolBar.AyahToolBarPosition position = ImageAyahUtils.getToolBarPosition( bounds, mImageView.getImageMatrix(), screenWidth, screenHeight, toolBarWidth, toolBarHeight); // If we're in landscape mode (wrapped in SV) update the y-offset position.yScroll = 0 - mQuranPageLayout.getCurrentScrollY(); return position; } return null; }
@Override public void handleRetryClicked() { mQuranPageLayout.setOnClickListener(null); mQuranPageLayout.setClickable(false); downloadImage(); }