Sunday, July 25, 2010

Android: Display dialogs in fullscreen

Ever wondered how to maximize a dialog to the screen's full size? The first thing probably everyone would naturally do is to set

android:layout_width="fill_parent" android:layout_height="fill_parent"
in your mydialog.xml layout file. However, that doesn't seem to have any effect at all.

The solution that works is not much more complicated than that, but unfortunately not that easy to think of in the first place. What you have to do is, when you setup your Dialog in code, you have to set (again) your layout (as you do in the .xml file) after you set your content view.
I don't know why it works when set in code and not when set in the .xml file, but for now I just accept that it does. If you know the answer to this please let me know in the comments.

Thursday, June 17, 2010

Android: open new Activity as Dialog

Did you ever have the problem that your pop-up dialog was so complex that it messed its parent's activity's code? There is a very simple solution to that. Just create the whole thing as a new activity class and change them theme to Theme.Dialog in your AndroidManifest.xml for that specific activity:

And the result should looking similar to this:

That's a really quick & dirty hack. However, the most important thing I learned out of this "accident" is, that I now know how I can easily customize the basic look of my activity screens, just by changing the android:theme attribute in the activity element of the AndroidManifest.xml.

Saturday, May 15, 2010

iPhone: "abuse" UITabBar to provide simple, good looking buttons

The iPhone's UITabBar can also be used to provide as a simple, good looking solution adding extra functionality to the current screen. Similar to what Android tries to solve with the menu button, which, when selected pops up a menu providing extra functionality. Since the iPhone doesn't have a menu I thought why not use a UITabBar for that, which saves you a lot of time developing your own custom solution.

UITabBar items "abused" as buttons
Each UITabBar has a UITabBarDelegate, which requires you to implement
(void)tabBar:(UITabBar *)tabBar didSelectItem:(UITabBarItem *)item
for example like this:


However, there is one little annoyance. Whenever you click a button on a UITabBar it stays selected. Which is the right thing to do, when you actually use it as a tab bar. But since we are not, we have to add a little line of code in our UITabBarDelegate method:
[self.localNavigation setSelectedItem:nil];
This line makes sure, that as soon as we select a tab item in the UITabBar it immediately gets deselected again, with the result that it appears to the user like a normal button behavior.

Warning: this solution worked perfectly for me in the past. However, Apple might reject future applications, since you're giving the UITabBar a totally different purpose as it was originally meant for.

Thursday, March 25, 2010

Chrome: adding shortcuts to bookmarks

In Firefox you can associate shortcuts to your bookmarks, which I used to:

  • quickly open frequently used sites, e.g. Gmail, Facebook, etc. or
  • to open a page with a specific topic, e.g. the Wikipedia article about "Linux" or
  • to trigger a custom search or query, e.g. on Google Translate
Now that I recently switched from Firefox to Chrome I imported my Firefox bookmarks and still had the shortcuts available, but when I edited my bookmarks I couldn't find the option to modify the shortcuts, neither could I add new shortcuts.

After playing around a while I finally found something called "Search Engines", which is a bit of a misleading name, but does exactly the same as bookmark shortcuts in Firefox.

You get there by right clicking on the URL bar / search bar and selecting Edit Search Engines...

Now, when you click on Add you get a form like this, where Keyword is the shortcut you use in the address bar, URL the site where you wanna go with %s as a placeholder for your search term.



In this case to get to the Wikipedia article for "Linux" I would just have to enter "wiki Linux" in the address bar and I get directly there. 

In case you wanna go to a static URL like Gmail you just don't use the %s placeholder and enter the URL completely.

Sunday, March 7, 2010

Andoid: Eclipse error "Conversion to Dalvik format failed"

If you receive this error in Eclipse when compiling large .java files or using big .jar libraries

[2009-03-30 17:28:14 - Dex Loader] Unable to execute dex: null
[2009-03-30 17:28:14 - MyProject] Conversion to Dalvik format failed: 
Unable to execute dex: null 
then add the following to your eclipse.ini and the problem should be fixed:
-Xms128m
-Xmx512m
Still problems? Increase these values and try again.

iPhone: debugging EXC_BAD_ACCESS errors

