Java Code Examples for android.support.annotation.Dimension

The following are top voted examples for showing how to use android.support.annotation.Dimension. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: turn-layout-manager   File: TurnLayoutManager.java   View source code 6 votes vote down vote up
/**
 * Accounting for the settings of {@link Gravity} and {@link Orientation}, find the center point
 * around which this layout manager should arrange list items.  Place the resulting coordinates
 * into {@code out}, to avoid reallocation.
 */
private Point deriveCenter(@Gravity int gravity,
                           int orientation,
                           @Dimension int radius,
                           @Dimension int peekDistance,
                           Point out) {
    final int gravitySign = gravity == Gravity.START ? -1 : 1;
    final int distanceMultiplier = gravity == Gravity.START ? 0 : 1;
    int x, y;
    switch (orientation) {
        case Orientation.HORIZONTAL:
            y = (distanceMultiplier * getHeight()) + gravitySign * (Math.abs(radius - peekDistance));
            x = getWidth() / 2;
            break;
        case Orientation.VERTICAL:
        default:
            y = getHeight() / 2;
            x = (distanceMultiplier * getWidth()) + gravitySign * (Math.abs(radius - peekDistance));
            break;
    }
    out.set(x, y);
    return out;
}
 
Example 2
Project: turn-layout-manager   File: TurnLayoutManager.java   View source code 6 votes vote down vote up
/**
 * Set bumper offsets on child views for {@link Orientation#HORIZONTAL}
 */
private void setChildOffsetsHorizontal(@Gravity int gravity,
                                       @Dimension int radius,
                                       Point center,
                                       int peekDistance) {
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int yOffset = (int) resolveOffsetY(radius, child.getX() + child.getWidth() / 2, center, peekDistance);
        final int y = gravity == Gravity.START ? yOffset + layoutParams.getMarginStart()
                : getHeight() - yOffset - child.getHeight() - layoutParams.getMarginStart();

        child.layout(child.getLeft(), y, child.getRight(), child.getHeight() + y);
        setChildRotationHorizontal(gravity, child, radius, center);
    }
}
 
Example 3
Project: RLibrary   File: TurnLayoutManager.java   View source code 6 votes vote down vote up
/**
 * Accounting for the settings of {@link Gravity} and {@link Orientation}, find the center point
 * around which this layout manager should arrange list items.  Place the resulting coordinates
 * into {@code out}, to avoid reallocation.
 */
private Point deriveCenter(@Gravity int gravity,
                           int orientation,
                           @Dimension int radius,
                           @Dimension int peekDistance,
                           Point out) {
    final int gravitySign = gravity == Gravity.START ? -1 : 1;
    final int distanceMultiplier = gravity == Gravity.START ? 0 : 1;
    int x, y;
    switch (orientation) {
        case Orientation.HORIZONTAL:
            y = (distanceMultiplier * getHeight()) + gravitySign * (Math.abs(radius - peekDistance));
            x = getWidth() / 2;
            break;
        case Orientation.VERTICAL:
        default:
            y = getHeight() / 2;
            x = (distanceMultiplier * getWidth()) + gravitySign * (Math.abs(radius - peekDistance));
            break;
    }
    out.set(x, y);
    return out;
}
 
Example 4
Project: RLibrary   File: TurnLayoutManager.java   View source code 6 votes vote down vote up
/**
 * Set bumper offsets on child views for {@link Orientation#HORIZONTAL}
 */
private void setChildOffsetsHorizontal(@Gravity int gravity,
                                       @Dimension int radius,
                                       Point center,
                                       int peekDistance) {
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int yOffset = (int) resolveOffsetY(radius, child.getX() + child.getWidth() / 2, center, peekDistance);
        final int y = gravity == Gravity.START ? yOffset + layoutParams.getMarginStart()
                : getHeight() - yOffset - child.getHeight() - layoutParams.getMarginStart();

        child.layout(child.getLeft(), y, child.getRight(), child.getHeight() + y);
        setChildRotationHorizontal(gravity, child, radius, center);
    }
}
 
Example 5
Project: amplify   File: DisplayUtils.java   View source code 6 votes vote down vote up
@Px
public static int dpToPx(@NonNull final Context context, @Dimension(unit = DP) final int dp) {
    if (dp < 0) {
        throw new IllegalStateException("Dimension must be > 0.");
    }

    if (dp == 0) {
        return 0;
    }

    final Resources resources = context.getResources();
    final DisplayMetrics displayMetrics = resources.getDisplayMetrics();
    final float floatResult = dp * ((float) displayMetrics.densityDpi / DENSITY_DEFAULT);

    return max(1, round(floatResult));
}
 
