Example usage for android.app Application getAssets

List of usage examples for android.app Application getAssets

Introduction

In this page you can find the example usage for android.app Application getAssets.

Prototype

@Override
    public AssetManager getAssets() 

Source Link

Usage

From source file:com.commonsware.android.diceware.PassphraseFragment.java

private void loadWords(boolean forceReload, boolean regenPassphrase) {
    if (wordsObservable == null || forceReload) {
        final Application app = getActivity().getApplication();

        wordsObservable = Observable
                .defer(() -> (Observable.just(PreferenceManager.getDefaultSharedPreferences(app))))
                .subscribeOn(Schedulers.io()).map(sharedPreferences -> {
                    PassphraseFragment.this.prefs = sharedPreferences;

                    return (sharedPreferences.getString(PREF_URI, ""));
                }).map(s -> {//www. j  a  v  a  2  s. c om
                    InputStream in;

                    if (s.length() == 0) {
                        in = app.getAssets().open(ASSET_FILENAME);
                    } else {
                        in = app.getContentResolver().openInputStream(Uri.parse(s));
                    }

                    return (readWords(in));
                }).cache().observeOn(AndroidSchedulers.mainThread());
    }

    unsubWords();

    if (regenPassphrase) {
        wordsSub = wordsObservable.subscribe(this::rollDemBones, error -> {
            Toast.makeText(getActivity(), error.getMessage(), Toast.LENGTH_LONG).show();
            Log.e(getClass().getSimpleName(), "Exception processing request", error);
        });
    }
}