Categoryandroid

copy assets script for multiple resolutions for android

Assuming you want to build multiple apks for multiple resolutions on android or just have faster apk upload time to your android device during development.

Considering you want to copy from /myapp/resources/ to /myapp/android/assets/ for several resolutions and you want only to click once for each resolution build.
To accomplish this i recommend using rsycn/ and cygwin.

You might have these script files in:

/myapp/scripts/320x_CopyAssets.bat
/myapp/scripts/480x_CopyAssets.bat
/myapp/scripts/540x_CopyAssets.bat
/myapp/scripts/600x_CopyAssets.bat
/myapp/scripts/720x_CopyAssets.bat
/myapp/scripts/768x_CopyAssets.bat
/myapp/scripts/800x_CopyAssets.bat
/myapp/scripts/1080x_CopyAssets.bat
/myapp/scripts/copy_assets.sh
/myapp/IgnoreCopyAssets/IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/320x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/480x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/540x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/600x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/720x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/768x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/800x_IgnoreCopyAssets.txt
/myapp/IgnoreCopyAssets/1080x_IgnoreCopyAssets.txt

Where you merely send the desired resolution at to the actually copy_assets shell script. (e.g the 768x_CopyAssets.bat)

The copy_assets.sh would look like:

And in case you want to ignore files or dirs you can use IgnoreCopyAssets.txt

Or the other resolutions (e.g the 768x_IgnoreCopyAssets.txt) Note: you can use # to comment files or directories out. ;)

Conclusion

Easy to use scripts to copy assets and remove all unwanted ones from your assets folder plus the posibility to ignore files and dirs on demand. Enjoy :)

c++ arc4random on android, windows and linux

Turns out native android development doesn’t supply you with a real ar4random method. However adapting the OpenBSD’s arc4random.c does the trick. And even works on windows without using CryptoAPI (thanks to Chris K. Jester-Young for these suggestions). Additionally with boost *ducks* it should be more or less multithreadsafe.

Mixed (red dots are generated by arc4; Math.Random() Arc4random)

And here are the convinience methods for it:

So you can use it like:

Enjoy. (:

See also

How to get the MAC address on Android

(A test project can be found on github)

Since you can easily get confused with the many permissions provided by google, let me show you two ways to get the mac address on android. The first approach would be to use the WifiManager.getMacAdress().

However there are Disadvantages:

  • Device should have Wi-Fi (where not all devices have Wi-Fi)
  • If Wi-Fi present in device should be turned on otherwise does not report the MAC address
  • And the suspicious permission ACCESS_WIFI_STATE

Another approach is the use the NetworkInterface.getHardwareAddress()

Disadvantage: uses permissions too, although they are required for your app to access the internet anyway and more likely commonly known to the end-user.

Conclusion:

Carring about permissions can be a pain in the butt there are even other ways if you just want identifying app installations, too.

Android libgdx ShaderAssetLoader & StillModelLoader

I totally love how libgdx brings a lot of interfaces for your application to connect to the graphics library. For instance the asset manager is really thought through well in particular. It has some really useful methods like Assets.manager.getProgress(). Especially since you can easily write your own asset loader and be able to utilize the loading progress in your app.

1) Simply add your loader to the asset manager at some point.

2) load your assets at required places, e.g. loading screen
(Note: SHADER_PHONG = “data/Graphics/Shader/Phong”; and MODEL_TEAPOT = “data/Graphics/Shader/teapot.obj”)

3) get your shader or model wherever you need them

4) free the resource by unloading when you’re done with them (e.g. disposing your app; changing screens)

That’s the shader asset loader for loading custom shaders in libgdx. (Note: adapt your extensions)

And here is the StillModel loader for loading 3D meshes:

Conclusion: assets are handled well in libgdx :D

My bumpy Samsung Galaxy S2 android upgrade to Lungo (CyanogenMod) for developping purposes

Ok here I was, totally innocent thinking about upgrading my Samsung Galaxy S2. I did that before some time ago and had no problems whatsoever. However when trying to install  Codename Lungo Mod (CyanogenMod) as described in things-to-do-before-and-after-installing-a-rom-troubleshooter some  problems occured.

lungo

Things to do when installing a new rom:

  1. “wipe data/factory reset”
  2. “wipe cache partition”
  3. Go to advanced and “wipe dalvik cache” and “wipe battery stats”
  4. Go to mounts and storage and ”format system”
  5. The go to “install zip from sdcard> choose zip from sdcard” and select the ROM file you want to install.
  6. In case, the developer has recommended to install GApps too, you should install it just after flashing the ROM (use Step 5).
  7. When it is installed, reboot the device

