From 8100a445830d03c5405eef0d79a18c8514d4daac Mon Sep 17 00:00:00 2001 From: Michael Date: Mon, 24 Jul 2017 20:14:19 +0200 Subject: [PATCH] fixed string check --- .../android/res/layout/layout_lottie.xml | 1 + android/src/ti/animation/LottieViewProxy.java | 52 +++++++++---- example/scaleTest.js | 75 +++++++++++++++++++ 3 files changed, 114 insertions(+), 14 deletions(-) create mode 100644 example/scaleTest.js diff --git a/android/platform/android/res/layout/layout_lottie.xml b/android/platform/android/res/layout/layout_lottie.xml index 0725ddc..9da02b3 100644 --- a/android/platform/android/res/layout/layout_lottie.xml +++ b/android/platform/android/res/layout/layout_lottie.xml @@ -5,5 +5,6 @@ android:scaleType="centerInside" android:layout_width="match_parent" android:layout_height="match_parent" + android:adjustViewBounds="true" /> diff --git a/android/src/ti/animation/LottieViewProxy.java b/android/src/ti/animation/LottieViewProxy.java index fe6b71f..d774f1c 100644 --- a/android/src/ti/animation/LottieViewProxy.java +++ b/android/src/ti/animation/LottieViewProxy.java @@ -66,6 +66,8 @@ public class LottieViewProxy extends TiViewProxy private int width = 0; private int height = 0; private boolean useSoftwareRendering = false; + private boolean mergePath = false; + private ScaleType viewScaleMode = ScaleType.CENTER_INSIDE; protected static final int MSG_STARTANIMATION = KrollProxy.MSG_LAST_ID + 101; @@ -119,8 +121,7 @@ private void animationEvent(float percentage, int status){ } } - private class LottieView extends TiUIView - { + private class LottieView extends TiUIView { public LottieView(TiViewProxy proxy) { super(proxy); @@ -143,6 +144,7 @@ public LottieView(TiViewProxy proxy) { appContext = TiApplication.getInstance(); isReady = true; + lottieView.setScaleType(viewScaleMode); lottieView.addAnimatorUpdateListener(new AnimatorUpdateListener()); lottieView.addAnimatorListener(new AnimatorListener()); if (useSoftwareRendering){ @@ -150,7 +152,7 @@ public LottieView(TiViewProxy proxy) { } else { lottieView.setLayerType(View.LAYER_TYPE_HARDWARE, null); } - + lottieView.enableMergePathsForKitKatAndAbove(mergePath); if (loadFile != ""){ setFile(loadFile); @@ -158,9 +160,23 @@ public LottieView(TiViewProxy proxy) { } @Override - public void processProperties(KrollDict d) - { + public void processProperties(KrollDict d) { super.processProperties(d); + if (d.containsKey("scaleMode")) { + String scaleMode = d.getString("scaleMode"); + if (scaleMode.equals("center")) { + viewScaleMode = ScaleType.CENTER; + } else if (scaleMode.equals("centerCrop")) { + viewScaleMode = ScaleType.CENTER_CROP; + } else if (scaleMode.equals("centerInside")) { + viewScaleMode = ScaleType.CENTER_INSIDE; + } else { + viewScaleMode = ScaleType.CENTER_INSIDE; + } + if (isReady){ + lottieView.setScaleType(viewScaleMode); + } + } } } @@ -215,6 +231,12 @@ public void handleCreationDict(KrollDict options) if (options.containsKey("update")) { callbackUpdate =(KrollFunction) options.get("update"); } + if (options.containsKey("mergePath")) { + mergePath = options.getBoolean("mergePath"); + if (isReady){ + lottieView.enableMergePathsForKitKatAndAbove(mergePath); + } + } if (options.containsKey("disableHardwareAcceleration")){ if (options.getBoolean("disableHardwareAcceleration")){ if (isReady){ @@ -226,16 +248,18 @@ public void handleCreationDict(KrollDict options) } if (options.containsKey("scaleMode")) { String scaleMode = options.getString("scaleMode"); - if (scaleMode == "center") { - lottieView.setScaleType(ScaleType.CENTER); - } else if (scaleMode == "centerCrop") { - lottieView.setScaleType(ScaleType.CENTER_CROP); - } else if (scaleMode == "centerInside") { - lottieView.setScaleType(ScaleType.CENTER_INSIDE); - } else if (scaleMode == "fitXY") { - lottieView.setScaleType(ScaleType.FIT_XY); + if (scaleMode.equals("center")) { + viewScaleMode = ScaleType.CENTER; + } else if (scaleMode.equals("centerCrop")) { + viewScaleMode = ScaleType.CENTER_CROP; + } else if (scaleMode.equals("centerInside")) { + viewScaleMode = ScaleType.CENTER_INSIDE; + } else { + viewScaleMode = ScaleType.CENTER_INSIDE; + } + if (isReady){ + lottieView.setScaleType(viewScaleMode); } - } } diff --git a/example/scaleTest.js b/example/scaleTest.js new file mode 100644 index 0000000..7ce3f0c --- /dev/null +++ b/example/scaleTest.js @@ -0,0 +1,75 @@ +var TiAnimation = require('ti.animation'); +var isAndroid = (Ti.Platform.osname == 'android'); + +var win = Ti.UI.createWindow({ + backgroundColor: '#fff', + title: '', + fullscreen: true +}); + +var scroller = Ti.UI.createScrollView({ + width: Ti.UI.FILL, + height: Ti.UI.FILL, + layout: "vertical" +}) + +var ani1 = TiAnimation.createLottieView({ + file: 'sample_lottie.json', + top: 5, + loop: true, + width: 200, + height: 200, + borderWidth: 1, + borderColor: "#000", + autoStart: true +}); +var ani2 = TiAnimation.createLottieView({ + file: 'sample_lottie.json', + top: 5, + loop: true, + width: 20, + height: 20, + borderWidth: 1, + borderColor: "#000", + autoStart: true +}); +var ani3 = TiAnimation.createLottieView({ + file: 'sample_lottie.json', + top: 5, + loop: true, + width: 200, + height: 20, + borderWidth: 1, + borderColor: "#000", + autoStart: true +}); +var ani4 = TiAnimation.createLottieView({ + file: 'sample_lottie.json', + top: 5, + loop: true, + width: 320, + height: 50, + borderWidth: 1, + borderColor: "#000", + autoStart: true, + scaleMode: "centerCrop" +}); +var ani5 = TiAnimation.createLottieView({ + file: 'sample_lottie.json', + top: 5, + loop: true, + width: 320, + height: 50, + borderWidth: 1, + borderColor: "#000", + autoStart: true +}); + +scroller.add(ani1); +scroller.add(ani2); +scroller.add(ani3); +scroller.add(ani4); +scroller.add(ani5); +win.add(scroller); + +win.open();