Example usage for android.content.res TypedArray getDimension

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

Introduction

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

Prototype

public float getDimension(@StyleableRes int index, float defValue) 

Source Link

Document

Retrieve a dimensional unit attribute at index.

Usage

From source file:com.github.shareme.gwsdiscreteseekbar.library.Marker.java

@SuppressWarnings("deprecation")
public Marker(Context context, AttributeSet attrs, int defStyleAttr, String maxValue) {
    super(context, attrs, defStyleAttr);
    DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DiscreteSeekBar,
            R.attr.discreteSeekBarStyle, R.style.Widget_DiscreteSeekBar);

    int padding = (int) (PADDING_DP * displayMetrics.density) * 2;
    int textAppearanceId = a.getResourceId(R.styleable.DiscreteSeekBar_dsb_indicatorTextAppearance,
            R.style.Widget_DiscreteIndicatorTextAppearance);
    mNumber = new TextView(context);
    //Add some padding to this textView so the bubble has some space to breath
    mNumber.setPadding(padding, 0, padding, 0);
    //TODO: setTextAppearance is depreciated
    mNumber.setTextAppearance(context, textAppearanceId);
    mNumber.setGravity(Gravity.CENTER);//from  w w w .j a  v  a  2  s.  c  o  m
    mNumber.setText(maxValue);
    mNumber.setMaxLines(1);
    mNumber.setSingleLine(true);
    //changed from TEXT_DIRECTION_LOCALE TO ViewCompat.LAYOUT_DIRECTION_LOCALE
    SeekBarCompat.setTextDirection(mNumber, ViewCompat.LAYOUT_DIRECTION_LOCALE);
    mNumber.setVisibility(View.INVISIBLE);

    //add some padding for the elevation shadow not to be clipped
    //I'm sure there are better ways of doing this...
    setPadding(padding, padding, padding, padding);

    resetSizes(maxValue);

    mSeparation = (int) (SEPARATION_DP * displayMetrics.density);
    int thumbSize = (int) (ThumbDrawable.DEFAULT_SIZE_DP * displayMetrics.density);
    ColorStateList color = a.getColorStateList(R.styleable.DiscreteSeekBar_dsb_indicatorColor);
    if (color != null) {
        mMarkerDrawable = new MarkerDrawable(color, thumbSize);
    }
    mMarkerDrawable.setCallback(this);
    mMarkerDrawable.setMarkerListener(this);
    mMarkerDrawable.setExternalOffset(padding);

    //Elevation for anroid 5+
    float elevation = a.getDimension(R.styleable.DiscreteSeekBar_dsb_indicatorElevation,
            ELEVATION_DP * displayMetrics.density);
    ViewCompat.setElevation(this, elevation);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        SeekBarCompat.setOutlineProvider(this, mMarkerDrawable);
    }
    a.recycle();
}

From source file:com.arksh.summer.ui.zone.widget.ExpandableTextView.java

/**
 * ?//from w  w w .  j a  v  a  2s  .  co m
 * @param attrs
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse);
    textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
    showExpandCollapseDrawable = typedArray
            .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true);

    if (showExpandCollapseDrawable) {
        if (mExpandDrawable == null) {
            mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
        }
        if (mCollapseDrawable == null) {
            mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
        }
    }

    if (TextUtils.isEmpty(textCollapse)) {
        textCollapse = getContext().getString(R.string.shink);
    }
    if (TextUtils.isEmpty(textExpand)) {
        textExpand = getContext().getString(R.string.expand);
    }
    contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor,
            ContextCompat.getColor(getContext(), R.color.light_gray));
    contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize,
            DisplayUtil.sp2px(14));

    collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor,
            ContextCompat.getColor(getContext(), R.color.main_color));
    collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize,
            DisplayUtil.sp2px(14));

    grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);

    typedArray.recycle();
    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);
    // default visibility is gone
    setVisibility(GONE);
}

From source file:recycle.com.example.nandy.dynamicdemo.widget.dynamic.ExpandableTextView.java

/**
 * ?// w  w  w . j a va2 s.com
 * @param attrs
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse);
    textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
    showExpandCollapseDrawable = typedArray
            .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true);

    if (showExpandCollapseDrawable) {
        if (mExpandDrawable == null) {
            mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
        }
        if (mCollapseDrawable == null) {
            mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
        }
    }

    if (TextUtils.isEmpty(textCollapse)) {
        textCollapse = getContext().getString(R.string.shink);
    }
    if (TextUtils.isEmpty(textExpand)) {
        textExpand = getContext().getString(R.string.expand);
    }
    contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor,
            ContextCompat.getColor(getContext(), R.color.white));
    contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize,
            DensityUtil.sp2px(14));

    collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor,
            ContextCompat.getColor(getContext(), R.color.black));
    collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize,
            DensityUtil.sp2px(14));

    grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);

    typedArray.recycle();
    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);
    // default visibility is gone
    setVisibility(GONE);
}

From source file:com.zzb.mynew.view.ExpandableTextView.java

/**
 * ?/*from  w  ww  . j  a  v  a2  s.c om*/
 * @param attrs
 */
