Example usage for android.content Context obtainStyledAttributes

List of usage examples for android.content Context obtainStyledAttributes

Introduction

In this page you can find the example usage for android.content Context obtainStyledAttributes.

Prototype

public final TypedArray obtainStyledAttributes(AttributeSet set, @StyleableRes int[] attrs,
        @AttrRes int defStyleAttr, @StyleRes int defStyleRes) 

Source Link

Document

Retrieve styled attribute information in this Context's theme.

Usage

From source file:android.hqs.view.pager.indicator.LinePageIndicator.java

/**
 * ?/*w w w.j a va  2s  . co m*/
 * @param context
 * @param attrs
 * @param defStyle
 */
@SuppressWarnings("deprecation")
public LinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

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

    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

    Drawable background = a.getDrawable(R.styleable.LinePageIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }

    a.recycle();

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

From source file:android.support.designox.widget.AppBarLayout.java

public AppBarLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);/*w  w w  . java  2 s  .c o m*/

    ThemeUtils.checkAppCompatTheme(context);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout, 0,
            R.style.Widget_Design_AppBarLayout);
    mTargetElevation = a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0);
    setBackgroundDrawable(a.getDrawable(R.styleable.AppBarLayout_android_background));
    if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
        setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false));
    }
    a.recycle();

    // Use the bounds view outline provider so that we cast a shadow, even without a background
    ViewUtils.setBoundsViewOutlineProvider(this);

    mListeners = new ArrayList<>();

    ViewCompat.setElevation(this, mTargetElevation);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4ox.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return onWindowInsetChanged(insets);
                }
            });
}

From source file:com.aero.control.helpers.Android.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from  w  ww . jav a 2  s . co m*/

    //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 = 0;
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = 2;
    final float defaultRadius = dpToPx(5, getResources());
    final boolean defaultCentered = true;
    final boolean defaultSnap = false;

    //Retrieve styles attributes
    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.appunite.scroll.ScaleImageView.java

