Skip to content

Commit

Permalink
feat: Improve palette widgets UI
Browse files Browse the repository at this point in the history
  • Loading branch information
aikrq committed Oct 20, 2024
1 parent 64e51db commit 4c5a8cb
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 40 deletions.
14 changes: 7 additions & 7 deletions app/src/main/java/a/a/a/ViewEditorFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,15 @@ private void e() {
viewEditor.addWidget(PaletteWidget.b.b, "", "TextView", "TextView");
viewEditor.addWidgetLayout(PaletteWidget.a.c, "");
viewEditor.addWidgetLayout(PaletteWidget.a.d, "");
viewEditor.extraWidgetLayout("", "RadioGroup");
viewEditor.extraWidgetLayout("", "RadioGroup", true);

viewEditor.paletteWidget.extraTitle("AndroidX", 0);
viewEditor.extraWidgetLayout("", "TabLayout");
viewEditor.extraWidgetLayout("", "BottomNavigationView");
viewEditor.extraWidgetLayout("", "CollapsingToolbarLayout");
viewEditor.extraWidgetLayout("", "CardView");
viewEditor.extraWidgetLayout("", "TextInputLayout");
viewEditor.extraWidgetLayout("", "SwipeRefreshLayout");
viewEditor.extraWidgetLayout("", "SwipeRefreshLayout", true);

viewEditor.addWidget(PaletteWidget.b.c, "", "EditText", "Edit Text");
viewEditor.extraWidget("", "AutoCompleteTextView", "AutoCompleteTextView");
Expand All @@ -243,34 +243,34 @@ private void e() {
viewEditor.extraWidget("", "RatingBar", "RatingBar");
viewEditor.extraWidget("", "SearchView", "SearchView");
viewEditor.extraWidget("", "VideoView", "VideoView");
viewEditor.addWidget(PaletteWidget.b.h, "", "WebView", "WebView");
viewEditor.addWidget(PaletteWidget.b.h, "", "WebView", "WebView", true);

viewEditor.paletteWidget.extraTitle("List", 1);
viewEditor.addWidget(PaletteWidget.b.e, "", "ListView", "ListView");
viewEditor.extraWidget("", "GridView", "GridView");
viewEditor.extraWidget("", "RecyclerView", "RecyclerView");
viewEditor.addWidget(PaletteWidget.b.f, "", "Spinner", "Spinner");
viewEditor.extraWidget("", "ViewPager", "ViewPager");
viewEditor.extraWidget("", "ViewPager", "ViewPager", true);

viewEditor.paletteWidget.extraTitle("Library", 1);
viewEditor.extraWidget("", "WaveSideBar", "WaveSideBar");
viewEditor.extraWidget("", "PatternLockView", "PatternLockView");
viewEditor.extraWidget("", "CodeView", "CodeView");
viewEditor.extraWidget("", "LottieAnimation", "LottieAnimation");
viewEditor.extraWidget("", "OTPView", "OTPView");
viewEditor.extraWidget("", "OTPView", "OTPView", true);

viewEditor.paletteWidget.extraTitle("Google", 1);
viewEditor.addWidget(PaletteWidget.b.l, "", "AdView", "AdView");
viewEditor.addWidget(PaletteWidget.b.n, "", "MapView", "MapView");
viewEditor.extraWidget("", "SignInButton", "SignInButton");
viewEditor.extraWidget("", "YoutubePlayer", "YoutubePlayer");
viewEditor.extraWidget("", "YoutubePlayer", "YoutubePlayer", true);

viewEditor.paletteWidget.extraTitle("Date & Time", 1);
viewEditor.extraWidget("", "AnalogClock", "AnalogClock");
viewEditor.extraWidget("", "DigitalClock", "DigitalClock");
viewEditor.extraWidget("", "TimePicker", "TimePicker");
viewEditor.extraWidget("", "DatePicker", "DatePicker");
viewEditor.addWidget(PaletteWidget.b.k, "", "CalendarView", "CalendarView");
viewEditor.addWidget(PaletteWidget.b.k, "", "CalendarView", "CalendarView", true);
}

private void startAnimation() {
Expand Down
18 changes: 15 additions & 3 deletions app/src/main/java/com/besome/sketch/editor/view/ViewEditor.java
Original file line number Diff line number Diff line change
Expand Up @@ -857,19 +857,31 @@ public void addWidgetLayout(PaletteWidget.a aVar, String str) {
}

public void extraWidgetLayout(String str, String str2) {
View extraWidgetLayout = paletteWidget.extraWidgetLayout(str, str2);
extraWidgetLayout(str, str2, false);
}

public void extraWidgetLayout(String str, String str2, boolean hideDivider) {
View extraWidgetLayout = paletteWidget.extraWidgetLayout(str, str2, hideDivider);
extraWidgetLayout.setClickable(true);
extraWidgetLayout.setOnTouchListener(this);
}

public void addWidget(PaletteWidget.b bVar, String str, String str2, String str3) {
View widget = paletteWidget.a(bVar, str, str2, str3);
addWidget(bVar, str, str2, str3, false);
}

public void addWidget(PaletteWidget.b bVar, String str, String str2, String str3, boolean hideDivider) {
View widget = paletteWidget.a(bVar, str, str2, str3, hideDivider);
widget.setClickable(true);
widget.setOnTouchListener(this);
}

public void extraWidget(String str, String str2, String str3) {
View extraWidget = paletteWidget.extraWidget(str, str2, str3);
extraWidget(str, str2, str3, false);
}

public void extraWidget(String str, String str2, String str3, boolean hideDivider) {
View extraWidget = paletteWidget.extraWidget(str, str2, str3, hideDivider);
extraWidget.setClickable(true);
extraWidget.setOnTouchListener(this);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ public class IconBase extends BaseWidget {

public IconBase(Context context) {
super(context);
setBackgroundResource(R.drawable.icon_bg);
}

public ViewBean getBean() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public View a(PaletteWidget.a layoutType, String tag) {
return layout;
}

public View a(PaletteWidget.b widgetType, String tag, String text, String resourceName) {
public View a(PaletteWidget.b widgetType, String tag, String text, String resourceName, boolean hideDivider) {
IconBase iconBase;
switch (widgetType) {
case a:
Expand Down Expand Up @@ -152,6 +152,7 @@ public View a(PaletteWidget.b widgetType, String tag, String text, String resour

iconBase.setText(text);
iconBase.setName(resourceName);
iconBase.setHideDivider(hideDivider);
widgetsContainer.addView(iconBase);
return iconBase;
}
Expand Down Expand Up @@ -179,23 +180,17 @@ public void removeWidgets() {
public void extraTitle(String title, int targetType) {
LinearLayout target = targetType == 0 ? layoutContainer : widgetsContainer;

LinearLayout divider = new LinearLayout(getContext());
divider.setLayoutParams(new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1)));
divider.setOrientation(LinearLayout.HORIZONTAL);
divider.setBackgroundColor(Color.parseColor("#00000000"));
target.addView(divider);

TextView titleView = new TextView(getContext());
LayoutParams layoutParams = new LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(dpToPx(4), dpToPx(4), dpToPx(4), dpToPx(4));
layoutParams.setMargins(dpToPx(6), dpToPx(6), dpToPx(6), dpToPx(6));
titleView.setLayoutParams(layoutParams);
titleView.setText(title);
titleView.setTextSize(12);
titleView.setTextColor(MaterialColors.getColor(titleView, com.google.android.material.R.attr.colorPrimary));
target.addView(titleView);
}

public View extraWidget(String tag, String title, String name) {
public View extraWidget(String tag, String title, String name, boolean hideDivider) {
IconBase iconBase;
Context context = getContext();
iconBase = switch (title) {
Expand Down Expand Up @@ -230,11 +225,12 @@ public View extraWidget(String tag, String title, String name) {

iconBase.setText(title);
iconBase.setName(name);
iconBase.setHideDivider(hideDivider);
widgetsContainer.addView(iconBase);
return iconBase;
}

public View extraWidgetLayout(String tag, String name) {
public View extraWidgetLayout(String tag, String name, boolean hideDivider) {
IconBase iconBase;
Context context = getContext();
iconBase = switch (name) {
Expand All @@ -251,6 +247,7 @@ public View extraWidgetLayout(String tag, String name) {
iconBase.setTag(tag);
}

iconBase.setHideDivider(hideDivider);
layoutContainer.addView(iconBase);
return iconBase;
}
Expand Down
12 changes: 8 additions & 4 deletions app/src/main/java/com/besome/sketch/lib/base/BaseWidget.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
public class BaseWidget extends LinearLayout {
private ImageView img_widget;
private TextView tv_widget;
private View divider_widget;
@DrawableRes
private int widgetImgResId;
private int widgetType;
Expand All @@ -24,7 +25,8 @@ public BaseWidget(Context context) {
super(context);
View.inflate(context, R.layout.widget_layout, this);

setOrientation(HORIZONTAL);
setDrawingCacheEnabled(true);
setOrientation(VERTICAL);
setGravity(Gravity.CENTER);

a(context);
Expand All @@ -33,9 +35,7 @@ public BaseWidget(Context context) {
public void a(Context context) {
img_widget = findViewById(R.id.img_widget);
tv_widget = findViewById(R.id.tv_widget);

setBackgroundResource(R.drawable.icon_bg);
setDrawingCacheEnabled(true);
divider_widget = findViewById(R.id.divider_widget);
}

public int getWidgetImageResId() {
Expand Down Expand Up @@ -67,6 +67,10 @@ public void setWidgetType(a widgetType) {
this.widgetType = widgetType.ordinal();
}

public void setHideDivider(boolean hideDivider) {
divider_widget.setVisibility(hideDivider ? View.GONE : View.VISIBLE);
}

public enum a {
a,
b
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/view_editor.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<LinearLayout
android:id="@+id/layout_palette"
android:layout_width="120dp"
android:layout_width="128dp"
android:layout_height="match_parent"
android:background="?attr/colorSurface"
android:orientation="vertical">
Expand Down
45 changes: 31 additions & 14 deletions app/src/main/res/layout/widget_layout.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,37 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<ImageView
android:id="@+id/img_widget"
android:layout_width="14dp"
android:layout_height="14dp"
android:layout_marginStart="4dp"
android:layout_gravity="center" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="6dp"
android:layout_marginStart="6dp"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="6dp"
android:paddingTop="6dp">

<ImageView
android:id="@+id/img_widget"
android:layout_width="14dp"
android:layout_height="14dp" />

<TextView
android:id="@+id/tv_widget"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:textAppearance="?attr/textAppearanceBodySmall"
android:textSize="11sp" />

</LinearLayout>

<TextView
android:id="@+id/tv_widget"
<com.google.android.material.divider.MaterialDivider
android:id="@+id/divider_widget"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="4dp"
android:layout_marginStart="3dp"
android:layout_gravity="center"
android:textAppearance="?attr/textAppearanceBodySmall"
android:textSize="11sp" />
app:dividerInsetEnd="6dp"
app:dividerInsetStart="6dp"
app:dividerThickness="0.5dp" />

</merge>

0 comments on commit 4c5a8cb

Please sign in to comment.