private void init(AttributeSet attrs) {
    mCollapsedStatus = new SparseBooleanArray();

    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.ExpandableTextView);
    mMaxCollapsedLines = typedArray.getInt(R.styleable.ExpandableTextView_maxCollapsedLines,
            MAX_COLLAPSED_LINES);
    mAnimationDuration = typedArray.getInt(R.styleable.ExpandableTextView_animDuration, DEFAULT_ANIM_DURATION);
    mExpandDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_expandDrawable);
    mCollapseDrawable = typedArray.getDrawable(R.styleable.ExpandableTextView_collapseDrawable);

    textCollapse = typedArray.getString(R.styleable.ExpandableTextView_textCollapse);
    textExpand = typedArray.getString(R.styleable.ExpandableTextView_textExpand);
    showExpandCollapseDrawable = typedArray
            .getBoolean(R.styleable.ExpandableTextView_showExpandCollapseDrawable, true);

    if (showExpandCollapseDrawable) {
        if (mExpandDrawable == null) {
            mExpandDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_down);
        }
        if (mCollapseDrawable == null) {
            mCollapseDrawable = ContextCompat.getDrawable(getContext(), R.drawable.icon_green_arrow_up);
        }
    }

    if (TextUtils.isEmpty(textCollapse)) {
        textCollapse = getContext().getString(R.string.shink);
    }
    if (TextUtils.isEmpty(textExpand)) {
        textExpand = getContext().getString(R.string.expand);
    }
    contentTextColor = typedArray.getColor(R.styleable.ExpandableTextView_contentTextColor,
            ContextCompat.getColor(getContext(), R.color.light_gray));
    contentTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_contentTextSize,
            DisplayUtil.sp2px(14));
    collapseExpandTextColor = typedArray.getColor(R.styleable.ExpandableTextView_collapseExpandTextColor,
            ContextCompat.getColor(getContext(), R.color.main_color));
    collapseExpandTextSize = typedArray.getDimension(R.styleable.ExpandableTextView_collapseExpandTextSize,
            DisplayUtil.sp2px(14));

    grarity = typedArray.getInt(R.styleable.ExpandableTextView_collapseExpandGrarity, Gravity.LEFT);

    typedArray.recycle();
    // enforces vertical orientation
    setOrientation(LinearLayout.VERTICAL);
    // default visibility is gone
    setVisibility(GONE);
}

From source file:com.bitflake.counter.HorizontalPicker.java

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

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);//from   ww  w.ja va 2s . co m
    textPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = this.sideItems;

    try {
        textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (textColor == null) {
            textColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                marqueeRepeatLimit);
        dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt();
    boringMetrics = new BoringLayout.Metrics();
    boringMetrics.ascent = fontMetricsInt.ascent;
    boringMetrics.bottom = fontMetricsInt.bottom;
    boringMetrics.descent = fontMetricsInt.descent;
    boringMetrics.leading = fontMetricsInt.leading;
    boringMetrics.top = fontMetricsInt.top;
    boringMetrics.width = itemWidth;

    setWillNotDraw(false);

    flingScrollerX = new OverScroller(context);
    adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    touchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    overscrollDistance = configuration.getScaledOverscrollDistance();

    previousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    touchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, touchHelper);

}

