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:com.albedinsky.android.ui.widget.SearchView.java

/**
 * Called from one of constructors of this view to perform its initialization.
 * <p>/*from w  w  w .  j a  va 2 s . co m*/
 * Initialization is done via parsing of the specified <var>attrs</var> set and obtaining for
 * this view specific data from it that can be used to configure this new view instance. The
 * specified <var>defStyleAttr</var> and <var>defStyleRes</var> are used to obtain default data
 * from the current theme provided by the specified <var>context</var>.
 */
@SuppressWarnings("ResourceType")
private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    this.mContext = context;
    setOrientation(HORIZONTAL);
    setGravity(Gravity.CENTER_VERTICAL);
    this.inflateHierarchy(context, R.layout.ui_search_view);
    this.mProgressBarAnimator = createProgressBarAnimator();
    this.mDefaultRevealAnimationHandler = createRevealAnimationHandler();
    ColorStateList tintList = null;
    PorterDuff.Mode tintMode = PorterDuff.Mode.SRC_IN;
    /**
     * Process attributes.
     */
    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Ui_SearchView, defStyleAttr,
            defStyleRes);
    if (typedArray != null) {
        final int n = typedArray.getIndexCount();
        for (int i = 0; i < n; i++) {
            final int index = typedArray.getIndex(i);
            if (index == R.styleable.Ui_SearchView_android_queryHint) {
                setQueryHint(typedArray.getText(index));
            } else if (index == R.styleable.Ui_SearchView_uiTint) {
                tintList = typedArray.getColorStateList(index);
            } else if (index == R.styleable.Ui_SearchView_uiTintMode) {
                tintMode = TintManager.parseTintMode(typedArray.getInt(R.styleable.Ui_SearchView_uiTintMode, 0),
                        tintList != null ? PorterDuff.Mode.SRC_IN : null);
            } else if (index == R.styleable.Ui_SearchView_uiRevealDuration) {
                mDefaultRevealAnimationHandler.revealDuration = typedArray.getInt(index, 0);
            } else if (index == R.styleable.Ui_SearchView_uiConcealDuration) {
                mDefaultRevealAnimationHandler.concealDuration = typedArray.getInt(index, 0);
            } else if (index == R.styleable.Ui_SearchView_uiRevealInterpolator) {
                final int resId = typedArray.getResourceId(index, 0);
                if (resId != 0) {
                    mDefaultRevealAnimationHandler.interpolator = AnimationUtils.loadInterpolator(context,
                            resId);
                }
            }
        }
        typedArray.recycle();
    }
    if (tintList != null || tintMode != null) {
        this.mTintInfo = new SearchTintInfo();
        this.mTintInfo.tintList = tintList;
        this.mTintInfo.hasTintList = tintList != null;
        this.mTintInfo.tintMode = tintMode;
        this.mTintInfo.hasTintMode = tintMode != null;
    }
    final Resources.Theme theme = context.getTheme();
    final TypedValue typedValue = new TypedValue();
    if (theme.resolveAttribute(R.attr.uiSearchSelectHandleColor, typedValue, true)) {
        if (mTintInfo == null) {
            this.mTintInfo = new SearchTintInfo();
        }
        if (typedValue.resourceId > 0) {
            mTintInfo.textSelectHandleTintList = ResourceUtils.getColorStateList(getResources(),
                    typedValue.resourceId, theme);
        } else {
            mTintInfo.textSelectHandleTintList = ColorStateList.valueOf(typedValue.data);
        }
        mTintInfo.hasTextSelectHandleTintList = mTintInfo.textSelectHandleTintList != null;
    }
    this.applyTint();
    this.mRevealAnimationHandler = mDefaultRevealAnimationHandler;
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = getContext();

    // Pull disabled alpha from theme.
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    mDisabledAlpha = outValue.getFloat();

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr,
            defStyleRes);//from w w  w .  j  a  v  a  2s . c  o m

    mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor);
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor);
    mTextColor[MINUTES] = mTextColor[HOURS];

    mPaint[HOURS] = new Paint();
    mPaint[HOURS].setAntiAlias(true);
    mPaint[HOURS].setTextAlign(Paint.Align.CENTER);

    mPaint[MINUTES] = new Paint();
    mPaint[MINUTES].setAntiAlias(true);
    mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);

    final ColorStateList selectorColors = a
            .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor);

    int selectorActivatedColor = Color.BLACK;
    if (selectorColors != null) {
        selectorActivatedColor = selectorColors
                .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0);
    }

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);

    mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
    mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);

    mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);

    mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor,
            ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner);

    mShowHours = true;
    mIs24HourMode = false;
    mAmOrPm = AM;

    // Set up accessibility components.
    mTouchHelper = new RadialPickerTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);

    if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    initHoursAndMinutesText();
    initData();

    a.recycle();

    // Initial values
    final Calendar calendar = Calendar.getInstance(Locale.getDefault());
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);

    setCurrentHourInternal(currentHour, false, false);
    setCurrentMinuteInternal(currentMinute, false);

    setHapticFeedbackEnabled(true);
}

