Example usage for android.content.res TypedArray getInt

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

Introduction

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

Prototype

public int getInt(@StyleableRes int index, int defValue) 

Source Link

Document

Retrieve the integer value for the attribute at index.

Usage

From source file:com.ehpefi.iforgotthat.swipelistview.SwipeListView.java

/**
 * Init ListView//  w  w  w  .  ja v  a  2 s .  c om
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs,
                com.ehpefi.iforgotthat.R.styleable.SwipeListView);
        swipeMode = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeActionLeft,
                SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeActionRight,
                SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOffsetLeft,
                0);
        swipeOffsetRight = styled
                .getDimension(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled
                .getBoolean(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled
                .getInteger(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled.getBoolean(
                com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled
                .getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled
                .getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeFrontView,
                0);
        swipeBackView = styled.getResourceId(com.ehpefi.iforgotthat.R.styleable.SwipeListView_swipeBackView, 0);
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.lgq.rssreader.controls.SwipeListView.java

/**
 * Init ListView/*from  w w w  . j ava  2  s.  com*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeAutoClose = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAutoClose = styled.getBoolean(R.styleable.SwipeListView_swipeAutoClose, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeAutoClose(swipeAutoClose);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.fortysevendeg.swipelistview.SwipeRecyclerView.java

/**
 * Init ListView/* www . j ava  2  s  . c o m*/
 *
 * @param attrs AttributeSet
 */
private void init(AttributeSet attrs) {

    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    boolean onlyOneOpenedWhenSwipe = false;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;

    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;

    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeRecyclerView);
        swipeMode = styled.getInt(R.styleable.SwipeRecyclerView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeRecyclerView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeRecyclerView_swipeActionRight, SWIPE_ACTION_REVEAL);
        onlyOneOpenedWhenSwipe = styled.getBoolean(R.styleable.SwipeRecyclerView_onlyOneOpenedWhenSwipe, false);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeRecyclerView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeRecyclerView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeRecyclerView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeRecyclerView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled
                .getBoolean(R.styleable.SwipeRecyclerView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeRecyclerView_swipeBackView, 0);
        styled.recycle();
    }

    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id",
                getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id",
                getContext().getPackageName());

        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format(
                    "You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers",
                    SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeRecyclerTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setOnlyOneOpenedWhenSwipe(onlyOneOpenedWhenSwipe);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}

From source file:com.bvhloc.numpicker.widget.NumberPicker.java

public NumberPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    mStart = DEFAULT_START;//from   w w  w  .  j  a  v  a 2  s  . c om
    mEnd = DEFAULT_END;
    mCurrent = mStart;

    boolean vertical = true;
    int displayedValues = 0;

    if (attrs != null && !isInEditMode()) {
        // this crashes in edit mode (?!)
        TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.NumberPicker);

        mStart = a.getInt(R.styleable.NumberPicker_rangeStart, DEFAULT_START);
        mEnd = a.getInt(R.styleable.NumberPicker_rangeEnd, DEFAULT_END);
        mSpeed = a.getInt(R.styleable.NumberPicker_speed, (int) mSpeed);
        mSpeedUp = mSpeed;
        mCurrent = a.getInt(R.styleable.NumberPicker_current, mCurrent);

        mNumColor = a.getColor(R.styleable.NumberPicker_numColor,
                ContextCompat.getColor(context, android.R.color.primary_text_light));
        mNumBackground = a.getDrawable(R.styleable.NumberPicker_numBackground);
        mNumSize = a.getDimension(R.styleable.NumberPicker_numSize, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numHorizontalPadding, mNumSize);
        mNumHorizontalPadding = (int) a.getDimension(R.styleable.NumberPicker_numVeticalPadding, mNumSize);
        mIncrementDrawable = a.getDrawable(R.styleable.NumberPicker_incrementDrawable);
        mDecrementDrawable = a.getDrawable(R.styleable.NumberPicker_decrementDrawable);
        mKeyboardInput = a.getBoolean(R.styleable.NumberPicker_keyboardInput, mKeyboardInput);

        String orientation = a.getString(R.styleable.NumberPicker_android_orientation);
        displayedValues = a.getResourceId(R.styleable.NumberPicker_displayedValues, 0);

        if (orientation != null) {
            vertical = !"0".equals(orientation);
        }

        a.recycle();
    } else if (attrs != null && isInEditMode()) {
        // fix orientation attribute for editor
        String orientation = attrs.getAttributeValue("http://schemas.android.com/apk/res/android",
                "orientation");

        if (orientation != null) {
            vertical = !"horizontal".equals(orientation);
        }
    }
    // set a wrong orientation so our own orientation method will perform changes
    super.setOrientation(!vertical ? VERTICAL : HORIZONTAL);
    setOrientation(vertical ? VERTICAL : HORIZONTAL);

    mChangeHandler = new Handler();
    InputFilter inputFilter = new NumberPickerInputFilter();
    mNumberInputFilter = new NumberRangeKeyListener();
    mIncrementButton = (NumberPickerButton) findViewById(R.id.increment);
    mIncrementButton.setOnClickListener(this);
    mIncrementButton.setOnLongClickListener(this);
    mIncrementButton.setNumberPicker(this);
    mDecrementButton = (NumberPickerButton) findViewById(R.id.decrement);
    mDecrementButton.setOnClickListener(this);
    mDecrementButton.setOnLongClickListener(this);
    mDecrementButton.setNumberPicker(this);

    mIncrementButton.setBackground(null);
    mDecrementButton.setBackground(null);
    mIncrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);
    mDecrementButton.setScaleType(ImageView.ScaleType.FIT_CENTER);

    if (mIncrementDrawable != null) {
        mIncrementButton.setImageDrawable(mIncrementDrawable);
    }
    if (mDecrementDrawable != null) {
        mDecrementButton.setImageDrawable(mDecrementDrawable);
    }

    mText = (EditText) findViewById(R.id.timepicker_input);
    mText.setOnFocusChangeListener(this);
    mText.setFilters(new InputFilter[] { inputFilter });
    mText.setRawInputType(InputType.TYPE_CLASS_NUMBER);
    LayoutParams params = (LayoutParams) mText.getLayoutParams();
    params.weight = 1;
    mText.setLayoutParams(params);

    mText.setPadding(mNumHorizontalPadding, mNumVerticalPadding, mNumHorizontalPadding, mNumVerticalPadding);
    mText.setTextSize(mNumSize);
    if (mNumBackground != null) {
        mText.setBackground(mNumBackground);
    } else {
        mText.setBackground(ContextCompat.getDrawable(context, android.R.drawable.edit_text));
    }
    if (!mKeyboardInput) {
        mText.setEnabled(false);
    }
    mText.setTextColor(mNumColor);

    if (!isEnabled()) {
        setEnabled(false);
    }

    if (displayedValues != 0) {
        setDisplayedRange(mStart, displayedValues);
    } else {
        setRange(mStart, mEnd);
    }
}