After developing for iPhone and Android for quite some time now I consider myself an advanced developer on both these mobile platforms. But even though I left the beginner stage, sometimes things still don't work as they should (or at least as I expected) and I thought sharing some of my learning experiences would help other developers to lessen their pain.

One of the biggest pains (besides Objective-C itself) is definitely the memory management on the iPhone. Luckily we don't have this problems on Android, due to the fact of using Java and garbage collection, which makes programming an ease (almost!) and enables you to focus on creating something rather than wasting a lot of time debugging. However, Apple decided not to include garbage collection for the iPhone, even though it's available within their frameworks and is actually used for Mac development. I won't elaborate much more on the pros and cons of Objective-C's memory management and the object ownership concept, since a lot of other bloggers ranted about that topic already too many times before me, but rather give you some useful tips to reduce the time you spend debugging.

The most common problem you will have is probably an EXC_BAD_ACCESS error, which occurs when you try to release memory that has already been released. This could be the reason if for example you try

  • to release an object, which you don't own
  • to release an object, which is in the autorelease pool
  • to release an object, which has the "assign" property instead of "retain"

Swype beta for Android

After having been using the leaked version of Swype for a while, I'm happy to hear that they finally provide an official beta for Android.

If you haven't heard about Swype, yet, it's an innovate new way of rapidly entering text on mobile touch screen devices.


I highly recommend that you give it a try. I cannot image going back to the standard Android or iPhone keyboard, even though they're pretty good themselves. Check out this video comparing Swype with a standard touch keyboard.

Sunday, February 21, 2010

My Tracks for Google Android

Have been playing around with My Tracks for Google Android this weekend. It's an application that tracks your location on a map (e.g. during a bike tour or a day of skiing down the slopes or whatever else you can think of) and monitors real time statistics like time, distance, speed and elevation. I didn't log the whole thing, because I was already on low battery when I left the house, but this should give you a pretty good idea of how it works. Here are the two links to view the route: [ Google Maps | Google Earth ]. FYI, I had my Nexus One almost the whole time in my pocket. For that I'm pretty surprised with the resulting accuracy of my track.

My Tracks doesn't support adding pictures, yet, but you can easily do that with Google's My Maps Editor for Android. And other than playing around with new mobile technology all day long I was also able to enjoy another beautiful "winter" day in Barcelona (see pictures here).

Saturday, January 23, 2010

Android: providing different layout resources for older versions

To provide backward compatibility with older phones still running on Android 1.5 you might have to provide separate layout resources for Android 1.5 and Android 1.6+. Especially when dealing a lot with RelativeLayout, which was basically crap before Android 1.6.

Instead of having one res/layout folder we will create two new folders:

  • res/layout-v3 for Android 1.5
  • res/layout-v4 for Android 1.6 and higher
Now move all your files to res/layout-v3 and test your application on various phones and emulators (which are running different Android versions). Whenever you see that there's a non-acceptable difference in the layout copy the responsible .xml-file to the res/layout-v4 folder and modify the file in both folders so that they work for Android 1.5 and Android 1.6 and higher again. Android will then pick the right layout resource during runtime depending on its current firmware version.

Bug in Android 2.0

There seems to be a bug in Android 2.0. Instead of picking the resource from res/layout-v4 as it should and if it doesn't find it there then from res/layout-v3, it expects the the resource wrongly in the default res/layout folder. To make it work you should rename res/layout-v3 back to res/layout again (or just create a symlink). The second problem or bug that comes with it, is to provide the special resources for Android 2.0 or higher. Instead of providing those in res/layout-v5 Android 2.0 expects wrongly res/layout-v6. So just use this instead for now. The bug is fixed in Android 2.0.1, but there are still quite some Android 2.0 phones out there.

I hope this post is not too confusing ;-)

Saturday, November 21, 2009

Android: Custom List Item with nested clickable Button

This tutorial will show you how to add a button (or any other clickable item) to a customized list view item.



In the screenshot above you can see a ListView with custom built items. Each list item consists of
  • TextView for the title
  • TextView for the content
  • RelativeLayout (clickable) consisting of
    • TextView: "For more information click here"
    • ImageView for the arrow icon
