Archive for January, 2009

Updating UI items from multiple threads

So I recently found out that only one thread is ever allowed to update things like ImageViews and whatnot. If you try to make another thread update them, everything breaks, and all of a sudden, that ImageView never ever updates again. This was causing trouble in RemoteDroid because I wanted the tap to click to update the on-screen button state, but the tap events had to come from a Timer object, which put everything in a different thread.

Anyway, if you need to make a graphical change from another thread, the solution is to use the Handler class. The you use it is by creating a handler in your UI thread, then create some Runnable objects that call all your graphics methods. Here’s an example:

public class Thing extends Activity {
        private Handler = new Handler();
        // runnables for updating state
        private runnable buttonOn = new Runnable() {
                private void run() {
                        drawImageOn();
                }
        };
        private runnable buttonOff = new Runnable() {
                private void run() {
                        drawImageOff();
                }
        };
        // our ImageView
        private ImageView iv;
        // a Timer object, which creates another thread for doing something else
        private Timer timer = new Timer();

        public void onCreate(Bundle savedInstanceState) {
                // set ref to ImageView
                this.iv = (ImageView)this.findViewById(R.id.whatever);
                //
                this.handler.post(this.buttonOn);
                // Let's start up another thread for whatever reason
                this.timer.scheduleAtFixedRate(new TimerTask() {
                        public void run() {
                                // If we tried to call drawImageOff() here directly, something would break.
                                handler.post(buttonOff);
                        }
                }, 0, 500);
        }

        // drawing methods

        public void drawImageOn() {
                // draw in our ImageView here
                ...
        }

        public void drawImageOff() {
                // draw in our ImageView here
                ...
        }
}

So basically, you’re setting up a few Runnables for changing graphical state, and then making every thread use the Handler for changing between those states.

Comments off

Windows 7 support?

Recently spotted on Twitter: a RemoteDroid user’s report that I believe was about the server app working fine on Windows 7, which is still in beta. The tweet was in German, so I’m guessing to some degree on the meaning. But if anyone out there has RemoteDroid up and running on Windows 7 — and can post a comment or drop me a line in English to confirm — that would be great, thanks.

Comments off

Version 1.2 available now

Hi, Josh’s web site co-collaborator here to let you know about the latest version of RemoteDroid, released today. A number of new features were added, many in response to user feedback:

  • Tap to click
    The onscreen touchpad is now clickable: tap once for a single click, twice for a double click, and tap and hold to select text or click-and-drag.
  • Trackball scroll wheel
    Clicking on the scroll wheel toggles it from a mouse controller to a scroll wheel. Click again to toggle it back.
  • Customizable mouse sensitivity
    New user preferences menu lets you set the sensitivity of your mouse and tap speed.
  • Saved IP address
    You no longer have to enter your IP address every time you launch the application. RemoteDroid saves the IP address of your last network used — just tap on “Connect” to begin.

The Preferences menu, mentioned above, also lets you choose which new features you want to globally turn on or off, such as tap to click or using your trackball as a scroll wheel.

The new version of RemoteDroid has been tested with computers running Mac OS (Tiger, Leopard), Windows (XP, Vista) and Linux. However, there will inevitably be certain operating system and computer configuration combos that will, for one reason or another, work less than perfectly. If you’ve read the Support page and have ruled out all of the possible reasons for the app not working listed there, you can report an issue using the contact form.

As always, the phone app is available in the Android Marketplace. And make sure you also have the latest version (1.2) of the server app, available here.

Comments off

Loading images from jar files in windows

In the first version of the server app, I was telling Windows users to start the program by clicking on a .bat file because for some reason, the thing wasn’t starting up when clicking on the .jar file directly.

I’d seen other apps that did start from the jar file just fine, and after a lot of hunting around, I figured out why. When you search google for load image from jar file, most of the hits have you getting a URL object like this:

URL url = this.getClass().getResource("the_image.jpg");

then using that to load the actual image.

This works just fine on OSX, and Linux, but does absolutely nothing on Windows for some reason. Instead, on Windows, you have to get a JarFile object for the jar you’re loading from, then get a ZipEntry (JarEntry, whatever) from that, then get an InputStream from the ZipEntry, turn that into a BufferedInputStream, then pass that off to your default Toolkit to turn into an image.

Of course this means you have to figure out whether the app’s being run in a jar file in the first place or not. This is how I’m doing it:

URL fileURL = this.getClass().getProtectionDomain().getCodeSource().getLocation();
String sBase = fileURL.toString();
if ("jar".equals(sBase.substring(sBase.length()-3, sBase.length()))) {
	MyClass.jar = new JarFile(new File(fileURL.toURI()));
}

after that, you can load the image ike this:

Image imReturn = null;
try {
	if (jar == null) {
		// This is used if you're not loading from a jar
		imReturn = this.toolkit.createImage(this.getClass().getClassLoader().getResource(sImage));
	} else {
		//
		BufferedInputStream bis = new BufferedInputStream(jar.getInputStream(jar.getEntry(sImage)));
		ByteArrayOutputStream buffer=new ByteArrayOutputStream(4096);
		int b;
		while((b=bis.read())!=-1) {
			buffer.write(b);
		}
		byte[] imageBuffer=buffer.toByteArray();
		imReturn = this.toolkit.createImage(imageBuffer);
		bis.close();
		buffer.close();
	}
} catch (IOException ex) {

}
return imReturn;

