android.content.res.TypedArray#getBoolean()源码实例Demo

下面列出了android.content.res.TypedArray#getBoolean() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: android_9.0.0_r45   文件: AdapterViewFlipper.java
public AdapterViewFlipper(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    super(context, attrs, defStyleAttr, defStyleRes);

    final TypedArray a = context.obtainStyledAttributes(attrs,
            com.android.internal.R.styleable.AdapterViewFlipper, defStyleAttr, defStyleRes);
    mFlipInterval = a.getInt(
            com.android.internal.R.styleable.AdapterViewFlipper_flipInterval, DEFAULT_INTERVAL);
    mAutoStart = a.getBoolean(
            com.android.internal.R.styleable.AdapterViewFlipper_autoStart, false);

    // A view flipper should cycle through the views
    mLoopViews = true;

    a.recycle();
}
 
@Override
public void onInflate(Activity activity, AttributeSet attrs, Bundle savedInstanceState) {
    super.onInflate(activity, attrs, savedInstanceState);
    TypedArray a = activity.obtainStyledAttributes(attrs, R.styleable.com_facebook_picker_fragment);

    setShowPictures(a.getBoolean(R.styleable.com_facebook_picker_fragment_show_pictures, showPictures));
    String extraFieldsString = a.getString(R.styleable.com_facebook_picker_fragment_extra_fields);
    if (extraFieldsString != null) {
        String[] strings = extraFieldsString.split(",");
        setExtraFields(Arrays.asList(strings));
    }

    showTitleBar = a.getBoolean(R.styleable.com_facebook_picker_fragment_show_title_bar, showTitleBar);
    titleText = a.getString(R.styleable.com_facebook_picker_fragment_title_text);
    doneButtonText = a.getString(R.styleable.com_facebook_picker_fragment_done_button_text);
    titleBarBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_title_bar_background);
    doneButtonBackground = a.getDrawable(R.styleable.com_facebook_picker_fragment_done_button_background);

    a.recycle();
}
 
源代码3 项目: fingerpoetry-android   文件: CircularProgress.java
public CircularProgress(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.CircularProgress);
    mColor = attributes.getColor(R.styleable.CircularProgress_circular_progress_color,
            getResources().getColor(R.color.circular_progress_color));
    mSize = attributes.getInt(R.styleable.CircularProgress_circular_progress_size, NORMAL_SIZE);
    mIndeterminate = attributes.getBoolean(R.styleable.CircularProgress_circular_progress_indeterminate,
            getResources().getBoolean(R.bool.circular_progress_indeterminate));
    mBorderWidth = attributes.getDimensionPixelSize(R.styleable.CircularProgress_circular_progress_border_width,
            getResources().getDimensionPixelSize(R.dimen.circular_progress_border_width));
    mDuration = attributes.getInteger(R.styleable.CircularProgress_circular_progress_duration, ANIMATION_RESOLUTION);
    mMax = attributes.getInteger(R.styleable.CircularProgress_circular_progress_max,
            getResources().getInteger(R.integer.circular_progress_max));
    attributes.recycle();

    if (mIndeterminate) {
        mIndeterminateProgressDrawable = new IndeterminateProgressDrawable(mColor, mBorderWidth);
        mIndeterminateProgressDrawable.setCallback(this);
    } else {
        mDeterminateProgressDrawable = new DeterminateProgressDrawable(mColor, mBorderWidth, 0);
        mDeterminateProgressDrawable.setCallback(this);
    }
}
 
