Search in sources :

Example 1 with QuranApplication

use of com.quran.labs.androidquran.QuranApplication in project quran_android by quran.

the class PagerActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    QuranApplication quranApp = (QuranApplication) getApplication();
    quranApp.refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    // field injection
    getPagerActivityComponent().inject(this);
    bookmarksCache = new SparseBooleanArray();
    boolean shouldAdjustPageNumber = false;
    isDualPages = QuranUtils.isDualPages(this, quranScreenInfo);
    // remove the window background to avoid overdraw. note that, per Romain's blog, this is
    // acceptable (as long as we don't set the background color to null in the theme, since
    // that is used to generate preview windows).
    getWindow().setBackgroundDrawable(null);
    numberOfPages = quranInfo.getNumberOfPages();
    numberOfPagesDual = quranInfo.getNumberOfPagesDual();
    int page = -1;
    isActionBarHidden = true;
    if (savedInstanceState != null) {
        Timber.d("non-null saved instance state!");
        DownloadAudioRequest lastAudioRequest = savedInstanceState.getParcelable(LAST_AUDIO_DL_REQUEST);
        if (lastAudioRequest != null) {
            Timber.d("restoring request from saved instance!");
            lastAudioDownloadRequest = lastAudioRequest;
        }
        page = savedInstanceState.getInt(LAST_READ_PAGE, -1);
        if (page != -1) {
            page = numberOfPages - page;
        }
        showingTranslation = savedInstanceState.getBoolean(LAST_READING_MODE_IS_TRANSLATION, false);
        if (savedInstanceState.containsKey(LAST_ACTIONBAR_STATE)) {
            isActionBarHidden = !savedInstanceState.getBoolean(LAST_ACTIONBAR_STATE);
        }
        boolean lastWasDualPages = savedInstanceState.getBoolean(LAST_WAS_DUAL_PAGES, isDualPages);
        shouldAdjustPageNumber = (lastWasDualPages != isDualPages);
        start = savedInstanceState.getParcelable(LAST_START_POINT);
        end = savedInstanceState.getParcelable(LAST_ENDING_POINT);
        this.lastAudioRequest = savedInstanceState.getParcelable(LAST_AUDIO_REQUEST);
    } else {
        Intent intent = getIntent();
        Bundle extras = intent.getExtras();
        if (extras != null) {
            page = numberOfPages - extras.getInt("page", Constants.PAGES_FIRST);
            showingTranslation = extras.getBoolean(EXTRA_JUMP_TO_TRANSLATION, showingTranslation);
            highlightedSura = extras.getInt(EXTRA_HIGHLIGHT_SURA, -1);
            highlightedAyah = extras.getInt(EXTRA_HIGHLIGHT_AYAH, -1);
        }
    }
    compositeDisposable = new CompositeDisposable();
    // subscribe to changes in bookmarks
    compositeDisposable.add(bookmarkModel.bookmarksObservable().observeOn(AndroidSchedulers.mainThread()).subscribe(ignore -> {
        onBookmarksChanged();
    }));
    final Resources resources = getResources();
    isImmersiveInPortrait = resources.getBoolean(R.bool.immersive_in_portrait);
    isLandscape = resources.getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
    ayahToolBarTotalHeight = resources.getDimensionPixelSize(R.dimen.toolbar_total_height);
    setContentView(R.layout.quran_page_activity_slider);
    audioStatusBar = (AudioStatusBar) findViewById(R.id.audio_area);
    audioStatusBar.setIsDualPageMode(quranScreenInfo.isDualPageMode());
    audioStatusBar.setQariList(audioUtils.getQariList(this));
    audioStatusBar.setAudioBarListener(this);
    audioBarParams = (ViewGroup.MarginLayoutParams) audioStatusBar.getLayoutParams();
    toolBarArea = findViewById(R.id.toolbar_area);
    translationsSpinner = (QuranSpinner) findViewById(R.id.spinner);
    // this is the colored view behind the status bar on kitkat and above
    final View statusBarBackground = findViewById(R.id.status_bg);
    statusBarBackground.getLayoutParams().height = getStatusBarHeight();
    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (quranSettings.isArabicNames() || QuranUtils.isRtl()) {
        // remove when we remove LTR from quran_page_activity's root
        ViewCompat.setLayoutDirection(toolbar, ViewCompat.LAYOUT_DIRECTION_RTL);
    }
    setSupportActionBar(toolbar);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setDisplayShowHomeEnabled(true);
        ab.setDisplayHomeAsUpEnabled(true);
    }
    initAyahActionPanel();
    if (showingTranslation && translationItems != null) {
        updateActionBarSpinner();
    } else {
        updateActionBarTitle(numberOfPages - page);
    }
    lastPopupTime = System.currentTimeMillis();
    pagerAdapter = new QuranPageAdapter(getSupportFragmentManager(), isDualPages, showingTranslation, quranInfo);
    ayahToolBar = (AyahToolBar) findViewById(R.id.ayah_toolbar);
    final NonRestoringViewPager nonRestoringViewPager = findViewById(R.id.quran_pager);
    nonRestoringViewPager.setIsDualPagesInLandscape(QuranUtils.isDualPagesInLandscape(this, quranScreenInfo));
    viewPager = nonRestoringViewPager;
    viewPager.setAdapter(pagerAdapter);
    ayahToolBar.setOnItemSelectedListener(new AyahMenuItemSelectionHandler());
    viewPager.addOnPageChangeListener(new OnPageChangeListener() {

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            if (ayahToolBar.isShowing() && ayahToolBarPos != null) {
                final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
                int barPos = quranInfo.getPosFromPage(startPage, isDualPages);
                if (position == barPos) {
                    // Swiping to next ViewPager page (i.e. prev quran page)
                    ayahToolBarPos.xScroll = 0 - positionOffsetPixels;
                } else if (position == barPos - 1) {
                    // Swiping to prev ViewPager page (i.e. next quran page)
                    ayahToolBarPos.xScroll = viewPager.getWidth() - positionOffsetPixels;
                } else {
                    // Totally off screen, should hide toolbar
                    ayahToolBar.setVisibility(View.GONE);
                    return;
                }
                ayahToolBar.updatePosition(ayahToolBarPos);
                // If the toolbar is not showing, show it
                if (ayahToolBar.getVisibility() != View.VISIBLE) {
                    ayahToolBar.setVisibility(View.VISIBLE);
                }
            }
        }

        @Override
        public void onPageSelected(int position) {
            Timber.d("onPageSelected(): %d", position);
            final int page = quranInfo.getPageFromPos(position, isDualPages);
            if (quranSettings.shouldDisplayMarkerPopup()) {
                lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page, lastPopupTime);
                if (isDualPages) {
                    lastPopupTime = QuranDisplayHelper.displayMarkerPopup(PagerActivity.this, quranInfo, page - 1, lastPopupTime);
                }
            }
            if (!showingTranslation) {
                updateActionBarTitle(page);
            } else {
                refreshActionBarSpinner();
            }
            if (bookmarksCache.indexOfKey(page) < 0) {
                if (isDualPages) {
                    if (bookmarksCache.indexOfKey(page - 1) < 0) {
                        checkIfPageIsBookmarked(page - 1, page);
                    }
                } else {
                    // we don't have the key
                    checkIfPageIsBookmarked(page);
                }
            }
            // If we're more than 1 page away from ayah selection end ayah mode
            if (isInAyahMode) {
                final int startPage = quranInfo.getPageFromSuraAyah(start.sura, start.ayah);
                int ayahPos = quranInfo.getPosFromPage(startPage, isDualPages);
                if (Math.abs(ayahPos - position) > 1) {
                    endAyahMode();
                }
            }
        }
    });
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        setUiVisibilityListener();
        audioStatusBar.setVisibility(View.VISIBLE);
    }
    toggleActionBarVisibility(true);
    if (shouldAdjustPageNumber) {
        // when going from two page per screen to one or vice versa, we adjust the page number,
        // such that the first page is always selected.
        int curPage = numberOfPages - page;
        if (isDualPages) {
            if (curPage % 2 != 0) {
                curPage++;
            }
            curPage = numberOfPagesDual - (curPage / 2);
        } else {
            if (curPage % 2 == 0) {
                curPage--;
            }
            curPage = numberOfPages - curPage;
        }
        page = curPage;
    } else if (isDualPages) {
        page = page / 2;
    }
    viewPager.setCurrentItem(page);
    // just got created, need to reconnect to service
    shouldReconnect = true;
    // enforce orientation lock
    if (quranSettings.isLockOrientation()) {
        int current = getResources().getConfiguration().orientation;
        if (quranSettings.isLandscapeOrientation()) {
            if (current == Configuration.ORIENTATION_PORTRAIT) {
                setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
                return;
            }
        } else if (current == Configuration.ORIENTATION_LANDSCAPE) {
            setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
            return;
        }
    }
    LocalBroadcastManager.getInstance(this).registerReceiver(audioReceiver, new IntentFilter(AudioService.AudioUpdateIntent.INTENT_NAME));
    downloadReceiver = new DefaultDownloadReceiver(this, QuranDownloadService.DOWNLOAD_TYPE_AUDIO);
    String action = QuranDownloadNotifier.ProgressIntent.INTENT_NAME;
    LocalBroadcastManager.getInstance(this).registerReceiver(downloadReceiver, new IntentFilter(action));
    downloadReceiver.setListener(this);
}
Also used : Bundle(android.os.Bundle) AUDIO_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.AUDIO_PAGE) AyahInfoDatabaseProvider(com.quran.labs.androidquran.data.AyahInfoDatabaseProvider) QuranSpinner(com.quran.labs.androidquran.widgets.QuranSpinner) AyahToolBar(com.quran.labs.androidquran.widgets.AyahToolBar) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) Handler(android.os.Handler) TranslationsDBAdapter(com.quran.labs.androidquran.database.TranslationsDBAdapter) TargetApi(android.annotation.TargetApi) AudioStatusBar(com.quran.labs.androidquran.widgets.AudioStatusBar) TabletFragment(com.quran.labs.androidquran.ui.fragment.TabletFragment) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) Set(java.util.Set) PagerActivityComponent(com.quran.labs.androidquran.component.activity.PagerActivityComponent) QuranScreenInfo(com.quran.labs.androidquran.util.QuranScreenInfo) HelpActivity(com.quran.labs.androidquran.HelpActivity) HapticFeedbackConstants(android.view.HapticFeedbackConstants) NonRestoringViewPager(android.support.v4.view.NonRestoringViewPager) Message(android.os.Message) DisposableObserver(io.reactivex.observers.DisposableObserver) TranslationsSpinnerAdapter(com.quran.labs.androidquran.ui.util.TranslationsSpinnerAdapter) QariItem(com.quran.labs.androidquran.common.QariItem) DisposableSingleObserver(io.reactivex.observers.DisposableSingleObserver) TAG_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TAG_PAGE) QuranDownloadService(com.quran.labs.androidquran.service.QuranDownloadService) NonNull(android.support.annotation.NonNull) AudioUtils(com.quran.labs.androidquran.util.AudioUtils) StreamingAudioRequest(com.quran.labs.androidquran.service.util.StreamingAudioRequest) BookmarkModel(com.quran.labs.androidquran.model.bookmark.BookmarkModel) QuranDataProvider(com.quran.labs.androidquran.data.QuranDataProvider) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) Observable(io.reactivex.Observable) SearchActivity(com.quran.labs.androidquran.SearchActivity) ComponentName(android.content.ComponentName) QuranDownloadNotifier(com.quran.labs.androidquran.service.util.QuranDownloadNotifier) TRANSLATION_PAGE(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.TRANSLATION_PAGE) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) QuranApplication(com.quran.labs.androidquran.QuranApplication) File(java.io.File) FragmentManager(android.support.v4.app.FragmentManager) AlertDialog(android.support.v7.app.AlertDialog) SparseBooleanArray(android.util.SparseBooleanArray) SharedPreferences(android.content.SharedPreferences) Toolbar(android.support.v7.widget.Toolbar) Configuration(android.content.res.Configuration) QuranPreferenceActivity(com.quran.labs.androidquran.QuranPreferenceActivity) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) SearchView(android.support.v7.widget.SearchView) Constants(com.quran.labs.androidquran.data.Constants) WindowManager(android.view.WindowManager) ShareUtil(com.quran.labs.androidquran.util.ShareUtil) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) AddTagDialog(com.quran.labs.androidquran.ui.fragment.AddTagDialog) HighlightType(com.quran.labs.androidquran.ui.helpers.HighlightType) AyahSelectedListener(com.quran.labs.androidquran.ui.helpers.AyahSelectedListener) ActivityInfo(android.content.pm.ActivityInfo) R(com.quran.labs.androidquran.R) View(android.view.View) Schedulers(io.reactivex.schedulers.Schedulers) ViewCompat(android.support.v4.view.ViewCompat) QuranAppUtils(com.quran.labs.androidquran.util.QuranAppUtils) PreferenceManager(android.preference.PreferenceManager) AyahToolBarPosition(com.quran.labs.androidquran.widgets.AyahToolBar.AyahToolBarPosition) SlidingUpPanelLayout(com.quran.labs.androidquran.widgets.SlidingUpPanelLayout) AudioRequest(com.quran.labs.androidquran.service.util.AudioRequest) AyahActionFragment(com.quran.labs.androidquran.ui.fragment.AyahActionFragment) AudioService(com.quran.labs.androidquran.service.AudioService) MenuItemCompat(android.support.v4.view.MenuItemCompat) LocalTranslation(com.quran.labs.androidquran.common.LocalTranslation) QuranDisplayHelper(com.quran.labs.androidquran.ui.helpers.QuranDisplayHelper) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) Timber(timber.log.Timber) PAGES(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter.PAGES) List(java.util.List) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) QuranInfo(com.quran.labs.androidquran.data.QuranInfo) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) TranslationFragment(com.quran.labs.androidquran.ui.fragment.TranslationFragment) Nullable(android.support.annotation.Nullable) SearchManager(android.app.SearchManager) RecentPagePresenter(com.quran.labs.androidquran.presenter.bookmark.RecentPagePresenter) Context(android.content.Context) ArabicDatabaseUtils(com.quran.labs.androidquran.model.translation.ArabicDatabaseUtils) KeyEvent(android.view.KeyEvent) JumpFragment(com.quran.labs.androidquran.ui.fragment.JumpFragment) ViewPager(android.support.v4.view.ViewPager) ServiceIntentHelper(com.quran.labs.androidquran.service.util.ServiceIntentHelper) Intent(android.content.Intent) QuranUtils(com.quran.labs.androidquran.util.QuranUtils) Single(io.reactivex.Single) MenuItem(android.view.MenuItem) IconPageIndicator(com.quran.labs.androidquran.widgets.IconPageIndicator) HashSet(java.util.HashSet) Inject(javax.inject.Inject) TagBookmarkDialog(com.quran.labs.androidquran.ui.fragment.TagBookmarkDialog) SuraAyah(com.quran.labs.androidquran.data.SuraAyah) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ActionBar(android.support.v7.app.ActionBar) SlidingPagerAdapter(com.quran.labs.androidquran.ui.helpers.SlidingPagerAdapter) QuranPageWorker(com.quran.labs.androidquran.ui.helpers.QuranPageWorker) QuranPage(com.quran.labs.androidquran.ui.helpers.QuranPage) AyahTracker(com.quran.labs.androidquran.ui.helpers.AyahTracker) JumpDestination(com.quran.labs.androidquran.ui.helpers.JumpDestination) Pair(android.support.v4.util.Pair) PagerActivityModule(com.quran.labs.androidquran.module.activity.PagerActivityModule) Resources(android.content.res.Resources) IntentFilter(android.content.IntentFilter) Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) OnPageChangeListener(android.support.v4.view.ViewPager.OnPageChangeListener) Intent(android.content.Intent) SearchView(android.support.v7.widget.SearchView) View(android.view.View) QuranApplication(com.quran.labs.androidquran.QuranApplication) NonRestoringViewPager(android.support.v4.view.NonRestoringViewPager) DefaultDownloadReceiver(com.quran.labs.androidquran.service.util.DefaultDownloadReceiver) SparseBooleanArray(android.util.SparseBooleanArray) QuranPageAdapter(com.quran.labs.androidquran.ui.helpers.QuranPageAdapter) DownloadAudioRequest(com.quran.labs.androidquran.service.util.DownloadAudioRequest) Resources(android.content.res.Resources) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ActionBar(android.support.v7.app.ActionBar) Toolbar(android.support.v7.widget.Toolbar)

