private void init(AttributeSet attrs) {
    setOrientation(VERTICAL);
    mData = new ArrayList<>();
    mRows = new ArrayList<>();

    DisplayMetrics dm = getResources().getDisplayMetrics();
    mItemMargin =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_ITEM_MARGIN, dm);
    mTextSize = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, DEFAULT_TEXT_SIZE, dm);
    mTextColor = DEFAULT_TEXT_COLOR;
    mPaddingHor =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_ITEM_PADDING_HOR, dm);
    mPaddingVer =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_ITEM_PADDING_VER, dm);
    mRowSpacing =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_ROW_SPACING, dm);

    // get custom attrs
    TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.SingleChoiceItemsView);
    mTextSize =
        a.getDimensionPixelSize(R.styleable.SingleChoiceItemsView_sciItemTextSize, mTextSize);
    mTextColor = a.getColor(R.styleable.SingleChoiceItemsView_sciItemTextColor, mTextColor);
    mItemBgResourceId =
        a.getResourceId(R.styleable.SingleChoiceItemsView_sciItemBackground, DEFAULT_ITEM_BG);
    mItemMargin =
        a.getDimensionPixelSize(R.styleable.SingleChoiceItemsView_sciItemMargin, mItemMargin);
    a.recycle();
  }
  /**
   * 获取自定义属性
   *
   * @param attrs
   */
  private void obtainStyledAttributes(AttributeSet attrs) {
    metrics = getContext().getResources().getDisplayMetrics();
    framePadding =
        (int)
            TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_PADDING, metrics);
    frameWidth =
        (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, DEFAULT_FRAME_WIDTH, metrics);

    TypedArray mTypedArray = getContext().obtainStyledAttributes(attrs, R.styleable.WaterMarkView);

    Drawable srcDrawble = mTypedArray.getDrawable(R.styleable.WaterMarkView_src);
    if (srcDrawble instanceof BitmapDrawable) {
      BitmapDrawable bd = (BitmapDrawable) srcDrawble;
      this.mWaterMarkBitmap = bd.getBitmap();
    }

    framePadding =
        mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_framePadding, framePadding);
    frameWidth =
        mTypedArray.getDimensionPixelSize(R.styleable.WaterMarkView_frameWidth, frameWidth);
    frameColor = mTypedArray.getColor(R.styleable.WaterMarkView_frameColor, DEFAULT_FRAME_COLOR);
    mScale = mTypedArray.getFloat(R.styleable.WaterMarkView_scale, DEFAULT_SCALE);
    mDegree = mTypedArray.getFloat(R.styleable.WaterMarkView_degree, DEFAULT_DEGREE);
    controlDrawable = mTypedArray.getDrawable(R.styleable.WaterMarkView_controlDrawable);
    controlLocation =
        mTypedArray.getInt(R.styleable.WaterMarkView_controlLocation, DEFAULT_CONTROL_LOCATION);
    isEditable = mTypedArray.getBoolean(R.styleable.WaterMarkView_editable, DEFAULT_EDITABLE);

    mTypedArray.recycle();
  }
  public ColorTrackView(Context context, AttributeSet attrs) {
    super(context, attrs);

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

    TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.ColorTrackView);
    mText = ta.getString(R.styleable.ColorTrackView_text);
    mTextNormalSize =
        ta.getDimensionPixelSize(R.styleable.ColorTrackView_text_normal_size, mTextNormalSize);
    mTextSelectSize =
        ta.getDimensionPixelSize(R.styleable.ColorTrackView_text_select_size, mTextNormalSize);

    mTextOriginColor = ta.getColor(R.styleable.ColorTrackView_text_origin_color, mTextOriginColor);

    mTextChangeColor = ta.getColor(R.styleable.ColorTrackView_text_change_color, mTextChangeColor);
    mProgress = ta.getFloat(R.styleable.ColorTrackView_progress, 0);

    mDirection = ta.getInt(R.styleable.ColorTrackView_direction, mDirection);

    bSelected = ta.getBoolean(R.styleable.ColorTrackView_isSelect, bSelected);

    ta.recycle();

    mPaint.setTextSize(mTextNormalSize);
    measureText();

    mTextOriginColorR = (mTextChangeColor & 0xff0000) >> 16;
    mTextOriginColorG = (mTextChangeColor & 0x00ff00) >> 8;
    mTextOriginColorB = (mTextChangeColor & 0x0000ff);
  }
  private void init(AttributeSet attrs) {
    getWindowVisibleDisplayFrame(mFrameRect);

    if (attrs == null) {
      mColumnNumber = (DEFAULT_COLUMN_NUMBER); // default column number is
      // 2.
    } else {
      TypedArray a =
          getContext().obtainStyledAttributes(attrs, R.styleable.PinterestLikeAdapterView);

      int landColNumber =
          a.getInteger(R.styleable.PinterestLikeAdapterView_plaLandscapeColumnNumber, 3);
      int defColNumber = a.getInteger(R.styleable.PinterestLikeAdapterView_plaColumnNumber, 2);

      if (mFrameRect.width() > mFrameRect.height() && landColNumber != -1) {
        mColumnNumber = (landColNumber);
      } else if (defColNumber != -1) {
        mColumnNumber = (defColNumber);
      } else {
        mColumnNumber = (DEFAULT_COLUMN_NUMBER);
      }

      mColumnPaddingLeft =
          a.getDimensionPixelSize(R.styleable.PinterestLikeAdapterView_plaColumnPaddingLeft, 0);
      mColumnPaddingRight =
          a.getDimensionPixelSize(R.styleable.PinterestLikeAdapterView_plaColumnPaddingRight, 0);
      a.recycle();
    }

    mColumns = new Column[getColumnNumber()];
    for (int i = 0; i < getColumnNumber(); ++i) mColumns[i] = new Column(i);

    mFixedColumn = new FixedColumn();
  }
  public VerticalProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mUiThreadId = Thread.currentThread().getId();
    initProgressBar();

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

    mNoInvalidate = true;

    Drawable drawable = a.getDrawable(R.styleable.ProgressBar_android_progressDrawable);
    if (drawable != null) {
      drawable = tileify(drawable, false);
      // Calling this method can set mMaxHeight, make sure the corresponding
      // XML attribute for mMaxHeight is read after calling this method
      setProgressDrawable(drawable);
    }

    mMinWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_android_minWidth, mMinWidth);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_android_maxWidth, mMaxWidth);
    mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_android_minHeight, mMinHeight);
    mMaxHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_android_maxHeight, mMaxHeight);

    setMax(a.getInt(R.styleable.ProgressBar_android_max, mMax));

    setProgress(a.getInt(R.styleable.ProgressBar_android_progress, mProgress));

    setSecondaryProgress(
        a.getInt(R.styleable.ProgressBar_android_secondaryProgress, mSecondaryProgress));

    mNoInvalidate = false;

    a.recycle();
  }
  public ChartSweepView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

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

    setSweepDrawable(a.getDrawable(R.styleable.ChartSweepView_sweepDrawable));
    setFollowAxis(a.getInt(R.styleable.ChartSweepView_followAxis, -1));
    setNeighborMargin(a.getDimensionPixelSize(R.styleable.ChartSweepView_neighborMargin, 0));

    setLabelMinSize(a.getDimensionPixelSize(R.styleable.ChartSweepView_labelSize, 0));
    setLabelTemplate(a.getResourceId(R.styleable.ChartSweepView_labelTemplate, 0));
    setLabelColor(a.getColor(R.styleable.ChartSweepView_labelColor, Color.BLUE));

    // TODO: moved focused state directly into assets
    setBackgroundResource(R.drawable.data_usage_sweep_background);

    mOutlinePaint.setColor(Color.RED);
    mOutlinePaint.setStrokeWidth(1f);
    mOutlinePaint.setStyle(Style.STROKE);

    a.recycle();

    setClickable(true);
    setFocusable(true);
    setOnClickListener(mClickListener);

    setWillNotDraw(false);
  }