@SuppressWarnings("UnusedDeclaration")
public ScaleImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    mMinEdge = viewConfiguration.getScaledEdgeSlop();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScaleImageView, defStyle, defStyle);
    assert a != null;

    Drawable src = null;//from ww w  .  j a v  a2s  .  co m
    try {
        mMinWidth = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minWidth, 0);
        mMinHeight = a.getDimensionPixelSize(R.styleable.ScaleImageView_android_minHeight, 0);
        src = a.getDrawable(R.styleable.ScaleImageView_android_src);
    } finally {
        a.recycle();
    }

    ScaleGestureDetector.OnScaleGestureListener scaleGestureListener = new ScaleGestureDetector.SimpleOnScaleGestureListener() {
        /**
         * This is the active focal point in terms of the viewport. Could be a local
         * variable but kept here to minimize per-frame allocations.
         */
        private PointF viewportFocus = new PointF();

        @Override
        public boolean onScaleBegin(ScaleGestureDetector scaleGestureDetector) {
            final ViewParent parent = getParent();
            if (parent != null) {
                parent.requestDisallowInterceptTouchEvent(true);
            }
            return true;
        }

        @Override
        public boolean onScale(ScaleGestureDetector scaleGestureDetector) {
            float focusX = scaleGestureDetector.getFocusX();
            float focusY = scaleGestureDetector.getFocusY();
            float scaleFactor = scaleGestureDetector.getScaleFactor();
            float previousScale = mScale;
            mScale *= scaleFactor;

            doScale(focusX, focusY, scaleFactor);
            return true;
        }

    };
    GestureDetector.SimpleOnGestureListener gestureListener = new GestureDetector.SimpleOnGestureListener() {
        @Override
        public boolean onDown(MotionEvent e) {

            releaseEdgeEffects();
            mScroller.forceFinished(true);
            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            return performClick();
        }

        @Override
        public boolean onDoubleTap(MotionEvent e) {
            mZoomer.forceFinished(true);
            mZoomStartScale = mScale;
            mZoomFocalPoint.set(e.getX(), e.getY());
            mZoomer.startZoom(ZOOM_AMOUNT);
            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        @Override
        public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
            getRealTranslation(mTranslation, mRealTranslation);
            mRealTranslation.offset(-distanceX, -distanceY);
            getTranslation(mRealTranslation, mTranslation);

            computeMaxScrollSize(mMaxScrollBuffer);
            getImageRect(mRectF);
            float scrolledX = -mRectF.left;
            float scrolledY = -mRectF.top;
            boolean canScrollX = mRectF.left > mContentRect.left || mRectF.right < mContentRect.right;
            boolean canScrollY = mRectF.top > mContentRect.top || mRectF.bottom < mContentRect.bottom;
            validateTranslation();

            disallowParentInterceptWhenOnEdge(distanceX, distanceY);

            if (mScale > mMinScale) {
                if (canScrollX && scrolledX < 0) {
                    mEdgeEffectLeft.onPull(scrolledX / (float) mContentRect.width());
                    mEdgeEffectLeftActive = true;
                }
                if (canScrollY && scrolledY < 0) {
                    mEdgeEffectTop.onPull(scrolledY / (float) mContentRect.height());
                    mEdgeEffectTopActive = true;
                }
                if (canScrollX && scrolledX > mMaxScrollBuffer.x) {
                    mEdgeEffectRight.onPull((scrolledX - mMaxScrollBuffer.x) / (float) mContentRect.width());
                    mEdgeEffectRightActive = true;
                }
                if (canScrollY && scrolledY > mMaxScrollBuffer.y) {
                    mEdgeEffectBottom.onPull((scrolledY - mMaxScrollBuffer.y) / (float) mContentRect.height());
                    mEdgeEffectBottomActive = true;
                }
            }

            ViewCompat.postInvalidateOnAnimation(ScaleImageView.this);
            return true;
        }

        private void disallowParentInterceptWhenOnEdge(float directionX, float directionY) {
            final ViewParent parent = getParent();
            if (parent != null && (mAllowParentHorizontalScroll || mAllowParentVerticalScroll)) {
                getImageRect(mRectF);
                if (mAllowParentHorizontalScroll) {
                    if (directionX > 0 && Math.abs(mRectF.right - mContentRect.right) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    if (directionX < 0 && Math.abs(mRectF.left - mContentRect.left) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
                if (mAllowParentVerticalScroll) {
                    if (directionY > 0 && Math.abs(mRectF.bottom - mContentRect.bottom) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                    if (directionY < 0 && Math.abs(mRectF.top - mContentRect.top) > mMinEdge) {
                        parent.requestDisallowInterceptTouchEvent(true);
                    }
                }
            }
        }

        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
            disallowParentInterceptWhenOnEdge(velocityX, velocityY);
            fling((int) -velocityX, (int) -velocityY);
            return true;
        }
    };

    mScaleGestureDetector = new ScaleGestureDetector(context, scaleGestureListener);
    mGestureDetector = new GestureDetectorCompat(context, gestureListener);

    mScroller = new OverScroller(context);
    mZoomer = new Zoomer(context);

    // Sets up edge effects
    mEdgeEffectLeft = new EdgeEffectCompat(context);
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectRight = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);

    setSrcDrawable(src);
}

From source file:co.mrktplaces.android.ui.views.smarttablayout.SmartTabLayout.java

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

    // Disable the Scroll Bar
    setHorizontalScrollBarEnabled(false);

    final DisplayMetrics dm = getResources().getDisplayMetrics();
    final float density = dm.density;

    int tabBackgroundResId = NO_ID;
    int textHorizontalPadding = (int) (TAB_VIEW_PADDING_DIPS * density);
    int textMinWidth = (int) (TAB_VIEW_TEXT_MIN_WIDTH * density);
    boolean distributeEvenly = DEFAULT_DISTRIBUTE_EVENLY;
    int customTabLayoutId = NO_ID;
    int customTabTextViewId = NO_ID;
    boolean clickable = TAB_CLICKABLE;
    int titleOffset = (int) (TITLE_OFFSET_DIPS * density);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.stl_SmartTabLayout, defStyle, 0);
    tabBackgroundResId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_defaultTabBackground,
            tabBackgroundResId);//from www. j  a va  2  s  .  com
    textHorizontalPadding = a.getDimensionPixelSize(
            R.styleable.stl_SmartTabLayout_stl_defaultTabTextHorizontalPadding, textHorizontalPadding);
    textMinWidth = a.getDimensionPixelSize(R.styleable.stl_SmartTabLayout_stl_defaultTabTextMinWidth,
            textMinWidth);
    customTabLayoutId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextLayoutId,
            customTabLayoutId);
    customTabTextViewId = a.getResourceId(R.styleable.stl_SmartTabLayout_stl_customTabTextViewId,
            customTabTextViewId);
    distributeEvenly = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_distributeEvenly, distributeEvenly);
    clickable = a.getBoolean(R.styleable.stl_SmartTabLayout_stl_clickable, clickable);
    titleOffset = a.getLayoutDimension(R.styleable.stl_SmartTabLayout_stl_titleOffset, titleOffset);
    a.recycle();

    this.titleOffset = titleOffset;
    this.tabViewBackgroundResId = tabBackgroundResId;
    this.tabViewTextHorizontalPadding = textHorizontalPadding;
    this.tabViewTextMinWidth = textMinWidth;
    this.internalTabClickListener = clickable ? new InternalTabClickListener() : null;
    this.distributeEvenly = distributeEvenly;

    if (customTabLayoutId != NO_ID) {
        setCustomTabView(customTabLayoutId, customTabTextViewId);
    }

    this.tabStrip = new SmartTabStrip(context, attrs);

    if (distributeEvenly && tabStrip.isIndicatorAlwaysInCenter()) {
        throw new UnsupportedOperationException(
                "'distributeEvenly' and 'indicatorAlwaysInCenter' both use does not support");
    }

    // Make sure that the Tab Strips fills this View
    setFillViewport(!tabStrip.isIndicatorAlwaysInCenter());

    addView(tabStrip, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);

}