From source file:kr.selfcontrol.selflocklauncher.picker.HorizontalPicker.java

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

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);//from ww w.j a v  a2s  .  c  o  m
    mTextPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = mSideItems;

    try {
        mTextColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (mTextColor == null) {
            mTextColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        mMarqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                mMarqueeRepeatLimit);
        mDividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, mDividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = mTextPaint.getFontMetricsInt();
    mBoringMetrics = new BoringLayout.Metrics();
    mBoringMetrics.ascent = fontMetricsInt.ascent;
    mBoringMetrics.bottom = fontMetricsInt.bottom;
    mBoringMetrics.descent = fontMetricsInt.descent;
    mBoringMetrics.leading = fontMetricsInt.leading;
    mBoringMetrics.top = fontMetricsInt.top;
    mBoringMetrics.width = mItemWidth;

    setWillNotDraw(false);

    mFlingScrollerX = new OverScroller(context);
    mAdjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    mOverscrollDistance = configuration.getScaledOverscrollDistance();

    mPreviousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    mTouchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

}

From source file:net.hadifar.dope.ui.widget.pagerIndicator.NumericPageIndicator.java

@SuppressWarnings("deprecation")
public NumericPageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*from w ww. java2s.com*/
    }

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultTextColor = res.getColor(R.color.default_page_number_indicator_text_color);
    final int defaultPageNumberTextColor = res
            .getColor(R.color.default_page_number_indicator_page_number_text_color);
    final boolean defaultPageNumberTextBold = res
            .getBoolean(R.bool.default_page_number_indicator_page_number_text_bold);
    final int defaultButtonPressedColor = res
            .getColor(R.color.default_page_number_indicator_pressed_button_color);
    final float defaultTopPadding = res.getDimension(R.dimen.default_page_number_indicator_top_padding);
    final float defaultBottomPadding = res.getDimension(R.dimen.default_page_number_indicator_bottom_padding);
    final float defaultTextSize = res.getDimension(R.dimen.default_page_number_indicator_text_size);
    final boolean defaultShowChangePageButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_change_page_buttons);
    final boolean defaultShowStartEndButtons = res
            .getBoolean(R.bool.default_page_number_indicator_show_start_end_buttons);

    // Retrieve styles attributes
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NumericPageIndicator, defStyle, 0);

    mTextTemplate = a.getString(R.styleable.NumericPageIndicator_textTemplate);
    if (mTextTemplate == null) {
        mTextTemplate = res.getString(R.string.default_page_number_indicator_text_template);
    }
    parseTextTemplate();

    mTextPreviousButton = a.getString(R.styleable.NumericPageIndicator_previousButtonText);
    if (mTextPreviousButton == null) {
        mTextPreviousButton = res.getString(R.string.default_page_number_indicator_previous_button_text);
    }
    mTextNextButton = a.getString(R.styleable.NumericPageIndicator_nextButtonText);
    if (mTextNextButton == null) {
        mTextNextButton = res.getString(R.string.default_page_number_indicator_next_button_text);
    }

    mColorText = a.getColor(R.styleable.NumericPageIndicator_android_textColor, defaultTextColor);
    mColorPageNumberText = a.getColor(R.styleable.NumericPageIndicator_pageNumberTextColor,
            defaultPageNumberTextColor);
    mPageNumberTextBold = a.getBoolean(R.styleable.NumericPageIndicator_pageNumberTextBold,
            defaultPageNumberTextBold);
    mColorPressedButton = a.getColor(R.styleable.NumericPageIndicator_pressedButtonColor,
            defaultButtonPressedColor);
    mPaddingTop = a.getDimension(R.styleable.NumericPageIndicator_android_paddingTop, defaultTopPadding);
    mPaddingBottom = a.getDimension(R.styleable.NumericPageIndicator_android_paddingBottom,
            defaultBottomPadding);
    mPaintText.setColor(mColorText);
    mShowChangePageButtons = a.getBoolean(R.styleable.NumericPageIndicator_showChangePageButtons,
            defaultShowChangePageButtons);
    mShowStartEndButtons = a.getBoolean(R.styleable.NumericPageIndicator_showStartEndButtons,
            defaultShowStartEndButtons);

    mPaintButtonBackground.setColor(mColorPressedButton);
    final float textSize = a.getDimension(R.styleable.NumericPageIndicator_android_textSize, defaultTextSize);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);

    mPaintPageNumberText.setColor(mColorPageNumberText);
    mPaintPageNumberText.setTextSize(textSize);
    mPaintPageNumberText.setAntiAlias(true);
    if (mPageNumberTextBold) {
        mPaintPageNumberText.setTypeface(Typeface.DEFAULT_BOLD);
    }

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

    a.recycle();
}

