Skip to content

Commit

Permalink
[core] Some fixes
Browse files Browse the repository at this point in the history
> EditText crash because gravity
> Move LinearAnimation to animation package
> Fix absolute layout crash because invalid cast
  • Loading branch information
GabrielBRDeveloper committed Aug 2, 2024
1 parent f1c37a6 commit d7029ac
Show file tree
Hide file tree
Showing 9 changed files with 81 additions and 57 deletions.
1 change: 1 addition & 0 deletions core/res/ex-layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
background="#C00"
src="@drawable/default_window_icon"
scaleType="fill"
rotation="45"
margin="10dp"/>

<ImageView
Expand Down
46 changes: 0 additions & 46 deletions core/src/br/nullexcept/mux/utils/LinearAnimation.java

This file was deleted.

1 change: 0 additions & 1 deletion core/src/br/nullexcept/mux/view/anim/AlphaAnimation.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.nullexcept.mux.view.anim;

import br.nullexcept.mux.utils.LinearAnimation;
import br.nullexcept.mux.view.View;

public class AlphaAnimation extends LinearAnimation {
Expand Down
68 changes: 68 additions & 0 deletions core/src/br/nullexcept/mux/view/anim/LinearAnimation.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package br.nullexcept.mux.view.anim;

import br.nullexcept.mux.app.Looper;
import br.nullexcept.mux.view.View;

public abstract class LinearAnimation {
private int duration;
private boolean loop = false;
private final Looper looper;
private final Runnable update = this::update;
private final long[] times = new long[3];
private boolean playing = false;

public LinearAnimation(View view, int duration) {
this.duration = duration;
this.looper = view.getContext().getMainLooper();
}

protected void setDuration(int duration) {
this.duration = duration;
}

private void update() {
if (times[1] > times[0]) {
playing = false;
onEnd();
if (loop) {
play();
}
return;
}
playing = true;
onFrame((double) times[1]/ times[0]);
times[1] += (System.currentTimeMillis() - times[2]);
times[2] = System.currentTimeMillis();
looper.post(update);
}

public void play() {
looper.cancel(update);
playing = true;
times[0] = duration;
times[1] = 0;
times[2] = System.currentTimeMillis();

onBegin();
looper.post(update);
}

public boolean isPlaying() {
return playing;
}

public void stop() {
if (playing) {
looper.cancel(update);
onEnd();
}
}

public void setLoop(boolean loop) {
this.loop = loop;
}

public abstract void onBegin();
public abstract void onFrame(double delta);
public abstract void onEnd();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package br.nullexcept.mux.view.anim;

import br.nullexcept.mux.utils.LinearAnimation;
import br.nullexcept.mux.view.View;

public class RotationAnimation extends LinearAnimation {
Expand Down
13 changes: 7 additions & 6 deletions core/src/br/nullexcept/mux/widget/AbsoluteLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,11 @@ public AbsoluteLayout(Context context, AttributeList attrs) {

@Override
public void addChild(View view, ViewGroup.LayoutParams params) {
if (params == null) {
params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LayoutParams newParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
if (params != null) {
newParams.from(params);
}
if (!(params instanceof LayoutParams)) {
params = new LayoutParams(params.width, params.height);
}
super.addChild(view, params);
super.addChild(view, newParams);
}

@Override
Expand All @@ -49,6 +47,9 @@ public void from(ViewGroup.LayoutParams params) {
if (params instanceof MarginLayoutParams) {
x = ((MarginLayoutParams) params).getMarginLeft();
y = ((MarginLayoutParams) params).getMarginTop();
} else if (params instanceof LayoutParams) {
x = ((LayoutParams) params).x;
y = ((LayoutParams) params).y;
}
super.from(params);
}
Expand Down
6 changes: 4 additions & 2 deletions core/src/br/nullexcept/mux/widget/EditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,10 @@ public void setEditable(boolean editable) {
@Override
public void setGravity(int gravity) {
super.setGravity(gravity);
measureText(true);
checkMeasure();
if (text != null) {
measureText(true);
checkMeasure();
}
}

@Override
Expand Down
2 changes: 1 addition & 1 deletion core/src/br/nullexcept/mux/widget/ImageView.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class ImageView extends View {
public static final int SCALE_FIT = 1;
public static final int SCALE_CROP = 2;
public static final int SCALE_WRAP = 3;

private Drawable image;
private final Rect rect = new Rect();
private int scaleType = SCALE_FIT;
Expand Down

0 comments on commit d7029ac

Please sign in to comment.