Example usage for android.content.res TypedArray getDrawable

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

Introduction

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

Prototype

@Nullable
public Drawable getDrawable(@StyleableRes int index) 

Source Link

Document

Retrieve the Drawable for the attribute at index.

Usage

From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java

/**
 * Get attributes// ww  w. j  a  v a  2s .  co m
 **/
private void getAttributes(AttributeSet attrs) {
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.SegmentedButtonGroup);

    hasDivider = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_dividerSize);
    dividerSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerSize, 0);
    dividerColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_dividerColor, Color.WHITE);
    dividerPadding = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerPadding, 0);
    dividerRadius = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_dividerRadius, 0);

    textColorOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor,
            Color.GRAY);
    hasTextColorOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorTextColor);
    drawableTintOnSelection = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint,
            Color.GRAY);
    hasDrawableTintOnSelection = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_selectorImageTint);
    selectorColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_selectorColor, Color.GRAY);
    animateSelector = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelector, 0);
    animateSelectorDuration = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_animateSelectorDuration,
            500);

    shadow = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_shadow, false);
    shadowElevation = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_shadowElevation, 0);
    shadowMargin = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMargin, -1);
    shadowMarginTop = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginTop, 0);
    shadowMarginBottom = typedArray
            .getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginBottom, 0);
    shadowMarginLeft = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginLeft,
            0);
    shadowMarginRight = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_shadowMarginRight,
            0);

    radius = typedArray.getDimension(R.styleable.SegmentedButtonGroup_sbg_radius, 0);
    position = typedArray.getInt(R.styleable.SegmentedButtonGroup_sbg_position, 0);
    backgroundColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_backgroundColor, Color.WHITE);

    ripple = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_ripple, false);
    hasRippleColor = typedArray.hasValue(R.styleable.SegmentedButtonGroup_sbg_rippleColor);
    rippleColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_rippleColor, Color.GRAY);

    borderSize = typedArray.getDimensionPixelSize(R.styleable.SegmentedButtonGroup_sbg_borderSize, 0);
    borderColor = typedArray.getColor(R.styleable.SegmentedButtonGroup_sbg_borderColor, Color.BLACK);

    backgroundDrawable = typedArray.getDrawable(R.styleable.SegmentedButtonGroup_sbg_backgroundDrawable);
    selectorBackgroundDrawable = typedArray
            .getDrawable(R.styleable.SegmentedButtonGroup_sbg_selectorBackgroundDrawable);
    dividerBackgroundDrawable = typedArray
            .getDrawable(R.styleable.SegmentedButtonGroup_sbg_dividerBackgroundDrawable);

    enabled = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_sbg_enabled, true);

    try {
        clickable = typedArray.getBoolean(R.styleable.SegmentedButtonGroup_android_clickable, true);
    } catch (Exception ex) {
        Log.d("SegmentedButtonGroup", ex.toString());
    }

    typedArray.recycle();
}

