Skip to content

Commit d7029ac

Browse files
[core] Some fixes
> EditText crash because gravity > Move LinearAnimation to animation package > Fix absolute layout crash because invalid cast
1 parent f1c37a6 commit d7029ac

9 files changed

Lines changed: 81 additions & 57 deletions

File tree

core/res/ex-layout/main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
background="#C00"
6969
src="@drawable/default_window_icon"
7070
scaleType="fill"
71+
rotation="45"
7172
margin="10dp"/>
7273

7374
<ImageView

core/src/br/nullexcept/mux/utils/LinearAnimation.java

Lines changed: 0 additions & 46 deletions
This file was deleted.

core/src/br/nullexcept/mux/view/anim/AlphaAnimation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package br.nullexcept.mux.view.anim;
22

3-
import br.nullexcept.mux.utils.LinearAnimation;
43
import br.nullexcept.mux.view.View;
54

65
public class AlphaAnimation extends LinearAnimation {
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package br.nullexcept.mux.view.anim;
2+
3+
import br.nullexcept.mux.app.Looper;
4+
import br.nullexcept.mux.view.View;
5+
6+
public abstract class LinearAnimation {
7+
private int duration;
8+
private boolean loop = false;
9+
private final Looper looper;
10+
private final Runnable update = this::update;
11+
private final long[] times = new long[3];
12+
private boolean playing = false;
13+
14+
public LinearAnimation(View view, int duration) {
15+
this.duration = duration;
16+
this.looper = view.getContext().getMainLooper();
17+
}
18+
19+
protected void setDuration(int duration) {
20+
this.duration = duration;
21+
}
22+
23+
private void update() {
24+
if (times[1] > times[0]) {
25+
playing = false;
26+
onEnd();
27+
if (loop) {
28+
play();
29+
}
30+
return;
31+
}
32+
playing = true;
33+
onFrame((double) times[1]/ times[0]);
34+
times[1] += (System.currentTimeMillis() - times[2]);
35+
times[2] = System.currentTimeMillis();
36+
looper.post(update);
37+
}
38+
39+
public void play() {
40+
looper.cancel(update);
41+
playing = true;
42+
times[0] = duration;
43+
times[1] = 0;
44+
times[2] = System.currentTimeMillis();
45+
46+
onBegin();
47+
looper.post(update);
48+
}
49+
50+
public boolean isPlaying() {
51+
return playing;
52+
}
53+
54+
public void stop() {
55+
if (playing) {
56+
looper.cancel(update);
57+
onEnd();
58+
}
59+
}
60+
61+
public void setLoop(boolean loop) {
62+
this.loop = loop;
63+
}
64+
65+
public abstract void onBegin();
66+
public abstract void onFrame(double delta);
67+
public abstract void onEnd();
68+
}

core/src/br/nullexcept/mux/view/anim/RotationAnimation.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package br.nullexcept.mux.view.anim;
22

3-
import br.nullexcept.mux.utils.LinearAnimation;
43
import br.nullexcept.mux.view.View;
54

65
public class RotationAnimation extends LinearAnimation {

core/src/br/nullexcept/mux/widget/AbsoluteLayout.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,11 @@ public AbsoluteLayout(Context context, AttributeList attrs) {
1919

2020
@Override
2121
public void addChild(View view, ViewGroup.LayoutParams params) {
22-
if (params == null) {
23-
params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
22+
LayoutParams newParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
23+
if (params != null) {
24+
newParams.from(params);
2425
}
25-
if (!(params instanceof LayoutParams)) {
26-
params = new LayoutParams(params.width, params.height);
27-
}
28-
super.addChild(view, params);
26+
super.addChild(view, newParams);
2927
}
3028

3129
@Override
@@ -49,6 +47,9 @@ public void from(ViewGroup.LayoutParams params) {
4947
if (params instanceof MarginLayoutParams) {
5048
x = ((MarginLayoutParams) params).getMarginLeft();
5149
y = ((MarginLayoutParams) params).getMarginTop();
50+
} else if (params instanceof LayoutParams) {
51+
x = ((LayoutParams) params).x;
52+
y = ((LayoutParams) params).y;
5253
}
5354
super.from(params);
5455
}

core/src/br/nullexcept/mux/widget/EditText.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,10 @@ public void setEditable(boolean editable) {
191191
@Override
192192
public void setGravity(int gravity) {
193193
super.setGravity(gravity);
194-
measureText(true);
195-
checkMeasure();
194+
if (text != null) {
195+
measureText(true);
196+
checkMeasure();
197+
}
196198
}
197199

198200
@Override

core/src/br/nullexcept/mux/widget/ImageView.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class ImageView extends View {
1818
public static final int SCALE_FIT = 1;
1919
public static final int SCALE_CROP = 2;
2020
public static final int SCALE_WRAP = 3;
21-
21+
2222
private Drawable image;
2323
private final Rect rect = new Rect();
2424
private int scaleType = SCALE_FIT;

core/src/br/nullexcept/mux/widget/HardwareSurface.java renamed to texel/src/br/nullexcept/mux/widget/HardwareSurface.java

File renamed without changes.

0 commit comments

Comments
 (0)