Skip to content

Commit

Permalink
Android: Update to 2.6.0, addEventListener (#40)
Browse files Browse the repository at this point in the history
* lottie 2.5.5, addEventListener, removed callback, passing frame in update event, clang

* autoplay complete, update example

* move to 2.5.7

* lottie 2.6.0-rc3, added auto/start property

* Readme
  • Loading branch information
m1ga authored Aug 25, 2018
1 parent 85132a4 commit 9158445
Show file tree
Hide file tree
Showing 10 changed files with 411 additions and 273 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

![gif](animation.gif)

Appcelerator Titanium Android module for [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) libray and for [Airbnb Lottie](https://github.com/airbnb/lottie-android).
Appcelerator Titanium Android module for [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) libray and for [Airbnb Lottie](https://github.com/airbnb/lottie-android).

## Requirements
- Titanium Mobile SDK 6.0.0 or later
- Titanium Mobile SDK 7.0.0 or later

## Library versions:
The Titanium modules use external libraries
Expand All @@ -14,7 +14,7 @@ The Titanium modules use external libraries
|---|---|---|---|
| [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) | Android | 1.0.0 | 2017/02/11 |
| [Facebooks Keyframes](https://github.com/facebookincubator/Keyframes) | iOS | 1.0.0 | 2017/02/11 |
| [Airbnb Lottie](https://github.com/airbnb/lottie-android) | Android | 2.3.1 | 2017/12/09 |
| [Airbnb Lottie](https://github.com/airbnb/lottie-android) | Android | 2.6.0-rc3 | 2018/08/14 |
| [Airbnb Lottie](https://github.com/airbnb/lottie-ios) | iOS | 2.5.0 | 2018/02/11 |


Expand Down
26 changes: 26 additions & 0 deletions android/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
Language: Java
AccessModifierOffset: -4
AllowShortBlocksOnASingleLine: false
AllowShortFunctionsOnASingleLine: None
AllowShortIfStatementsOnASingleLine: false
AllowShortLoopsOnASingleLine: false
# class, constructor, method should be next line
BreakBeforeBraces: Linux
# Keep '=' at end of line when wrapping, but move things like '&&', '||' to beginning of newline
BreakBeforeBinaryOperators: NonAssignment
# FIXME: break for brace after synchronized block, anonymous class declarations
BreakAfterJavaFieldAnnotations: true
ColumnLimit: 120
IndentCaseLabels: true
IndentWidth: 4
MaxEmptyLinesToKeep: 1
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpacesInParentheses: false
TabWidth: 4
UseTab: ForContinuationAndIndentation
SpaceAfterCStyleCast: true
# Spaces inside {} for array literals, i.e. "new Object[] { args }"
Cpp11BracedListStyle: false
ReflowComments: false
Binary file removed android/lib/lottie-2.5.0.aar
Binary file not shown.
Binary file added android/lib/lottie-2.6.0-rc3.aar
Binary file not shown.
2 changes: 1 addition & 1 deletion android/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# this is your module manifest and used by Titanium
# during compilation, packaging, distribution, etc.
#
version: 2.0.1
version: 2.1.0
apiversion: 4
architectures: arm64-v8a armeabi-v7a x86
description: ti.animation
Expand Down
139 changes: 73 additions & 66 deletions android/src/ti/animation/KeyframeViewProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@
import android.widget.ImageView;
import android.graphics.drawable.Drawable;


@Kroll.proxy(creatableInModule=TiAnimationModule.class)
@Kroll.proxy(creatableInModule = TiAnimationModule.class)
public class KeyframeViewProxy extends TiViewProxy
{
// Standard Debugging variables
Expand All @@ -49,31 +48,30 @@ public class KeyframeViewProxy extends TiViewProxy

private class Keyframes extends TiUIView
{
public Keyframes(TiViewProxy proxy) {
public Keyframes(TiViewProxy proxy)
{
super(proxy);



String packageName = proxy.getActivity().getPackageName();
Resources resources = proxy.getActivity().getResources();
View videoWrapper;
int resId_videoHolder = -1;
int resId_video = -1;

resId_videoHolder = resources.getIdentifier("layout", "layout", packageName);
resId_video = resources.getIdentifier("ImageView", "id", packageName);
LayoutInflater inflater = LayoutInflater.from(getActivity());
videoWrapper = inflater.inflate(resId_videoHolder, null);
if (resId_video != 0){
imageView = (ImageView)videoWrapper.findViewById(resId_video);
Resources resources = proxy.getActivity().getResources();
View videoWrapper;
int resId_videoHolder = -1;
int resId_video = -1;

resId_videoHolder = resources.getIdentifier("layout", "layout", packageName);
resId_video = resources.getIdentifier("ImageView", "id", packageName);

LayoutInflater inflater = LayoutInflater.from(getActivity());
videoWrapper = inflater.inflate(resId_videoHolder, null);
if (resId_video != 0) {
imageView = (ImageView) videoWrapper.findViewById(resId_video);
imageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
imageView.setImageDrawable(kfDrawable);
imageView.setImageAlpha(0);
setNativeView(videoWrapper);
} else {
Log.e(LCAT, "Layout not found");
}

setNativeView(videoWrapper);
} else {
Log.e(LCAT, "Layout not found");
}
}

@Override
Expand All @@ -84,64 +82,74 @@ public void processProperties(KrollDict d)
}

@Kroll.method
public void initialize() {
}
public void initialize()
{
}

@Kroll.method
public void stop() {
kfDrawable.stopAnimation();
}
public void stop()
{
kfDrawable.stopAnimation();
}

@Kroll.method
public void start() {
if (!isLoop){
@Kroll.method
public void start()
{
if (!isLoop) {
kfDrawable.playOnce();
} else {
kfDrawable.startAnimation();
kfDrawable.startAnimation();
}
}
}

@Kroll.method
public void pause() {
public void pause()
{
kfDrawable.pauseAnimation();
}
}

@Kroll.method
public void resume() {
public void resume()
{
kfDrawable.resumeAnimation();
}
}

@Kroll.method
public void seekToProgress(float pos) {
public void seekToProgress(float pos)
{
kfDrawable.seekToProgress(pos);
}
}

@Kroll.method
public void setProgress(float pos) {
public void setProgress(float pos)
{
kfDrawable.seekToProgress(pos);
}
}

@Kroll.method
public int getFrameCount() {
public int getFrameCount()
{
return kfImage.getFrameCount();
}
}

@Kroll.method
public int getFrameRate() {
public int getFrameRate()
{
return kfImage.getFrameRate();
}
}

@Kroll.method
public void addViewToLayer() {
public void addViewToLayer()
{
// TODO empty for now
}
}

@Kroll.method
public boolean isPlaying() {
// TODO
public boolean isPlaying()
{
// TODO
return false;
}
}

// Constructor
public KeyframeViewProxy()
Expand All @@ -158,13 +166,13 @@ public TiUIView createView(Activity activity)
view.getLayoutParams().autoFillsWidth = true;
return view;
}

private String getPathToApplicationAsset(String assetName)
{
// The url for an application asset can be created by resolving the specified
// path with the proxy context. This locates a resource relative to the
// path with the proxy context. This locates a resource relative to the
// application resources folder

String result = resolveUrl(null, assetName);
return result;
}
Expand All @@ -184,21 +192,20 @@ public void handleCreationDict(KrollDict options)
if (options.containsKey("file")) {
try {
String url = getPathToApplicationAsset(options.getString("file"));
TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false);
TiBaseFile file = TiFileFactory.createTitaniumFile(new String[] { url }, false);
stream = file.getInputStream();
kfImage = KFImageDeserializer.deserialize(stream);
kfDrawable = new KeyframesDrawableBuilder().withImage(kfImage).build();
if (isAutoStart){
if (isLoop){
if (isAutoStart) {
if (isLoop) {
kfDrawable.startAnimation();
} else {
kfDrawable.playOnce();
}
}
} catch (IOException e){
} catch (IOException e) {
Log.i(LCAT, "error " + e);
}
}

}
}
Loading

0 comments on commit 9158445

Please sign in to comment.