源代码4 项目: bubble-layout   文件: BubbleLayout.java
public BubbleLayout(Context c, AttributeSet attrs, int defStyleAttr) {
    super(c, attrs, defStyleAttr);

    // Create default sizes from density
    final float density = getResources().getDisplayMetrics().density;
    final int DEFAULT_BUBBLE_SIZE = (int)(40f * density);
    final int DEFAULT_BUBBLE_MARGIN = (int)(4f * density);
    final int DEFAULT_BORDER_WIDTH = (int)(1f * density);
    final int DEFAULT_BUBBLE_OFFSET = 2; // 1/2 of each bubble
    final int DEFAULT_BUBBLE_PEEK = 4;

    // Set XML attributes
    TypedArray a = c.obtainStyledAttributes(attrs, R.styleable.BubbleLayout);
    this.bubbleSize = a.getDimensionPixelSize(R.styleable.BubbleLayout_bubbleSize, DEFAULT_BUBBLE_SIZE);
    this.bubbleOffset = bubbleSize / (a.getInt(R.styleable.BubbleLayout_bubbleOffset, DEFAULT_BUBBLE_OFFSET));
    this.bubblePeek = a.getInt(R.styleable.BubbleLayout_bubblePeek, DEFAULT_BUBBLE_PEEK);
    this.bubbleBorderWidth = a.getDimensionPixelSize(R.styleable.BubbleLayout_borderWidth, DEFAULT_BORDER_WIDTH);
    this.bubbleMargin = a.getDimensionPixelSize(R.styleable.BubbleLayout_bubbleMargin, DEFAULT_BUBBLE_MARGIN);
    this.bubbleBorderColor = a.getColor(R.styleable.BubbleLayout_borderColor, ContextCompat.getColor(c, R.color.default_circle_border_color));
    this.textColor = a.getColor(R.styleable.BubbleLayout_android_textColor, ContextCompat.getColor(c, R.color.default_circle_text_color));
    this.useOffset = a.getBoolean(R.styleable.BubbleLayout_useBubbleOffset, true);
    a.recycle();
}
 
源代码5 项目: Knife   文件: KnifeText.java
private void init(AttributeSet attrs) {
    TypedArray array = getContext().obtainStyledAttributes(attrs, R.styleable.KnifeText);
    bulletColor = array.getColor(R.styleable.KnifeText_bulletColor, 0);
    bulletRadius = array.getDimensionPixelSize(R.styleable.KnifeText_bulletRadius, 0);
    bulletGapWidth = array.getDimensionPixelSize(R.styleable.KnifeText_bulletGapWidth, 0);
    historyEnable = array.getBoolean(R.styleable.KnifeText_historyEnable, true);
    historySize = array.getInt(R.styleable.KnifeText_historySize, 100);
    linkColor = array.getColor(R.styleable.KnifeText_linkColor, 0);
    linkUnderline = array.getBoolean(R.styleable.KnifeText_linkUnderline, true);
    quoteColor = array.getColor(R.styleable.KnifeText_quoteColor, 0);
    quoteStripeWidth = array.getDimensionPixelSize(R.styleable.KnifeText_quoteStripeWidth, 0);
    quoteGapWidth = array.getDimensionPixelSize(R.styleable.KnifeText_quoteCapWidth, 0);
    array.recycle();

    if (historyEnable && historySize <= 0) {
        throw new IllegalArgumentException("historySize must > 0");
    }
}
 
源代码6 项目: Android-Bootstrap   文件: BootstrapThumbnail.java
protected void initialise(AttributeSet attrs) {
    TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.BootstrapThumbnail);

    try {
        int typeOrdinal = a.getInt(R.styleable.BootstrapThumbnail_bootstrapBrand, -1);
        int sizeOrdinal = a.getInt(R.styleable.BootstrapThumbnail_bootstrapSize, -1);

        this.hasBorder = a.getBoolean(R.styleable.BootstrapCircleThumbnail_hasBorder, true);
        this.bootstrapSize = DefaultBootstrapSize.fromAttributeValue(sizeOrdinal).scaleFactor();

        if (typeOrdinal == -1) { // override to use Primary for default border (looks nicer)
            this.bootstrapBrand = DefaultBootstrapBrand.PRIMARY;
        }
        else {
            this.bootstrapBrand = DefaultBootstrapBrand.fromAttributeValue(typeOrdinal);
        }
    }
    finally {
        a.recycle();
    }

    placeholderPaint = new Paint();
    placeholderPaint.setColor(ColorUtils.resolveColor(R.color.bootstrap_gray_light, getContext()));
    placeholderPaint.setStyle(Paint.Style.FILL);
    placeholderPaint.setAntiAlias(true);

    this.baselineCornerRadius = getResources().getDimension(R.dimen.bthumbnail_rounded_corner);
    this.baselineBorderWidth = getResources().getDimension(R.dimen.bthumbnail_default_border);
    setScaleType(ScaleType.CENTER_CROP);

    super.initialise(attrs);
}
 