From source file:com.acbelter.scheduleview.ScheduleView.java

public ScheduleView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mClipRect = new Rect();
    mClickedViewBounds = new Rect();
    mSelectedIds = new HashSet<Long>();
    mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    mTopEdgeEffect = new EdgeEffectCompat(context);
    mBottomEdgeEffect = new EdgeEffectCompat(context);

    mDataSetObserver = new DataSetObserver() {
        @Override//from   ww  w .j  a v  a 2  s . c om
        public void onChanged() {
            super.onChanged();
            removeAllViewsInLayout();
            requestLayout();
        }

        @Override
        public void onInvalidated() {
            super.onInvalidated();
            removeAllViewsInLayout();
            requestLayout();
        }
    };

    init(context);

    setVerticalScrollBarEnabled(true);
    setHorizontalScrollBarEnabled(false);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ScheduleView, defStyle, 0);
    try {
        if (a != null) {
            DisplayMetrics dm = context.getResources().getDisplayMetrics();
            mInternalPaddingTop = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingTop,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mInternalPaddingBottom = (int) a.getDimension(R.styleable.ScheduleView_internalPaddingBottom,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mTimeMarksDistance = (int) a.getDimension(R.styleable.ScheduleView_timeMarksDistance,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 40, dm));
            mItemPaddingLeft = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingLeft,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            mItemPaddingRight = (int) a.getDimension(R.styleable.ScheduleView_itemPaddingRight,
                    TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 8, dm));
            initializeScrollbars(a);
        }
    } finally {
        if (a != null) {
            a.recycle();
        }
    }

    // Draw the background even if no items to display
    setWillNotDraw(false);

    mActionModeCallback = new ActionMode.Callback() {
        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            mode.getMenuInflater().inflate(R.menu.menu_context, menu);
            mIsActionMode = true;
            return true;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            if (item.getItemId() == R.id.delete_items) {
                deleteSelectedItems();
            }
            return false;
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            clearSelection();
            mIsActionMode = false;
            mActionMode = null;
            invalidate();
        }
    };
}

From source file:android.support.v7.widget.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 *//*from ww w .j a v  a  2  s.c  o m*/
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:android.support.v7.preference.Preference.java

/**
 * Perform inflation from XML and apply a class-specific base style. This
 * constructor of Preference allows subclasses to use their own base style
 * when they are inflating. For example, a {@link CheckBoxPreference}
 * constructor calls this version of the super class constructor and
 * supplies {@code android.R.attr.checkBoxPreferenceStyle} for
 * <var>defStyleAttr</var>. This allows the theme's checkbox preference
 * style to modify all of the base preference attributes as well as the
 * {@link CheckBoxPreference} class's attributes.
 *
 * @param context The Context this is associated with, through which it can
 *            access the current theme, resources,
 *            {@link android.content.SharedPreferences}, etc.
 * @param attrs The attributes of the XML tag that is inflating the
 *            preference.//  w ww  . j  a v a2 s . c  om
 * @param defStyleAttr An attribute in the current theme that contains a
 *            reference to a style resource that supplies default values for
 *            the view. Can be 0 to not look for defaults.
 * @param defStyleRes A resource identifier of a style resource that
 *            supplies default values for the view, used only if
 *            defStyleAttr is 0 or can not be found in the theme. Can be 0
 *            to not look for defaults.
 * @see #Preference(Context, android.util.AttributeSet)
 */
