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.support.design.widget.FloatingActionButton.java

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

    ThemeUtils.checkAppCompatTheme(context);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr,
            R.style.Widget_Design_FloatingActionButton);
    mBackgroundTint = a.getColorStateList(R.styleable.FloatingActionButton_backgroundTint);
    mBackgroundTintMode = ViewUtils// w ww  .j a v  a  2  s .c  om
            .parseTintMode(a.getInt(R.styleable.FloatingActionButton_backgroundTintMode, -1), null);
    mRippleColor = a.getColor(R.styleable.FloatingActionButton_rippleColor, 0);
    mSize = a.getInt(R.styleable.FloatingActionButton_fabSize, SIZE_AUTO);
    mBorderWidth = a.getDimensionPixelSize(R.styleable.FloatingActionButton_borderWidth, 0);
    final float elevation = a.getDimension(R.styleable.FloatingActionButton_elevation, 0f);
    final float pressedTranslationZ = a.getDimension(R.styleable.FloatingActionButton_pressedTranslationZ, 0f);
    mCompatPadding = a.getBoolean(R.styleable.FloatingActionButton_useCompatPadding, false);
    a.recycle();

    mImageHelper = new AppCompatImageHelper(this);
    mImageHelper.loadFromAttributes(attrs, defStyleAttr);

    mMaxImageSize = (int) getResources().getDimension(R.dimen.design_fab_image_size);

    getImpl().setBackgroundDrawable(mBackgroundTint, mBackgroundTintMode, mRippleColor, mBorderWidth);
    getImpl().setElevation(elevation);
    getImpl().setPressedTranslationZ(pressedTranslationZ);
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.DayPickerView.java

public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(SUtils.createThemeWrapper(context, R.attr.sublimePickerStyle, R.style.SublimePickerStyleLight,
            defStyleAttr, R.style.DayPickerViewStyle), attrs);

    context = getContext();/*  w  w  w. j a v a2  s  .  c o  m*/

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

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DayPickerView, defStyleAttr,
            R.style.DayPickerViewStyle);

    final int monthTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spMonthTextAppearance,
            R.style.SPMonthLabelTextAppearance);
    // verified
    final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spWeekDayTextAppearance,
            R.style.SPWeekDayLabelTextAppearance);
    // verified
    final int dayTextAppearanceResId = a.getResourceId(R.styleable.DayPickerView_spDateTextAppearance,
            R.style.SPDayTextAppearance);

    final ColorStateList daySelectorColor = a.getColorStateList(R.styleable.DayPickerView_spDaySelectorColor);

    a.recycle();

    if (Config.DEBUG) {
        Log.i(TAG, "MDayPickerView_spmMonthTextAppearance: " + monthTextAppearanceResId);
        Log.i(TAG, "MDayPickerView_spmWeekDayTextAppearance: " + dayOfWeekTextAppearanceResId);
        Log.i(TAG, "MDayPickerView_spmDateTextAppearance: " + dayTextAppearanceResId);
    }

    // Set up adapter.
    mAdapter = new DayPickerPagerAdapter(context, R.layout.date_picker_month_item, R.id.month_view);
    mAdapter.setMonthTextAppearance(monthTextAppearanceResId);
    mAdapter.setDayOfWeekTextAppearance(dayOfWeekTextAppearanceResId);
    mAdapter.setDayTextAppearance(dayTextAppearanceResId);
    mAdapter.setDaySelectorColor(daySelectorColor);

    final LayoutInflater inflater = LayoutInflater.from(context);

    int layoutIdToUse, viewPagerIdToUse;

    if (getTag() != null && getTag() instanceof String
            && getResources().getString(R.string.recurrence_end_date_picker_tag).equals(getTag())) {
        layoutIdToUse = R.layout.day_picker_content_redp;
        viewPagerIdToUse = R.id.redp_view_pager;
    } else {
        layoutIdToUse = R.layout.day_picker_content_sdp;
        viewPagerIdToUse = R.id.sdp_view_pager;
    }

    inflater.inflate(layoutIdToUse, this, true);

    OnClickListener onClickListener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            final int direction;
            if (v == mPrevButton) {
                direction = -1;
            } else if (v == mNextButton) {
                direction = 1;
            } else {
                return;
            }

            // Animation is expensive for accessibility services since it sends
            // lots of scroll and content change events.
            final boolean animate = !mAccessibilityManager.isEnabled();

            // ViewPager clamps input values, so we don't need to worry
            // about passing invalid indices.
            final int nextItem = mViewPager.getCurrentItem() + direction;
            mViewPager.setCurrentItem(nextItem, animate);
        }
    };

    mPrevButton = (ImageButton) findViewById(R.id.prev);
    mPrevButton.setOnClickListener(onClickListener);

    mNextButton = (ImageButton) findViewById(R.id.next);
    mNextButton.setOnClickListener(onClickListener);

    ViewPager.OnPageChangeListener onPageChangedListener = new ViewPager.OnPageChangeListener() {
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
            final float alpha = Math.abs(0.5f - positionOffset) * 2.0f;
            mPrevButton.setAlpha(alpha);
            mNextButton.setAlpha(alpha);
        }

        @Override
        public void onPageScrollStateChanged(int state) {
        }

        @Override
        public void onPageSelected(int position) {
            updateButtonVisibility(position);
        }
    };

    mViewPager = (DayPickerViewPager) findViewById(viewPagerIdToUse);
    mViewPager.setAdapter(mAdapter);
    mViewPager.addOnPageChangeListener(onPageChangedListener);

    // Proxy the month text color into the previous and next buttons.
    if (monthTextAppearanceResId != 0) {
        final TypedArray ta = context.obtainStyledAttributes(null, ATTRS_TEXT_COLOR, 0,
                monthTextAppearanceResId);
        final ColorStateList monthColor = ta.getColorStateList(0);
        if (monthColor != null) {
            SUtils.setImageTintList(mPrevButton, monthColor);
            SUtils.setImageTintList(mNextButton, monthColor);
        }
        ta.recycle();
    }

    // Proxy selection callbacks to our own listener.
    mAdapter.setDaySelectionEventListener(new DayPickerPagerAdapter.DaySelectionEventListener() {
        @Override
        public void onDaySelected(DayPickerPagerAdapter adapter, Calendar day) {
            if (mProxyDaySelectionEventListener != null) {
                mProxyDaySelectionEventListener.onDaySelected(DayPickerView.this, day);
            }
        }

        @Override
        public void onDateRangeSelectionStarted(@NonNull SelectedDate selectedDate) {
            if (mProxyDaySelectionEventListener != null) {
                mProxyDaySelectionEventListener.onDateRangeSelectionStarted(selectedDate);
            }
        }

        @Override
        public void onDateRangeSelectionEnded(@Nullable SelectedDate selectedDate) {
            if (mProxyDaySelectionEventListener != null) {
                mProxyDaySelectionEventListener.onDateRangeSelectionEnded(selectedDate);
            }
        }

        @Override
        public void onDateRangeSelectionUpdated(@NonNull SelectedDate selectedDate) {
            if (mProxyDaySelectionEventListener != null) {
                mProxyDaySelectionEventListener.onDateRangeSelectionUpdated(selectedDate);
            }
        }
    });
}

