Java Code Examples for com.gc.materialdesign.utils.Utils#dpToPx()

The following examples show how to use com.gc.materialdesign.utils.Utils#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: ButtonFloat.java    From MaterialDesignLibrary with Apache License 2.0 6 votes vote down vote up
public ButtonFloat(Context context, AttributeSet attrs) {
	super(context, attrs);
	setBackgroundResource(R.drawable.background_button_float);
	setBackgroundColor(backgroundColor);
	sizeRadius = 28;
	setDefaultProperties();
	icon = new ImageView(context);
	icon.setAdjustViewBounds(true);
	icon.setScaleType(ScaleType.CENTER_CROP);
	if(drawableIcon != null) {
		icon.setImageDrawable(drawableIcon);
	}
	LayoutParams params = new LayoutParams(Utils.dpToPx(sizeIcon, getResources()),Utils.dpToPx(sizeIcon, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	addView(icon);		
	
}
 
Example 2
Source File: ButtonFloat.java    From Social with Apache License 2.0 6 votes vote down vote up
public ButtonFloat(Context context, AttributeSet attrs) {
	super(context, attrs);
	setBackgroundResource(R.drawable.background_button_float);
	setBackgroundColor(backgroundColor);
	sizeRadius = 28;
	setDefaultProperties();
	icon = new ImageView(context);
	icon.setAdjustViewBounds(true);
	icon.setScaleType(ScaleType.CENTER_CROP);
	if(drawableIcon != null) {
		icon.setImageDrawable(drawableIcon);
	}
	LayoutParams params = new LayoutParams(Utils.dpToPx(sizeIcon, getResources()), Utils.dpToPx(sizeIcon, getResources()));
	params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
	icon.setLayoutParams(params);
	addView(icon);		
	
}
 
Example 3
Source File: ButtonRectangle.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
	protected void onDraw(Canvas canvas) {
//		if(!txtCenter)
//		centrarTexto();
		super.onDraw(canvas);
		if (x != -1) {
			Rect src = new Rect(0, 0, getWidth()- Utils.dpToPx(6, getResources()), getHeight()- Utils.dpToPx(7, getResources()));
			Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth()- Utils.dpToPx(6, getResources()), getHeight()- Utils.dpToPx(7, getResources()));
			canvas.drawBitmap(makeCircle(), src, dst, null);
			invalidate();
		}
	}
 
Example 4
Source File: ButtonRectangle.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
@Override
	protected void onDraw(Canvas canvas) {
//		if(!txtCenter)
//		centrarTexto();
		super.onDraw(canvas);
		if (x != -1) {
			Rect src = new Rect(0, 0, getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources()));
			Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()), getWidth()-Utils.dpToPx(6, getResources()), getHeight()-Utils.dpToPx(7, getResources()));
			canvas.drawBitmap(makeCircle(), src, dst, null);
			invalidate();
		}
	}
 
Example 5
Source File: Switch.java    From meiShi with Apache License 2.0 5 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, getResources()));

        // Set background Color
        // Color by resource
        int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
                "background", -1);
        if (bacgroundColor != -1) {
			setBackgroundColor(getResources().getColor(bacgroundColor));
		} else {
			// Color by hexadecimal
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check",
				false);
		eventCheck = check;
		ball = new Ball(getContext());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
		ball.setLayoutParams(params);
		addView(ball);

	}
 
Example 6
Source File: ButtonFloat.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
protected void setDefaultProperties() {
        rippleSpeed = Utils.dpToPx(2, getResources());
        rippleSize = Utils.dpToPx(5, getResources());
        setMinimumWidth(Utils.dpToPx(sizeRadius * 2, getResources()));
        setMinimumHeight(Utils.dpToPx(sizeRadius * 2, getResources()));
        super.background = R.drawable.background_button_float;
//		super.setDefaultProperties();
    }
 