From source file:com.awrtechnologies.carbudgetsales.hlistview.widget.HListView.java

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

    if (LOG_ENABLED) {
        Log.i(LOG_TAG, "defStyle: " + defStyle);
    }/* w w  w  . ja va2  s .  c  o m*/

    final Resources.Theme theme = context.getTheme();
    TypedArray array = theme.obtainStyledAttributes(attrs, R.styleable.HListView, defStyle, 0);

    CharSequence[] entries = null;
    Drawable dividerDrawable = null;
    Drawable overscrollHeader = null;
    Drawable overscrollFooter = null;
    int dividerWidth = 0;

    boolean headerDividersEnabled = true;
    boolean footerDividersEnabled = true;
    int measureWithChild = -1;

    if (null != array) {
        entries = array.getTextArray(R.styleable.HListView_android_entries);
        dividerDrawable = array.getDrawable(R.styleable.HListView_android_divider);
        overscrollHeader = array.getDrawable(R.styleable.HListView_hlv_overScrollHeader);
        overscrollFooter = array.getDrawable(R.styleable.HListView_hlv_overScrollFooter);
        dividerWidth = array.getDimensionPixelSize(R.styleable.HListView_hlv_dividerWidth, 0);
        headerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_headerDividersEnabled, true);
        footerDividersEnabled = array.getBoolean(R.styleable.HListView_hlv_footerDividersEnabled, true);
        measureWithChild = array.getInteger(R.styleable.HListView_hlv_measureWithChild, -1);
        array.recycle();

        if (LOG_ENABLED) {
            Log.d(LOG_TAG, "divider: " + dividerDrawable);
            Log.d(LOG_TAG, "overscrollHeader: " + overscrollHeader);
            Log.d(LOG_TAG, "overscrollFooter: " + overscrollFooter);
            Log.d(LOG_TAG, "dividerWith: " + dividerWidth);
            Log.d(LOG_TAG, "headerDividersEnabled: " + headerDividersEnabled);
            Log.d(LOG_TAG, "footerDividersEnabled: " + footerDividersEnabled);
            Log.d(LOG_TAG, "measureWithChild: " + measureWithChild);
        }
    }

    if (entries != null) {
        setAdapter(new ArrayAdapter<CharSequence>(context, android.R.layout.simple_list_item_1, entries));
    }

    if (dividerDrawable != null) {
        // If a divider is specified use its intrinsic height for divider height
        setDivider(dividerDrawable);
    }

    if (overscrollHeader != null) {
        setOverscrollHeader(overscrollHeader);
    }

    if (overscrollFooter != null) {
        setOverscrollFooter(overscrollFooter);
    }

    // Use the height specified, zero being the default
    if (dividerWidth != 0) {
        setDividerWidth(dividerWidth);
    }

    mHeaderDividersEnabled = headerDividersEnabled;
    mFooterDividersEnabled = footerDividersEnabled;
    mMeasureWithChild = measureWithChild;

}

From source file:android.support.design.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 .ja  va  2s  .c o  m*/
            .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(
            android.support.v7.appcompat.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));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    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.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}

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

private void initializeLayout() {
    mContext = getContext();//  www  . j av a2  s . c  om
    setCurrentLocale(Locale.getDefault());

    // process style attributes
    final TypedArray a = mContext.obtainStyledAttributes(R.styleable.SublimeTimePicker);
    final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final Resources res = mContext.getResources();

    mSelectHours = res.getString(R.string.select_hours);
    mSelectMinutes = res.getString(R.string.select_minutes);

    DateFormatSymbols dfs = DateFormatSymbols.getInstance(mCurrentLocale);
    String[] amPmStrings = dfs.getAmPmStrings();/*{"AM", "PM"}*/

    if (amPmStrings.length == 2 && !TextUtils.isEmpty(amPmStrings[0]) && !TextUtils.isEmpty(amPmStrings[1])) {
        mAmText = amPmStrings[0].length() > 2 ? amPmStrings[0].substring(0, 2) : amPmStrings[0];
        mPmText = amPmStrings[1].length() > 2 ? amPmStrings[1].substring(0, 2) : amPmStrings[1];
    } else {
        // Defaults
        mAmText = "AM";
        mPmText = "PM";
    }

    final int layoutResourceId = R.layout.time_picker_layout;
    final View mainView = inflater.inflate(layoutResourceId, this);

    mHeaderView = mainView.findViewById(R.id.time_header);

    // Set up hour/minute labels.
    mHourView = (TextView) mainView.findViewById(R.id.hours);
    mHourView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(mContext, R.string.select_hours));

    mSeparatorView = (TextView) mainView.findViewById(R.id.separator);

    mMinuteView = (TextView) mainView.findViewById(R.id.minutes);
    mMinuteView.setOnClickListener(mClickListener);

    ViewCompat.setAccessibilityDelegate(mMinuteView,
            new ClickActionDelegate(mContext, R.string.select_minutes));

    // Now that we have text appearances out of the way, make sure the hour
    // and minute views are correctly sized.
    mHourView.setMinWidth(computeStableWidth(mHourView, 24));
    mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60));

    // Set up AM/PM labels.
    mAmPmLayout = mainView.findViewById(R.id.ampm_layout);
    mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label);
    mAmLabel.setText(obtainVerbatim(amPmStrings[0]));
    mAmLabel.setOnClickListener(mClickListener);
    mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label);
    mPmLabel.setText(obtainVerbatim(amPmStrings[1]));
    mPmLabel.setOnClickListener(mClickListener);

    ColorStateList headerTextColor = a.getColorStateList(R.styleable.SublimeTimePicker_spHeaderTextColor);

    if (headerTextColor != null) {
        mHourView.setTextColor(headerTextColor);
        mSeparatorView.setTextColor(headerTextColor);
        mMinuteView.setTextColor(headerTextColor);
        mAmLabel.setTextColor(headerTextColor);
        mPmLabel.setTextColor(headerTextColor);
    }

    // Set up header background, if available.
    if (SUtils.isApi_22_OrHigher()) {
        if (a.hasValueOrEmpty(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    } else {
        if (a.hasValue(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    }

    a.recycle();

    mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker);

    setupListeners();

    mAllowAutoAdvance = true;

    // Set up for keyboard mode.
    mDoublePlaceholderText = res.getString(R.string.time_placeholder);
    mDeletedKeyFormat = res.getString(R.string.deleted_key);
    mPlaceholderText = mDoublePlaceholderText.charAt(0);
    mAmKeyCode = mPmKeyCode = -1;
    generateLegalTimesTree();

    // Initialize with current time
    final Calendar calendar = Calendar.getInstance(mCurrentLocale);
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);
    initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX);
}

