Year: 2014

Blog Summary of 2014

2014-12-31 Uncategorized No comments

Short blog summary of 2014:

  • 28 748 sessions
  • 24 400 users
  • 35 212 page views
  • 1.22 pages per session
  • 00:00:41 was average session duration
  • about 115 unique visitors everyday
  • The greatest amount of blog visitors was from India
  • I also had a lot of visitors from USA, Poland (my home country), Germany, Vietnam, South Korea and other countries
  • I had 881 visitors from Bengaluru, 601 visitors from Chennai (Hello, India!) and 587 visitors from Seoul (Hello, South Korea!)
  • I had visitors from every country in the Europe, Asia, North America, South America, Australia, New Zeland and about half of the countries from Africa
  • Most of keywords in search traffic were connected with Android
  • I started using Linux (Ubuntu) on daily basis and wrote few articles about it
  • I still use Windows at work
  • I graduated from my university and started working full-time
  • I released my own mobile Android application created during writing my Master Thesis which has been downloaded by 1603 people and has 815 active users up to now

Numbers were retrieved from Google Analytics and Google Play Console.

I learnt a lot and still have to learn more.
Thanks for visiting my blog. I hope that New Year will bring new challenges and opportunities for all of us!

Synapse Indicator – Spotlight for Ubuntu

2014-12-27 Linux, Ubuntu 3 comments

Introduction

If you were using Ubuntu for some time, you might have noticed that Ubuntu Dash from Unity is working quite slow. We can disable on-line search or a few other elements, but it’s still very slow. If we want to have fast search, we can use external software like synapse.

Synapse

Synapse is searching really fast and we don’t have to wait a few seconds like in Ubuntu Dash or disable some search options.

synapse

Synapse can be installed with the following commands:

sudo add-apt-repository ppa:synapse-core/ppa
sudo apt-get update
sudo apt-get install synapse

After installing it, in Synapse Preferences we can set appropriate shortcut for opening Synapse.

Synapse Indicator

If we want to have “Mac OS-like” experience, we can use Synapse Indicator which is similar to Spotlight from OS provided by Apple.

spotlightsynapse

Synapse Indicator (AKA indicator-synapse) can be installed with the following commands:

sudo add-apt-repository ppa:noobslab/apps
sudo apt-get update
sudo apt-get install indicator-synapse

Drawback of Synapse Indicator is the fact that it does not have shortcut for search. We can set it by doing some “hack” described at Nerd Answer page.

Adding keyboard shortcut for Synapse Indicator (hack)

Step 1: Install xdtool.

sudo apt-get install xdotool

Step 2: Move your mouse over the synapse icon and get mouse location

xdotool getmouselocation

You should get output like this:

x:1568 y:9 screen:0 window:62914568

Step 3: Add keyboard shortcut for indicator

Go to System Settings -> Keyboard -> Shortcuts -> Custom Shortcuts.

Click add and for the command type (replace x and y with the ones from the previous command):

xdotool mousemove <x> <y> click 1 mousemove restore

Then add the shortcut you want.

It’s not pretty and elegant way, but I don’t know any other solution. If you know, how to do it better, leave a comment, below this article.

Additional note

Please remember that if you change your screen resolution or switch between two screens (e.g. laptop screen and external, bigger screen), your mouse click coordinates will have to be updated in the shortcut.

Detecting swipe gesture in mobile application

2014-12-25 Android No comments

Introduction

Update: Swipe Detector project is now called swipe.

Some time ago, I needed to detect moment when user is swiping finger on the screen horizontally (from left to right or opposite) or when user swiped horizontally. I’ve decided to spend some time for analyzing onTouch(MotionEvent event) and dispatchTouchEvent(MotionEvent event) method. We can read more about differences between triggering onTouch eventes on StackOverflow thread. Method like onTouch(MotionEvent event) allows to trigger any touch event, but it doesn’t allow to detect type of that event. Android API has GestureDetector class, which allows to detect long press and double tap events. There is also GestureDetector.OnGestureListener interface, which has the following methods:

  • onDown(MotionEvent e)
  • onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
  • onLongPress(MotionEvent e)
  • onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
  • onShowPress(MotionEvent e)
  • onSingleTapUp(MotionEvent e)