Example 2 with QuranApplication

use of com.quran.labs.androidquran.QuranApplication in project quran_android by quran.

the class QuranActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    QuranApplication quranApp = (QuranApplication) getApplication();
    quranApp.refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    quranApp.getApplicationComponent().inject(this);
    setContentView(R.layout.quran_index);
    compositeDisposable = new CompositeDisposable();
    settings = QuranSettings.getInstance(this);
    isRtl = isRtl();
    final Toolbar tb = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(tb);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(R.string.app_name);
    }
    final ViewPager pager = (ViewPager) findViewById(R.id.index_pager);
    pager.setOffscreenPageLimit(3);
    PagerAdapter pagerAdapter = new PagerAdapter(getSupportFragmentManager());
    pager.setAdapter(pagerAdapter);
    final SlidingTabLayout indicator = (SlidingTabLayout) findViewById(R.id.indicator);
    indicator.setViewPager(pager);
    if (isRtl) {
        pager.setCurrentItem(TITLES.length - 1);
    }
    if (savedInstanceState != null) {
        showedTranslationUpgradeDialog = savedInstanceState.getBoolean(SI_SHOWED_UPGRADE_DIALOG, false);
    }
    recentPages = recentPageModel.getLatestPageObservable();
    Intent intent = getIntent();
    if (intent != null) {
        Bundle extras = intent.getExtras();
        if (extras != null) {
            if (extras.getBoolean(EXTRA_SHOW_TRANSLATION_UPGRADE, false)) {
                if (!showedTranslationUpgradeDialog) {
                    showTranslationsUpgradeDialog();
                }
            }
        }
        if (ShortcutsActivity.ACTION_JUMP_TO_LATEST.equals(intent.getAction())) {
            jumpToLastPage();
        }
    }
    updateTranslationsListAsNeeded();
}
Also used : Bundle(android.os.Bundle) SlidingTabLayout(com.quran.labs.androidquran.widgets.SlidingTabLayout) Intent(android.content.Intent) ViewPager(android.support.v4.view.ViewPager) CompositeDisposable(io.reactivex.disposables.CompositeDisposable) ActionBar(android.support.v7.app.ActionBar) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) QuranApplication(com.quran.labs.androidquran.QuranApplication) Toolbar(android.support.v7.widget.Toolbar)

