Running WinXP Pro in a Virtual Machine under Ubuntu
I like running Ubuntu but there are certain Windows applications that I cannot do without. Dual booting works but it is not so convenient. So operating Win XP in a virtual machine under Linux seemed worth the try. The main apllication I am interested in is Quicken. I tried installing Quicken under WINE but had problems. Perhaps someday my version of Quicken will work under WINE, but until then, VMware seems to work well. Running Quicken under VMware is noticeably slower but not annoying so. There seem to be many ways to increase performance. Installation was a little tedious but it is working. I decided to benchmark Win XP in VMware and compare performance to Win XP running on its own partition. In this way I have a method of measuring performance as I try out some 'improvements'.
My Setup
HOST: Ubuntu 8.10 Kernel 2.6.27-7-generic GNOME 2.24.1
GUEST: WinXP Pro with SP3
VMware 2.5.0 build-122581
Gigabyte MoBo GA-G31M-ES2L
Intel(R) Core(TM)2 Duo CPU E4500 @ 2.20GHz
GeForce FX 5200 with Dual Monitors each 1440x900
4096 MB System RAM
My Installation
At first I tried VMware Player but I had troubles. After Googling the problem, I found that more people had success using VM Server 2. The VM Server 2 tar can be dowloaded from vmware.com. For installation I found the following 3 resources very helpful.
Ubuntu Documentation VMwareServer
How To Install VMware Server 2 On Ubuntu 8.10 from HOWtoForge
VMware Server Manual
Benchmarks
I used Novabench2 to benchmark Win XP. I tried runing this benchmark under WINE, but unfortunately I could not get it to operate correctly. There are many choices for benchmarking but sometimes you have give up searching and use what works and move on. If anyone knows of a benchmark that runs under WINE, let me know. The chart below summarizes the results. As expected when Win XP is the booted operating system the results are better.
| VMware | Win XP Pro SP3 | % Difference | |
| Overall NovaBench Score | 193 | 255 | -24.3 |
| System Memory (Gb) | 2 | 4 | -50.0 |
| System RAM R/W | 81 | 112 | -27.7 |
| Overall CPU Test | 81 | 97 | -16.5 |
| Floating Point (Operations/sec) | 41421115 | 39840496 | +4.0 |
| Integer (Operations/sec) | 16879727 | 30175040 | -44.1 |
| MD5 Hashes (Gerenerated/sec) | 23232 | 60628 | -61.7 |
| Overall Graphic Test | 25 | 18 | +38.9 |
| Random Lines (Drawn/sec) | 8973 | 9355 | -4.1 |
| Random Shapes (Drawn/sec) | 6766 | 2250 | +200.7 |
| Overall Hardware Test | 6 | 28 | -78.6 |
| Primary Partition Capacity (Gb) | 10 | 117 | -91.1 |
| Hard Drive Write Speed (MB/s) | 5.52 | 20.74 | -73.4 |
| Upload Speed (Kbps) | 491 | 494 | -0.4 |
| Dowload Speed (Kbps) | 4918 | 4894 | +0.5 |
Novabench2 has some overall performance summaries for various subsystems that are highlighted in yellow. Overall Win Xp performance under VMware is 24.3% less. Some of this can be explained by access to less memory. Booted Win XP has the full 4 Gb while VMware must share with Ubuntu with only 2 Gb. I am not sure why R/W to system RAM should be slower but it is 27.7% slower. The CPU tests evaluate number crunching ability. Surprisingly, floating point operations with Win XP under VMware is 4% faster. It was also unexpected that VMware performed the graphic tests faster. After some thought it was obvious why. Booted Win XP is driving dual monitors while VMware drives only 1 window on one monitor. VMware has much fewer pixels to test and the window is contained in only one video buffer. When I drag the VMware window so it straddles 2 monitors and then run the benchmark I get slower performance results. I am more than happy operating Win XP in a window and reaping the speedier graphics performance. Overall hardware tests are rated at 78.6% lower. This is stilted by the primary partition capacity parameter. I only allocated 10 Gb to VMware and that is all I need. Hard drive writes are 78.6% slower. Given the applications I am running, this is not noticeable. Internet access speeds seem about the same under VMware.
Conclusions
I can now use Linux and all my applications without the need to reboot. I find the performance of Win XP under VMware acceptable. Of course there is always room for improvement. The VMware Server Manual has many suggestions for speeding up Win XP under Ubuntu. I can now try these changes out and then measure the results. I am also sure that there are plenty of other advice available from the net. Later I will post the top 5 improvements that I find.
Linksys Model WCG200
Hardware version 1.2b (Note Version 1 has 2 antennae, Version 2 only 1 antenna) Firmware: 1.12.9.4-1104
This device is a cable modem/router/WiFi hub. I wanted to change the configuration of my router because I wanted to setup port forwarding for faster bit torrent downloads. I also wanted to improve security. Unfortunately, I had forgotten my password. Googling for a solution to this problem, I found that resetting the modem will set the user ID and password to the factory setting. It will also set the modem/router/WiFi settings to their factory default values. I also found that everyone who then attempts to change the user ID and password gets locked out of the modem setup. Then the only way to get back in is to reset the modem. For security reasons you do not want to leave the default user ID and password since anyone connecting to the modem could login and change the settings. So most people change the ID and password and get locked out. Then the only way to get in is to do a reset. Then you have to again change your settings back. It is secure but it is a hassle. While playing around with the settings, I accidentally figured out why this happens. So I made this post hoping it might help someone else. I also included some additional notes about this product.
Reset the Cable Modem
There is a rest button on the back of the modem. It is located next to the plug where the AC adaptor plugs in. The reset button is recessed. You will need a sharp pencil or pen to push the button. While the modem is powered up press and hold the reset for about 5 seconds
Log IN
It is best to connect to the WCG200 with an ethernet connection since there are no settings to change to get it to work.. You might be able to connect through WiFi but you just reset the hub parameters so you might have setup problems. Set your browser to 192.168.0.1. You will receive a login prompt. Leave the user ID blank. The password is 'admin' (no quotes all lower case). That is it, you are in.
Change the Password
Click Administration and then Security. You will see 2 boxes. The user manual mistakenly says enter new user ID and password. If you do this and click Save Changes, you will be locked out. If you look carefully at these boxes, you will see Enter password between the boxes and then confirm password below the second box. You should enter your password in the first box and then enter the password again in the second box. Theere is no user ID. Click save changes. When you log in leave the user ID blank and enter your new password. It seems really obvious once you see it. It is a case of poor documentation and poor dialog box design.
Change Settings to improve security
1.) Change your password.
2.) Disable remote/access control.
3.) Change SSID from the default. It is set to Linksys.
4.) Change SSID to not broadcast. Someone trying to connect to the hub must then know the ID to get in.
5.) Use 128 bit encryption.
6.) Used Shared authentication not Open.
7.) Restrict the number of IP's the router will assign to the number you need. Do not leave the default 255.
Want to upgrade you firmware - TOO BAD
It is a conspiracy. Apparently cable modem firmware can only be changed through the cable interface. So only the cable company can change your firmware. The is particularly bad for the WCG200. The firmware controls not only the modem but the router and hub. So it is strongly advised to record your firmware version. If you have strange problems or the WCG200 stops working you can check if the firmware has been "upgraded". There have been several anecdotes about cable companies uploading the wrong firmware. One common problem is having the wrong version firmware for version of the hardware. Version 1 hardware has firmware version beginning with a 1. Version 2 hardware has firmware version beginning with a 2 The only solution is to purchase a separate modem, router and hub. This is the only way to have control over your router and hub..
My dad made a star for his Christmas tree in 1982. He used aluminum foil, tape, and some punch cards from an old program of his he had laying around at the time. He has used it every year since.
The punch cards are fortran code that ran on an IBM 360. Here it is on his tree today.
I've been waiting for Dell to release a new driver for my laptop's nVidia 8400m gs video card since I bought my laptop. The driver provided by dell is pretty outdated; it was released 12/14/2007.
After waiting passively for a few months for them to release drivers I looked around google and found laptopvideo2go. This site releases edited versions of the new nVidia forceware drivers for you to download. My first attempt at installing the drivers with the "have disk" method resulted in a resolution of 640x480 with 256 color -- didn't work. After a bit of reading laptopvideo2go's forums I found the correct way of installing the drivers:
- Download the video driver from dell's support page. The WinXP 8400M GS driver can be found here.
- Run the executable you downloaded and it will extract the files to C:\dell\drivers\ by default.
- Download a modded inf file that is compatible with your video card and OS. You can find a list at the laptopvideo2go forums.
- Open the inf file found in the dell driver folder (mine was labeled "NVDM.inf") and the modded inf file you downloaded from laptopvideo2go.
- Replace the value for CatalogFile in the modded inf file with the value found in the dell driver inf file, save, and close.
I had to replace "CatalogFile = NV_DISP.CAT" with "CatalogFile = NVDM.CAT" - Replace the dell driver inf file with the modded inf file by renaming or deleting the original dell inf and moving the modded inf file into the dell driver directory and renaming it to what the original inf file was named.
- Run setup like you normally would and it should install.
Let's Get Started
The goal of this tutorial is to show the basic concepts involved in MySQL/PHP paging and how you go about coding a simple solution. This is not meant as a final class ready to use on a live site with lots of traffic. The class can be further optimized and streamlined, but that is beyond the purpose of this article.
To accomplish simple MySQL pagination you need two things: a function to run the MySQL statement through to go grab the right rows from the database and a function to create the navigation. I want mine to output a fully styled navigation, with some default css that is really easy to change. To begin with lets call the class pagination and make the two functions.
<?php
class pagination {
function paginate() {
}
function navigation() {
}
}
?>
If you want you can download the files here.
Handling the SQL
First let's make the function which handles the MySQL statement. Let's call it paginate. Paginate will take 3 arguments: the page we are on, the sql statement, and how many results per page we want (with a default of 10). It will return the limited MySQL statement. First take a look at the complete function then I'll break down each part.
function paginate($page,$sql,$perpage=10)
{
//count the number of resutls
$count = mysql_num_rows(mysql_query("$sql"));
//if the page isnt a number set it to page 1
$page = is_nan($page)?1:$page;
//limit the sql statement
$start = (($page - 1) * $perpage);
$end = $start + $perpage;
$sql .= " LIMIT $start, $perpage";
//return the result
return $sql;
}
First off let's take a look at the first two lines.
$count = mysql_num_rows(mysql_query("$sql"));
$page = is_nan($page)?1:$page;
The first thing we do is count the number of rows for the statement and store it in $count. The second line just makes it so that if the page number is not a number it will default to page one. Now the rest.
$start = (($page - 1) * $perpage);
$end = $start + $perpage;
$sql = " LIMIT $start, $perpage";
All these lines do is LIMIT the MySQL statement by starting on the first record for that page, and ending on the last record for that page. Pretty simple. For example let's say you are displaying a list of blog posts and want 10 to a page. You might do something like this to show all the posts on page 5:
//start the class
$paging = new paging;
//this grabs all the blog posts
$sql = "SELECT * FROM `blog_posts`";
//set this to the page you want
$currentpage = "5";
//limit the statement to just this page
$new_sql = $paging->paginate($currentpage,$sql);
//now use the new_sql like you normally would...
Now that you see how it works, you can change the page in the best way you see fit. An easy way is setting a GET variable like /blog_post.php?page=5 and running it like this:
//start the class
$paging = new paging;
//this grabs all the blog posts
$sql = "SELECT * FROM `blog_posts`";
//limit the statement to just this page
$new_sql = $paging->paginate($_GET['page'],$sql);
//now use the new_sql like you normally would...
Implementing a Navigation
The navigation function is a bit more complex. It takes 5 arguments: the page we are on, the original MySQL statement, optional number of results per page, optional number of links to limit the navigation to, and optional url of the page we are on. Take a look at the full thing, with comments explaining what is going on.
function navigation($page,$sql,$perpage=10,$limitnav=10,$link="") {
//count the number of rows
$count = mysql_num_rows(mysql_query("$sql"));
//if the page isnt a number set it to page 1
$page = is_nan($page)?1:$page;
//if the number of rows is less than the number per page we only need
//one page and no nav
if($count <= $perpage) {
return;
}
//set some variables and counters to use
$nav = ""
$a=1;
$previous = $page - 1;
$next = $page + 1;
//get the total number of pages rounded up
$pages = ceil($count/$perpage);
//as long as we are not on page 1 we will build the navigation
if($pages !== 1) {
if(($page - ($limitnav/2)) > 1) {
$nav .= "<span class='pagenav'><a href=\"$link?page=1\"><b>first</b></a></span>";
}
if($page !== 1 && $page !== "1") {
$nav .= " <span class='pagenav'><a href=\"$link?page=$previous\"><b>prev</b></a></span> ";
}
//if the number of pages is more than our limit for links in the
//navigation then create the inner links
if($pages > $limitnav) {
//if we are past halfway then start at half the limit under the page
if(( $page - ($limitnav/2) ) > 0) {
$a = $page - ($limitnav/2);
} else {
//otherwise start at page 1
$a = 1;
}
//similarly find the end page number of the navigation
if(($page+($limitnav/2))<$pages) {
$toplim = $page + ($limitnav/2);
} else {
$toplim = $pages;
}
//from the first page of the nav to the last add a link
while($a <= $toplim) {
//if this is the page we are on add some classes so we can style it
if($a == $page) {
//page we are on
$nav .= "<span class='pagenav pageat'><b>$page</b></span> ";
} else {
//any other page
$nav .= "<span class='pagenav'><a href=\"$link?page=$a\">$a</a></span> ";
}
//increment the counter
$a++;
}
} else {
//if this is the page we are on add some classes so we can style it
while($a <= $pages) {
//page we are on
if($a == $page) {
$nav .= "<span class='pagenav pageat'><b>$page</b></span> ";
} else {
//every other page
$nav .= "<span class='pagenav'><a href=\"$link?page=$a\">$a</a></span> ";
}
//increment the counter
$a++;
}
}
//if we need to add the next and last links
if($page != $pages && $pages != '0') {
$nav .= " <span class='pagenav'><a href=\"$link?page=$next\"><b>next</b></a></span>";
}
if($page < ($pages - ($limitnav/2))) {
$nav .= " <span class='pagenav'><a href=\"$link?page=$pages\"><b>last</b></a></span>";
}
}
//add a div to wrap it in and return it
return "<div class='paging'>$nav</div>";
}
You can use the function like so to show a navigation and paginate the results.
//start the class
$paging = new paging;
//this grabs all the blog posts
$sql = "SELECT * FROM `blog_posts`";
//limit the statement to just this page
$new_sql = $paging->paginate($_GET['page'],$sql);
//output the navigation at the top
//we don't have any other get variables so we dont need to set the link
//make sure to use the ORIGINAL sql here, not the new one
echo $paging->navigation($_GET['page'],$sql);
//now use the new_sql like you normally would...
Styling your navigation
Here is the default styling that I use for pagination. I usually just take this and change the colors and it is fine.
.pagenav {
padding-left:5px;
padding-right:5px;
height:12px;
font-weight:bold;
}
a .pagenav {
color:#E3BD14;
}
.pageat {
background-color:#cccccc;
}
.paging {
text-align:center;
padding-top:3px;
padding-bottom:2px;
}
#paging {
border:1px solid gray;
background-color:#2f281e;
}
You can download the files here.
If you have questions, remarks, bugs, or you want to show off how you styled it please leave me a comment below!
Casually stopping by T-Mobile, hoping to get some information on the G1 phone, we found out more than we could have hoped for… except for my original question, what is the monthly plan going to be? I guess I should mention I was with my friend Trevor so the use of we implies us, not my having multiple personalities… which I don’t… know of. The salesgirl, whose name shall not be… named, came over to help us. We asked a few questions and she basically said, “We won’t know anything about the phone until Sunday’s training session.” We continued to chat and after a bit she asked us, “do you want to see it?” Unsure at first what she was talking about, I said yes… she had snuck back to grab the G1! Yeah she lied about knowing nothing, but who could stay mad? She opened it up and we got to see many of its features and try the Android software. The phone felt very solid and light for its size. The flip-screen was awesome. I don’t think people will have to worry about that breaking off. It’s more likely to survive any accident than you or me.
The first application she opened up was the GPS/Google-Map navigator (sorry I don’t really know the names of these things). We played with this for 10 or 15 minutes. Well, it was like the video so I won’t go into detail there, but I can confirm it is just as fun and functional as you’d imagine from the snippets you have probably seen. I should also mention that the multi-touch does work very well.
The second application we tried was the SmartShopper… or something like that. I don’t remember if this application has been shown online, but what it does is it allows you to take a snapshot of a barcode and it will read the code, tell you the store you are at and how much the item is. I also believe it checks the stores online price. According to Trevor’s memory, the item we scanned was on sale online. This is great for price comparison and competitor price matching. I’m sure this feature alone is going to cover the cost of the phone and possibly the monthly fees.
Those were the only applications we messed around with, but I’ll go into a little more detail about the phone itself. The buttons are great, not so easy to press that you will accidentally hit them while doing whatever you are doing. Also, typing on a real keypad is 1000 times easier than on a touch-screen, another superior feature to the I-Phone. I am personally a fan of the larger phones because you can actually type and read what is on the screen. In addition, you can see everything you are typing so you really have at least twice as much viewable screen area as the I-Phone. It still fits in your pocket and you’re not very likely to forever lose it if you drop it like a super mini nano I-Pod.
As I placed my hand on the door, I almost slipped as my excitement was taking hold. Was I actually going to see it? Was this the pinnacle of technology, the end all to the personal device? I barely noticed the saleswoman assure me that she would help me soon; all I could focus on was a small nondescript plaque with the following:
G-1 Phone: Coming October 22nd
“How may I help you?” she said, as I tried to cover up my anticipation and play it cool.
“Uh…um… I’d like to know more about the G-1.” My voice didn’t betray the hours I spent gazing at my shimmering LCD monitor at home, gleaning every morsel of information I could find about the contraption.
“The G-1 will not be here until October 22nd.” Rejected yet again, I thought. She went into some diatribe about how she had to go to a five hour meeting on Sunday to talk about the phone. I nodded sympathetically, even though I would have given up my right nut just to be able to touch and cradle the G-1. “Would you like to see it? My manager doesn’t want me to show anyone, but I think I can sneak this by him.” This caught me totally off guard; I could merely nod and drool. She slumbered away deftly as I crept behind a sales rack. She came back and in moments I had my eye on the G-1.
What a masterpiece of engineering! I was amazed by the ease of using the trackball to navigate Google Maps, and a smile slowly grew on my face as she flipped the touch-screen up and revealed the QWERTY keyboard. She told me to bring her an item, I quickly grabbed a Bluetooth earpiece as I thought her boss was coming and she was going to have to put the G-1 away.
Instead I was treated to a demonstration of the bar-code scanning ability, which clearly showed that the in-store price was three bucks more than online. Worrying about revealing too much, my newfound friend carefully closed the flip screen and snuck it into her bra. I wished her good day, and promised that I would return on October 22nd. As I left the store, the sun shown brilliant rays, a my spirits lifted, and the whole world became a much happier place.
Uh, actually I knew dick about the G-1 Phone until I stepped into the T-Mobile store and while this post is a little exaggerated, the thing was freakin’ awesome!
Where Art Thou, Good Web Version Control?
This post started out as an ask Reddit question in programming, but I soon realized that I couldn't quite ask the question in just a self reddit title. My question was as follows: Is there version control software that automatically backs up changes I make to files in a directory on my webserver? After much looking and a bit of pondering I think the answer is, unfortunately, no.

