Java Code Examples for me.jfenn.androidutils.DimenUtils#dpToPx()

The following examples show how to use me.jfenn.androidutils.DimenUtils#dpToPx() . 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: SlideActionView.java    From SlideActionView with Apache License 2.0 5 votes vote down vote up
private void init() {
    handleRadius = DimenUtils.dpToPx(12);
    expandedHandleRadius = DimenUtils.dpToPx(32);
    selectionRadius = DimenUtils.dpToPx(42);
    rippleRadius = DimenUtils.dpToPx(140);

    selected = new AnimatedFloat(0);
    ripples = new HashMap<>();

    normalPaint = new Paint();
    normalPaint.setStyle(Paint.Style.FILL);
    normalPaint.setColor(Color.GRAY);
    normalPaint.setAntiAlias(true);
    normalPaint.setDither(true);

    outlinePaint = new Paint();
    outlinePaint.setStyle(Paint.Style.STROKE);
    outlinePaint.setColor(Color.GRAY);
    outlinePaint.setAntiAlias(true);
    outlinePaint.setDither(true);

    bitmapPaint = new Paint();
    bitmapPaint.setStyle(Paint.Style.FILL);
    bitmapPaint.setColor(Color.GRAY);
    bitmapPaint.setAntiAlias(true);
    bitmapPaint.setDither(true);
    bitmapPaint.setFilterBitmap(true);

    setOnTouchListener(this);
    setFocusable(true);
    setClickable(true);
}
 
Example 2
Source File: PageIndicatorView.java    From Alarmio with Apache License 2.0 5 votes vote down vote up
public void onDrawIndicator(Canvas canvas) {
    int height = indicator.getHeight();

    for (int i = 0; i < indicator.getTotalPages(); i++) {
        int x = DimenUtils.dpToPx(4) + DimenUtils.dpToPx(16 * i);
        canvas.drawCircle(x, height / 2f, DimenUtils.dpToPx(4), unselectedPaint);
    }

    int firstX;
    int secondX;

    firstX = DimenUtils.dpToPx(4 + indicator.getActualPosition() * 16);

    if (indicator.getPositionOffset() > .5f) {
        firstX += DimenUtils.dpToPx(16 * (indicator.getPositionOffset() - .5f) * 2);
    }

    secondX = DimenUtils.dpToPx(4 + indicator.getActualPosition() * 16);

    if (indicator.getPositionOffset() < .5f) {
        secondX += DimenUtils.dpToPx(16 * indicator.getPositionOffset() * 2);
    } else {
        secondX += DimenUtils.dpToPx(16);
    }

    canvas.drawCircle(firstX, DimenUtils.dpToPx(4), DimenUtils.dpToPx(4), selectedPaint);
    canvas.drawCircle(secondX, DimenUtils.dpToPx(4), DimenUtils.dpToPx(4), selectedPaint);
    canvas.drawRect(firstX, 0, secondX, DimenUtils.dpToPx(8), selectedPaint);
}
 
Example 3
Source File: ColorView.java    From ColorPickerDialog with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    super.init();

    outlineSize = DimenUtils.dpToPx(2);

    tilePaint = new Paint();
    tilePaint.setAntiAlias(true);
    tilePaint.setStyle(Paint.Style.FILL);
    tilePaint.setColor(Color.LTGRAY);
}
 
Example 4
Source File: ImageColorPickerView.java    From ColorPickerDialog with Apache License 2.0 5 votes vote down vote up
@Override
protected void init() {
    setFocusable(true);
    setClickable(true);
    setWillNotDraw(false);

    x = new AnimatedInteger(-1);
    y = new AnimatedInteger(-1);

    circleWidth = DimenUtils.dpToPx(18);

    paint = new Paint();
    paint.setDither(true);
    paint.setAntiAlias(true);
    paint.setFilterBitmap(true);

    fillPaint = new Paint();
    fillPaint.setStyle(Paint.Style.FILL);
    fillPaint.setAntiAlias(true);

    strokePaint = new Paint();
    strokePaint.setStyle(Paint.Style.STROKE);
    strokePaint.setStrokeWidth(DimenUtils.dpToPx(2));
    strokePaint.setAntiAlias(true);

    bitmapMatrix = new Matrix();

    getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
        @Override
        public void onGlobalLayout() {
            if (bitmap != null)
                calculateBitmapMatrix();

            getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });
}
 