From source file:com.android.launcher3.BubbleTextView.java

public BubbleTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mLauncher = Launcher.getLauncher(context);
    DeviceProfile grid = mLauncher.getDeviceProfile();

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BubbleTextView, defStyle, 0);
    mCustomShadowsEnabled = a.getBoolean(R.styleable.BubbleTextView_customShadows, true);
    mLayoutHorizontal = a.getBoolean(R.styleable.BubbleTextView_layoutHorizontal, false);
    mDeferShadowGenerationOnTouch = a.getBoolean(R.styleable.BubbleTextView_deferShadowGeneration, false);

    int display = a.getInteger(R.styleable.BubbleTextView_iconDisplay, DISPLAY_WORKSPACE);
    int defaultIconSize = grid.iconSizePx;
    if (display == DISPLAY_WORKSPACE) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.iconTextSizePx);
    } else if (display == DISPLAY_ALL_APPS) {
        setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
        setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
        defaultIconSize = grid.allAppsIconSizePx;
    } else if (display == DISPLAY_FOLDER) {
        setCompoundDrawablePadding(grid.folderChildDrawablePaddingPx);
    }/* w  w w.  ja va 2s  .  c o m*/
    mCenterVertically = a.getBoolean(R.styleable.BubbleTextView_centerVertically, false);

    if (Utilities.getIconSizePrefEnabled(context) == -1) {
        mIconSize = a.getDimensionPixelSize(R.styleable.BubbleTextView_iconSizeOverride, defaultIconSize);
        Utilities.setIconSizeValue(context, mIconSize);
        a.recycle();
    } else {
        mIconSize = Utilities.getIconSizePrefEnabled(context);
    }

    if (mCustomShadowsEnabled) {
        // Draw the background itself as the parent is drawn twice.
        mBackground = getBackground();
        setBackground(null);

        // Set shadow layer as the larger shadow to that the textView does not clip the shadow.
        float density = getResources().getDisplayMetrics().density;
        setShadowLayer(density * AMBIENT_SHADOW_RADIUS, 0, 0, AMBIENT_SHADOW_COLOR);
    } else {
        mBackground = null;
    }

    mLongPressHelper = new CheckLongPressHelper(this);
    mStylusEventHelper = new StylusEventHelper(new SimpleOnStylusPressListener(this), this);

    mOutlineHelper = HolographicOutlineHelper.obtain(getContext());
    setAccessibilityDelegate(mLauncher.getAccessibilityDelegate());

}