I work in many small development groups for many different web sites. Most of the groups consist of me and one or two other people. A few projects have a couple more. I started learning about version control software after realizing that backing up the public_html and the mysql databases every so often is not quite enough. I have yet to lose any significant portion of my work, but I imagine it is only a matter of time unless I get a version control solution. The problem is I couldn't get subversion to work quite how I wanted it to, and other options that I looked at seem to be even further from what I want. After looking at what was available I started thinking about what would be ideal. I realized that it was really only 5 things:
I Want it to be Unobtrusive
I should not have to change my work flow to accommodate my version control. If I change any file for my website it should get backed up automatically. When I set it up I imagine I should have to specify a directory (such as public_html.) where if any file in that directory is edited, a backup is made. If I choose to edit via FTP, locally, through SSH, or whatever the version control software should notice and backup the change. I shouldn't have to check anything out or in. I shouldn't have to tell the software to do anything. It should just work.
I Want it to be Easy
Many of the people I work with only know and change html. These people shouldn't have to worry that the changes they are making to the site may cause an irrevocable loss of information. These people need access to the files to edit them, but shouldn't (or can't) be expected to know how to set up and use version control software and have to check things in and out. I don't really care how hard the thing is to set up, just that once it is set up it is easy for everyone to use.
I Want it to Track Who Is Doing What, and When it Was Done
It should log the IP address and timestamp of each change. It should log how this IP address is accessing the system. I should be able to set up a system based on FTP users or linux users where only certain users get to change files in directories of my choosing. Is 6.43.143.4 using FTP to edit it? Is diane@myserver logging in through SSH and using nano to edit it? I should know.
I Want Database Backups
I want options on how to deal with backing up my databases. Maybe I want to save space by keeping infrequent snapshots. Maybe I want it to export a backup to another computer or DB every so often. Maybe I want to backup certain tables more frequently than others. I should have options. It should integrate with MySQL (and probably others) off the bat.
I Want Web-Based Administration
I want a web-based administration area along the lines of phpMyAdmin. From here I should be able to see who changed files and when. I should be able to revert to backups of my choosing, or a snapshot in time of my choosing. If I want it to be just how it was last friday before Joe went through and messed up half the site, it should be easy to do that. I shouldn't have to know what files Joe messed up, or how he messed them up. I should just be able to revert to a date.
I should be able to have some sort of diff functionality so I can compare what has changed in different revisions. I should have the ability to merge changes from the diff view. I should have options to use these features intelligently and easily.
I should be able to do all of this from http://www.domain.com/myVersionControl or something similar. Of everything I want this is probably the least important. If I could get the first four things and not this one I would be happy, but this would be the icing on the cake.
Is There Such a Thing?
I wrote this post hoping that someone could tell me there would be something, or some set of things, that could do what I want. Or, if there isn't that magic software maybe some people on Reddit or Digg might like to start a new open source project to make it. I would definitely be willing to work on it if others were.
Do you know of anything that might work? Comment below!
This is part two of our Programming for Android series. See part one: A Look at the Android SDK.
Now that we have set up the Android emulator, we need to get cracking with Eclipse and the Android Development plugins. It's time to make an (admittedly simple) app!
Setting Up Eclipse
After installing JDK 6 I had to get Eclipse Ganymede from the Eclipse website. The version that comes in the Ubuntu repositories is 3.2, and you need at least 3.3 to work with Android. Once that was out of the way I installed the WST and Android plugins for Eclipse. Just go to Help > Software Updates, click Add Site, and put
https://dl-ssl.google.com/android/eclipse/
Check the developer tools box and the Web Tools. Once that is done hit Install. Go through the windows and it will automatically install. Restart Eclipse and set up the Android Project location by going to Window > Preferences > Android and add the SDK location. Mine is ~/Programs/android-sdk-linux_x86-1.0_r1/.
Hello World
Start up by opening your emulator. Go to File > New > Project > Android and fill in the project details. I called my project Hello World, with the package name of com.oxavi.hello, an activity name of HelloWorld, and application name of HelloWorld. The package name has to follow the same naming convention as Java packages. This is what it looked like right after I made the project.
On the phone an error message popped up so I hit force close and went on to changing the code. I added a few lines to HelloWorld.java to get it to do something. Lines that I added are commented.
package com.oxavi.hello;
import android.app.Activity;
import android.os.Bundle;
//you need this to get the TextView functions to work
import android.widget.TextView;
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this sets TextView variable tv
TextView tv = new TextView(this);
//this sets the text of the tv variable
tv.setText("Hello, Android. This is Oxavi!");
//this displays the tv variable
setContentView(tv);
}
}
Now go to Run > Run > Android Application and hit OK. You should see something like this on the phone after a few seconds.
Starting Out With XML Layouts
Writing the layout into the code can be a problem when you later want to make a small interface change and you now have to edit code all over the place. Here enters the XML layout, which lets you separate the layout from the logic, similarly to how you separate it with HTML and CSS in web design. Eclipse already made an XML layout for us, we just haven't been using it. To use it lets go to res > layout > main.xml and change the code to in that file to:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="Hello, Android. This is Oxavi, and we are using XML layouts!"/>
You can change the android:text="" to whatever you want it to say. res will be used a lot later, it is the folder that will contain stuff your app uses that isn't code, like images. Now open up R.java. This file contains references to some of the stuff your app needs to run. It lets you use the references as a shorthand while coding. This file is auto-generated by Eclipse, so there is no need to change it. It will get auto-updated as you change things and work on your app. Now we need to change a few lines in the HelloWorld.java file to:
package com.oxavi.hello;
import android.app.Activity;
import android.os.Bundle;
/* we no longer need this to run the XML layout so comment it out
//need this to get the textview functions to work
import android.widget.TextView;
*/
public class HelloWorld extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//this sets the XML layout to display
setContentView(R.layout.main);
/* this is the old layout view that we dont need, so comment it out
//this sets textview variable
TextView tv = new TextView(this);
//this sets the text of the tv variable
tv.setText("Hello, Android. This is Oxavi!");
//this displays the tv variable
setContentView(tv);
*/
}
}
Now we have successfully ran our first XML based app! Here is what it should look like, a lot like before. If you check the menu you will see your HelloWorld app there, but it needs an icon! Let's do that now.
Adding Application Attributes
We can go ahead and add a description first. Go to res > values > strings.xml and click add. I named mine app_description and added the value 'This app says hello to the world.' Save your png icon to your workspace/res/drawable folder and open the AndoidManifest.xml file. This file contains all the information about your app, and makes it easy for you to edit it. Go to the Application tab and click browse next to the icon field. Browse for the icon you saved and set enabled to true. Now do the same for the description and browse to values > strings > app_description. Save everything and run it.
And you should see your shiny new icon for your app!
Thoughts
Google has taken care to make this really easy to do. I guess now it's time for me learn some more Java before I dive head first into development. Hopefully the other API's are just as easy to access as the textview. You can do quite a bit with just textview, drawables, and sql. Since we at Oxavi are considering developing a game for this platform I'll have to find out before we start if these API's will be enough, in the next post.
This is part two of our Programming for Android series. See part one: A Look at the Android SDK.
This is part one of our Programming for Android series. See part two: Programming for Android with Eclipse.
Setting up the Emulator
Today I decided to crack open the Android SDK and mess around a little bit to see if I wanted to try to develop for it. I'm running Ubuntu 8.04 so I went over to the android site and downloaded it for Linux. My main goal for today was to set up the emulator and have a look around the phone.
Make sure you have JDK 5 or 6. The SDK is surprisingly easy to get going, just extract it to any folder. I chose ~/Programs/android-sdk-linux_x86-1.0_r1/
Getting the emulator to run was really easy. First you have to set the directory where the image is kept. I just made a folder called android in ~/Programs then ran this code:
~/Programs/android-sdk-linux_x86-1.0_r1/tools/emulator -datadir ~/Programs/android
Every time you want to run it after you don't need to set the data directory. Now you should see it booting up. It took me a good minute before it popped up, on a friends old laptop it took at least fifteen minutes.