From source file:com.acbelter.directionalcarousel.CarouselViewPager.java

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

    mConfig = CarouselConfig.getInstance();
    mConfig.pagerId = getId();//from w w  w  .  ja  v  a  2  s  .co  m
    mResources = context.getResources();
    mPackageName = context.getPackageName();
    mPageContentWidthId = mResources.getIdentifier("page_content_width", "dimen", mPackageName);
    mPageContentHeightId = mResources.getIdentifier("page_content_height", "dimen", mPackageName);

    DisplayMetrics dm = mResources.getDisplayMetrics();
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CarouselViewPager, defStyle, 0);
    try {
        if (a != null) {
            mConfig.orientation = a.getInt(R.styleable.CarouselViewPager_android_orientation,
                    CarouselConfig.HORIZONTAL);
            mConfig.infinite = a.getBoolean(R.styleable.CarouselViewPager_infinite, true);
            mConfig.scrollScalingMode = a.getInt(R.styleable.CarouselViewPager_scrollScalingMode,
                    CarouselConfig.SCROLL_MODE_BIG_CURRENT);

            float bigScale = a.getFloat(R.styleable.CarouselViewPager_bigScale,
                    CarouselConfig.DEFAULT_BIG_SCALE);
            if (bigScale > 1.0f || bigScale < 0.0f) {
                bigScale = CarouselConfig.DEFAULT_BIG_SCALE;
                Log.w(TAG, "Invalid bigScale attribute. Default value " + CarouselConfig.DEFAULT_BIG_SCALE
                        + " will be used.");
            }
            mConfig.bigScale = bigScale;

            float smallScale = a.getFloat(R.styleable.CarouselViewPager_smallScale,
                    CarouselConfig.DEFAULT_SMALL_SCALE);
            if (smallScale > 1.0f || smallScale < 0.0f) {
                smallScale = CarouselConfig.DEFAULT_SMALL_SCALE;
                Log.w(TAG, "Invalid smallScale attribute. Default value " + CarouselConfig.DEFAULT_SMALL_SCALE
                        + " will be used.");
            } else if (smallScale > bigScale) {
                smallScale = bigScale;
                Log.w(TAG, "Invalid smallScale attribute. Value " + bigScale + " will be used.");
            }
            mConfig.smallScale = smallScale;

            mMinPagesOffset = (int) a.getDimension(R.styleable.CarouselViewPager_minPagesOffset,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, dm));
            mSidePagesVisiblePart = a.getFloat(R.styleable.CarouselViewPager_sidePagesVisiblePart,
                    DEFAULT_SIDE_PAGES_VISIBLE_PART);
            mWrapPadding = (int) a.getDimension(R.styleable.CarouselViewPager_wrapPadding,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    mGestureListener = new SimpleOnGestureListener() {
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendSingleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            if (getCarouselAdapter() != null) {
                getCarouselAdapter().sendDoubleTap(mTouchedView, mTouchedItem);
            }
            mTouchedView = null;
            mTouchedItem = null;
            return true;
        }
    };

    mGestureDetector = new GestureDetector(context, mGestureListener);
}

From source file:com.aosijia.dragonbutler.ui.widget.ActionSheet.java