Example #7
0
  // region Helper Methods
  private void init(AttributeSet attrs) {
    //        if (isInEditMode()) {
    //            return;
    //        }

    LayoutInflater.from(getContext()).inflate((R.layout.material_search_view), this, true);
    ButterKnife.bind(this);

    if (attrs != null) {
      TypedArray a =
          getContext()
              .getTheme()
              .obtainStyledAttributes(attrs, R.styleable.MaterialSearchView, 0, 0);
      try {
        mLeftDrawableType = a.getInteger(R.styleable.MaterialSearchView_leftDrawableType, 1);
        mHintText = a.getString(R.styleable.MaterialSearchView_hintText);
        mMarginTop = a.getDimensionPixelSize(R.styleable.MaterialSearchView_layout_marginTop, 0);
        mMarginBottom =
            a.getDimensionPixelSize(R.styleable.MaterialSearchView_layout_marginBottom, 0);
        mMarginLeft = a.getDimensionPixelSize(R.styleable.MaterialSearchView_layout_marginLeft, 0);
        mMarginRight =
            a.getDimensionPixelSize(R.styleable.MaterialSearchView_layout_marginRight, 0);

      } finally {
        a.recycle();
      }
    }

    setUpLeftDrawable(false);
    setUpCardView();
    setUpHintText();
    setUpListeners();
  }
  private void init(Context context, AttributeSet attrs, int defStyleAttr) {
    TypedArray attr =
        context.obtainStyledAttributes(attrs, R.styleable.FloatingActionButton, defStyleAttr, 0);
    mColorNormal = attr.getColor(R.styleable.FloatingActionButton_fab_colorNormal, 0xFFDA4336);
    mColorPressed = attr.getColor(R.styleable.FloatingActionButton_fab_colorPressed, 0xFFE75043);
    mColorDisabled = attr.getColor(R.styleable.FloatingActionButton_fab_colorDisabled, 0xFFAAAAAA);
    mColorRipple = attr.getColor(R.styleable.FloatingActionButton_fab_colorRipple, 0x99FFFFFF);
    mShowShadow = attr.getBoolean(R.styleable.FloatingActionButton_fab_showShadow, true);
    mShadowColor = attr.getColor(R.styleable.FloatingActionButton_fab_shadowColor, 0x66000000);
    mShadowRadius =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowRadius, mShadowRadius);
    mShadowXOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowXOffset, mShadowXOffset);
    mShadowYOffset =
        attr.getDimensionPixelSize(
            R.styleable.FloatingActionButton_fab_shadowYOffset, mShadowYOffset);
    mFabSize = attr.getInt(R.styleable.FloatingActionButton_fab_size, SIZE_NORMAL);
    mLabelText = attr.getString(R.styleable.FloatingActionButton_fab_label);
    mShouldProgressIndeterminate =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_indeterminate, false);
    mProgressColor = attr.getColor(R.styleable.FloatingActionButton_fab_progress_color, 0xFF009688);
    mProgressBackgroundColor =
        attr.getColor(R.styleable.FloatingActionButton_fab_progress_backgroundColor, 0x4D000000);
    mProgressMax = attr.getInt(R.styleable.FloatingActionButton_fab_progress_max, mProgressMax);
    mShowProgressBackground =
        attr.getBoolean(R.styleable.FloatingActionButton_fab_progress_showBackground, true);

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_progress)) {
      mProgress = attr.getInt(R.styleable.FloatingActionButton_fab_progress, 0);
      mShouldSetProgress = true;
    }

    if (attr.hasValue(R.styleable.FloatingActionButton_fab_elevationCompat)) {
      float elevation =
          attr.getDimensionPixelOffset(R.styleable.FloatingActionButton_fab_elevationCompat, 0);
      if (isInEditMode()) {
        setElevation(elevation);
      } else {
        setElevationCompat(elevation);
      }
    }

    initShowAnimation(attr);
    initHideAnimation(attr);
    attr.recycle();

    if (isInEditMode()) {
      if (mShouldProgressIndeterminate) {
        setIndeterminate(true);
      } else if (mShouldSetProgress) {
        saveButtonOriginalPosition();
        setProgress(mProgress, false);
      }
    }

    //        updateBackground();
    setClickable(true);
  }
  public MediaRouteButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mRouter = (MediaRouter) context.getSystemService(Context.MEDIA_ROUTER_SERVICE);

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, com.android.internal.R.styleable.MediaRouteButton, defStyleAttr, 0);
    setRemoteIndicatorDrawable(
        a.getDrawable(
            com.android.internal.R.styleable.MediaRouteButton_externalRouteEnabledDrawable));
    mMinWidth =
        a.getDimensionPixelSize(com.android.internal.R.styleable.MediaRouteButton_minWidth, 0);
    mMinHeight =
        a.getDimensionPixelSize(com.android.internal.R.styleable.MediaRouteButton_minHeight, 0);
    final int routeTypes =
        a.getInteger(
            com.android.internal.R.styleable.MediaRouteButton_mediaRouteTypes,
            MediaRouter.ROUTE_TYPE_LIVE_AUDIO);
    a.recycle();

    setClickable(true);
    setLongClickable(true);

    setRouteTypes(routeTypes);
  }
 private void initialize(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray a =
       context.obtainStyledAttributes(
           attrs, R.styleable.CardView, defStyleAttr, R.style.CardView_Light);
   int backgroundColor = a.getColor(R.styleable.CardView_cardBackgroundColor, 0);
   float radius = a.getDimension(R.styleable.CardView_cardCornerRadius, 0);
   float elevation = a.getDimension(R.styleable.CardView_cardElevation, 0);
   float maxElevation = a.getDimension(R.styleable.CardView_cardMaxElevation, 0);
   mCompatPadding = a.getBoolean(R.styleable.CardView_cardUseCompatPadding, false);
   mPreventCornerOverlap = a.getBoolean(R.styleable.CardView_cardPreventCornerOverlap, true);
   int defaultPadding = a.getDimensionPixelSize(R.styleable.CardView_contentPadding, 0);
   mContentPadding.left =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingLeft, defaultPadding);
   mContentPadding.top =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingTop, defaultPadding);
   mContentPadding.right =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingRight, defaultPadding);
   mContentPadding.bottom =
       a.getDimensionPixelSize(R.styleable.CardView_contentPaddingBottom, defaultPadding);
   if (elevation > maxElevation) {
     maxElevation = elevation;
   }
   a.recycle();
   IMPL.initialize(this, context, backgroundColor, radius, elevation, maxElevation);
 }