We start this tutorial at a point where you should already know how to create your own customized ListViews and Adapters. If you have no clue how to do so please let me know in the comments. If there's a demand I will eventually compile another tutorial about creating custom list items and list adapters in the future.

Saturday, November 7, 2009

Android: Simple HttpClient to send/receive JSON Objects

This tutorial is focused on creating a very simple HTTP client for Google's mobile operating system Android, which then can communicate with a web server and exchange JSON information. I won't go too much into detail, since the code is pretty much self-explaining and already has a lot of comments describing the program flow.

Saturday, October 31, 2009

Android: Custom ListView Selector

The following tutorial will show you how to create a custom list selector as shown in the image below. I use an orange frame around the selected list item in this example, but you can virtually design anything you like.

To make it easier we use the original files for the list selector and transition from the Android SDK as a draft and modify them instead of starting from scratch.

How to enable fake GPS on Android

In order to build a location depend app or to test the behavior of your app at places besides the one you're currently located it is very helpful to use the Android emulator and just set your location manually.

This post  will guide you through the steps of setting up fake GPS on the Google Android emulator

Monday, October 26, 2009

Android: easier click listeners in 1.6

Romain guy just posted a really cool improvement of button click listeners for the Android SDK 1.6 on the official Android Developers Blog.

Instead of having every time this recurring bunch of code to set up a simple click listener you can now just add

<Button android:onClick="myClickHandler" />
to your button element in your layout's XML file.

Finally the code to handle the click is as simple as that:
class MyActivity extends Activity {
  public void myClickHandler(View target) {
  // Do stuff
  }
}

Tuesday, October 6, 2009

Wired-Marker (Firefox Add-on)

A really cool Firefox add-on I recently stumbled upon: Wired-Marker

Wired-Marker is a permanent (indelible) highlighter that you use on Web pages. The highlighter, which comes in various colors and styles, is a kind of electronic bookmark that serves as a guide when you revisit a Web page. The highlighted content is automatically recorded in a scrapbook and saved.



Surprisingly it wasn't really slowing down Firefox as I expected it to be. Maybe that is because all the information is stored in a SQLite database, which also allows you to sync your markers between other computers by using a free Online Storage Service like Dropbox. More details on how to set this up is here.

Wired-Marker is easy to install and to use, but it also offers a lot of different options for the more advanced user.

Personally I prefer a minimalistic approach. I deleted the default preset markers and created just three simple markers with different colors and each linked to a keyboard shortcut:
  • Yellow (ALT+C): just an interesting word or line on a web page, which I want to emphasize from the the other content
  • Orange (ALT+D): important stuff, which I wanna find quickly again.
  • Green (ALT+F): follow-up, for an item that needs more time to continue reading or a lead I'd like to follow.
Overall Wired-Marker is super simple, easy to install and to use. It quickly became one of my favorite daily tools, which I don't wanna miss any more.

Monday, October 5, 2009

Windows 7: Symbolic & Hard Links

If you are coming from the Linux world you are probably familiar with symbolic and hard links. I recently discovered a very similar feature implemented in the NTFS file system, which enables you to create Symbolic Links and Junction Points in Windows Vista and Windows 7 by utilizing the mklink command.

The mklink command is used to create a symbolic link. It has the following command line syntax:

mklink [[/D] | [/H] | [/J]] link target
  • /D – Creates a directory symbolic link. Can also point to a remote SMB network path.
  • /H – Creates a hard link instead of a symbolic link.
  • /J – Creates a Directory Junction. Can only point to directories on the same volume.
  • If no arugement is specified, mklink creates a file symbolic link.
  • link – Specifies the new symbolic link name.
  • target – Specifies the path (relative or absolute) that the new link refers to.
Just like ordinary files and folders, del and rmdir can be used to delete the symbolic links to files and directories respectively.
To delete symbolic link to a file, the following command line syntax can be used:
del filename
  • filename – Specifies the name of the file/symbolic link to be deleted
To delete symbolic link to a folder, the following command line syntax can be used:
rmdir directoryname
  • directoryname – Specifies the name of the folder/symbolic link to be deleted

For those who are interested here's a list of related articles with some more background information about the NTFS file system, Symbolic Links and Junction Points:

  © Blogger template 'Minimalist F' by Ourblogtemplates.com 2008

Back to TOP