Profile cover photo
Profile photo
Gildas Cuisinier
343 followers
343 followers
About
Gildas's posts

Post has attachment

Post has attachment
Les photos du #Yajug  - Google Glasses avec +Alain Regnier 
PhotoPhotoPhotoPhotoPhoto
Yajug 2014 - Google Glasses
44 Photos - View album

Post has attachment

Post has shared content
Android App Polishing: Customizing Soft Keyboard Action Button

With the release of Capitaine Train for Android[0], several people recently asked me how we implemented some of the tips & tricks available in the application (some of these tricks are barely visible but remember, I love details :p). In order to showcase some of the most interesting application bits of code, I thought it could be helpful to Android developers to start a small series of posts. Feel free to comment this article if you want me to describe something you found nice in the Capitaine Train application. 

A long long time ago, Android 1.6 introduced soft input methods. Soft input methods has many advantages over traditional hardware keyboards. It obviously requires less hardware and may help to build lighter devices. It also allow content-dependent keyboards. For instance, a keyboard may be different when typing a person name, an email address or a pin code.

By default, the Android framework bundles several constants you may use to control the keyboard that will appear. From the code perspective, this can be controlled with the android:inputType[1] XML attributes on TextView. You can also change the "Enter" button to display a text that better match its purpose. This can be done thanks to the android:imeOptions attribute (see [2] for an exhaustive list of all the possible values):

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeOptions="actionDone"
    android:inputType="textPassword" />

While a "Done" button can fit almost all purposes (log in form, sign up form, etc.) it is quite ambiguous and not really satisfying to my mind. At Capitaine Train we wanted the action button to better reflect the actual action it performs. As a consequence, when signing in, we wanted the button to display "Sign in" rather that "Done". Because that's what it does after all!

Android lets you customize the action button thanks to the android:imeActionLabel[3] and android:imeActionId[4] attributes (or their TextView#setActionLabelId(CharSequence, int)[5] Java equivalent). Using these methods basically consists on setting a label to the done button and a unique id used to identify the action. Here is what your XML layout should be look like:

<EditText
    android:id="@+id/password"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:imeActionId="@+id/action_sign_in"
    android:imeActionLabel="@string/sign_in_short"
    android:inputType="textPassword" />

The second part consists on catch all taps on the soft input keyboard action button made with the appropriate action id:

mEditText = (EditText) view.findViewById(R.id.password);
mEditText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
   @Override
    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
        if (actionId == R.id.action_sign_in) {
            // Do sign in
            return true;
        }
        return false;
    }
});

#gde   #android  

[0]: https://play.google.com/store/apps/details?id=com.capitainetrain.android
[1]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:inputType
[2]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeOptions
[3]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeActionLabel
[4]: http://developer.android.com/reference/android/widget/TextView.html#attr_android:imeActionId
[5]: http://developer.android.com/reference/android/widget/TextView.html#setImeActionLabel(java.lang.CharSequence,%20int)
Photo

Post has attachment
Devoxx4Kids Arlon! Inscriptions ouvertes! 

Post has shared content
Si vous êtes ou si vous connaissez des femmes développeurs (développeuses?) intéressées par Devoxx France (du 16 au 18 avril), ce formulaire est à remplir au plus vite.

Post has attachment
Le manque de neige a un impact sur le psychologique des enfants 
Animated Photo

Post has shared content
Wait while more posts are being loaded