Example #11
0
  public FixedTabsView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);

    this.mContext = context;

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

    mDividerColor = a.getColor(R.styleable.ViewPagerExtensions_dividerColor, mDividerColor);

    mDividerMarginTop =
        a.getDimensionPixelSize(
            R.styleable.ViewPagerExtensions_dividerMarginTop, mDividerMarginTop);
    mDividerMarginBottom =
        a.getDimensionPixelSize(
            R.styleable.ViewPagerExtensions_dividerMarginBottom, mDividerMarginBottom);

    mDividerVisibility = a.getInt(R.styleable.ViewPagerExtensions_dividerVisibility, View.VISIBLE);

    mDividerDrawable = a.getDrawable(R.styleable.ViewPagerExtensions_dividerDrawable);

    a.recycle();

    this.setOrientation(LinearLayout.HORIZONTAL);
  }
  /**
   * Constructor that is called when inflating SwipeRefreshLayout from XML.
   *
   * @param context
   * @param attrs
   */
  public NoisySwipeRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    mMediumAnimationDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);

    setWillNotDraw(false);
    final DisplayMetrics metrics = getResources().getDisplayMetrics();
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mAccelerateInterpolator = new AccelerateInterpolator(ACCELERATE_INTERPOLATION_FACTOR);

    final TypedArray a = context.obtainStyledAttributes(attrs, LAYOUT_ATTRS);
    setEnabled(a.getBoolean(0, true));
    a.recycle();

    final TypedArray va =
        context.obtainStyledAttributes(attrs, R.styleable.SuperSwipeRefreshLayout);
    mProgressBarOffsetTop =
        a.getDimensionPixelSize(R.styleable.SuperSwipeRefreshLayout_topOffset, 0);
    mProgressBarHeight =
        a.getDimensionPixelSize(
            R.styleable.SuperSwipeRefreshLayout_progressBarHeight,
            (int) (metrics.density * PROGRESS_BAR_HEIGHT));
    va.recycle();
  }
