Android: Dialog Box with an EditText

A simple code snippet I found over at http://www.androidsnippets.com/, shows how to create a dialog box with an EditText in it. I needed it to save a user’s login name into the preferences when first starting a program, but it pretty much has a limitless amount of uses

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Title");
alert.setMessage("Message");

// Set an EditText view to get user input 
final EditText input = new EditText(this);
alert.setView(input);

alert.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
  String value = input.getText();
  // Do something with value!
  }
});

alert.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
  public void onClick(DialogInterface dialog, int whichButton) {
    // Canceled.
  }
});

alert.show();

-Kevin Grant

Advertisements

Crypto++ and Linux

This week I’ve re-acquainted myself with Linux at work in order to port an app from Windows to Linux. Besides the aggravation of setting up the OS, IDE, and workflow, I had to use a 3rd party library called Crypto++. Well, it wasn’t obvious to set up or figure out so I’d put this out there in case someone has the same problem.

Basically I was able to include the files, but I got a linker error despite including the files in the project file in Qt. This is the error:

g++ -o encrypter -L/usr/lib -Lcryptopp -lcrypto++ -lQtGui -lQtCore -lpthread
encrypter.o: In function `CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)':
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x2b): undefined reference to `CryptoPP::AlignedAllocate(unsigned int)'
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE8allocateEjPKv[CryptoPP::AllocatorWithCleanup::allocate(unsigned int, void const*)]+0x38): undefined reference to `CryptoPP::UnalignedAllocate(unsigned int)'
encrypter.o: In function `CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)':
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x25): undefined reference to `CryptoPP::AlignedDeallocate(void*)'
encrypter.cpp:(.text._ZN8CryptoPP20AllocatorWithCleanupIhLb1EE10deallocateEPvj[CryptoPP::AllocatorWithCleanup::deallocate(void*, unsigned int)]+0x32): undefined reference to `CryptoPP::UnalignedDeallocate(void*)'
collect2: ld returned 1 exit status
make: Leaving directory `/home/alex/projects/encrypter'
make: *** [encrypter] Error 1
Exited with code 2.
Error while building project encrypter
When executing build step 'Make'

The proper way to include crypto++ is NOT to download it from the website. Use terminal to get the library:

sudo apt-get install libcrypto++8 libcrypto++8-dbg libcrypto++-dev

Then check if installed on system:

apt-cache pkgnames | grep -i crypto++

Which should result with:

libcrypto++-utils
libcrypto++8
libcrypto++8-dbg
libcrypto++-dev
libcrypto++-doc

If the information above is different (which is possible if it becomes out of date), check the Crypto++ Linux wiki for instructions.

Now add the library to project with the following linkage (written as a makefile macro, but just put the -L and -I parts in the command line if you’re compiling manually):

LIBS += -L/usr/lib/crypto++ -lcrypto++
INCS += -I/usr/include/crypto++

While is is rather specific, someone out there is probably searching for this so here ya go!

If Linux was a car

Really? But your car still runs with Windows

Linux enthusiasts are scary

Shameless cross-post from my car blog: http://yudrivebad.wordpress.com/

(Recursion!!!!)

If Linux was a car, you’d have to build it from scratch just to go to the store to buy some milk. You’d start by compiling an engine and put it on a chassis. That’s fine and dandy and it’ll get you where you need to guy, but it sure is a pain in the ass to turn with a socket wrench on the rack and pinion. So let’s put in a steering column and steering wheel.

It’s not very comfortable so let’s add some seats. Now you realize there are different flavors of seats. Bench, bucket, velour, cloth, leather, etc. Bench sounds nice which is great for cuddling with a significant other! Oh wait, you use Linux. Scratch that, let’s go with buckets for the sportier feel.

Great, but it’s not that great looking. It needs a body. Those damn Apple cars look so sleek and sexy with their glossy exterior, but we all know you can’t modify them. Fk the sheeple and their pretty cars. Those Windows cars actually look pretty good now unlike a few years ago when the Fisher Price Cozy Coup called them out on plagiarism. What can I do with the Linux car? Well, there’s not much to choose from out of the box. Fkr looks cartoony. Meh, fk it, let’s roll.

It drives just as well as the Apple car because they’re almost identical under the hood. You’re feeling pretty smug because you built your own car for free. Well, let’s keep adding mods. You want lib-vtec-honda, but it won’t work in your car. You hack it to work instead. You’re somewhat successful, but you needed another obscure library to get it to work: lib-jdm-bolts. Ok, it works fine, but not perfect.

Oh no, the radio stopped working! Ok, don’t panic, just use another antenna. Crap, it’s not compatible with Linux and you just paid out the butt for it. To the Googles! So many people have the same issue, but with different hardware. WTF?! Grrrr! Ok, this guy says to download ndis-radio-wifi-2.6.1 and compile it for my specific car. Ok. Fk! I need another obscure library: lib-am-fm-cassette. Don’t I already have that?! Jebus H. Chrysler this is retarded.

Wheee, got the radio working. Let’s roll. Going to Taco Bell for some chalupas and Baja Blast. Oh muffin fudger, it doesn’t have a fkn cupholder. Google it. Cupholders aren’t available to Linux due to it being proprietary technology developed by Adobe?! GD it to hell! You end up burning the car and buying a Windows car.

Want to learn C#?

I’ve been wanting to learn C# for a while so I finally started learning it a few weeks ago. I lightly touched C# back in the fall of 2009. We had a quick crash course trying to get a XNA game working thinking that was the best way to make a game in two weeks. That was a very terrible learning situation and I haven’t thought much about C# since then. Once I decided to take a shot at it again, I was definitely a lot wiser than I was 1.5 years ago. Now that I’ve got some good C++ programming, MFC UI development, and Visual Studio usage skills down, jumping into C# was not as hard as it was when I first came across it. Actually, working with C# in Visual Studio is so much easier than C++ and MFC that I feel like I’ve been converted to a new religion. Seriously, how did I live without this all my programming life?! String conversions, getting file paths/names/extensions, and capturing events are just one call away instead of some hackjob conversion and string parsing! C++ and MFC is like driving a Volvo 240: solid, reliable, and old, but hard to work on and possibly relies on hackjob repairs to make things work. C# with .NET is like a brand new Volvo S60: new, easy to use (from the driver’s seat), and safe with all the electro-nannies, but it’s a lot more complicated under the hood, but you’re not likely to go that deep anyways. I followed the tutorial at Home and Learn and got a nice primer on C#. The tutorials are very easy to read and understand so I recommend checking it out if you’re a beginner. It’s nice that Microsoft offers Visual Studio Express for free to play around with also. Get Visual Studio Express and start making some programs!

Prince William: Put a ring on it!

At phamous-apps, we’re shameless fans of the royal wedding, and in lieu of this, we’re giving you another precious gem for your application arsenal. We present to you…

Prince William: Put a ring on it!

A simple mini-game where you can put a ring on Prince Williams finger. Description from the marketplace

The Royal Wedding is soon, and Prince William is refusing to wear his ring. Kate Middleton seems ok with it, but we all know that shes not!
In this minigame, “Put a Ring On it!” you need to put as many rings on the Prince’s hand as possible! Rack up a high score, let him know that you want that ring on there!

There seem to be some problems if you have a ridiculously large screen where the hand moves too fast, but just think of it as “expert mode” and you’ll be fine, until we can fix it anyways 😉

Is there an Android API for Google Maps 5.0?

I’ve been looking for this for some personal projects today. After a few hours of research and testing on 3/29/2011, my definitive answer is no.

There remains an unanswered comment on the official blog post about it here from December, and when using the latest 2.3.3 Google APIs in the SDK, I still receive tile based maps. I have also found numerous unanswered questions from stackoverflow and other QA sites to back up my statement that it is currently unavailable.

I will update this post when the Maps 5.0 API becomes updated, or if anyone hears otherwise before I do, please comment!

How to shoot yourself in the foot in any programming language

Searching through the documents on my hard drive this weekend I came across a document containing the joke of how to shoot yourself in the foot in any programming language. Well, not literally, but it does relate how the different languages behave by using the analogy of shooting one’s self in the foot. I forgot where I found this so if someone knows, post the link in the comments!

* * *

How to Shoot Yourself in the Foot in Any Programming Language

The proliferation of modern programming languages (all of which seem to have stolen countless features from one another) sometimes makes it difficult to remember what language you’re currently using. This guide is offered as a public service to help programmers who find themselves in such dilemmas.

C
You shoot yourself in the foot.

C++
You accidentally create a dozen clones of yourself and shoot them all in the foot. Providing emergency medical assistance is impossible since you can’t tell which are bitwise copies and which are just pointing at others and saying, “That’s me, over there.”

JAVA
After importing java.awt.right.foot.* and java.awt.gun.right.hand.*, and writing the classes and methods of those classes needed, you’ve forgotten what the hell you’re doing.

Ruby
Your foot is ready to be shot in roughly five minutes, but you just can’t find anywhere to shoot it.

PHP
You shoot yourself in the foot with a gun made with pieces from 300 other guns.

ASP.NET
Find a gun, it falls apart. Put it back together, it falls apart again. You try using the .GUN Framework, it falls apart. You stab yourself in the foot instead.

SQL
SELECT @ammo:=bullet FROM gun WHERE trigger = ‘PULLED’;
INSERT INTO leg (foot) VALUES (@ammo);

Perl
You shoot yourself in the foot, but nobody can understand how you did it. Six months later, neither can you.

Javascript
You’ve perfected a robust, rich user experience for shooting yourself in the foot. You then find that bullets are disabled on your gun.

CSS
You shoot your right foot with one hand, then switch hands to shoot your left foot but you realize that the gun has turned into a banana.

FORTRAN
You shoot yourself in each toe, iteratively, until you run out of toes, then you read in the next foot and repeat. If you run out of bullets, you continue anyway because you have no exception-handling ability.

Modula2
After realizing that you can’t actually accomplish anything in this language, you shoot yourself in the head.

COBOL
Using a COLT 45 HANDGUN, AIM gun at LEG.FOOT, THEN place ARM.HAND.FINGER. on HANDGUN.TRIGGER and SQUEEZE. THEN return HANDGUN to HOLSTER. CHECK whether shoelace needs to be retied.

LISP
You shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds the gun with which
you shoot yourself in the appendage which holds ….

BASIC
Shoot yourself in the foot with a water pistol. On big systems, continue until entire lower body is waterlogged.

FORTH
Foot in yourself shoot.

APL
You shoot yourself in the foot, then spend all day figuring out how to do it in fewer characters.

Pascal
The compiler won’t let you shoot yourself in the foot.

SNOBOL
If you succeed, shoot yourself in the left foot.
If you fail, shoot yourself in the right foot.

Concurrent Euclid
You shoot yourself in somebody else’s foot.

HyperTalk
Put the first bullet of the gun into the foot of the left leg of you.
Answer the result.

Motif
You spend days writing a UIL description of your foot, the trajectory, the bullet, and the intricate scrollwork on the ivory handles of the gun. When you finally get around to pulling the trigger, the gun jams.

Unix
% ls
foot.c foot.h foot.o toe.c toe.o
% rm * .o
rm: .o: No such file or directory
% ls
%

Paradox
Not only can you shoot yourself in the foot, your users can too.

Revelation
You’ll be able to shoot yourself in the foot just as soon as you figure out what all these bullets are for.

Visual Basic
You’ll shoot yourself in the foot, but you’ll have so much fun doing it that you won’t care.

Prolog
You tell your program you want to be shot in the foot. The program figures out how to do it, but the syntax doesn’t allow it to explain.

Ada
After correctly packaging your foot, you attempt to concurrently load the gun, pull the trigger, scream and shoot yourself in the foot. When you try, however, you discover that your foot is of the wrong type.

Assembly
You try to shoot yourself in the foot only to discover you must first reinvent the gun, the bullet, and your foot. After that’s done, you pull the trigger, the gun beeps several times, then crashes.

370 JCL
You send your foot down to MIS with a 4000-page document explaining how you want it to be shot. Three years later, your foot comes back deep-fried.

Python
You try to shoot yourself in the foot but you just keep hitting the whitespace between your toes.