Leap Motion: Try the Diagnostic Visualizer

Leap Motion: Try the Diagnostic Visualizer

With the integrated Diagnostic Visualizer it is easy to test all the features that the leap motion platform is offering. This application is included when you install the Leap Motion software. If you want to open this application yourself, then just follow the steps below.

1. Open the settings

Leap Motion options

2. Open the visualizer

In the Settings, go to the “Troubleshooting”-Tab and there is a button called “Diagnostic Visualizer”, which opens the Visualizer:Leap Motion settings-dialog

3. Try out some of the following commands

  • “j” –  for the cool looking visualisation, as shown in the screenshot on the top of this post
  • “y” – for better looking paths
  • “t” – to show the tracked fingers

Leap Motion: Try the Diagnostic Visualizer

Screen Shot 2014-01-18 at 16.57.25

With the integrated Diagnostic Visualizer it is easy to test all the features that the leap motion platform is offering. This application is included when you install the Leap Motion software. If you want to open this application yourself, then just follow the steps below: Screen Shot 2014-01-18 at 16.47.33In the Settings, go to the “Troubleshooting”-Tab and there is a button called “Diagnostic Visualizer”, which opens the Visualizer: Screen Shot 2014-01-18 at 16.49.54Try out some of the following commands:

  • “j” –  for the cool looking visualisation, as shown in the screenshot on the top of this post
  • “y” – for better looking paths
  • “t” – to show the tracked fingers

 

Leap Motion: Visualize vertical hand movement

Leap Motion: Visualize vertical hand movement

I finally had a bit of time to continue my work with the Leap Motion Framework. My goal this time is to visualize the positions and movements of the hands. To achieve this, I had to decide on a framework that I want to use for the application. I ended up with choosing the Swing-Framework, because it’s easy to draw figures on a canvas and I don’t need to care about platform specific things.

I then roughly wrote down some points I wanted to implement.

  • Display the actual distance between the controller and the hand
  • Display the amount of visible fingers of each hand
  • Either display 1  or 2 hands (according on how many are over the controller)
  • Display the vertical value of the y-axis for each hand
  • Handle a disconnected Leap Motion device correctly

Implementation

screenshot of the coordinate the fingers applicationThere are a few ways to get the relevant position data from the hands. For the application I decided to use the following line:

hand.palmPosition()

This returns a vector which has the values of the palm. Another possibility would be to use stabilizedPalmPosition(). The difference between the vectors of those two methods, is shown here:

palmPosition(): (10.4119, 252.632, 262.645)
stabilizedPalmPosition(): (18.7797, 247.261, 262.403)

The official API documentation described the difference to the normal palmPosition() as below:

Smoothing and stabilization is performed in order to make this value more suitable for interaction with 2D content. The stabilized position lags behind the palm position by a variable amount, depending primarily on the speed of movement. – Leap Motion API Documentation

This means, that for applications where the performance of the UI and the speed of the hands is very important, you better use the normal palmPosition(). But when it comes to accuracy of the data the usage of stabilizedPalmPosition() is recommended.

Vector(x, y, z)
x – Corresponds to the left to right dimension of the Leap Motion controller.
y – Corresponds to height above the device.
z – Corresponds to the front-back dimension of the Leap Motion controller.
Coordinate the fingers

The application is quite quick and very accurate with drawing the heights of the hands. It also displays the y-position and the amount of fingers the sensor recognizes. When the Leap Motion controller is connected correctly, then a green light shows up in the bottom right corner.

The next step for me is to work with the other two axes in another application. You can find the code for this application on GitHub. Keep in mind, that if you want to run it, you need to set up a Leap Motion project first. See this post for more information: Set up a Leap Motion project

Link to the GitHub project: https://github.com/mrwonderman/leap-motion-basics

Unity: How to tag a camera

I just continued my work with the Unity-Framework and run into a basic beginner mistake. I wanted to get the transform values of my camera. So I tried the following lines of code:

Camera cam = Camera.main;
GameObject gameobj = (GameObject)Instantiate(baseobject, cam.transform.position + cam.transform.forward, cam.transform.rotation);

