Whowehoo

Bakpacking makes it difficult to keep on developing, that’s why I needed a small project to keep updated with the developer world.
A quick look on share expenses app on the play store revealed that all of them have an old design or are too complex for this simple usage.

Now here it is!

As a developer point of view, here some very quick thinking of some Android features or library I haven’t used before

About ActionBar

The ToolBar is as good and flexible as expected compared to the ActionBar.
I can only advice to use it.

About Bindings

One should not expect too much from android bindings. I was very disapointed by the API, more about this:
http://blog.hithredin.eu/development/android-binding/

About RecyclerView

I got a lot of statisfaction to see in the RecyclerView some pattern we developed internally in my company before the introduction of this component.
Forget the ListView, if not already done.

About Cell/Fragment/Activity communication

Bus event system is a go to avoid crapy getActivity, dangerous casting, strong coupling and redudant setter.
The only problem comes from the message origin and answer system which is not supported by common bus android libraries.

About Snackbar

Snackbar is a beautiful UI pattern. But it has one technical problem: it needs access to the CoordinatorLayout. Which means it must be done in the activity while the instigator is usually a fragment or a list’s cell.

That’s why all my app Snackbar are coded in the generic abstract Activity, called via Bus:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
public void onEvent(final ExpenseRemoved event) {
if (!isActive()) {
return;
}
final CoordinatorLayout coordinatorLayout = (CoordinatorLayout) findViewById(R.id.coordinator);

Snackbar.make(coordinatorLayout, R.string.expense_snack_deleted, Snackbar.LENGTH_LONG).setAction(R.string.cancel, new View.OnClickListener() {
@Override
public void onClick(View view) {
event.trip.addExpense(event.expense);
DataManager.get().saveExpense(event.trip, event.expense);

Snackbar.make(coordinatorLayout, R.string.expense_snack_restored, Snackbar.LENGTH_SHORT).show();
}
})
.show();
}

Ion

Ion is awesome. Easy to use and efficient, I can recommend it has a network library over Volley

FishBun

FishBun is a good to go library if you want an image picker.

Glide

Glide is a good choice as an image loader library. I find it better than Volley.

About recyclable-no-scrollable layout

Picture in your mind a ListView that is added on the bottom of the page.

The page is big and the List goes far into the bottom, so the top parent must be a ScrollView to be able to see everything. But the List contains a lot of data: recycling is mandatory for performance.

Still no solution to implements this use-case, which I often see in design. Here my stackoverflow question:
http://stackoverflow.com/questions/25763569/listview-in-fragment-in-viewpager-in-scrollview-for-android-2-3

Manger au Japon

Petit déjeuner:
Saumon grillé, bol de riz, soupe et petits accompagnements pour bien démarrer la journée

Katsudon:
Porc pané dans une omelette, posée dans un bol de riz tapissé d’oignons. Toujours bon.

Tonkotsu Ramen:
Sans doute la meilleure soupe de nouilles au monde, et de mon point de vue le meilleur plat du Japon. Des os de porc ont été mijotés dans cette mixture, auquels ils ajoutent entre autre de l’ail brun et autres légumes avant d’y cuire les nouilles
Le service vient avec ail à volonté!

Okonomiyaki:
Si le plat est bon, l’intérêt se porte plus dans la fabrication que dans la dégustation.


Soba:
Nouilles Soba, à tremper dans de la sauce soja au wasabi. On peut boire le jus de cuisson des nouilles. Très simple mais bon.

Curry:
Si la sauce n’est pas aussi bonne qu’un curry indien, la viande panée rattrape bien le tout.

Haricots blancs confits:
S’il fallait donner la plus grosse différence culinaire entre les cuisines françaises et japonaises, ce serait la relation avec les haricots. Ici c’est utilisé comme le chocolat en france.

Chirachi
Censé être meilleur à Hokkaido, l’hiver ne doit sans doute pas être la meilleure saison pour déguster des fruits de mer crus.

Tempura:
Une merveille, de la panure partout autour de champignons, crevettes, légumes,….