Example 5
Source File: StatusView.java    From Status with Apache License 2.0 5 votes vote down vote up
public void init() {
    isAnimations = PreferenceData.STATUS_ICON_ANIMATIONS.getValue(getContext());
    backgroundColor.setDefault((int) PreferenceData.STATUS_COLOR.getValue(getContext()));
    isTransparentHome = PreferenceData.STATUS_HOME_TRANSPARENT.getValue(getContext());

    int sidePaddingInt = DimenUtils.dpToPx((int) PreferenceData.STATUS_SIDE_PADDING.getValue(getContext()));
    if (sidePadding == null)
        sidePadding = new AnimatedInteger(sidePaddingInt);
    else sidePadding.to(sidePaddingInt);

    isBurnInProtection = PreferenceData.STATUS_BURNIN_PROTECTION.getValue(getContext());

    for (IconData icon : icons)
        icon.init();

    if (backgroundImage != null)
        setTransparent();
    else setColor(backgroundColor.getTarget());

    if (isBurnInProtection && !isBurnInProtectionStarted) {
        handler.post(burnInRunnable);
        isBurnInProtectionStarted = true;
    }

    sortIcons();
    postInvalidate();
}
 
Example 6
Source File: ColorView.java    From Status with Apache License 2.0 5 votes vote down vote up
void setUp() {
    outlineSize = DimenUtils.dpToPx(2);

    tilePaint = new Paint();
    tilePaint.setAntiAlias(true);
    tilePaint.setStyle(Paint.Style.FILL);
    tilePaint.setColor(Color.LTGRAY);
}
 
Example 7
Source File: PageIndicatorView.java    From Alarmio with Apache License 2.0 4 votes vote down vote up
public int getMeasuredHeight() {
    return DimenUtils.dpToPx(8);
}
 
Example 8
Source File: PageIndicatorView.java    From Alarmio with Apache License 2.0 4 votes vote down vote up
public int getMeasuredWidth() {
    return DimenUtils.dpToPx(8 * (indicator.getTotalPages() * 2 - 1));
}
 
Example 9
Source File: RoundedSquareImageView.java    From ColorPickerDialog with Apache License 2.0 4 votes vote down vote up
private void init() {
    radius = DimenUtils.dpToPx(4);
    path = new Path();
    rect = new RectF(0, 0, getWidth(), getHeight());
}
 
Example 10
Source File: FontPreferenceData.java    From Status with Apache License 2.0 4 votes vote down vote up
@Override
public void onClick(View v) {
    ScrollView scrollView = new ScrollView(getContext());

    RadioGroup group = new RadioGroup(getContext());
    int vPadding = DimenUtils.dpToPx(12);
    group.setPadding(0, vPadding, 0, vPadding);

    AppCompatRadioButton normalButton = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
    normalButton.setId(0);
    normalButton.setText(R.string.font_default);
    normalButton.setChecked(preference == null || preference.length() == 0);
    group.addView(normalButton);

    for (int i = 0; i < items.size(); i++) {
        String item = items.get(i);

        AppCompatRadioButton button = (AppCompatRadioButton) LayoutInflater.from(getContext()).inflate(R.layout.item_dialog_radio_button, group, false);
        button.setId(i + 1);
        button.setText(item.replace(".ttf", ""));
        button.setTag(item);
        try {
            button.setTypeface(Typeface.createFromAsset(getContext().getAssets(), item));
        } catch (Exception e) {
            continue;
        }
        button.setChecked(preference != null && preference.equals(item));
        group.addView(button);
    }

    group.setOnCheckedChangeListener((group1, checkedId) -> {
        for (int i = 0; i < group1.getChildCount(); i++) {
            RadioButton child = (RadioButton) group1.getChildAt(i);
            child.setChecked(child.getId() == checkedId);
            if (child.getId() == checkedId)
                selectedPreference = (String) child.getTag();
        }
    });

    scrollView.addView(group);

    new AlertDialog.Builder(getContext())
            .setTitle(getIdentifier().getTitle())
            .setView(scrollView)
            .setPositiveButton(android.R.string.ok, (dialog, which) -> {
                FontPreferenceData.this.preference = selectedPreference;

                getIdentifier().setPreferenceValue(getContext(), selectedPreference);
                onPreferenceChange(selectedPreference);
                selectedPreference = null;
            })
            .setNegativeButton(android.R.string.cancel, (dialog, which) -> selectedPreference = null)
            .show();
}
 
Example 11
Source File: PickerDialog.java    From ColorPickerDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Specify the corner radius for the dialog to use, in dp.
 *
 * @param cornerRadius          The corner radius of the dialog, in dp.
 * @return                      "This" dialog instance, for method chaining.
 */
public T withCornerRadius(float cornerRadius) {
    this.cornerRadius = DimenUtils.dpToPx(cornerRadius);
    return (T) this;
}