android.support.annotation.Dimension Java Examples

The following examples show how to use android.support.annotation.Dimension. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: StarsSeparationFragment.java    From SimpleRatingBar with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
  float limit = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 25, getResources().getDisplayMetrics());
  // Handle item selection
  switch (item.getItemId()) {
    case R.id.menu_action_refresh:
      if (ratingBar1.getStarsSeparation() <= limit) {
        ratingBar1.setStarsSeparation(ratingBar1.getStarsSeparation(Dimension.DP) + 4, Dimension.DP);
        ratingBar2.setStarsSeparation(ratingBar2.getStarsSeparation(Dimension.DP) + 4, Dimension.DP);
        ratingBar3.setStarsSeparation(ratingBar3.getStarsSeparation(Dimension.DP) + 4, Dimension.DP);
        ratingBar4.setStarsSeparation(ratingBar4.getStarsSeparation(Dimension.DP) + 4, Dimension.DP);
        ratingBar5.setStarsSeparation(ratingBar5.getStarsSeparation(Dimension.DP) + 4, Dimension.DP);
      } else {
        ratingBar1.setStarsSeparation(4, Dimension.DP);
        ratingBar2.setStarsSeparation(6, Dimension.DP);
        ratingBar3.setStarsSeparation(8, Dimension.DP);
        ratingBar4.setStarsSeparation(10, Dimension.DP);
        ratingBar5.setStarsSeparation(12, Dimension.DP);
      }
      return false;
    default:
      return super.onOptionsItemSelected(item);
  }
}
 
Example #2
Source File: CommentActivity.java    From NoiseCapture with GNU General Public License v3.0 5 votes vote down vote up
private void addTag(String tagName, int id, ViewGroup column, int color) {
    ToggleButton tagButton = new ToggleButton(this);
    if(color != -1) {
        LinearLayout colorBox = new LinearLayout(this);
        // Convert the dps to pixels, based on density scale
        final int tagPaddingPx = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                1, getResources().getDisplayMetrics());
        final int tagPaddingPxBottom = (int) TypedValue.applyDimension(TypedValue
                .COMPLEX_UNIT_DIP,
                3, getResources().getDisplayMetrics());
        //use a GradientDrawable with only one color set, to make it a solid color
        colorBox.setBackgroundResource(R.drawable.tag_round_corner);
        GradientDrawable gradientDrawable = (GradientDrawable) colorBox.getBackground();
        gradientDrawable.setColor(color);
        LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams
                .MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT);
        params.setMargins(tagPaddingPx,tagPaddingPx,tagPaddingPx,tagPaddingPxBottom);
        colorBox.setLayoutParams(params);
        colorBox.addView(tagButton);
        column.addView(colorBox);
    } else {
        column.addView(tagButton);
    }
    tagButton.setTextOff(tagName);
    tagButton.setTextOn(tagName);
    boolean isChecked = checkedTags.contains(id);
    tagButton.setChecked(isChecked);
    if(isChecked) {
        tagButton.setTextColor(selectedColor);
    }
    tagButton.setOnCheckedChangeListener(new TagStateListener(id, checkedTags));
    tagButton.setMinHeight(0);
    tagButton.setMinimumHeight(0);
    tagButton.setTextSize(Dimension.SP, 12);
    tagButton.setEnabled(record == null || record.getUploadId().isEmpty());
    tagButton.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    tagButton.invalidate();
}
 
Example #3
Source File: PatternLockView.java    From PatternLockView with Apache License 2.0 5 votes vote down vote up
public void setDotNormalSize(@Dimension int dotNormalSize) {
    mDotNormalSize = dotNormalSize;

    for (int i = 0; i < sDotCount; i++) {
        for (int j = 0; j < sDotCount; j++) {
            mDotStates[i][j] = new DotState();
            mDotStates[i][j].mSize = mDotNormalSize;
        }
    }

    invalidate();
}
 
Example #4
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 5 votes vote down vote up
/**
 * How much of the button must the user swipe to trigger the OnSwipeListener successfully
 *
 * @param swipeDistance float from 0.0 to 1.0 where 1.0 means user must swipe the button fully from end to end. Default is 0.85.
 */
public void setSwipeDistance(@Dimension float swipeDistance) {
    if (swipeDistance > 1.0f) {
        swipeDistance = 1.0f;
    }
    if (swipeDistance < 0.0f) {
        swipeDistance = 0.0f;
    }
    this.swipeDistance = swipeDistance;
}
 
Example #5
Source File: RectanglePromptFocal.java    From styT with Apache License 2.0 5 votes vote down vote up
/**
 * Set the padding between the target bounds and the rectangle edge.
 *
 * @param padding The distance from the target edge to the rectangle edge.
 * @return This prompt focal.
 */
@NonNull
public RectanglePromptFocal setTargetPadding(@Dimension final float padding)
{
    mPadding = padding;
    return this;
}
 
Example #6
Source File: MiscUtils.java    From BottomBar with Apache License 2.0 5 votes vote down vote up
/**
 * Converts dps to pixels nicely.
 *
 * @param context the Context for getting the resources
 * @param dp      dimension in dps
 * @return dimension in pixels
 */
