Month: January 2015

Introducing NetworkEvents

2015-01-31 Android No comments

I have released NetworkEvents library for Android. It’s a wrapper for system Broadcast Receivers built with Otto library. It allows you to listen change of connectivity status (connected to WiFi network with or without Internet access, mobile network, off-line) and change of the WiFi signal strength very easily with @Subscribe annotation. The only thing you need to do, is to create Bus and NetworkEvents objects, register them in onResume() method and unregister them in onPause() method in your activity. After that, you can subscribe for the events you want to listen. Of course, remember to give your app appropriate permissions in AndroidManifest.xml file.

In contrast to Broadcast Receivers available in Android SDK, NetworkEvents sends only one event per one occurrence of this event. Android Broadcast Receivers have a bug, which causes sending multiple Intents even if only one event occurred. This behavior may vary on different devices. Regardless of this fact, this bug was handled by NetworkEvents and you shouldn’t encounter that problem while using this library.

Important facts:

  • Minimum Android SDK version required by the library is API 9 (Android 2.3 – GINGERBREAD) or above.
  • Latest version of the library is 1.0.1.
  • Library is available in Maven Central Repository and you can depend on it in your project via Maven or Gradle.
  • Project is open source and available on GitHub.
  • Library has Apache 2.0 License.

For more details, usage and download instructions, visit website of the project at https://github.com/pwittchen/NetworkEvents.

Feel free to fork it! If you found any bug or have an idea for improvements, don’t hesitate and create an issue or pull request.

Android Resource Converter

2015-01-17 Android, Python No comments

In international projects sometimes there’s a need to send resource files to the client in order to have translated strings. Client doesn’t have to understand XML notation and editing two or more files at the same time is inconvenient. It’s easier to send file which can be edited in MS Excel or Libre Office Calc.

I’ve created Python scripts, which are able to convert Android xml resources with translations to a single *.csv file ready to open in software for common users. In addition, there’s another script, which can generate xml resource files with translations from *.csv file.

Generating *.csv file from resources is easy:
$ python xml2csv.py directory_with_resources

Exemplary output looks as follows:

key;strings_english.xml;strings_polish.xml
hello_world;Hello World!;Witaj Świecie!
app_name;My application;Moja aplikacja

Generating resources from file with translations is easy as well:
$ python csv2xml.py translations.csv

As an output we will get *.xml files containing resources for translations in Android application.

Check out repository here: https://github.com/pwittchen/android-resource-converter

Kirai – flavored Android string formatting library

2015-01-13 Android No comments

Overview

Recently I’ve developed and realased to Maven Central Repository Kirai, which is flavored Android string formatting library. Kirai means phrase in Swahili language. Project is inspired by phrase, TaggerString and BabushkaText. Kirai has fluent API similar to phrase with additional formatting similar to TaggerString and allows to add formatted pieces of text like BabushkaText. Development including writing Unit Tests took me about 2 days. Deployment and release to Maven Central Repository took me about 2 days as well. It was my first deployment, so it wasn’t so easy, but people from Sonatype are helpful, problems were solved very quickly and release went quite smooth.

Usage

Usage of the library is quite simple:

Download

You can depend on this library through Maven:

or through Gradle:

Open-source

Library is open-source and available on GitHub at: https://github.com/pwittchen/kirai/
If you want to know more about library, check GitHub website of the project.
Feel free to use it or fork it!

Interpreting data in *.csv files generated by EEG Analyzer

2015-01-06 Analysis, Brain Computer Interface 4 comments

Introduction

Sometimes people send me e-mails concerning EEG Analyzer app. Usually they are not sure how to interpret or analyze results generated by the app and uploaded to Dropbox server. My app is quite “raw” and simple, because it is additional project created during writing my Master Thesis, which helped me to perform some experiments and analysis of EEG data. That’s why I didn’t focused on generating reports from gathered data. I focused only on reading and gathering data from MindWave Mobile device. In this article I’ll show you how to interpret data generated by EEG Analyzer and draw simple plots showing change of attention level, meditation level and blink strength.