Example 6
Project: PatternLockView   File: PatternLockView.java   View source code 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 7
Project: turn-layout-manager   File: TurnLayoutManager.java   View source code 5 votes vote down vote up
/**
 * Traffic method to divert calls based on {@link Orientation}.
 *
 * @see #setChildOffsetsVertical(int, int, Point, int)
 * @see #setChildOffsetsHorizontal(int, int, Point, int)
 */
private void setChildOffsets(@Gravity int gravity,
                             int orientation,
                             @Dimension int radius,
                             Point center,
                             int peekDistance) {
    if (orientation == VERTICAL) {
        setChildOffsetsVertical(gravity, radius, center, peekDistance);
    } else if (orientation == HORIZONTAL) {
        setChildOffsetsHorizontal(gravity, radius, center, peekDistance);
    }
}
 
Example 8
Project: turn-layout-manager   File: TurnLayoutManager.java   View source code 5 votes vote down vote up
/**
 * Set the bumper offsets on child views for {@link Orientation#VERTICAL}
 */
private void setChildOffsetsVertical(@Gravity int gravity,
                                     @Dimension int radius,
                                     Point center,
                                     int peekDistance) {
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int xOffset = (int) resolveOffsetX(radius, child.getY() + child.getHeight() / 2, center, peekDistance);
        final int x = gravity == Gravity.START ? xOffset + layoutParams.getMarginStart()
                : getWidth() - xOffset - child.getWidth() - layoutParams.getMarginStart();
        child.layout(x, child.getTop(), child.getWidth() + x, child.getBottom());
        setChildRotationVertical(gravity, child, radius, center);
    }
}
 
Example 9
Project: SingleSelectBar   File: ResHelper.java   View source code 5 votes vote down vote up
boolean setTabStrokeWidth(@Dimension int strokeWidth) {
    boolean hasChanged = false;
    if (this.strokeWidth != strokeWidth) {
        this.strokeWidth = strokeWidth;
        updateCornerStateDrawable();
        hasChanged = true;
    }
    return hasChanged;
}
 
Example 10
Project: SingleSelectBar   File: SingleSelectBar.java   View source code 5 votes vote down vote up
/**
 * Set a dimension for border and divider.
 *
 * @param width The width of border and divider.
 */
public void setTabStrokeWidth(@Dimension int width) {
    if (resHelper.setTabStrokeWidth(width)) {
        updateBackground();
        invalidate();
    }
}
 
Example 11
Project: Customerly-Android-SDK   File: IU_Utils.java   View source code 5 votes vote down vote up
@Contract(pure = true)
@Px static int px(@Dimension(unit = Dimension.DP) int dp) {
    float dpi = Resources.getSystem().getDisplayMetrics().density;
    dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi;
    dpi = dpi == 0 ? 1f : dpi;
    return (int) (dp * dpi);
}
 
Example 12
Project: RLibrary   File: TurnLayoutManager.java   View source code 5 votes vote down vote up
/**
 * Traffic method to divert calls based on {@link Orientation}.
 *
 * @see #setChildOffsetsVertical(int, int, Point, int)
 * @see #setChildOffsetsHorizontal(int, int, Point, int)
 */
private void setChildOffsets(@Gravity int gravity,
                             int orientation,
                             @Dimension int radius,
                             Point center,
                             int peekDistance) {
    if (orientation == VERTICAL) {
        setChildOffsetsVertical(gravity, radius, center, peekDistance);
    } else if (orientation == HORIZONTAL) {
        setChildOffsetsHorizontal(gravity, radius, center, peekDistance);
    }
}
 
Example 13
Project: RLibrary   File: TurnLayoutManager.java   View source code 5 votes vote down vote up
/**
 * Set the bumper offsets on child views for {@link Orientation#VERTICAL}
 */
private void setChildOffsetsVertical(@Gravity int gravity,
                                     @Dimension int radius,
                                     Point center,
                                     int peekDistance) {
    for (int i = 0; i < getChildCount(); i++) {
        View child = getChildAt(i);
        RecyclerView.LayoutParams layoutParams = (RecyclerView.LayoutParams) child.getLayoutParams();
        final int xOffset = (int) resolveOffsetX(radius, child.getY() + child.getHeight() / 2, center, peekDistance);
        final int x = gravity == Gravity.START ? xOffset + layoutParams.getMarginStart()
                : getWidth() - xOffset - child.getWidth() - layoutParams.getMarginStart();
        child.layout(x, child.getTop(), child.getWidth() + x, child.getBottom());
        setChildRotationVertical(gravity, child, radius, center);
    }
}
 