源代码7 项目: FastAccess   文件: ViewPagerView.java
public ViewPagerView(Context context, AttributeSet attrs) {
    super(context, attrs);
    int[] attrsArray = {enabled};
    TypedArray array = context.obtainStyledAttributes(attrs, attrsArray);
    isEnabled = array.getBoolean(0, true);
    array.recycle();
}
 
源代码8 项目: UltimateAndroid   文件: ShowcaseView.java
private void updateStyle(TypedArray styled, boolean invalidate) {
    int backgroundColor = styled.getColor(R.styleable.ShowcaseView_sv_backgroundColor, Color.argb(128, 80, 80, 80));
    int showcaseColor = styled.getColor(R.styleable.ShowcaseView_sv_showcaseColor, HOLO_BLUE);
    String buttonText = styled.getString(R.styleable.ShowcaseView_sv_buttonText);
    if (TextUtils.isEmpty(buttonText)) {
        buttonText ="ok";
    }
    boolean tintButton = styled.getBoolean(R.styleable.ShowcaseView_sv_tintButtonColor, true);

    int titleTextAppearance = styled.getResourceId(R.styleable.ShowcaseView_sv_titleTextAppearance,
            R.style.TextAppearance_ShowcaseView_Title);
    int detailTextAppearance = styled.getResourceId(R.styleable.ShowcaseView_sv_detailTextAppearance,
            R.style.TextAppearance_ShowcaseView_Detail);

    styled.recycle();

    showcaseDrawer.setShowcaseColour(showcaseColor);
    showcaseDrawer.setBackgroundColour(backgroundColor);
    tintButton(showcaseColor, tintButton);
    mEndButton.setText(buttonText);
    textDrawer.setTitleStyling(titleTextAppearance);
    textDrawer.setDetailStyling(detailTextAppearance);
    hasAlteredText = true;

    if (invalidate) {
        invalidate();
    }
}
 
源代码9 项目: HeadsUp   文件: HeadsUpNotificationView.java
public HeadsUpNotificationView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.HeadsUpNotificationView);
    mRipple = a.getBoolean(R.styleable.HeadsUpNotificationView_ripple, false);
    a.recycle();

    mTimeout = new Timeout();

    float densityScale = getResources().getDisplayMetrics().density;
    float pagingTouchSlop = ViewConfiguration.get(getContext()).getScaledPagingTouchSlop();
    mSwipeHelperX = new SwipeHelper(SwipeHelper.X, this, densityScale, pagingTouchSlop);
}
 