protected static int dpToPixel(@NonNull Context context, @Dimension(unit = DP) float dp) {
    Resources resources = context.getResources();
    DisplayMetrics metrics = resources.getDisplayMetrics();

    try {
        return (int) (dp * metrics.density);
    } catch (NoSuchFieldError ignored) {
        return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, metrics);
    }
}
 
Example #7
Source File: DefaultItemDecoration.java    From LightAdapter with Apache License 2.0 5 votes vote down vote up
public DefaultItemDecoration(@ColorInt int backgroundColor,
                             @ColorInt int dividerColor,
                             @Dimension int middlePaddingLeft) {
    mBackgroundPaint = new Paint();
    mBackgroundPaint.setColor(backgroundColor);
    mDividerPaint = new Paint();
    mDividerPaint.setColor(dividerColor);

    mPaddingLeft = middlePaddingLeft;
}
 
Example #8
Source File: XBanner.java    From XBanner with Apache License 2.0 5 votes vote down vote up
/**
 * 设置viewpager间距
 * @param viewPagerMargin 单位dp
 */
public void setViewPagerMargin(@Dimension int viewPagerMargin) {
    this.mViewPagerMargin = viewPagerMargin;
    if (mViewPager != null) {
        mViewPager.setPageMargin(XBannerUtils.dp2px(getContext(), viewPagerMargin));
    }
}
 
Example #9
Source File: SimpleRatingBar.java    From SimpleRatingBar with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to convert a value in the given dimension to pixels.
 * @param value
 * @param dimen
 * @return
 */
private float valueToPixels(float value, @Dimension int dimen) {
  switch (dimen) {
    case Dimension.DP:
      return applyDimension(COMPLEX_UNIT_DIP, value, getResources().getDisplayMetrics());
    case Dimension.SP:
      return applyDimension(COMPLEX_UNIT_SP, value, getResources().getDisplayMetrics());
    default:
      return value;
  }
}
 
Example #10
Source File: SimpleRatingBar.java    From SimpleRatingBar with Apache License 2.0 5 votes vote down vote up
/**
 * Convenience method to convert a value from pixels to the given dimension.
 * @param value
 * @param dimen
 * @return
 */
private float valueFromPixels(float value, @Dimension int dimen) {
  switch (dimen) {
    case Dimension.DP:
      return value / getResources().getDisplayMetrics().density;
    case Dimension.SP:
      return value / getResources().getDisplayMetrics().scaledDensity;
    default:
      return value;
  }
}
 
Example #11
Source File: SimpleRatingBar.java    From SimpleRatingBar with Apache License 2.0 5 votes vote down vote up
/**
 * Parses attributes defined in XML.
 */
private void parseAttrs(AttributeSet attrs) {
  TypedArray arr = getContext().obtainStyledAttributes(attrs, R.styleable.SimpleRatingBar);

  borderColor = arr.getColor(R.styleable.SimpleRatingBar_srb_borderColor, getResources().getColor(R.color.srb_golden_stars));
  fillColor = arr.getColor(R.styleable.SimpleRatingBar_srb_fillColor, borderColor);
  starBackgroundColor = arr.getColor(R.styleable.SimpleRatingBar_srb_starBackgroundColor, Color.TRANSPARENT);
  backgroundColor = arr.getColor(R.styleable.SimpleRatingBar_srb_backgroundColor, Color.TRANSPARENT);

  pressedBorderColor = arr.getColor(R.styleable.SimpleRatingBar_srb_pressedBorderColor, borderColor);
  pressedFillColor = arr.getColor(R.styleable.SimpleRatingBar_srb_pressedFillColor, fillColor);
  pressedStarBackgroundColor = arr.getColor(R.styleable.SimpleRatingBar_srb_pressedStarBackgroundColor, starBackgroundColor);
  pressedBackgroundColor = arr.getColor(R.styleable.SimpleRatingBar_srb_pressedBackgroundColor, backgroundColor);

  numberOfStars = arr.getInteger(R.styleable.SimpleRatingBar_srb_numberOfStars, 5);

  starsSeparation = arr.getDimensionPixelSize(R.styleable.SimpleRatingBar_srb_starsSeparation, (int)valueToPixels(4, Dimension.DP));
  maxStarSize = arr.getDimensionPixelSize(R.styleable.SimpleRatingBar_srb_maxStarSize, Integer.MAX_VALUE);
  desiredStarSize = arr.getDimensionPixelSize(R.styleable.SimpleRatingBar_srb_starSize, Integer.MAX_VALUE);
  stepSize = arr.getFloat(R.styleable.SimpleRatingBar_srb_stepSize, 0.1f);
  starBorderWidth = arr.getFloat(R.styleable.SimpleRatingBar_srb_starBorderWidth, 5f);
  starCornerRadius = arr.getFloat(R.styleable.SimpleRatingBar_srb_starCornerRadius, 6f);

  rating = normalizeRating(arr.getFloat(R.styleable.SimpleRatingBar_srb_rating, 0f));
  isIndicator = arr.getBoolean(R.styleable.SimpleRatingBar_srb_isIndicator, false);
  drawBorderEnabled = arr.getBoolean(R.styleable.SimpleRatingBar_srb_drawBorderEnabled, true);
  gravity = Gravity.fromId(arr.getInt(R.styleable.SimpleRatingBar_srb_gravity, Gravity.Left.id));

  arr.recycle();

  validateAttrs();
}
 
