@Override public void onPageFlipEnd(QuranPageCurlView pageView, int flipDirection) { if (flipDirection == OnPageFlipListener.NEXT_PAGE) { loadNextPage(pageView); } else if (flipDirection == OnPageFlipListener.PREVIOUS_PAGE) { loadPreviousPage(pageView); } QuranSettings.getInstance().setLastPage(mCurrentPageNumber); QuranSettings.save(mContext.prefs); }
private BookmarkPresenter(Context context) { mAppContext = context.getApplicationContext(); mQuranSettings = QuranSettings.getInstance(context); mBookmarkModel = BookmarkModel.getInstance(context); mSortOrder = mQuranSettings.getBookmarksSortOrder(); mGroupByTags = mQuranSettings.getBookmarksGroupedByTags(); try { mArabicDatabaseUtils = ArabicDatabaseUtils.getInstance(context); } catch (Exception e) { mArabicDatabaseUtils = null; } subscribeToChanges(); }
@VisibleForTesting BookmarkPresenter( Context context, QuranSettings settings, BookmarkModel bookmarkModel, boolean subscribeToChanges) { mAppContext = context.getApplicationContext(); mQuranSettings = settings; mBookmarkModel = bookmarkModel; mSortOrder = mQuranSettings.getBookmarksSortOrder(); mGroupByTags = mQuranSettings.getBookmarksGroupedByTags(); if (subscribeToChanges) { subscribeToChanges(); } }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); Activity activity = getActivity(); if (activity instanceof PagerActivity) { final PagerActivity pagerActivity = (PagerActivity) activity; downloadImage(); handler.postDelayed( () -> new QueryPageCoordinatesTask(pagerActivity).execute(pageNumber), 1000); if (QuranSettings.getInstance(activity).shouldHighlightBookmarks()) { // Observable.timer by default runs on Schedulers.computation() compositeDisposable.add( Completable.timer(250, TimeUnit.MILLISECONDS) .subscribeOn(AndroidSchedulers.mainThread()) .subscribeWith( new DisposableCompletableObserver() { @Override public void onComplete() { highlightTagsTask(); } @Override public void onError(Throwable e) {} })); } } }
public void toggleGroupByTags() { mGroupByTags = !mGroupByTags; mQuranSettings.setBookmarksGroupedByTags(mGroupByTags); requestData(); Answers.getInstance() .logCustom(new CustomEvent(mGroupByTags ? "groupByTags" : "doNotGroupByTags")); }
private List<QuranRow> getBookmarkRows(BookmarkData data, boolean groupByTags) { List<QuranRow> rows; List<Tag> tags = data.getTags(); List<Bookmark> bookmarks = data.getBookmarks(); if (groupByTags) { rows = getRowsSortedByTags(tags, bookmarks); } else { rows = getSortedRows(bookmarks); } int lastPage = mQuranSettings.getLastPage(); boolean showLastPage = lastPage != Constants.NO_PAGE_SAVED; if (showLastPage && (lastPage > Constants.PAGES_LAST || lastPage < Constants.PAGES_FIRST)) { showLastPage = false; Timber.w("Got invalid last saved page as %d", lastPage); } if (showLastPage) { rows.add(0, QuranRowFactory.fromCurrentPageHeader(mAppContext)); rows.add(1, QuranRowFactory.fromCurrentPage(mAppContext, lastPage)); } return rows; }
@Override public void bind(BookmarksFragment fragment) { mFragment = fragment; boolean isRtl = mQuranSettings.isArabicNames() || QuranUtils.isRtl(); if (isRtl == mIsRtl) { requestData(true); } else { // don't use the cache if rtl changed mIsRtl = isRtl; requestData(false); } }
public void jumpToPage(int page) { if (page <= ApplicationConstants.PAGES_FIRST) { page = ApplicationConstants.PAGES_FIRST; mQuranPage.addNextPage(null); mQuranPage.addNextPage(createPage(page)); mQuranPage.addNextPage(createPage(page + 1)); } else if (page >= ApplicationConstants.PAGES_LAST) { page = ApplicationConstants.PAGES_LAST; mQuranPage.addPreviousPage(null); mQuranPage.addPreviousPage(createPage(page)); mQuranPage.addPreviousPage(createPage(page - 1)); } else { mQuranPage.addNextPage(createPage(page - 1)); mQuranPage.addNextPage(createPage(page)); mQuranPage.addNextPage(createPage(page + 1)); } mCurrentPageNumber = page; QuranSettings.getInstance().setLastPage(page); QuranSettings.save(mContext.prefs); mQuranPage.refresh(true); }
public void updateView(boolean nightMode, boolean useNewBackground, int pagesVisible) { if (rightGradient == null || gradientForNumberOfPages != pagesVisible) { final WindowManager mgr = (WindowManager) context.getApplicationContext().getSystemService(Context.WINDOW_SERVICE); Display display = mgr.getDefaultDisplay(); int width = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT ? QuranDisplayHelper.getWidthKitKat(display) : display.getWidth(); width = width / pagesVisible; leftGradient = QuranDisplayHelper.getPaintDrawable(width, 0); rightGradient = QuranDisplayHelper.getPaintDrawable(0, width); gradientForNumberOfPages = pagesVisible; } isNightMode = nightMode; int lineColor = Color.BLACK; final int nightModeTextBrightness = nightMode ? QuranSettings.getInstance(context).getNightModeTextBrightness() : Constants.DEFAULT_NIGHT_MODE_TEXT_BRIGHTNESS; if (nightMode) { lineColor = Color.argb(nightModeTextBrightness, 255, 255, 255); } if (pageNumber % 2 == 0) { leftBorder = nightMode ? BorderMode.DARK : BorderMode.LIGHT; rightBorder = BorderMode.HIDDEN; } else { rightBorder = nightMode ? BorderMode.DARK : BorderMode.LIGHT; if (QuranPageLayout.lineColor != lineColor) { QuranPageLayout.lineColor = lineColor; lineDrawable.getPaint().setColor(lineColor); } leftBorder = BorderMode.LINE; } setContentNightMode(nightMode, nightModeTextBrightness); if (nightMode) { setBackgroundColor(Color.BLACK); } else if (useNewBackground) { setBackgroundDrawable((pageNumber % 2 == 0 ? leftGradient : rightGradient)); } else { setBackgroundColor(ContextCompat.getColor(context, R.color.page_background)); } if (errorText != null) { updateErrorTextColor(); } }
public static String getLocalizedNumber(Context context, int number) { if (QuranSettings.getInstance(context).isArabicNames()) { if (mNumberFormatter == null || !mIsArabicFormatter) { mIsArabicFormatter = true; mNumberFormatter = DecimalFormat.getIntegerInstance(new Locale("ar")); } } else { if (mNumberFormatter == null || mIsArabicFormatter) { mIsArabicFormatter = false; mNumberFormatter = DecimalFormat.getIntegerInstance(); } } return mNumberFormatter.format(number); }
public void highlightAyah(int sura, int ayah) { View v = mQuranPage.getCurrentPage(); HighlightingImageView iv = (HighlightingImageView) v.findViewById(R.id.page_image); if (iv != null) { HighlightingImageView hi = (HighlightingImageView) iv; hi.highlightAyah(sura, ayah); if (QuranSettings.getInstance().isAutoScroll() && v.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) { AyahBounds yBounds = hi.getYBoundsForCurrentHighlight(); if (yBounds != null) mQuranPage.scrollToAyah(R.id.page_scroller, yBounds); } mQuranPage.invalidate(); } }
public void run() { ImageView iv = (ImageView) v.findViewById(R.id.page_image); if (bitmap == null) { Log.d(TAG, "Page not found: " + index); updateViewForUser(v, false, true); } else { iv.setImageBitmap(bitmap); mQuranPage.refresh(); updateViewForUser(v, false, false); if (QuranSettings.getInstance().isDisplayMarkerPopup()) displayMarkerPopup(); } // clear for GC iv = null; bitmap = null; v = null; }
protected void updateViewForUser(View v, boolean loading, boolean pageNotFound) { TextView tv = (TextView) v.findViewById(R.id.txtPageNotFound); HighlightingImageView iv = (HighlightingImageView) v.findViewById(R.id.page_image); if ((loading) || (pageNotFound)) { if (QuranSettings.getInstance().isNightMode()) { tv.setTextColor(Color.WHITE); } tv.setText(loading ? R.string.pageLoading : R.string.pageNotFound); if (!loading && mHasBeenOutOfMemory != null && mHasBeenOutOfMemory) tv.setText(R.string.couldNotLoadPage); tv.setVisibility(View.VISIBLE); iv.setVisibility(View.GONE); } else { iv.adjustNightMode(); tv.setVisibility(View.GONE); iv.setVisibility(View.VISIBLE); } }
@Override protected void onPostExecute(Boolean result) { if (!mIsPaused) { dialog.dismiss(); if (result) { QuranSettings.setAppCustomLocation(QuranPreferenceActivity.this, newLocation); if (mListStorageOptions != null) { mListStorageOptions.setValue(newLocation); } } else { Toast.makeText( QuranPreferenceActivity.this, getString(R.string.prefs_err_moving_app_files), Toast.LENGTH_LONG) .show(); } dialog = null; mMoveFilesTask = null; } }
@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); } }
@WorkerThread public static String getDebugInfo(Context context) { StringBuilder builder = new StringBuilder(); builder.append("Android SDK Version: ").append(Build.VERSION.SDK_INT); String location = QuranSettings.getInstance(context).getAppCustomLocation(); builder.append("\nApp Location:").append(location); try { File file = new File(location); builder .append("\n App Location Directory ") .append(file.exists() ? "exists" : "doesn't exist") .append("\n Image zip files:"); String[] list = file.list(); for (String fileName : list) { if (fileName.contains("images_")) { File f = new File(fileName); builder.append("\n file: ").append(fileName).append("\tlength: ").append(f.length()); } } } catch (Exception e) { builder.append("Exception trying to list files").append(e); } QuranScreenInfo info = QuranScreenInfo.getInstance(); if (info != null) { builder.append("\nDisplay: ").append(info.getWidthParam()); if (info.isTablet(context)) { builder.append(", tablet width: ").append(info.getWidthParam()); } builder.append("\n"); } int memClass = ((ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass(); builder.append("memory class: ").append(memClass).append("\n\n"); return builder.toString(); }
private void loadStorageOptions() { try { CharSequence[] values = new CharSequence[mStorageList.size()]; CharSequence[] displayNames = new CharSequence[mStorageList.size()]; int i = 0; final HashMap<String, Integer> storageEmptySpaceMap = new HashMap<String, Integer>(mStorageList.size()); for (StorageUtils.Storage storage : mStorageList) { values[i] = storage.getMountPoint(); displayNames[i] = storage.getLabel() + " " + storage.getFreeSpace() + " " + getString(R.string.prefs_megabytes); i++; storageEmptySpaceMap.put(storage.getMountPoint(), storage.getFreeSpace()); } String msg = getString(R.string.prefs_app_location_summary) + "\n" + getString(R.string.prefs_app_size) + " " + mAppSize + " " + getString(R.string.prefs_megabytes); mListStorageOptions.setSummary(msg); mListStorageOptions.setEntries(displayNames); mListStorageOptions.setEntryValues(values); String current = QuranSettings.getAppCustomLocation(this); if (TextUtils.isEmpty(current)) { current = values[0].toString(); } mListStorageOptions.setValue(current); mListStorageOptions.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { if (TextUtils.isEmpty( QuranSettings.getAppCustomLocation(QuranPreferenceActivity.this)) && Environment.getExternalStorageDirectory().equals(newValue)) { // do nothing since we're moving from empty settings to // the default sdcard setting, which are the same, but write it. return false; } // this is called right before the preference is saved String newLocation = (String) newValue; String current = QuranSettings.getAppCustomLocation(QuranPreferenceActivity.this); if (mAppSize < storageEmptySpaceMap.get(newLocation)) { if (current == null || !current.equals(newLocation)) { mMoveFilesTask = new MoveFilesAsyncTask(newLocation); mMoveFilesTask.execute(); } } else { Toast.makeText( QuranPreferenceActivity.this, getString(R.string.prefs_no_enough_space_to_move_files), Toast.LENGTH_LONG) .show(); } // this says, "don't write the preference" return false; } }); } catch (Exception e) { Log.e(TAG, "error loading storage options", e); } }
public void setSortOrder(int sortOrder) { mSortOrder = sortOrder; mQuranSettings.setBookmarksSortOrder(mSortOrder); requestData(); }