Example usage for android.content Context isRestricted

List of usage examples for android.content Context isRestricted

Introduction

In this page you can find the example usage for android.content Context isRestricted.

Prototype

public boolean isRestricted() 

Source Link

Document

Indicates whether this Context is restricted.

Usage

From source file:android.support.v7.widget.AppCompatTextHelper.java

private void updateTypefaceAndStyle(Context context, TintTypedArray a) {
    mStyle = a.getInt(R.styleable.TextAppearance_android_textStyle, mStyle);

    if (a.hasValue(R.styleable.TextAppearance_android_fontFamily)
            || a.hasValue(R.styleable.TextAppearance_fontFamily)) {
        mFontTypeface = null;/* ww w . j a v a 2 s .  com*/
        int fontFamilyId = a.hasValue(R.styleable.TextAppearance_fontFamily)
                ? R.styleable.TextAppearance_fontFamily
                : R.styleable.TextAppearance_android_fontFamily;
        if (!context.isRestricted()) {
            final WeakReference<TextView> textViewWeak = new WeakReference<>(mView);
            ResourcesCompat.FontCallback replyCallback = new ResourcesCompat.FontCallback() {
                @Override
                public void onFontRetrieved(@NonNull Typeface typeface) {
                    onAsyncTypefaceReceived(textViewWeak, typeface);
                }

                @Override
                public void onFontRetrievalFailed(int reason) {
                    // Do nothing.
                }
            };
            try {
                // Note the callback will be triggered on the UI thread.
                mFontTypeface = a.getFont(fontFamilyId, mStyle, replyCallback);
                // If this call gave us an immediate result, ignore any pending callbacks.
                mAsyncFontPending = mFontTypeface == null;
            } catch (UnsupportedOperationException | Resources.NotFoundException e) {
                // Expected if it is not a font resource.
            }
        }
        if (mFontTypeface == null) {
            // Try with String. This is done by TextView JB+, but fails in ICS
            String fontFamilyName = a.getString(fontFamilyId);
            if (fontFamilyName != null) {
                mFontTypeface = Typeface.create(fontFamilyName, mStyle);
            }
        }
        return;
    }

    if (a.hasValue(R.styleable.TextAppearance_android_typeface)) {
        // Ignore previous pending fonts
        mAsyncFontPending = false;
        int typefaceIndex = a.getInt(R.styleable.TextAppearance_android_typeface, SANS);
        switch (typefaceIndex) {
        case SANS:
            mFontTypeface = Typeface.SANS_SERIF;
            break;

        case SERIF:
            mFontTypeface = Typeface.SERIF;
            break;

        case MONOSPACE:
            mFontTypeface = Typeface.MONOSPACE;
            break;
        }
    }
}