Example #13
0
  public CropImageView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mFocusWidth =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, mFocusWidth, getResources().getDisplayMetrics());
    mFocusHeight =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, mFocusHeight, getResources().getDisplayMetrics());
    mBorderWidth =
        (int)
            TypedValue.applyDimension(
                TypedValue.COMPLEX_UNIT_DIP, mBorderWidth, getResources().getDisplayMetrics());

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CropImageView);
    mMaskColor = a.getColor(R.styleable.CropImageView_cropMaskColor, mMaskColor);
    mBorderColor = a.getColor(R.styleable.CropImageView_cropBorderColor, mBorderColor);
    mBorderWidth = a.getDimensionPixelSize(R.styleable.CropImageView_cropBorderWidth, mBorderWidth);
    mFocusWidth = a.getDimensionPixelSize(R.styleable.CropImageView_cropFocusWidth, mFocusWidth);
    mFocusHeight = a.getDimensionPixelSize(R.styleable.CropImageView_cropFocusHeight, mFocusHeight);
    mDefaultStyleIndex = a.getInteger(R.styleable.CropImageView_cropStyle, mDefaultStyleIndex);
    mStyle = styles[mDefaultStyleIndex];
    a.recycle();

    // 只允许图片为当前的缩放模式
    setScaleType(ScaleType.MATRIX);
  }
