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 Project: SimpleRatingBar   Author: FlyingPumba   File: StarsSeparationFragment.java    License: 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 Project: styT   Author: stytooldex   File: RectanglePromptFocal.java    License: 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 #3
Source Project: PatternLockView   Author: aritraroy   File: PatternLockView.java    License: 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 Project: proSwipeButton   Author: shadowfaxtech   File: ProSwipeButton.java    License: 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 Project: BottomBar   Author: roughike   File: MiscUtils.java    License: 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 #6
Source Project: LightAdapter   Author: lufficc   File: DefaultItemDecoration.java    License: 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 #7
Source Project: XBanner   Author: xiaohaibin   File: XBanner.java    License: 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 #8
Source Project: SimpleRatingBar   Author: FlyingPumba   File: SimpleRatingBar.java    License: 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 #9
Source Project: SimpleRatingBar   Author: FlyingPumba   File: SimpleRatingBar.java    License: 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 Project: SimpleRatingBar   Author: FlyingPumba   File: SimpleRatingBar.java    License: 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 Project: NoiseCapture   Author: Ifsttar   File: CommentActivity.java    License: 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 #12
Source Project: CircularImageView   Author: abdularis   File: AvatarImageView.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
public float getTextSize() {
    return mTextPaint.getTextSize();
}
 
Example #13
Source Project: CircularImageView   Author: abdularis   File: AvatarImageView.java    License: Apache License 2.0 4 votes vote down vote up
public void setTextSize(@Dimension float size) {
    mTextPaint.setTextSize(size);
    updateTextBounds();
    invalidate();
}
 
Example #14
Source Project: CircularImageView   Author: abdularis   File: CircleImageView.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
public float getStrokeWidth() {
    return mStrokePaint.getStrokeWidth();
}
 
Example #15
Source Project: CircularImageView   Author: abdularis   File: CircleImageView.java    License: Apache License 2.0 4 votes vote down vote up
public void setStrokeWidth(@Dimension float width) {
    mStrokePaint.setStrokeWidth(width);
    invalidate();
}
 
Example #16
Source Project: PatternLockView   Author: aritraroy   File: PatternLockView.java    License: Apache License 2.0 4 votes vote down vote up
public void setPathWidth(@Dimension int pathWidth) {
    mPathWidth = pathWidth;

    initView();
    invalidate();
}
 
Example #17
Source Project: PatternLockView   Author: aritraroy   File: PatternLockView.java    License: Apache License 2.0 4 votes vote down vote up
public void setDotSelectedSize(@Dimension int dotSelectedSize) {
    mDotSelectedSize = dotSelectedSize;
}
 
Example #18
Source Project: PasscodeView   Author: kevalpatel2106   File: CirclePatternCell.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public CirclePatternCell.Builder setRadius(@Dimension final float radius) {
    mRadius = radius;
    return this;
}
 
Example #19
Source Project: PasscodeView   Author: kevalpatel2106   File: CirclePatternCell.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public CirclePatternCell.Builder setStrokeWidth(@Dimension final float strokeWidth) {
    mStrokeWidth = strokeWidth;
    return this;
}
 
Example #20
Source Project: PasscodeView   Author: kevalpatel2106   File: DotPatternCell.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public DotPatternCell.Builder setRadius(@Dimension final float radius) {
    mRadius = radius;
    return this;
}
 
Example #21
Source Project: PasscodeView   Author: kevalpatel2106   File: BasePasscodeView.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
public float getFingerPrintStatusTextSize() {
    return mBoxFingerprint.getStatusTextSize();
}
 
Example #22
Source Project: PasscodeView   Author: kevalpatel2106   File: BasePasscodeView.java    License: Apache License 2.0 4 votes vote down vote up
public void setFingerPrintStatusTextSize(@Dimension final float statusTextSize) {
    mBoxFingerprint.setStatusTextSize(statusTextSize);
    invalidate();
}
 
Example #23
Source Project: PasscodeView   Author: kevalpatel2106   File: Indicator.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
public abstract float getIndicatorWidth();
 
Example #24
Source Project: PasscodeView   Author: kevalpatel2106   File: CircleIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public CircleIndicator.Builder setIndicatorRadius(@Dimension final float indicatorRadius) {
    mIndicatorRadius = indicatorRadius;
    return this;
}
 
Example #25
Source Project: PasscodeView   Author: kevalpatel2106   File: CircleIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public CircleIndicator.Builder setIndicatorStrokeWidth(@Dimension final float indicatorStrokeWidth) {
    mIndicatorStrokeWidth = indicatorStrokeWidth;
    return this;
}
 
Example #26
Source Project: PasscodeView   Author: kevalpatel2106   File: CircleIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
@Override
public float getIndicatorWidth() {
    return mIndicatorRadius;
}
 
Example #27
Source Project: PasscodeView   Author: kevalpatel2106   File: DotIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public DotIndicator.Builder setIndicatorRadius(@Dimension final float indicatorRadius) {
    mIndicatorRadius = indicatorRadius;
    return this;
}
 
Example #28
Source Project: PasscodeView   Author: kevalpatel2106   File: DotIndicator.java    License: Apache License 2.0 4 votes vote down vote up
@Dimension
@Override
public float getIndicatorWidth() {
    return mIndicatorRadius;
}
 
Example #29
Source Project: PasscodeView   Author: kevalpatel2106   File: SquareKey.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public Builder setKeyPadding(@Dimension final float keyPadding) {
    mKeyPadding = keyPadding;
    return this;
}
 
Example #30
Source Project: PasscodeView   Author: kevalpatel2106   File: RoundKey.java    License: Apache License 2.0 4 votes vote down vote up
@NonNull
public RoundKey.Builder setKeyPadding(@Dimension final float keyPadding) {
    mKeyPadding = keyPadding;
    return this;
}