Example usage for android.content.res TypedArray getBoolean

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

Introduction

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

Prototype

public boolean getBoolean(@StyleableRes int index, boolean defValue) 

Source Link

Document

Retrieve the boolean value for the attribute at index.

Usage

From source file:com.example.xusoku.dragtopviewdemo.DragTopLayout.java

private void init(AttributeSet attrs) {
    dragHelper = ViewDragHelper.create(this, 1.0f, callback);

    // init from attrs
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.DragTopLayout);
    setCollapseOffset(a.getDimensionPixelSize(R.styleable.DragTopLayout_dtlCollapseOffset, collapseOffset));
    overDrag = a.getBoolean(R.styleable.DragTopLayout_dtlOverDrag, overDrag);
    dragContentViewId = a.getResourceId(R.styleable.DragTopLayout_dtlDragContentView, -1);
    topViewId = a.getResourceId(R.styleable.DragTopLayout_dtlTopView, -1);
    initOpen(a.getBoolean(R.styleable.DragTopLayout_dtlOpen, true));
    captureTop = a.getBoolean(R.styleable.DragTopLayout_dtlCaptureTop, true);
    a.recycle();/*from w  w  w  . ja  v a  2  s .c om*/
}

From source file:android.support.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *///www.j av a 2s . c  om
public DrawerArrowDrawable(Context context) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.MITER);
    mPaint.setStrokeCap(Paint.Cap.BUTT);
    mPaint.setAntiAlias(true);

    final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_AppCompat_DrawerArrowToggle);

    setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
    setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0));
    setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true));
    // round this because having this floating may cause bad measurements
    setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0)));

    mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    // round this because having this floating may cause bad measurements
    mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0));
    // round this because having this floating may cause bad measurements
    mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0));
    mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0);
    a.recycle();
}

From source file:com.commonsware.cwac.crossport.v7.graphics.drawable.DrawerArrowDrawable.java

/**
 * @param context used to get the configuration for the drawable from
 *//*w ww .  j  a  v  a  2  s. co m*/
public DrawerArrowDrawable(Context context) {
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeJoin(Paint.Join.MITER);
    mPaint.setStrokeCap(Paint.Cap.BUTT);
    mPaint.setAntiAlias(true);

    final TypedArray a = context.getTheme().obtainStyledAttributes(null, R.styleable.DrawerArrowToggle,
            R.attr.drawerArrowStyle, R.style.Base_Widget_Material_DrawerArrowToggle);

    setColor(a.getColor(R.styleable.DrawerArrowToggle_color, 0));
    setBarThickness(a.getDimension(R.styleable.DrawerArrowToggle_thickness, 0));
    setSpinEnabled(a.getBoolean(R.styleable.DrawerArrowToggle_spinBars, true));
    // round this because having this floating may cause bad measurements
    setGapSize(Math.round(a.getDimension(R.styleable.DrawerArrowToggle_gapBetweenBars, 0)));

    mSize = a.getDimensionPixelSize(R.styleable.DrawerArrowToggle_drawableSize, 0);
    // round this because having this floating may cause bad measurements
    mBarLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_barLength, 0));
    // round this because having this floating may cause bad measurements
    mArrowHeadLength = Math.round(a.getDimension(R.styleable.DrawerArrowToggle_arrowHeadLength, 0));
    mArrowShaftLength = a.getDimension(R.styleable.DrawerArrowToggle_arrowShaftLength, 0);
    a.recycle();
}

From source file:com.android.inputmethod.keyboard.emoji.EmojiPalettesView.java

public EmojiPalettesView(final Context context, final AttributeSet attrs, final int defStyle) {
    super(context, attrs, defStyle);
    final TypedArray keyboardViewAttr = context.obtainStyledAttributes(attrs, R.styleable.KeyboardView,
            defStyle, R.style.KeyboardView);
    final int keyBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_keyBackground, 0);
    mFunctionalKeyBackgroundId = keyboardViewAttr
            .getResourceId(R.styleable.KeyboardView_functionalKeyBackground, keyBackgroundId);
    mSpacebarBackgroundId = keyboardViewAttr.getResourceId(R.styleable.KeyboardView_spacebarBackground,
            keyBackgroundId);/* w w  w .j  av a 2s  . c o  m*/
    keyboardViewAttr.recycle();
    final KeyboardLayoutSet.Builder builder = new KeyboardLayoutSet.Builder(context, null /* editorInfo */);
    final Resources res = context.getResources();
    mEmojiLayoutParams = new EmojiLayoutParams(res);
    builder.setSubtype(RichInputMethodSubtype.getEmojiSubtype());
    builder.setKeyboardGeometry(ResourceUtils.getDefaultKeyboardWidth(res),
            mEmojiLayoutParams.mEmojiKeyboardHeight);
    final KeyboardLayoutSet layoutSet = builder.build();
    final TypedArray emojiPalettesViewAttr = context.obtainStyledAttributes(attrs,
            R.styleable.EmojiPalettesView, defStyle, R.style.EmojiPalettesView);
    mEmojiCategory = new EmojiCategory(PreferenceManager.getDefaultSharedPreferences(context), res, layoutSet,
            emojiPalettesViewAttr);
    mCategoryIndicatorEnabled = emojiPalettesViewAttr
            .getBoolean(R.styleable.EmojiPalettesView_categoryIndicatorEnabled, false);
    mCategoryIndicatorDrawableResId = emojiPalettesViewAttr
            .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorDrawable, 0);
    mCategoryIndicatorBackgroundResId = emojiPalettesViewAttr
            .getResourceId(R.styleable.EmojiPalettesView_categoryIndicatorBackground, 0);
    mCategoryPageIndicatorColor = emojiPalettesViewAttr
            .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorColor, 0);
    mCategoryPageIndicatorBackground = emojiPalettesViewAttr
            .getColor(R.styleable.EmojiPalettesView_categoryPageIndicatorBackground, 0);
    emojiPalettesViewAttr.recycle();
    mDeleteKeyOnTouchListener = new DeleteKeyOnTouchListener();
}