Example #14
0
 private void init(Context context, AttributeSet attrs) {
   setClipChildren(false);
   TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.MultiViewPager);
   setMaxWidth(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxWidth, -1));
   setMaxHeight(ta.getDimensionPixelSize(R.styleable.MultiViewPager_android_maxHeight, -1));
   setMatchChildWidth(ta.getResourceId(R.styleable.MultiViewPager_matchChildWidth, 0));
   ta.recycle();
 }
  public ProgressBar(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    mUiThreadId = Thread.currentThread().getId();
    initProgressBar();

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

    mNoInvalidate = true;

    Drawable drawable = a.getDrawable(R.styleable.ProgressBar_progressDrawable);
    if (drawable != null) {
      drawable = tileify(drawable, false);
      // Calling this method can set mMaxHeight, make sure the corresponding
      // XML attribute for mMaxHeight is read after calling this method
      setProgressDrawable(drawable);
    }

    mDuration = a.getInt(R.styleable.ProgressBar_indeterminateDuration, mDuration);

    mMinWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_minWidth, mMinWidth);
    mMaxWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_maxWidth, mMaxWidth);
    mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_minHeight, mMinHeight);
    mMaxHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_maxHeight, mMaxHeight);

    mBehavior = a.getInt(R.styleable.ProgressBar_indeterminateBehavior, mBehavior);

    final int resID =
        a.getResourceId(
            com.android.internal.R.styleable.ProgressBar_interpolator,
            android.R.anim.linear_interpolator); // default to linear interpolator
    if (resID > 0) {
      setInterpolator(context, resID);
    }

    setMax(a.getInt(R.styleable.ProgressBar_max, mMax));

    setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));

    setSecondaryProgress(a.getInt(R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));

    drawable = a.getDrawable(R.styleable.ProgressBar_indeterminateDrawable);
    if (drawable != null) {
      drawable = tileifyIndeterminate(drawable);
      setIndeterminateDrawable(drawable);
    }

    mOnlyIndeterminate =
        a.getBoolean(R.styleable.ProgressBar_indeterminateOnly, mOnlyIndeterminate);

    mNoInvalidate = false;

    setIndeterminate(
        mOnlyIndeterminate || a.getBoolean(R.styleable.ProgressBar_indeterminate, mIndeterminate));

    a.recycle();
  }
 private void readStyleParameters(Context context, AttributeSet attributeSet) {
   TypedArray a = context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout);
   try {
     horizontalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_horizontalSpacing, 0);
     verticalSpacing = a.getDimensionPixelSize(R.styleable.FlowLayout_verticalSpacing, 0);
     orientation = a.getInteger(R.styleable.FlowLayout_orientation, HORIZONTAL);
     debugDraw = a.getBoolean(R.styleable.FlowLayout_debugDraw, false);
   } finally {
     a.recycle();
   }
 }
  public PaperButton(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    mPadding = getResources().getDimensionPixelSize(R.dimen.paper_padding);
    TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.PaperButton);
    mColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_color,
            getResources().getColor(R.color.paper_button_color));
    mShadowColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_shadow_color,
            getResources().getColor(R.color.paper_button_shadow_color));
    mCornerRadius =
        attributes.getDimensionPixelSize(
            R.styleable.PaperButton_paper_corner_radius,
            getResources().getDimensionPixelSize(R.dimen.paper_button_corner_radius));
    mText = attributes.getText(R.styleable.PaperButton_paper_text);
    mTextSize =
        attributes.getDimensionPixelSize(
            R.styleable.PaperButton_paper_text_size,
            getResources().getDimensionPixelSize(R.dimen.paper_text_size));
    mTextColor =
        attributes.getColor(
            R.styleable.PaperButton_paper_text_color,
            getResources().getColor(R.color.paper_text_color));
    final String assetPath = attributes.getString(R.styleable.PaperButton_paper_font);
    if (assetPath != null) {
      AssetManager assets = context.getAssets();
      Typeface typeface = Typeface.createFromAsset(assets, assetPath);
      textPaint.setTypeface(typeface);
    }
    mShadowRadius = attributes.getFloat(R.styleable.PaperButton_paper_shadow_radius, SHADOW_RADIUS);
    mShadowOffsetX =
        attributes.getFloat(R.styleable.PaperButton_paper_shadow_offset_x, SHADOW_OFFSET_X);
    mShadowOffsetY =
        attributes.getFloat(R.styleable.PaperButton_paper_shadow_offset_y, SHADOW_OFFSET_Y);
    attributes.recycle();

    backgroundPaint.setColor(mColor);
    backgroundPaint.setStyle(Paint.Style.FILL);
    int shadowColor = changeColorAlpha(mShadowColor, MIN_SHADOW_COLOR_ALPHA);
    backgroundPaint.setShadowLayer(mShadowRadius, mShadowOffsetX, mShadowOffsetY, shadowColor);

    textPaint.setColor(mTextColor);
    textPaint.setTextSize(mTextSize);
    textPaint.setTextAlign(TextPaint.Align.CENTER);

    ripplePaint.setColor(darkenColor(mColor));

    setWillNotDraw(false);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
      setLayerType(View.LAYER_TYPE_SOFTWARE, null);
    }
  }