From source file:com.aksalj.viewpagerslideshow.LinePageIndicator.java

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

    final Resources res = getResources();

    //Load defaults from resources
    final int defaultLineStyle = res.getInteger(R.integer.default_line_style);
    final int defaultSelectedColor = res.getColor(R.color.default_line_indicator_selected_color);
    final int defaultUnselectedColor = res.getColor(R.color.default_line_indicator_unselected_color);
    final float defaultLineWidth = res.getDimension(R.dimen.default_line_indicator_line_width);
    final float defaultGapWidth = res.getDimension(R.dimen.default_line_indicator_gap_width);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_line_indicator_stroke_width);
    final boolean defaultCentered = res.getBoolean(R.bool.default_line_indicator_centered);

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

    mBoxStyle = a.getInt(R.styleable.LinePageIndicator_lineStyle, defaultLineStyle) == 1;
    mCentered = a.getBoolean(R.styleable.LinePageIndicator_centered, mBoxStyle ? false : defaultCentered);
    mLineWidth = a.getDimension(R.styleable.LinePageIndicator_lineWidth, defaultLineWidth);
    mGapWidth = a.getDimension(R.styleable.LinePageIndicator_gapWidth, mBoxStyle ? 0.0f : defaultGapWidth);
    setStrokeWidth(a.getDimension(R.styleable.LinePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintUnselected
            .setColor(a.getColor(R.styleable.LinePageIndicator_unselectedColor, defaultUnselectedColor));
    mPaintSelected.setColor(a.getColor(R.styleable.LinePageIndicator_selectedColor, defaultSelectedColor));

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

    a.recycle();

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

From source file:com.actionbarsherlock.internal.widget.IcsProgressBar.java

/**
 * @hide/*w  w w. j av a 2s  . c  o  m*/
 */
public IcsProgressBar(Context context, AttributeSet attrs, int defStyle, int styleRes) {
    super(context, attrs, defStyle);
    mUiThreadId = Thread.currentThread().getId();
    initProgressBar();

    TypedArray a = context.obtainStyledAttributes(attrs, /*R.styleable.*/ProgressBar, defStyle, styleRes);

    mNoInvalidate = true;

    Drawable drawable = a.getDrawable(/*R.styleable.*/ProgressBar_progressDrawable);
    if (drawable != null) {
        drawable = tileify(drawable, false);
        // Calling this method can set mMaxHeight, make sure the corresponding
        // XML attribute for mMaxHeight is read after calling this method
        setProgressDrawable(drawable);
    }

    mDuration = a.getInt(/*R.styleable.*/ProgressBar_indeterminateDuration, mDuration);

    mMinWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minWidth, mMinWidth);
    mMaxWidth = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxWidth, mMaxWidth);
    mMinHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_minHeight, mMinHeight);
    mMaxHeight = a.getDimensionPixelSize(/*R.styleable.*/ProgressBar_maxHeight, mMaxHeight);

    mBehavior = a.getInt(/*R.styleable.*/ProgressBar_indeterminateBehavior, mBehavior);

    final int resID = a.getResourceId(/*com.android.internal.R.styleable.*/ProgressBar_interpolator,
            android.R.anim.linear_interpolator); // default to linear interpolator
    if (resID > 0) {
        setInterpolator(context, resID);
    }

    setMax(a.getInt(/*R.styleable.*/ProgressBar_max, mMax));

    setProgress(a.getInt(/*R.styleable.*/ProgressBar_progress, mProgress));

    setSecondaryProgress(a.getInt(/*R.styleable.*/ProgressBar_secondaryProgress, mSecondaryProgress));

    drawable = a.getDrawable(/*R.styleable.*/ProgressBar_indeterminateDrawable);
    if (drawable != null) {
        drawable = tileifyIndeterminate(drawable);
        setIndeterminateDrawable(drawable);
    }

    mOnlyIndeterminate = a.getBoolean(/*R.styleable.*/ProgressBar_indeterminateOnly, mOnlyIndeterminate);

    mNoInvalidate = false;

    setIndeterminate(
            mOnlyIndeterminate || a.getBoolean(/*R.styleable.*/ProgressBar_indeterminate, mIndeterminate));

    mAnimationResolution = a.getInteger(/*R.styleable.*/ProgressBar_animationResolution, ANIMATION_RESOLUTION);

    a.recycle();

    mAccessibilityManager = (AccessibilityManager) context.getSystemService(Context.ACCESSIBILITY_SERVICE);
}