From source file:com.lovely3x.eavlibrary.EasyAdapterView.java

/**
 * ??//from w w  w . j a  v  a 2s  . c o m
 *
 * @param attrs ?
 */
protected void initAttrs(AttributeSet attrs) {
    if (attrs != null) {

        TypedArray typeArray = null;
        try {
            typeArray = getContext().obtainStyledAttributes(attrs, R.styleable.EasyAdapterView);

            mLayoutDirectly = typeArray.getInteger(R.styleable.EasyAdapterView_orientation,
                    LAYOUT_DIRECTLY_VERTICAL);
            mViewMode = ViewMode.wrap(typeArray.getInteger(R.styleable.EasyAdapterView_mode, LIST_VIEW.mValue));

            mDividerHeight = typeArray.getDimensionPixelOffset(R.styleable.EasyAdapterView_dividerHeight,
                    mDividerHeight);
            Drawable divider = typeArray.getDrawable(R.styleable.EasyAdapterView_divider);
            if (divider != null)
                mDivider = divider;

            switch (mLayoutDirectly) {
            case LAYOUT_DIRECTLY_HORIZONTAL: {
                setHorizontalScrollBarEnabled(true);
                setVerticalScrollBarEnabled(false);

            }
                break;
            case LAYOUT_DIRECTLY_VERTICAL: {
                setVerticalScrollBarEnabled(true);
                setHorizontalScrollBarEnabled(false);
            }
                break;
            }

        } finally {
            if (typeArray != null)
                typeArray.recycle();
        }

    }
}