Example 7
Source File: Slider.java    From meiShi with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (numberIndicatorResize == false) {
        LayoutParams params = (LayoutParams) numberIndicator.numberIndicator
                .getLayoutParams();
        params.height = (int) finalSize * 2;
        params.width = (int) finalSize * 2;
        numberIndicator.numberIndicator.setLayoutParams(params);
    }
    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(backgroundColor);
    if (animate) {
        if (y == 0)
            y = finalY + finalSize * 2;
        y -= Utils.dpToPx(6, getResources());
        size += Utils.dpToPx(2, getResources());
    }
    canvas.drawCircle(
            ViewHelper.getX(ball)
                    + Utils.getRelativeLeft((View) ball.getParent())
                    + ball.getWidth() / 2, y, size, paint);
    if (animate && size >= finalSize)
        animate = false;
    if (animate == false) {
        ViewHelper
                .setX(numberIndicator.numberIndicator,
                        (ViewHelper.getX(ball)
                                + Utils.getRelativeLeft((View) ball
                                .getParent()) + ball.getWidth() / 2)
                                - size);

         ViewHelper.setY(numberIndicator.numberIndicator, y - size);
        numberIndicator.numberIndicator.setText(getNumberIndicatorValue(value));
    }
    invalidate();
}
 
Example 8
Source File: ButtonFloatSmall.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
protected void setDefaultProperties(){
		rippleSpeed = Utils.dpToPx(2, getResources());
		rippleSize = 10;		
		// Min size
		setMinimumHeight(Utils.dpToPx(sizeRadius*2, getResources()));
		setMinimumWidth(Utils.dpToPx(sizeRadius*2, getResources()));
		// Background shape
		setBackgroundResource(R.drawable.background_button_float);
//		setBackgroundColor(backgroundColor);
	}
 
Example 9
Source File: Slider.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    if (numberIndicatorResize == false) {
        RelativeLayout.LayoutParams params = (LayoutParams) numberIndicator.numberIndicator
                .getLayoutParams();
        params.height = (int) finalSize * 2;
        params.width = (int) finalSize * 2;
        numberIndicator.numberIndicator.setLayoutParams(params);
    }

    Paint paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(backgroundColor);
    if (animate) {
        if (y == 0)
            y = finalY + finalSize * 2;
        y -= Utils.dpToPx(6, getResources());
        size += Utils.dpToPx(2, getResources());
    }
    canvas.drawCircle(
            ViewHelper.getX(ball)
                    + Utils.getRelativeLeft((View) ball.getParent())
                    + ball.getWidth() / 2, y, size, paint);
    if (animate && size >= finalSize)
        animate = false;
    if (animate == false) {
        ViewHelper
                .setX(numberIndicator.numberIndicator,
                        (ViewHelper.getX(ball)
                                + Utils.getRelativeLeft((View) ball
                                .getParent()) + ball.getWidth() / 2)
                                - size);
        ViewHelper.setY(numberIndicator.numberIndicator, y - size);
        numberIndicator.numberIndicator.setText(value + "");
    }

    invalidate();
}
 
Example 10
Source File: ButtonRectangle.java    From MoeGallery with GNU General Public License v3.0 5 votes vote down vote up
@Override
    protected void onDraw(Canvas canvas) {
//		if(!txtCenter)
//		centrarTexto();
        super.onDraw(canvas);
        if (x != -1) {
            Rect src = new Rect(0, 0, getWidth() - Utils.dpToPx(6, getResources()),
                    getHeight() - Utils.dpToPx(7, getResources()));
            Rect dst = new Rect(Utils.dpToPx(6, getResources()), Utils.dpToPx(6, getResources()),
                    getWidth() - Utils.dpToPx(6, getResources()),
                    getHeight() - Utils.dpToPx(7, getResources()));
            canvas.drawBitmap(makeCircle(), src, dst, null);
            invalidate();
        }
    }
 
Example 11
Source File: ButtonIcon.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
public ButtonIcon(Context context, AttributeSet attrs) {
	super(context, attrs);
	try {
		setBackground(new ColorDrawable(getResources().getColor(R.color.transparent)));
	} catch (NoSuchMethodError e) {
		setBackgroundDrawable(new ColorDrawable(getResources().getColor(R.color.transparent)));
	}
	rippleSpeed = Utils.dpToPx(2, getResources());
	rippleSize = Utils.dpToPx(5, getResources());
}
 