Example 14
Project: BottomBar   File: MiscUtils.java   View source code 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 15
Project: bigbang   File: MetricsHelper.java   View source code 5 votes vote down vote up
/**
 * Retrieves the toolbar height of the current app theme.
 *
 * @param theme the device {@link Theme}
 * @param actionBarSize the current {@link ActionBar} size
 * @return the toolbar height of the current app theme
 */
@Dimension(unit = Dimension.DP)
public static int getToolbarHeight(@NonNull Theme theme, @AttrRes int actionBarSize) {
  final TypedArray styledAttributes = theme.obtainStyledAttributes(new int[] {actionBarSize});
  int toolbarHeight = (int) styledAttributes.getDimension(0, 0);
  styledAttributes.recycle();
  return toolbarHeight;
}
 
Example 16
Project: groupie   File: InsetItemDecoration.java   View source code 5 votes vote down vote up
public InsetItemDecoration(@ColorInt int backgroundColor, @Dimension int padding, String key, String value) {
    this.key = key;
    this.value = value;
    paint = new Paint();
    paint.setColor(backgroundColor);
    this.padding = padding;
}
 
Example 17
Project: aptoide-client-v8   File: CommentWidget.java   View source code 5 votes vote down vote up
private void setLayoutLeftPadding(ComplexComment complexComment) {
  final int level = complexComment.getLevel();
  int baseMargin =
      AptoideUtils.ScreenU.getPixelsForDip(MARGIN_IN_DIP, getContext().getResources());
  @Dimension int leftMargin = level < 2 ? baseMargin : baseMargin * level;
  outerLayout.setPadding(leftMargin, outerLayout.getPaddingTop(), baseMargin,
      outerLayout.getPaddingBottom());
}
 
Example 18
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the primary text font size.
 *
 * @param size The primary text font size
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setPrimaryTextSize(@Dimension final float size)
{
    mPrimaryTextSize = size;
    return (T) this;
}
 
Example 19
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the secondary text font size.
 *
 * @param size The secondary text font size
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setSecondaryTextSize(@Dimension final float size)
{
    mSecondaryTextSize = size;
    return (T) this;
}
 
Example 20
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the text left and right padding.
 *
 * @param padding The padding on the text left and right
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setTextPadding(@Dimension final float padding)
{
    mTextPadding = padding;
    return (T) this;
}
 
Example 21
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the distance between the primary and secondary text.
 *
 * @param separation The distance separation between the primary and secondary text
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setTextSeparation(@Dimension final float separation)
{
    mTextSeparation = separation;
    return (T) this;
}
 
Example 22
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the padding between the text and the focal point.
 *
 * @param padding The distance between the text and focal
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setFocalPadding(@Dimension final float padding)
{
    mFocalPadding = padding;
    return (T) this;
}
 
Example 23
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the max width that the primary and secondary text can be.
 *
 * @param width The max width that the text can reach
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setMaxTextWidth(@Dimension final float width)
{
    mMaxTextWidth = width;
    return (T) this;
}
 
Example 24
Project: MaterialTapTargetPrompt   File: PromptOptions.java   View source code 5 votes vote down vote up
/**
 * Set the focal point radius.
 *
 * @param radius The focal radius
 * @return This Builder object to allow for chaining of calls to set methods
 */
@NonNull
public T setFocalRadius(@Dimension final float radius)
{
    mFocalRadius = radius;
    return (T) this;
}
 
Example 25
Project: MaterialTapTargetPrompt   File: RectanglePromptFocal.java   View source code 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 26
Project: material-components-android   File: ChipGroup.java   View source code 5 votes vote down vote up
/** Sets the horizontal spacing between chips in this group. */
public void setChipSpacingHorizontal(@Dimension int chipSpacingHorizontal) {
  if (this.chipSpacingHorizontal != chipSpacingHorizontal) {
    this.chipSpacingHorizontal = chipSpacingHorizontal;
    requestLayout();
  }
}
 