Crêpes de canard chinoises:
Ne pas aller dans les restau chinois au Japon. Il nous a fallu négocier pour avoir de la viande et pas seulement de la peau dans ce plat déjà trop cher de crêpes de canard.

Moulin à sésame:

Open thé:
Le thé est en libre service, comme le pain peut l’être en France.

Android binding framework: a deception

Data binding is a wonderful feature for user interface developement. It ease the development process, help to clean the code, and do a lot of the job for you.

A quick insight of the gain

You have a form screen, we will take the android materiel design sample:

Drawing

Before databinding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>

TextView tv;
User user = DataManager.getActiveUser();

public void onCreate(){
[...]
tv = findViewById(R.id.name);
tv.setText(user.name);
}

public void validate(){
String name = tv.getText().toString();
}

We have to get each views by id or by annotations libraries. We use them by calling the getters and setters when we need

With Binding

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@{user.name}" />

User user = DataManager.getActiveUser();

public void onCreate(){
[...]
binding.setUser(user);
}

public void validate(){
String name = user.getName();
}

Notice the removable of the id, an information that has now become irrelevant. Things are automatics. The data (should) be a direct image of what is in the screen.
If the Java code change the name, it is immediatly set in the TextView without setText(),.
If the user tap some characters, the model is updated without tv.getText();

Other cool stuff you can do

You want to bind the color or the text to a custom rules (red if too short, green if ok)?
You can do it without multiple lines of java code.

You want to link the progress of a ProgressBar to the advance of a media object?
Just do it in one line of XML.

You want to set a view’s visibility according to your data, nothing easier:

1
android:visibility="@{user.hasAccount ? View.VISIBLE : View.GONE}"

The deception

When google announced the beta of Android binding it was a wonderful news.
When they released the guide, it was wonderful too. A lot of features were availables (converters, expressions, collection support, …)

But, using the android databinding framework has proven to be quite a deception after working with Qt or Windows store sdk:

Not as straightforward as concurrents

A library to include, ViewModels to be declared in each layout, different layout root, other generated class to import, a different way to inflate fragment’s layout.
It is expectable since DataBinding is not included as part as Android SDK. But we see the difference compared to a language designed with binding in mind.

Verbose viewmodel

Android binding require you to change your model, making it extend a specific class from the binding API, or worst, transform all your members into an observable instead of a simple type (Observable instead of String).

This is not acceptable for a clean structure, as well as for Gson auto deserializing. So the solution is exposing every attributes of the model inside the viewModel, which is sooo verbose.

Where the ** is the 2-ways binding?

There is no 2-way binding. Some hacks are available, but it is not a good long term solution for a complex project.
Good bye auto-handled form (the typical always annoying screen to implement), where databinding is nothing else than a saviour.

Pizza Bread

A full-fat meal you can bring in your role-play table, everybody will have sufficient food for exploring donjons all night.

Ingredients:

  • Chorizo
  • Using different cheeses is better for the taste :
    .. Mozarella for the texture
    ..
    Hard cheese for the taste (Comté, Beaufort, Gruyère, Cantal, …)
    ..* Cheddar (Has a strong taste for a cheap price)

  • Bread base, follow one of the multiple receipe to make your bread:
    https://www.meilleurduchef.com/cgi/mdc/l/fr/recette/boule-pain.html

Receipe:

  1. Make your bread, stop before cooking it
  2. Find a high tin with a small surface, add some flour at the bottom
  3. Put one layer of bread, one of cheese and one of chorizo
  4. Do it two or three time and finish by a layer of bread
  5. For a more tasty looking, spread the yellow of egg on the top, with some cheese chips
  6. Cook it like bread (230°) until the subtle smell of the cheese brings your neighbour into your house with his fork in hands.

Manger en Thaïlande

Pas déçu du voyage culinaire en Thaïlande. On trouve partout et à toutes heures toutes sortes de plats, souvent sans mauvaise surprise.
Les portions sont généralement peu copieuses, les thaïlandais s’offrant plus de repas par jours qu’en europe.