Example 12
Source File: ButtonFloat.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
protected void setDefaultProperties(){
		rippleSpeed = Utils.dpToPx(2, getResources());
		rippleSize = Utils.dpToPx(5, getResources());
		setMinimumWidth(Utils.dpToPx(sizeRadius*2, getResources()));
		setMinimumHeight(Utils.dpToPx(sizeRadius*2, getResources()));
		super.background = R.drawable.background_button_float;
//		super.setDefaultProperties();
	}
 
Example 13
Source File: ButtonFloat.java    From meiShi with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (x != -1) {
		Rect src = new Rect(0, 0, getWidth(), getHeight());
		Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth()-Utils.dpToPx(1, getResources()), getHeight()-Utils.dpToPx(2, getResources()));
		canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null);
		invalidate();
	}
}
 
Example 14
Source File: ButtonFloat.java    From Social with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (x != -1) {
		Rect src = new Rect(0, 0, getWidth(), getHeight());
		Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth()- Utils.dpToPx(1, getResources()), getHeight()- Utils.dpToPx(2, getResources()));
		canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null);
		invalidate();
	}
}
 
Example 15
Source File: ButtonFloat.java    From MaterialDesignLibrary with Apache License 2.0 5 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
	super.onDraw(canvas);
	if (x != -1) {
		Rect src = new Rect(0, 0, getWidth(), getHeight());
		Rect dst = new Rect(Utils.dpToPx(1, getResources()), Utils.dpToPx(2, getResources()), getWidth()-Utils.dpToPx(1, getResources()), getHeight()-Utils.dpToPx(2, getResources()));
		canvas.drawBitmap(cropCircle(makeCircle()), src, dst, null);
		invalidate();
	}
}
 
Example 16
Source File: Switch.java    From Social with Apache License 2.0 5 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, getResources()));

        // Set background Color
        // Color by resource
        int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
                "background", -1);
        if (bacgroundColor != -1) {
            setBackgroundColor(getResources().getColor(bacgroundColor));
        } else {
            // Color by hexadecimal
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML, "check",
                false);
        eventCheck = check;
        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

    }
 
Example 17
Source File: Slider.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, getResources()));

        // Set background Color
        // Color by resource
        int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
                "background", -1);
        if (bacgroundColor != -1) {
            setBackgroundColor(getResources().getColor(bacgroundColor));
        } else {
            // Color by hexadecimal
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
                "showNumberIndicator", false);
        min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
        max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0);
        value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min);

        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

        // Set if slider content number indicator
        // TODO
        if (showNumberIndicator) {
            numberIndicator = new NumberIndicator(getContext());
        }

    }
 
Example 18
Source File: CheckBox.java    From MoeGallery with GNU General Public License v3.0 4 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

		setBackgroundResource(R.drawable.background_checkbox);

		// Set size of view
		setMinimumHeight(Utils.dpToPx(48, getResources()));
		setMinimumWidth(Utils.dpToPx(48, getResources()));

		// Set background Color
		// Color by resource
		int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
				"background", -1);
		if (bacgroundColor != -1) {
			setBackgroundColor(getResources().getColor(bacgroundColor));
		} else {
			// Color by hexadecimal
			// Color by hexadecimal
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
				"check", false);
			post(new Runnable() {

				@Override
				public void run() {
					setChecked(check);
					setPressed(false);
					changeBackgroundColor(getResources().getColor(
							android.R.color.transparent));
				}
			});

		checkView = new Check(getContext());
        checkView.setId(View.generateViewId());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		checkView.setLayoutParams(params);
		addView(checkView);

        // Adding text view to checkbox
        int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1);
        String text = null;

        if(textResource != -1) {
            text = getResources().getString(textResource);
        } else {
            text = attrs.getAttributeValue(ANDROIDXML, "text");
        }

        if(text != null) {
            params.removeRule(RelativeLayout.CENTER_IN_PARENT);
            params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
                    TextView textView = new TextView(getContext());
            RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            textViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, checkView.getId());
            textViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
            textViewLayoutParams.setMargins(10, 0, 0, 0);
            textView.setLayoutParams(textViewLayoutParams);
            textView.setText(text);

            addView(textView);
        }
	}
 