From source file:com.android.hcframe.DraggableGridViewPager.java

public DraggableGridViewPager(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (attrs != null) {
        TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.dragGridView, defStyle, 0);
        mShowDivider = typedArray.getBoolean(R.styleable.dragGridView_dividerShowed, false);
        mDividerColor = typedArray.getColor(R.styleable.dragGridView_dividerColor, 0);
        mDividerPaddingTop = typedArray.getDimensionPixelSize(R.styleable.dragGridView_dividerPaddingTop, 0);
        mDividerPaddingBottom = typedArray.getDimensionPixelSize(R.styleable.dragGridView_dividerPaddingBottom,
                0);//  w  w  w.ja  v  a2  s.com
        mDividerWidth = typedArray.getDimensionPixelSize(R.styleable.dragGridView_dividerWidth, 1);
        typedArray.recycle();
        HcLog.D(TAG + " divider color = " + mDividerColor);
    }
    initDraggableGridViewPager();
}

From source file:android.support.designox.widget.CollapsingToolbarLayout.java

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

    ThemeUtils.checkAppCompatTheme(context);

    mCollapsingTextHelper = new CollapsingTextHelper(this);
    mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.DECELERATE_INTERPOLATOR);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CollapsingToolbarLayout, defStyleAttr,
            R.style.Widget_Design_CollapsingToolbar);

    mCollapsingTextHelper.setExpandedTextGravity(a.getInt(
            R.styleable.CollapsingToolbarLayout_expandedTitleGravity, GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper/*from  w w  w  . java2s. c  om*/
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

    mExpandedMarginStart = mExpandedMarginTop = mExpandedMarginEnd = mExpandedMarginBottom = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMargin, 0);

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginEnd,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop)) {
        mExpandedMarginTop = a.getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginTop,
                0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_title));

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(R.style.TextAppearance_AppCompat_Widget_ActionBar_Title);

    // Now overlay any custom text appearances
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance)) {
        mCollapsingTextHelper.setExpandedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_expandedTitleTextAppearance, 0));
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance)) {
        mCollapsingTextHelper.setCollapsedTextAppearance(
                a.getResourceId(R.styleable.CollapsingToolbarLayout_collapsedTitleTextAppearance, 0));
    }

    setContentScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_contentScrim));
    setStatusBarScrim(a.getDrawable(R.styleable.CollapsingToolbarLayout_statusBarScrim));

    mToolbarId = a.getResourceId(R.styleable.CollapsingToolbarLayout_toolbarId, -1);

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this,
            new android.support.v4ox.view.OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return setWindowInsets(insets);
                }
            });
}

From source file:com.aretha.slidemenu.SlideMenu.java

public SlideMenu(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    // we want to draw drop shadow of content
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    mVelocityTracker = VelocityTracker.obtain();
    mScroller = new Scroller(context, mInterpolator);
    mContentHitRect = new Rect();
    STATUS_BAR_HEIGHT = (int) getStatusBarHeight(context);
    setWillNotDraw(false);//w w w  .jav  a 2  s.com

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

    // Set the shadow attributes
    setPrimaryShadowWidth(a.getDimension(R.styleable.SlideMenu_primaryShadowWidth, 30));
    setSecondaryShadowWidth(a.getDimension(R.styleable.SlideMenu_secondaryShadowWidth, 30));

    Drawable primaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable);
    if (null == primaryShadowDrawable) {
        primaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT,
                new int[] { Color.TRANSPARENT, Color.argb(99, 0, 0, 0) });
    }
    setPrimaryShadowDrawable(primaryShadowDrawable);

    Drawable secondaryShadowDrawable = a.getDrawable(R.styleable.SlideMenu_primaryShadowDrawable);
    if (null == secondaryShadowDrawable) {
        secondaryShadowDrawable = new GradientDrawable(Orientation.LEFT_RIGHT,
                new int[] { Color.argb(99, 0, 0, 0), Color.TRANSPARENT });
    }
    setSecondaryShadowDrawable(secondaryShadowDrawable);

    mSlideDirectionFlag = a.getInt(R.styleable.SlideMenu_slideDirection,
            FLAG_DIRECTION_LEFT | FLAG_DIRECTION_RIGHT);
    setFocusable(true);
    setFocusableInTouchMode(true);
    a.recycle();
}