Example 27
Project: material-components-android   File: ChipGroup.java   View source code 5 votes vote down vote up
/** Sets the vertical spacing between chips in this group. */
public void setChipSpacingVertical(@Dimension int chipSpacingVertical) {
  if (this.chipSpacingVertical != chipSpacingVertical) {
    this.chipSpacingVertical = chipSpacingVertical;
    requestLayout();
  }
}
 
Example 28
Project: material-components-android   File: TabLayout.java   View source code 5 votes vote down vote up
@Dimension(unit = Dimension.DP)
private int getDefaultHeight() {
  boolean hasIconAndText = false;
  for (int i = 0, count = tabs.size(); i < count; i++) {
    Tab tab = tabs.get(i);
    if (tab != null && tab.getIcon() != null && !TextUtils.isEmpty(tab.getText())) {
      hasIconAndText = true;
      break;
    }
  }
  return (hasIconAndText && !inlineLabel) ? DEFAULT_HEIGHT_WITH_TEXT_ICON : DEFAULT_HEIGHT;
}
 
Example 29
Project: Customerly-Android-SDK   File: IU_Utils.java   View source code 5 votes vote down vote up
@Contract(pure = true)
@Px static int px(@Dimension(unit = Dimension.DP) int dp) {
    float dpi = Resources.getSystem().getDisplayMetrics().density;
    dpi = dpi > 100/*120, 160, 213, 240, 320, 480 or 640 dpi*/ ? dpi / 160f : dpi;
    dpi = dpi == 0 ? 1f : dpi;
    return (int) (dp * dpi);
}
 
Example 30
Project: plaid   File: InsetDividerDecoration.java   View source code 5 votes vote down vote up
public InsetDividerDecoration(@Dimension int dividerHeight,
                              @Dimension int leftInset,
                              @ColorInt int dividerColor) {
    inset = leftInset;
    height = dividerHeight;
    paint = new Paint();
    paint.setColor(dividerColor);
    paint.setStyle(Paint.Style.STROKE);
    paint.setStrokeWidth(dividerHeight);
}
 
Example 31
Project: plaid   File: GridItemDividerDecoration.java   View source code 5 votes vote down vote up
public GridItemDividerDecoration(@Dimension int dividerSize,
                                 @ColorInt int dividerColor) {
    this.dividerSize = dividerSize;
    paint = new Paint();
    paint.setColor(dividerColor);
    paint.setStyle(Paint.Style.FILL);
}
 
Example 32
Project: NoiseCapture   File: CommentActivity.java   View source code 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 33
Project: number-keyboard   File: NumberKeyboard.java   View source code 4 votes vote down vote up
/**
 * Sets number keys text size.
 */
public void setNumberKeyTextSize(@Dimension int size) {
    for (TextView key : numericKeys) {
        key.setTextSize(TypedValue.COMPLEX_UNIT_PX, size);
    }
}
 
Example 34
Project: PatternLockView   File: PatternLockView.java   View source code 4 votes vote down vote up
public void setPathWidth(@Dimension int pathWidth) {
    mPathWidth = pathWidth;

    initView();
    invalidate();
}
 
Example 35
Project: PatternLockView   File: PatternLockView.java   View source code 4 votes vote down vote up
public void setDotSelectedSize(@Dimension int dotSelectedSize) {
    mDotSelectedSize = dotSelectedSize;
}
 
Example 36
Project: turn-layout-manager   File: TurnLayoutManager.java   View source code 4 votes vote down vote up
/**
 * Create a {@link TurnLayoutManager} with default settings for gravity, orientation, and rotation.
 */
public TurnLayoutManager(Context context,
                         @Dimension int radius,
                         @Dimension int peekDistance) {
    this(context, Gravity.START, Orientation.VERTICAL, radius, peekDistance, false);
}
 
Example 37
Project: genius-groupie   File: InsetItemDecoration.java   View source code 4 votes vote down vote up
public InsetItemDecoration(@ColorInt int backgroundColor, @Dimension int padding) {
    paint = new Paint();
    paint.setColor(backgroundColor);
    this.padding = padding;
}
 
Example 38
Project: PasscodeView   File: PatternCell.java   View source code 4 votes vote down vote up
@Dimension
public abstract float getCellRadius();
 
Example 39
Project: PasscodeView   File: CirclePatternCell.java   View source code 4 votes vote down vote up
@Dimension
@Override
public float getCellRadius() {
    return mRadius * 2;
}
 
Example 40
Project: PasscodeView   File: CirclePatternCell.java   View source code 4 votes vote down vote up
@Dimension
public float getRadius() {
    return mRadius;
}