From source file:com.blue.sky.control.CirclePageIndicator.java

@SuppressWarnings("deprecation")
public CirclePageIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from w w  w .  j a v  a2  s . c o  m*/

    // Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);
    final float defaultPadding = res.getDimension(R.dimen.default_circle_indicator_padding);
    defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);

    // Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, Styleable.CirclePageIndicator, defStyle, 0);

    indicateCircleType = a.getInt(Styleable.CirclePageIndicator_unIndicateCircleType, 0);
    mCentered = a.getBoolean(Styleable.CirclePageIndicator_centered, defaultCentered);
    mOrientation = a.getInt(Styleable.CirclePageIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(Styleable.CirclePageIndicator_pageColor, defaultPageColor));
    if (indicateCircleType == 0) {
        mPaintStroke.setStyle(Style.STROKE);
    } else if (indicateCircleType == 1) {
        mPaintStroke.setStyle(Style.FILL);
    }
    mPaintStroke.setColor(a.getColor(Styleable.CirclePageIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(Styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(Styleable.CirclePageIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(Styleable.CirclePageIndicator_radius, defaultRadius);
    padding = a.getDimension(Styleable.CirclePageIndicator_padding, defaultPadding);
    mSnap = a.getBoolean(Styleable.CirclePageIndicator_snap, defaultSnap);
    Drawable background = a.getDrawable(Styleable.CirclePageIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }

    a.recycle();

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

From source file:com.chibatching.imgindicatortab.ImgIndicatorTab.java

public ImgIndicatorTab(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode()) {
        return;/*ww w.java 2  s.  c o m*/
    }

    // Load default value
    float defaultTextSize = getResources().getDimension(R.dimen.iit_default_text_size);
    int defaultSelectedColor = getResources().getColor(R.color.iit_default_selected_text_color);
    int defaultDeselectedColor = getResources().getColor(R.color.iit_default_deselected_text_color);
    boolean defaultFitIndicator = getResources().getBoolean(R.bool.iit_default_fit_indicator_with_tab);

    // Load style attributes
    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ImgIndicatorTab, defStyle, 0);

    setSelectedTextColor(ta.getColor(R.styleable.ImgIndicatorTab_selectedTextColor, defaultSelectedColor));
    setDeselectedTextColor(
            ta.getColor(R.styleable.ImgIndicatorTab_deselectedTextColor, defaultDeselectedColor));
    setIndicatorDrawable(ta.getDrawable(R.styleable.ImgIndicatorTab_indicatorDrawable));
    setTextSize(ta.getDimension(R.styleable.ImgIndicatorTab_android_textSize, defaultTextSize));
    setFitIndicator(ta.getBoolean(R.styleable.ImgIndicatorTab_fitIndicatorWithTabWidth, defaultFitIndicator));

    int background = ta.getResourceId(R.styleable.ImgIndicatorTab_android_background, 0);
    if (background != 0) {
        setBackgroundResource(background);
    }

    ta.recycle();
}

From source file:com.artemchep.horario.ui.fragments.master.LessonsFragment.java

@Override
protected void setupToolbar() {
    super.setupToolbar();
    CustomAppBar appBar = getMainActivity().mAppBar;
    appBar.setTitle(getString(R.string.nav_lessons));

    Toolbar toolbar = appBar.getToolbarSpecific();
    toolbar.inflateMenu(R.menu.master_lessons_week);
    toolbar.setOnMenuItemClickListener(this);

    // Load week icon
    TypedArray a = getActivity().getTheme()
            .obtainStyledAttributes(new int[] { R.attr.icon_calendar_empty_grey, R.attr.is_dark_theme });
    int iconDrawableRes = a.getResourceId(0, 0);
    boolean isDarkTheme = a.getBoolean(1, false);
    a.recycle();/*from   w  w w  .  j  a  v  a2 s. c o m*/

    float density = getResources().getDisplayMetrics().density;
    mWeekDrawable = new TextDrawable();
    mWeekDrawable.setTranslationY(density * 2);
    mWeekDrawable.setTextSize(density * 10);
    mWeekDrawable.setColor(isDarkTheme ? Color.WHITE : Color.GRAY);
    mWeekCompositeDrawable = new LayerDrawable(
            new Drawable[] { ContextCompat.getDrawable(getContext(), iconDrawableRes), mWeekDrawable });

    Menu menu = toolbar.getMenu();
    mWeekMenuItem = menu.findItem(R.id.action_switch_week);
    mWeekMenuItem.setIcon(mWeekCompositeDrawable);
    mWeekMenuItem.setVisible(mWeekCycle > 1);
    updateWeekNumberMenuItemText();
}

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  va2 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:com.android.andryyu.lifehelper.widget.RippleView.java

/**
 * Method that initializes all fields and sets listeners
 *
 * @param context Context used to create this view
 * @param attrs   Attribute used to initialize fields
 *///from w  ww  .j a va2s  .c  o  m
private void init(final Context context, final AttributeSet attrs) {
    if (isInEditMode())
        return;

    final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleView);
    rippleColor = typedArray.getColor(R.styleable.RippleView_rv_color, Color.parseColor("#33626262"));
    rippleType = typedArray.getInt(R.styleable.RippleView_rv_type, 0);
    hasToZoom = typedArray.getBoolean(R.styleable.RippleView_rv_zoom, false);
    isCentered = typedArray.getBoolean(R.styleable.RippleView_rv_centered, false);
    rippleDuration = typedArray.getInteger(R.styleable.RippleView_rv_rippleDuration, rippleDuration);
    frameRate = typedArray.getInteger(R.styleable.RippleView_rv_framerate, frameRate);
    rippleAlpha = typedArray.getInteger(R.styleable.RippleView_rv_alpha, rippleAlpha);
    ripplePadding = typedArray.getDimensionPixelSize(R.styleable.RippleView_rv_ripplePadding, 0);
    canvasHandler = new Handler();
    zoomScale = typedArray.getFloat(R.styleable.RippleView_rv_zoomScale, 1.03f);
    zoomDuration = typedArray.getInt(R.styleable.RippleView_rv_zoomDuration, 200);
    isListMode = typedArray.getBoolean(R.styleable.RippleView_rv_listMode, false);
    typedArray.recycle();
    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setStyle(Paint.Style.FILL);
    paint.setColor(rippleColor);
    paint.setAlpha(rippleAlpha);
    this.setWillNotDraw(false);

    gestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() {
        @Override
        public void onLongPress(MotionEvent event) {
            super.onLongPress(event);
            animateRipple(event);
            sendClickEvent(true);
            lastLongPressX = (int) event.getX();
            lastLongPressY = (int) event.getY();
            rippleStatus = RIPPLE_LONG_PRESS;
        }

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

        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            return true;
        }
    });

    this.setDrawingCacheEnabled(true);
    this.setClickable(true);
    this.touchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
}

