JDD 2016 Conference

2016-08-21 Conferences, Java No comments

Overview

This year in the beginning of the October is highly recommended to be in Kraków, Poland in order to attend JDD (Java Developers Days) Conference.

jdd_logoJDD is an unusual conference. You can hear the presentations of both experienced people and those who are starting their adventure in the IT industry. You meet speakers from Poland and all around the world. There’s also a wide range of presentation topics concerning not only technical trends and practices but also work methodology, communication, how to talk with people, etc. what has the same importance as coding proficiency.

JDD_4  JDD_1  JDD_7

Besides the presentations, you can meet a lot of interesting people from IT industry in Poland and abroad including programmers, QAs, managers, leaders, etc. There’s a great possibility to establish new contacts and meet old friends. If you are looking for new job opportunities or want to make a market research, you can also do that because there’s a lot of companies looking for new employees. I’ve attended this conference in the last years and I can tell that atmosphere is really great and you can learn a lot. Moreover, Kraków is a very nice city to spend some time, visit the old town, sightseeing, and go to the pubs in the night. Not to mention, there’s party after conference days :-).

Details

Discount for the blog readers!

All blog readers have 15% discount for the conference tickets with the code JDD_wittblog. I hope, it’ll encourage you to fill in the registration form.

See you at the conference!

Dockerizing Hybris

2016-07-27 Docker, Hybris, Java 1 comment

Introduction

A few months ago, I started work at Hybris, which was acquired by SAP, so our “division” is officially called SAP Hybris. I work in a team developing an extension for Hybris platform with assisting extensions and internal framework. There are many teams around the world developing their own extensions, which are finally integrated and packed into Commerce Suite provided to the clients and partners. We have our own development environment, but sometimes there’s need to build and run whole Commerce Suite in the case of system tests, bug reproduction, verification, etc. It’s not really hard, but you have to know what to do and you have to perform a lot of steps manually. This is kind of old approach in present days. Moreover, it’s really big project, so build and initialization process takes time. You have to download huge zipped package, unpack it, run Gradle script with installation recipe, compile project, run initialization and finally start the server.

Automating work

I wondered if it’s possible to automate mentioned process. Moreover, I wanted to learn more about Docker and create more advanced Dockerfile than “hello world”, which will be real life use case. That’s why I decided to dockerize SAP Hybris Commerce Suite. I called this project ydocker and you can find it at https://github.com/pwittchen/ydocker. Before you start doing anything, you need to remember to install Docker on your system. You can check out my notes about installation Docker on Linux in learning-docker repository.

Note #1: It’s not official company solution yet. Right now it’s just my personal proof of concept.

Note #2: I had problems with building and running this Docker container on OS X and I haven’t tested it on MS Windows. These systems need to use boot2docker, Docker Toolbox or another approach like that. I had no problems with it on Linux (Ubuntu 14.04 LTS), so this system is recommended if you want to build and run this container successfully. Probably other Linux distributions or Ubuntu versions will handle this as well.

Note #3 (update from 01.10.2016): Guys working on Docker improved their software for Mac, so it should work without any problems on this system now. It was tested on OS X El Capitan 10.11.6 and works fine. We just need to get Docker for Mac.

Building Docker container

Except for Dockerfile, ydocker repository also contains helper script ydocker, which has the following parameters:

-b    building Docker container
-r    running Hybris Server in Docker container
-c    running Docker container with CLI
-i    showing info about Docker container
-u    showing Commerce Suite Download Url
-d    deleting Docker container
-h    showing help

This script uses configuration file ydocker.conf, which has the following contents:

DOCKER_IMAGE_NAME=sap-hybris-commerce-suite
COMMERCE_SUITE_VERSION=latest
RECIPE=b2c_acc
HOST_PORT=9002
CONTAINER_PORT=9002

You can customize this configuration. E.g. choose a different version of the suite, different recipe or change server port.

To build container, you can just type:

./ydocker -b

Then, provide your credentials and Docker will:

  1. create container based on Ubuntu
  2. install Java 8
  3. set Java 8 as default Java version
  4. install wget
  5. download SAP Hybris Commerce Suite via wget
  6. unpack downloaded SAP Hybris Commerce Suite
  7. remove downloaded zipped package to save some disk space
  8. run configured installation recipe
  9. compile the project
  10. run system initialization