@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);

		/**
		 * 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);
		}
	}
}
 
源代码11 项目: Luhn   文件: Luhn.java
private void initStyle(int style) {
    TypedArray ta = obtainStyledAttributes(style, R.styleable.luhnStyle);
    String fontName = ta.getString(R.styleable.luhnStyle_luhn_typeface);
    String title = ta.getString(R.styleable.luhnStyle_luhn_title);
    includeCalligraphy(fontName);
    initViews();
    retrievePin = ta.getBoolean(R.styleable.luhnStyle_luhn_show_pin, false);
    ((AppCompatTextView) findViewById(R.id.toolbar_title)).setText(TextUtils.isEmpty(title) ? "Add Card" : title);
    findViewById(R.id.btn_proceed).setBackground(ta.getDrawable(R.styleable.luhnStyle_luhn_btn_verify_selector));
    findViewById(R.id.toolbar).setBackgroundColor(ta.getColor(R.styleable.luhnStyle_luhn_show_toolbar_color, ContextCompat.getColor(this, R.color.ln_colorPrimary)));
}
 
源代码12 项目: UltimateRecyclerView   文件: FloatingActionsMenu.java
private void init(Context context, AttributeSet attributeSet) {
    mAddButtonPlusColor = getColor(android.R.color.white);
    mAddButtonColorNormal = getColor(android.R.color.holo_blue_dark);
    mAddButtonColorPressed = getColor(android.R.color.holo_blue_light);

    mButtonSpacing = (int) (getResources().getDimension(R.dimen.fab_actions_spacing) - getResources().getDimension(R.dimen.fab_shadow_radius) - getResources().getDimension(R.dimen.fab_shadow_offset));

    if (attributeSet != null) {
        TypedArray attr = context.obtainStyledAttributes(attributeSet, R.styleable.FloatingActionsMenu, 0, 0);
        if (attr != null) {
            try {
                mAddButtonPlusColor = attr.getColor(R.styleable.FloatingActionsMenu_addButtonPlusIconColor, getColor(android.R.color.white));
                mAddButtonColorNormal = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorNormal, getColor(android.R.color.holo_blue_dark));
                mAddButtonColorPressed = attr.getColor(R.styleable.FloatingActionsMenu_addButtonColorPressed, getColor(android.R.color.holo_blue_light));
                isHorizontal = attr.getBoolean(R.styleable.FloatingActionsMenu_addButtonIsHorizontal, false);
            } finally {
                attr.recycle();
            }
        }
    }
    WindowManager mWindowManager = (WindowManager)
            context.getSystemService(Context.WINDOW_SERVICE);
    Display display = mWindowManager.getDefaultDisplay();
    Point size = new Point();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
        display.getSize(size);
        mYHidden = size.y;
    } else mYHidden = display.getHeight();

    createAddButton(context);
}
 
源代码13 项目: VMLibrary   文件: VMSquareLayout.java
/**
 * 获取资源属性
 *
 * @param context
 * @param attrs
 */
private void handleAttrs(Context context, AttributeSet attrs) {
    if (attrs == null) {
        return;
    }
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.VMSquareLayout);
    isUnifyWidth = array.getBoolean(R.styleable.VMSquareLayout_vm_unify_width, true);
}
 
源代码14 项目: ncalc   文件: ViewUtils.java
public static boolean getBoolean(Context context, int attr, boolean def) {
    TypedValue typedValue = new TypedValue();
    TypedArray a = context.obtainStyledAttributes(typedValue.data, new int[]{attr});
    boolean value = a.getBoolean(0, def);
    a.recycle();
    return value;
}
 
源代码15 项目: ForegroundViews   文件: ForegroundLinearLayout.java
public ForegroundLinearLayout(Context context, AttributeSet attrs, int defStyle) {
  super(context, attrs, defStyle);

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

  final Drawable d = a.getDrawable(R.styleable.ForegroundLayout_foreground);
  foregroundPadding = a.getBoolean(R.styleable.ForegroundLayout_foregroundInsidePadding, false);

  backgroundAsForeground = a.getBoolean(R.styleable.ForegroundLayout_backgroundAsForeground, false);

  // Apply foreground padding for ninepatches automatically
  if (!foregroundPadding && getBackground() instanceof NinePatchDrawable) {
    final NinePatchDrawable npd = (NinePatchDrawable) getBackground();
    if (npd != null && npd.getPadding(rectPadding)) {
      foregroundPadding = true;
    }
  }

  final Drawable b = getBackground();
  if (backgroundAsForeground && b != null) {
    setForeground(b);
  } else if (d != null) {
    setForeground(d);
  }

  a.recycle();
}
 
