Skip to content

Commit

Permalink
Merge pull request #65 from afarra/master
Browse files Browse the repository at this point in the history
Issue #33
  • Loading branch information
hmaher committed Aug 14, 2011
2 parents e68e3b4 + 2f1b851 commit d12d27d
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 0 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<string name="settings_keep_screen_on">Keep screen on.</string>
<string name="prefs_use_arabic_names">useArabicNames</string>
<string name="prefs_keep_screen_on">keepScreenOn</string>
<string name="prefs_display_marker_popup">displayMarkerPopup</string>
<string name="prefs_lock_orientation">lockOrientation</string>
<string name="prefs_landscape_orientation">landscapeOrientation</string>
<string name="prefs_translation_text_size">translationTextSize</string>
Expand All @@ -101,6 +102,7 @@
<string name="no_active_translation">No active translation set, set an active translation first (Settings > Set Active Translation) and then search again.</string>
<string name="set_active_translation">Set Active Translation</string>
<string name="no_translations_available">You have not got any available translations, please download a translation first (Menu > Get More Translations) and then search again.</string>
<string name="prefs_category_reading">Reading Preferences</string>
<string name="prefs_category_translation">Translation Preferences</string>
<string name="prefs_category_display_settings">Display Settings</string>
<string name="prefs_active_translation">activeTranslation</string>
Expand Down
7 changes: 7 additions & 0 deletions res/xml/quran_preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@
<CheckBoxPreference android:title="Lock Screen Orientation" android:summaryOn="Quran page will be in fixed orientation mode" android:summaryOff="Adaptive to current orientation mode" android:key="@string/prefs_lock_orientation" android:defaultValue="false" android:persistent="true" android:disableDependentsState="false"></CheckBoxPreference>
<CheckBoxPreference android:key="@string/prefs_landscape_orientation" android:title="Landscape Orientation" android:persistent="true" android:summaryOn="Landscape orientation will be used" android:summaryOff="Portrait orientation will be used" android:dependency="@string/prefs_lock_orientation"></CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_category_reading">
<CheckBoxPreference
android:title="Display Marker Popups"
android:summaryOn="Display popup when reaching Juz', Hizb, etc." android:summaryOff="Don't display popup when reaching Juz', Hizb, etc."
android:persistent="true" android:key="@string/prefs_display_marker_popup">
</CheckBoxPreference>
</PreferenceCategory>
<PreferenceCategory android:title="@string/prefs_category_translation">
<com.quran.labs.androidquran.widgets.SelectTranslationPreference
android:key="@string/prefs_active_translation"
Expand Down
31 changes: 31 additions & 0 deletions src/com/quran/labs/androidquran/common/QuranPageFeeder.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;