Example #18
0
  private void init(Context context, AttributeSet attrs) {
    mPaint = new Paint();
    mPaint.setColor(Color.WHITE);
    Resources resources = context.getResources();

    // get attrConfiguration
    TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.SwitchButton);
    int width = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmWidth, 0);
    int height = (int) array.getDimensionPixelSize(R.styleable.SwitchButton_bmHeight, 0);
    array.recycle();

    // size width or height
    if (width <= 0 || height <= 0) {
      width = COMMON_WIDTH_IN_PIXEL;
      height = COMMON_HEIGHT_IN_PIXEL;
    } else {
      float scale = (float) COMMON_WIDTH_IN_PIXEL / COMMON_HEIGHT_IN_PIXEL;
      if ((float) width / height > scale) {
        width = (int) (height * scale);
      } else if ((float) width / height < scale) {
        height = (int) (width / scale);
      }
    }

    // get viewConfiguration
    mClickTimeout = ViewConfiguration.getPressedStateDuration() + ViewConfiguration.getTapTimeout();
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

    // get Bitmap
    bmBgGreen = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_green);
    bmBgWhite = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_bg_white);
    bmBtnNormal = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_normal);
    bmBtnPressed = BitmapFactory.decodeResource(resources, R.drawable.switch_btn_pressed);

    // size Bitmap
    bmBgGreen = Bitmap.createScaledBitmap(bmBgGreen, width, height, true);
    bmBgWhite = Bitmap.createScaledBitmap(bmBgWhite, width, height, true);
    bmBtnNormal = Bitmap.createScaledBitmap(bmBtnNormal, height, height, true);
    bmBtnPressed = Bitmap.createScaledBitmap(bmBtnPressed, height, height, true);

    bmCurBtnPic = bmBtnNormal; // 初始按钮图片
    bmCurBgPic = mChecked ? bmBgGreen : bmBgWhite; // 初始背景图片
    bgWidth = bmBgGreen.getWidth(); // 背景宽度
    bgHeight = bmBgGreen.getHeight(); // 背景高度
    btnWidth = bmBtnNormal.getWidth(); // 按钮宽度
    offBtnPos = 0; // 关闭时在最左边
    onBtnPos = bgWidth - btnWidth; // 开始时在右边
    curBtnPos = mChecked ? onBtnPos : offBtnPos; // 按钮当前为初始位置

    // get density
    float density = resources.getDisplayMetrics().density;
    mVelocity = (int) (VELOCITY * density + 0.5f); // 动画距离
    mSaveLayerRectF = new RectF(0, 0, bgWidth, bgHeight);
  }
  public PagerHeader(Context context, AttributeSet attrs) {
    super(context, attrs);
    mContext = context;

    Resources resources = context.getResources();
    mDisplayMetrics = resources.getDisplayMetrics();

    // Get attributes from the layout xml
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.PagerHeader, 0, 0);
    //		mActiveTextColor = new ColorSet(
    //				a.getColor(R.styleable.PagerHeader_activeTextColor, Color.GREEN));
    mActiveTextColor = new ColorSet(resources.getColor(R.color.cputuner_green));
    mInactiveTextColor =
        new ColorSet(a.getColor(R.styleable.PagerHeader_inactiveTextColor, Color.LTGRAY));
    mTabColor =
        new ColorSet(a.getColor(R.styleable.PagerHeader_tabColor, mActiveTextColor.getColor()));
    mTabHeight = a.getDimensionPixelSize(R.styleable.PagerHeader_tabHeight, dipToPixels(4));
    mTabPadding = a.getDimensionPixelSize(R.styleable.PagerHeader_tabPadding, dipToPixels(10));
    mPaddingPush = a.getDimensionPixelSize(R.styleable.PagerHeader_paddingPush, dipToPixels(50));
    mFadingEdgeLength =
        a.getDimensionPixelSize(R.styleable.PagerHeader_fadingEdgeLength, dipToPixels(30));
    mShowTopShadow = a.getBoolean(R.styleable.PagerHeader_showTopShadow, true);
    mShowBottomBar = a.getBoolean(R.styleable.PagerHeader_showBottomBar, true);
    mShowTab = a.getBoolean(R.styleable.PagerHeader_showTab, true);

    ColorSet fadingEdgeColorHint = new ColorSet(0);
    int backgroundColor = a.getColor(R.styleable.PagerHeader_backgroundColor, Color.DKGRAY);
    setBackgroundColor(backgroundColor);
    fadingEdgeColorHint.setColor(backgroundColor);

    mTabDrawable = new ShapeDrawable(new RectShape());
    mTabDrawable.getPaint().setColor(mTabColor.getColor());

    mBottomBar = new ShapeDrawable(new RectShape());
    mBottomBar.getPaint().setColor(mTabColor.getColor());
    mBottomBarHeight = dipToPixels(2);

    mShadow =
        new GradientDrawable(
            GradientDrawable.Orientation.TOP_BOTTOM, new int[] {0x88000000, 0x00000000});
    mShadowHeight = dipToPixels(3);

    int[] fadingEdgeGradient =
        new int[] {fadingEdgeColorHint.getColor(), fadingEdgeColorHint.getColor(0)};
    mFadingEdgeLeft =
        new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, fadingEdgeGradient);
    mFadingEdgeRight =
        new GradientDrawable(GradientDrawable.Orientation.RIGHT_LEFT, fadingEdgeGradient);

    final ViewConfiguration config = ViewConfiguration.get(context);
    int touchSlop = config.getScaledTouchSlop();
    mTouchSlopSquare = touchSlop * touchSlop;
  }
    public LayoutParams(Context c, AttributeSet attrs) {
      super(c, attrs);

      final TypedArray a =
          c.obtainStyledAttributes(attrs, R.styleable.KeyguardSecurityViewFlipper_Layout, 0, 0);
      maxWidth =
          a.getDimensionPixelSize(
              R.styleable.KeyguardSecurityViewFlipper_Layout_layout_maxWidth, 0);
      maxHeight =
          a.getDimensionPixelSize(
              R.styleable.KeyguardSecurityViewFlipper_Layout_layout_maxHeight, 0);
      a.recycle();
    }
  public ShadowView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    TypedArray a =
        context.getTheme().obtainStyledAttributes(attrs, R.styleable.ShadowView, defStyleAttr, 0);
    int n = a.getIndexCount();
    for (int i = 0; i < n; i++) {
      int attr = a.getIndex(i);
      switch (attr) {
        case R.styleable.ShadowView_sv_text:
          text = a.getString(attr);
          break;
        case R.styleable.ShadowView_sv_textColor:
          textColor = a.getColor(attr, Color.BLACK);
          break;
        case R.styleable.ShadowView_sv_textSize:
          textSize =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_SP, 16, getResources().getDisplayMetrics()));
          break;
        case R.styleable.ShadowView_sv_shadowColor:
          shadowColor = a.getColor(attr, Color.BLACK);
          break;
        case R.styleable.ShadowView_sv_shadowSize:
          shadowSize =
              a.getDimensionPixelSize(
                  attr,
                  (int)
                      TypedValue.applyDimension(
                          TypedValue.COMPLEX_UNIT_DIP, 0, getResources().getDisplayMetrics()));
          break;
        case R.styleable.ShadowView_sv_direction:
          shadowDirection = a.getInt(attr, RIGHTBOTTOM);
          break;
      }
    }
    a.recycle();

    paint = new Paint();
    paint.setTextSize(textSize);
    paint.setFakeBoldText(true);
    paint.setColor(textColor);
    textBound = new Rect();
    paint.getTextBounds(text, 0, text.length(), textBound);
    calcShadow();
  }
