Android

New release of Kirai – elegant string formatting library for Java

2015-11-22 Android, Java, Open source No comments

I’ve recently released version 1.4.0 of Kirai library. Kirai means phrase in Swahili language. It’s string formatting library written in Java. It originally started as an Android library, but it evolved to pure Java library. It’s first possibilities were basic string formatting and text formatting for Android TextViews. Now, it allows to format strings for Java, Web, Android and even Unix Terminal! Have you ever wanted to have colorful and styled text in your mobile app, website or terminal app? Now you can with an elegant and fluent API! Moreover, I’ve added test coverage supported by codecov.io. It’s really nice service, which integrates with Travis CI and is free for open-source projects. It’s available for various programming languages and build systems.

Check library source code and samples at: https://github.com/pwittchen/kirai

You can add it to your project via Maven:

<dependency>
    <groupId>com.github.pwittchen.kirai</groupId>
    <artifactId>library</artifactId>
    <version>1.4.0</version>
</dependency>

or through Gradle:

dependencies {
  compile 'com.github.pwittchen.kirai:library:1.4.0'
}

Bunch of updates in my OSS for Android

2015-11-08 Android, Java, Kotlin, Open source No comments

Introduction

In the last days I prepared a bunch of updates in my open-source software for Android. Most of them are bug fixes and are related to increasing robustness of the projects as well as their overall quality. I also decided to play a little with Kotlin language from JetBrains, which seems to be reasonable choice for mobile applications running on Android. Nevertheless, writing an app in Kotlin requires some additional configuration and we should remember, it’s still in beta version. If you are interested in Kotlin programming for Android, take a look at Getting started with Android and Kotlin guide from official Kotlin website. You can also take a look at one of my sample apps written in Kotlin and its configuration in Gradle.

Summary of updates

ReactiveNetwork v. 0.1.3

  • fixed bug with incorrect status after going back from background inside the sample app reported in issue #31
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • updated code formatting
  • added sample sample app in Kotlin

Unfortunately, in Android we cannot use Java 8 yet and code should be written in Java 7. We can do some hacks like using RetroLambda or libraries implementing part of functionalities available in Java 8 like streams, but these solutions are still hacks – not the right way. In Kotlin we can use lambdas like in Java 8. In addition, we have a lot of other cool features, which allow us to write less lines of code and detect possible mistakes while writing apps. E.g. Kotlin helps us to avoid NPEs with its additional operators like !!, which tells us that NPE can occur, so we can think of eliminating this possibility. If we don’t use this operator when we should, IntelliJ IDEA or Android Studio will warn us. Below, we can see exemplary usage of ReactiveNetwork library with Kotlin. In this code snippet, we are using so called synthetic properties from Kotlin Extensions for Android. Value connectivity_status is an id of the view defined in XML layout. We can call it directly in Kotlin code and treat as object. It’s really useful and allows us to avoid calling findViewById(...) method for every view in Activity or injecting views with additional libraries like ButterKnife or KotterKnife. It means that we can get rid of a lot of boilerplate code.

ReactiveSensors

  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • added static code analysis
  • refactored sample app and removed repetitions in code

In this project I made only changes inside the documentation, improved Gradle configuration and added another sample app. There were no changes inside the library code, so there was no need to release new library version to Maven Central Repository. Moreover, I’m going to add sample app in Kotlin for this project in the nearest future.

ReactiveBeacons v. 0.3.0

  • replaced distinct() operator with distinctUntilChanged() operator in Observable observe() method in ReactiveBeacons class
  • added permissions ACCESS_FINE_LOCATION and ACCESS_COARSE_LOCATION to satisfy requirements of Android 6
  • renamed void requestBluetoothAccessIfDisabled(activity) method to void requestBluetoothAccess(activity)
  • added boolean isBluetoothEnabled() method
  • added boolean isLocationEnabled(context) method
  • added void requestLocationAccess(activity) method
  • modified sample app in order to make it work on Android 6 Marshmallow
  • reduced target API from 23 to 22 in library due to problems with additional permissions and new permission model (it can be subject of improvements in the next releases)
  • added package private AccessRequester class
  • added sample app in Kotlin

WeatherIconView v. 1.1.0

  • added icons from 2.0 version of the original weather-icons project
  • updated compile sdk version
  • updated Gradle Build Tools version

