Skip to content

Instantly share code, notes, and snippets.

Avatar

Andriy Bas AndriyBas

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am andriybas on github.
  • I am andriybas (https://keybase.io/andriybas) on keybase.
  • I have a public key ASABDupy0ZcakpjaI57_qPDSYqSOqNeK5PvuBebiwr2ECgo

To claim this, I am signing this object:

View TextEditorDialogFragment.java
Window window = dialog.getWindow();
if (window != null) {
// remove background
window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);
// remove dim
WindowManager.LayoutParams windowParams = window.getAttributes();
window.setDimAmount(0.0F);
window.setAttributes(windowParams);
}
View TextEntity.java
@NonNull
private Bitmap createBitmap(@NonNull TextLayer textLayer, @Nullable Bitmap reuseBmp) {
int boundsWidth = canvasWidth;
// init params - size, color, typeface
textPaint.setStyle(Paint.Style.FILL);
textPaint.setTextSize(textLayer.getFont().getSize() * canvasWidth);
textPaint.setColor(textLayer.getFont().getColor());
textPaint.setTypeface(fontProvider.getTypeface(textLayer.getFont().getFace()));
View TextLayer.java
class Font {
// color value (ex: 0xFF00FF)
private int color;
// name of the font
private String typeface;
// size of the font, relative to parent
private float size;
}
View GuestureParams.java
boolean onRotate(RotateGestureDetector detector) {
// ...
rotationInDegrees -= detector.getRotationDegreesDelta();
}
boolean onScale(ScaleGestureDetector detector) {
// ...
scale += (detector.getScaleFactor() - 1.0F);
}
boolean onMove(MoveGestureDetector detector) {
// ...
View PointInTriangle.java
boolean pointInTriangle(@NonNull PointF pt, @NonNull PointF v1,
@NonNull PointF v2, @NonNull PointF v3) {
boolean b1 = crossProduct(pt, v1, v2) < 0.0f;
boolean b2 = crossProduct(pt, v2, v3) < 0.0f;
boolean b3 = crossProduct(pt, v3, v1) < 0.0f;
return (b1 == b2) && (b2 == b3);
}
View MapPoints.java
// map rect vertices, where destPoint and srcPoints are float[]
matrix.mapPoints(destPoints, srcPoints);
@AndriyBas
AndriyBas / MatrixMath.java
Last active Nov 9, 2016
all the math how to create Matrix from the model
View MatrixMath.java
// calculate params
float topLeftX = layer.getX() * canvasWidth;
float topLeftY = layer.getY() * canvasHeight;
// center - for rotation
float centerX = topLeftX + getWidth() * holyScale * 0.5F;
float centerY = topLeftY + getHeight() * holyScale * 0.5F;
float rotationInDegree = layer.getRotationInDegrees();
float scaleX = layer.getScale();
float scaleY = layer.getScale();
@AndriyBas
AndriyBas / HolyScaleMath.java
Created Nov 9, 2016
how to calculate the holy scale
View HolyScaleMath.java
float widthAspect = 1.0F * canvasWidth / width;
float heightAspect = 1.0F * canvasHeight / height;
// fit the smallest size
holyScale = Math.min(widthAspect, heightAspect);
View Layer.java
class Layer {
float x; // top left X
float y; // top left Y
float scale;
@FloatRange(from = 0.0F, to = 360.0F)
float rotationInDegrees;
}