Example 19
Source File: Slider.java    From MaterialDesignLibrary with Apache License 2.0 4 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

        setBackgroundResource(R.drawable.background_transparent);

        // Set size of view
        setMinimumHeight(Utils.dpToPx(48, getResources()));
        setMinimumWidth(Utils.dpToPx(80, getResources()));

        // Set background Color
        // Color by resource
        int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
                "background", -1);
        if (bacgroundColor != -1) {
            setBackgroundColor(getResources().getColor(bacgroundColor));
        } else {
            // Color by hexadecimal
            int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
            if (background != -1)
                setBackgroundColor(background);
        }

        showNumberIndicator = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
                "showNumberIndicator", false);
        min = attrs.getAttributeIntValue(MATERIALDESIGNXML, "min", 0);
        max = attrs.getAttributeIntValue(MATERIALDESIGNXML, "max", 0);
        value = attrs.getAttributeIntValue(MATERIALDESIGNXML, "value", min);

        ball = new Ball(getContext());
        RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
                getResources()), Utils.dpToPx(20, getResources()));
        params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
        ball.setLayoutParams(params);
        addView(ball);

        // Set if slider content number indicator
        // TODO
        if (showNumberIndicator) {
            numberIndicator = new NumberIndicator(getContext());
        }

    }
 
Example 20
Source File: CheckBox.java    From meiShi with Apache License 2.0 4 votes vote down vote up
protected void setAttributes(AttributeSet attrs) {

		setBackgroundResource(R.drawable.background_checkbox);

		// Set size of view
		setMinimumHeight(Utils.dpToPx(48, getResources()));
		setMinimumWidth(Utils.dpToPx(48, getResources()));

		// Set background Color
		// Color by resource
		int bacgroundColor = attrs.getAttributeResourceValue(ANDROIDXML,
				"background", -1);
		if (bacgroundColor != -1) {
			setBackgroundColor(getResources().getColor(bacgroundColor));
		} else {
			// Color by hexadecimal
			// Color by hexadecimal
			int background = attrs.getAttributeIntValue(ANDROIDXML, "background", -1);
			if (background != -1)
				setBackgroundColor(background);
		}

		final boolean check = attrs.getAttributeBooleanValue(MATERIALDESIGNXML,
				"check", false);
			post(new Runnable() {

				@Override
				public void run() {
					setChecked(check);
					setPressed(false);
					changeBackgroundColor(getResources().getColor(
							android.R.color.transparent));
				}
			});

		checkView = new Check(getContext());
        checkView.setId(View.generateViewId());
		RelativeLayout.LayoutParams params = new LayoutParams(Utils.dpToPx(20,
				getResources()), Utils.dpToPx(20, getResources()));
		params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE);
		checkView.setLayoutParams(params);
		addView(checkView);

        // Adding text view to checkbox
        int textResource = attrs.getAttributeResourceValue(ANDROIDXML, "text", -1);
        String text = null;

        if(textResource != -1) {
            text = getResources().getString(textResource);
        } else {
            text = attrs.getAttributeValue(ANDROIDXML, "text");
        }

        if(text != null) {
            params.removeRule(RelativeLayout.CENTER_IN_PARENT);
            params.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
                    TextView textView = new TextView(getContext());
            RelativeLayout.LayoutParams textViewLayoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
                    LayoutParams.WRAP_CONTENT);
            textViewLayoutParams.addRule(RelativeLayout.RIGHT_OF, checkView.getId());
            textViewLayoutParams.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
            textViewLayoutParams.setMargins(10, 0, 0, 0);
            textView.setLayoutParams(textViewLayoutParams);
            textView.setText(text);

            addView(textView);
        }
	}