me.jfenn.androidutils.DimenUtils Java Examples

The following examples show how to use me.jfenn.androidutils.DimenUtils. 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: PickerDialog.java    From ColorPickerDialog with Apache License 2.0 6 votes vote down vote up
@Override
public void onResume() {
    super.onResume();

    Window window = getDialog().getWindow();
    DisplayMetrics displayMetrics = new DisplayMetrics();
    WindowManager windowmanager = window.getWindowManager();
    windowmanager.getDefaultDisplay().getMetrics(displayMetrics);

    window.setLayout(
            Math.min(DimenUtils.dpToPx(displayMetrics.widthPixels > displayMetrics.heightPixels ? 800 : 500),
                    (int) (displayMetrics.widthPixels * 0.9f)),
            WindowManager.LayoutParams.WRAP_CONTENT
    );

    GradientDrawable drawable = new GradientDrawable();
    drawable.setColor(ColorUtils.fromAttr(new ContextThemeWrapper(getContext(), getTheme()),
            android.R.attr.colorBackground, Color.WHITE));
    drawable.setCornerRadius(cornerRadius);

    window.setBackgroundDrawable(new InsetDrawable(drawable, DimenUtils.dpToPx(12)));
}
 
Example #2
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 #3
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 #4
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 #5
Source File: VerticalSmoothColorView.java    From ColorPickerDialog with Apache License 2.0 5 votes vote down vote up
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);

    int size = getMeasuredHeight();
    setMeasuredDimension(Math.min(DimenUtils.dpToPx(200), size), size);
}
 
Example #6
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 #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: IconData.java    From Status with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize all of the settings / variables of the icon to their
 * preference values. If it's the first init, this will also set up
 * the animated attributes; if not, it will simply update them to match
 * their 'default' values.
 *
 * @param isFirstInit Whether this is the first initialization of
 *                    the icon (this method may be called externally
 *                    to update values on a preference change without
 *                    restarting Status's entire service).
 */
protected void init(boolean isFirstInit) {
    iconColor.setDefault((int) PreferenceData.ICON_ICON_COLOR_LIGHT.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_ICON_COLOR.getValue(getContext()), getIdentifierArgs()));
    defaultIconDarkColor = (int) PreferenceData.ICON_ICON_COLOR_DARK.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_DARK_ICON_COLOR.getValue(getContext()), getIdentifierArgs());

    textColor.setDefault((int) PreferenceData.ICON_TEXT_COLOR_LIGHT.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_ICON_TEXT_COLOR.getValue(getContext()), getIdentifierArgs()));
    defaultTextDarkColor = (int) PreferenceData.ICON_TEXT_COLOR_DARK.getSpecificOverriddenValue(getContext(),
            PreferenceData.STATUS_DARK_ICON_TEXT_COLOR.getValue(getContext()), getIdentifierArgs());

    iconSize.setDefault(DimenUtils.dpToPx((int) PreferenceData.ICON_ICON_SCALE.getSpecificValue(getContext(), getIdentifierArgs())));
    iconOffsetX.to((int) PreferenceData.ICON_ICON_OFFSET_X.getSpecificValue(getContext(), getIdentifierArgs()));
    iconOffsetY.to((int) PreferenceData.ICON_ICON_OFFSET_Y.getSpecificValue(getContext(), getIdentifierArgs()));
    textSize.setDefault((float) DimenUtils.spToPx((float) (int) PreferenceData.ICON_TEXT_SIZE.getSpecificValue(getContext(), getIdentifierArgs())));
    textOffsetX.to((int) PreferenceData.ICON_TEXT_OFFSET_X.getSpecificValue(getContext(), getIdentifierArgs()));
    textOffsetY.to((int) PreferenceData.ICON_TEXT_OFFSET_Y.getSpecificValue(getContext(), getIdentifierArgs()));
    padding.to(DimenUtils.dpToPx((int) PreferenceData.ICON_ICON_PADDING.getSpecificValue(getContext(), getIdentifierArgs())));

    backgroundColor = PreferenceData.STATUS_COLOR.getValue(getContext());

    Typeface typefaceFont = Typeface.DEFAULT;
    String typefaceName = PreferenceData.ICON_TEXT_TYPEFACE.getSpecificOverriddenValue(getContext(), null, getIdentifierArgs());
    if (typefaceName != null) {
        try {
            typefaceFont = Typeface.createFromAsset(getContext().getAssets(), typefaceName);
        } catch (Exception ignored) {
        }
    }

    typeface = Typeface.create(typefaceFont, (int) PreferenceData.ICON_TEXT_EFFECT.getSpecificValue(getContext(), getIdentifierArgs()));

    isAnimations = PreferenceData.STATUS_ICON_ANIMATIONS.getValue(getContext());

    if (styles.size() > 0) {
        String name = PreferenceData.ICON_ICON_STYLE.getSpecificOverriddenValue(context, styles.get(0).name, getIdentifierArgs());
        if (name != null) {
            for (IconStyleData style : styles) {
                if (style.name.equals(name)) {
                    this.style = style;
                    break;
                }
            }
        }

        if (style == null) style = styles.get(0);
        onIconUpdate(level);
    }

    if (isFirstInit) {
        textAlpha.to(255);
        iconAlpha.to(255);
        textColor.setCurrent(textColor.getDefault());
        iconColor.setCurrent(iconColor.getDefault());
        textSize.toDefault();
        textOffsetX.setCurrent(textOffsetX.getTarget());
        textOffsetY.setCurrent(textOffsetY.getTarget());
        iconSize.toDefault();
        iconOffsetX.setCurrent(iconOffsetX.getTarget());
        iconOffsetY.setCurrent(iconOffsetY.getTarget());
    } else {
        if (isText)
            textSize.toDefault();
        if (isIcon)
            iconSize.toDefault();
    }
}
 
Example #13
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 #14
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;
}
 
Example #15
Source File: PickerDialog.java    From ColorPickerDialog with Apache License 2.0 2 votes vote down vote up
/**
 * Get the currently applied corner radius, in dp.
 *
 * @return                      The corner radius, in dp.
 */
public float getCornerRadius() {
    return DimenUtils.pxToDp(cornerRadius);
}