Bagels Bands and Bright Backgrounds

by Peter_vdL Motorola 12-30-2011 09:49 AM - edited 12-30-2011 05:00 PM

Friday is “Bagel and Donut Day” at Motorola Mobility, where management fosters the Silicon Valley tradition of providing complimentary baked goods in the breakrooms one day a week.  I’d recently read a note from a mathematician that mentioned you could slice a bagel to form two interlinked rings.  I couldn’t wait to try it, and Bagel Friday was the perfect opportunity.

Here’s how you turn a single bagel into two linked rings.
1.  Using a small paring knife (put down those machetes and cutlasses) open up the hole in the middle of the bagel to a decent size.  Observe that, topologically-speaking, you now have not one torus, but two.  Already, the educational magic has started!  Discard the center section that you just cut out.  Or take it to Radcliffe over in the Motoblur team - he eats everything put in front of him.

2. Spear the bagel vertically, like this.

3.  Extract the knife, and move it to a spot one quarter of the way around the bagel perimeter.   Stab the bagel again, but this time horizontally, like this:

4.  Again, extract the knife.   Now your mission is to extend the first cut over to the second cut, while slowly rotating the knife orientation so that the start and end knife positions exactly match pictures 2 and 3.  It is easier to rotate the knife if you make smooth sawing motions as you rotate, and nearly completely withdraw the blade on each sawcut.  If you’re a klutz like me, you can do this spiraling cut more easily using a hacksaw or jigsaw blade (for maximum safety, wear gloves to protect your hands, and don't start the project until your spouse goes out shopping).

5.   Repeat steps 2 to 4, three more times, each cut following on from the previous with a 90 degree rotation each time, so that when you have cut all the way around the bagel, you have also rotated the knife 360 degrees around the bagel’s thin axis.  Put the bagel on the table, and wiggle it a bit.   It will look like this (if you’re anything like me, you'll go through a few trial-and-errors, and Radcliffe will be filling up on bagel fragments for the rest of the week).

6. Carefully separate the two halves, and observe that you have converted your bagel into two linked rings.  Bask in the appreciative applause of your breakroom co-workers, and point out that you have more surface area for cream cheese than their conventionally-sliced bagels.
The picture above shows a Moebius strip next to the bagel.   If you cut a Moebius strip along the center line (as has been done here), you can open it out into one big circular ring, or fold it back into a strip.  I did the inverse to the bagel.   I took one big ring, and cut a twist into it by clever knife rotation, to end up with two linked rings.  And there’s no need to stop at two - with a fine blade and enough planning, you could get 20 linked rings (not me, you).   Haven't had enough Moebius entertainment yet?  I recommend the excellent "Wind and Mr Ug" video from the mathemusician Vi Hart.

Here’s how you see what's going on with layouts

That’s how I spent my bagel break this morning.  But what I really intended to tell you about today is a tip for debugging layouts.  Android support for layout design has improved a great deal recently, with Google’s purchase last year of the Instantiations company bringing some award-winning GUI Eclipse tools.  If you’re still hand-editing Android xml files, you should update to the latest version of the Android tools and take another look at the “Graphical Layout” tab instead of the raw xml tab.

A screen snapshot from MOTODEV Studio ver 3.1.0, using ADT version 16.0.1

You can now drag and drop Views from the icon trays on the left, onto the xml palette on the right, and reposition them afterwards.  It’s still not perfect, and some xml hand-editing is still usually needed.  But it’s a good start on a complete visual layout editor, and it’s getting better with each ADT release.

Here’s today’s tip.  When you have more than one or two nested layouts, it is sometimes easier to see what’s happening if you can clearly visualize the boundaries of each layout.   Every View, and therefore every ViewGroup, has an xml attribute called android:background which is used to set the drawable resource to use for the View’s background.   You can also set the attribute in Java with


A drawable resource can be as simple as a color, which can be expressed as a 3-byte red-green-blue value, like this:


There’s a table of common RGB values-and-colors here.  When debugging, you can add that one line attribute to each layout manager, using a different RGB value for each, like this.





You usually give names to colors, and use them like this:


   <color name="red">#FF0000</color>

   <color name="yellow">#FFFF00</color>

   <color name="green">#00FF00</color>




    android:background="@color/green"   … >

You typically don’t give the name of a color, but the name of its purpose.  E.g.

<color name=data_highlight>#00FF00</color>

Then, when you need to change the shade, the name remains accurate.  But all that is overkill for a one-liner you’ll remove after debugging.  The first version is easy to add, easy to remove, and it gives great visual clarity to your nested layouts, as this screen snapshot shows.

All that blogging has made me hungry.  I think I’ll go to the break room and see if there are any bagels left.  There probably won't be any - that hound Radcliffe was selfishly tearing into about six of them, earlier.  What are your favorite Android debugging techniques?  The MOTODEV team would love to hear your thoughts on the topic.

Peter van der Linden
Android Technology Evangelist

Post a Comment
Be sure to enter a unique name. You can't reuse a name that's already in use.
Be sure to enter a unique email address. You can't reuse an email address that's already in use.
Type the characters you see in the picture above.Type the words you hear.
About MOTODEV Blog
The MOTODEV blog keeps you updated on mobile app development news from MOTODEV and the Android developer community.

Subscribe to our RSS feed Subscribe via RSS

Follow Us:
Fan MOTODEV on Facebook Join the MOTODEV LinkedIn Group MOTODEV on YouTube

motodev profile

motodev @david_latham what specifically are you trying to download? 7 days ago · reply · retweet · favorite

motodev profile

motodev RT @StackMob: Join StackMob and Salesforce at the MOTODEV Google + Hangout today at noon. Register here 7 days ago · reply · retweet · favorite

motodev profile

motodev G+ Hangout: Migrating ur legacy systems to the cloud & mobile is at @ 12pm PDT today. Join us and bring your questions. #l2cloud 7 days ago · reply · retweet · favorite

Our Blog & Comment Policy
Opinions expressed here and in any corresponding comments are the personal opinions of the original authors, not of Motorola. The content is provided for informational purposes only and is not meant to be an endorsement or representation by Motorola or any other party.

Remember, when you comment, please stay on topic and avoid spam, profanity, and anything else that violates our user guidelines. All comments require approval by Motorola and can be rejected for any reason.

For customer support issues with your Motorola phone go to the Motorola customer support website.