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
910package 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