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(); }
@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(); }
public ButtonFloat(Context context, AttributeSet attrs) { super(context, attrs); setBackgroundResource(R.drawable.background_button_float); sizeRadius = 28; setDefaultProperties(); icon = new ImageView(context); icon.setAdjustViewBounds(true); icon.setScaleType(ScaleType.CENTER_CROP); if (drawableIcon != null) { icon.setImageDrawable(drawableIcon); // try { // icon.setBackground(drawableIcon); // } catch (NoSuchMethodError e) { // icon.setBackgroundDrawable(drawableIcon); // } } RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams( Utils.dpToPx(sizeIcon, getResources()), Utils.dpToPx(sizeIcon, getResources())); params.addRule(RelativeLayout.CENTER_IN_PARENT, RelativeLayout.TRUE); icon.setLayoutParams(params); addView(icon); }
// Set atributtes of XML to View @SuppressLint("NewApi") protected void setAttributes(AttributeSet attrs) { setBackgroundResource(R.drawable.background_checkbox); // Set size of view setMinimumHeight(Utils.dpToPx(16, getResources())); setMinimumWidth(Utils.dpToPx(16, 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(16, getResources()), Utils.dpToPx(16, 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); textView.setTextSize(12); addView(textView); } }