Comments off

Slot Depo 5k yang Memberikan Fleksibilitas dalam Bermain

Banyak pemain kini mencari permainan yang memungkinkan mereka untuk bermain dengan deposit yang terjangkau. Slot Depo 5k menawarkan fleksibilitas ini, membuatnya menjadi pilihan yang populer di kalangan berbagai pemain. Dengan modal yang kecil, Anda dapat menikmati berbagai permainan dan peluang menang yang menarik.

Pentingnya memilih slot dengan RTP slot gacor tertinggi hari ini tidak bisa diabaikan jika pemain ingin mendapatkan hasil terbaik dalam permainan slot online. Dengan memantau RTP live, pemain bisa mengetahui slot mana yang memberikan peluang menang terbaik berdasarkan persentase pembayaran yang aktual. Slot gacor hari ini sering kali menawarkan RTP tinggi, memberikan pemain lebih banyak kesempatan untuk meraih kemenangan besar. RTP slot adalah alat penting bagi pemain yang ingin bermain dengan strategi dan meningkatkan potensi keuntungan mereka.

Mahjong Slot membawa keseruan permainan tradisional ke dalam dunia slot online, memberikan pengalaman yang luar biasa. Fitur Scatter Hitam dalam permainan ini memberi peluang untuk mendapatkan putaran gratis, yang sangat menguntungkan bagi pemain. Pemain yang memilih Mahjong Ways akan melihat simbol-simbol Mahjong bergabung untuk menciptakan berbagai cara untuk menang. Mahjong Ways 2 mengusung konsep yang lebih modern dan inovatif, memperkenalkan fitur-fitur yang dapat membawa kemenangan lebih besar.

Meningkatkan Peluang Menang dengan Menganalisis Statistik Togel dari Situs Togel Terpercaya

Pemain togel yang bijak selalu mencari cara untuk meningkatkan peluang menang mereka. Salah satu cara yang bisa Anda lakukan adalah dengan menganalisis statistik togel yang disediakan oleh situs togel terpercaya. Banyak daftar akun togel resmi menawarkan data yang dapat membantu Anda membuat keputusan yang lebih baik dalam memilih angka. Gunakan informasi ini untuk meningkatkan peluang Anda untuk menang dan rasakan sensasi bermain yang lebih mengasyikkan. Tidak hanya itu, bandar togel yang terpercaya juga sering memberikan tips dan trik untuk membantu pemain meningkatkan skill mereka.

Kejujuran adalah hal utama dalam Toto Macau, itulah mengapa Live Draw Macau selalu disiarkan secara terbuka. Keluaran Macau diumumkan dengan sistem yang fair, memastikan setiap angka yang muncul benar-benar hasil undian asli. Result Macau juga bisa langsung dicek oleh semua pemain, memberikan rasa percaya diri dalam bermain. Dengan sistem yang transparan ini, Anda bisa fokus dalam menikmati permainan dan berburu jackpot besar!

Bermain toto semakin menarik dengan adanya berbagai pilihan pasaran yang bisa dijelajahi. Setiap pasaran memiliki karakteristik tersendiri yang memberikan pengalaman bermain yang berbeda. Pemain bisa memilih pasaran yang paling sesuai dengan strategi dan gaya permainan mereka. Dengan banyaknya opsi yang tersedia, permainan menjadi lebih fleksibel dan tidak terbatas pada satu pilihan saja. Hal ini membuat pemain selalu penasaran untuk mencoba dan mencari peluang terbaik mereka.

Pelayanan Customer Service Situs Toto Slot yang Ramah dan Responsif

Situs toto terbaik selalu mengutamakan pelayanan pelanggan yang cepat dan responsif dalam membantu setiap pemain. Tim customer service yang profesional siap memberikan solusi untuk setiap kendala yang dialami pemain kapan saja. Toto slot semakin menarik dimainkan karena ada dukungan layanan yang siap membantu 24 jam nonstop. Situs toto terpercaya selalu menyediakan berbagai kanal komunikasi agar pemain bisa lebih mudah menghubungi tim support. Dengan pelayanan terbaik, pemain merasa lebih nyaman dan percaya diri dalam bermain.

Slot777, Pilihan Terbaik untuk Menang dengan Slot Gacor yang Menguntungkan

Bermain di Slot777 memberikan peluang besar untuk meraih kemenangan dengan bermain Slot Gacor yang sangat menguntungkan. Dengan RTP tinggi yang dimiliki, setiap putaran memberikan kesempatan lebih besar untuk meraih jackpot. Situs slot gacor juga menawarkan berbagai jenis permainan yang seru dan menarik, memberikan pengalaman bermain yang menyenangkan. Bonus yang melimpah semakin membuat kemenangan terasa lebih berarti. Permainan togel online yang tersedia juga menambah variasi permainan yang bisa dimainkan, menjadikan Slot777 semakin lengkap dan menarik.

Related Links

Resource Links