Prefser v. 2.0.2

  • fixed bug reported in issue #70: get(...) method now returns a null value instead of “null” string when setting default value to null of String type
  • fixed RxJava usage in sample app
  • fixed RxJava usage in code snippets in README.md
  • changed code formatting to SquareAndroid
  • added static code analysis
  • improved code according to static code analysis suggestions

Kirai v. 1.1.0

  • removed formatter(...) method from Kirai class
  • added format(...) method accepting implementation of Formatter interface to Kirai class
  • added Syntax interface and HtmlSyntax class implementing this interface
  • added put(String key, Object value, Syntax syntax) method to Piece class
  • set HtmlSyntax as default Syntax implementation in Piece class
  • removed dependencies to Android SDK
  • updated project dependencies
  • applied Square code style
  • updated tests, sample app and code snippets in README.md
  • added gh-pages with JavaDoc

Any suggestions of further improvements are more than welcome as usual!

Introducing ReactiveBeacons

2015-09-30 Android, Context awareness, Java, Open source No comments

Recently, I’ve created yet another reactive library for Android. It’s called ReactiveBeacons and it’s responsible for observing BLE (Bluetooth Low Energy) beacons. Beacons are small devices, which became quite popular in the last years. They can be utilized in creating Contextual Awareness, Contextual Computing and Internet of Things. Beacons have lithium battery, are constantly turned on and emit signals via Bluetooth all the time. ReactiveBeacons library allows to transform these signals into Observable stream compatible with RxJava. Whenever new beacon is detected or RSSI (Received signal strength indication) changes, new immutable beacon data is emitted.

Usage of the library inside the Activity is simple:

We also have to remember to unregister subscription correctly in order to stop BLE scan, which can drain the battery.

If you want to use this library in your project, add the following dependency to your build.gradle file.

dependencies {
  compile 'com.github.pwittchen:reactivebeacons:0.0.1'
}

Don’t forget to add dependency to RxAndroid if you want to use Android-specific features of RxJava.

Source code of the library can be found at: https://github.com/pwittchen/ReactiveBeacons.

Any new issues or pull requests are welcome!
Happy coding!

Introducing ReactiveSensors

2015-09-05 Android, Java, Open source, RxJava No comments

Another month, another library. Recently, I’ve released yet another reactive library called ReactiveSensors. It’s an open-source Android library monitoring hardware sensors with RxJava Observables. Library is compatible with RxJava 1.0.+ and RxAndroid 1.0.+ and uses them under the hood.

Library is available at: https://github.com/pwittchen/ReactiveSensors.

In my opinion, hardware sensors are perfect case for applying RxJava, because in fact we’re constantly receiving a stream of events emitted by many sensors. With Reactive Programming approach we have plenty of possibilities and easy API for manipulating received sensor’s data.

Usage of the library is really simple. You just need to subscribe an Observable with RxJava in the same way like in any other reactive library.

Code sample below demonstrates how to observe Gyroscope sensor:

Please note that we are filtering events occuring when sensors reading change with ReactiveSensorEvent.filterSensorChanged() method. There’s also event describing change of sensor’s accuracy, which can be filtered with ReactiveSensorEvent.filterAccuracyChanged() method. When we don’t apply any filter, we will be notified both about sensor readings and accuracy changes.

We can observe any hardware sensor in the same way. You can check list of all sensors in official Android documentation.

I’ve created section about Good Practices regarding working with hardware sensors on Android in README.md file in the GitHub repository.You should also read an article about Best Practices for Accessing and Using Sensors in official Android documentation.

Read more in the README.md file located in the repository of the library at: https://github.com/pwittchen/ReactiveSensors.

You can also find JavaDoc at: http://pwittchen.github.io/ReactiveSensors/.

If you want to use ReactiveSensors in your project, add the following dependency to your build.gradle file:

dependencies {
  compile 'com.github.pwittchen:reactivesensors:0.0.1'
}

Feel free to send me feedback, report an issue or fork the library!

Learning Android and being up to date

2015-08-22 Android, Java, Open source No comments

Recently a few people asked me, what are my methods for gathering knowledge and being up to date with all news connected with Android. I didn’t really think about that. I just grabbed all knowledge from a various places and then tried to use it in practice. I decided to sum everything up and create a collection of my knowledge resources. Of course, we are not able to use all of that every day, because it’s too much, but it’s good to know where we can find something interesting. Android is very dynamic mobile platform, which changes really fast. It’s hard to be up to date with all of new features and programming techniques. That’s why it’s worth to find places where we can gather interesting information. Below, I collected some resources, links and information, which I find useful for learning Android & Java and being up to date with Android development.

