Posts Tagged ‘Java’
These posts contain code written in Java or are somehow related to Java.
Android: Loading files from the Assets and Raw folders
Posted by Dimitri | Filed under Programming
This tutorial will explain how to load files from the res/raw and the Assets folder using a String to specify the file name. Yes, there are a lot of tutorials on this subject, but they all use the automatically generated integer IDs from the R class as inputs and not many of them even mention the possibility of loading files from the Assets folder. As a result of depending on the ID, the file reference must be known beforehand.
Instead, the code featured in this post will explain how to find the reference to the file and then load it at runtime based solely on its name. This means that the reference ID and the file don’t even have to exist in the first place, and can be acquired at run time.
Android: Acessing the gyroscope sensor for simple applications
Posted by Dimitri | Filed under Programming
This post explains how to get values from the gyroscope (or any sensor that returns the device’s relative angle) to create simple application. The reason why I’m stating ‘for simple applications’ is because the code featured here is already deprecated. I’m just explaining how to do it because it still works, and it’s very clean and short to explain, as opposed to the new method, which is much more accurate but more complex to implement.
Still, it’s possible to use it for simple applications, although, if the application requires accuracy from the sensors, such as augmented reality applications or even games, it’s recommended to use the getRotationMatrix() method from the Sensor Manger class instead.
With that said, the following code just prints the rotation values from the gyroscope on the screen: (more…)
Android: changing the screen brightness
Posted by Dimitri | Filed under Programming
This post will explain how to change the current system brightness with a seek bar GUI on Android devices. The code here featured only works on real devices, because it is not possible to see brightness changes on the emulator. Also, all the code explained here is available for download at the end of this post.
The first thing one must know is that Android system brightness value is applied to the screen’s backlight only when the screen turns on. This means that only after a boot up or awaking the phone from a sleeping state will make the screen as bright as the value defined by the System.SCREEN_BRIGHTNESS variable. Consequently, changing only that variable won’t be enough to preview the brightness level.
Android: Changing the animation between Activities
Posted by Dimitri | Filed under Programming
This post features how to change Android’s default animation when switching between Activities. Before reading the rest, please know that the code that changes the standard animation be found at the API Demo that comes with the Android SDK. But since there’s a lack of proper documentation regarding this subject and it’s difficult to find a place explaining it, here is a post that helps in aiding these two problems.
So, the code to change the animation between two Activities is very simple: just call the overridePendingTransition() from the current Activity, after starting a new Intent. This method is available from Android version 2.0 (API level 5), and it takes two parameters, that are used to define the enter and exit animations of your current Activity. Here’s an example: (more…)
Game Programming Basics: Creating a FPS counter
Posted by Dimitri | Filed under Programming
Sometimes, while creating a game, a programmer realizes that he/she needs to make sure if some part of the code is running fast enough, before adding more things that could cause the game to slowdown. To properly measure a game’s performance, there is the need to program a FPS (frames per second) counter. As the name suggests, it will count the number of frames that where rendered at the period of one second.
This is an essential information when creating games, as it will serve as a strong indicator to measure the performance impact of a recently added element to the game.