But this gave me the following error message:

NullReferenceException
UnityEngine.Component.get_transform ()

So I then figured out that I need to tag my camera as my MainCamera when I want to use Camera.main. To do such a tag you need to open your camera in the Inspector. Right under the name field is a small dropdown-menu called Tag. There you can set your desired tag for your camera:

Screen Shot 2014-01-18 at 16.22.10

Link: http://answers.unity3d.com/questions/63221/how-to-set-main-camera.html

Android: Disable/Lock NavigationDrawer

I just had the situation where I wanted to disable the NavigationDrawer from within a fragment. So the user is forced to do something and can’t switch to another view. I did a bit of research and found the following method in the android api docs:

drawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED);

Now the NavigationDrawer is locked. Of course there is another LockMode that you can set to unlock the NavigatioDrawer again:

DrawerLayout.LOCK_MODE_UNLOCKED

android-square-progressbar v.1.3.0

android-square-progressbar v.1.3.0

After my second holidays this year I’m finally publishing the next major version of the android-square-progressbar. This includes some new stylish effects to the library and fixes a few bugs which appeared. Thanks again for the feedback guys.

Start-/Outline

android_square_progress_startlineandroid_square_progress_outline

I added 2 more or less small tweaks for the image border, but they give an additional nice look. You can simply add them to your android-square-progressbar with the following commands:

squareProgressBar.drawStartline(true);
squareProgressBar.drawOutline(true);

Show percent

second_style

This is one of the features I was looking forward to implement. So I decided to put a bit of more effort into it, and I came up with the following usage:

There is a new object called PercentStyle which has 3 attributes:

  • Text align
  • Text size
  • Display percentsign

You can easily assign different styles to the square-progressbar. This is how you can do it:

squareProgressBar.setPercentStyle(new PercentStyle(Align.CENTER, 76, true));
squareProgressBar.showProgress(true);

In the example application I implemented a new dialog where you can play around with different combinations:

dialog_style

Opacity-Bugfix

A bug appeared while using the library and the opacity option (added with the version 1.2.0). If you didn’t set the opacity to false, there would be a NullPointerException. This is now fixed with this version.

You can find the newest code on GitHub here: https://github.com/mrwonderman/android-square-progressbar

There should be an updated example application on Google Play in the next few minutes: https://play.google.com/store/apps/details?id=net.yscs.android.square_progressbar_example

For questions and/or feedback, just drop me a line via email: yannick@signer.pro

Leap Motion: The first application

Finally I got my Leap Motion sensor today. I waited like ever for this little magical device. If you don’t know it, then check out the following video:

The package contains 2 USB cables (two different sizes), an information guide and the motion leap controller.

You can install the software and try some of the applications from Airspace, which all work pretty nice. But the most interesting part is of course the SDK. You can download the Java SDK here: https://developer.leapmotion.com/documentation/Languages/Java/Guides/Leap_Frames.html

It is quite easy to create a java project with the right libraries and start writing code. You can find more information about that here: https://developer.leapmotion.com/documentation/Languages/Java/Guides/Setup_Java.html

My first simple Java program simply counts the amount of fingers and hands the sensor detects. You can find the code on GitHub here: https://github.com/mrwonderman/leap-motion-basics. The result in the console looks like that and works quite well.

android: database in 5 minutes

