Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Header and Footer Text #1500

Merged
merged 3 commits into from
Dec 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added app/src/main/assets/UthmanTN1Ver10.otf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ void onSetPageBounds(PageCoordinates pageCoordinates) {
String juzText = quranDisplayData.getJuzDisplayStringForPage(context, page);
String pageText = QuranUtils.getLocalizedNumber(context, page);
String rub3Text = QuranDisplayHelper.displayRub3(context, quranInfo, page);
ayahView.setOverlayText(suraText, juzText, pageText, rub3Text);
ayahView.setOverlayText(context, suraText, juzText, pageText, rub3Text);
}
ayahView.setPageData(pageCoordinates, imageDrawHelpers);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public static String displayRub3(Context context, QuranInfo quranInfo, int page)
}
int hizb = (rub3 / 4) + 1;
StringBuilder sb = new StringBuilder();
sb.append(" , ");
sb.append(context.getString(R.string.comma_with_spaces));
int remainder = rub3 % 4;
if (remainder == 1) {
sb.append(context.getString(R.string.quran_rob3)).append(' ');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class TypefaceManager {

private static Typeface typeface;
private static Typeface arabicTafseerTypeface;
private static Typeface arabicHeaderFooterTypeface;

public static Typeface getUthmaniTypeface(@NonNull Context context) {
if (typeface == null) {
Expand All @@ -38,4 +39,11 @@ public static Typeface getTafseerTypeface(@NonNull Context context) {
}
return arabicTafseerTypeface;
}

public static Typeface getHeaderFooterTypeface(@NonNull Context context) {
if (arabicHeaderFooterTypeface == null) {
arabicHeaderFooterTypeface = Typeface.createFromAsset(context.getAssets(), "UthmanTN1Ver10.otf");
}
return arabicHeaderFooterTypeface;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.graphics.Paint.FontMetrics;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.util.AttributeSet;
import android.util.SparseArray;

Expand All @@ -23,6 +24,7 @@
import com.quran.labs.androidquran.ui.helpers.HighlightType;
import com.quran.labs.androidquran.ui.helpers.SingleAyahHighlight;
import com.quran.labs.androidquran.ui.helpers.TransitionAyahHighlight;
import com.quran.labs.androidquran.ui.util.TypefaceManager;
import com.quran.page.common.data.AyahBounds;
import com.quran.page.common.data.AyahCoordinates;
import com.quran.page.common.data.PageCoordinates;
Expand Down Expand Up @@ -52,6 +54,8 @@ public class HighlightingImageView extends AppCompatImageView {
private static int headerFooterFontSize;
private static int scrollableHeaderFooterSize;
private static int scrollableHeaderFooterFontSize;
private static int dualPageHeaderFooterSize;
private static int dualPageHeaderFooterFontSize;

// Sorted map so we use highest priority highlighting when iterating
private final SortedMap<HighlightType, Set<AyahHighlight>> currentHighlights = new TreeMap<>();
Expand Down Expand Up @@ -90,9 +94,12 @@ public HighlightingImageView(Context context, AttributeSet attrs) {
overlayTextColor = ContextCompat.getColor(context, R.color.overlay_text_color);
headerFooterSize = res.getDimensionPixelSize(R.dimen.page_overlay_size);
scrollableHeaderFooterSize = res.getDimensionPixelSize(R.dimen.page_overlay_size_scrollable);
dualPageHeaderFooterSize = res.getDimensionPixelSize(R.dimen.page_overlay_size_dualPage);
headerFooterFontSize = res.getDimensionPixelSize(R.dimen.page_overlay_font_size);
scrollableHeaderFooterFontSize =
res.getDimensionPixelSize(R.dimen.page_overlay_font_size_scrollable);
dualPageHeaderFooterFontSize =
res.getDimensionPixelSize(R.dimen.page_overlay_font_size_dualPage);
}

Insetter.builder()
Expand All @@ -111,14 +118,16 @@ public HighlightingImageView(Context context, AttributeSet attrs) {
.applyToView(this);
}

public void setIsScrollable(boolean scrollable) {
int topBottom = scrollable ? scrollableHeaderFooterSize : headerFooterSize;
public void setIsScrollable(boolean scrollable, boolean landscape) {
int topBottom = scrollable ? scrollableHeaderFooterSize :
landscape ? dualPageHeaderFooterSize : headerFooterSize;
verticalOffsetForScrolling = topBottom;
setPadding(horizontalSafeOffset,
topBottom + topSafeOffset,
horizontalSafeOffset,
topBottom + bottomSafeOffset);
fontSize = scrollable ? scrollableHeaderFooterFontSize : headerFooterFontSize;
fontSize = scrollable ? scrollableHeaderFooterFontSize :
landscape ? dualPageHeaderFooterFontSize : headerFooterFontSize;
}

public void unHighlight(int surah, int ayah, HighlightType type) {
Expand Down Expand Up @@ -353,7 +362,7 @@ private static class OverlayParams {
String rub3Text = null;
}

public void setOverlayText(String suraText, String juzText, String pageText, String rub3Text) {
public void setOverlayText(Context context, String suraText, String juzText, String pageText, String rub3Text) {
// Calculate page bounding rect from ayahinfo db
if (pageBounds == null) {
return;
Expand All @@ -366,7 +375,10 @@ public void setOverlayText(String suraText, String juzText, String pageText, Str
overlayParams.rub3Text = rub3Text;
overlayParams.paint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DEV_KERN_TEXT_FLAG);
overlayParams.paint.setTextSize(fontSize);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && juzText.contains("ج")) {
// change typeface for Arabic
overlayParams.paint.setTypeface(TypefaceManager.getHeaderFooterTypeface(context));
}
if (!didDraw) {
invalidate();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public QuranImagePageLayout(Context context) {
protected View generateContentView(Context context, boolean isLandscape) {
imageView = new HighlightingImageView(context);
imageView.setAdjustViewBounds(true);
imageView.setIsScrollable(isLandscape && shouldWrapWithScrollView());
imageView.setIsScrollable(isLandscape && shouldWrapWithScrollView(), isLandscape);
return imageView;
}

Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@

<string name="canceling">جاري إلغاء اﻷمر…</string>
<string name="juz2_description">الجزء %1$s</string>
<string name="page_description">صفحة %1$s, جزء %2$s</string>
<string name="page_description">صفحة %1$s، جزء %2$s</string>
<string name="highlighting_database">جاري تحميل الملفات المطلوبة</string>
<string name="timing_database">جاري تحميل الملفات المطلوبة</string>

Expand Down Expand Up @@ -349,5 +349,6 @@
مكان غير مجلد التطبيق الافتراضي قد يؤدي إلى عدم تمكن التطبيق من الوصول لملفاته في إصدارات أندرويد
القادمة، هل ترغب في نقل البيانات على أية حال؟
</string>
<string name="comma_with_spaces">" ، "</string>

</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<color name="translation_background_color_night">#ff1d1f21</color>
<color name="translation_ayah_selected_color">#ffe0f2f1</color>
<color name="translation_ayah_selected_color_night">#ff2d2d2d</color>
<color name="overlay_text_color">#ff888888</color>
<color name="overlay_text_color">#ff505050</color>
<color name="selection_highlight">#404694A6</color>
<color name="audio_highlight">#4046A646</color>
<color name="note_highlight">#40EBEB21</color>
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,12 @@
<dimen name="repeat_text_y_padding">4dp</dimen>

<!-- page overlay text -->
<dimen name="page_overlay_size">12sp</dimen>
<dimen name="page_overlay_font_size">10sp</dimen>
<dimen name="page_overlay_font_size_scrollable">16sp</dimen>
<dimen name="page_overlay_size_scrollable">20sp</dimen>
<dimen name="page_overlay_size">15dp</dimen>
<dimen name="page_overlay_font_size">14dp</dimen>
<dimen name="page_overlay_font_size_scrollable">16dp</dimen>
<dimen name="page_overlay_font_size_dualPage">9dp</dimen>
<dimen name="page_overlay_size_scrollable">20dp</dimen>
<dimen name="page_overlay_size_dualPage">12dp</dimen>

<!-- tags -->
<dimen name="tag_width">50dp</dimen>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@

<string name="canceling">Canceling&#8230;</string>
<string name="juz2_description">Juz\' %1$s</string>
<string name="comma_with_spaces" translatable="false"> , </string>
<string name="page_description">page %1$s, Juz\' %2$s</string>
<string name="highlighting_database">Required Files</string>
<string name="timing_database">Required Files</string>
Expand Down