Anko – Pleasant Android development in Kotlin
github.com
github.com
It was my understanding the XML was compiled into a binary format for faster parsing on device, am I wrong on that?
EDIT: http://en.wikipedia.org/wiki/Android_application_package "resources.arsc: a file containing precompiled resources, such as binary XML for example." Ah yes, I think it does.
> Most of all, it allows no code reuse.
If we are talking code reuse in terms of having one common bit of layout that is used across several different layouts, actually you can: http://developer.android.com/training/improving-layouts/reus...
Also, the Android view system as it stands is incredible flexible.
You can provide different layouts and style rules for different screensizes and device configs - an kinda equivalent to the webs responsive design using CSS media queries.
Also, every view component is just a Java class. As well as allowing you to create your own class from scratch that you can just use as part of a view, you can also extend an existing view class and just change one bit of it's behaviour.
I don't especially mean to have a go at Anko - sorry. It's just that I think the Android views are actually pretty good, and certainly when I'm working on Android apps this isn't one of the major problems I have!
yes, SO answer: http://stackoverflow.com/a/6646113
That's correct, but it still requires the additional overhead of parsing the compiled resources and using reflection to instantiate Views. Anko instantiates Views directly.
Interesting point - the resource table still has references to the XML files for configuration-resolving purposes, but they are only strings. E.g. getString(R.layout.main) will actually work and return "res/layout/main.xml" or "res/layout-land/main.xml" depending on the device configuration (and assuming one has the layout-land version). Vice-versa, if you have a string resource with the value "res/layout/main.xml" and say, name foo, then calling setContentView(R.string.foo) actually works.
https://github.com/zserge/anvil
http://zserge.com/blog/anvil-2.html
Kotlin is supported as well (http://zserge.com/blog/anvil-kotlin.html)
I plan to keep v<Class> anyway because it works nice with custom views when there is no generated syntax sugar.
Also, if you're open to Xamarin, there's a great library there called MvvmCross that gives you in-AXML databinding and a general feel similar to Angular.
Unfortunately neither of the data binding libraries for Android worked for me, because they are either too hard to extend or too big/complex.
RoboBinding's idea is nice, but to me it's too implicit. It's really hard to tell what's happening behind the scenes.
As for the Xaramin - I would like to try it, but I run linux on my development machine, and it didn't start with Wine.
I think yelp is written as that. And to add insult when they moved to the material hype the home button on top left became yet another back button... they did add shortcuts on the left now. But it's all breaking stuff and adding bandaids on top of bandaids
Activities are indeed the piece of the framework I would be most eager to see removed/revamped. I have seen many devs (even supposedly experienced ones) use/encourage to use patterns that lead to leaking the Activity context (like retaining everything, especially the UI). There will always be people writing awful code, but Activities may too hard to grok for many devs (and that's not their only issue by far).
There is brilliant article from Squareup about that - https://corner.squareup.com/2014/10/advocating-against-andro...
In Anvil I try to follow Square's approach, e.g. keep components as viewgroups and use a custom backstack to manage them as needed (e.g. back/home navigation, multi-pane layouts etc). Then you get just one activity per application and it's a big relief.
I'm not sold on using it as a layout DSL, it's just not as easy to format as XML, and I don't think it looks syntactically that much better. However, I am sold on using anko as replacement for setters and getters (ie. `setText("test")` is just `.text = "test"`). Additionally, it's incredibly easy to add more extensions for other view types, like `RecyclerView` and custom layouts.
- XMLs are not type safe, I can type any tag name in there, and I can set almost any value to my attributes - AAPT won't even notice (yes, Android Studio is much smarter these days, it may give a warning, but it won't be a compiler warning, so it won't be in your automated build logs. You will also miss it when using other text editor or IDE). I can put a view inside another view (not a viewgroup) - and it will pass as well. Since we waste CPU time on XMLs preprocessing - it would be nice if they also warned us about our errors at this stage, not crashes in runtime.
- The file hierarchy is terrible. All XMLs must be in the same folder, no nested folders. Having a large project makes you have dozens of XMLs on the same layer of hierarchy. Since we have OS with directories - it would be nice to use that feature like we use it for java packages.
- There are some styles, but they are too limited comparing to, say, CSS. If one ever tried LESS or SASS - he will love the mixing, variables, calculated expressions etc. It's fast to write, it's easy to read, it's reusable. You don't have to jump around multiple closely related files to tie it all together in your head. You have them in one place. Since XMLs are processed - it would be nice if I could write something like "android:background=darken(@color/mycolor, 30%)"
- There is some responsiveness, but it's too limited. If you have 3 nested views, and the topmost has margin in landscape and no margin in portrait - you have to have two (almost identical) files. Or three, if you want to use merge/include. In fact now they are all in different folders, despite they are very closely related!
- There is no way to merge with unique ids (child layout will have the duplicated ids when included twice).
- There is no mixins or macros. If I have layout with textview+button pairs - I will end up copying those two tags everywhere. If I have macros - I would write it once, and then would only type `<TextViewWithButton text="foo" buttonText="bar">` - that is supposed to be expaded into <TextView .../><Button ..../> with some texview and button attributes substituded to the given actual values.
- There is no data binding.
It's a dilemma, as Java+XML is very verbose. still, with the amount of work Android Studio does, I'm not sure its a big problem for most of us Android Developers.
I think the kind of developer who dislikes the current Android dev alternatives enough to avoid it as much as possible is more likely to be the target audience for most of these alternative tools than you are.
The Rust developers have done a fabulous job of posting here and answering questions in detail, and I hope the Kotlin guys at JetBrains will eventually start doing the same thing.
First of all, it is a platform name (Android) and a language name (Kotlin), joined together and abbreviated. The word "anko" is short and there's no other library with the same name (at least, I didn't heard of one).
Also, it was created to make Android development sweeter with some synthetic sugar^Wanko.
Finally, I just love daifuku.
Alright. I guess it makes sense here.