Страницы

воскресенье, 6 сентября 2015 г.

Making fast performance complex animations in android

Recently, I've ran into a problem with animating item's height inside a list for some devices with poor performance. And I've done a library for that. It animates RecyclerView or ListView item's height, but isn't heavy-bounded to that containers - see on github. That animation is also known as expand-collapse animation. Here I describe main problems and solutions founded so far, which is used in library. Library is finished and I'll be very glad if you find some issues or propose pull requests.

So, let's start. To be more clear, I'll write some straightforward code which does what I'm telling about:

ValueAnimator animator = ValueAnimator.ofInt(100, 300);
animator.setDuration(1000);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
  @Override
  public void onAnimationUpdate(ValueAnimator animation) {
    listViewItem.getLayoutParams().height = (Integer) animation.getAnimatedValue();
    listViewItem.requestLayout();
  }
});
animator.start();
Many libraries, I so before, use this technique. But that is heavy because of requestLayout() - it causes layout and measure steps repeated again each call. From the other side,

суббота, 2 мая 2015 г.

LibGDX: Kotlin setup

In my previous post I wrote how to configure gradle files to increase build and open IDE speed. Those steps needs to be done if you want to configure kotlin in your libGDX project. Otherwise, you'll get really poor IDE responsiveness and even gradle daemon crashes. Assuming, that you've done all instructions from my previous post, here is the magic steps to use Kotlin. It's easy now:

1. Android Studio (AS) / IDEA -> Settings -> find by "plugin" -> Click "Jetbrains" -> find by "kotlin" -> install kotlin and kotlin for android (optional) plugins and click restart IDE to complete install plugin
2. Open core/src/main directory and create "kotlin" directory there. Recreate directories for your package, like they are in "java" directory. If your app's package is com.mycompany.mygame, then create directory com, open it, create mycompany and so on.
3. Return to IDE. You may try tools -> Kotlin -> Configure kotlin in project... or add bold lines to your core/build.gradle:

Speed up libgdx gradle build in Intellij IDEA

This article describes how to exclude running unnessary tools when building for concrete platform. Here I will make an example for desktop and Android platform, but builds for other platforms can be optimized that way too. The main idea is to move all gradle staff, related to project to it's gradle's build file. So, the way it's designed. Nothing new. While this post may be outdated, see complete and update example project on github . I'm using Android Studio, but IDEA may be used too. And yes, only gradle is here and no Eclipse. I'm a professional programmer and I believe, that Android Studio is far way better than Eclipse if it is set up well.

So, here are the steps to make IDE build fast.

Will Kotlin be the future for libGdx to target Web platform?

Currently, libgdx uses GWT plugin to target web platform. And GWT doesn't support even Java 1.6! See official docs. And it allways needs source files! (see GWT/html section in libgdx docs) It's not allways affordable.

What about Kotlin? It's robust, brand new language which is fully compatible with JVM, starting from Java 1.6+!

Let's see what's about integration in modern IDE's. Kotlin plugin for Android Studio / IDEA successfully compiles both .kt and .java files to .class! (see here and here for android)

And what about starting to code best libGDX projects in Kotlin and deploy them to web now? Now we have libgdx backends only for GWT...

What we may try now?

1. Kotlin can be converted to javascript thanks to JetBrains. Here is an example of web project, where javascript is generated from kotlin code. So, we may do that generation for now (hoping things become better in the future) and add generated javascript to GWT's web project to use with libgdx gwt backends as usual. In theory, it could work.

2. Or we may try investigating about current possibilities of Kotlin in conversion to javascript, running HTML5. Get gwt backend sources as an example and write our own backend for Kotlin's javascript and contribute to libGDX?

What will you say? Interesting, isn't it? I'll be glad to see your thoughts! Post comments, please