Example #12
Source File: CircleImageView.java    From CircularImageView with Apache License 2.0 4 votes vote down vote up
public void setStrokeWidth(@Dimension float width) {
    mStrokePaint.setStrokeWidth(width);
    invalidate();
}
 
Example #13
Source File: PatternLockView.java    From PatternLockView with Apache License 2.0 4 votes vote down vote up
public void setPathWidth(@Dimension int pathWidth) {
    mPathWidth = pathWidth;

    initView();
    invalidate();
}
 
Example #14
Source File: CircleIndicator.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@NonNull
public CircleIndicator.Builder setIndicatorStrokeWidth(@Dimension final float indicatorStrokeWidth) {
    mIndicatorStrokeWidth = indicatorStrokeWidth;
    return this;
}
 
Example #15
Source File: CircleIndicator.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@Dimension
@Override
public float getIndicatorWidth() {
    return mIndicatorRadius;
}
 
Example #16
Source File: DotIndicator.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@NonNull
public DotIndicator.Builder setIndicatorRadius(@Dimension final float indicatorRadius) {
    mIndicatorRadius = indicatorRadius;
    return this;
}
 
Example #17
Source File: SquareKey.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@NonNull
public Builder setKeyPadding(@Dimension final float keyPadding) {
    mKeyPadding = keyPadding;
    return this;
}
 
Example #18
Source File: RoundKey.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@NonNull
public RoundKey.Builder setKeyPadding(@Dimension final float keyPadding) {
    mKeyPadding = keyPadding;
    return this;
}
 
Example #19
Source File: RectKey.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@NonNull
public Builder setKeyPadding(@Dimension float keyPadding) {
    mKeyPadding = keyPadding;
    return this;
}
 
Example #20
Source File: Spans.java    From spanner with Apache License 2.0 4 votes vote down vote up
/**
 * @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int)
 */
public static Span sizePX(@Dimension(unit = Dimension.PX) final int px) {
    return new Span(new AbsoluteSizeSpanBuilder(px, false));
}
 
Example #21
Source File: DotIndicator.java    From PasscodeView with Apache License 2.0 4 votes vote down vote up
@Dimension
@Override
public float getIndicatorWidth() {
    return mIndicatorRadius;
}
 
Example #22
Source File: Spans.java    From spanner with Apache License 2.0 4 votes vote down vote up
/**
 * @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int, boolean)
 */
public static Span sizeDP(@Dimension(unit = Dimension.DP) final int dp) {
    return new Span(new AbsoluteSizeSpanBuilder(dp, true));
}
 
Example #23
Source File: Spans.java    From spanner with Apache License 2.0 4 votes vote down vote up
/**
 * @see android.text.style.AbsoluteSizeSpan#AbsoluteSizeSpan(int, boolean)
 */
public static Span sizeSP(@Dimension(unit = Dimension.SP) final int sp) {
    return new Span(new AbsoluteSizeSpanBuilder(sp, true));
}
 
Example #24
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 4 votes vote down vote up
public void setTextSize(@Dimension float textSize) {
    this.textSize = textSize;
    contentTv.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
}
 
Example #25
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 4 votes vote down vote up
@Dimension
public float getTextSize() {
    return this.textSize;
}
 
Example #26
Source File: UniversalDraweeView.java    From JianshuApp with GNU General Public License v3.0 4 votes vote down vote up
public void setCornerRadius(@Dimension float radius) {
    ensureRoundingParams();
    mDraweeHierarchy.getRoundingParams().setCornersRadius(radius);
}
 
Example #27
Source File: HorizontalItemDecoration.java    From JianshuApp with GNU General Public License v3.0 4 votes vote down vote up
public HorizontalItemDecoration(@Dimension int space) {
    this.mContext = AppUtils.getContext();
    this.space = space;
}
 
Example #28
Source File: ProSwipeButton.java    From proSwipeButton with MIT License 4 votes vote down vote up
@Dimension
public float getSwipeDistance() {
    return this.swipeDistance;
}
 
Example #29
Source File: BubblePageIndicator.java    From BubblePagerIndicator with Apache License 2.0 4 votes vote down vote up
public void setRadius(@Dimension float radius) {
    this.radius = radius;
    forceLayoutChanges();
}
 
Example #30
Source File: BubblePageIndicator.java    From BubblePagerIndicator with Apache License 2.0 4 votes vote down vote up
public void setMarginBetweenCircles(@Dimension float margin) {
    this.marginBetweenCircles = margin;
    forceLayoutChanges();
}