Podcasts

  • Fragmented Podcast – talks about building good software and becoming better Android developer – you can hear interviews with famous developers like Jake Wharton here

Videos

Collections of articles, issues & libraries

  • Android Weekly – free newsletter that helps us to stay cutting-edge with our Android Development
  • Android Arsenal – huge collection of categorized open-source Android libraries and tools
  • Slicedham.co – collection of engineering stories (not only about Android)

Blogs

Not all articles on the blogs below are connected with Android.

StackOverflow

We can browse interesting topics tagged with Android tag, read them and even try to solve some problems. It will allow us to learn something new or improve existing knowledge.

GitHub repositories

It’s worth to check open-source repositories of great companies and developers to see how smart people solve the problems.
Not all repositories of the companies and developers below are connected with Android, but most of them do.
Moreover, we can still learn a lot from various kinds of OS projects.

Companies

Organizations

Developers

We can also check trending Java repositories or trending repositories in general.

In addition, we can try to analyze source code of various repositories and try to contribute back to them. I guarantee, we’ll learn a lot. We can start with small steps and we don’t have to implement the most complicated features in the beginning.

Twitter

We can follow famous developers or companies. We can also check tags like: #AndroidDev, #Android or #Java and so on.

Experiments & open-source projects

We can create our own projects. We can publish our app on Google Play or create an open-source library on GitHub and let other people use it and review it. Then, we’ll be able to determine if our libraries are usable, code is clean, API is simple and documentation informative enough. In addition, other developers can report bugs or new issues, which will allow improve our projects and develop our programming and communication skills.

Other

Meetings, conferences, hackathons, etc.

Sometimes it’s good to go to a conference, meeting, etc. to talk with people and learn from them. We can take a look at the events around us, attend them or maybe present something. If there’s no events in our location, we can always organize one and ask others for help!

Books

It’s good to have strong basics. Not every book is universal and valuable over the time, but there’re a few fundamental positions for programmers worth reading like Clean Code, Effective Java, Java Concurrency in Practice & Test Driven Development: By Example. It’s an open list and we can always extend it with another position on our shelf.

What else?

Everyone has his or her own method of learning new things. If you know another interesting resources or methods, share them in comments below this article.

Android Marshmallow – API level 23

2015-08-17 Android No comments

Google recently released official Android 6.0 SDK & Final M Preview. New Android version is called Marshmallow.

android-marshmallow

Whether you like them straight out of the bag, roasted to a golden brown exterior with a molten center, or in fluff form, who doesn’t like marshmallows? We definitely like them! Since the launch of the M Developer Preview at Google I/O in May, we’ve enjoyed all of your participation and feedback. Today with the final Developer Preview update, we’re introducing the official Android 6.0 SDK and opening Google Play for publishing your apps that target the new API level 23 in Android Marshmallow.

Jamal Eason, Product Manager, Android

Read more at: http://android-developers.blogspot.com/2015/08/m-developer-preview-3-final-sdk.html

Introducing ReactiveNetwork

2015-08-10 Android, Open source, RxJava No comments

I’ve recently released ReactiveNetwork. It is an open-source Android library listening network connection state and change of the WiFi signal strength with RxJava Observables. It’s a successor of Network Events library rewritten with Reactive Programming approach.

Library is compatible with RxJava 1.0.+ and RxAndroid 1.0.+ and uses them under the hood. Min Android SDK version is 9.
JavaDoc can be found at: http://pwittchen.github.io/ReactiveNetwork.
Repository is available at: https://github.com/pwittchen/ReactiveNetwork.

This library is much simpler and easier to use than NetworkEvents. Even code-base is much smaller, but we have to remember that it utilizes powerful RxJava and RxAndroid. RxJava hase huge API and gives a lot of possibilities. That’s why I was able to obtain desired result with fewer lines of code.

Basic library usage is quite simple. E.g if we want to monitor ConnectivityStatus (WIFI_CONNECTED, MOBILE_CONNECTED or OFFLINE), we can create the following subscription, which is quite familiar for software developers who already know RxJava:

When we want to monitor available WiFi Access Points and we want to get fresh list of them whenever strength of the WiFi Access Points signal changes (e.g. when we are moving with a mobile device around), we can use the following code snippet:

If you want to use ReactiveNetwork in your project, add the following dependency to your build.gradle file:

dependencies {
  compile 'com.github.pwittchen:reactivenetwork:0.0.2'
}

Find more in the GitHub repository of the project at: https://github.com/pwittchen/ReactiveNetwork.

It’s worth mentioning that this library was featured on Android Arsenal, Android Weekly and Android Weekly China websites.

I hope you will find it useful and you will make your apps more reactive!
Feel free to fork the library. Any feedback is welcome as usual.

Releasing Prefser 2.0.0

2015-08-06 Android, Open source No comments

I’ve recently released Prefser library v. 2.0.0.
Prefser is a wrapper for Android SharedPreferences with object serialization and RxJava Observables.
This update couldn’t be done without help of awesome open-source community and people who reported new issues and created pull requests.
Thanks for that! A lot of issues related to RxJava was fixed. Moreover, now we can store and retrieve lists of objects of any type with Prefser.
Examples of library usage can be found in README.md file and in unit tests covering 96% of the code.

Below, you can find release notes for this version of the library:

  • fixed not keeping reference to listener when Observable instance is reused
  • fixed not unregistering listener, which causes onNext() even after unsubscribe()
  • fixed possible missed update with getAndObserve()
  • removed observe(sharedPreferences) method – backward incompatible
  • changed observeDefaultPreferences() method name to observePreferences()backward incompatible
  • added TypeToken and use of generics for interfaces
  • added possibility to store Lists of different types of data including custom objects
  • added more unit tests
  • updated test dependencies
  • updated JavaDoc available at http://pwittchen.github.io/prefser/

Feel free to fork the project or report new issues! Any kind of feedback is warmly welcome.

Releasing NetworkEvents 2.0.0

2015-07-31 Android, Open source No comments

I’ve recently released NetworkEvents library v. 2.0.0.
It’s an Android library listening network connection state and change of the Wifi signal strength.
It has a few significant changes in the API and new features, which people were requesting on GitHub.
Moreover, codebase was slightly refactored and updated.

I’m going to keep major.minor.patch convention AKA semantic versioning now:

  • major – new feature or update – backward incompatible
  • minor – new feature – backward compatible
  • patch – bug-fix – backward compatible

A few changes are backward incompatible, so I’ve increased major number.

Below, you can find list of changes. As you can see, there is a lot of stuff. That’s why I’ve made the most important changes bold.

  • removed withPingUrl(url) method
  • removed withPingTimeout() method
  • removed withoutPing() method
  • removed withoutWifiAccessPointsScan() method
  • removed Otto dependency (now, it’s available only for unit tests)
  • removed example-disabling-ping-and-wifi-scan app sample
  • removed example-ping-customization app sample
  • removed NetworkHelper class and moved its method to specific classes with changed scope
  • moved permissions to Manifest of library
  • disabled WiFi scan by default
  • disabled Internet connection check by default
  • added BusWrapper, which is abstraction for Event Bus required by NetworkEvents object
  • added example-greenrobot-bus app sample
  • added enableWifiScan() method
  • added enableInternetCheck() method
  • added getWifiScanResults() method in WifiSignalStrengthChanged event
  • added getMobileNetworkType() method in ConnectivityChanged event
  • added JavaDoc at: http://pwittchen.github.io/NetworkEvents/
  • updated existing sample applications
  • updated documentation in README.md and library code

Feel free to download, use or fork this library!

Releasing Weather Icon View v. 1.0.0 for Android

2015-07-21 Android, Open source No comments

Today I released Weather Icon View library v. 1.0.0
It’s very simple and easy to use Android library, which allows you to use Weather Icons created by Erik Flowers in your mobile applications. This library was already available on GitHub as I wrote in one of my previous posts, but today it was released to Maven Central Repository and you can use it as Maven or Gradle dependency. I was encouraged to make this project more available by the open-source community and people who find it useful as I could read in the issue reported on the repository website. Thanks for that.

You can find more details, usage examples and sample app in the repository of the project at: https://github.com/pwittchen/WeatherIconView.

By the way, this is article no. 100 on this blog. Thanks for your visits. 🙂