From source file:com.muzakki.ahmad.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/*  w w  w  .j a v  a2  s.  c o  m*/
            .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));

    // begin modification
    TypedArray mStyle = context.obtainStyledAttributes(attrs, R.styleable.SubtitleCollapsingToolbar,
            defStyleAttr, R.style.SubtitleCollapsingToolbar);
    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_subtitle))
        setSubtitle(mStyle.getText(R.styleable.SubtitleCollapsingToolbar_subtitle).toString());

    //load default appearances first
    mCollapsingTextHelper.setCollapsedSubAppearance(R.style.CollapsedSubtitleAppearance);
    mCollapsingTextHelper.setExpandedSubAppearance(R.style.ExpandedSubtitleAppearance);

    // now apply custom sub appearance
    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_collapsedSubtitleAppearance)) {
        mCollapsingTextHelper.setCollapsedSubAppearance(
                mStyle.getResourceId(R.styleable.SubtitleCollapsingToolbar_collapsedSubtitleAppearance, 0));
    }

    if (mStyle.hasValue(R.styleable.SubtitleCollapsingToolbar_expandedSubtitleAppearance)) {
        mCollapsingTextHelper.setExpandedSubAppearance(
                mStyle.getResourceId(R.styleable.SubtitleCollapsingToolbar_expandedSubtitleAppearance, 0));
    }
    // end

    // First load the default text appearances
    mCollapsingTextHelper.setExpandedTextAppearance(R.style.TextAppearance_Design_CollapsingToolbar_Expanded);
    mCollapsingTextHelper.setCollapsedTextAppearance(
            android.support.v7.appcompat.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));
    }

    mScrimVisibleHeightTrigger = a
            .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_scrimVisibleHeightTrigger, -1);

    mScrimAnimationDuration = a.getInt(R.styleable.CollapsingToolbarLayout_scrimAnimationDuration,
            DEFAULT_SCRIM_ANIMATION_DURATION);

    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.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            return onWindowInsetChanged(insets);
        }
    });
}

From source file:com.appunite.list.AbsHorizontalListView.java

public AbsHorizontalListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initAbsListView();//w w  w .j  a va  2s .  c  om

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

    Drawable d = a.getDrawable(R.styleable.AbsListView_listSelector);
    if (d != null) {
        setSelector(d);
    }

    mDrawSelectorOnTop = a.getBoolean(R.styleable.AbsListView_drawSelectorOnTop, false);

    boolean stackFromRight = a.getBoolean(R.styleable.AbsListView_stackFromBottom, false);
    setStackFromRight(stackFromRight);

    boolean scrollingCacheEnabled = a.getBoolean(R.styleable.AbsListView_scrollingCache, true);
    setScrollingCacheEnabled(scrollingCacheEnabled);

    boolean useTextFilter = a.getBoolean(R.styleable.AbsListView_textFilterEnabled, false);
    setTextFilterEnabled(useTextFilter);

    int transcriptMode = a.getInt(R.styleable.AbsListView_transcriptMode, TRANSCRIPT_MODE_DISABLED);
    setTranscriptMode(transcriptMode);

    int color = a.getColor(R.styleable.AbsListView_cacheColorHint, 0);
    setCacheColorHint(color);

    boolean smoothScrollbar = a.getBoolean(R.styleable.AbsListView_smoothScrollbar, true);
    setSmoothScrollbarEnabled(smoothScrollbar);

    setChoiceMode(a.getInt(R.styleable.AbsListView_choiceMode, CHOICE_MODE_NONE));

    a.recycle();
}

From source file:com.appunite.list.AbsListView.java

public AbsListView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    initAbsListView();//from  ww w  .j  a  v a 2  s.  com

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

    Drawable d = a.getDrawable(R.styleable.AbsListView_listSelector);
    if (d != null) {
        setSelector(d);
    }

    mDrawSelectorOnTop = a.getBoolean(R.styleable.AbsListView_drawSelectorOnTop, false);

    boolean stackFromBottom = a.getBoolean(R.styleable.AbsListView_stackFromBottom, false);
    setStackFromBottom(stackFromBottom);

    boolean scrollingCacheEnabled = a.getBoolean(R.styleable.AbsListView_scrollingCache, true);
    setScrollingCacheEnabled(scrollingCacheEnabled);

    boolean useTextFilter = a.getBoolean(R.styleable.AbsListView_textFilterEnabled, false);
    setTextFilterEnabled(useTextFilter);

    int transcriptMode = a.getInt(R.styleable.AbsListView_transcriptMode, TRANSCRIPT_MODE_DISABLED);
    setTranscriptMode(transcriptMode);

    int color = a.getColor(R.styleable.AbsListView_cacheColorHint, 0);
    setCacheColorHint(color);

    boolean enableFastScroll = a.getBoolean(R.styleable.AbsListView_fastScrollEnabled, false);
    setFastScrollEnabled(enableFastScroll);

    boolean smoothScrollbar = a.getBoolean(R.styleable.AbsListView_smoothScrollbar, true);
    setSmoothScrollbarEnabled(smoothScrollbar);

    setChoiceMode(a.getInt(R.styleable.AbsListView_choiceMode, CHOICE_MODE_NONE));
    setFastScrollAlwaysVisible(a.getBoolean(R.styleable.AbsListView_fastScrollAlwaysVisible, false));

    a.recycle();
}