Example 3 with QuranApplication

use of com.quran.labs.androidquran.QuranApplication in project quran_android by quran.

the class QuranAdvancedSettingsFragment method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.quran_advanced_preferences);
    final Context context = getActivity();
    appContext = context.getApplicationContext();
    // field injection
    ((QuranApplication) appContext).getApplicationComponent().inject(this);
    final Preference logsPref = findPreference(Constants.PREF_LOGS);
    if (BuildConfig.DEBUG || "beta".equals(BuildConfig.BUILD_TYPE)) {
        logsPref.setOnPreferenceClickListener(preference -> {
            if (logsSubscription == null) {
                logsSubscription = Observable.fromIterable(Timber.forest()).filter(tree -> tree instanceof RecordingLogTree).firstElement().map(tree -> ((RecordingLogTree) tree).getLogs()).map(logs -> QuranUtils.getDebugInfo(appContext, quranScreenInfo) + "\n\n" + logs).subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableMaybeObserver<String>() {

                    @Override
                    public void onSuccess(String logs) {
                        Intent intent = new Intent(Intent.ACTION_SEND);
                        intent.setType("message/rfc822");
                        intent.putExtra(Intent.EXTRA_EMAIL, new String[] { appContext.getString(R.string.logs_email) });
                        intent.putExtra(Intent.EXTRA_TEXT, logs);
                        intent.putExtra(Intent.EXTRA_SUBJECT, "Logs");
                        startActivity(Intent.createChooser(intent, appContext.getString(R.string.prefs_send_logs_title)));
                        logsSubscription = null;
                    }

                    @Override
                    public void onError(Throwable e) {
                    }

                    @Override
                    public void onComplete() {
                    }
                });
            }
            return true;
        });
    } else {
        removeAdvancePreference(logsPref);
    }
    final Preference importPref = findPreference(Constants.PREF_IMPORT);
    importPref.setOnPreferenceClickListener(preference -> {
        Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
        intent.setType("*/*");
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            String[] mimeTypes = new String[] { "application/*", "text/*" };
            intent.putExtra(Intent.EXTRA_MIME_TYPES, mimeTypes);
        }
        startActivityForResult(intent, REQUEST_CODE_IMPORT);
        return true;
    });
    final Preference exportPref = findPreference(Constants.PREF_EXPORT);
    exportPref.setOnPreferenceClickListener(preference -> {
        if (exportSubscription == null) {
            exportSubscription = bookmarkImportExportModel.exportBookmarksObservable().observeOn(AndroidSchedulers.mainThread()).subscribeWith(new DisposableSingleObserver<Uri>() {

                @Override
                public void onSuccess(Uri uri) {
                    Answers.getInstance().logCustom(new CustomEvent("exportData"));
                    Intent shareIntent = new Intent(Intent.ACTION_SEND);
                    shareIntent.setType("application/json");
                    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    shareIntent.putExtra(Intent.EXTRA_STREAM, uri);
                    List<ResolveInfo> intents = appContext.getPackageManager().queryIntentActivities(shareIntent, 0);
                    if (intents.size() > 1) {
                        // if only one, then that is likely Quran for Android itself, so don't show
                        // the chooser since it doesn't really make sense.
                        context.startActivity(Intent.createChooser(shareIntent, context.getString(R.string.prefs_export_title)));
                    } else {
                        File exportedPath = new File(appContext.getExternalFilesDir(null), "backups");
                        String exported = appContext.getString(R.string.exported_data, exportedPath.toString());
                        Toast.makeText(appContext, exported, Toast.LENGTH_LONG).show();
                    }
                }

                @Override
                public void onError(Throwable e) {
                    exportSubscription = null;
                    if (isAdded()) {
                        Toast.makeText(context, R.string.export_data_error, Toast.LENGTH_LONG).show();
                    }
                }
            });
        }
        return true;
    });
    internalSdcardLocation = Environment.getExternalStorageDirectory().getAbsolutePath();
    listStoragePref = (DataListPreference) findPreference(getString(R.string.prefs_app_location));
    listStoragePref.setEnabled(false);
    try {
        storageList = StorageUtils.getAllStorageLocations(context.getApplicationContext());
    } catch (Exception e) {
        Timber.d(e, "Exception while trying to get storage locations");
        storageList = new ArrayList<>();
    }
    // except for the normal Environment.getExternalStorageDirectory
    if (storageList == null || storageList.size() <= 1) {
        Timber.d("removing advanced settings from preferences");
        hideStorageListPref();
    } else {
        loadStorageOptionsTask = new LoadStorageOptionsTask(context, quranFileUtils);
        loadStorageOptionsTask.execute();
    }
}
Also used : Context(android.content.Context) Context(android.content.Context) QuranImportActivity(com.quran.labs.androidquran.QuranImportActivity) Bundle(android.os.Bundle) Environment(android.os.Environment) Constants(com.quran.labs.androidquran.data.Constants) Uri(android.net.Uri) DataListPreference(com.quran.labs.androidquran.ui.preference.DataListPreference) Intent(android.content.Intent) QuranUtils(com.quran.labs.androidquran.util.QuranUtils) HashMap(java.util.HashMap) AndroidSchedulers(io.reactivex.android.schedulers.AndroidSchedulers) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) Toast(android.widget.Toast) R(com.quran.labs.androidquran.R) BuildConfig(com.quran.labs.androidquran.BuildConfig) QuranFileUtils(com.quran.labs.androidquran.util.QuranFileUtils) QuranSettings(com.quran.labs.androidquran.util.QuranSettings) Observable(io.reactivex.Observable) Schedulers(io.reactivex.schedulers.Schedulers) Build(android.os.Build) AsyncTask(android.os.AsyncTask) QuranAdvancedPreferenceActivity(com.quran.labs.androidquran.QuranAdvancedPreferenceActivity) ProgressDialog(android.app.ProgressDialog) TextUtils(android.text.TextUtils) QuranApplication(com.quran.labs.androidquran.QuranApplication) PermissionUtil(com.quran.labs.androidquran.service.util.PermissionUtil) QuranScreenInfo(com.quran.labs.androidquran.util.QuranScreenInfo) File(java.io.File) Timber(timber.log.Timber) ResolveInfo(android.content.pm.ResolveInfo) CustomEvent(com.crashlytics.android.answers.CustomEvent) StorageUtils(com.quran.labs.androidquran.util.StorageUtils) List(java.util.List) Disposable(io.reactivex.disposables.Disposable) PreferenceGroup(android.preference.PreferenceGroup) AlertDialog(android.support.v7.app.AlertDialog) BookmarkImportExportModel(com.quran.labs.androidquran.model.bookmark.BookmarkImportExportModel) DisposableMaybeObserver(io.reactivex.observers.DisposableMaybeObserver) Preference(android.preference.Preference) PreferenceFragment(android.preference.PreferenceFragment) Answers(com.crashlytics.android.answers.Answers) Activity(android.app.Activity) DisposableSingleObserver(io.reactivex.observers.DisposableSingleObserver) RecordingLogTree(com.quran.labs.androidquran.util.RecordingLogTree) CustomEvent(com.crashlytics.android.answers.CustomEvent) DisposableSingleObserver(io.reactivex.observers.DisposableSingleObserver) ArrayList(java.util.ArrayList) Intent(android.content.Intent) Uri(android.net.Uri) ResolveInfo(android.content.pm.ResolveInfo) DataListPreference(com.quran.labs.androidquran.ui.preference.DataListPreference) Preference(android.preference.Preference) RecordingLogTree(com.quran.labs.androidquran.util.RecordingLogTree) DisposableMaybeObserver(io.reactivex.observers.DisposableMaybeObserver) File(java.io.File)