It may take some time. If you have good hardware setup it may take about 30 minutes.

Running Docker container

When everything is done, you can run docker image, with the command:

./ydocker -r

After that, Docker will start the server at localhost (127.0.0.1) and port 9002, which is exposed.
Commerce Suite will be started in a default configuration, which is not production ready, but is good for testing and demonstration purposes.
You need to wait for a few minutes to let the server warm up and then you can open administration console from the browser at http://127.0.0.1:9002.

In addition, if you want to browse generated configuration or unpacked suite, you can run Docker container with CLI with the following command:

./ydocker -c

It won’t start the server, but allow you to take a look around container via terminal.

Summary

That’s it! This proof of concept shows that we can get, build and run complicated and a huge project like SAP Hybris Commerce Suite inside Docker container, automate a lot of manual work and transform old school manual deployment and build process into elegant and standardized Docker container.

ReactiveNetwork – release v. 0.5.0

2016-07-24 Android, Java, Open source No comments

I have never thought that seemingly tiny thing like monitoring network connectivity on a mobile device can be subject to development for at least about one year!

I’ve recently released a new version of my project – ReactiveNetwork library – v. 0.5.0.

Highlights of this release are as follows:

  • added support for the new network monitoring strategy with NetworkCallback available since Android Lollipop (API 21)
  • kept backward compatibility of network monitoring with pre-Lollipop devices
  • added possibility to implement custom network monitoring strategy
  • made methods responsible for creating Observables static like in original RxJava project
  • added Preconditions class verifying correctness of the input parameters
  • changed API of Observable responsible for monitoring network from Observable<ConnectivityStatus> observeNetworkConnectivity(context) to Observable<Connectivity> observeNetworkConnectivity(context)
  • replaced ConnectivityStatus enum with Connectivity class containing info about network state, type and name
  • added more unit tests

You can read detailed release notes on GitHub.

I hope, this project will make your apps more robust and you won’t be surprised by incorrect network monitoring when your users will upgrade their devices to Android N. The newest Android version is not officially released to all Android devices yet, but it’s already supported by ReactiveNetwork library.

Setting up Android Studio on OS X

2016-07-05 Android, Apple, macOS, OS X No comments

Setting up Android Studio on OS X can be tricky. I had a strange problem with tools.jar file and I am not the only one.

After installation of Android Studio, when I started it up, I got an error, which looked like that:

'tools.jar' seems to be not in Android Studio classpath.  
Please ensure JAVA_HOME points to JDK rather than JRE.

jdk_required_screenshot

Luckilly, I fixed this problem and set up Android studio in the following way in my .zshrc file.

If you are not using ZSH, you should set it up in your .bashrc or .bash_profile file.

  # android
  export STUDIO_JDK=/Library/Java/JavaVirtualMachines/jdk1.8.0_65.jdk
  export ANDROID_HOME=$HOME/Library/Android/sdk
  export PATH=$ANDROID_HOME:$PATH
  export PATH=$ANDROID_HOME/tools:$PATH
  export PATH=$ANDROID_HOME/platform-tools:$PATH
  alias runAndroidStudio="/Applications/Android\ Studio.app/Contents/MacOS/studio"

Please, remember to set your version of JDK. If you have a different version than me, you need to change STUDIO_JDK variable respectively.

Complete source of my .zshrc file can be found here: https://github.com/pwittchen/dotfiles/blob/master/.zshrc

Then, I need to start Android Studio with the following command from terminal:

$ runAndroidStudio

Unfortunately, opening it via Spotlight or from Applications menu doesn’t work properly in my case. If you know, how to fix it, leave a comment below this article!

That’s it! With that setup, I can finally use Android Studio on Mac OS X.

ReactiveNetwork – new releases & roadmap

2016-06-10 Android, Java, Open source, RxJava No comments

Recent updates

I’ve recently released version 0.3.0 of ReactiveNetwork library for Android. As you can see in the release notes, it contains a lot of updates.
Highlights:

  • Deprecated methods related to monitoring WiFi Access Points and WiFi Singal level in favor of ReactiveWiFi project, which has this functionality extracted from ReactiveNetwork
  • Deprecated methods and enums related to monitoring connectivity with The Internet
  • Added Observables, which allows monitoring Internet connectivity basing on socket connection with a remote host (we can also monitor specific host with given parameters)