After wipping everything and trying to “install zip from sdcard> choose zip from sdcard” some weird “Status 7” assertion errors appeared. Which basically denied the installation because clockworkmod thought the rom was not compatable with my device which was caused by my rather super outdated clockworkmod . Upgrading clockworkmod  didn’t work for some weird reason. Please let me know why it didn’t ate the update.zip if you happend to know.

Anyways, so I had to delete the  assertions in the rom zip file as described in how-to-fix-android-custom-rom-status-7-installation-abort-assert-failed-error-in-recovery-easily. Well changing the updater-script was no big deal. However how to get the zip on the device which has no rom installed anymore? I could have rolled back the backup, copied the rom.zip on the device, wiped and attempt another install or push the rom via adb onto the device.

android

But that approach probably took just as long in the end. At first my laptop didn’t find the android device anymore although I’m developing on it on a daily basis so the USB driver were installed. After some research I’ve found a website describing that very problem how-to-solve-adb-device-not-found-error.  Which basically let me install PdaNet. My Samsung mobile phone could be found via “adb devices” after I went into clockworkmod start screen, then plugged in the USB cable and then went into the mounting screen. The article stated to use adbfastboot but I have android platform tools installed and just used the officially shipped by google adb tool. Now I could simply “adb push rom.zip /sdcard/rom.zip” and “install zip from sdcard> choose zip from sdcard” , select the lungo and install the rom.

To my surprise the “Enable USB Debugging” menu item was missing which had to be enabled by tapping 7 times on the about information for some weird reason. Is Google hidding stuff like Mac now? Also to note that if you want to get your device “online” when developing look into how-to-fix-adb-device-is-listed-as-offline-on-android-4-2-2.

 

TL;DR: upgrading to a new rom can be quiet more troublesome than advertised. ^^’

 

Bonus: on this tiny journey I stumbled on a collection of android rom installation errors and also collection of useful Tools, Drivers, utilities, downloaders and various fixes for Androids and PC.  .

 

Android: Saving Screenshots in OpenGLES

1) Get your helper methods:

2) get a queue ready

3) add new filepath the the queue via e.g. events:

4) IMPORTANT! save the screen at the end of the opengl render process. (Note: If try to capture somewhere in the middle you might end up with a black screen or any other funny effects.)

DroidCon Wednesday 10-04-2013 at Kosmos Berlin

11:15 Dos and Dont’s of Android UI by Juhari Lebtimäki (SnappT)

He talked about a lot of generic and common sense design guidelines. Which you probably know all along by books like “Don’t make me think” by Steve Krug just applied to on android. He gave a couple of recommended principles like

  • designing for mdpi resolutions (1dp = 1px = mdpi) and scale from there (android dimensions)
  • use conventional icons when appropriate
  • use 9-patch
  • action bar on top and not on bottom
  • naturally swipe between slides (instead of teleporting by tabs)
  • errors on top like google play app (leats surprising)
  • be careful with tutorials, instructions are bad, try to be self-explanatory
  • popups are bad, because it interrupts use flow for no real reason and
  • use notifications instead, android did a good job at that
  • first time start like evernote for complicated usages
  • be conistent with the navigation as much as possible
  • let the user use the app without login for the first start even with restricted functionionality, avoid invoking the user to feel like doing a blind bargain
  • don’t hide the status bar, your app is not the reason the user has his phone!
  • customization is not an alternative to design
  • user tests for obvious reasons.

Well nothing really new but it was a well hold presentation nonetheless.

11:40 ProGuard, Optimizer and Obfuscator in the Android SDK by Eric Lafortune (Saikoa)

He basically gave an overview about what proguard does. That it is shrink, optimizes and obfuscates the final release versions of your android apk. Turns out it is a rather powerful tool. I’m using it for protecting code and removing logging so far. There is also a commercial version called dexguard.

12:20 Tracking User Behaviour Creatively by Kiana Tennyson (Manheim)

Google Analytics how-to tutorial kind of talk. Let’s hope people with bad intentions don’t abuse it.

12:20 Build your own app analytics tools by Matthais Huber and Monica Tudora (1&1 Internet)

Monica showed some simple code examples how to track user input and publishing it to private servers in order to improve the app with ACRA and heatmaps. Probably bigget advantage of that approach is that you don’t need to publish anylitic statistics on public and / or 3rd person services. Also she made me aware of how easy it is to create own analytic tools. It can be simple and still can be useful.

13:00 LUNCH

14:00 Firefox OS by Andreas Gal (Modzilla)

It’s quiet interesting concept of having an entire OS being programmable by html, js and css. Sadly very presented too quiet.

