Example usage for android.content.res TypedArray hasValue

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

Introduction

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

Prototype

public boolean hasValue(@StyleableRes int index) 

Source Link

Document

Determines whether there is an attribute at index.

Usage

From source file:com.actionbarsherlock.internal.ActionBarSherlockCompat.java

private ViewGroup generateLayout() {
    if (DEBUG)//from w  w  w. j  a  v  a2  s  .c om
        Log.d(TAG, "[generateLayout]");

    // Apply data from current theme.

    TypedArray a = mActivity.getTheme().obtainStyledAttributes(R.styleable.SherlockTheme);

    mIsFloating = a.getBoolean(R.styleable.SherlockTheme_android_windowIsFloating, false);

    if (!a.hasValue(R.styleable.SherlockTheme_windowActionBar)) {
        throw new IllegalStateException(
                "You must use Theme.Sherlock, Theme.Sherlock.Light, Theme.Sherlock.Light.DarkActionBar, or a derivative.");
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowNoTitle, false)) {
        requestFeature(Window.FEATURE_NO_TITLE);
    } else if (a.getBoolean(R.styleable.SherlockTheme_windowActionBar, false)) {
        // Don't allow an action bar if there is no title.
        requestFeature(Window.FEATURE_ACTION_BAR);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionBarOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
    }

    if (a.getBoolean(R.styleable.SherlockTheme_windowActionModeOverlay, false)) {
        requestFeature(Window.FEATURE_ACTION_MODE_OVERLAY);
    }

    a.recycle();

    int layoutResource;
    if (!hasFeature(Window.FEATURE_NO_TITLE)) {
        if (mIsFloating) {
            //Trash original dialog LinearLayout
            mDecor = (ViewGroup) mDecor.getParent();
            mDecor.removeAllViews();

            layoutResource = R.layout.abs__dialog_title_holo;
        } else {
            if (hasFeature(Window.FEATURE_ACTION_BAR_OVERLAY)) {
                layoutResource = R.layout.abs__screen_action_bar_overlay;
            } else {
                layoutResource = R.layout.abs__screen_action_bar;
            }
        }
    } else if (hasFeature(Window.FEATURE_ACTION_MODE_OVERLAY) && !hasFeature(Window.FEATURE_NO_TITLE)) {
        layoutResource = R.layout.abs__screen_simple_overlay_action_mode;
    } else {
        layoutResource = R.layout.abs__screen_simple;
    }

    if (DEBUG)
        Log.d(TAG, "[generateLayout] using screen XML " + mActivity.getResources().getString(layoutResource));
    View in = mActivity.getLayoutInflater().inflate(layoutResource, null);
    mDecor.addView(in, new ViewGroup.LayoutParams(MATCH_PARENT, MATCH_PARENT));

    ViewGroup contentParent = (ViewGroup) mDecor.findViewById(R.id.abs__content);
    if (contentParent == null) {
        throw new RuntimeException("Couldn't find content container view");
    }

    //Make our new child the true content view (for fragments). VERY VOLATILE!
    mDecor.setId(View.NO_ID);
    contentParent.setId(android.R.id.content);

    if (hasFeature(Window.FEATURE_INDETERMINATE_PROGRESS)) {
        IcsProgressBar progress = getCircularProgressBar(false);
        if (progress != null) {
            progress.setIndeterminate(true);
        }
    }

    return contentParent;
}

From source file:ticwear.design.widget.StretchingLayout.java

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

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

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

    mCollapsingTextHelper// ww  w .  ja va 2s .  co  m
            .setExpandedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_expandedTitleGravity,
                    GravityCompat.START | Gravity.BOTTOM));
    mCollapsingTextHelper
            .setCollapsedTextGravity(a.getInt(R.styleable.CollapsingToolbarLayout_tic_collapsedTitleGravity,
                    GravityCompat.START | Gravity.CENTER_VERTICAL));

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

    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart)) {
        mExpandedMarginStart = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginStart, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd)) {
        mExpandedMarginEnd = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginEnd, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop)) {
        mExpandedMarginTop = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginTop, 0);
    }
    if (a.hasValue(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom)) {
        mExpandedMarginBottom = a
                .getDimensionPixelSize(R.styleable.CollapsingToolbarLayout_tic_expandedTitleMarginBottom, 0);
    }

    mCollapsingTitleEnabled = a.getBoolean(R.styleable.CollapsingToolbarLayout_tic_titleEnabled, true);
    setTitle(a.getText(R.styleable.CollapsingToolbarLayout_android_title));

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

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

    a.recycle();

    setWillNotDraw(false);

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        @Override
        public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
            if (isShown()) {
                mLastInsets = insets;
                requestLayout();
                return insets.consumeSystemWindowInsets();
            } else {
                return insets;
            }
        }
    });
}