Pad Thai
On trouve partout de ces nouilles frites accompagnées de légumes

Le riz n’est pas toujours fris lorqu’il est accompagné de viande et de légumes. Mais le résultat reste très bon.
Le coca à 20bath (45cents) soulage bien le portefeuille.

Les accompagnements sont infinis. Ici j’ai eu de la salade de papaye et du poulet mijoté en sauce piquante, sud de la thaïlande oblige.
Le tout accompagné de choux et de mini comcombre frais. Il parait que ce concombre sert à adoucir la bouche après tout ce piquant.

L’un des meilleurs mets que j’ai trouvé! Du riz gluant au sucre roux et à la noix de coco grillé au feu dans une feuille de bambou.
Légèrement caramélisé, ce riz est succulent.

“Légumes vides” sautés à l’ail et pimentés.

Les thaïs sont des experts en poulets fris. Le Kentucky peut se rhabiller.
Quand on a la chance de tomber sur un cuisinier qui utilise une panure aromatisée à l’ail, c’est le paradis gustatif.

Ces minis crèpes sont fourrées avec une meringue très légèrement cuite. Elle colle aux dents, mais c’est intéressant.
Ca m’a l’air d’être traditionnel pour les fêtes tel que le Lyo Krathong.

Un énième stand de brochettes et poulets fris parmis tant d’autres.

Cette omelette est très proche d’une galette bretonne en terme de texture. Et les huitres fraîches par dessus ne sont vraiment pas chères.

Les produits de la mer ne sont par contre pas tous donnés en Thaïlande et ces scampis de chinatown étaient plus alléchantes que fameuses

Soupe au lait de coco. Ca peut tout aussi bien arracher la gueule comme être extrêmement doux, celon la recette.

Champignons pânés fris. Dès que j’ai un accès à une cuisine je me fait ça avec une panure à l’ail.

Champignons enroulés de jambon pour être grillés au barbecue. A faire avec une vraie tranche de lard et ce serait une merveille.

Quelques sucreries correctes à base de coco et de riz.

Photo by restaurant-douvaine
Non malheureusement, ça, ça commence a sévèrement manquer…

XPeria for development on Linux

This small article gathers some useful tips for using a XPeria as the main test phone for android app developement, using a freshly installed Linux desktop.

adb

First thing first, install the Android developer tools with android studio.
Then add adb to the PATH.

1
2
3
4
5
sudo gedit ~/.bashrc

#Add these lines to the file with gedit
PATH=$PATH:/home/benoit/Android/Sdk/platform-tools/
export PATH

Devices steps

To develop, the device need to be reached by adb.
These steps concern the XPeria devices (tested at least on the M4 Aqua and the Z2).

  1. Go to Settings > About Phone > Click many times on “Build Number”
  2. Go to Settings > Developer options > Put “On” and USB debugging “on” too
  3. Go To Settings > XPeria Connectivity > USB Connectivity > Choose MTP as the USB Connection type

Linux steps

Adb will lack the required permissions to access the device. The steps to solve the problem are cpmmon.

1
2
cd /etc/udev/rules.d
sudo gedit 70-android.rules

Add this line to the file 70-android.rules:
SUBSYSTEM==”usb”, ATTR{idVendor}==”0fce″, MODE=”0666″

1
2
3
sudo service udev restart
adb kill-server
adb devices

Some websites proposes a useful list of idVendor to add the permissions to many devices:
https://github.com/faux123/ubuntu_udev_rules_4_android

XPeria for travelling developers

A la quête du smartphone idéal.

Il doit être conçu pour une utilisation outdoor:
Soit être résistant à l’eau, posséder un bon GPS et une bonne boussole, consommer peu et contenir une batterie solide. Etre résistant aux chocs et à la poussière est aussi important.
Mais, n’ayant pas envie d’acheter plusieurs smartphones, il doit être utilisable dans la vie moderne: fluide, compatible avec beaucoup d’application, utilisable pour développer et donc mis à jour régulièrement.