import com.quran.labs.androidquran.R;
import com.quran.labs.androidquran.data.ApplicationConstants;
import com.quran.labs.androidquran.data.QuranInfo;
import com.quran.labs.androidquran.util.QuranSettings;
import com.quran.labs.androidquran.util.QuranUtils;
import com.quran.labs.androidquran.widgets.HighlightingImageView;
Expand Down Expand Up @@ -47,6 +49,8 @@ public class QuranPageFeeder implements OnPageFlipListener {
protected int mPageLayout;
protected int mCurrentPageNumber;

private long lastPopupTime = System.currentTimeMillis();

public QuranPageFeeder(PageViewQuranActivity context,
QuranPageCurlView quranPage, int page_layout) {
mContext = context;
Expand Down Expand Up @@ -151,6 +155,31 @@ public void onPageFlipEnd(QuranPageCurlView pageView, int flipDirection) {
}
}

public void displayMarkerPopup() {
if(System.currentTimeMillis() - lastPopupTime < 3000)
return;
int rub3 = QuranInfo.getRub3FromPage(mCurrentPageNumber);
if (rub3 == -1)
return;
int hizb = (rub3 / 4) + 1;
StringBuilder sb = new StringBuilder();

if (rub3 % 8 == 0) {
sb.append("Juz' ").append((hizb/2) + 1);
} else {
sb.append("Hizb ").append(hizb);
int remainder = rub3 % 4;
if (remainder == 1)
sb.insert(0, "¼ ");
else if (remainder == 2)
sb.insert(0, "½ ");
else if (remainder == 3)
sb.insert(0, "¾ ");
}
Toast.makeText(mContext, sb.toString(), Toast.LENGTH_SHORT).show();
lastPopupTime = System.currentTimeMillis();
}

public int loadNextPage(QuranPageCurlView pageView) {
mCurrentPageNumber += 1;
if (mCurrentPageNumber < ApplicationConstants.PAGES_LAST){
Expand Down Expand Up @@ -292,6 +321,8 @@ public void run(){
updateViewForUser(v, false, false);
QuranSettings.getInstance().setLastPage(mCurrentPageNumber);
QuranSettings.save(mContext.prefs);
if (QuranSettings.getInstance().isDisplayMarkerPopup())
displayMarkerPopup();
}

//clear for GC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class ApplicationConstants {
public static final String PREF_KEEP_SCREEN_ON = "keepScreenOn";
public static final String PREF_LOCK_ORIENTATION = "lockOrientation";
public static final String PREF_LANDSCAPE_ORIENTATION = "landscapeOrientation";
public static final String PREF_DISPLAY_MARKER_POPUP = "displayMarkerPopup";
public static final String PREF_TRANSLATION_TEXT_SIZE = "translationTextSize";
public static final String PREF_ACTIVE_TRANSLATION = "activeTranslation";
public static final String PREF_RESHAPE_ARABIC = "reshapeArabic";
Expand Down
71 changes: 71 additions & 0 deletions src/com/quran/labs/androidquran/data/QuranInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,67 @@ private static String getPageTitleNoPrefix() {
402, 422, 442, 462, 482, 502, 522, 542, 562, 582
};

public static int[] RUB3_PAGE_START = {
5, 7, 9, 11, 14, 17, 19, 22, 24,
27, 29, 32, 34, 37, 39, 42, 44, 46, 49, 51, 54, 56, 59, 62, 64, 67,
69, 72, 74, 77, 79, 82, 84, 87, 89, 92, 94, 97, 100, 102, 104, 106,
109, 112, 114, 117, 119, 121, 124, 126, 129, 132, 134, 137, 140,
142, 144, 146, 148, 151, 154, 156, 158, 162, 164, 167, 170, 173,
175, 177, 179, 182, 184, 187, 189, 192, 194, 196, 199, 201, 204,
206, 209, 212, 214, 217, 219, 222, 224, 226, 228, 231, 233, 236,
238, 242, 244, 247, 249, 252, 254, 256, 259, 262, 264, 267, 270,
272, 275, 277, 280, 282, 284, 287, 289, 292, 295, 297, 299, 302,
304, 306, 309, 312, 315, 317, 319, 322, 324, 326, 329, 332, 334,
336, 339, 342, 344, 347, 350, 352, 354, 356, 359, 362, 364, 367,
369, 371, 374, 377, 379, 382, 384, 386, 389, 392, 394, 396, 399,
402, 404, 407, 410, 413, 415, 418, 420, 422, 425, 426, 429, 431,
433, 436, 439, 442, 444, 446, 449, 451, 454, 456, 459, 462, 464,
467, 469, 472, 474, 477, 479, 482, 484, 486, 488, 491, 493, 496,
499, 502, 505, 507, 510, 513, 515, 517, 519, 522, 524, 526, 529,
531, 534, 536, 539, 542, 544, 547, 550, 553, 554, 558, 560, 562,
564, 566, 569, 572, 575, 577, 579, 582, 585, 587, 589, 591, 594,
596, 599
};

public static int[] PAGE_RUB3_START = {
-1, -1, -1, -1, 1, -1, 2, -1, 3, -1, 4, -1, -1, 5, -1, -1, 6, -1, 7,
-1, -1, 8, -1, 9, -1, -1, 10, -1, 11, -1, -1, 12, -1, 13, -1, -1, 14,
-1, 15, -1, -1, 16, -1, 17, -1, 18, -1, -1, 19, -1, 20, -1, -1, 21, -1,
22, -1, -1, 23, -1, -1, 24, -1, 25, -1, -1, 26, -1, 27, -1, -1, 28, -1,
29, -1, -1, 30, -1, 31, -1, -1, 32, -1, 33, -1, -1, 34, -1, 35, -1, -1,
36, -1, 37, -1, -1, 38, -1, -1, 39, -1, 40, -1, 41, -1, 42, -1, -1, 43,
-1, -1, 44, -1, 45, -1, -1, 46, -1, 47, -1, 48, -1, -1, 49, -1, 50, -1,
-1, 51, -1, -1, 52, -1, 53, -1, -1, 54, -1, -1, 55, -1, 56, -1, 57, -1,
58, -1, 59, -1, -1, 60, -1, -1, 61, -1, 62, -1, 63, -1, -1, -1, 64, -1,
65, -1, -1, 66, -1, -1, 67, -1, -1, 68, -1, 69, -1, 70, -1, 71, -1, -1,
72, -1, 73, -1, -1, 74, -1, 75, -1, -1, 76, -1, 77, -1, 78, -1, -1, 79,
-1, 80, -1, -1, 81, -1, 82, -1, -1, 83, -1, -1, 84, -1, 85, -1, -1, 86,
-1, 87, -1, -1, 88, -1, 89, -1, 90, -1, 91, -1, -1, 92, -1, 93, -1, -1,
94, -1, 95, -1, -1, -1, 96, -1, 97, -1, -1, 98, -1, 99, -1, -1, 100, -1,
101, -1, 102, -1, -1, 103, -1, -1, 104, -1, 105, -1, -1, 106, -1, -1,
107, -1, 108, -1, -1, 109, -1, 110, -1, -1, 111, -1, 112, -1, 113, -1,
-1, 114, -1, 115, -1, -1, 116, -1, -1, 117, -1, 118, -1, 119, -1, -1,
120, -1, 121, -1, 122, -1, -1, 123, -1, -1, 124, -1, -1, 125, -1, 126,
-1, 127, -1, -1, 128, -1, 129, -1, 130, -1, -1, 131, -1, -1, 132, -1,
133, -1, 134, -1, -1, 135, -1, -1, 136, -1, 137, -1, -1, 138, -1, -1,
139, -1, 140, -1, 141, -1, 142, -1, -1, 143, -1, -1, 144, -1, 145, -1,
-1, 146, -1, 147, -1, 148, -1, -1, 149, -1, -1, 150, -1, 151, -1, -1,
152, -1, 153, -1, 154, -1, -1, 155, -1, -1, 156, -1, 157, -1, 158, -1,
-1, 159, -1, -1, 160, -1, 161, -1, -1, 162, -1, -1, 163, -1, -1, 164,
-1, 165, -1, -1, 166, -1, 167, -1, 168, -1, -1, 169, 170, -1, -1, 171,
-1, 172, -1, 173, -1, -1, 174, -1, -1, 175, -1, -1, 176, -1, 177, -1,
178, -1, -1, 179, -1, 180, -1, -1, 181, -1, 182, -1, -1, 183, -1, -1,
184, -1, 185, -1, -1, 186, -1, 187, -1, -1, 188, -1, 189, -1, -1, 190,
-1, 191, -1, -1, 192, -1, 193, -1, 194, -1, 195, -1, -1, 196, -1, 197,
-1, -1, 198, -1, -1, 199, -1, -1, 200, -1, -1, 201, -1, 202, -1, -1,
203, -1, -1, 204, -1, 205, -1, 206, -1, 207, -1, -1, 208, -1, 209, -1,
210, -1, -1, 211, -1, 212, -1, -1, 213, -1, 214, -1, -1, 215, -1, -1,
216, -1, 217, -1, -1, 218, -1, -1, 219, -1, -1, 220, 221, -1, -1, -1,
222, -1, 223, -1, 224, -1, 225, -1, 226, -1, -1, 227, -1, -1, 228, -1,
-1, 229, -1, 230, -1, 231, -1, -1, 232, -1, -1, 233, -1, 234, -1, 235,
-1, 236, -1, -1, 237, -1, 238, -1, -1, 239, -1, -1, -1, -1, -1
};

public static int[] SURA_NUM_AYAHS = {
7, 286, 200, 176, 120, 165, 206, 75, 129, 109, 123, 111,
43, 52, 99, 128, 111, 110, 98, 135, 112, 78, 118, 64, 77,
Expand Down Expand Up @@ -264,6 +325,16 @@ public static int getJuzFromPage(int page) {
return juz > 30 ? 30 : juz < 1 ? 1 : juz;
}

public static int getPageFromRub3(int rub3){
if ((rub3 < 1) || (rub3 > 8 * ApplicationConstants.JUZ2_COUNT)) return -1;
return QuranInfo.RUB3_PAGE_START[rub3-1];
}

public static int getRub3FromPage(int page) {
if ((page > ApplicationConstants.PAGES_LAST) || (page < 1)) return -1;
return PAGE_RUB3_START[page-1];
}

public static int getPageFromSuraAyah(int sura, int ayah){
// basic bounds checking
if (ayah == 0) ayah = 1;
Expand Down
11 changes: 11 additions & 0 deletions src/com/quran/labs/androidquran/util/QuranSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class QuranSettings {
private boolean keepScreenOn = false;
private boolean lockOrientation = false;
private boolean landscapeOrientation = false;
private boolean displayMarkerPopup = false;
private int translationTextSize = ApplicationConstants.DEFAULT_TEXT_SIZE;
private int lastPage = 0;
private String activeTranslation = null;
Expand Down Expand Up @@ -75,6 +76,14 @@ public void setLandscapeOrientation(boolean landscapeOrientation) {
this.landscapeOrientation = landscapeOrientation;
}

public boolean isDisplayMarkerPopup() {
return displayMarkerPopup;
}

public void setMarkerPopup(boolean displayMarkerPopup) {
this.displayMarkerPopup = displayMarkerPopup;
}

public int getTranslationTextSize() {
return translationTextSize;
}
Expand All @@ -100,6 +109,7 @@ public static void load(SharedPreferences preferences) {
instance.keepScreenOn = preferences.getBoolean(ApplicationConstants.PREF_KEEP_SCREEN_ON, true);
instance.lockOrientation = preferences.getBoolean(ApplicationConstants.PREF_LOCK_ORIENTATION, false);
instance.landscapeOrientation = preferences.getBoolean(ApplicationConstants.PREF_LANDSCAPE_ORIENTATION, false);
instance.displayMarkerPopup = preferences.getBoolean(ApplicationConstants.PREF_DISPLAY_MARKER_POPUP, false);
instance.translationTextSize = preferences.getInt(ApplicationConstants.PREF_TRANSLATION_TEXT_SIZE, ApplicationConstants.DEFAULT_TEXT_SIZE);
instance.lastPage = preferences.getInt(ApplicationConstants.PREF_LAST_PAGE, ApplicationConstants.NO_PAGE_SAVED);
instance.activeTranslation = preferences.getString(ApplicationConstants.PREF_ACTIVE_TRANSLATION, null);
Expand All @@ -113,6 +123,7 @@ public static void save(SharedPreferences preferences) {
editor.putBoolean(ApplicationConstants.PREF_KEEP_SCREEN_ON, instance.keepScreenOn);
editor.putBoolean(ApplicationConstants.PREF_LOCK_ORIENTATION, instance.lockOrientation);
editor.putBoolean(ApplicationConstants.PREF_LANDSCAPE_ORIENTATION, instance.landscapeOrientation);
editor.putBoolean(ApplicationConstants.PREF_DISPLAY_MARKER_POPUP, instance.displayMarkerPopup);
editor.putInt(ApplicationConstants.PREF_TRANSLATION_TEXT_SIZE, instance.translationTextSize);
editor.putInt(ApplicationConstants.PREF_LAST_PAGE, instance.lastPage);
editor.putString(ApplicationConstants.PREF_ACTIVE_TRANSLATION, instance.activeTranslation);
Expand Down

0 comments on commit d12d27d

Please sign in to comment.