From source file:am.widget.indicatortabstrip.IndicatorTabStrip.java

public IndicatorTabStrip(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    setItemClickable(true);/*from ww  w .  ja v a 2 s. c  om*/
    setClickSmoothScroll(true);
    final float density = getResources().getDisplayMetrics().density;
    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
    mTextPaint.setTextAlign(Align.CENTER);
    if (Build.VERSION.SDK_INT > 4) {
        updateTextPaintDensity();
    }
    mTagLocation = new TagLocation(TagLocation.LOCATION_EDGE);
    final TypedArray a = context.obtainStyledAttributes(attrs, ATTRS);
    int n = a.getIndexCount();
    int textSize = (int) (DEFAULT_TEXT_SIZE * density);
    ColorStateList textColors = null;
    Drawable divider = null;
    for (int i = 0; i < n; i++) {
        int attr = a.getIndex(i);
        switch (attr) {
        case 0:
            textSize = a.getDimensionPixelSize(attr, textSize);
            break;
        case 1:
            textColors = a.getColorStateList(attr);
            break;
        case 2:
            divider = a.getDrawable(attr);
            break;
        }
    }
    a.recycle();
    float scale = 1;
    Drawable itemBackground = null;
    ColorStateList gradient = null;
    Drawable indicator = null;
    int indicatorWidthMode = INDICATOR_WIDTH_MODE_SET;
    int indicatorPadding = 0;
    int indicatorWidth = INDICATOR_WIDTH_BY_DRAWABLE;
    int indicatorHeight = INDICATOR_HEIGHT_BY_DRAWABLE;
    Drawable interval = null;
    int minItemWidth = (int) (DEFAULT_ITEM_WIDTH * density);
    int minItemHeight = (int) (DEFAULT_ITEM_HEIGHT * density);
    int tagTextSize = (int) (DEFAULT_TAG_TEXT_SIZE * density);
    int tagTextColor = DEFAULT_TAG_TEXT_COLOR;
    Drawable tagBackground = getDefaultTagBackground();
    int tagMinSizeMode = TAG_MIN_SIZE_MODE_HAS_TEXT;
    int tagMinWidth = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagMinHeight = (int) (DEFAULT_TAG_MIN_SIZE * density);
    int tagPaddingLeft = 0;
    int tagPaddingTop = 0;
    int tagPaddingRight = 0;
    int tagPaddingBottom = 0;
    int tagMarginLeft = 0;
    int tagMarginTop = 0;
    int tagMarginRight = 0;
    int tagMarginBottom = 0;
    TypedArray custom = context.obtainStyledAttributes(attrs, R.styleable.IndicatorTabStrip);
    textSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTextSize, textSize);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTextColor))
        textColors = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsTextColor);
    scale = custom.getFloat(R.styleable.IndicatorTabStrip_ttsTextScale, scale);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsBackground))
        itemBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsBackground);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsGradient))
        gradient = custom.getColorStateList(R.styleable.IndicatorTabStrip_ttsGradient);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsDivider))
        divider = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsDivider);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsIndicator))
        indicator = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsIndicator);
    indicatorWidthMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsIndicatorWidthMode, indicatorWidthMode);
    indicatorPadding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorPadding,
            indicatorPadding);
    indicatorWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorWidth,
            indicatorWidth);
    indicatorHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsIndicatorHeight,
            indicatorHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsInterval))
        interval = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsInterval);
    minItemWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemWidth, minItemWidth);
    minItemHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsMinItemHeight,
            minItemHeight);
    tagTextSize = custom.getDimensionPixelSize(R.styleable.IndicatorTabStrip_ttsTagTextSize, tagTextSize);
    tagTextColor = custom.getColor(R.styleable.IndicatorTabStrip_ttsTagTextColor, tagTextColor);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagBackground))
        tagBackground = custom.getDrawable(R.styleable.IndicatorTabStrip_ttsTagBackground);
    tagMinSizeMode = custom.getInt(R.styleable.IndicatorTabStrip_ttsTagMinSizeMode, tagMinSizeMode);
    tagMinWidth = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinWidth, tagMinWidth);
    tagMinHeight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMinHeight, tagMinHeight);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagPadding)) {
        final int padding = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPadding, 0);
        tagPaddingLeft = padding;
        tagPaddingTop = padding;
        tagPaddingRight = padding;
        tagPaddingBottom = padding;
    }
    tagPaddingLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingLeft,
            tagPaddingLeft);
    tagPaddingTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingTop,
            tagPaddingTop);
    tagPaddingRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingRight,
            tagPaddingRight);
    tagPaddingBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagPaddingBottom,
            tagPaddingBottom);
    if (custom.hasValue(R.styleable.IndicatorTabStrip_ttsTagMargin)) {
        final int margin = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMargin, 0);
        tagMarginLeft = margin;
        tagMarginTop = margin;
        tagMarginRight = margin;
        tagMarginBottom = margin;
    }
    tagMarginLeft = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginLeft,
            tagMarginLeft);
    tagMarginTop = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginTop, tagMarginTop);
    tagMarginRight = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginRight,
            tagMarginRight);
    tagMarginBottom = custom.getDimensionPixelOffset(R.styleable.IndicatorTabStrip_ttsTagMarginBottom,
            tagMarginBottom);
    custom.recycle();
    setTextSize(textSize);
    if (textColors != null) {
        setTextColor(textColors);
    } else {
        setTextColor(DEFAULT_TEXT_COLOR);
    }
    setTextScale(scale);
    setItemBackground(itemBackground);
    setGradient(gradient);
    setDivider(divider);
    setIndicator(indicator);
    setIndicatorWidthMode(indicatorWidthMode);
    setIndicatorPadding(indicatorPadding);
    setIndicatorWidth(indicatorWidth);
    setIndicatorHeight(indicatorHeight);
    setInterval(interval);
    setMinItemWidth(minItemWidth);
    setMinItemHeight(minItemHeight);
    setTagTextSize(tagTextSize);
    setTagTextColor(tagTextColor);
    setTagBackground(tagBackground);
    setTagMinSizeMode(tagMinSizeMode);
    setTagMinWidth(tagMinWidth);
    setTagMinHeight(tagMinHeight);
    setTagPadding(tagPaddingLeft, tagPaddingTop, tagPaddingRight, tagPaddingBottom);
    setTagMargin(tagMarginLeft, tagMarginTop, tagMarginRight, tagMarginBottom);
}

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

public AppBarLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);/*from w  w  w .ja  va2s  .c  o m*/

    ThemeUtils.checkAppCompatTheme(context);

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

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

    mListeners = new ArrayList<>();

    ViewCompat.setElevation(this, mTargetElevation);

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

From source file:jp.tkgktyk.xposed.forcetouchdetector.app.util.fab.AppBarLayout.java

public AppBarLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    setOrientation(VERTICAL);/*from ww w.j a  v a  2 s. co  m*/

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

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

    mListeners = new ArrayList<>();

    ViewCompat.setElevation(this, mTargetElevation);

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

From source file:com.handmark.pulltorefresh.library.PullToRefreshListView.java

@Override
protected void handleStyledAttributes(TypedArray a) {
    super.handleStyledAttributes(a);

    mListViewExtrasEnabled = a.getBoolean(R.styleable.PullToRefresh_ptrListViewExtrasEnabled, true);

    if (mListViewExtrasEnabled) {
        final FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
                FrameLayout.LayoutParams.WRAP_CONTENT, Gravity.CENTER_HORIZONTAL);

        // Create Loading Views ready for use later
        FrameLayout frame = new FrameLayout(getContext());
        mHeaderLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_START, a);
        mHeaderLoadingView.setVisibility(View.GONE);
        frame.addView(mHeaderLoadingView, lp);
        mRefreshableView.addHeaderView(frame, null, false);

        mLvFooterLoadingFrame = new FrameLayout(getContext());
        mFooterLoadingView = createLoadingLayout(getContext(), Mode.PULL_FROM_END, a);
        mFooterLoadingView.setVisibility(View.GONE);
        mLvFooterLoadingFrame.addView(mFooterLoadingView, lp);

        /**// ww  w.j a  va  2  s  .c  o m
         * If the value for Scrolling While Refreshing hasn't been
         * explicitly set via XML, enable Scrolling While Refreshing.
         */
        if (!a.hasValue(R.styleable.PullToRefresh_ptrScrollingWhileRefreshingEnabled)) {
            setScrollingWhileRefreshingEnabled(true);
        }
    }
}

From source file:com.albedinsky.android.ui.widget.BaseProgressBar.java

/**
 * Called from the constructor to process tint values for this view.
 *
 * @param context    The context passed to constructor.
 * @param typedArray TypedArray obtained for styleable attributes specific for this view.
 *///  w  ww.ja  v  a 2 s  .c om