From source file:android.support.v7.internal.widget.ActivityChooserView.java

/**
 * Create a new instance./*  ww  w  . java  2  s.com*/
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.ActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.ActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.ActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(getContext());
    inflater.inflate(R.layout.abc_activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (LinearLayoutCompat) findViewById(R.id.activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.image);

    final FrameLayout expandButton = (FrameLayout) findViewById(R.id.expand_activities_button);
    expandButton.setOnClickListener(mCallbacks);
    expandButton.setOnTouchListener(new ListPopupWindow.ForwardingListener(expandButton) {
        @Override
        public ListPopupWindow getPopup() {
            return getListPopupWindow();
        }

        @Override
        protected boolean onForwardingStarted() {
            showPopup();
            return true;
        }

        @Override
        protected boolean onForwardingStopped() {
            dismissPopup();
            return true;
        }
    });
    mExpandActivityOverflowButton = expandButton;
    mExpandActivityOverflowButtonImage = (ImageView) expandButton.findViewById(R.id.image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abc_config_prefDialogWidth));
}

From source file:com.alimuzaffar.lib.pin.PinEntryEditText.java

private void init(Context context, AttributeSet attrs) {
    float multi = context.getResources().getDisplayMetrics().density;
    mLineStroke = multi * mLineStroke;//from   w w  w  . j av  a 2s.  c o  m
    mLineStrokeSelected = multi * mLineStrokeSelected;
    mSpace = multi * mSpace; //convert to pixels for our density
    mTextBottomPadding = multi * mTextBottomPadding; //convert to pixels for our density

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.PinEntryEditText, 0, 0);
    try {
        TypedValue outValue = new TypedValue();
        ta.getValue(R.styleable.PinEntryEditText_pinAnimationType, outValue);
        mAnimatedType = outValue.data;
        mMask = ta.getString(R.styleable.PinEntryEditText_pinCharacterMask);
        mSingleCharHint = ta.getString(R.styleable.PinEntryEditText_pinRepeatedHint);
        mLineStroke = ta.getDimension(R.styleable.PinEntryEditText_pinLineStroke, mLineStroke);
        mLineStrokeSelected = ta.getDimension(R.styleable.PinEntryEditText_pinLineStrokeSelected,
                mLineStrokeSelected);
        mSpace = ta.getDimension(R.styleable.PinEntryEditText_pinCharacterSpacing, mSpace);
        mTextBottomPadding = ta.getDimension(R.styleable.PinEntryEditText_pinTextBottomPadding,
                mTextBottomPadding);
        mIsDigitSquare = ta.getBoolean(R.styleable.PinEntryEditText_pinBackgroundIsSquare, mIsDigitSquare);
        mPinBackground = ta.getDrawable(R.styleable.PinEntryEditText_pinBackgroundDrawable);
        ColorStateList colors = ta.getColorStateList(R.styleable.PinEntryEditText_pinLineColors);
        if (colors != null) {
            mColorStates = colors;
        }
    } finally {
        ta.recycle();
    }

    mCharPaint = new Paint(getPaint());
    mLastCharPaint = new Paint(getPaint());
    mSingleCharPaint = new Paint(getPaint());
    mLinesPaint = new Paint(getPaint());
    mLinesPaint.setStrokeWidth(mLineStroke);

    TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(R.attr.colorControlActivated, outValue, true);
    int colorSelected = outValue.data;
    mColors[0] = colorSelected;

    int colorFocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[1] = colorFocused;

    int colorUnfocused = isInEditMode() ? Color.GRAY : ContextCompat.getColor(context, R.color.pin_normal);
    mColors[2] = colorUnfocused;

    setBackgroundResource(0);

    mMaxLength = attrs.getAttributeIntValue(XML_NAMESPACE_ANDROID, "maxLength", 4);
    mNumChars = mMaxLength;

    //Disable copy paste
    super.setCustomSelectionActionModeCallback(new ActionMode.Callback() {
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public void onDestroyActionMode(ActionMode mode) {
        }

        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            return false;
        }

        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return false;
        }
    });
    // When tapped, move cursor to end of text.
    super.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            setSelection(getText().length());
            if (mClickListener != null) {
                mClickListener.onClick(v);
            }
        }
    });

    super.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            setSelection(getText().length());
            return true;
        }
    });

    //If input type is password and no mask is set, use a default mask
    if ((getInputType() & InputType.TYPE_TEXT_VARIATION_PASSWORD) == InputType.TYPE_TEXT_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    } else if ((getInputType()
            & InputType.TYPE_NUMBER_VARIATION_PASSWORD) == InputType.TYPE_NUMBER_VARIATION_PASSWORD
            && TextUtils.isEmpty(mMask)) {
        mMask = "\u25CF";
    }

    if (!TextUtils.isEmpty(mMask)) {
        mMaskChars = getMaskChars();
    }

    //Height of the characters, used if there is a background drawable
    getPaint().getTextBounds("|", 0, 1, mTextHeight);

    mAnimate = mAnimatedType > -1;
}

