use of com.airbnb.lottie.OnCompositionLoadedListener in project lottie-android by airbnb.
the class AnimationFragment method loadUrl.
private void loadUrl(String url) {
Request request;
try {
request = new Request.Builder().url(url).build();
} catch (IllegalArgumentException e) {
onLoadError();
return;
}
if (client == null) {
client = new OkHttpClient();
}
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
onLoadError();
}
@Override
public void onResponse(Call call, Response response) throws IOException {
if (!response.isSuccessful()) {
onLoadError();
}
try {
JSONObject json = new JSONObject(response.body().string());
LottieComposition.Factory.fromJson(getResources(), json, new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
setComposition(composition, "Network Animation");
}
});
} catch (JSONException e) {
onLoadError();
}
}
});
}
use of com.airbnb.lottie.OnCompositionLoadedListener in project fluttie by simolus3.
the class FluttiePlugin method loadComposition.
private void loadComposition(final int requestId, String sourceType, String source) throws JSONException {
final JSONObject object = new JSONObject();
object.put("request_id", requestId);
object.put("event_type", "load_composition");
OnCompositionLoadedListener listener = new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(@Nullable LottieComposition composition) {
try {
if (composition == null) {
Log.w("FluttiePlugin", "Could not load composition");
object.put("success", false);
writeToSink(object);
return;
}
if (!composition.getWarnings().isEmpty()) {
Log.w("FluttiePlugin", "You tried to load a composition that has some warnings, it might not be displayed correctly");
for (String warning : composition.getWarnings()) {
Log.w("FluttiePlugin", warning);
}
}
loadedCompositions.append(requestId, composition);
object.put("success", true);
} catch (JSONException e) {
Log.w("FluttiePlugin", "Could not add JSON value to event stream");
}
writeToSink(object);
}
};
switch(sourceType) {
case "inline":
LottieComposition.Factory.fromJsonString(source, listener);
break;
default:
object.put("success", false);
writeToSink(object);
}
}
use of com.airbnb.lottie.OnCompositionLoadedListener in project lottie-android by airbnb.
the class AnimationFragment method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode != Activity.RESULT_OK) {
return;
}
switch(requestCode) {
case RC_ASSET:
final String assetName = data.getStringExtra(EXTRA_ANIMATION_NAME);
animationView.setImageAssetsFolder(assetFolders.get(assetName));
LottieComposition.Factory.fromAssetFileName(getContext(), assetName, new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
setComposition(composition, assetName);
}
});
break;
case RC_FILE:
onFileLoaded(data.getData());
break;
case RC_URL:
break;
}
}
use of com.airbnb.lottie.OnCompositionLoadedListener in project lottie-android by airbnb.
the class AnimationFragment method onFileLoaded.
private void onFileLoaded(final Uri uri) {
InputStream fis;
try {
switch(uri.getScheme()) {
case "file":
fis = new FileInputStream(uri.getPath());
break;
case "content":
fis = getContext().getContentResolver().openInputStream(uri);
break;
default:
onLoadError();
return;
}
} catch (FileNotFoundException e) {
onLoadError();
return;
}
LottieComposition.Factory.fromInputStream(getContext(), fis, new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
setComposition(composition, uri.getPath());
}
});
}
use of com.airbnb.lottie.OnCompositionLoadedListener in project lottie-android by airbnb.
the class LottieFontViewGroup method init.
private void init() {
setFocusableInTouchMode(true);
LottieComposition.Factory.fromAssetFileName(getContext(), "Mobilo/BlinkingCursor.json", new OnCompositionLoadedListener() {
@Override
public void onCompositionLoaded(LottieComposition composition) {
cursorView = new LottieAnimationView(getContext());
cursorView.setLayoutParams(new LottieFontViewGroup.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
cursorView.setComposition(composition);
cursorView.loop(true);
cursorView.playAnimation();
addView(cursorView);
}
});
}
Aggregations