June 2013
M T W T F S S
« Jan    
 12
3456789
10111213141516
17181920212223
24252627282930

Language

Categories

Meta

Android custom AlertDialog

By Bart | January 7, 2013

For our Snøg Android app, I was browsing the web, figuring out how to add the UnlockBar I wrote to a Dialog, to create a slide-to-OK dialog. I reckoned this would be a simple case of extending the Dialog or AlertDialog class, build it and be done with  it. Well I was wrong. There is a lot of information to be found on the internet about Android programming in general and Dialogs in particular. But not the simple application I wanted. The official documentation tells me to subclass DialogFragment, but it seems like I need to have an ActivityFragment to support that correctly. That’s where I stopped, because the app is a plain simple phone Activity-app. So I ditched that. Then, a lot of blogs and info talking about the onCreateDialog method (nobody telling me in which class it is supposed to be overridden; tip: it’s Activity), that I haven’t had as well. I was just using the AlertDialog.Builder class to create dialogs, and all I wanted was to replace the OK button with my UnlockBar. That’s it! So, after looking around and experimenting a little, I got it: subclass the AlertDialog.Builder class:

public class UnlockDialog extends AlertDialog.Builder {
    UnlockBar unlockbar = null;

    protected UnlockDialog(Activity context) {
        super(context);

        LayoutInflater inflater = context.getLayoutInflater();
        View dlgView =inflater.inflate(R.layout.unlock_dialog, null); 
        setView(dlgView);
        unlockbar = (UnlockBar)dlgView.findViewById(R.id.unlockbar);
    }
}

Then, to use it, simply use this in your Activity to show the Dialog:

UnlockDialog builder = new UnlockDialog(this);
builder.setTitle(R.string.are_you_sure_);
builder.setMessage(R.string.slide_to_quit_snog).setNegativeButton(R.string.cancel, null);
builder.show();

Topics: Geekstuff, Opinie | Geen reacties »

iOS vs Android Development, Round 1: Getting Started

By Bart | October 31, 2012

This week, I took up porting our Snøg Avalanche Buddy to iPhone. To do so, I had to learn quite some things. This post will touch all the troubles I have encountered and I try to compare it to developing an app in Android.

Development Machine

The first hurdle to take is getting your development machine. Android can be developed in virtually all host hardware. Eclipse  is the main IDE used to create Android apps and it is available on Linux, Windows and OSX. Developing for iOS is not so easy. You will need a Mac running at least OSX 10.7 to get to use the latest version of Xcode. Turns out, it is not so easy to get a (second hand) Mac. Luckily I could borrow on old one from somebody. Good thing is that Xcode is free.

Because I come from a Linux (Ubuntu) background, I also have quite some trouble getting used to the OSX user interface. It is not so easy as everybody makes you believe it is. One of the main reasons I switched to Linux in the beginning of the millennium is multiple desktops and I still cannot get my head around the fact that the two other major OS’s still haven’t embraced it. My head just gets completely messed up with so many windows on one screen. But maybe it is just me. Also the shortcuts are different, but that’s just something to get used to, so I won’t bash Apple over that.

The Language

Mostly because of historical reasons, the iOS / OSX ecosystem is built around Objective-C. When you come from a C/C++/C#/Java background (like me), you are in for quite a ride. The syntax is based on the early-80s language Smalltalk and is completely different from what I am used to. I won’t go into details, there are many tutorials out there to teach you the language. All I can say is that it all feels very messy and inconsistent to me. I have to admit of course, that I just started out with it, and have over 15 years experience in C and its descendants.

The IDE (Xcode)

Three words: What The Fuck!

This IDE seems to be designed by people that care about looks instead of clarity. There is a lot of clicking and completely incomprehensible windows, icons, etc. I have to connect a button touch event to an event handler by dragging a line? Seriously? There is a separate “Interface Builder” that doesn’t seem to have any connection with Xcode whatsoever?

It could be the tutorial I was following, but it otherwise also doesn’t seem loigcal whatsoever. It could also be that I have to use Xcode 3 instead of 4, because of the Mac I am using, but still. Compared to this thing, Borland Builder is heaven.

In Conclusion

First remind that I am completely new to both Macs and Objective-C, and have quite some experience in Java and Linux when I started Android development. But, I remember the first “Hello World” app in Android to take me less than 25 minutes, from downloading and installing the IDE to having it on an actual, real device. Xcode took quite some time downloading and installing (10 GB for an IDE and SDK? Second WTF), not to mention getting some app to run. In the emulator. Even though the iOS version on my iPad is newer, Xcode wouldn’t accept it as a development device. Android has no problems at all like this.

The Winner: Android Development

I am going to give this round to Android. Developing for it really is a breeze. The IDE installs and runs on all modern OS’s, is clear and concise and easily supports all devices. Getting to use Java is very nice as it is (in my opinion) the cleanest OOP language out there.