From source file:co.paulburke.android.textviewpager.TextViewPagerIndicator.java

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

    final Resources res = getResources();

    // Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.scroll_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.scroll_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.scroll_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.scroll_indicator_selected_color);

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

    setFades(a.getBoolean(R.styleable.TextViewPagerIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.TextViewPagerIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.TextViewPagerIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.TextViewPagerIndicator_fadeLength, defaultFadeLength));

    Drawable background = a.getDrawable(R.styleable.TextViewPagerIndicator_android_background);
    if (background != null)
        setBackgroundDrawable(background);

    a.recycle();
}

From source file:com.actionbarsherlock.widget.ActivityChooserView.java

/**
 * Create a new instance.//from   ww w . j av  a  2 s.c o  m
 *
 * @param context The application environment.
 * @param attrs A collection of attributes.
 * @param defStyle The default style to apply to this view.
 */
public ActivityChooserView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mContext = context;

    TypedArray attributesArray = context.obtainStyledAttributes(attrs, R.styleable.SherlockActivityChooserView,
            defStyle, 0);

    mInitialActivityCount = attributesArray.getInt(R.styleable.SherlockActivityChooserView_initialActivityCount,
            ActivityChooserViewAdapter.MAX_ACTIVITY_COUNT_DEFAULT);

    Drawable expandActivityOverflowButtonDrawable = attributesArray
            .getDrawable(R.styleable.SherlockActivityChooserView_expandActivityOverflowButtonDrawable);

    attributesArray.recycle();

    LayoutInflater inflater = LayoutInflater.from(mContext);
    inflater.inflate(R.layout.abs__activity_chooser_view, this, true);

    mCallbacks = new Callbacks();

    mActivityChooserContent = (IcsLinearLayout) findViewById(R.id.abs__activity_chooser_view_content);
    mActivityChooserContentBackground = mActivityChooserContent.getBackground();

    mDefaultActivityButton = (FrameLayout) findViewById(R.id.abs__default_activity_button);
    mDefaultActivityButton.setOnClickListener(mCallbacks);
    mDefaultActivityButton.setOnLongClickListener(mCallbacks);
    mDefaultActivityButtonImage = (ImageView) mDefaultActivityButton.findViewById(R.id.abs__image);

    mExpandActivityOverflowButton = (FrameLayout) findViewById(R.id.abs__expand_activities_button);
    mExpandActivityOverflowButton.setOnClickListener(mCallbacks);
    mExpandActivityOverflowButtonImage = (ImageView) mExpandActivityOverflowButton
            .findViewById(R.id.abs__image);
    mExpandActivityOverflowButtonImage.setImageDrawable(expandActivityOverflowButtonDrawable);

    mAdapter = new ActivityChooserViewAdapter();
    mAdapter.registerDataSetObserver(new DataSetObserver() {
        @Override
        public void onChanged() {
            super.onChanged();
            updateAppearance();
        }
    });

    Resources resources = context.getResources();
    mListPopupMaxWidth = Math.max(resources.getDisplayMetrics().widthPixels / 2,
            resources.getDimensionPixelSize(R.dimen.abs__config_prefDialogWidth));
}

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();/*ww  w . ja v a  2 s . c o  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:cn.smilecity.viewpagerindicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;// ww w. j  a  v  a2s. co  m

    final Resources res = getResources();

    // Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.bg_title);

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

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

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

    a.recycle();

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

From source file:app.viewpagerindicator.UnderlinePageIndicator.java

public UnderlinePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//from w ww . j  av a2s  .c  om

    final Resources res = getResources();

    //Load defaults from resources
    final boolean defaultFades = res.getBoolean(R.bool.default_underline_indicator_fades);
    final int defaultFadeDelay = res.getInteger(R.integer.default_underline_indicator_fade_delay);
    final int defaultFadeLength = res.getInteger(R.integer.default_underline_indicator_fade_length);
    final int defaultSelectedColor = res.getColor(R.color.default_underline_indicator_selected_color);

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

    setFades(a.getBoolean(R.styleable.UnderlinePageIndicator_fades, defaultFades));
    setSelectedColor(a.getColor(R.styleable.UnderlinePageIndicator_selectedColor, defaultSelectedColor));
    setFadeDelay(a.getInteger(R.styleable.UnderlinePageIndicator_fadeDelay, defaultFadeDelay));
    setFadeLength(a.getInteger(R.styleable.UnderlinePageIndicator_fadeLength, defaultFadeLength));

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

    a.recycle();

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