Roadmap for the future versions

Updates planned for 0.4.0:

  • Removing deprecated methods
  • Removing unused permissions from AndroidManifest.xml

Track progress of releasing 0.4.0 on GitHub

Updates planned for 0.5.0:

  • Updating library code with respect to the updates in Android 5 and 6 (especially ConnectivityManager) related to monitoring network connectivity mentioned in issue #62 on GitHub
  • Creating strategy interface to keep backward compatibility with Pre-Lollipop devices, so we’ll be able to monitor network in a different way depending on the given Android version

Track progress of releasing 0.5.0 on GitHub

Another future updates (not related to any version):
These updates are also important, but they’re not related to library API

  • Adding example of library usage with Retrofit (without breaking reactive stream chain)

Track progress of resolving this issue on GitHub

Final thoughts

Currently, it’s my most popular open-source project and people rely on it in production apps, so I’m trying to keep it as simple and as good as I can with respect to the recent updates of Android SDK. I’m getting really good feedback from people on GitHub and seriously considering it during the development process. If something bothers you in that project, don’t hesitate to create an Issue or new Pull Request on GitHub.

Silesia Java Users Group – re-activation

2016-06-05 Java, Meetups No comments

In the beginning of this year, after a very long break, small group of Java and JVM enthusiasts re-activated Silesia Java Users Group (SJUG) in the upper Silesia region of southern Poland. There were four meetings this year up to now. The fifth meeting is planned for this Friday (10th of June 2016 at 17:30) in Katowice, ul. Jesionowa 9a, Biurowiec Budrol, piętro 1, sala 102. The topic is Thinking Immutably About Pipelines and will be presented by David Pollak. If you are in Katowice or somewhere around on this Friday afternoon, don’t hesitate to come to this meeting!

More information

Everyone interested in software development, Java and JVM is invited to these meetings. Doesn’t matter if you’re an expert or a newbie. New speakers are also welcome.

There’ll be free pizza, licenses for IntelliJ and JProfiler to give . 🙂

Handle swipe events in reactive style

2016-03-11 Android, Java, Open source, RxJava No comments

Introduction

Initial Swipe Detector project was created on 24th of December 2014 on GitHub, so more than one year ago. I also wrote an article about that on my blog. I needed that to detect moment when user is swiping horizontally, to block vertical scroll on the ListView while deleting item with “swipe to delete” functionality. This gives better UX and apps from Google works in the same way. Mentioned project was just a simple proof of concept showing how can we detect whether user is swiping on the screen of mobile device and in which direction. Recently, I thought that it would be cool if we had a separate generic library to do the same thing. It would be even cooler if this library will provide RxJava Observable to handle such events in a reactive way. That’s why I’ve decided to take this project, extract generic code to library and write an Observable wrapping listener, which handles swipe events. Please, take a look at the outcome of that work.

swipe

Preparation

New library is called swipe. If we want to use it, we need to add proper dependencies to our build.gradle file:

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

Next, we need to create Swipe attribute in our Activity:

private Swipe swipe;

We also need to remember to call dispatchTouchEvent(MotionEvent) method:

We need to perform things described above both for listener and RxJava Observable.

Imperative way

If we are not familiar with RxJava, we can handle swipe events in an imperative way with listener:

Reactive way

If we want to use the power of RxJava and code our app in a reactive style, we need to add Subscription attribute.

private Subscription subscription;

Now, we can subscribe an Observable:

Please note, there’s much less code than in the case of listener.

We need to remember to unsubscribe our Observable, when it’s no longer needed:

That’s it! I hope it will help you to detect and handle swipe events in your apps.

Source code of the library is available on GitHub: https://github.com/pwittchen/swipe.

Infinite scroll for RecyclerView in Android

2016-02-28 Android, Java, Open source, UI 5 comments

Introduction

