Example usage for android.content.res TypedArray peekValue

List of usage examples for android.content.res TypedArray peekValue

Introduction

In this page you can find the example usage for android.content.res TypedArray peekValue.

Prototype

public TypedValue peekValue(@StyleableRes int index) 

Source Link

Document

Retrieve the raw TypedValue for the attribute at index and return a temporary object holding its data.

Usage

From source file:me.sweetll.tucao.widget.CustomBottomSheetBehavior.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*from w  w w.j a  va 2 s. c  o  m*/
 * @param attrs   The {@link AttributeSet}.
 */
public CustomBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:net.osmand.plus.widgets.tools.ExtendedBottomSheetBehavior.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//from  w  w  w. ja  va  2s.  com
 * @param attrs   The {@link AttributeSet}.
 */
public ExtendedBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java

/**
 * Default constructor for inflating ViewPagerBottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*from   w w  w.j av  a  2 s .co m*/
 * @param attrs   The {@link AttributeSet}.
 */
public ViewPagerBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    scrollableViews = new ArrayList<>();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.matcontrol.control.BottomSheetBehavior_v27.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.// ww w . j  a  v a  2 s.  c  o m
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetBehavior_v27(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a
            .peekValue(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(
                android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable,
            false));
    setSkipCollapsed(a.getBoolean(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.matcontrol.control.BottomSheetBehavior_v25.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//  w w w  . j  ava  2s  .  c  o m
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetBehavior_v25(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a
            .peekValue(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(
                android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable,
            false));
    setSkipCollapsed(a.getBoolean(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.runzii.lib.widgets.behavior.BottomSheetAnchorBehavior.java

/**
 * Default constructor for inflating BottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}./*w  ww.  j  av  a2s  . co m*/
 * @param attrs   The {@link AttributeSet}.
 */
public BottomSheetAnchorBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a.peekValue(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(R.styleable.BottomSheetBehavior_Layout_behavior_hideable, false));
    setSkipCollapsed(a.getBoolean(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();

    /**
     * Getting the anchorPoint...
     */
    mAnchorPoint = DEFAULT_ANCHOR_POINT;
    a = context.obtainStyledAttributes(attrs, R.styleable.BottomSheetAnchorBehavior);
    if (attrs != null)
        mAnchorPoint = (int) a.getDimension(R.styleable.BottomSheetAnchorBehavior_anchor_point, 0);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
}

From source file:com.trafi.anchorbottomsheetbehavior.AnchorBottomSheetBehavior.java

/**
 * Default constructor for inflating AnchorBottomSheetBehaviors from layout.
 *
 * @param context The {@link Context}.//from  w w  w .  jav  a  2 s.  c om
 * @param attrs   The {@link AttributeSet}.
 */
public AnchorBottomSheetBehavior(Context context, AttributeSet attrs) {
    super(context, attrs);
    TypedArray a = context.obtainStyledAttributes(attrs,
            android.support.design.R.styleable.BottomSheetBehavior_Layout);
    TypedValue value = a
            .peekValue(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight);
    if (value != null && value.data == PEEK_HEIGHT_AUTO) {
        setPeekHeight(value.data);
    } else {
        setPeekHeight(a.getDimensionPixelSize(
                android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_peekHeight,
                PEEK_HEIGHT_AUTO));
    }
    setHideable(a.getBoolean(android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_hideable,
            false));
    setSkipCollapsed(a.getBoolean(
            android.support.design.R.styleable.BottomSheetBehavior_Layout_behavior_skipCollapsed, false));
    a.recycle();

    a = context.obtainStyledAttributes(attrs, R.styleable.AnchorBottomSheetBehavior_Layout);
    mAnchorOffset = (int) a.getDimension(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_anchorOffset, 0);
    //noinspection WrongConstant
    mState = a.getInt(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_defaultState, mState);

    mShouldAnchoredBeforeExpand = a.getBoolean(
            R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeExpand, false);
    mShouldAnchoredBeforeCollapse = a.getBoolean(
            R.styleable.AnchorBottomSheetBehavior_Layout_behavior_shouldAnchoredBeforeCollapse, false);
    mExpandable = a.getBoolean(R.styleable.AnchorBottomSheetBehavior_Layout_behavior_expandable, true);
    a.recycle();

    ViewConfiguration configuration = ViewConfiguration.get(context);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
}

From source file:com.androzic.Preferences.java

/**
 * Parse the given XML file as a header description, adding each
 * parsed Header into the target list.//  w  ww .j  ava  2  s.c  o  m
 *
 * @param resid
 *            The XML resource to load and parse.
 * @param target
 *            The list in which the parsed headers should be placed.
 */
public void loadHeadersFromResource(int resid, List<Header> target) {
    Androzic application = Androzic.getApplication();
    XmlResourceParser parser = null;
    try {
        Resources resources = getResources();
        parser = resources.getXml(resid);
        AttributeSet attrs = Xml.asAttributeSet(parser);

        int type;
        //noinspection StatementWithEmptyBody
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
            // Parse next until start tag is found
        }

        String nodeName = parser.getName();
        if (!"preference-headers".equals(nodeName)) {
            throw new RuntimeException("XML document must start with <preference-headers> tag; found" + nodeName
                    + " at " + parser.getPositionDescription());
        }

        Bundle curBundle = null;

        final int outerDepth = parser.getDepth();
        while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
            if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                continue;
            }

            nodeName = parser.getName();
            if ("header".equals(nodeName)) {
                Header header = new Header();

                TypedArray sa = resources.obtainAttributes(attrs, R.styleable.PreferenceHeader);
                header.id = sa.getResourceId(R.styleable.PreferenceHeader_id, (int) HEADER_ID_UNDEFINED);
                TypedValue tv = sa.peekValue(R.styleable.PreferenceHeader_title);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.titleRes = tv.resourceId;
                    } else {
                        header.title = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_summary);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.summaryRes = tv.resourceId;
                    } else {
                        header.summary = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbTitle);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.breadCrumbTitleRes = tv.resourceId;
                    } else {
                        header.breadCrumbTitle = tv.string;
                    }
                }
                tv = sa.peekValue(R.styleable.PreferenceHeader_breadCrumbShortTitle);
                if (tv != null && tv.type == TypedValue.TYPE_STRING) {
                    if (tv.resourceId != 0) {
                        header.breadCrumbShortTitleRes = tv.resourceId;
                    } else {
                        header.breadCrumbShortTitle = tv.string;
                    }
                }
                header.iconRes = sa.getResourceId(R.styleable.PreferenceHeader_icon, 0);
                header.fragment = sa.getString(R.styleable.PreferenceHeader_fragment);
                header.help = sa.getResourceId(R.styleable.PreferenceHeader_help, 0);
                sa.recycle();

                if (curBundle == null) {
                    curBundle = new Bundle();
                }

                final int innerDepth = parser.getDepth();
                while ((type = parser.next()) != XmlPullParser.END_DOCUMENT
                        && (type != XmlPullParser.END_TAG || parser.getDepth() > innerDepth)) {
                    if (type == XmlPullParser.END_TAG || type == XmlPullParser.TEXT) {
                        continue;
                    }

                    String innerNodeName = parser.getName();
                    if (innerNodeName.equals("extra")) {
                        resources.parseBundleExtra(innerNodeName, attrs, curBundle);
                        XmlUtils.skipCurrentTag(parser);

                    } else if (innerNodeName.equals("intent")) {
                        header.intent = Intent.parseIntent(resources, parser, attrs);

                    } else {
                        XmlUtils.skipCurrentTag(parser);
                    }
                }

                if (curBundle.size() > 0) {
                    header.fragmentArguments = curBundle;
                    curBundle = null;
                }

                if (header.id == R.id.pref_plugins && application.getPluginsPreferences().size() == 0)
                    continue;

                target.add(header);
            } else {
                XmlUtils.skipCurrentTag(parser);
            }
        }

    } catch (XmlPullParserException | IOException e) {
        throw new RuntimeException("Error parsing headers", e);
    } finally {
        if (parser != null)
            parser.close();
    }

}

From source file:org.florescu.android.rangeseekbar.RangeSeekBar.java

@SuppressWarnings("unchecked")
private T extractNumericValueFromAttributes(TypedArray a, int attribute, int defaultValue) {
    TypedValue tv = a.peekValue(attribute);
    if (tv == null) {
        return (T) Integer.valueOf(defaultValue);
    }/*  www  . ja  v  a  2s  . co m*/

    int type = tv.type;
    if (type == TypedValue.TYPE_FLOAT) {
        return (T) Float.valueOf(a.getFloat(attribute, defaultValue));
    } else {
        return (T) Integer.valueOf(a.getInteger(attribute, defaultValue));
    }
}

From source file:com.android.incallui.widget.multiwaveview.GlowPadView.java

private int getResourceId(TypedArray a, int id) {
    TypedValue tv = a.peekValue(id);
    return tv == null ? 0 : tv.resourceId;
}