Smartphone outdoor: Kyocera Torque

Il existe de nombreux modèles de smartphones conçus pour une utilisation outdoor. Ils sont résistants aux chocs, à la poussière et à l’eau. La quasi totalité tourne sous android.

Les fabricants sont entre autre:
Kyocera, Motorola, …. [TODO]

J’ai pu utiliser un Kyocera Torque pour une randonnée en vélo de 4 jours. Ce smartphone se comporte à merveille, particulièrement concernant la consommation de la batterie et l’utilisation de son écran tactile même mouillé.

En l’utilisant dans un mode de vie citadin, pareil, rien à redire: fluide pas trop encombrant, toutes les applications disponibles, son prix est honnête.
Mais grand défaut: il n’a aucune mise à jour mis à part les corrections de bugs. Après avoir parcouru tout les concurrents, et bien il s’avère que tous suivent la même politique:
Un smartphone durçi ou outdoor sera quasiment toujours limité à la même version d’Android.

Ce n’est donc pas envisageable pour une utilisation par un développeur.

Smartphone résistants: XPeria M4 Aqua

Une autre gamme de smartphone pourrait donc convenir: les smartphones résistants, construits par des fabricants grands publics tel que Sony, Samsung, … Résistants à la poussière et à l’eau, ils le sont moins aux chocs.

J’ai donc acheté le XPeria M4 Aqua, pour un prix très intéressant, et j’ai eu l’occasion de tester le Xperia Z3. Tout deux sont semblables, le M4 ayant juste un meilleur format et une meilleure batterie l’air de rien.

  • Utilisation dévelopeur:
    Pas de solution sous Windows, ils ne proposent pas de drivers pouvant être utilisé par adb. Mais sous Linux, une simple manipulation suffit:
    http://blog.hithredin.eu/development/xperia-dev-setup/

  • Utilisation vadrouilleur:
    Ce smartphone est réellement résistant à l’eau: testé sous la mousson thaïlandaise et dans un torrent néo-zélandais. Par contre l’écran devient inutilisable, ce qui est génant lors des longues pluies.
    Toutes les applications possibles et de tout pays sont disponibles sous Android

Pour le prix (230€), les XPeria sont des bons choix.

Needed

Here Maps: Des cartes gratuites sans data dans beaucoup de pays.
La recherche de lieu s’est fortement améliorée et se rapproche de Google Maps. Un must.

OsmAnd: Cartes basée sur openStreet Maps.
C’est un complément intéressant à Here, ou un remplaçant dans des pays ou Here n’est pas disponible (Japon, Laos, …). Plus de petits chemins perdus, mais moins de lieux trouvables.

GPX Viewer: Suivi de traces GPX
Simple et efficace pour suivre une trace GPS. Vous pouvez bloquer la data pour ne pas télécharger le fond de carte, qui n’est de toute façon pas nécessaire.

Bacon confit

A medieval receipe, full of spices, it may reveal mervellous tastes. This one could be name a bacon confit: medium pieces of bacon slowly cooked in its own fat with overtasty spices.

Ingredients:

  • As much thick bacon as possible
  • As much spices as possible among:
    .. cinnamon
    ..
    pepper
    .. anise
    ..
    clove
    .. unpeeled garlic
    ..
    nutmeg
    .. ginger
    ..
    thyme in branch
  • A shooter of water

This is the spices I used, but you can use different ones (chili, coriander,…)

Receipe:

  1. Remove the skin from the pieces of bacon. Save all the fat from the skin with a knife and put it the frying pan.
  2. Start the frying pan at medium/low fire to get the fat off the pieces
  3. Get rid of the bones and cut the bacon into large dices
  4. You may remove the fat from the pan (even if I’d recommand not to do it) and put all the ingredients in it. Don’t be shy on the spicies
  5. Cook it at low fire for 2 hours at least, while stiring from time to time.
  6. Serve with toothpicks for aperitif or with brown bread to eat it as a regular menu.

UX303LB and linux dual boot