14:45 Re-Engineering the Facebook SDK by Connor Treacy (Facebook)

Connor Treacy presented the latest Facebook SDK 3 changes compared to 2. The sdk is easier to use now, and probably easier as well.

15:25 Real Time High Performance Multimedia Systems on Android by Prashant Dixit (Ittiam Systems)

slides will follow…

16:35 Biitstrap Continues Testing for Android in 5 Minutes by Andreas Lüdeke (TestObject)

http://www.cloudbees.com/#slide-2 and http://testobject.com/ in toolchain

DroidCon Tuesday 9-04-2013 at Kosmos Berlin

11:15 Efficient Android Threading by Anders Göransson (Jayway)

Anders gave a nice overview with code examples about multiple ways to do threading on android. Especially the use cases were distinguished rather well.

11:55 Incorporating touch feedback in your apps by Peter van der Linden (Immerson)

Very good and entertaining talk about the haptic feedback sdk. (demo app in android market) I’m definitely going to test in the near future. Because it looks easy to use but still powerful to give vibration feedback with your android device. And a tweet about it got me a stylish android hat :D

12:35 Libgdx game development framework by Alexander Fröhlich and Thomas Madsen (Andlabs)

Well it was kinda like the same talk as yesterday. You had the feeling they only used it for like one day and not went any further. Maybe it’s the restricted time limit of half an hour for the talk. At any rate. I didn’t learn anything new that I couldn’t have learned within a few tutorials myself. Except maybe the recommendation about tile map editors – like tile map editor – and the Physics Body Editor, especially the last one looked really promising for future boxed2d projects. At least the presentation has been done with prezi so the slide transitions weren’t boring. xD

13:15 LUNCH ^_^ <3

14:15 Designing Accessible Android Applications by Sonia Sharman (Google)

Sonia basically advertised to use android build-in functionality like AccessabilityEvents and AccessabilityServices in order to support the use for sight or else handicapped people. It reminded of accessibility guide lines for websites. For instance, minimize chatter, provide feedback, label UI elements / tagging and grouping view elements properly in order to help text to speech programs to be actually useful. I think it’s very important but I can also imagine to most of the developer it will be last on their checklist since their android apps are not needed to be tagged like websites do for SEO reasons. She also mentioned talkback and tripple-tap-zoom. Further informations can be found in the official android documentation.

Also quiet interesting is the Google I/O 2012 talk about it:

15:00 Improving Android Experience by Pavel Lahoda (Actiwerks)

Pavel talked about how to improve the UI. He suggested that android developer can learn from web developers in order to support multiple screen resolutions and layouts for instance using responsive design. Some mentioned solutions were standout – floating windows, fly-out menu, actionbarsherlock. He also pointed out that the native android sdk doesn’t provide enough functionality for that purpose. Not for all devices and all screen resolutions anyway.

15:40 Location and vision based AR by Simon Heinen and Mostafa Akbari (Bitstarts)

Well regrettably this was merely an advertising show off bitstars AR SDK.  They basically use a JMonkey Engine to render, GPS (>10-30 meter precision), WIFI, Step detection (> 5 meter precision) and SLAM (>1 centimeter precision) for getting precise locations. At any rate augmented reality is cool especially without markers and I’m looking forward for awesome applications in the future.

16:50 Unifying Callbacks in Android by Matt Brenner (UnME2)

Matt introduced his cooked up EventConsumer Pattern. Which seems to be a way to minimize the boilerplate for events. Although based on the reaction by the audience it didn’t quiet convince everyone. I think it’s a good idea to minimize doubled code though.

17:30 Understanding the GPU to write better code by Guillem Vinals Gangolells (Imagination Technologies)

The last talk today was quiet interesting. Rather low level but a lot of generalised recommendation. Mostly Guillem talked the graphic pipeline for OpenGL on android. I’m going to put his presentation online as soon as they publish it.

Conclusion

Today were far better and mostly way more organised talks. I learned quiet a few new things for which I’m grateful. For instance the haptic sdk, the physics body editor, standalone, fly-out actionbarsherlock are worth looking into. I would have wished for deeper information (not something i can read up in first timer tutorials) at the libgdx talk and less vacuum-cleaner salesman feeling at the android augmented reality talk. Other than that it was well worth attending.

DroidCon Barcamp 8-04-2013 at Kosmos Berlin

This is going to be a short recap for myself about the DroidCon 2013 in the Kosmos Berlin. In deepest respect I thank every presenter for their hard work who took the time to share their knowledge and insights. The following is purely my observation and might be very subjective. If anything appears to be offending please read it as my personal opinion.

11:45 – Interaction and beyond – Wolter