Example 4 with QuranApplication

use of com.quran.labs.androidquran.QuranApplication in project quran_android by quran.

the class AudioManagerActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    QuranApplication quranApp = (QuranApplication) getApplication();
    quranApp.getApplicationComponent().inject(this);
    quranApp.refreshLocale(this, false);
    super.onCreate(savedInstanceState);
    final ActionBar ab = getSupportActionBar();
    if (ab != null) {
        ab.setTitle(R.string.audio_manager);
        ab.setDisplayHomeAsUpEnabled(true);
    }
    setContentView(R.layout.audio_manager);
    recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
    recyclerView.setHasFixedSize(true);
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    recyclerView.setItemAnimator(new DefaultItemAnimator());
    qariItems = audioUtils.getQariList(this);
    shuyookhAdapter = new ShuyookhAdapter(qariItems);
    recyclerView.setAdapter(shuyookhAdapter);
    progressBar = (ProgressBar) findViewById(R.id.progress);
    basePath = quranFileUtils.getQuranAudioDirectory(this);
    getShuyookhData();
}
Also used : LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) ActionBar(android.support.v7.app.ActionBar) DefaultItemAnimator(android.support.v7.widget.DefaultItemAnimator) QuranApplication(com.quran.labs.androidquran.QuranApplication)