From source file:com.bolaa.medical.view.banner.LoopCirclePageIndicator.java

public LoopCirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);

    mPaintPageFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintPageFill.setStyle(Style.FILL);
    //        mPaintPageFill.setStrokeWidth(3);//?
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));

    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.FILL);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke/*w  w w. j a  v  a 2  s . c  o m*/
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));

    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);//
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));

    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);

    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.bolaa.sleepingbar.view.banner.LoopCirclePageIndicator.java

public LoopCirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle,
            R.style.Widget_CirclePageIndicator);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_orientation, defaultOrientation);

    mPaintPageFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setStrokeWidth(3);//?
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));

    mPaintStroke = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintStroke.setStyle(Style.FILL);
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke/*from   ww w.j a  va  2  s  . c  o  m*/
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));

    mPaintFill = new Paint(Paint.ANTI_ALIAS_FLAG);
    mPaintFill.setStyle(Style.FILL);//
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));

    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);

    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.android.fastlibrary.ui.activity.swipeback.SwipeBackLayout.java

public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle,
            R.style.SwipeBackLayout);//w  w w.j a  v a2s. c om

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0) {
        setEdgeSize(edgeSize);
    }
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left);
    int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right);
    int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom);
    setShadow(shadowLeft, EDGE_LEFT);
    setShadow(shadowRight, EDGE_RIGHT);
    setShadow(shadowBottom, EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
}

From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java

private void parseMenu(XmlPullParser parser, AttributeSet attrs) throws XmlPullParserException, IOException {

    int eventType = parser.getEventType();
    String tagName;//  www  .j  a  v  a  2s .  c om
    boolean lookingForEndOfUnknownTag = false;
    String unknownTagName = null;

    // This loop will skip to the menu start tag
    do {
        if (eventType == XmlPullParser.START_TAG) {
            tagName = parser.getName();
            if (tagName.equals("menu")) {
                // Go to next tag
                eventType = parser.next();
                break;
            }

            throw new RuntimeException("Expecting menu, got " + tagName);
        }
        eventType = parser.next();
    } while (eventType != XmlPullParser.END_DOCUMENT);

    boolean reachedEndOfMenu = false;

    while (!reachedEndOfMenu) {
        switch (eventType) {
        case XmlPullParser.START_TAG:
            if (lookingForEndOfUnknownTag) {
                break;
            }

            tagName = parser.getName();
            if (tagName.equals("item")) {
                TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.MenuItem);
                int itemShowAsAction = a.getInt(R.styleable.MenuItem_showAsAction, -1);

                if ((itemShowAsAction & MenuItem.SHOW_AS_ACTION_ALWAYS) != 0) {
                    int itemId = a.getResourceId(R.styleable.MenuItem_android_id, NO_ID);
                    if (itemId != NO_ID)
                        alwaysShowingMenu.add(itemId);
                }
                a.recycle();
            } else {
                lookingForEndOfUnknownTag = true;
                unknownTagName = tagName;
            }
            break;

        case XmlPullParser.END_TAG:
            tagName = parser.getName();
            if (lookingForEndOfUnknownTag && tagName.equals(unknownTagName)) {
                lookingForEndOfUnknownTag = false;
                unknownTagName = null;
            } else if (tagName.equals("menu")) {
                reachedEndOfMenu = true;
            }
            break;

        case XmlPullParser.END_DOCUMENT:
            throw new RuntimeException("Unexpected end of document");
        }

        eventType = parser.next();
    }
}

From source file:com.icloud.listenbook.base.view.viewpagerindicator.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  ww.ja  va 2s .c o  m

    // ?
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    // ?
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePageIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePageIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePageIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePageIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
}

From source file:com.bowyoung.enhancelibrary.libs.swipeback.SwipeBackLayout.java

public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SwipeBackLayout, defStyle,
            R.style.SwipeBackLayout);/*from w  ww . j  av  a 2 s .  c  o m*/

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0)
        setEdgeSize(edgeSize);
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft = a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left);
    int shadowRight = a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right);
    int shadowBottom = a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom);
    setShadow(shadowLeft, EDGE_LEFT);
    setShadow(shadowRight, EDGE_RIGHT);
    setShadow(shadowBottom, EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
}