public Preference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.Preference, defStyleAttr,
            defStyleRes);

    mIconResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_icon,
            R.styleable.Preference_android_icon, 0);

    mKey = TypedArrayUtils.getString(a, R.styleable.Preference_key, R.styleable.Preference_android_key);

    mTitle = TypedArrayUtils.getString(a, R.styleable.Preference_title, R.styleable.Preference_android_title);

    mSummary = TypedArrayUtils.getString(a, R.styleable.Preference_summary,
            R.styleable.Preference_android_summary);

    mOrder = TypedArrayUtils.getInt(a, R.styleable.Preference_order, R.styleable.Preference_android_order,
            DEFAULT_ORDER);

    mFragment = TypedArrayUtils.getString(a, R.styleable.Preference_fragment,
            R.styleable.Preference_android_fragment);

    mLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_layout,
            R.styleable.Preference_android_layout, R.layout.preference);

    mWidgetLayoutResId = TypedArrayUtils.getResourceId(a, R.styleable.Preference_widgetLayout,
            R.styleable.Preference_android_widgetLayout, 0);

    mEnabled = TypedArrayUtils.getBoolean(a, R.styleable.Preference_enabled,
            R.styleable.Preference_android_enabled, true);

    mSelectable = TypedArrayUtils.getBoolean(a, R.styleable.Preference_selectable,
            R.styleable.Preference_android_selectable, true);

    mPersistent = TypedArrayUtils.getBoolean(a, R.styleable.Preference_persistent,
            R.styleable.Preference_android_persistent, true);

    mDependencyKey = TypedArrayUtils.getString(a, R.styleable.Preference_dependency,
            R.styleable.Preference_android_dependency);

    if (a.hasValue(R.styleable.Preference_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_defaultValue);
    } else if (a.hasValue(R.styleable.Preference_android_defaultValue)) {
        mDefaultValue = onGetDefaultValue(a, R.styleable.Preference_android_defaultValue);
    }

    mShouldDisableView = TypedArrayUtils.getBoolean(a, R.styleable.Preference_shouldDisableView,
            R.styleable.Preference_android_shouldDisableView, true);

    a.recycle();
}

From source file:chickennugget.spaceengineersdata.material.widgets.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context      Context used for contained views.
 * @param attrs        Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Default style attribute to use for popup content.
 * @param defStyleRes  Default style to use for popup content.
 *//*  w  ww  .ja v  a 2s.com*/
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new PopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    int mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:cn.lanqiushe.view.CirclePageIndicator.java

public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  w w  .  ja  v a 2 s. c om

    // 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, 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_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:android.support.v7ox.widget.ListPopupWindow.java

/**
 * Create a new, empty popup window capable of displaying items from a ListAdapter.
 * Backgrounds should be set using {@link #setBackgroundDrawable(Drawable)}.
 *
 * @param context Context used for contained views.
 * @param attrs Attributes from inflating parent views used to style the popup.
 * @param defStyleAttr Style attribute to read for default styling of popup content.
 * @param defStyleRes Style resource ID to use for default styling of popup content.
 */// www. j a v a  2  s  .  c  o  m
public ListPopupWindow(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    mContext = context;
    mHandler = new Handler(context.getMainLooper());

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ListPopupWindow, defStyleAttr,
            defStyleRes);
    mDropDownHorizontalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownHorizontalOffset, 0);
    mDropDownVerticalOffset = a
            .getDimensionPixelOffset(R.styleable.ListPopupWindow_android_dropDownVerticalOffset, 0);
    if (mDropDownVerticalOffset != 0) {
        mDropDownVerticalOffsetSet = true;
    }
    a.recycle();

    mPopup = new AppCompatPopupWindow(context, attrs, defStyleAttr);
    mPopup.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);

    // Set the default layout direction to match the default locale one
    final Locale locale = mContext.getResources().getConfiguration().locale;
    mLayoutDirection = TextUtilsCompat.getLayoutDirectionFromLocale(locale);
}

From source file:com.apptentive.android.sdk.view.ApptentiveNestedScrollView.java

public ApptentiveNestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initScrollView();/*from   w w  w.  ja v a  2s. com*/

    final TypedArray a = context.obtainStyledAttributes(attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);

    setFillViewport(a.getBoolean(0, false));

    a.recycle();

    mParentHelper = new NestedScrollingParentHelper(this);
    mChildHelper = new NestedScrollingChildHelper(this);

    // ...because why else would you be using this widget?
    setNestedScrollingEnabled(true);

    ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE);
}

From source file:com.android.launcher2.PagedView.java

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagedView, defStyle, 0);
    setPageSpacing(a.getDimensionPixelSize(R.styleable.PagedView_pageSpacing, 0));
    mPageLayoutPaddingTop = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingTop, 0);
    mPageLayoutPaddingBottom = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingBottom, 0);
    mPageLayoutPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingLeft, 0);
    mPageLayoutPaddingRight = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutPaddingRight, 0);
    mPageLayoutWidthGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutWidthGap, 0);
    mPageLayoutHeightGap = a.getDimensionPixelSize(R.styleable.PagedView_pageLayoutHeightGap, 0);
    mScrollIndicatorPaddingLeft = a.getDimensionPixelSize(R.styleable.PagedView_scrollIndicatorPaddingLeft, 0);
    mScrollIndicatorPaddingRight = a.getDimensionPixelSize(R.styleable.PagedView_scrollIndicatorPaddingRight,
            0);//w  w w . ja va  2  s  .c o m
    a.recycle();

    setHapticFeedbackEnabled(false);
    init();
}