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.reddyetwo.hashmypass.app.view.ViewPagerIndicator.java

/**
 * Constructor/*from w  w w. jav  a 2s.c  o m*/
 *
 * @param context the {@link android.content.Context} instance
 * @param attrs   the view attributes
 */
public ViewPagerIndicator(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.ViewPagerIndicator, 0, 0);
    mRadius = array.getDimensionPixelSize(R.styleable.ViewPagerIndicator_radius, 0);
    mSpacing = array.getDimensionPixelSize(R.styleable.ViewPagerIndicator_spacing, 0);
    mAlpha = (int) (array.getFloat(R.styleable.ViewPagerIndicator_alpha, DEFAULT_ALPHA) * ALPHA_MAX);
    mCurrentPositionAlpha = (int) (array.getFloat(R.styleable.ViewPagerIndicator_current_position_alpha,
            DEFAULT_CURRENT_POSITION_ALPHA) * ALPHA_MAX);

    // Initialize paint
    mPaint.setAntiAlias(true);
    mPaint.setColor(getResources().getColor(android.R.color.white));

}

From source file:ru.tlrs.vincent.VincentView.java

public VincentView(Context context, AttributeSet attrs, int src) {
    super(context, attrs, src);
    mContext = context;//from  w  w  w.  ja  v a 2  s .co m
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.VincentView, 0, 0);
    TypedArray b = context.getTheme().obtainStyledAttributes(attrs, new int[] { src }, 0, 0);
    try {
        mImgUri = a.getString(R.styleable.VincentView_imageUri);
        mOverlayMode = a.getBoolean(R.styleable.VincentView_overlayMode, false);
        mPinch2Zoom = !mOverlayMode && a.getBoolean(R.styleable.VincentView_pinch2zoomEnable, true);
        mGroupId = a.getInt(R.styleable.VincentView_groupId, 0);
        mSrc = b.getString(0);
    } finally {
        a.recycle();
        b.recycle();
    }
    setOnClickListener(this);
}

From source file:com.todev.rabbitmqmanagement.ui.overview.widget.MessageRatesIndicator.java

@Override
protected void initializeAttributes(Context context, AttributeSet attrs) {
    super.initializeAttributes(context, attrs);

    TypedArray array = context.getTheme().obtainStyledAttributes(attrs, R.styleable.MessageRatesIndicator, 0,
            0);//from  ww w  .j a v  a  2 s  .c  om

    try {
        publishColor = array.getColor(R.styleable.MessageRatesIndicator_publish_color,
                ContextCompat.getColor(context, R.color.messageRatesPublished));

        confirmColor = array.getColor(R.styleable.MessageRatesIndicator_confirm_color,
                ContextCompat.getColor(context, R.color.messagesRatesConfirmed));

        publishInColor = array.getColor(R.styleable.MessageRatesIndicator_publish_in_color,
                ContextCompat.getColor(context, R.color.messagesRatesPublishedIn));

        publishOutColor = array.getColor(R.styleable.MessageRatesIndicator_publish_out_color,
                ContextCompat.getColor(context, R.color.messagesRatesPublishedOut));

        deliverColor = array.getColor(R.styleable.MessageRatesIndicator_deliver_color,
                ContextCompat.getColor(context, R.color.messagesRatesDelivered));

        redeliveredColor = array.getColor(R.styleable.MessageRatesIndicator_redelivered_color,
                ContextCompat.getColor(context, R.color.messagesRatesRedelivered));
    } finally {
        array.recycle();
    }
}

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

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

    final Context context = getActivity();
    setBadgeDrawable(/*from  w w  w.  j  a  va 2  s. co m*/
            ResourcesCompat.getDrawable(context.getResources(), R.drawable.ic_title, context.getTheme()));
    setTitle("Leanback Vertical Grid Demo");

    setupFragment();
    if (TEST_ENTRANCE_TRANSITION) {
        // don't run entrance transition if fragment is restored.
        if (savedInstanceState == null) {
            prepareEntranceTransition();
        }
    }
    // simulates in a real world use case  data being loaded two seconds later
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            loadData();
            startEntranceTransition();
        }
    }, 2000);
}

