From b8de2defb90e208440f343e36c8567a1f19361df Mon Sep 17 00:00:00 2001
From: aikrq <95296093+aikrq@users.noreply.github.com>
Date: Sun, 20 Oct 2024 12:11:23 +0700
Subject: [PATCH] feat: Improve palette widgets UI
---
.../main/java/a/a/a/ViewEditorFragment.java | 14 +++---
.../besome/sketch/editor/view/ViewEditor.java | 18 ++++++--
.../sketch/editor/view/palette/IconBase.java | 1 -
.../editor/view/palette/PaletteWidget.java | 20 +++------
.../besome/sketch/lib/base/BaseWidget.java | 12 +++--
app/src/main/res/layout/palette_widget.xml | 12 ++---
app/src/main/res/layout/view_editor.xml | 2 +-
app/src/main/res/layout/widget_layout.xml | 45 +++++++++++++------
8 files changed, 72 insertions(+), 52 deletions(-)
diff --git a/app/src/main/java/a/a/a/ViewEditorFragment.java b/app/src/main/java/a/a/a/ViewEditorFragment.java
index 6bb395ab56..b71d49c4f3 100644
--- a/app/src/main/java/a/a/a/ViewEditorFragment.java
+++ b/app/src/main/java/a/a/a/ViewEditorFragment.java
@@ -218,7 +218,7 @@ 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");
@@ -226,7 +226,7 @@ private void e() {
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");
@@ -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() {
diff --git a/app/src/main/java/com/besome/sketch/editor/view/ViewEditor.java b/app/src/main/java/com/besome/sketch/editor/view/ViewEditor.java
index f5fa317c8d..b466dedfc8 100644
--- a/app/src/main/java/com/besome/sketch/editor/view/ViewEditor.java
+++ b/app/src/main/java/com/besome/sketch/editor/view/ViewEditor.java
@@ -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);
}
diff --git a/app/src/main/java/com/besome/sketch/editor/view/palette/IconBase.java b/app/src/main/java/com/besome/sketch/editor/view/palette/IconBase.java
index 5c4dc23739..2cbbf3455a 100644
--- a/app/src/main/java/com/besome/sketch/editor/view/palette/IconBase.java
+++ b/app/src/main/java/com/besome/sketch/editor/view/palette/IconBase.java
@@ -11,7 +11,6 @@ public class IconBase extends BaseWidget {
public IconBase(Context context) {
super(context);
- setBackgroundResource(R.drawable.icon_bg);
}
public ViewBean getBean() {
diff --git a/app/src/main/java/com/besome/sketch/editor/view/palette/PaletteWidget.java b/app/src/main/java/com/besome/sketch/editor/view/palette/PaletteWidget.java
index 4ca462112a..dc6669e1ae 100644
--- a/app/src/main/java/com/besome/sketch/editor/view/palette/PaletteWidget.java
+++ b/app/src/main/java/com/besome/sketch/editor/view/palette/PaletteWidget.java
@@ -51,7 +51,6 @@ public class PaletteWidget extends LinearLayout {
private LinearLayout layoutContainer;
private LinearLayout widgetsContainer;
- private View divider;
private TextView titleLayouts;
private TextView titleWidgets;
private CustomScrollView scrollView;
@@ -82,7 +81,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:
@@ -152,6 +151,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;
}
@@ -164,7 +164,6 @@ private void initialize(Context context) {
wB.a(context, this, R.layout.palette_widget);
layoutContainer = findViewById(R.id.layout);
widgetsContainer = findViewById(R.id.widget);
- divider = findViewById(R.id.divider);
titleLayouts = findViewById(R.id.tv_layout);
titleWidgets = findViewById(R.id.tv_widget);
titleLayouts.setText(Helper.getResString(R.string.view_panel_title_layouts));
@@ -179,15 +178,9 @@ 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);
@@ -195,7 +188,7 @@ public void extraTitle(String title, int targetType) {
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) {
@@ -230,11 +223,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) {
@@ -251,13 +245,13 @@ public View extraWidgetLayout(String tag, String name) {
iconBase.setTag(tag);
}
+ iconBase.setHideDivider(hideDivider);
layoutContainer.addView(iconBase);
return iconBase;
}
public void setLayoutVisible(int visibility) {
layoutContainer.setVisibility(visibility);
- divider.setVisibility(visibility);
titleLayouts.setVisibility(visibility);
}
diff --git a/app/src/main/java/com/besome/sketch/lib/base/BaseWidget.java b/app/src/main/java/com/besome/sketch/lib/base/BaseWidget.java
index 2f98f1d23e..bdc2b85e17 100644
--- a/app/src/main/java/com/besome/sketch/lib/base/BaseWidget.java
+++ b/app/src/main/java/com/besome/sketch/lib/base/BaseWidget.java
@@ -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;
@@ -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);
@@ -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() {
@@ -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
diff --git a/app/src/main/res/layout/palette_widget.xml b/app/src/main/res/layout/palette_widget.xml
index 4ca4ce9911..8f3dc7df4d 100644
--- a/app/src/main/res/layout/palette_widget.xml
+++ b/app/src/main/res/layout/palette_widget.xml
@@ -17,7 +17,7 @@
android:id="@+id/tv_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:layout_margin="4dp"
+ android:layout_margin="6dp"
android:textColor="?attr/colorPrimary"
android:textSize="12sp" />
@@ -29,18 +29,11 @@
android:paddingRight="4dp"
android:paddingBottom="4dp" />
-
-
@@ -51,6 +44,7 @@
android:orientation="vertical"
android:paddingRight="4dp"
android:paddingBottom="4dp" />
+
diff --git a/app/src/main/res/layout/view_editor.xml b/app/src/main/res/layout/view_editor.xml
index fdab19e231..59bde5da5b 100644
--- a/app/src/main/res/layout/view_editor.xml
+++ b/app/src/main/res/layout/view_editor.xml
@@ -6,7 +6,7 @@
diff --git a/app/src/main/res/layout/widget_layout.xml b/app/src/main/res/layout/widget_layout.xml
index 3ab327b3b4..66c35bf9e5 100644
--- a/app/src/main/res/layout/widget_layout.xml
+++ b/app/src/main/res/layout/widget_layout.xml
@@ -1,20 +1,37 @@
-
+
-
+
+
+
+
+
+
+
-
+ app:dividerInsetEnd="6dp"
+ app:dividerInsetStart="24dp"
+ app:dividerThickness="0.5dp" />