@SuppressWarnings("All")
private void processTintValues(Context context, TypedArray typedArray) {
    this.ensureTintInfo();
    if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiProgressTint)) {
        mTintInfo.progressTintList = typedArray.getColorStateList(R.styleable.Ui_ProgressBar_uiProgressTint);
    }
    if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiIndeterminateTint)) {
        mTintInfo.indeterminateTintList = typedArray
                .getColorStateList(R.styleable.Ui_ProgressBar_uiIndeterminateTint);
    }
    if (typedArray.hasValue(R.styleable.Ui_ProgressBar_uiProgressBackgroundTint)) {
        mTintInfo.backgroundTintList = typedArray
                .getColorStateList(R.styleable.Ui_ProgressBar_uiProgressBackgroundTint);
    }
    mTintInfo.progressTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_ProgressBar_uiProgressTintMode, 0), PorterDuff.Mode.SRC_IN);
    mTintInfo.indeterminateTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_ProgressBar_uiIndeterminateTintMode, 0), PorterDuff.Mode.SRC_IN);
    mTintInfo.backgroundTintMode = TintManager.parseTintMode(
            typedArray.getInt(R.styleable.Ui_ProgressBar_uiProgressBackgroundTintMode, 0),
            PorterDuff.Mode.SRC_IN);
    // If there is no tint mode specified within style/xml do not tint at all.
    if (mTintInfo.backgroundTintMode == null)
        mTintInfo.backgroundTintList = null;
    if (mTintInfo.progressTintMode == null)
        mTintInfo.progressTintList = null;
    if (mTintInfo.indeterminateTintMode == null)
        mTintInfo.indeterminateTintList = null;
    mTintInfo.hasBackgroundTintList = mTintInfo.backgroundTintList != null;
    mTintInfo.hasBackgroundTinMode = mTintInfo.backgroundTintMode != null;
    mTintInfo.hasProgressTintList = mTintInfo.progressTintList != null;
    mTintInfo.hasProgressTintMode = mTintInfo.progressTintMode != null;
    mTintInfo.hasIndeterminateTintList = mTintInfo.indeterminateTintList != null;
    mTintInfo.hasIndeterminateTintMode = mTintInfo.indeterminateTintMode != null;
}

From source file:com.tr4android.support.extension.picker.date.DayPickerView.java

public DayPickerView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

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

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DatePickerDialog, defStyleAttr, 0); //TODO: add default style res

    final int firstDayOfWeek = a.getInt(R.styleable.DatePickerDialog_firstDayOfWeek,
            Calendar.getInstance(Locale.getDefault()).getFirstDayOfWeek());

    final String minDate = a.getString(R.styleable.DatePickerDialog_minDate);
    final String maxDate = a.getString(R.styleable.DatePickerDialog_maxDate);

    final int monthTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_monthTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Month);
    final int dayOfWeekTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_weekDayTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_DayOfWeek);
    final int dayTextAppearanceResId = a.getResourceId(R.styleable.DatePickerDialog_dateTextAppearance,
            R.style.TextAppearance_Material_Widget_Calendar_Day);

    // Set up day selected color, if available.
    final ColorStateList daySelectorColor;
    if (a.hasValue(R.styleable.DatePickerDialog_daySelectorColor)) {
        daySelectorColor = a.getColorStateList(R.styleable.DatePickerDialog_daySelectorColor);
    } else {// w  w w  .  j a va2s.c  om
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated });
        daySelectorColor = ta.getColorStateList(0);
        ta.recycle();
    }

    // Set up day highlight color, if available.
    final ColorStateList dayHighlightColor;
    if (a.hasValue(R.styleable.DatePickerDialog_dayHighlightColor)) {
        dayHighlightColor = a.getColorStateList(R.styleable.DatePickerDialog_dayHighlightColor);
    } else {
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlHighlight });
        dayHighlightColor = ta.getColorStateList(0);
        ta.recycle();
    }

    a.recycle();

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

    final LayoutInflater inflater = LayoutInflater.from(context);
    final ViewGroup content = (ViewGroup) inflater.inflate(DEFAULT_LAYOUT, this, false);

    // Transfer all children from content to here.
    while (content.getChildCount() > 0) {
        final View child = content.getChildAt(0);
        content.removeViewAt(0);
        addView(child);
    }

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

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

    mViewPager = (ViewPager) findViewById(R.id.day_picker_view_pager);
    mViewPager.setAdapter(mAdapter);
    mViewPager.addOnPageChangeListener(mOnPageChangedListener);

    // Set up background of the previous and next buttons.
    ViewCompatUtils.setBackground(mPrevButton, PickerThemeUtils.getNavButtonBackground(context));
    ViewCompatUtils.setBackground(mNextButton, PickerThemeUtils.getNavButtonBackground(context));

    // Set up min and max dates.
    final Calendar tempDate = Calendar.getInstance();
    if (!parseDate(minDate, tempDate)) {
        tempDate.set(DEFAULT_START_YEAR, Calendar.JANUARY, 1);
    }
    final long minDateMillis = tempDate.getTimeInMillis();

    if (!parseDate(maxDate, tempDate)) {
        tempDate.set(DEFAULT_END_YEAR, Calendar.DECEMBER, 31);
    }
    final long maxDateMillis = tempDate.getTimeInMillis();

    if (maxDateMillis < minDateMillis) {
        throw new IllegalArgumentException("maxDate must be >= minDate");
    }

    final long setDateMillis = MathUtils.constrain(System.currentTimeMillis(), minDateMillis, maxDateMillis);

    setFirstDayOfWeek(firstDayOfWeek);
    setMinDate(minDateMillis);
    setMaxDate(maxDateMillis);
    setDate(setDateMillis, false);

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