private Attributes readAttribute() {
    Attributes attrs = new Attributes(getActivity());
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.ActionSheet,
            R.attr.actionSheetStyle, 0);
    Drawable background = a.getDrawable(R.styleable.ActionSheet_actionSheetBackground);
    if (background != null) {
        attrs.background = background;/*w  ww.  j  a va  2 s .  co  m*/
    }
    Drawable cancelButtonBackground = a.getDrawable(R.styleable.ActionSheet_cancelButtonBackground);
    if (cancelButtonBackground != null) {
        attrs.cancelButtonBackground = cancelButtonBackground;
    }
    Drawable otherButtonTopBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonTopBackground);
    if (otherButtonTopBackground != null) {
        attrs.otherButtonTopBackground = otherButtonTopBackground;
    }
    Drawable otherButtonMiddleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonMiddleBackground);
    if (otherButtonMiddleBackground != null) {
        attrs.otherButtonMiddleBackground = otherButtonMiddleBackground;
    }
    Drawable otherButtonBottomBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonBottomBackground);
    if (otherButtonBottomBackground != null) {
        attrs.otherButtonBottomBackground = otherButtonBottomBackground;
    }
    Drawable otherButtonSingleBackground = a.getDrawable(R.styleable.ActionSheet_otherButtonSingleBackground);
    if (otherButtonSingleBackground != null) {
        attrs.otherButtonSingleBackground = otherButtonSingleBackground;
    }
    attrs.cancelButtonTextColor = a.getColor(R.styleable.ActionSheet_cancelButtonTextColor,
            attrs.cancelButtonTextColor);
    attrs.otherButtonTextColor = a.getColor(R.styleable.ActionSheet_otherButtonTextColor,
            attrs.otherButtonTextColor);
    attrs.padding = (int) a.getDimension(R.styleable.ActionSheet_actionSheetPadding, attrs.padding);
    attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.ActionSheet_otherButtonSpacing,
            attrs.otherButtonSpacing);
    attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.ActionSheet_cancelButtonMarginTop,
            attrs.cancelButtonMarginTop);
    attrs.actionSheetTextSize = a.getDimensionPixelSize(R.styleable.ActionSheet_actionSheetTextSize,
            (int) attrs.actionSheetTextSize);

    a.recycle();
    return attrs;
}

From source file:com.shenzhen.elson.selectordialoglib.SelectorDialog.java

private Attributes readAttribute() {
    Attributes attrs = new Attributes(getActivity());
    TypedArray a = getActivity().getTheme().obtainStyledAttributes(null, R.styleable.SelectorDialog,
            R.attr.selectorDialogStyle, 0);
    Drawable background = a.getDrawable(R.styleable.SelectorDialog_selectorDialogBackground);
    if (background != null) {
        attrs.background = background;/*from   ww w. j ava2  s.co m*/
    }
    Drawable cancelButtonBackground = a.getDrawable(R.styleable.SelectorDialog_cancelButtonBackground);
    if (cancelButtonBackground != null) {
        attrs.cancelButtonBackground = cancelButtonBackground;
    }
    Drawable otherButtonTopBackground = a.getDrawable(R.styleable.SelectorDialog_otherButtonTopBackground);
    if (otherButtonTopBackground != null) {
        attrs.otherButtonTopBackground = otherButtonTopBackground;
    }
    Drawable otherButtonMiddleBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonMiddleBackground);
    if (otherButtonMiddleBackground != null) {
        attrs.otherButtonMiddleBackground = otherButtonMiddleBackground;
    }
    Drawable otherButtonBottomBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonBottomBackground);
    if (otherButtonBottomBackground != null) {
        attrs.otherButtonBottomBackground = otherButtonBottomBackground;
    }
    Drawable otherButtonSingleBackground = a
            .getDrawable(R.styleable.SelectorDialog_otherButtonSingleBackground);
    if (otherButtonSingleBackground != null) {
        attrs.otherButtonSingleBackground = otherButtonSingleBackground;
    }
    attrs.cancelButtonTextColor = a.getColor(R.styleable.SelectorDialog_cancelButtonTextColor,
            attrs.cancelButtonTextColor);
    attrs.otherButtonTextColor = a.getColor(R.styleable.SelectorDialog_otherButtonTextColor,
            attrs.otherButtonTextColor);
    attrs.padding = (int) a.getDimension(R.styleable.SelectorDialog_selectorDialogPadding, attrs.padding);
    attrs.otherButtonSpacing = (int) a.getDimension(R.styleable.SelectorDialog_otherButtonSpacing,
            attrs.otherButtonSpacing);
    attrs.cancelButtonMarginTop = (int) a.getDimension(R.styleable.SelectorDialog_cancelButtonMarginTop,
            attrs.cancelButtonMarginTop);
    attrs.SelectorDialogTextSize = a.getDimensionPixelSize(R.styleable.SelectorDialog_selectorDialogTextSize,
            (int) attrs.SelectorDialogTextSize);

    a.recycle();
    return attrs;
}