Step #1 – download and install LibreOffice Calc

LibreOffice Calc is free software similar to MS Office. Currently, I’m using Linux, so I’ve chosen this tool, but if you are using MS Windows, you can perform similar operations in MS Office and MS Excel.

Step #2 – gather EEG and eye blinking data

Download EEG Analyzer app to your mobile device, connect it with MindWave, go to the settings and enable “Save EEG and eye blinking data” option. After that, go back to the main screen. Wait for some time and let the app record your EEG data. Next, go to the Settings screen again. You should see that “Number of the signals saved on the device” is greater than zero, so your data was recorded. Click button “Export data to Dropbox”. After that, you should see a message informing you that data was exported successfully.

Step #3 – access gathered and uploaded data

Go to your Dropbox directory on your disk or Dropbox website. Next, go to the “EEG_Analyzer” directory. You should see files containing your exported signals in that directory. Names of the files should look like that: egg_analyzer_data_20140830_183410.csv. First section with the numbers represents date. 20140830 means 30th of August 2014. Second section represents time. 183410 means 18:34, 10 sec. (6:34 PM, 10 sec.)
When you open this file in a text editor, you should see something like in table below.

See raw *.csv file here.

Values on the top describes contents of the columns. _id is id of the record in SQLite database table on the device, type represents type of the signal (4 – attention, 5 – meditation, 22 – blink strength), level represents attention level (from 0 to 100), meditation level (from 0 to 100) or blink strength (I don’t know maximum value, but it’s always positive integer value), milliseconds represents Unix Timestamp in milliseconds. We can extract date and time in many ways. E.g. using website currentmillis.com or by writing our own script, software or formula in spreadsheet software like LibreOffice or MS Excel.

Step #4 – open exported file in LibreOffice Calc and draw plots

Below, you can follow the steps, which allow you to analyze EEG data and generate plots presenting change of attention level, meditation level and blink strength in time. I am using Polish version of the Ubuntu and LibreOffice, but you can find the same options in your language in the same places.

Step #4.1 – open *.csv file with LibreOffice Calc

eeg_librecalc_tut_01

Step #4.2 – import data

eeg_librecalc_tut_02

Step #4.3 – display data

When you confirm importing of the data, you should see data in LibreOffice Calc.

eeg_librecalc_tut_03

Step #4.4 – add data auto-filter

Mark “type” column and from menu choose “Data” » “Filter” » “Auto”.

eeg_librecalc_tut_04

Step #4.5 – apply filter

After adding filter, you should see little arrow in the “type” column. When you click on the arrow you can filter all signals representing attention by choosing type = 4 and “unchecking” other types.

eeg_librecalc_tut_05

When you click “OK”, you should see only “attention” signals.

eeg_librecalc_tut_06

Step #4.6 – draw the chart

Choose option “Insert” » “Object” » “Chart (Plot)”

eeg_librecalc_tut_07

Or click on the icon:

eeg_librecalc_tut_08

Define initial plot parameters:

eeg_librecalc_tut_09

Click “Next” to see “Range of data”. Don’t do anything and click “Next” again. Click “Add” below “Data series” field.

eeg_librecalc_tut_10

Click “choose data range for Y values” and mark values in the “level” column.

eeg_librecalc_tut_11

Afterwards, you can click “Next” and adjust Chart parameters.

eeg_librecalc_tut_12

Click “Finish” and your chart is ready.

eeg_librecalc_tut_13

You can draw plots of change of meditation level and eye blink strength in time in the same way by filtering other signals.
I hope this tutorial is useful for you and clears up doubts connected with data generated by EEG Analyzer. In addition it shows simple way of generating plot of the attention level change in time what can be useful for displaying EEG data in a graphical way.