From source file:com.example.anumbrella.viewpager.CirclePagerIndicator.java

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

    ///*from   w w  w  .  j ava 2 s  . co  m*/
    if (isInEditMode()) {
        return;
    }

    //??
    final Resources res = getResources();

    //
    //?

    //??
    final int defaultPageColor = res.getColor(R.color.default_circle_indicator_page_color);
    //
    final int defaultFillColor = res.getColor(R.color.default_circle_indicator_fill_color);
    //?
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    //
    final int defaultStrokeColor = res.getColor(R.color.default_circle_indicator_stroke_color);
    //
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    //??
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    //??
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    //?(?())
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //xml
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0);

    mCentered = array.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered);
    mOrientation = array.getInteger(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation);
    //
    mPaintPageFill.setStyle(Paint.Style.FILL);
    //
    mPaintPageFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor));
    //
    mPaintFill.setStyle(Paint.Style.FILL);
    //
    mPaintFill.setColor(array.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor));
    //
    mPaintStroke.setColor(array.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor));
    //(??)
    mPaintStroke.setStyle(Paint.Style.STROKE);
    //
    mPaintStroke.setStrokeWidth(
            array.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth));
    //???
    mRadius = array.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius);
    //?
    mSnap = array.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap);
    Drawable background = array.getDrawable(R.styleable.CirclePagerIndicator_android_background);
    if (background != null) {
        setBackgroundDrawable(background);
    }
    array.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);

}