源代码16 项目: android-otpview-pinview   文件: OtpView.java
public OtpView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  final Resources res = getResources();
  paint = new Paint(Paint.ANTI_ALIAS_FLAG);
  paint.setStyle(Paint.Style.STROKE);
  animatorTextPaint.set(getPaint());
  final Resources.Theme theme = context.getTheme();
  TypedArray typedArray =
      theme.obtainStyledAttributes(attrs, R.styleable.OtpView, defStyleAttr, 0);
  viewType = typedArray.getInt(R.styleable.OtpView_viewType, VIEW_TYPE_NONE);
  otpViewItemCount = typedArray.getInt(R.styleable.OtpView_itemCount, DEFAULT_COUNT);
  otpViewItemHeight = (int) typedArray.getDimension(R.styleable.OtpView_itemHeight,
      res.getDimensionPixelSize(R.dimen.otp_view_item_size));
  otpViewItemWidth = (int) typedArray.getDimension(R.styleable.OtpView_itemWidth,
      res.getDimensionPixelSize(R.dimen.otp_view_item_size));
  otpViewItemSpacing = typedArray.getDimensionPixelSize(R.styleable.OtpView_itemSpacing,
      res.getDimensionPixelSize(R.dimen.otp_view_item_spacing));
  otpViewItemRadius = (int) typedArray.getDimension(R.styleable.OtpView_itemRadius, 0);
  lineWidth = (int) typedArray.getDimension(R.styleable.OtpView_lineWidth,
      res.getDimensionPixelSize(R.dimen.otp_view_item_line_width));
  lineColor = typedArray.getColorStateList(R.styleable.OtpView_lineColor);
  isCursorVisible = typedArray.getBoolean(R.styleable.OtpView_android_cursorVisible, true);
  cursorColor = typedArray.getColor(R.styleable.OtpView_cursorColor, getCurrentTextColor());
  cursorWidth = typedArray.getDimensionPixelSize(R.styleable.OtpView_cursorWidth,
      res.getDimensionPixelSize(R.dimen.otp_view_cursor_width));
  itemBackground = typedArray.getDrawable(R.styleable.OtpView_android_itemBackground);
  hideLineWhenFilled = typedArray.getBoolean(R.styleable.OtpView_hideLineWhenFilled, false);
  rtlTextDirection = typedArray.getBoolean(R.styleable.OtpView_rtlTextDirection, false);
  maskingChar = typedArray.getString(R.styleable.OtpView_maskingChar);
  typedArray.recycle();
  if (lineColor != null) {
    cursorLineColor = lineColor.getDefaultColor();
  }
  updateCursorHeight();
  checkItemRadius();
  setMaxLength(otpViewItemCount);
  paint.setStrokeWidth(lineWidth);
  setupAnimator();
  super.setCursorVisible(false);
  setTextIsSelectable(false);
}
 