Here is a picture of the phone when it first boots. It shows that I have no service (of course), the time, the date, and the charge left (which always stays at 50%).

Click menu and you are in! Here is the home screen.
A Look Around

You can mess around with all the applications and test stuff out, as well as get access to some of the development tools. Here is a screen of the menu going up.

The browser works and the sites look nice in it. It doesn't try to resize anything, but will fit the text to the width of your screen. I like it better than most phone browsers I've used.
Setting Up An SD Card
Next I made an SD card for the device. I did that by running the following code:
~/Programs/android-sdk-linux_x86-1.0_r1/tools/mksdcard -l myfirstcard 1000mb ~/Programs/android/myfirstcard
This named it myfirstcard, set it to be 1000 megabytes, and put the file to store it all in ~/Programs/android/. Now you can save pictures, music, and anything else to the emulation.
Next post I'll install Eclipse and the development plugins and run a hello world. So far, Google has made this pretty easy to set up. If that continues to be true maybe I'll start a new project for it.
This is part one of our Programming for Android series. See part two: Programming for Android with Eclipse.
I found this somewhere and thought it was useful. If you need to automatically format phone numbers, this is a small lightweight function to do it.
<?php
function format_phone($phone)
{
$phone = preg_replace("/[^0-9]/", "", $phone);
if(strlen($phone) == 7)
return preg_replace("/([0-9]{3})([0-9]{4})/", "$1-$2", $phone);
elseif(strlen($phone) == 10)
return preg_replace("/([0-9]{3})([0-9]{3})([0-9]{4})/", "($1) $2-$3", $phone);
else
return $phone;
}
?>
I finally got a copy of our original game and an old copy of 3dsmax, so now I will begin converting the old models to use as placeholders until the new models are complete.
Flashpoint Balkans is now live.
Flashpoint Balkans has been successfully compiled for the first time.
First things todo:
set up controls
set up money/buy system
set up teams
This is a small function we use on this site for code highlighting. It takes content and highlights anything between [ code ] and [ /code ] tags.
<?php
function highlight_code($content) {
$highlighted = preg_replace('/\[code\](.*?)[\/code\]/es',"'<div class=\"code\">'.highlight_string(html_entity_decode(str_replace('<br />','\n','\\1')),TRUE).'</div>'",$content);
return $highlighted;
}
?>
This is a short but dense piece of code, so I'll explain it step by step, from what it does first to what it does last. First off:
str_replace('<br />','\n','\\1')
This replaces all back returns with newlines in everything between the code tags. Without this the code would be one long line.
html_entity_decode(PREVIOUS_CODE)
This decodes all html entities so they will show up correctly after being highlighted.
highlight_string(PREVIOUS_CODE,TRUE)
This does the actual code highlighting. The TRUE as the second parameter sets the function to return the code.
$highlighted = preg_replace('/\[code\](.*?)\[\/code\]/es',"'<div class=\"code\">'.PREVIOUS_CODE.'</div>'",$content);
This is the hardest bit of code. It uses regular expressions to replace everything between code tags with the div. It also runs the previous functions on the section it is replacing. \\1 is a variable is the contents of the match (.*?). (.*?) matches any number of characters of any kind.
Hello everyone. James and I are currently working to finish this website up. This project is being developed with PHP and MySQL and is running on an Apache server. James has done a bulk of the PHP/MySQL work so far as well as most of the design. I'm going to try to finish up most of the code in the next few days. We will be posting the PHP Classes this site in the software portion of the site. This blog will be updated whenever new content is available so be sure to check back often and subscribe to the RSS feed.










