Thursday, 23 December 2010

Custom Timer for Android OS (with Cross Thread Messaging to Handle the UI updates )

Code below shows MyTimer class which implements the Runnable interface in order to be run as an individual thread. This class also supports MyTimerListener to inform the classes which are registered to this class, onTick event.

MyTimerClass

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class MyTimer implements Runnable {

long interval;
List<MyTimerListener> l = new ArrayList<MyTimerListener>();
@Override
public void run() {
while(true)
{
try {
Thread.sleep(interval);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Iterator<MyTimerListener> it = l.iterator();
while(it.hasNext())
{
((MyTimerListener)it.next()).onTick();
}
}

}
MyTimer(long Interval)
{
interval=Interval;
}
public void addListener(MyTimerListener mtl)
{
if(!l.contains(mtl))
l.add(mtl);
}
public void removeListener(MyTimerListener mtl)
{
if(l.contains(mtl))
l.remove(mtl);
}
public void start()
{
Thread t = new Thread(this);
t.start();
}

}



MyTimerListerner interface responsible for handling the onTick event.


public interface MyTimerListener {
void onTick();
}



Implementation of MyTimer


android.os.Handler;

public class AttachedClass implements MyTimerListener {

private MyTimer mt = new MyTimer(1);
private Handler mHandler = new Handler();// Main thread attaaches this handler itself while it creates the instance of AttachedClass instance
public void startAttachedClass()
{
mt.start();// start method creates a new thread and runs mt in it.
}
@Override
public void onTick() {
Runnable r = new Runnable() {
public void run() {
TextView1.setText("Text has setted");
}
};
mHandler.post(r);// onTick event called by new thread which has been created in mt.start(). but TextView1 belonges to the main thread. In order to make handled setText method by new thread, Handler's post method has used which requires a Runnable(method) which will be run in main thread.

}
}
}


You can leave your questions to the comment section. Than you..

Monday, 20 December 2010

Android TranslateAnimation sucks!

I really searched a lot on getting animated object's current location on the screen during the translate animation but I just found an android forum complaint title on it. And an Android officer was saying that It is not available to get this info during the animation and it could be added in the newer versions of android sdk. But this sucks and an important lack if you are developing a game in 2D. Animations are important and there are just 3 event listeners in IAnimationListener which listens 3 events of the animation; Start, End, Repeat. What about the during? I want to gather the info about my object which has being effected. Therefore, there is just 1 way for me, I will develop my own animation class rather to use TranslateAnimation. I will share it from here shortly.

Wednesday, 8 December 2010

Damn developer.android.com is not working

The is the second time in last 3 days I am trying to connect to the Android Developer website (developer.android.com) and it is not responding again. It is a massive shame to Google. I hated it damnn!! the the worst is because of the Android Developer website is so good, there is no alternative answers to Android problems in anonymous website in the internet.

Edit: It has been Turkish Telecom's fault some wrong google IPs are stille banned because of Youtube Ban in Turkey. Grghhhhhhh....

Monday, 15 November 2010

My Windows Phone 7 Application: Ringring

My very first WP7 application, I have developed an alarm clock it is my custom design :). I also designed my custom slider control which cannot be found anywhere. This application is for understanding WP7 application development I will come with new ones in the upcoming days.

Wednesday, 6 October 2010

Windows Phone 7 Speech Recognition helps to improve your American English accent

I have just downloaded and started to develop applications for WP7 for a few days. My first impression is Silverlight + XNA rocks for the game developers. It is obvious that Microsoft aims to hit mobile game and entertainment market with its new product. I am developing my very first WP7 application at the moment and I will share its screenshots in later days.

One last thing about WP7 is speech recognition which is really fun :)). You need to speak proper american english though otherwise you say 'banana' and it gets it as 'hanna' . Anyway, it is a way to test your accent for free right?
We will see the MS's achievements in next few months but I really like this product as a Silverlight and .Net Developer.

Monday, 27 September 2010

I like this way too


Extended desktops, yeah!

Quick tips: What is devenv.exe?

devenv.exe is the starter program for Visual Studio family IDEs which can be used for adding rules to starting of the Visual Studio or opening a new instance of Visual Studio automatically. It can be called from the command line (cmd.exe) with the parameters which are used for handling the start up of new Visual Studio instance. You can find the devenv.exe's user manual in the link below

http://www.cmake.org/pipermail/cmake/2006-July/010015.html