源代码17 项目: ShareBox   文件: FloatingActionMenu.java
private void init(Context context, AttributeSet attrs) {
    TypedArray attr = context.obtainStyledAttributes(attrs, R.styleable.FloatingActionMenu, 0, 0);
    mButtonSpacing = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_buttonSpacing, mButtonSpacing);
    mLabelsMargin = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_margin, mLabelsMargin);
    mLabelsPosition = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_position, LABELS_POSITION_LEFT);
    mLabelsShowAnimation = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_showAnimation,
            mLabelsPosition == LABELS_POSITION_LEFT ? R.anim.fab_slide_in_from_right : R.anim.fab_slide_in_from_left);
    mLabelsHideAnimation = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_hideAnimation,
            mLabelsPosition == LABELS_POSITION_LEFT ? R.anim.fab_slide_out_to_right : R.anim.fab_slide_out_to_left);
    mLabelsPaddingTop = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingTop, mLabelsPaddingTop);
    mLabelsPaddingRight = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingRight, mLabelsPaddingRight);
    mLabelsPaddingBottom = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingBottom, mLabelsPaddingBottom);
    mLabelsPaddingLeft = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_paddingLeft, mLabelsPaddingLeft);
    mLabelsTextColor = attr.getColorStateList(R.styleable.FloatingActionMenu_menu_labels_textColor);
    // set default value if null same as for textview
    if (mLabelsTextColor == null) {
        mLabelsTextColor = ColorStateList.valueOf(Color.WHITE);
    }
    mLabelsTextSize = attr.getDimension(R.styleable.FloatingActionMenu_menu_labels_textSize, getResources().getDimension(R.dimen.labels_text_size));
    mLabelsCornerRadius = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_cornerRadius, mLabelsCornerRadius);
    mLabelsShowShadow = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_showShadow, true);
    mLabelsColorNormal = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorNormal, 0xFF333333);
    mLabelsColorPressed = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorPressed, 0xFF444444);
    mLabelsColorRipple = attr.getColor(R.styleable.FloatingActionMenu_menu_labels_colorRipple, 0x66FFFFFF);
    mMenuShowShadow = attr.getBoolean(R.styleable.FloatingActionMenu_menu_showShadow, true);
    mMenuShadowColor = attr.getColor(R.styleable.FloatingActionMenu_menu_shadowColor, 0x66000000);
    mMenuShadowRadius = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowRadius, mMenuShadowRadius);
    mMenuShadowXOffset = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowXOffset, mMenuShadowXOffset);
    mMenuShadowYOffset = attr.getDimension(R.styleable.FloatingActionMenu_menu_shadowYOffset, mMenuShadowYOffset);
    mMenuColorNormal = attr.getColor(R.styleable.FloatingActionMenu_menu_colorNormal, 0xFFDA4336);
    mMenuColorPressed = attr.getColor(R.styleable.FloatingActionMenu_menu_colorPressed, 0xFFE75043);
    mMenuColorRipple = attr.getColor(R.styleable.FloatingActionMenu_menu_colorRipple, 0x99FFFFFF);
    mAnimationDelayPerItem = attr.getInt(R.styleable.FloatingActionMenu_menu_animationDelayPerItem, 50);
    mIcon = attr.getDrawable(R.styleable.FloatingActionMenu_menu_icon);
    if (mIcon == null) {
        mIcon = getResources().getDrawable(R.drawable.fab_add);
    }
    mLabelsSingleLine = attr.getBoolean(R.styleable.FloatingActionMenu_menu_labels_singleLine, false);
    mLabelsEllipsize = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_ellipsize, 0);
    mLabelsMaxLines = attr.getInt(R.styleable.FloatingActionMenu_menu_labels_maxLines, -1);
    mMenuFabSize = attr.getInt(R.styleable.FloatingActionMenu_menu_fab_size, FloatingActionButton.SIZE_NORMAL);
    mLabelsStyle = attr.getResourceId(R.styleable.FloatingActionMenu_menu_labels_style, 0);
    String customFont = attr.getString(R.styleable.FloatingActionMenu_menu_labels_customFont);
    try {
        if (!TextUtils.isEmpty(customFont)) {
            mCustomTypefaceFromFont = Typeface.createFromAsset(getContext().getAssets(), customFont);
        }
    } catch (RuntimeException ex) {
        throw new IllegalArgumentException("Unable to load specified custom font: " + customFont, ex);
    }
    mOpenDirection = attr.getInt(R.styleable.FloatingActionMenu_menu_openDirection, OPEN_UP);
    mBackgroundColor = attr.getColor(R.styleable.FloatingActionMenu_menu_backgroundColor, Color.TRANSPARENT);

    if (attr.hasValue(R.styleable.FloatingActionMenu_menu_fab_label)) {
        mUsingMenuLabel = true;
        mMenuLabelText = attr.getString(R.styleable.FloatingActionMenu_menu_fab_label);
    }

    if (attr.hasValue(R.styleable.FloatingActionMenu_menu_labels_padding)) {
        int padding = attr.getDimensionPixelSize(R.styleable.FloatingActionMenu_menu_labels_padding, 0);
        initPadding(padding);
    }

    mOpenInterpolator = new OvershootInterpolator();
    mCloseInterpolator = new AnticipateInterpolator();
    mLabelsContext = new ContextThemeWrapper(getContext(), mLabelsStyle);

    initBackgroundDimAnimation();
    createMenuButton();
    initMenuButtonAnimations(attr);

    attr.recycle();
}
 
