Skip to content

Commit 6b297bc

Browse files
committed
update dialog (add rounded corner)
1 parent e9a359c commit 6b297bc

6 files changed

Lines changed: 102 additions & 201 deletions

File tree

libwebview/src/main/cpp/libwebview/libwebview.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,15 +89,15 @@ jint JNI_OnLoad(JavaVM *vm, void *reserved) {
8989
g_func_set_unity_texture_id = g_main_thread_env->GetMethodID(g_class_unity_connect,
9090
"setUnityTextureID", "(J)V");
9191

92-
if (g_func_content_exists == nullptr) {
93-
LOGE("JNI Function 'contentExists' not found");
92+
if (g_func_set_unity_texture_id == nullptr) {
93+
LOGE("JNI Function 'setUnityTextureID' not found");
9494
}
9595

9696
g_func_content_exists = g_main_thread_env->GetMethodID(g_class_unity_connect,
9797
"contentExists", "()Z");
9898

99-
if (g_func_set_unity_texture_id == nullptr) {
100-
LOGE("JNI Function 'setUnityTextureID' not found");
99+
if (g_func_content_exists == nullptr) {
100+
LOGE("JNI Function 'contentExists' not found");
101101
}
102102

103103
g_func_set_surface = g_main_thread_env->GetMethodID(g_class_unity_connect, "setSurface",

libwebview/src/main/java/com/tlab/dialog/AlertDialog.java

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public class AlertDialog extends Dialog implements DialogInterface {
1818

1919
private final TextView m_title;
2020
private final TextView m_body;
21-
private final LinearLayout m_options;
2221

2322
public AlertDialog(Context context) {
2423
super(context);
@@ -51,14 +50,10 @@ public AlertDialog(Context context) {
5150
// convenient to use as a scalable margin.
5251
TextView dummy = new TextView(context);
5352
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
54-
dummy.setText(" ");
53+
dummy.setText(" ");
5554
dummy.setTextSize(15);
5655
vertical.addView(dummy);
5756

58-
m_options = new LinearLayout(context);
59-
m_options.setOrientation(LinearLayout.HORIZONTAL);
60-
m_options.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
61-
m_options.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
6257
vertical.addView(m_options);
6358

6459
addView(vertical);
@@ -68,24 +63,4 @@ public void setMessage(String title, String body) {
6863
m_title.setText(title);
6964
m_body.setText(body);
7065
}
71-
72-
public void setOptions(String option, final DialogInterface.OnSelectOptionListener listener) {
73-
TextView dummy = new TextView(m_context);
74-
dummy.setText(" ");
75-
dummy.setTextSize(15);
76-
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
77-
78-
m_options.addView(dummy);
79-
80-
Button button = new Button(m_context);
81-
button.setTextSize(15);
82-
button.setText(option);
83-
button.setTextColor(Color.GREEN);
84-
button.setBackgroundColor(Color.TRANSPARENT);
85-
86-
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
87-
button.setOnClickListener(v -> listener.OnSelectOption(option));
88-
89-
m_options.addView(button);
90-
}
9166
}

libwebview/src/main/java/com/tlab/dialog/ColorPicker.java

Lines changed: 26 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import android.content.Context;
44
import android.graphics.Color;
5+
import android.graphics.drawable.GradientDrawable;
56
import android.view.Gravity;
6-
import android.view.View;
77
import android.widget.Button;
88
import android.widget.LinearLayout;
99
import android.widget.SeekBar;
@@ -14,8 +14,7 @@ public class ColorPicker extends Dialog implements DialogInterface {
1414
private final int DEFAULT_SLIDER_SIZE_X = 500;
1515
private final int DEFAULT_SLIDER_SIZE_Y = 100;
1616

17-
private final LinearLayout m_options;
18-
private final LinearLayout m_vertical;
17+
private final GradientDrawable m_colorPreview;
1918
private int m_r;
2019
private int m_g;
2120
private int m_b;
@@ -30,19 +29,19 @@ public ColorPicker(Context context) {
3029
setLayoutParams(new LayoutParams(DEFAULT_VIEW_SIZE, DEFAULT_VIEW_SIZE));
3130
setGravity(Gravity.CENTER);
3231

33-
m_vertical = new LinearLayout(context);
34-
m_vertical.setOrientation(LinearLayout.VERTICAL);
35-
m_vertical.setGravity(Gravity.CENTER);
36-
m_vertical.setLayoutParams(new LayoutParams((int) (DEFAULT_VIEW_SIZE * 0.75f), LayoutParams.WRAP_CONTENT));
32+
LinearLayout vertical = new LinearLayout(context);
33+
vertical.setOrientation(LinearLayout.VERTICAL);
34+
vertical.setGravity(Gravity.CENTER);
35+
vertical.setLayoutParams(new LayoutParams((int) (DEFAULT_VIEW_SIZE * 0.75f), LayoutParams.WRAP_CONTENT));
3736

3837
m_r = 126;
3938
m_g = 126;
4039
m_b = 126;
41-
SeekBar r = getSeekBar(context, 0, 255, m_r, DEFAULT_SLIDER_SIZE_X, DEFAULT_SLIDER_SIZE_Y, new SeekBar.OnSeekBarChangeListener() {
40+
SeekBar r = getSeekBar(context, m_r, new SeekBar.OnSeekBarChangeListener() {
4241
@Override
4342
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
4443
m_r = progress;
45-
m_vertical.setBackgroundColor(Color.rgb(m_r, m_g, m_b));
44+
m_colorPreview.setColor(Color.rgb(m_r, m_g, m_b));
4645
}
4746

4847
@Override
@@ -55,13 +54,13 @@ public void onStopTrackingTouch(SeekBar seekBar) {
5554

5655
}
5756
});
58-
m_vertical.addView(r);
57+
vertical.addView(r);
5958

60-
SeekBar g = getSeekBar(context, 0, 255, m_g, DEFAULT_SLIDER_SIZE_X, DEFAULT_SLIDER_SIZE_Y, new SeekBar.OnSeekBarChangeListener() {
59+
SeekBar g = getSeekBar(context, m_g, new SeekBar.OnSeekBarChangeListener() {
6160
@Override
6261
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
6362
m_g = progress;
64-
m_vertical.setBackgroundColor(Color.rgb(m_r, m_g, m_b));
63+
m_colorPreview.setColor(Color.rgb(m_r, m_g, m_b));
6564
}
6665

6766
@Override
@@ -74,13 +73,13 @@ public void onStopTrackingTouch(SeekBar seekBar) {
7473

7574
}
7675
});
77-
m_vertical.addView(g);
76+
vertical.addView(g);
7877

79-
SeekBar b = getSeekBar(context, 0, 255, m_b, DEFAULT_SLIDER_SIZE_X, DEFAULT_SLIDER_SIZE_Y, new SeekBar.OnSeekBarChangeListener() {
78+
SeekBar b = getSeekBar(context, m_b, new SeekBar.OnSeekBarChangeListener() {
8079
@Override
8180
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
8281
m_b = progress;
83-
m_vertical.setBackgroundColor(Color.rgb(m_r, m_g, m_b));
82+
m_colorPreview.setColor(Color.rgb(m_r, m_g, m_b));
8483
}
8584

8685
@Override
@@ -93,70 +92,30 @@ public void onStopTrackingTouch(SeekBar seekBar) {
9392

9493
}
9594
});
96-
m_vertical.setBackgroundColor(Color.rgb(m_r, m_g, m_b));
97-
m_vertical.addView(b);
95+
m_colorPreview = getBackGround(16);
96+
m_colorPreview.setColor(Color.rgb(m_r, m_g, m_b));
97+
vertical.setBackground(m_colorPreview);
98+
vertical.addView(b);
9899

99-
m_options = new LinearLayout(context);
100-
m_options.setOrientation(LinearLayout.HORIZONTAL);
101-
m_options.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
102-
m_options.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
103-
104-
m_vertical.addView(m_options);
100+
vertical.addView(m_options);
105101

106102
TextView dummy = new TextView(m_context);
107-
dummy.setText(" ");
103+
dummy.setText(" ");
108104
dummy.setTextSize(7);
109105
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
110106

111-
m_vertical.addView(dummy);
107+
vertical.addView(dummy);
112108

113-
addView(m_vertical);
109+
addView(vertical);
114110
}
115111

116-
private SeekBar getSeekBar(Context context, int min, int max, int init, int width, int height, SeekBar.OnSeekBarChangeListener listener) {
112+
private SeekBar getSeekBar(Context context, int init, SeekBar.OnSeekBarChangeListener listener) {
117113
SeekBar seekbar = new SeekBar(context);
118-
seekbar.setMin(min);
119-
seekbar.setMax(max);
114+
seekbar.setMin(0);
115+
seekbar.setMax(255);
120116
seekbar.setProgress(init);
121117
seekbar.setOnSeekBarChangeListener(listener);
122-
seekbar.setLayoutParams(new LayoutParams(width, height));
118+
seekbar.setLayoutParams(new LayoutParams(500, 100));
123119
return seekbar;
124120
}
125-
126-
public void setOptions(String option, final DialogInterface.OnSelectOptionListener listener) {
127-
TextView dummy = new TextView(m_context);
128-
dummy.setText(" ");
129-
dummy.setTextSize(15);
130-
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
131-
132-
m_options.addView(dummy);
133-
134-
Button button = getButton(option, listener);
135-
136-
m_options.addView(button);
137-
138-
dummy = new TextView(m_context);
139-
dummy.setText(" ");
140-
dummy.setTextSize(15);
141-
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
142-
143-
m_options.addView(dummy);
144-
}
145-
146-
private Button getButton(String option, OnSelectOptionListener listener) {
147-
Button button = new Button(m_context);
148-
button.setPadding(10, 10, 10, 10);
149-
button.setMinWidth(0);
150-
button.setMinHeight(0);
151-
button.setMinimumWidth(0);
152-
button.setMinimumHeight(0);
153-
button.setTextSize(15);
154-
button.setText(option);
155-
button.setTextColor(Color.GREEN);
156-
button.setBackgroundColor(Color.WHITE);
157-
158-
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
159-
button.setOnClickListener(v -> listener.OnSelectOption(option));
160-
return button;
161-
}
162121
}

libwebview/src/main/java/com/tlab/dialog/DataTimePickerDialog.java

Lines changed: 9 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
import android.content.Context;
55
import android.graphics.Color;
66
import android.view.Gravity;
7-
import android.view.View;
87
import android.widget.Button;
98
import android.widget.LinearLayout;
109
import android.widget.NumberPicker;
@@ -14,8 +13,6 @@
1413

1514
@SuppressLint("ViewConstructor")
1615
public class DataTimePickerDialog extends Dialog implements DialogInterface {
17-
private final LinearLayout m_options;
18-
1916
private int m_year = 0;
2017
private int m_month = 0;
2118
private int m_day = 0;
@@ -51,7 +48,7 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
5148
setGravity(Gravity.CENTER);
5249

5350
LinearLayout vertical = new LinearLayout(context);
54-
vertical.setBackgroundColor(Color.WHITE);
51+
vertical.setBackground(getBackGround(16));
5552
vertical.setOrientation(LinearLayout.VERTICAL);
5653
vertical.setGravity(Gravity.CENTER);
5754
vertical.setLayoutParams(new LayoutParams((int) (DEFAULT_VIEW_SIZE * 0.75f), LayoutParams.WRAP_CONTENT));
@@ -65,15 +62,15 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
6562
datePicker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
6663

6764
m_year = c.get(Calendar.YEAR);
68-
NumberPicker yearPicker = getNumberPicker(context, 0, 3000, m_year, DEFAULT_NUMBER_PICKER_SIZE_X, DEFAULT_NUMBER_PICKER_SIZE_Y, (picker, oldVal, newVal) -> m_year = newVal);
65+
NumberPicker yearPicker = getNumberPicker(context, 0, 3000, m_year, (picker, oldVal, newVal) -> m_year = newVal);
6966
datePicker.addView(yearPicker);
7067

7168
m_month = c.get(Calendar.MONTH) + 1;
72-
NumberPicker monthPicker = getNumberPicker(context, 1, 12, m_month, DEFAULT_NUMBER_PICKER_SIZE_X, DEFAULT_NUMBER_PICKER_SIZE_Y, (picker, oldVal, newVal) -> m_month = newVal);
69+
NumberPicker monthPicker = getNumberPicker(context, 1, 12, m_month, (picker, oldVal, newVal) -> m_month = newVal);
7370
datePicker.addView(monthPicker);
7471

7572
m_day = c.get(Calendar.DATE);
76-
NumberPicker dayPicker = getNumberPicker(context, 1, 31, m_day, DEFAULT_NUMBER_PICKER_SIZE_X, DEFAULT_NUMBER_PICKER_SIZE_Y, (picker, oldVal, newVal) -> m_day = newVal);
73+
NumberPicker dayPicker = getNumberPicker(context, 1, 31, m_day, (picker, oldVal, newVal) -> m_day = newVal);
7774
datePicker.addView(dayPicker);
7875

7976
vertical.addView(datePicker);
@@ -86,25 +83,20 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
8683
timePicker.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
8784

8885
m_hour = c.get(Calendar.HOUR);
89-
NumberPicker hourPicker = getNumberPicker(context, 0, 23, m_hour, DEFAULT_NUMBER_PICKER_SIZE_X, DEFAULT_NUMBER_PICKER_SIZE_Y, (picker, oldVal, newVal) -> m_hour = newVal);
86+
NumberPicker hourPicker = getNumberPicker(context, 0, 23, m_hour, (picker, oldVal, newVal) -> m_hour = newVal);
9087
timePicker.addView(hourPicker);
9188

9289
m_minutes = c.get(Calendar.MINUTE);
93-
NumberPicker minutesPicker = getNumberPicker(context, 0, 59, m_minutes, DEFAULT_NUMBER_PICKER_SIZE_X, DEFAULT_NUMBER_PICKER_SIZE_Y, (picker, oldVal, newVal) -> m_minutes = newVal);
90+
NumberPicker minutesPicker = getNumberPicker(context, 0, 59, m_minutes, (picker, oldVal, newVal) -> m_minutes = newVal);
9491
timePicker.addView(minutesPicker);
9592

9693
vertical.addView(timePicker);
9794
}
9895

99-
m_options = new LinearLayout(context);
100-
m_options.setOrientation(LinearLayout.HORIZONTAL);
101-
m_options.setGravity(Gravity.RIGHT | Gravity.BOTTOM);
102-
m_options.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
103-
10496
vertical.addView(m_options);
10597

10698
TextView dummy = new TextView(m_context);
107-
dummy.setText(" ");
99+
dummy.setText(" ");
108100
dummy.setTextSize(7);
109101
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
110102

@@ -113,50 +105,13 @@ public DataTimePickerDialog(Context context, boolean date, boolean time) {
113105
addView(vertical);
114106
}
115107

116-
private NumberPicker getNumberPicker(Context context, int min, int max, int init, int width, int height, NumberPicker.OnValueChangeListener listener) {
108+
private NumberPicker getNumberPicker(Context context, int min, int max, int init, NumberPicker.OnValueChangeListener listener) {
117109
NumberPicker numberPicker = new NumberPicker(context);
118110
numberPicker.setMinValue(min);
119111
numberPicker.setMaxValue(max);
120112
numberPicker.setValue(init);
121113
numberPicker.setOnValueChangedListener(listener);
122-
numberPicker.setLayoutParams(new LayoutParams(width, height));
114+
numberPicker.setLayoutParams(new LayoutParams(150, 300));
123115
return numberPicker;
124116
}
125-
126-
public void setOptions(String option, final DialogInterface.OnSelectOptionListener listener) {
127-
TextView dummy = new TextView(m_context);
128-
dummy.setText(" ");
129-
dummy.setTextSize(15);
130-
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
131-
132-
m_options.addView(dummy);
133-
134-
Button button = getButton(option, listener);
135-
136-
m_options.addView(button);
137-
138-
dummy = new TextView(m_context);
139-
dummy.setText(" ");
140-
dummy.setTextSize(15);
141-
dummy.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
142-
143-
m_options.addView(dummy);
144-
}
145-
146-
private Button getButton(String option, OnSelectOptionListener listener) {
147-
Button button = new Button(m_context);
148-
button.setPadding(10, 10, 10, 10);
149-
button.setMinWidth(0);
150-
button.setMinHeight(0);
151-
button.setMinimumWidth(0);
152-
button.setMinimumHeight(0);
153-
button.setTextSize(15);
154-
button.setText(option);
155-
button.setTextColor(Color.GREEN);
156-
button.setBackgroundColor(Color.WHITE);
157-
158-
button.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
159-
button.setOnClickListener(v -> listener.OnSelectOption(option));
160-
return button;
161-
}
162117
}

0 commit comments

Comments
 (0)