Example #22
0
 private void readStyleParameters(Context context, AttributeSet attributeSet) {
   TypedArray a =
       context.obtainStyledAttributes(attributeSet, R.styleable.FlowLayout_LayoutParams);
   try {
     horizontalSpacing =
         a.getDimensionPixelSize(
             R.styleable.FlowLayout_LayoutParams_layout_horizontalSpacing, NO_SPACING);
     verticalSpacing =
         a.getDimensionPixelSize(
             R.styleable.FlowLayout_LayoutParams_layout_verticalSpacing, NO_SPACING);
     newLine = a.getBoolean(R.styleable.FlowLayout_LayoutParams_layout_newLine, false);
   } finally {
     a.recycle();
   }
 }
  public FlowLayout(Context context, AttributeSet attrs) {
    super(context, attrs);

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FlowLayout);
    try {
      mHorizontalSpacing =
          a.getDimensionPixelSize(
              R.styleable.FlowLayout_horizontal_spacing, DEFAULT_HORIZONTAL_SPACING);
      mVerticalSpacing =
          a.getDimensionPixelSize(
              R.styleable.FlowLayout_vertical_spacing, DEFAULT_VERTICAL_SPACING);
    } finally {
      a.recycle();
    }
  }
Example #24
0
  private void initView(Context context, AttributeSet attrs) {
    color = Color.WHITE;
    width = dpToPx(context, DEFAULT_WIDTH);
    shadowPosition = dpToPx(getContext(), DEFAULT_SHADOW_POSITION);

    if (null != attrs) {
      TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RotateLoading);
      color = typedArray.getColor(R.styleable.RotateLoading_loading_color, Color.WHITE);
      width =
          typedArray.getDimensionPixelSize(
              R.styleable.RotateLoading_loading_width, dpToPx(context, DEFAULT_WIDTH));
      shadowPosition =
          typedArray.getInt(R.styleable.RotateLoading_shadow_position, DEFAULT_SHADOW_POSITION);
      speedOfDegree =
          typedArray.getInt(R.styleable.RotateLoading_loading_speed, DEFAULT_SPEED_OF_DEGREE);
      typedArray.recycle();
    }
    speedOfArc = speedOfDegree / 4;
    mPaint = new Paint();
    mPaint.setColor(color);
    mPaint.setAntiAlias(true);
    mPaint.setStyle(Paint.Style.STROKE);
    mPaint.setStrokeWidth(width);
    mPaint.setStrokeCap(Paint.Cap.ROUND);
  }
 public DashboardViewAttr(Context context, AttributeSet attrs, int defStyleAttr) {
   TypedArray ta =
       context.obtainStyledAttributes(attrs, R.styleable.DashboardView, defStyleAttr, 0);
   mTikeCount = ta.getInt(R.styleable.DashboardView_tikeCount, 48);
   mTextSize =
       ta.getDimensionPixelSize(
           PxUtils.spToPx(R.styleable.DashboardView_android_textSize, context), 24);
   mText = ta.getString(R.styleable.DashboardView_android_text);
   //        progressHeight =
   // ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_progressHeight,context), 20);
   unit = ta.getString(R.styleable.DashboardView_Unit);
   textColor =
       ta.getColor(
           R.styleable.DashboardView_textColor,
           context.getResources().getColor(R.color.textColor));
   background = ta.getColor(R.styleable.DashboardView_backgroundColor, 0);
   startColor = ta.getColor(R.styleable.DashboardView_startProgressColor, 0);
   endColor = ta.getColor(R.styleable.DashboardView_endProgressColor, 0);
   startNum = ta.getInt(R.styleable.DashboardView_startNumber, 0);
   maxNum = ta.getInt(R.styleable.DashboardView_maxNumber, 120);
   padding = ta.getInt(PxUtils.dpToPx(R.styleable.DashboardView_padding, context), 0);
   progressColor =
       ta.getColor(
           R.styleable.DashboardView_progressColor,
           context.getResources().getColor(R.color.skyblue));
   ta.recycle();
 }
  public SwipeBackLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs);
    mDragHelper = ViewDragHelper.create(this, new ViewDragCallback());

    TypedArray a =
        context.obtainStyledAttributes(
            attrs, R.styleable.SwipeBackLayout, defStyle, R.style.SwipeBackLayout);

    int edgeSize = a.getDimensionPixelSize(R.styleable.SwipeBackLayout_edge_size, -1);
    if (edgeSize > 0) setEdgeSize(edgeSize);
    int mode = EDGE_FLAGS[a.getInt(R.styleable.SwipeBackLayout_edge_flag, 0)];
    setEdgeTrackingEnabled(mode);

    int shadowLeft =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_left, R.drawable.shadow_left);
    int shadowRight =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_right, R.drawable.shadow_right);
    int shadowBottom =
        a.getResourceId(R.styleable.SwipeBackLayout_shadow_bottom, R.drawable.shadow_bottom);
    setShadow(shadowLeft, EDGE_LEFT);
    setShadow(shadowRight, EDGE_RIGHT);
    setShadow(shadowBottom, EDGE_BOTTOM);
    a.recycle();
    final float density = getResources().getDisplayMetrics().density;
    final float minVel = MIN_FLING_VELOCITY * density;
    mDragHelper.setMinVelocity(minVel);
    mDragHelper.setMaxVelocity(minVel * 2f);
  }
