Skip to content

Commit b2bfb8c

Browse files
author
qinpengcheng
committed
append method setCornerRadii
1 parent 38a12fd commit b2bfb8c

File tree

5 files changed

+178
-38
lines changed

5 files changed

+178
-38
lines changed

VideoOS/LuaViewSDK/src/com/taobao/luaview/fun/mapper/ui/UIViewMethodMapper.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ public class UIViewMethodMapper<U extends UDView> extends BaseMethodMapper<U> {
145145
"margin",//104
146146
"onTouch",//105
147147
"mqttCallback",//106
148-
"tag"//107
148+
"tag",//107
149+
"cornerRadii"//108
149150
};
150151

151152
public Varargs tag(U view, Varargs varargs) {
@@ -387,6 +388,8 @@ public Varargs invoke(int code, U target, Varargs varargs) {
387388
return mqttCallback(target, varargs);
388389
case 107:
389390
return tag(target, varargs);
391+
case 108:
392+
return cornerRadii(target, varargs);
390393

391394
}
392395
return super.invoke(code, target, varargs);
@@ -2250,6 +2253,52 @@ public LuaValue getCornerRadius(U view, Varargs varargs) {
22502253
return valueOf(DimenUtil.pxToDpi(view.getCornerRadius()));
22512254
}
22522255

2256+
/**
2257+
* 设置边框圆角 单独设置四个角
2258+
*
2259+
* @param view
2260+
* @param varargs
2261+
* @return
2262+
*/
2263+
public LuaValue cornerRadii(U view, Varargs varargs) {
2264+
if (varargs.narg() > 1) {
2265+
return setCornerRadii(view, varargs);
2266+
} else {
2267+
return LuaValue.TRUE;
2268+
}
2269+
}
2270+
2271+
public LuaValue setCornerRadii(U view, Varargs varargs) {
2272+
Float leftTopX = LuaUtil.getFloat(varargs, 2);
2273+
leftTopX = leftTopX == null ? 0 : leftTopX;
2274+
Float leftTopY = LuaUtil.getFloat(varargs, 3);
2275+
leftTopY = leftTopY == null ? 0 : leftTopY;
2276+
Float rightTopX = LuaUtil.getFloat(varargs, 4);
2277+
rightTopX = rightTopX == null ? 0 : rightTopX;
2278+
Float rightTopY = LuaUtil.getFloat(varargs, 5);
2279+
rightTopY = rightTopY == null ? 0 : rightTopY;
2280+
Float leftBottomX = LuaUtil.getFloat(varargs, 6);
2281+
leftBottomX = leftBottomX == null ? 0 : leftBottomX;
2282+
Float leftBottomY = LuaUtil.getFloat(varargs, 7);
2283+
leftBottomY = leftBottomY == null ? 0 : leftBottomY;
2284+
Float rightBottomX = LuaUtil.getFloat(varargs, 8);
2285+
rightBottomX = rightBottomX == null ? 0 : rightBottomX;
2286+
Float rightBottomY = LuaUtil.getFloat(varargs, 9);
2287+
rightBottomY = rightBottomY == null ? 0 : rightBottomY;
2288+
float[] radii = {
2289+
leftTopX != null ? DimenUtil.dpiToPxF(leftTopX) : 0.0f,
2290+
leftTopY != null ? DimenUtil.dpiToPxF(leftTopY) : 0.0f,
2291+
rightTopX != null ? DimenUtil.dpiToPxF(rightTopX) : 0.0f,
2292+
rightTopY != null ? DimenUtil.dpiToPxF(rightTopY) : 0.0f,
2293+
leftBottomX != null ? DimenUtil.dpiToPxF(leftBottomX) : 0.0f,
2294+
leftBottomY != null ? DimenUtil.dpiToPxF(leftBottomY) : 0.0f,
2295+
rightBottomX != null ? DimenUtil.dpiToPxF(rightBottomX) : 0.0f,
2296+
rightBottomY != null ? DimenUtil.dpiToPxF(rightBottomY) : 0.0f
2297+
};
2298+
return view.setCornerRadii(radii);
2299+
}
2300+
2301+
22532302
/**
22542303
* 开始动画
22552304
*

VideoOS/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDImageView.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ public UDImageView(T view, Globals globals, LuaValue metatable, Varargs initPara
6161
super(view, globals, metatable, initParams);
6262
}
6363

64+
@Override
65+
public UDView setCornerRadii(float[] radii) {
66+
final T view = getView();
67+
if (view != null) {
68+
view.setCornerRadii(radii);
69+
}
70+
return this;
71+
}
72+
6473
@LuaViewApi(since = VmVersion.V_540, revisions = {"之前写在View无效果,5.4.0开始,Image支持该方法"})
6574
@Override
6675
public UDView setCornerRadius(float radius) {

VideoOS/LuaViewSDK/src/com/taobao/luaview/userdata/ui/UDView.java

Lines changed: 71 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
* Copyright (c) 2017, Alibaba Group. All rights reserved.
44
*
55
* This source code is licensed under the MIT.
6-
* For the full copyright and license information,please view the LICENSE file in the root directory of this source tree.
6+
* For the full copyright and license information,please view the LICENSE file in the root
7+
* directory of this source tree.
78
*/
89

910
package com.taobao.luaview.userdata.ui;
@@ -165,10 +166,12 @@ public int getPaddingBottom() {
165166
* @param bottom
166167
* @return
167168
*/
168-
public UDView setMargin(Integer left, Integer top, Integer right, Integer bottom) {//TODO 这里的margin,MarginLayoutParams上有一个问题,当left+right=width或者top+bottom=height有一个问题
169+
public UDView setMargin(Integer left, Integer top, Integer right, Integer bottom) {//TODO
170+
// 这里的margin,MarginLayoutParams上有一个问题,当left+right=width或者top+bottom=height有一个问题
169171
View view = getView();
170172
if (view != null && view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
171-
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
173+
ViewGroup.MarginLayoutParams layoutParams =
174+
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
172175
if (left != null) {
173176
layoutParams.leftMargin = left;
174177
}
@@ -190,7 +193,8 @@ public UDView setMargin(Integer left, Integer top, Integer right, Integer bottom
190193
public int getMarginLeft() {
191194
View view = getView();
192195
if (view != null && view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
193-
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
196+
ViewGroup.MarginLayoutParams layoutParams =
197+
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
194198
return layoutParams.leftMargin;
195199
}
196200
return 0;
@@ -199,7 +203,8 @@ public int getMarginLeft() {
199203
public int getMarginTop() {
200204
View view = getView();
201205
if (view != null && view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
202-
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
206+
ViewGroup.MarginLayoutParams layoutParams =
207+
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
203208
return layoutParams.topMargin;
204209
}
205210
return 0;
@@ -208,7 +213,8 @@ public int getMarginTop() {
208213
public int getMarginRight() {
209214
View view = getView();
210215
if (view != null && view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
211-
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
216+
ViewGroup.MarginLayoutParams layoutParams =
217+
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
212218
return layoutParams.rightMargin;
213219
}
214220
return 0;
@@ -217,7 +223,8 @@ public int getMarginRight() {
217223
public int getMarginBottom() {
218224
View view = getView();
219225
if (view != null && view.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
220-
ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) view.getLayoutParams();
226+
ViewGroup.MarginLayoutParams layoutParams =
227+
(ViewGroup.MarginLayoutParams) view.getLayoutParams();
221228
return layoutParams.bottomMargin;
222229
}
223230
return 0;
@@ -262,7 +269,8 @@ public UDView setBackgroundAlpha(Double alpha) {
262269
public float getBackgroundAlpha() {
263270
T view = getView();
264271
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
265-
return (view != null && view.getBackground() != null) ? view.getBackground().getAlpha() / 255.0f : 1;
272+
return (view != null && view.getBackground() != null) ?
273+
view.getBackground().getAlpha() / 255.0f : 1;
266274
}
267275
return 1;
268276
}
@@ -276,7 +284,8 @@ public UDView setBackgroundColor(Integer color) {
276284
if (color != null) {
277285
View view = getView();
278286
if (view != null) {
279-
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
287+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable
288+
? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
280289
drawable.setColor(color);
281290
LuaViewUtil.setBackground(view, drawable);
282291
}
@@ -303,7 +312,8 @@ public int getBackgroundColor() {
303312
public UDView setCornerRadius(float radius) {
304313
T view = getView();
305314
if (view != null) {
306-
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
315+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ?
316+
(LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
307317
drawable.setCornerRadius(radius);
308318
LuaViewUtil.setBackground(view, drawable);
309319
}
@@ -313,11 +323,23 @@ public UDView setCornerRadius(float radius) {
313323
public float getCornerRadius() {
314324
T view = getView();
315325
if (view != null) {
316-
return view.getBackground() instanceof LVGradientDrawable ? ((LVGradientDrawable) view.getBackground()).getCornerRadius() : 0;
326+
return view.getBackground() instanceof LVGradientDrawable ?
327+
((LVGradientDrawable) view.getBackground()).getCornerRadius() : 0;
317328
}
318329
return 0;
319330
}
320331

332+
public UDView setCornerRadii(float[] radii) {
333+
T view = getView();
334+
if (view != null) {
335+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ?
336+
(LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
337+
drawable.setCornerRadii(radii);
338+
LuaViewUtil.setBackground(view, drawable);
339+
}
340+
return this;
341+
}
342+
321343
/**
322344
* 边框宽度
323345
*
@@ -327,7 +349,8 @@ public float getCornerRadius() {
327349
public UDView setBorderWidth(int borderWidth) {
328350
T view = getView();
329351
if (view != null) {
330-
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
352+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ?
353+
(LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
331354
drawable.setStrokeWidth(borderWidth);
332355
LuaViewUtil.setBackground(view, drawable);
333356
}
@@ -337,7 +360,8 @@ public UDView setBorderWidth(int borderWidth) {
337360
public int getBorderWidth() {
338361
T view = getView();
339362
if (view != null) {
340-
return view.getBackground() instanceof LVGradientDrawable ? ((LVGradientDrawable) view.getBackground()).getStrokeWidth() : 0;
363+
return view.getBackground() instanceof LVGradientDrawable ?
364+
((LVGradientDrawable) view.getBackground()).getStrokeWidth() : 0;
341365
}
342366
return 0;
343367
}
@@ -352,7 +376,8 @@ public UDView setBorderColor(Integer borderColor) {
352376
if (borderColor != null) {
353377
T view = getView();
354378
if (view != null) {
355-
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
379+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable
380+
? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
356381
drawable.setStrokeColor(borderColor);
357382
LuaViewUtil.setBackground(view, drawable);
358383
}
@@ -363,7 +388,8 @@ public UDView setBorderColor(Integer borderColor) {
363388
public int getBorderColor() {
364389
T view = getView();
365390
if (view != null) {
366-
return view.getBackground() instanceof LVGradientDrawable ? ((LVGradientDrawable) view.getBackground()).getStrokeColor() : 0;
391+
return view.getBackground() instanceof LVGradientDrawable ?
392+
((LVGradientDrawable) view.getBackground()).getStrokeColor() : 0;
367393
}
368394
return 0;
369395
}
@@ -378,7 +404,8 @@ public int getBorderColor() {
378404
public UDView setBorderDashSize(float dashWidth, float dashGap) {
379405
T view = getView();
380406
if (view != null) {
381-
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ? (LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
407+
LVGradientDrawable drawable = view.getBackground() instanceof LVGradientDrawable ?
408+
(LVGradientDrawable) view.getBackground() : new LVGradientDrawable();
382409
drawable.setDashSize(dashWidth, dashGap);
383410
}
384411
return this;
@@ -387,15 +414,17 @@ public UDView setBorderDashSize(float dashWidth, float dashGap) {
387414
public float getBorderDashWidth() {
388415
T view = getView();
389416
if (view != null) {
390-
return view.getBackground() instanceof LVGradientDrawable ? ((LVGradientDrawable) view.getBackground()).getDashWidth() : 0;
417+
return view.getBackground() instanceof LVGradientDrawable ?
418+
((LVGradientDrawable) view.getBackground()).getDashWidth() : 0;
391419
}
392420
return 0;
393421
}
394422

395423
public float getBorderDashGap() {
396424
T view = getView();
397425
if (view != null) {
398-
return view.getBackground() instanceof LVGradientDrawable ? ((LVGradientDrawable) view.getBackground()).getDashGap() : 0;
426+
return view.getBackground() instanceof LVGradientDrawable ?
427+
((LVGradientDrawable) view.getBackground()).getDashGap() : 0;
399428
}
400429
return 0;
401430
}
@@ -412,7 +441,8 @@ public float getBorderDashGap() {
412441
public UDView setFrame(int x, int y, int width, int height) {
413442
View view = getView();
414443
if (view != null && view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
415-
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
444+
RelativeLayout.LayoutParams layoutParams =
445+
(RelativeLayout.LayoutParams) view.getLayoutParams();
416446
layoutParams.leftMargin = x;
417447
layoutParams.topMargin = y;
418448
layoutParams.width = width;
@@ -433,7 +463,8 @@ public UDView setXY(int x, int y) {
433463
View view = getView();
434464
if (view != null) {
435465
if (view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
436-
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
466+
RelativeLayout.LayoutParams layoutParams =
467+
(RelativeLayout.LayoutParams) view.getLayoutParams();
437468
layoutParams.leftMargin = x;
438469
layoutParams.topMargin = y;
439470
view.setLayoutParams(layoutParams);
@@ -452,7 +483,8 @@ public UDView setX(int x) {
452483
View view = getView();
453484
if (view != null) {
454485
if (view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
455-
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
486+
RelativeLayout.LayoutParams layoutParams =
487+
(RelativeLayout.LayoutParams) view.getLayoutParams();
456488
layoutParams.leftMargin = x;
457489
view.setLayoutParams(layoutParams);
458490
}
@@ -485,7 +517,8 @@ public UDView setY(int y) {
485517
View view = getView();
486518
if (view != null) {
487519
if (view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
488-
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
520+
RelativeLayout.LayoutParams layoutParams =
521+
(RelativeLayout.LayoutParams) view.getLayoutParams();
489522
layoutParams.topMargin = y;
490523
view.setLayoutParams(layoutParams);
491524
}
@@ -592,7 +625,8 @@ public UDView setWidth(int width) {
592625
public int getWidth() {
593626
View view = getView();
594627
if (view != null && view.getLayoutParams() != null) {
595-
return view.getLayoutParams().width >= 0 ? view.getLayoutParams().width : view.getWidth();
628+
return view.getLayoutParams().width >= 0 ? view.getLayoutParams().width :
629+
view.getWidth();
596630
}
597631
return view != null ? view.getWidth() : 0;
598632
}
@@ -654,7 +688,8 @@ public UDView setHeight(int height) {
654688
public int getHeight() {
655689
View view = getView();
656690
if (view != null && view.getLayoutParams() != null) {
657-
return view.getLayoutParams().height >= 0 ? view.getLayoutParams().height : view.getHeight();
691+
return view.getLayoutParams().height >= 0 ? view.getLayoutParams().height :
692+
view.getHeight();
658693
}
659694
return view != null ? view.getHeight() : 0;
660695
}
@@ -717,7 +752,8 @@ public UDView setBackgroundResource(String picName) {
717752
public UDView align(Integer... rules) {
718753
View view = getView();
719754
if (view != null && view.getLayoutParams() instanceof RelativeLayout.LayoutParams) {
720-
RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
755+
RelativeLayout.LayoutParams layoutParams =
756+
(RelativeLayout.LayoutParams) view.getLayoutParams();
721757
if (rules != null) {
722758
for (int rule : rules) {
723759
layoutParams.addRule(rule);
@@ -992,9 +1028,12 @@ public float getScaleY() {
9921028
public UDView setCallback(LuaValue callbacks) {
9931029
this.mCallback = callbacks;
9941030
if (this.mCallback != null) {
995-
mOnClick = mCallback.isfunction() ? mCallback : LuaUtil.getFunction(mCallback, "onClick", "Click", "OnClick", "click");//TODO OnClick
996-
mOnLongClick = mCallback.istable() ? LuaUtil.getFunction(mCallback, "onLongClick", "LongClick", "OnLongClick", "longClick") : null;//TODO OnLongClick
997-
mOnTouch = mCallback.istable() ? LuaUtil.getFunction(mCallback, "onTouch", "OnTouch") : null;//TODO OnTouch
1031+
mOnClick = mCallback.isfunction() ? mCallback : LuaUtil.getFunction(mCallback,
1032+
"onClick", "Click", "OnClick", "click");//TODO OnClick
1033+
mOnLongClick = mCallback.istable() ? LuaUtil.getFunction(mCallback, "onLongClick",
1034+
"LongClick", "OnLongClick", "longClick") : null;//TODO OnLongClick
1035+
mOnTouch = mCallback.istable() ?
1036+
LuaUtil.getFunction(mCallback, "onTouch", "OnTouch") : null;//TODO OnTouch
9981037

9991038
//setup listener
10001039
setOnClickListener();
@@ -1121,8 +1160,10 @@ public boolean onTouch(View v, MotionEvent event) {
11211160
mOnTouchEventData = new LuaTable();
11221161
}
11231162
if (event != null) {
1124-
mOnTouchEventData.set("action", event.getActionMasked());//0按下,1起来,2移动,3取消,4外部
1125-
mOnTouchEventData.set("pointer", event.getPointerId(event.getActionIndex()));
1163+
mOnTouchEventData.set("action", event.getActionMasked());//0按下,1起来,2
1164+
// 移动,3取消,4外部
1165+
mOnTouchEventData.set("pointer",
1166+
event.getPointerId(event.getActionIndex()));
11261167
mOnTouchEventData.set("x", DimenUtil.pxToDpi(event.getX()));
11271168
mOnTouchEventData.set("y", DimenUtil.pxToDpi(event.getY()));
11281169
mOnTouchEventData.set("gx", DimenUtil.pxToDpi(event.getRawX()));

0 commit comments

Comments
 (0)