About setting up a dual boot Linux Mint / Windows 10 on a fresh Asus UX303LB

Choice of Linux distribution

I wanted an easy to install and to configure Linux distribution, for a developping purpose as well as for every day needs (game, media, music, browsing…)

Ubuntu:
Works great, but Unity is not my favorite desktop interface. Moreover Unity happened to bug too often while gaming on native as well as on Wine games

Fedora:
Sounds better and gnome 3 is great! But it needs more configuration to have steam, mp3, proprietary drivers, …

OpenSuse:
KDE is efficient, and OpenSuse has a good user documentation. Open Suse is a good choice.

Mint:
It comes with the diversity of ubuntu applications and support, but with a stable gaming desktop. That was my final choice

Other:
They are so many other distributions than may be better, but well…

Issues with installation

Windows partitions

Windows 10 had trouble to install itself, with errors messages about GPT file system required. But it is unable to solve the issue itself.
Reading an article on the subject helps a lot to understand the situation: https://fr.wikipedia.org/wiki/GUID_Partition_Table

A linux started from a live USB can help windows:

1) Create a linux live USB
You can use lili, which works well : http://www.linuxliveusb.com/fr/home

2) Reformat the drive with gdisk
This post contains a great answer that helps me a lot:
http://askubuntu.com/questions/84501/how-can-i-change-convert-a-ubuntu-mbr-drive-to-a-gpt-and-make-ubuntu-boot-from

You’ll have to enter into the terminal

1
gdisk /dev/sda1

And follow the guide:
d to delete the partition
n to create a new partition, and then select the GPT system.
h to get a list of the available commands

Execute access with NTFS

After installing Windows and Linux, the last one cannot access my Windows files with execute rights.
This is a common and solvable problem:

1
2
3
4
sudo apt-get install ntfs-3g
sudo umount -a
sugo gedit /etc/fstab
sudo mount -a

And add this line to the fstab file
UUID=YOUR_DISK_UUID /media/data ntfs-3g rw,user,auto,exec,gid=100,uid=1000,nls=utf8,umask=002 0 0

HiDpi

This Asus comes with a high definition (3200*1800) screen which is not handled correctly by a lot of apps. But with a little configuration, it is easy to tell them how to behave.

General Desktop:
Search for “general” in the main menu to set the dpi settings to Double and then restart. The desktop will now be usable.

Other tools:
Follow this complete guide: https://wiki.archlinux.org/index.php/HiDPI

Best Applications

Web Browser
Chrome is for the time being the web browser that behave the best with a multitouch HiDpi screen.
Mint’s Chromium fails with HiDpi while firefox and opera cannot take advantage of the touchscreen

Usefull Apps

Some applications that tweaks your system:

Because having a terminal entry in the File browser is great:
http://community.linuxmint.com/software/view/nemo-terminal

Brackets is a good simple web editor, with a specific extension:
https://github.com/cgaspard/brackets-hidpi

White label structure for Android

In the projects we worked on, I often faced the need to create multiple builds of one application for different clients. Android SDK is very powerful in such situation and exposes many possibilities.

Here a proposition of different solutions for an Android application that is expected to be built into many different targets.
The main purposes I see are :

  • reducing the number of code lines
  • propagating the bug fixes to every flavour
  • isolating the specific codes of one flavour

Some definitions are needed, taken from the the Android Documentation:

  • Flavour: A product flavor defines a customized version of the application build by the project.
  • Build Type: A build type allows configuration of how an application is packaged for debugging or release purpose.
  • Build Variant: This is a combination af a flavour and a build Type.
      

White label sample

This article is based on a fake sample: a white label application that is declined for different restaurants, among which “PizzaGood”, “Kebab200” and “JapSushi”. The design will change as well as the available features.