Example 5 with QuranApplication

use of com.quran.labs.androidquran.QuranApplication in project quran_android by quran.

the class QuranDataProvider method query.

@Override
public Cursor query(@NonNull Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) {
    Context context = getContext();
    if (!didInject) {
        Context appContext = context == null ? null : context.getApplicationContext();
        if (appContext instanceof QuranApplication) {
            ((QuranApplication) appContext).getApplicationComponent().inject(this);
            didInject = true;
        } else {
            Timber.e("unable to inject QuranDataProvider");
            return null;
        }
    }
    Crashlytics.log("uri: " + uri.toString());
    switch(uriMatcher.match(uri)) {
        case SEARCH_SUGGEST:
            {
                if (selectionArgs == null) {
                    throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
                }
                return getSuggestions(selectionArgs[0]);
            }
        case SEARCH_VERSES:
            {
                if (selectionArgs == null) {
                    throw new IllegalArgumentException("selectionArgs must be provided for the Uri: " + uri);
                }
                return search(selectionArgs[0]);
            }
        default:
            {
                throw new IllegalArgumentException("Unknown Uri: " + uri);
            }
    }
}
Also used : Context(android.content.Context) QuranApplication(com.quran.labs.androidquran.QuranApplication)

Aggregations

QuranApplication (com.quran.labs.androidquran.QuranApplication)5 Context (android.content.Context)3 Intent (android.content.Intent)3 Bundle (android.os.Bundle)3 ActionBar (android.support.v7.app.ActionBar)3 ProgressDialog (android.app.ProgressDialog)2 Build (android.os.Build)2 ViewPager (android.support.v4.view.ViewPager)2 AlertDialog (android.support.v7.app.AlertDialog)2 Toolbar (android.support.v7.widget.Toolbar)2 TextUtils (android.text.TextUtils)2 Toast (android.widget.Toast)2 R (com.quran.labs.androidquran.R)2 Constants (com.quran.labs.androidquran.data.Constants)2 QuranFileUtils (com.quran.labs.androidquran.util.QuranFileUtils)2 QuranScreenInfo (com.quran.labs.androidquran.util.QuranScreenInfo)2 QuranSettings (com.quran.labs.androidquran.util.QuranSettings)2 QuranUtils (com.quran.labs.androidquran.util.QuranUtils)2 Observable (io.reactivex.Observable)2 AndroidSchedulers (io.reactivex.android.schedulers.AndroidSchedulers)2