Let’s see what the other rounds may give.

Topics: Geekstuff, Opinie | Geen reacties »

C#.NET snack: sign data with RSA

By Bart | July 10, 2012

Create keys:

var csp = new RSACryptoServiceProvider(keyStrength);
var privateKey = csp.ExportCspBlob(true);
var publicKey = csp.ExportCspBlob(false);

Sign data:
var csp = new RSACryptoServiceProvider();
csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(privateKeyFile));
var sig = csp.SignData(data, new SHA1CryptoServiceProvider());

Verify data:

csp.Clear();
csp.ImportCspBlob(File.ReadAllBytes(publicKeyFile));
if (csp.VerifyData(data, new SHA1CryptoServiceProvider(), sig)) {
    Console.WriteLine("Data is OK");
} else {
    Console.WriteLine("Data is not OK");
}

Topics: Geekstuff, Snack | Geen reacties »

Copy JVC Everio .MOD files on Linux

By Bart | June 4, 2012

I patched a little Python script to correctly copy .MOD/.MOI files to MPEG-2, including the aspect ratio bug in the format: http://blog.friesoft.nl/files/sdcopy.py. It is tested and works on Ubuntu 12.04.

Topics: Geekstuff | Geen reacties »

Adobe Flex snack: Error #2048: Security sandbox violation

By Bart | May 22, 2012

If you are building a Adobe Flex application that uses sockets, you have to send the policy-file-request, or crossdomain.xml. A lot of info available on it, except that you need to send a null character at the end of it.

Topics: Geekstuff, Snack | Geen reacties »

Javascript snack: enable both click and doubleclick events on one element

By Bart | May 10, 2012

HTML defines onClick and onDblClick event handlers on all elements. However, if you want to enable both on the same element, something goes wrong. the onClick event gets fired twice! And that is not what we want, so here’s a little Javascript to fix that:

// use these functions to enable *both* onclick and 
// ondblclick on one element:
// usage: onclick="singleClick(someFunction)" 
//        ondblclick="doubleClick(otherFunction)"

singleClickTimeout = null;
function singleClick(fcn) {
    if (singleClickTimeout == null) {
        singleClickTimeout = setTimeout(function() {
            singleClickTimeout = null;
            fcn();
        }, 500);
    }
}
function doubleClick(fcn) {
    if (singleClickTimeout != null) {
        clearTimeout(singleClickTimeout);
        singleClickTimeout = null;
    }
    fcn();
}

Topics: Geekstuff, Snack | Geen reacties »

Javascript snack: new Date() with time zone

By Bart | February 9, 2012

To set a time, use the (very convenient) Dat eobject:

var now = new Date();

If you want to set a certain date, use:

var someDate = new Date("yyyy-mm-ddThh:mm:ss+hh:mm");

e.g.:

var someDate = new Date("2012-05-17T00:00:00+02:00");

For May 17th, 2012 00:00:00, CEST. Notice (and I just found that out), not all browsers take the same timezone when it is not supplied. To be sure, use the time zone in your date definition.

Topics: Geekstuff, Snack | Geen reacties »

(Nederlands) Haiku

By Bart | January 10, 2012

Sorry, this entry is only available in Nederlands.

Topics: Lief dagboek, Verhalen | Geen reacties »

Android-dev-snack: what if R.id. doesn’t seem to be right anymore?

By Bart | November 1, 2011

In Eclipse, with the ADT plugin for Android development, what to do if your widget-IDs seem to be all over the place? What if that TextEdit suddenly seems to have jumped over two TextView widgets? Simply running a “Clean project” fixes it. It seems to be triggered by a lot of dragging, dropping and cutting and pasting in the UI-editor.

Still have to figure out how that R.id.<id> is linked to the XML file…

Topics: Geekstuff, Snack | Geen reacties »

Bye bye Facebook

By Bart | October 3, 2011

Ja hoor, vandaag al mijn social media profielen sites verwijderd. Facebook exit, Google+ exit. Ik ben er klaar mee. Wat mij betreft is de hype voorbij en kostte het alleen maar tijd. Ik kreeg er niks voor terug. Ow, en al dat privacy gedoe stond me vanaf het begin al niet aan.

Dus vanaf nu ben ik nog te volgen op Twitter, LinkedIn en dit weblog. Verder niks meer. En weet je? Het voelt als een bevrijding. Geen status updates meer moeten posten, niet meer in de gaten houden wat je ‘vrienden’ (ik heb ze gevraagd te helpen verhuizen, niks nie geen reacties denk) aan het doen zijn.

In de tijd van IRC, fora en een blog was het toch overzichtelijker. Daar ben ik dus weer terug. Overigens ben ik benieuwd of ik nu een trendsetter ben, of een loner. De tijd zal het leren.

Topics: Gelul in de ruimte, Lief dagboek, Opinie | 2 Reacties »


« Voorgaande Artikelen