Example usage for android.util TypedValue TypedValue

List of usage examples for android.util TypedValue TypedValue

Introduction

In this page you can find the example usage for android.util TypedValue TypedValue.

Prototype

TypedValue

Source Link

Usage

From source file:com.flexible.flexibleadapter.utils.DrawableUtils.java

/**
 * Helper to get the default selectableItemBackground drawable of the
 * {@code R.attr.selectableItemBackground} attribute of the overridden style.
 *
 * @param context the context//from w w w.j  a  v a  2s .  c o  m
 * @return Default selectable item background drawable
 * @since 5.0.0-rc1
 */
public static Drawable getSelectableItemBackground(Context context) {
    TypedValue outValue = new TypedValue();
    // It's important to not use the android.R because this wouldn't add the overridden drawable
    context.getTheme().resolveAttribute(R.attr.selectableItemBackground, outValue, true);
    return getDrawableCompat(context, outValue.resourceId);
}

From source file:com.google.android.apps.santatracker.village.Village.java

public int[] getIntArray(Resources resources, int resId) {
    TypedArray array = resources.obtainTypedArray(resId);
    int[] rc = new int[array.length()];
    TypedValue value = new TypedValue();
    for (int i = 0; i < array.length(); i++) {
        array.getValue(i, value);//from  ww  w .  ja  v  a2  s  . c o m
        rc[i] = value.resourceId;
    }
    array.recycle();
    return rc;
}

From source file:com.axum.darivb.searchview.SlidingTabLayout.java

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(bariol_regular_tf);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // If we're running on Honeycomb or newer, then we can use the Theme's
        // selectableItemBackground to ensure that the View has a pressed state
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }/*from   w w  w.j  a v  a 2 s.  c o  m*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        // If we're running on ICS or newer, enable all-caps to match the Action Bar tab style
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:android.support.v7ox.app.AppCompatDialog.java

private static int getThemeResId(Context context, int themeId) {
    if (themeId == 0) {
        // If the provided theme is 0, then retrieve the dialogTheme from our theme
        TypedValue outValue = new TypedValue();
        context.getTheme().resolveAttribute(R.attr.dialogTheme_ox, outValue, true);
        themeId = outValue.resourceId;// w w w.j a v a 2 s.  co m
    }
    return themeId;
}

From source file:com.dimelo.sampleapp.google.IconSlidingTabLayout.java

@Override
protected void populateTabStrip() {
    final PagerAdapter adapter = mViewPager.getAdapter();
    final View.OnClickListener tabClickListener = new TabClickListener();

    for (int i = 0; i < adapter.getCount(); i++) {
        View tabView = null;/*from   w  w  w . j  av a 2s .  c o  m*/
        TextView tabTitleView = null;
        ImageView iconImageView = null;

        if (mTabViewLayoutId == 0) {
            setCustomTabView(R.layout.icon_sliding_tab, R.id.tab_layout_title);
        }

        // If there is a custom tab view layout id set, try and inflate it
        tabView = LayoutInflater.from(getContext()).inflate(R.layout.icon_sliding_tab, mTabStrip, false);
        tabTitleView = (TextView) tabView.findViewById(mTabViewTextViewId);

        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        tabTitleView.setBackgroundResource(outValue.resourceId);
        tabTitleView.setAllCaps(true);

        int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
        tabTitleView.setPadding(padding, padding, padding, padding);

        iconImageView = (ImageView) tabView.findViewById(R.id.tab_layout_icon);

        //            if (tabView == null) {
        //                tabView = createDefaultTabView(getContext());
        //            }
        //
        //            if (tabTitleView == null && TextView.class.isInstance(tabView)) {
        //                tabTitleView = (TextView) tabView;
        //            }

        if (mDistributeEvenly) {
            LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) tabView.getLayoutParams();
            lp.width = 0;
            lp.weight = 1;
        }

        tabTitleView.setText(adapter.getPageTitle(i));
        // Not very beautifull, can be improved in the future
        if (adapter instanceof ViewPagerIconAndTextAdapter) {
            //                int id = ((ViewPagerIconAndTextAdapter)adapter).getPageIconId(i);
            //                Drawable drawable = getContext().getResources().getDrawable(id);
            //                DrawableCompat.setTint(drawable, Color.GREEN);
            //                iconImageView.setImageDrawable(drawable);
            updateIcon(iconImageView, i);
        }
        tabView.setOnClickListener(tabClickListener);
        String desc = mContentDescriptions.get(i, null);
        if (desc != null) {
            tabView.setContentDescription(desc);
        }

        mTabStrip.addView(tabView);
        if (i == mViewPager.getCurrentItem()) {
            tabView.setSelected(true);
        }
        tabTitleView.setTextColor(getResources().getColorStateList(R.color.text_slider_selector));
    }
}