There is also GestureDetector.SimpleOnGestureListener class implementing GestureDetector.OnGestureListener and GestureDetector.OnDoubleTapListener interface. I also found an interesting project extending Android API called better-gesture-detector.

Detecting swipe gesture

swiped_right

swiped_up

swiping_horizontal

swiping_vertical

Unfortunately, all of these solutions doesn’t allow to detect swipe gestures (swipe left, right, up and down). That’s why I’ve decided to create my own project, which allows to detect, whether user is currently swiping in a specific direction or if user already swiped. We can implement SwipeListener interface and do whatever we want, when desired event occurs. Check out SwipeDetector project on GitHub. If you want to see how swipe events are detected, browse source of SwipeDetector class. If you want to see exemplary usage of this class, check out SwipeDetectorActivity.
SwipeDetector.SwipeListener interface allows to implement the following methods:

  • onSwipingLeft(MotionEvent e)
  • onSwipedLeft(MotionEvent e)
  • onSwipingRight(MotionEvent e)
  • onSwipedRight(MotionEvent e)
  • onSwipingUp(MotionEvent e)
  • onSwipedUp(MotionEvent e)
  • onSwipingDown(MotionEvent e)
  • onSwipedDown(MotionEvent e)

Moreover, we can take a look on a similar project called better-gesture-detector, which recognizes more types of gestures and also can be useful.

That’s it. I hope, it will be useful in your projects as well.

Installing release and debug version of app on a single device

2014-12-25 Android, Gradle No comments

Introduction

During software development process developers and QAs may want to have installed release and debug version of the app on a single device, what can be very helpful when they want to develop and use application at the same time. Another advantage is the fact that debug and release version of the app may need different configuration. It this post I will show you an example in which we are changing application name and launcher icon, but we can also change different values during compilation in the same way (e.g. address of the webservice). Some time ago, I’ve created similar template, but it was using older version of Build Tools, Android SDK and Android Studio. I’ve created new template, with the newest version of Android Studio (1.0.2) and newest version of Build Tools (1.0.0), so in that case, build.gradle file is smaller and simpler, but does its work correctly.

Exemplary repository

You can find exemplary project template at: https://github.com/FutureProcessing/android-debug-release-template.
All important information are included in README.md file and build.gradle file with project configuration.

Important files:

Source of essential build.gradle file presenting main idea is as follows:

Basics of Git

2014-11-27 Git No comments

Introduction

Git is very popular Version Control System used in many software projects today. In my opinion, it’s the best VCS available today.
In order to start your adventure with this tool, you should know its basic commands and features.
There are graphical tools, which allows to use Git without terminal, but I recommend you to use terminal. With CLI you can work faster, you can understand Git better and you have more control over your repository.

Basic commands

In my opinion, list presented below contains commands, which are used on daily basis and you should start journey with them.

Git hist

There is one more fancy feature, which allows you to display colorful and graphical representation of branches and commits.

You can assign this command to hist alias in your .gitconfig file. After that, you can type: git hist and this command will be executed.

You should see something similar to the log on the screen below.

git_hist_example

It’s a history of commits to AndEngine repository.

More advanced commands and features can be mastered after some work with basic Git stuff.

Resolving conflicts

It may happen that someone modified file and pushed changes into repository and after that we modified the same file in the same place and want to push our changes. In such case, we have to resolve conflicts and merge changes. Sometimes, its more convenient to resolve conflicts with graphical tools than editing raw files modified by Git. If you are using IDE provided by JetBrains (e.g. IntelliJ IDEA or Android Studio) you can use VCS tools built-in IDE. Just choose option VCS -> Git -> Merge changes... for program menu and you can merges via graphical interface. There are also other tools like Kdiff3 or Meld, but I personally prefer JetBrains tools.

Git flow

Last, but not least, remember to read about Git workflow and familiarize yourself with that concept:

Further learning

There are many Git tutorials and materials worth reading, which can help with extending knowledge about this VCS:

7 Rules for Creating Gorgeous UI

2014-11-23 Design, UI No comments

Rules

