@Override protected BitmapDrawable doInBackground(Integer... params) { data = params[0]; Bitmap bitmap = QuranDisplayHelper.getQuranPage(mContext, mWidthParam, data); if (bitmap == null) { if (QuranScreenInfo.getInstance().isTablet(mContext)) { Log.w(TAG, "tablet got bitmap null, trying alternate width..."); String param = QuranScreenInfo.getInstance().getWidthParam(); if (param.equals(mWidthParam)) { param = QuranScreenInfo.getInstance().getTabletWidthParam(); } bitmap = QuranDisplayHelper.getQuranPage(mContext, param, data); if (bitmap == null) { Log.w(TAG, "bitmap still null, giving up..."); } } Log.w(TAG, "got bitmap back as null..."); } BitmapDrawable drawable = null; if (bitmap != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { drawable = new BitmapDrawable(mResources, bitmap); } else { drawable = new RecyclingBitmapDrawable(mResources, bitmap); } addBitmapToCache(data + mWidthParam, drawable); } return drawable; }
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(); }
private void downloadImage() { final Activity activity = getActivity(); if (activity instanceof PagerActivity) { QuranPageWorker worker = ((PagerActivity) activity).getQuranPageWorker(); pageLoadTask = worker.loadPage( QuranScreenInfo.getInstance().getWidthParam(), pageNumber, QuranPageFragment.this); } }
private void handleHighlightAyah(int sura, int ayah) { if (mImageView == null) { return; } mImageView.highlightAyah(sura, ayah); if (mScrollView != null) { AyahBounds yBounds = mImageView.getYBoundsForCurrentHighlight(); if (yBounds != null) { int screenHeight = QuranScreenInfo.getInstance().getHeight(); int y = yBounds.getMinY() - (int) (0.05 * screenHeight); mScrollView.smoothScrollTo(mScrollView.getScrollX(), y); } } mImageView.invalidate(); }
@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 protected void onCreate(Bundle savedInstanceState) { setTheme(R.style.Theme_Sherlock); super.onCreate(savedInstanceState); // add preferences addPreferencesFromResource(R.xml.quran_preferences); // special handling for the arabic checkbox CheckBoxPreference arabicPreference = (CheckBoxPreference) findPreference(Constants.PREF_USE_ARABIC_NAMES); mInitiallyIsArabic = arabicPreference.isChecked(); mIsArabic = mInitiallyIsArabic; arabicPreference.setOnPreferenceChangeListener( new OnPreferenceChangeListener() { @Override public boolean onPreferenceChange(Preference preference, Object newValue) { boolean isArabic = (Boolean) newValue; mIsArabic = isArabic; Locale lang = (isArabic ? new Locale("ar") : getResources().getConfiguration().locale); Locale.setDefault(lang); Configuration config = new Configuration(); config.locale = lang; getResources().updateConfiguration(config, getResources().getDisplayMetrics()); return true; } }); // remove the tablet mode preference if it doesn't exist if (!QuranScreenInfo.getOrMakeInstance(this).isTablet(this)) { Preference tabletModePreference = findPreference(Constants.PREF_TABLET_ENABLED); PreferenceCategory category = (PreferenceCategory) findPreference(Constants.PREF_DISPLAY_CATEGORY); category.removePreference(tabletModePreference); } Preference advancedPrefs = findPreference(getString(R.string.prefs_advanced_settings)); advancedPrefs.setOnPreferenceClickListener( new Preference.OnPreferenceClickListener() { @Override public boolean onPreferenceClick(Preference preference) { mLoadStorageOptionsTask = new LoadStorageOptionsTask(); mLoadStorageOptionsTask.execute(); return false; } }); /* // can enable this to get logs from users until we move it to // a setting. needs READ_LOGS permissions below jellybean. this // is a work around until we properly use the Logger framework // to roll our own log files. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { mReadLogsTask = new ReadLogsTask(); mReadLogsTask.execute(); } */ mListStorageOptions = (ListPreference) findPreference(getString(R.string.prefs_app_location)); mStorageList = StorageUtils.getAllStorageLocations(getApplicationContext()); // Hide Advanced Preferences Screen if there is no storage option // except for the normal Environment.getExternalStorageDirectory if (mStorageList.size() <= 1) { Log.d(TAG, "removing advanced settings from preferences"); getPreferenceScreen().removePreference(advancedPrefs); } }
@Override protected void onPostExecute(String logs) { if (mIsPaused) { return; } Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setType("plain/text"); QuranScreenInfo qsi; String body = "\n\n"; try { PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0); body = pInfo.packageName + " Version: " + pInfo.versionName; } catch (Exception e) { } try { body += "\nPhone: " + android.os.Build.MANUFACTURER + " " + android.os.Build.MODEL; body += "\nAndroid Version: " + android.os.Build.VERSION.CODENAME + " " + android.os.Build.VERSION.RELEASE; qsi = QuranScreenInfo.getOrMakeInstance(QuranPreferenceActivity.this); body += "\nDisplay: " + qsi.getWidthParam(); if (qsi.isTablet(QuranPreferenceActivity.this)) { body += ", tablet width: " + qsi.getWidthParam(); } body += "\n"; body += "max bitmap height: " + qsi.getBitmapMaxHeight() + "\n"; if (QuranFileUtils.haveAllImages(QuranPreferenceActivity.this, qsi.getWidthParam())) { body += "all images found for " + qsi.getWidthParam() + "\n"; } if (qsi.isTablet(QuranPreferenceActivity.this) && QuranFileUtils.haveAllImages( QuranPreferenceActivity.this, qsi.getTabletWidthParam())) { body += "all tablet images found for " + qsi.getTabletWidthParam() + "\n"; } } catch (Exception e) { } int memClass = ((ActivityManager) QuranPreferenceActivity.this.getSystemService(Context.ACTIVITY_SERVICE)) .getMemoryClass(); body += "memory class: " + memClass + "\n\n"; body += "\n\n"; body += "\nLogs: " + logs; body += "\n\n"; emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, body); emailIntent.putExtra( android.content.Intent.EXTRA_SUBJECT, getString(R.string.email_logs_subject)); emailIntent.putExtra( android.content.Intent.EXTRA_EMAIL, new String[] {getString(R.string.email_to)}); startActivity(Intent.createChooser(emailIntent, getString(R.string.send_email))); }
GetAyahCoordsTask(Context context, int sura, int ayah, HighlightType type) { super(context, QuranScreenInfo.getInstance().getWidthParam(), sura, ayah, type); }
GetAyahCoordsTask(Context context, MotionEvent event, EventType eventType) { super(context, event, eventType, QuranScreenInfo.getInstance().getWidthParam(), pageNumber); }
GetAyahCoordsTask(Context context) { super(context, QuranScreenInfo.getInstance().getWidthParam()); }
QueryPageCoordinatesTask(Context context) { super(context, QuranScreenInfo.getInstance().getWidthParam()); }