Example usage for android.content Context getTheme

List of usage examples for android.content Context getTheme

Introduction

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

Prototype

@ViewDebug.ExportedProperty(deepExport = true)
public abstract Resources.Theme getTheme();

Source Link

Document

Return the Theme object associated with this Context.

Usage

From source file:com.snippet.widget.ViewIndicator.java

private void init(Context context) {
    TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.ViewIndicator, R.attr.viStyles,
            0);/*from   w ww.  j a  v a2 s .  co m*/
    float radiusDp = a.getDimension(R.styleable.ViewIndicator_vi_radius, DEFAULT_RADIUS);
    mRadius = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, radiusDp,
            getResources().getDisplayMetrics());
    if (mRadius <= 0) {
        mRadius = DEFAULT_RADIUS;
    }
    float distanceDp = a.getDimension(R.styleable.ViewIndicator_vi_distance, DEFAULT_DISTANCE);
    mDistance = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, distanceDp,
            getResources().getDisplayMetrics());
    if (mDistance <= 0) {
        mDistance = DEFAULT_DISTANCE;
    }
    a.recycle();
}

From source file:com.druk.bonjour.browser.ui.adapter.TxtRecordsAdapter.java

public TxtRecordsAdapter(Context context, Map<String, String> records) {
    TypedValue mTypedValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.selectableItemBackground, mTypedValue, true);
    mBackground = mTypedValue.resourceId;
    mRecords.putAll(records);/* ww  w .  j  a  va2  s  .c om*/
}

From source file:wistcat.overtime.widget.DividerItemDecoration.java

public DividerItemDecoration(Context context, int orientation, int leftOffset, int rightOffset) {
    final TypedArray ta = context.getTheme().obtainStyledAttributes(ATTRS);
    mDivider = ta.getDrawable(0);/*from   ww  w .ja  v a2s. c o m*/
    ta.recycle();
    setOrientation(orientation);
    mLeftOffset = leftOffset;
    mRightOffset = rightOffset;
}

From source file:com.netpace.expressit.android.ui.TypefaceEditText.java

public TypefaceEditText(Context context, AttributeSet attrs) {
    super(context, attrs);

    // Get our custom attributes
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TypefaceTextView, 0, 0);

    try {//from   ww w.  j  ava 2 s  .  co  m
        String typefaceName = a.getString(R.styleable.TypefaceTextView_typeface);

        if (!isInEditMode() && !TextUtils.isEmpty(typefaceName)) {
            Typeface typeface = sTypefaceCache.get(typefaceName);

            if (typeface == null) {
                typeface = Typeface.createFromAsset(context.getAssets(),
                        String.format("fonts/%s_0.otf", typefaceName));

                // Cache the Typeface object
                sTypefaceCache.put(typefaceName, typeface);
            }
            setTypeface(typeface);

            // Note: This flag is required for proper typeface rendering
            setPaintFlags(getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG);
        }
    } finally {
        a.recycle();
    }
}

From source file:com.qiscus.sdk.ui.view.QiscusLinkPreviewView.java

private void applyAttrs(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.QiscusLinkPreviewView, 0, 0);
    int titleColor;
    int descColor;
    try {/*  ww  w .  ja  v  a 2 s .c om*/
        titleColor = a.getColor(R.styleable.QiscusLinkPreviewView_qpreview_titleColor,
                ContextCompat.getColor(getContext(), R.color.qiscus_white));
        descColor = a.getColor(R.styleable.QiscusLinkPreviewView_qpreview_descColor,
                ContextCompat.getColor(getContext(), R.color.qiscus_white));
    } finally {
        a.recycle();
    }

    title.setTextColor(titleColor);
    description.setTextColor(descColor);

    initLayout();
}

From source file:com.example.android.leanback.ErrorFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate");
    super.onCreate(savedInstanceState);

    setTitle("Leanback Sample App");
    final Context context = getActivity();
    setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.lb_ic_sad_cloud,
            context.getTheme()));
    setMessage("An error occurred.");
    setDefaultBackground(TRANSLUCENT);// w w w.  ja v a 2s  . c o  m

    setButtonText("Dismiss");
    setButtonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Log.i(TAG, "button clicked");
            getFragmentManager().beginTransaction().remove(ErrorFragment.this).commit();
        }
    });
}

From source file:com.example.android.leanback.ErrorSupportFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    Log.i(TAG, "onCreate");
    super.onCreate(savedInstanceState);

    setTitle("Leanback Sample App");
    final Context context = getActivity();
    setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), R.drawable.lb_ic_sad_cloud,
            context.getTheme()));
    setMessage("An error occurred.");
    setDefaultBackground(TRANSLUCENT);//from ww w  . jav a 2 s.c  om

    setButtonText("Dismiss");
    setButtonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View arg0) {
            Log.i(TAG, "button clicked");
            getFragmentManager().beginTransaction().remove(ErrorSupportFragment.this).commit();
        }
    });
}

From source file:org.bubenheimer.android.preference.ConstrainedEditTextPreference.java

@SuppressWarnings("WeakerAccess")
protected ConstrainedEditTextPreference(final Context context, final AttributeSet attrs,
        final Pair<Integer, Integer> defaults) {
    super(context, attrs);

    final TypedArray a = context.getTheme().obtainStyledAttributes(attrs,
            R.styleable.ConstrainedEditTextPreference, 0, 0);
    try {/*from  w  w w .  j ava  2 s .c  o  m*/
        this.minLength = a.getInteger(R.styleable.ConstrainedEditTextPreference_minLen, defaults.first);
        this.maxLength = a.getInteger(R.styleable.ConstrainedEditTextPreference_maxLen, defaults.second);
    } finally {
        a.recycle();
    }
}

From source file:org.kontalk.ui.adapter.ContactsListAdapter.java

public void setPinnedHeader(Context context) {
    final TypedValue typedValue = new TypedValue();

    context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedValue, true);
    int pinnedHeaderBackgroundColor = ContextCompat.getColor(context, typedValue.resourceId);
    setPinnedHeaderBackgroundColor(pinnedHeaderBackgroundColor);

    int textColor = ContextCompat.getColor(context, R.color.pinned_header_text);
    setPinnedHeaderTextColor(textColor);
}

From source file:com.google.blockly.android.CategorySelectorFragment.java

@Override
public void onInflate(Context context, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(context, attrs, savedInstanceState);
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.BlocklyCategory, 0, 0);

    try {//  w  w w. ja va2 s  .c o  m
        mScrollOrientation = a.getInt(R.styleable.BlocklyCategory_scrollOrientation, mScrollOrientation);
        //noinspection ResourceType
        mLabelRotation = a.getInt(R.styleable.BlocklyCategory_labelRotation, mLabelRotation);
    } finally {
        a.recycle();
    }
}