Three years ago I wrote short article about Endless ListView in Android. This solution was dedicated to ListView, wasn’t perfect and generic. Moreover, lot of people asked questions about this solution and they weren’t sure how to use it properly. I also had some problems with implementing endless scroll AKA infinite scroll in Android apps. In addition, in the newest Android SDK it’s recommended to use RecyclerView instead of ListView. For a long time I couldn’t find the right implementation of the infinite scroll AKA endless scroll for Android. A few solutions I’ve found weren’t production ready, weren’t working correctly or had too many features. I wanted to have small, easy and flexible solution to implement infinite scroll for Android, which works with RecyclerView from the newest Android API. That’s why I created new project called InfiniteScroll, which helps to implement infinite scroll on Android. Library is tested and its behavior is documented by appropriate unit tests. If you would like to see it in action, check out gif animation presenting how sample app works. Library is very tiny, but does its job.

How to use it?

First of all, we need to add library dependency to our build.gradle file:

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

We also need to create necessary fields in our Activity:

public RecyclerView recyclerView;
private LinearLayoutManager layoutManager;

Next, we need to create new InfiniteScrollListener:

Then, we need to initialize RecyclerView and LinearLayoutManager in our Activity and add previously created listener to RecyclerView:

If we want to display loading progress, we should add additional view for it, show it while loading starts and hide it when loading is finished.

That’s it!

Please note: We can also implement “Load more” button with that library. Instead of loading items immediately, we can display such button when user scrolled to the end of the list.

Exemplary apps

You can see how, library can be implemented in the following places:

  • Sample app from main repository, which loads Strings into RecyclerView
  • Search Twitter app, which allows to search tweets and scroll them infinitely

Summary

I think, this time infinite scroll is implemented in the right and re-usable way. I hope, it will make your life easier while developing your apps.

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

ReactiveNetwork – release of v. 0.2.0

2016-02-11 Android, Java, Open source, RxJava No comments

I’ve recently released new version of ReactiveNetwork library for Android.

Here are the fresh release notes for version 0.2.0:

  • added possibility to observe WiFi signal level with observeWifiSignalLevel(context, numLevels) and observeWifiSignalLevel(context) method
  • created WifiSignalLevel enum
  • added internet check to parameters of getConnectivityStatus(context, checkInternet) method
  • made getConnectivityStatus(context, checkInternet) method public
  • changed String variable status in ConnectivityStatus enum to description and made it public
  • changed output of the toString() method in ConnectivityStatus to keep consistency with another enum
  • made ReactiveNetwork class non-final
  • bumped Kotlin version in sample app to 1.0.0-rc-1036
  • increased immutability of code of the library
  • updated sample apps and documentation

Thanks to @llp and his Pull Request, we are able to observe WiFi signal level AKA RSSI now! It’s one of the most interesting features in the newest release.

We can do it as follows:

or we can observe an enum value instead of integer:

WifiSignalLevel enum can have the following values:

public enum WifiSignalLevel {
  NO_SIGNAL(0, "no signal"),
  POOR(1, "poor"),
  FAIR(2, "fair"),
  GOOD(3, "good"),
  EXCELLENT(4, "excellent");
  ...
}

Any feedback will be appreciated!

Happy coding!

Converting audio CD to *.mp3 files on Linux

2016-01-24 Linux, Ubuntu 2 comments

Not all songs are available on Spotify and sometimes we need to rip music from audio CDs in order to listen it on our computer or mobile device.

There are several approaches to do that. Here is mine:

Get RipperX:

sudo apt-get install ripperx

Put audio CD into your computer. Open RipperX, select All Tracks and check Rip to WAV option. Set quality of output files via “Config” option and names of the tracks if your want. Press “Go!”. After conversion, you should have directory with ripped *.wav files in your home directory.

Get SoundConverter:

sudo apt-get install soundconverter

Run it and convert *.wav files to *.mp3. You can choose another output format if you want.

Get EasyTag:

sudo add-apt-repository ppa:amigadave/ppa
sudo apt-get update
sudo apt-get install easytag

Open EasyTag and set appropriate tags for your *.mp3 files. You can also set CD cover as image for each file.

You are done!

Now, you can import files to your favorite music player. I’m using Spotify right now, where I can select local files, create a playlist and even sync it with my mobile device if my computer is in the same WiFi network. It’s very handy option.

I hope, this short tutorial will be helpful for you.