From source file:com.chaos.dmactiontabsexample.view.SlidingTabLayout.java

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);/*  w  w w. j a v  a2s.  c  o  m*/

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.example.emamianrizif.Movie.views.SlidingTabLayout.java

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
    textView.setTypeface(Typeface.DEFAULT_BOLD);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        TypedValue outValue = new TypedValue();
        getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
        textView.setBackgroundResource(outValue.resourceId);
    }/* w w w  .j av a 2s  .  com*/

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        textView.setAllCaps(true);
    }

    int padding = (int) (TAB_VIEW_PADDING_DIPS * getResources().getDisplayMetrics().density);
    textView.setPadding(padding, padding, padding, padding);

    return textView;
}

From source file:com.android.purenexussettings.utils.SlidingTabLayout.java

protected TextView createDefaultTabView(Context context) {
    TextView textView = new TextView(context);
    textView.setGravity(Gravity.CENTER);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,
            getResources().getInteger(R.integer.slidetab_view_text_size_sp));
    textView.setTypeface(Typeface.DEFAULT_BOLD);
    textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));

    TypedValue outValue = new TypedValue();
    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
    textView.setBackgroundResource(outValue.resourceId);
    textView.setAllCaps(true);/* ww  w.j  ava  2s.c om*/

    // some fudging around for padding of the tabs
    int paddingtb = (int) (getResources().getInteger(R.integer.slidetab_view_top_padding_dips)
            * getResources().getDisplayMetrics().density);
    int paddinglr = (int) (getResources().getInteger(R.integer.slidetab_view_padding_dips)
            * getResources().getDisplayMetrics().density);
    textView.setPadding(paddinglr, paddingtb, paddinglr, paddingtb);

    return textView;
}

From source file:com.frozendevs.periodictable.view.ViewPagerTabs.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ViewPagerTabs(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    setFillViewport(true);// www. j a  va 2 s .  co m

    mSidePadding = getResources().getDimensionPixelOffset(R.dimen.tab_side_padding);

    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    mTextSize = a.getDimensionPixelSize(0, 0);
    mTextStyle = a.getInt(1, 0);
    mTextColor = a.getColorStateList(2);
    a.recycle();

    Resources.Theme theme = getContext().getTheme();
    TypedValue typedValue = new TypedValue();
    theme.resolveAttribute(R.attr.theme, typedValue, true);
    TypedArray typedArray = theme.obtainStyledAttributes(typedValue.resourceId,
            new int[] { R.attr.selectableItemBackground });
    mTextBackground = typedArray.getResourceId(0, 0);
    typedArray.recycle();

    mTabStrip = new ViewPagerTabStrip(context);
    addView(mTabStrip, new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // enable shadow casting from view bounds
        setOutlineProvider(new ViewOutlineProvider() {
            @TargetApi(Build.VERSION_CODES.LOLLIPOP)
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setRect(0, 0, view.getWidth(), view.getHeight());
            }
        });
    }
}

From source file:com.github.rubensousa.floatingtoolbar.FloatingToolbar.java

public FloatingToolbar(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingToolbar, 0, 0);

    TypedValue outValue = new TypedValue();

    // Set colorAccent as default color
    if (getBackground() == null) {
        getContext().getTheme().resolveAttribute(R.attr.colorAccent, outValue, true);
        setBackgroundResource(outValue.resourceId);
    }/*from ww  w  . j  ava2s. c  o  m*/

    getContext().getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);

    mMorphListeners = new ArrayList<>();
    mScrollListener = new FloatingScrollListener(this);
    mShowToast = a.getBoolean(R.styleable.FloatingToolbar_floatingToastOnLongClick, true);
    mHandleFabClick = a.getBoolean(R.styleable.FloatingToolbar_floatingHandleFabClick, true);
    mItemBackground = a.getResourceId(R.styleable.FloatingToolbar_floatingItemBackground, outValue.resourceId);
    mMenuRes = a.getResourceId(R.styleable.FloatingToolbar_floatingMenu, 0);

    int customView = a.getResourceId(R.styleable.FloatingToolbar_floatingCustomView, 0);

    if (customView != 0) {
        mCustomView = LayoutInflater.from(context).inflate(customView, this, true);
    }

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        mAnimator = new FloatingAnimatorImpl(this);
    } else {
        mAnimator = new FloatingAnimatorLollipopImpl(this);
    }

    if (mCustomView != null) {
        mAnimator.setContentView(mCustomView);
    }

    // Set elevation to 6dp
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        setElevation(dpToPixels(context, 6));
    }

    if (mMenuRes != 0 && customView == 0) {
        mMenuLayout = new LinearLayoutCompat(context, attrs, defStyleAttr);

        LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);

        mMenuLayout.setId(genViewId());
        addView(mMenuLayout, layoutParams);
        addMenuItems();
        mAnimator.setContentView(mMenuLayout);
    }

    if (!isInEditMode()) {
        setVisibility(View.INVISIBLE);
    }

    a.recycle();

    setOrientation(HORIZONTAL);
}