I’m working on an application where I need to save and read data fast and uncomplicated. As I always have had problems with databases and so on. This time I first tried a combination of Gson(https://code.google.com/p/google-gson/) and a file in the filesystem. But this was complicated and I had the problem that the file got removed after a special amount of time.

I then came along sugar (https://github.com/satyan/sugar & http://satyan.github.io/sugar/). And this is the solution for all basic database-problems you will ever have and it only needs 5 minutes to integrate.

1. Get the sugar library and include it into your project

Screen Shot 2013-09-08 at 09.27.45

 

2. Extend your Object:

public class GraphValue extends SugarRecord<GraphValue>

3. Modify the AndroidManifest.xml
I modified the application tag as shown below. You kinda need to set the android:name=”com.orm.SugarApp”.

<application
android:name="com.orm.SugarApp"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@android:style/Theme.Holo.Light" >
<meta-data
android:name="DATABASE"
android:value="graph_values.db" />
<meta-data
android:name="VERSION"
android:value="2" />
<meta-data
android:name="QUERY_LOG"
android:value="true" />
<meta-data
android:name="DOMAIN_PACKAGE_NAME"
android:value="your.package.name" />
<!--  your <activity> stuff comes here -->
</application>

4. Save data

You now can simply call  save() on the object you want to save onto the database.

graphValue.save();

5. Read data

If you want to read all values from a table you can do this in one line:

List<GraphValue> allValues = GraphValue.listAll(GraphValue.class);

When you want to specify which data you want to have, then you can use the following code:

GraphValue.find(GraphValue.class, "name = ?", editText.getText().toString())

Here name reffers to the name I gave the variable in the Object class.

6. That’s it.

It took me like 5 minutes to integrate this for the first time, because it’s really very easy, but limited. I had problems to store a Date. The workaround for this is to save it as a String, but I guess for simple data storing this is alright. Have fun with the library :).

android: java.lang.IllegalStateException: The specified child already has a parent.

I had quite a problem with fragments and the FragmentManager recently. The problem was the following stacktrace, which came when I tried to launch the application:

08-29 18:10:19.761: E/AndroidRuntime(17159): java.lang.RuntimeException: Unable to start activity ComponentInfo{packagename.MainActivity}: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2247)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2297)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread.access$700(ActivityThread.java:152)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1282)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.os.Handler.dispatchMessage(Handler.java:99)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.os.Looper.loop(Looper.java:137)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread.main(ActivityThread.java:5328)

08-29 18:10:19.761: E/AndroidRuntime(17159): at java.lang.reflect.Method.invokeNative(Native Method)

08-29 18:10:19.761: E/AndroidRuntime(17159): at java.lang.reflect.Method.invoke(Method.java:511)

08-29 18:10:19.761: E/AndroidRuntime(17159): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1102)

08-29 18:10:19.761: E/AndroidRuntime(17159): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:869)

08-29 18:10:19.761: E/AndroidRuntime(17159): at dalvik.system.NativeStart.main(Native Method)

08-29 18:10:19.761: E/AndroidRuntime(17159): Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addViewInner(ViewGroup.java:3435)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(ViewGroup.java:3306)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(ViewGroup.java:3251)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.view.ViewGroup.addView(ViewGroup.java:3227)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:914)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.FragmentManagerImpl.moveToState(FragmentManager.java:1075)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.BackStackRecord.run(BackStackRecord.java:682)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:1455)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.Activity.performStart(Activity.java:5259)

08-29 18:10:19.761: E/AndroidRuntime(17159): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2220)

08-29 18:10:19.761: E/AndroidRuntime(17159): ... 11 more

The problem was the Fragment itself. You actually need to use a different constructor for the inflate method. I forgot to set attachToRoot to “false”, this should fix the problem:

View view = inflater.inflate(R.layout.fragment_graph, container, false);

various android ui things

20130817_120219

I just finished a small android project this morning. Yesterday evening I came across the code of someone on GitHub who had built a small duel game about Harry Potter. This was java application and you can play this in the console. So I then forked the repo and created the android application for it. You can find my project here: https://github.com/mrwonderman/Harry-Potter-Duel

The application is completely playable but I won’t publish the application to the play store as the game code isn’t from myself. But feel free to check the code out and try it yourself.

Now I learned some nice small things while writing the application. For example, you can append text to a TextView with the following command. So you don’t need to get and set the text manually.

textView.append("yay !");

Another thing is, how to make a TextView scrollable. I added the following lines to the xml layout of the TextView:

android:scrollbars="vertical"

android:singleLine="false"

and in the java code you need to use the following line:

textView.setMovementMethod(ScrollingMovementMethod.getInstance());

To display a Progressbar from right to left is very easy. Just use the following code:

progressBar.setRotation(180);

This then can look like that:

progressbarRTL