源代码18 项目: FABRevealMenu-master   文件: FABRevealMenu.java
private void initView(Context context, AttributeSet attrs) {
    mContext = context;

    //helper initialization
    viewHelper = new ViewHelper(context);
    animationHelper = new AnimationHelper(viewHelper);

    if (attrs != null) {
        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FABRevealMenu, 0, 0);

        //background
        mMenuBackground = a.getColor(R.styleable.FABRevealMenu_menuBackgroundColor, getColor(R.color.colorWhite));
        mOverlayBackground = a.getColor(R.styleable.FABRevealMenu_overlayBackground, getColor(R.color.colorOverlayDark));

        //menu
        mMenuRes = a.getResourceId(R.styleable.FABRevealMenu_menuRes, -1);

        //custom view
        int customView = a.getResourceId(R.styleable.FABRevealMenu_menuCustomView, -1);
        if (customView != -1)
            mCustomView = LayoutInflater.from(context).inflate(customView, null);

        //direction
        mDirection = Direction.fromId(a.getInt(R.styleable.FABRevealMenu_menuDirection, 0));

        //title
        mTitleTextColor = a.getColor(R.styleable.FABRevealMenu_menuTitleTextColor, getColor(android.R.color.white));
        mTitleDisabledTextColor = a.getColor(R.styleable.FABRevealMenu_menuTitleDisabledTextColor, getColor(android.R.color.darker_gray));
        mShowTitle = a.getBoolean(R.styleable.FABRevealMenu_showTitle, true);
        mShowIcon = a.getBoolean(R.styleable.FABRevealMenu_showIcon, true);
        mShowOverlay = a.getBoolean(R.styleable.FABRevealMenu_showOverlay, true);

        //size
        mMenuSize = a.getInt(R.styleable.FABRevealMenu_menuSize, FAB_MENU_SIZE_NORMAL);

        //animation
        animateItems = a.getBoolean(R.styleable.FABRevealMenu_animateItems, true);

        //Font
        if (a.hasValue(R.styleable.FABRevealMenu_menuTitleFontFamily)) {
            int fontId = a.getResourceId(R.styleable.FABRevealMenu_menuTitleFontFamily, -1);
            if (fontId != -1)
                mMenuTitleTypeface = ResourcesCompat.getFont(context, fontId);
        }

        a.recycle();

        //initialization
        if (mMenuRes != -1) {
            setMenu(mMenuRes);
        } else if (mCustomView != null) {
            setCustomView(mCustomView);
        }
    }
}
 
源代码19 项目: Kawaii_LoadingView   文件: Kawaii_LoadingView.java
/**
 * 步骤1:初始化动画的属性
 */