Building the variant with gradle

  1. Create the main folder as well as one folder for each white flavour, in the “src” folder of the project.

  2. Edit your project build.gradle to configure the flavour

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
productFlavors {
main {
versionName "6.0.0"
packageName "eu.hithredin.sample"
}
pizzaGood {
versionName "1.0.1"
packageName "com.pizzagood"
}
}
```
&nbsp;&nbsp;

## Implementing specific features

### The config file method
A good solution consists on implementating a custom config file that is read dynamically at startup. The code will be activated and parametrized according to this config.

#### PROS:
+ Only one code to handle all the specific features
+ Easy to re-configure and create a new white label

#### CONS:
- Impose a reflexion to generify the specific features
- Complex if the specific requirement is a big feature

#### HOWTO:

1. Create a Json config file in the "res/raw" folder of each flavour

``` json
{
"flavorSearch": {
"filters": ["ingredient", "price"],
},
"flavorGlobal": {
"facebookEnabled": false,
"subscribeEnabled": true,
"noteAppEnabled": false,
"shareAppEnabled": false
}
}
  1. Create a singleton manager, named FlavorParam, which is basically a model binded to the Json
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
public class FlavorParam {

private static FlavorParam instance;

public FlavorSearch flavorSearch;
public FlavorGlobal flavorGlobal;

public static void init(Context ctx) {
//Load config
Gson gson = new Gson();
try {
InputStream inStream = ctx.getResources().openRawResource(R.raw.flavor_param.json);
instance = gson.fromJson(BaseUtils.inputStreamToString(inStream), FlavorParam.class);
} catch (Exception e) {
Log.e("AppContext", "FATAL error, cannot load AppContext");
e.printStackTrace();
}
}

public static FlavorParam get() {
return instance;
}

public static class FlavorGlobal implements Serializable {
public boolean subscribeEnabled;
public boolean facebookEnabled;
public boolean noteAppEnabled;
public boolean shareAppEnabled;
}

public static class FlavorSearch implements Serializable {
public List<String> filters;
}

}
  1. Implement the thing, for exemple the activation of a Facebook login for PizzaGood but not Kebab200.
1
2
3
if(FlavorParam.get().flavorGlobal.facebookEnabled()){
showFacebookLogin();
}

  

The build constants method

Use the gradle system to send the configuration of the flavour.

PROS:

  • Very efficient for constants
  • Easy to re-configure and create new white label

CONS:

  • No code, just data

HOWTO:

Just add a line to the gradle configuration:

1
2
3
4
5
6
7
productFlavors {
pizzaGood {
versionName "1.0.1"
packageName "com.pizzagood"
buildConfigField "String", "PUSH_SENDER_ID", '"1010010404040"'
}
}

That can be easily accessed in Java:

1
GCMRegistrar.register(context, BuildConfig.PUSH_SENDER_ID);

  

The flavour file resolution method

Each xml or java file with a specific behaviour is duplicated in the flavour corresponding folder

PROS:

  • Very flexible: do what you want
  • Very efficient for styles, images and sizing customisation

CONS:

  • Code is duplicated
  • Specific code cannot be shared between multiple while label
  • No bug fix or new features propagation

How to reduce duplication

  • Do not hesitate to create multiple files for the same fonctions. For instance, create two dimen.xml files, one with generic values and the other one for specific values.
  • Highly rely on the composite design pattern, and divide your once unique class into multiple features class. Each class can then be redefined in the flavour without recoding everything
  • If not wanted, in the main project create an empty class that extends the real class, and use this one. This empty class can be redefined in the flavour. It will be able to keep or override all the generic code.

TODO UML diagram
  

The custom global code

Use a simple “if” each time you write a new feature (LabelManager.isPizzaGood())

PROS:

  • Very flexible

CONS:

  • The code is spread everywhere
  • Difficult to debug
  • Difficult to add a new white label
  • Complex if the specific requirement is a big feature

I would definitly not recommend to use this method. Easy at the beginning but the developer will faced parts of specific code everywhere which makes a new white label quite an horror to add.
  


Which solution for which case?

Cases Flavour file resolution Gradle build file Config file method
Resources (color, drawable, string, dimen, ….) V
Constants configuration V
Independant Features activated for multiple flavour V
Complex features that are specific to one flavour only V