Example #27
0
 public ActionBarContainer(Context context, AttributeSet attrs) {
   boolean z = true;
   super(context, attrs);
   setBackgroundDrawable(
       VERSION.SDK_INT >= 21
           ? new ActionBarBackgroundDrawableV21(this)
           : new ActionBarBackgroundDrawable(this));
   TypedArray a = context.obtainStyledAttributes(attrs, C0170R.styleable.ActionBar);
   this.mBackground = a.getDrawable(C0170R.styleable.ActionBar_background);
   this.mStackedBackground = a.getDrawable(C0170R.styleable.ActionBar_backgroundStacked);
   this.mHeight = a.getDimensionPixelSize(C0170R.styleable.ActionBar_height, -1);
   if (getId() == C0170R.id.split_action_bar) {
     this.mIsSplit = true;
     this.mSplitBackground = a.getDrawable(C0170R.styleable.ActionBar_backgroundSplit);
   }
   a.recycle();
   if (this.mIsSplit) {
     if (this.mSplitBackground != null) {
       z = false;
     }
   } else if (!(this.mBackground == null && this.mStackedBackground == null)) {
     z = false;
   }
   setWillNotDraw(z);
 }
 public LinearLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
   super(context, attrs, defStyleAttr, defStyleRes);
   this.mBaselineAligned = true;
   this.mBaselineAlignedChildIndex = -1;
   this.mBaselineChildTop = SHOW_DIVIDER_NONE;
   this.mGravity = 8388659;
   TypedArray a =
       context.obtainStyledAttributes(attrs, R.styleable.LinearLayout, defStyleAttr, defStyleRes);
   int index = a.getInt(VERTICAL, -1);
   if (index >= 0) {
     setOrientation(index);
   }
   index = a.getInt(SHOW_DIVIDER_NONE, -1);
   if (index >= 0) {
     setGravity(index);
   }
   boolean baselineAligned = a.getBoolean(SHOW_DIVIDER_MIDDLE, true);
   if (!baselineAligned) {
     setBaselineAligned(baselineAligned);
   }
   this.mWeightSum =
       a.getFloat(
           VERTICAL_GRAVITY_COUNT,
           android.view.WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE);
   this.mBaselineAlignedChildIndex = a.getInt(INDEX_FILL, -1);
   this.mUseLargestChild = a.getBoolean(6, false);
   setDividerDrawable(a.getDrawable(5));
   this.mShowDividers = a.getInt(7, SHOW_DIVIDER_NONE);
   this.mDividerPadding = a.getDimensionPixelSize(8, SHOW_DIVIDER_NONE);
   a.recycle();
 }
  public void init(
      @NonNull View view, @Nullable AttributeSet attrs, @NonNull TextPaint baseTextPaint) {
    final Context context = view.getContext();
    final int defColor = baseTextPaint.getColor();
    final int defPadding =
        context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_default_padding);
    final float minTextSize =
        context.getResources().getDimensionPixelSize(R.dimen.drag_direction_text_min_size);

    if (attrs == null) {
      for (DragDirection direction : DragDirection.values()) {
        final Text text = new Text(direction, view, minTextSize);
        text.init(baseTextPaint, null, DEF_SCALE, defColor, DEF_ALPHA, defPadding);
        texts.put(direction, text);
      }
      return;
    }
    final TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.DirectionText);
    final float scale = array.getFloat(R.styleable.DirectionText_directionTextScale, DEF_SCALE);
    final float alpha = array.getFloat(R.styleable.DirectionText_directionTextAlpha, DEF_ALPHA);
    final int color = array.getColor(R.styleable.DirectionText_directionTextColor, defColor);
    final int padding =
        array.getDimensionPixelSize(R.styleable.DirectionText_directionTextPadding, defPadding);
    for (DragDirection direction : DragDirection.values()) {
      final Text text = new Text(direction, view, minTextSize);
      text.init(baseTextPaint, array, scale, color, alpha, padding);
      texts.put(direction, text);
    }
    array.recycle();
  }
Example #30
0
 private void setCustomAttributes(AttributeSet attrs) {
   TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.roundedimageview);
   mBorderThickness = a.getDimensionPixelSize(R.styleable.roundedimageview_border_thickness, 0);
   mBorderOutsideColor =
       a.getColor(R.styleable.roundedimageview_border_outside_color, defaultColor);
   mBorderInsideColor = a.getColor(R.styleable.roundedimageview_border_inside_color, defaultColor);
 }