He basically showed of a couple of different devices to develop for and encouraged everyone to think out of the box to get your application as appropriate as possible to increase the end user experience. For instance:

Nothing new in particular though.

12:45 – Libgdx Thomas

He gave a very brief overview about the high level layer of the framework and some components like the SpriteBatch, InputProcessors, how to get the deltaT value, and how to swap some screens. I was a bit disappointed, since I was – work related – looking forward for this talk in particular.

13:15 FOOD! ^_^ Well there was a very delicious all you can eat lunch buffet, which basically amortised  the 10€ entry fee* already. (*which got sponsored by my awesome employer, thank you very much Wooga <3)

14:15 – Push Notifications with Netmera / Android Software Craftsmanship

Well this talk was kinda boring, since the presenter only walked you through the process of using their service layer for using google cloud notifications. He didn’t give much insight or reasoning behind the steps he clicked through. Felt like something I could read up later in a tutorial. So I changed to: Android Software Craftsmanship. Which basically was a free highly unprepared discussion about the common ways to develop software. (not a bad thing in this case) It appeared to be consens for all of he participants to use the test-driven approach. Using version controle like git and svn and even use a continues integration development layer to not mess up things in the long run. If something is not automatable: use conventions and iterate over them so they don’t force outdated rules. Also to abstract layers like DAO-Pattern in order to test them more separately has been recommended. Another recommendation was to use integration and behavioural tests for obvious reasons.

The very most and interesting part for myself was to get to know code retreat. Which basically makes you start a project (possibly pair programming) and work on it for 45 min and then throw every code base away in order to start over the same project again. The goal is not to finish the project but to approach the same problem 6-7 times. Usually differently and most likely better. (e.g. Coneway’s Game of Life) Personal I think it’s a pretty cool and fun idea to improve your own skills.

15:00 Mobility Android

Basically they gave an introduction about their flat search app and some thought process behind certain layout questions. They also opened a discussion on how to improve it even further. Turns out there is always someone with a bright idea to about everything. I think these kind of discussions are very worthwhile attending since you won’t forget the reasons for solving problems in a certain kind of way.

15:45 Reverse Engineering Ingris

Dirk Jäckel put his presentation online. Well – as the title states. If you’re into these kind of stuff it’s worth reading. For me however it was a bit too unrelated to everything I’m doing. So I’m not going into details about that one.

15:45 NFC in Games by Hannes Breul

Since the reverse engineering talk was shorter than expected I joined that talk at the middle. He was giving a good summery about where NFC could be used and about it’s strengths and weaknesses. For instance it can be used for location based games, crowd games with single/multiple locations, since it can be used for transmitting content. I didn’t quiet get all the details, but it sounded quiet interesting. I’m going to link his presentation, as soon as he puts it online.

16:15 Sascha Pallenberg from MobileGeeks opened a discussion about the awareness of the public imagine from younger generations on the internet. And that there should be some sort of education for it. So young people don’t put content online which could ruin their job carrer years ahead before actually applying. Which is troublesome since the knowledge about teachers and younger generations seems to be reverse. Pupils might know more about key technologies than teachers but are not entirely aware of the consequences of their public and transparent internet image and how hard it is to erase unfavourable content. It turned out to be some quiet interesting discussion to follow for one because of Sascha’s well communication skills and for the other because the very different opinion about how transparency could be interpreted in the near future by HR people.

17:15 What to consider when teaming up with a co-founder.

Was quiet interesting as well. Especially the consens to write everything down before starting anything. Better be safe than sorry I suppose.

17:45 Demo/Judgment

Basically a couple of startups showed off their latest android app and were looking for feedback, new designers, developer, business people to join their team or to find new investors. I’m gonna talk about this later when the judgement people are done judging and put their stuff online.

Conclusion

Monday the Barcamp was probably designed for people who haven’t done much with android yet I suppose, since it was rather surficial for my taste. Anyway I got to know some new people which was totally worth participating. It’s all about the people there after all. And the food was quiet enjoyable, which usually convince me to recommend it. :D

How to boost android canvas performance with a buffered Image

When it comes to drawing to canvas on android one very big performance boost can be gained by using a buffered bitmap image. The idea is to draw lines to a bitmap. And then draw the bitmap to the screen.
This approach avoids unnecessarily redrawing elements that has been drawn already multiple times.

1) Create a bitmap in your view.

2) Remember all touch events.

3) Process all touch events. (Draw lines or something)

4) Draw to buffered bitmap image.

lineManager.draw():

5) And finally draw the buffered bitmap image.

Bonus: invalidate canvas only around finger area and only every 90 milliseconds.

See also

Performance in 2D Canvas App / Game on Android and Traceview War Story