From source file:com.roughike.swipeselector.SwipeSelector.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    TypedArray ta = context.getTheme().obtainStyledAttributes(attrs, R.styleable.SwipeSelector, defStyleAttr,
            defStyleRes);//from w  w w.j  ava  2s  .com

    int indicatorSize;
    int indicatorMargin;
    int indicatorInActiveColor;
    int indicatorActiveColor;
    int leftButtonResource;
    int rightButtonResource;

    String customFontPath;
    int titleTextAppearance;
    int descriptionTextAppearance;

    try {
        indicatorSize = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorSize,
                PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_SIZE));
        indicatorMargin = (int) ta.getDimension(R.styleable.SwipeSelector_swipe_indicatorMargin,
                PixelUtils.dpToPixel(context, DEFAULT_INDICATOR_MARGIN));
        indicatorInActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorInActiveColor,
                ContextCompat.getColor(context, R.color.swipeselector_color_indicator_inactive));
        indicatorActiveColor = ta.getColor(R.styleable.SwipeSelector_swipe_indicatorActiveColor,
                ContextCompat.getColor(context, R.color.swipeselector_color_indicator_active));

        leftButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_leftButtonResource,
                R.drawable.ic_action_navigation_chevron_left);
        rightButtonResource = ta.getResourceId(R.styleable.SwipeSelector_swipe_rightButtonResource,
                R.drawable.ic_action_navigation_chevron_right);

        customFontPath = ta.getString(R.styleable.SwipeSelector_swipe_customFontPath);
        titleTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_titleTextAppearance, -1);
        descriptionTextAppearance = ta.getResourceId(R.styleable.SwipeSelector_swipe_descriptionTextAppearance,
                -1);
    } finally {
        ta.recycle();
    }

    LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.swipeselector_layout, this);

    ViewPager pager = (ViewPager) findViewById(R.id.swipeselector_layout_swipePager);
    ViewGroup indicatorContainer = (ViewGroup) findViewById(R.id.swipeselector_layout_circleContainer);
    ImageView leftButton = (ImageView) findViewById(R.id.swipeselector_layout_leftButton);
    ImageView rightButton = (ImageView) findViewById(R.id.swipeselector_layout_rightButton);

    mAdapter = new SwipeAdapter.Builder().viewPager(pager).indicatorContainer(indicatorContainer)
            .indicatorSize(indicatorSize).indicatorMargin(indicatorMargin)
            .inActiveIndicatorColor(indicatorInActiveColor).activeIndicatorColor(indicatorActiveColor)
            .leftButtonResource(leftButtonResource).rightButtonResource(rightButtonResource)
            .leftButton(leftButton).rightButton(rightButton).customTypeFace(customFontPath)
            .titleTextAppearance(titleTextAppearance).descriptionTextAppearance(descriptionTextAppearance)
            .build();
    pager.setAdapter(mAdapter);
}

From source file:com.dictionary.codebhak.LangTextView.java

/**
 * Constructs a new {@code LangTextView}.
 *
 * @param context the {@link Context} to use
 * @param attrs the {@link AttributeSet} to use
 *//*from w  w  w  .  ja va  2s  .  com*/
public LangTextView(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray attrArray = context.getTheme().obtainStyledAttributes(attrs, R.styleable.lang_text_view, 0, 0);
    try {
        int attribute = R.styleable.lang_text_view_allowTextSizeChanges;
        mAllowTextSizeChanges = attrArray.getBoolean(attribute, true);
    } finally {
        attrArray.recycle();
    }

    setFont(context);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    prefs.registerOnSharedPreferenceChangeListener(this);
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static int getActionBarPopupThemeRes(final Context context, int def) {
    final TypedValue outValue = new TypedValue();
    if (context.getTheme().resolveAttribute(R.attr.actionBarPopupTheme, outValue, true)) {
        return outValue.resourceId;
    }//  w  w w.j a va2 s .c  o  m
    return def;
}

From source file:au.com.roadhouse.licensehelper.library.VerticalDividerItemDecorator.java

public VerticalDividerItemDecorator(Context context, @DimenRes int dividerHeight, @ColorRes int dividerColor) {
    mDividerHeight = context.getResources().getDimensionPixelOffset(dividerHeight);
    mDividerColor = ResourcesCompat.getColor(context.getResources(), dividerColor, context.getTheme());
    mDividerColorDrawable = new ColorDrawable(mDividerColor);
}

From source file:talex.zsw.baselibrary.view.CoolSwitch.CoolSwitch.java

private void initialize(Context context, AttributeSet attrs) {
    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.CoolSwitch, 0, 0);

    try {/*from   ww  w  . j  a  v a 2 s.co m*/
        disabledViewId = a.getResourceId(R.styleable.CoolSwitch_CS_disabledView, NO_ID);
        enabledViewId = a.getResourceId(R.styleable.CoolSwitch_CS_enabledView, NO_ID);
    } finally {
        a.recycle();
    }

    initialize();
}

From source file:com.google.blockly.android.ui.TrashCanView.java

public TrashCanView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.TrashCanView, 0, 0);
    try {//from ww w.  j  av a2  s .  co  m
        //noinspection ResourceType
        setDefaultIcon(a.getResourceId(R.styleable.TrashCanView_defaultIcon, R.drawable.blockly_trash));
        setOnHoverIcon(a.getResourceId(R.styleable.TrashCanView_onHoverIcon, R.drawable.blockly_trash_open));
    } finally {
        a.recycle();
    }
}