Skip to content

Commit

Permalink
Implement SeekBar
Browse files Browse the repository at this point in the history
-> Implement SeekBar widget
-> Fix LayerListDrawable size
  • Loading branch information
GabrielBRDeveloper committed Jul 25, 2024
1 parent ac8d6be commit eeba3e0
Show file tree
Hide file tree
Showing 13 changed files with 323 additions and 7 deletions.
27 changes: 27 additions & 0 deletions core/res/drawable-default/seekbar_progress.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list>
<item height="4dp">
<selector>
<item pressed="true">
<layer-list>
<item>
<shape
type="rounded"
radius="2dp"
color="?colorPrimaryVariant"/>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape
type="rounded"
radius="2dp"
color="?colorPrimary"/>
</item>
</layer-list>
</item>
</selector>
</item>
</layer-list>
27 changes: 27 additions & 0 deletions core/res/drawable-default/seekbar_thumb.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list>
<item height="16dp" width="16dp">
<selector>
<item pressed="true">
<layer-list>
<item>
<shape
type="rounded"
radius="64dp"
color="?colorPrimaryVariant"/>
</item>
</layer-list>
</item>
<item>
<layer-list>
<item>
<shape
type="rounded"
radius="64dp"
color="?colorPrimary"/>
</item>
</layer-list>
</item>
</selector>
</item>
</layer-list>
9 changes: 9 additions & 0 deletions core/res/drawable-default/seekbar_track.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8" ?>
<layer-list>
<item height="4dp">
<shape
type="rounded"
radius="2dp"
color="?colorSurfaceVariant"/>
</item>
</layer-list>
5 changes: 4 additions & 1 deletion core/res/ex-layout/main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
width="match_parent"
height="wrap_content"
margin="5dp"/>
<Button
<SeekBar
width="match_parent"
height="wrap_content"
progress="50"
background="#F00"
max="100"
margin="5dp"/>

</LinearLayout>
Expand Down
6 changes: 6 additions & 0 deletions core/res/style/defaults.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@
<item name="scrollbar">@drawable/scrollbar_thumb</item>
</style>

<style name="Widget.SeekBar">
<item name="trackDrawable">@drawable-default/seekbar_track</item>
<item name="thumbDrawable">@drawable-default/seekbar_thumb</item>
<item name="progressDrawable">@drawable-default/seekbar_progress</item>
</style>

<style name="Widget.MenuLayout">
<style name="background">@drawable/menu_background</style>
<style name="paddingTop">10dp</style>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public void draw(Canvas canvas) {
public int getWidth() {
int width = 1;
for (Layer layer: layers) {
width = Math.max(width, layer.drawable.getWidth()+layer.padding.left+layer.padding.right);
width = Math.max(width, layer.getWidth()+layer.padding.left+layer.padding.right);
}
return width;
}
Expand All @@ -45,7 +45,7 @@ public int getWidth() {
public int getHeight() {
int height = 1;
for (Layer layer: layers) {
height = Math.max(height, layer.drawable.getWidth()+layer.padding.bottom+layer.padding.top);
height = Math.max(height, layer.getHeight()+layer.padding.bottom+layer.padding.top);
}
return height;
}
Expand Down Expand Up @@ -105,5 +105,13 @@ public void setBounds(Rect rect) {

drawable.setBounds(tmp);
}

public int getWidth() {
return size.width == -1 ? drawable.getWidth() : size.width;
}

public int getHeight() {
return size.height == -1 ? drawable.getHeight() : size.height;
}
}
}
10 changes: 10 additions & 0 deletions core/src/br/nullexcept/mux/graphics/drawable/SelectorDrawable.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,16 @@ public boolean setState(StateList state) {
return !current.equals(old);
}

@Override
public int getWidth() {
return current == null ? super.getWidth() : current.getWidth();
}

@Override
public int getHeight() {
return current == null ? super.getHeight() : current.getHeight();
}

private class StateDrawable {
public final StateList stateList;
public final Drawable drawable;
Expand Down
5 changes: 5 additions & 0 deletions core/src/br/nullexcept/mux/lang/Function3.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package br.nullexcept.mux.lang;

public interface Function3<A,B,C> {
void run(A a, B b, C c);
}
1 change: 1 addition & 0 deletions core/src/br/nullexcept/mux/res/LayoutInflater.java
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ private ViewGroup.LayoutParams parseLayoutParams(AttributeList attr){
registerView("TextView", TextView::new);
registerView("Switch", Switch::new);
registerView("View", View::new);
registerView("SeekBar", SeekBar::new);
}

public static void registerView(String name, ViewRegister register){
Expand Down
3 changes: 2 additions & 1 deletion core/src/br/nullexcept/mux/res/Parser.java
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ private static Bitmap openBitmap(String path) {
}

public static Drawable parseDrawable(Resources resources, String value) {
value = value.trim();
if (value.startsWith("#")){
return new ColorDrawable(Color.parseColor(value));
} else {
Expand All @@ -242,7 +243,7 @@ public static Drawable parseDrawable(Resources resources, String value) {
}
}
}
Log.error(LOG_TAG,"Invalid background value: "+value);
Log.error(LOG_TAG,"Invalid drawable source value: "+value);
return null;
}

Expand Down
5 changes: 5 additions & 0 deletions core/src/br/nullexcept/mux/view/AttrList.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public class AttrList {
public static final String summary = "summary";
public static final String icon = "icon";
public static final String visibility = "visibility";
public static final String progress = "progress";
public static final String max = "max";
public static final String thumbDrawable = "thumbDrawable";
public static final String trackDrawable = "trackDrawable";
public static final String progressDrawable = "progressDrawable";
}
9 changes: 6 additions & 3 deletions core/src/br/nullexcept/mux/widget/FlowLayout.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
import br.nullexcept.mux.app.Context;
import br.nullexcept.mux.graphics.Point;
import br.nullexcept.mux.res.AttributeList;
import br.nullexcept.mux.view.AttrList;
import br.nullexcept.mux.view.Gravity;
import br.nullexcept.mux.view.View;
import br.nullexcept.mux.view.ViewGroup;

public class FlowLayout extends ViewGroup {
private int dividerSize = 16;
public FlowLayout(Context context) {
super(context);
this(context, null);
}

public FlowLayout(Context context, AttributeList attrs) {
super(context, attrs);
public FlowLayout(Context context, AttributeList init) {
super(context, init);
AttributeList attrs = initialAttributes();
attrs.searchDimension(AttrList.dividerSize, x -> dividerSize = x.intValue());
}

@Override
Expand Down
Loading

0 comments on commit eeba3e0

Please sign in to comment.