From source file:nuclei.ui.view.ButtonBarView.java

private void init(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ButtonBarView, defStyleAttr,
            defStyleRes);//from   w w w .  jav  a2s  .  c  o m

    final boolean bottom = a.getBoolean(R.styleable.ButtonBarView_bottom, false);

    final int layout = a.getResourceId(R.styleable.ButtonBarView_control_layout,
            bottom ? R.layout.cyto_view_button_bar_bottom : R.layout.cyto_view_button_bar);

    final View view = LayoutInflater.from(context).inflate(layout, this, false);
    addView(view);

    mButtons = (LinearLayout) view.findViewById(R.id.buttons);

    mOrientation = a.getInt(R.styleable.ButtonBarView_control_orientation, 1);
    switch (mOrientation) {
    case 1:
        mButtons.setOrientation(LinearLayout.HORIZONTAL);
        break;
    case 2:
        mButtons.setOrientation(LinearLayout.VERTICAL);
        break;
    }

    mSelectedTint = a.getColor(R.styleable.ButtonBarView_selected_color,
            ResourcesCompat.getColor(getResources(), R.color.black, context.getTheme()));
    mUnselectedTint = a.getColor(R.styleable.ButtonBarView_unselected_color,
            ResourcesCompat.getColor(getResources(), R.color.grey, context.getTheme()));

    if (a.hasValue(R.styleable.ButtonBarView_buttons_background)) {
        final int color = a.getColor(R.styleable.ButtonBarView_buttons_background, Color.WHITE);
        View v = view.findViewById(R.id.buttons_container);
        if (v != null)
            v.setBackgroundColor(color);
        else
            mButtons.setBackgroundColor(color);
    }

    a.recycle();
}

From source file:com.commonsware.cwac.crossport.design.widget.AppBarLayout.java

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

    // ThemeUtils.checkAppCompatTheme(context);

    if (Build.VERSION.SDK_INT >= 21) {
        // Use the bounds view outline provider so that we cast a shadow, even without a
        // background
        ViewUtilsLollipop.setBoundsViewOutlineProvider(this);

        // If we're running on API 21+, we should reset any state list animator from our
        // default style
        ViewUtilsLollipop.setStateListAnimatorFromAttrs(this, attrs, 0, R.style.Widget_Design_AppBarLayout);
    }

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AppBarLayout, 0,
            R.style.Widget_Design_AppBarLayout);
    ViewCompat.setBackground(this, a.getDrawable(R.styleable.AppBarLayout_android_background));
    if (a.hasValue(R.styleable.AppBarLayout_expanded)) {
        setExpanded(a.getBoolean(R.styleable.AppBarLayout_expanded, false), false, false);
    }
    /*
            if (Build.VERSION.SDK_INT >= 21 && a.hasValue(R.styleable.AppBarLayout_elevation)) {
          ViewUtilsLollipop.setDefaultAppBarLayoutStateListAnimator(
            this, a.getDimensionPixelSize(R.styleable.AppBarLayout_elevation, 0));
            }
    */
    /*
            if (Build.VERSION.SDK_INT >= 26) {
    // In O+, we have these values set in the style. Since there is no defStyleAttr for
    // AppBarLayout at the AppCompat level, check for these attributes here.
    if (a.hasValue(R.styleable.AppBarLayout_android_keyboardNavigationCluster)) {
        this.setKeyboardNavigationCluster(a.getBoolean(
                R.styleable.AppBarLayout_android_keyboardNavigationCluster, false));
    }
    if (a.hasValue(R.styleable.AppBarLayout_android_touchscreenBlocksFocus)) {
        this.setTouchscreenBlocksFocus(a.getBoolean(
                R.styleable.AppBarLayout_android_touchscreenBlocksFocus, false));
    }
        }
    */
    a.recycle();

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