When we start creating good, clear and consistent UI, we should make some assumptions.
We can follow such rules:

  1. Light comes from the sky
  2. Black and white first
  3. Double your whitespace
  4. Learn the methods of overlaying text on images
  5. Make text pop and un-pop
  6. Only use good fonts
  7. Steal like an artist

Reference

There is quite interesting article about creating gorgeous UI, which describes mentioned rules in details and is divided into two parts:

Some aspects are obvious, but it’s good summary.
mobile-design-cards-01

How to update forked GitHub repository?

2014-11-07 Git No comments

When you fork GitHub repository, you usually want to have your fork up to date with the original repository.
You can update your fork in a few easy steps. Just look at the following example of the Git commands:

Original StackOverflow post with this solution can be found here: http://stackoverflow.com/a/7244456.

How to switch Java version on Linux?

2014-11-02 Java, Linux No comments

Sometimes we need to run specific program with a concrete version of JVM. We can also work with Java 7, but we want to try Java 8. In such cases, we can have installed both Java 7 and 8 on our system and easily switch between them.

In order to show current java version, we can simply type: java -version in terminal.
On my computer I received the following response:

Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar
java version "1.8.0_25"
Java(TM) SE Runtime Environment (build 1.8.0_25-b17)
Java HotSpot(TM) 64-Bit Server VM (build 25.25-b02, mixed mode)

We can see that I am using Java 8. If we want to switch to Java 7, we can use the following command:
sudo update-alternatives --config java

I am using Polish lanugage version of Ubuntu, so I received response, which you can see below.
If you are using another language version, you will see messages in your language.

Są 3 dostępne alternatywy dla java (dostarczające /usr/bin/java).

  Wybór       Ścieżka                                       Priorytet  Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-8-oracle/jre/bin/java          1075      tryb auto
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      tryb ręczny
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1074      tryb ręczny
* 3            /usr/lib/jvm/java-8-oracle/jre/bin/java          1075      tryb ręczny

Proszę wcisnąć Enter, aby pozostawić bieżący wybór[*]; albo wpisać wybrany numer:

Basically, we can just type number of a concrete version of JVM and press Enter. Currently, I have Oracle Java 7, Oracle Java 8 and Open JDK 7 installed in the system. When we type 2, we will switch to Java 7. After that, when we type: java -version, we will see the following message:

Picked up JAVA_TOOL_OPTIONS: -javaagent:/usr/share/java/jayatanaag.jar 
java version "1.7.0_72"
Java(TM) SE Runtime Environment (build 1.7.0_72-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.72-b04, mixed mode)

If we want to switch back to Java 8, we can do it in the same way.

Java Gradle Template

2014-10-17 Gradle, Java No comments

Some time ago, I had some troubles with configuring Java project with Gradle in IntelliJ IDEA CE. There is possibility to create new Gradle project in mentioned IDE, but for some reason it didn’t worked out-of-the box in my case on Ubuntu. I wanted to have pure, clean Java project with Gradle build system ready to open in IntelliJ IDEA. I found well configured simple project at: https://github.com/quinnliu/SampleGradleProject. Basing on that project, I created my simple template. I modified this project a little bit, added FEST assertions and wrote a few Unit Tests. In addition, I configured main class in build.gradle file in order to execute it via ./gradlew run command. My project template also has gradle wrapper, which is very convenient practice.

You can find my project template at: https://github.com/pwittchen/java-gradle-template
If you want to compile project, run the following command: ./gradlew clean build
If you want to start tests, run the following command: ./gradlew test
Actually build command will run tests as well.
If you want to run application, use the following command: ./gradlew run.
You can also run application, tests or start compilation from the IntelliJ IDEA IDE.

I hope, you will find that template useful and handy.

Square is advocating against Android fragments

2014-10-12 Android No comments

Recently, Square engineers confirmed my doubts I always had about fragments. I definitely knew that something was wrong with them, but Google introduced fragments into Android API, so I thought it must be okay for some reason and I tried to live with them feeling pain. Finally, concrete company have written an article criticizing Android Fragments and I totally agree with them. Read the article at:
http://corner.squareup.com/2014/10/advocating-against-android-fragments.html.