From source file:com.qurater.pivotal.ui.TwoWayView.java

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

    mNeedSync = false;//from   ww  w.  ja  v a  2  s . co  m
    mVelocityTracker = null;

    mLayoutMode = LAYOUT_NORMAL;
    mTouchMode = TOUCH_MODE_REST;
    mLastTouchMode = TOUCH_MODE_UNKNOWN;

    mIsAttached = false;

    mContextMenuInfo = null;

    mOnScrollListener = null;
    mLastScrollState = OnScrollListener.SCROLL_STATE_IDLE;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaximumVelocity = vc.getScaledMaximumFlingVelocity();
    mFlingVelocity = vc.getScaledMinimumFlingVelocity();
    mOverscrollDistance = getScaledOverscrollDistance(vc);

    mOverScroll = 0;

    mScroller = new Scroller(context);

    mIsVertical = true;

    mItemsCanFocus = false;

    mTempRect = new Rect();

    mArrowScrollFocusResult = new ArrowScrollFocusResult();

    mSelectorPosition = INVALID_POSITION;

    mSelectorRect = new Rect();
    mSelectedStart = 0;

    mResurrectToPosition = INVALID_POSITION;

    mSelectedStart = 0;
    mNextSelectedPosition = INVALID_POSITION;
    mNextSelectedRowId = INVALID_ROW_ID;
    mSelectedPosition = INVALID_POSITION;
    mSelectedRowId = INVALID_ROW_ID;
    mOldSelectedPosition = INVALID_POSITION;
    mOldSelectedRowId = INVALID_ROW_ID;

    mChoiceMode = ChoiceMode.NONE;
    mCheckedItemCount = 0;
    mCheckedIdStates = null;
    mCheckStates = null;

    mRecycler = new RecycleBin();
    mDataSetObserver = null;

    mAreAllItemsSelectable = true;

    mStartEdge = null;
    mEndEdge = null;

    setClickable(true);
    setFocusableInTouchMode(true);
    setWillNotDraw(false);
    setAlwaysDrawnWithCacheEnabled(false);
    setWillNotDraw(false);
    setClipToPadding(false);

    ViewCompat.setOverScrollMode(this, ViewCompat.OVER_SCROLL_IF_CONTENT_SCROLLS);

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

    mDrawSelectorOnTop = a.getBoolean(R.styleable.TwoWayView_android_drawSelectorOnTop, false);

    Drawable d = a.getDrawable(R.styleable.TwoWayView_android_listSelector);
    if (d != null) {
        setSelector(d);
    }

    int orientation = a.getInt(R.styleable.TwoWayView_android_orientation, -1);
    if (orientation >= 0) {
        setOrientation(Orientation.values()[orientation]);
    }

    int choiceMode = a.getInt(R.styleable.TwoWayView_android_choiceMode, -1);
    if (choiceMode >= 0) {
        setChoiceMode(ChoiceMode.values()[choiceMode]);
    }

    a.recycle();
}

From source file:com.tandong.sa.vpic.TitlePageIndicator.java

public TitlePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//ww w  .  jav a2s. c  o m

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultFooterColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_footer_color", "color", context.getPackageName()));
    // final int defaultFooterColor = res
    // .getColor(R.color.default_title_indicator_footer_color);
    final float defaultFooterLineHeight = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_footer_line_height", "dimen", context.getPackageName()));
    // final float defaultFooterLineHeight = res
    // .getDimension(R.dimen.default_title_indicator_footer_line_height);
    final int defaultFooterIndicatorStyle = res.getInteger(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_style", "integer", context.getPackageName()));
    // final int defaultFooterIndicatorStyle = res
    // .getInteger(R.integer.default_title_indicator_footer_indicator_style);
    final float defaultFooterIndicatorHeight = res.getDimension(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_height", "dimen", context.getPackageName()));
    // final float defaultFooterIndicatorHeight = res
    // .getDimension(R.dimen.default_title_indicator_footer_indicator_height);
    final float defaultFooterIndicatorUnderlinePadding = res.getDimension(context.getResources().getIdentifier(
            "default_title_indicator_footer_indicator_underline_padding", "dimen", context.getPackageName()));
    // final float defaultFooterIndicatorUnderlinePadding = res
    // .getDimension(R.dimen.default_title_indicator_footer_indicator_underline_padding);
    final float defaultFooterPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_footer_padding", "dimen", context.getPackageName()));
    // final float defaultFooterPadding = res
    // .getDimension(R.dimen.default_title_indicator_footer_padding);
    final int defaultLinePosition = res.getInteger(context.getResources()
            .getIdentifier("default_title_indicator_line_position", "integer", context.getPackageName()));
    // final int defaultLinePosition = res
    // .getInteger(R.integer.default_title_indicator_line_position);
    final int defaultSelectedColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_selected_color", "color", context.getPackageName()));
    // final int defaultSelectedColor = res
    // .getColor(R.color.default_title_indicator_selected_color);
    final boolean defaultSelectedBold = res.getBoolean(context.getResources()
            .getIdentifier("default_title_indicator_selected_bold", "bool", context.getPackageName()));
    // final boolean defaultSelectedBold = res
    // .getBoolean(R.bool.default_title_indicator_selected_bold);
    final int defaultTextColor = res.getColor(context.getResources()
            .getIdentifier("default_title_indicator_text_color", "color", context.getPackageName()));
    // final int defaultTextColor = res
    // .getColor(R.color.default_title_indicator_text_color);
    final float defaultTextSize = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_text_size", "dimen", context.getPackageName()));
    // final float defaultTextSize = res
    // .getDimension(R.dimen.default_title_indicator_text_size);
    final float defaultTitlePadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_title_padding", "dimen", context.getPackageName()));
    // final float defaultTitlePadding = res
    // .getDimension(R.dimen.default_title_indicator_title_padding);
    final float defaultClipPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_clip_padding", "dimen", context.getPackageName()));
    // final float defaultClipPadding = res
    // .getDimension(R.dimen.default_title_indicator_clip_padding);
    final float defaultTopPadding = res.getDimension(context.getResources()
            .getIdentifier("default_title_indicator_top_padding", "dimen", context.getPackageName()));
    // final float defaultTopPadding = res
    // .getDimension(R.dimen.default_title_indicator_top_padding);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs,
            new int[] {
                    getResources().getIdentifier("TitlePageIndicator", "styleable", context.getPackageName()) },
            defStyle, 0);
    // TypedArray a = context.obtainStyledAttributes(attrs,
    // R.styleable.TitlePageIndicator, defStyle, 0);

    // Retrieve the colors to be used for this view and apply them.
    mFooterLineHeight = a.getDimension(getResources().getIdentifier("TitlePageIndicator_footerLineHeight",
            "styleable", context.getPackageName()), defaultFooterLineHeight);
    // mFooterLineHeight = a.getDimension(
    // R.styleable.TitlePageIndicator_footerLineHeight,
    // defaultFooterLineHeight);
    mFooterIndicatorStyle = IndicatorStyle
            .fromValue(a.getInteger(getResources().getIdentifier("TitlePageIndicator_footerIndicatorStyle",
                    "styleable", context.getPackageName()), defaultFooterIndicatorStyle));
    // mFooterIndicatorStyle = IndicatorStyle.fromValue(a.getInteger(
    // R.styleable.TitlePageIndicator_footerIndicatorStyle,
    // defaultFooterIndicatorStyle));
    mFooterIndicatorHeight = a.getDimension(getResources()
            .getIdentifier("TitlePageIndicator_footerIndicatorHeight", "styleable", context.getPackageName()),
            defaultFooterIndicatorHeight);
    // mFooterIndicatorHeight = a.getDimension(
    // R.styleable.TitlePageIndicator_footerIndicatorHeight,
    // defaultFooterIndicatorHeight);
    mFooterIndicatorUnderlinePadding = a
            .getDimension(getResources().getIdentifier("TitlePageIndicator_footerIndicatorUnderlinePadding",
                    "styleable", context.getPackageName()), defaultFooterIndicatorUnderlinePadding);
    // mFooterIndicatorUnderlinePadding = a.getDimension(
    // R.styleable.TitlePageIndicator_footerIndicatorUnderlinePadding,
    // defaultFooterIndicatorUnderlinePadding);
    mFooterPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_footerPadding",
            "styleable", context.getPackageName()), defaultFooterPadding);
    // mFooterPadding = a.getDimension(
    // R.styleable.TitlePageIndicator_footerPadding,
    // defaultFooterPadding);
    mLinePosition = LinePosition
            .fromValue(a.getInteger(getResources().getIdentifier("TitlePageIndicator_linePosition", "styleable",
                    context.getPackageName()), defaultLinePosition));
    // mLinePosition = LinePosition.fromValue(a.getInteger(
    // R.styleable.TitlePageIndicator_linePosition,
    // defaultLinePosition));
    mTopPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_topPadding", "styleable",
            context.getPackageName()), defaultTopPadding);
    // mTopPadding =
    // a.getDimension(R.styleable.TitlePageIndicator_topPadding,
    // defaultTopPadding);
    mTitlePadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_titlePadding", "styleable",
            context.getPackageName()), defaultTitlePadding);
    // mTitlePadding = a.getDimension(
    // R.styleable.TitlePageIndicator_titlePadding,
    // defaultTitlePadding);
    mClipPadding = a.getDimension(getResources().getIdentifier("TitlePageIndicator_clipPadding", "styleable",
            context.getPackageName()), defaultClipPadding);
    // mClipPadding = a.getDimension(
    // R.styleable.TitlePageIndicator_clipPadding, defaultClipPadding);
    mColorSelected = a.getColor(getResources().getIdentifier("TitlePageIndicator_selectedColor", "styleable",
            context.getPackageName()), defaultSelectedColor);
    // mColorSelected = a.getColor(
    // R.styleable.TitlePageIndicator_selectedColor,
    // defaultSelectedColor);
    mColorText = a.getColor(getResources().getIdentifier("TitlePageIndicator_android_textColor", "styleable",
            context.getPackageName()), defaultTextColor);
    // mColorText = a.getColor(
    // R.styleable.TitlePageIndicator_android_textColor,
    // defaultTextColor);
    mBoldText = a.getBoolean(getResources().getIdentifier("TitlePageIndicator_selectedBold", "styleable",
            context.getPackageName()), defaultSelectedBold);
    // mBoldText = a.getBoolean(R.styleable.TitlePageIndicator_selectedBold,
    // defaultSelectedBold);

    final float textSize = a.getDimension(getResources().getIdentifier("TitlePageIndicator_android_textSize",
            "styleable", context.getPackageName()), defaultTextSize);
    // final float textSize = a.getDimension(
    // R.styleable.TitlePageIndicator_android_textSize,
    // defaultTextSize);
    final int footerColor = a.getColor(getResources().getIdentifier("TitlePageIndicator_footerColor",
            "styleable", context.getPackageName()), defaultFooterColor);
    // final int footerColor = a.getColor(
    // R.styleable.TitlePageIndicator_footerColor, defaultFooterColor);
    mPaintText.setTextSize(textSize);
    mPaintText.setAntiAlias(true);
    mPaintFooterLine.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterLine.setStrokeWidth(mFooterLineHeight);
    mPaintFooterLine.setColor(footerColor);
    mPaintFooterIndicator.setStyle(Paint.Style.FILL_AND_STROKE);
    mPaintFooterIndicator.setColor(footerColor);

    Drawable background = a.getDrawable(getResources().getIdentifier("TitlePageIndicator_android_background",
            "styleable", context.getPackageName()));
    // Drawable background = a
    // .getDrawable(R.styleable.TitlePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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