private void initAttrs(Context context, AttributeSet attrs) {

    // 控件资源名称
    TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.Kawaii_LoadingView);

    // 方块行数量(最少3行)
    lineNumber = typedArray.getInteger(R.styleable.Kawaii_LoadingView_lineNumber, 3);
    if (lineNumber < 3) {
        lineNumber = 3;
    }

    // 半个方块的宽度(dp)
    half_BlockWidth = typedArray.getDimension(R.styleable.Kawaii_LoadingView_half_BlockWidth, 30);
    // 方块间隔宽度(dp)
    blockInterval = typedArray.getDimension(R.styleable.Kawaii_LoadingView_blockInterval, 10);

    // 移动方块的圆角半径
    moveBlock_Angle = typedArray.getFloat(R.styleable.Kawaii_LoadingView_moveBlock_Angle, 10);
    // 固定方块的圆角半径
    fixBlock_Angle = typedArray.getFloat(R.styleable.Kawaii_LoadingView_fixBlock_Angle, 30);
    // 通过设置两个方块的圆角半径使得二者不同可以得到更好的动画效果哦

    // 方块颜色(使用十六进制代码,如#333、#8e8e8e)
    int defaultColor = context.getResources().getColor(R.color.colorAccent); // 默认颜色
    blockColor = typedArray.getColor(R.styleable.Kawaii_LoadingView_blockColor, defaultColor);

    // 移动方块的初始位置(即空白位置)
    initPosition = typedArray.getInteger(R.styleable.Kawaii_LoadingView_initPosition, 0);

    // 由于移动方块只能是外部方块,所以这里需要判断方块是否属于外部方块 -->关注1
    if (isInsideTheRect(initPosition, lineNumber)) {
        initPosition = 0;
    }
    // 动画方向是否 = 顺时针旋转
    isClock_Wise = typedArray.getBoolean(R.styleable.Kawaii_LoadingView_isClock_Wise, true);

    // 移动方块的移动速度
    // 注:不建议使用者将速度调得过快
    // 因为会导致ValueAnimator动画对象频繁重复的创建,存在内存抖动
    moveSpeed = typedArray.getInteger(R.styleable.Kawaii_LoadingView_moveSpeed, 250);

    // 设置移动方块动画的插值器
    int move_InterpolatorResId = typedArray.getResourceId(R.styleable.Kawaii_LoadingView_move_Interpolator,
            android.R.anim.linear_interpolator);
    move_Interpolator = AnimationUtils.loadInterpolator(context, move_InterpolatorResId);

    // 当方块移动后,需要实时更新的空白方块的位置
    mCurrEmptyPosition = initPosition;

    // 释放资源
    typedArray.recycle();
}
 
public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (isInEditMode()) {
        mShadowDrawable = null;
        mDragHelper = null;
        return;
    }

    Interpolator scrollerInterpolator = null;
    if (attrs != null) {
        TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);

        if (defAttrs != null) {
            int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY);
            setGravity(gravity);
            defAttrs.recycle();
        }


        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout);

        if (ta != null) {
            mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoPanelHeight, -1);
            mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoShadowHeight, -1);
            mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_umanoParallaxOffset, -1);

            mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_umanoFlingVelocity, DEFAULT_MIN_FLING_VELOCITY);
            mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_umanoFadeColor, DEFAULT_FADE_COLOR);

            mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoDragView, -1);
            mScrollableViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoScrollableView, -1);

            mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoOverlay, DEFAULT_OVERLAY_FLAG);
            mClipPanel = ta.getBoolean(R.styleable.SlidingUpPanelLayout_umanoClipPanel, DEFAULT_CLIP_PANEL_FLAG);

            mAnchorPoint = ta.getFloat(R.styleable.SlidingUpPanelLayout_umanoAnchorPoint, DEFAULT_ANCHOR_POINT);

            mSlideState = PanelState.values()[ta.getInt(R.styleable.SlidingUpPanelLayout_umanoInitialState, DEFAULT_SLIDE_STATE.ordinal())];

            int interpolatorResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_umanoScrollInterpolator, -1);
            if (interpolatorResId != -1) {
                scrollerInterpolator = AnimationUtils.loadInterpolator(context, interpolatorResId);
            }
            ta.recycle();
        }
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mPanelHeight == -1) {
        mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f);
    }
    if (mShadowHeight == -1) {
        mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f);
    }
    if (mParallaxOffset == -1) {
        mParallaxOffset = (int) (DEFAULT_PARALLAX_OFFSET * density);
    }
    // If the shadow height is zero, don't show the shadow
    if (mShadowHeight > 0) {
        if (mIsSlidingUp) {
            mShadowDrawable = getResources().getDrawable(R.drawable.above_shadow);
        } else {
            mShadowDrawable = getResources().getDrawable(R.drawable.below_shadow);
        }
    } else {
        mShadowDrawable = null;
    }

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 0.5f, scrollerInterpolator, new DragHelperCallback());
    mDragHelper.setMinVelocity(mMinFlingVelocity * density);

    mIsTouchEnabled = true;
}