tag:blogger.com,1999:blog-51257974209984998202024-03-13T10:08:56.787-03:00Small and AdaptiveTips and good practices on how to create Small and Adaptive Java ME applications.
All knowledge posted here comes from my <a href="http://smallandadaptive.blogspot.com/search/label/applications">free applications</a>.Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.comBlogger66125tag:blogger.com,1999:blog-5125797420998499820.post-37303422900001271622012-11-20T17:21:00.001-03:002012-11-20T17:21:28.500-03:00Using NULL constantsI think the Null Object pattern is a good approach to not have null checks in the source code, but I do it a little differently from what is shown at Wikipedia.
First thing - I do not use an interface nor a Null class. Second thing - I use a constant to hold the Null object.
class MyClass {
public static final MyClass NULL = new MyClass();}
If I add a method to MyClass that changes the Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com3tag:blogger.com,1999:blog-5125797420998499820.post-50032023447691937242012-07-17T14:12:00.004-03:002012-07-17T14:12:45.540-03:00One million downloadsIt took five years, but it finally hapenned! July 2012 its the month when my chess board reached ONE MILLION downloads!!
First version went live on July 16, 2007. With it I learned how to create a graphical interface that can adapt to the screen size and wrote my findings at this blog.
Up until now I did now earn a dime with this app, but the pride is big nonetheless!
If you've got a phone that Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-73056875464554811472012-06-26T16:18:00.000-03:002012-06-26T16:18:22.330-03:00Single Canvas TheoryWhen you decide to create a custom UI based on low level graphics you might be tempted to fall into one of the following: have a [Game]Canvas child for each screen or have a single [Game]Canvas child to render all the UI.
I advocate to use a single [Game]Canvas child because we do not how how much memory each [Game]Canvas instance might need. Different JVMs will use more or less memory for [Game]Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-86981549467009735232011-07-19T11:40:00.001-03:002011-07-19T11:42:25.381-03:00Don't use RecordComparatorEven if you try to keep the number of classes to a minimum you must create some classes to represent your entities. More so if you use these entities on IO operations: save on recordStore; send on httpRequest; etc.This tip is for those who do not use/know Floggy and create methods to [de]serialize these entity classes from/to byte arrays:Do not use RecordComparatorWhy? Because this interface Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-68400765604203969262011-04-28T21:00:00.002-03:002011-04-28T21:01:12.982-03:00keyReleased not calledDo not take for granted that a call to keyPress will have a keyReleased counterpart.Yes, Java ME VMs may not call it and the simple tip here is to not rely on keyReleased at all.One exception, however, is when you have a very closed set of target devices and can do manual tests on all of them.Do I need to say to NOT trust an emulator execution?Even in this situation, when would you use Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-80500445479297126642011-04-27T21:56:00.001-03:002011-04-27T21:58:57.508-03:00hasPointerEvents wrong returnTouch enabled handsets are more and more common these days. Some does not even have a keyboard!Custom User Interfaces should adapt to touch screens and, at least, display with bigger selectable items.One easy way to know if your MIDlet is running on a touch enabled handset is to call Canvas.hasPointerEvents.Unfortunately some Java ME Virtual Machines do not return true even if the handset DOES Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-361169009871350212011-04-17T19:00:00.000-03:002011-04-17T19:08:10.176-03:00sizeChanged not calledTo achieve the Single Jar theory we must deal with handsets fragmentation upfront.One special piece of these fragments is the orientation change.Screen orientations are: portrait (height > width) and landscape (width > height).When the change happens the Java Virtual Machine should notify the running MIDlet with a call to sizeChanged method on the currently displayed Canvas.Unfortunately this is Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-29340933899661639612010-12-10T18:00:00.004-03:002010-12-10T18:04:32.498-03:00Touch MenuCros-posted at Technè - Blog de Tecnologia do C.E.S.A.R.Continuing with the details on how to develop touch enabled Java ME applications, today we will see a way of using such screens as input: if the user touchs an area it will trigger an action, like a menu.This menu will also adapt to screen orientation.First lets create a class to represent a menu entry. It knows how to paint the entry and Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-50389670513424608222010-12-09T09:25:00.002-03:002010-12-09T09:32:33.766-03:00Touch Screen supportCros-posted at Technè - Blog de Tecnologia do C.E.S.A.R.More and more cell phones have touch screens. And when we hear about them the first thing that we think are the most expensive smartphones. Big screens and amazing computer power.But there are also feature phones with such screens. And amongst them there is a lot supporting Java ME. So, how do you enable an application to get the user's "Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-37884267524645161272010-12-07T16:22:00.003-03:002010-12-07T16:29:06.626-03:00Bar ChartCros-posted at Technè - Blog de Tecnologia do C.E.S.A.R.When developing a mobile application one must consider screen size fragmentation. If Apple have only two screen sizes for iPhone until now, this is the exception. All other manufacturers vary the screen sizes a lot.To make developers life easier each technology provides widgets and ways to combine them. But there are times when you need an Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-37128564783128582912010-11-13T07:27:00.009-03:002010-11-13T07:42:42.824-03:00XML Data BindingCross-posted (in Portuguese) at Technè - Blog de Tecnologia do C.E.S.A.R.It is an easy task to load XML data as Java Objects if you are using SE or EE versions. You can use, for example, JAXB or Castor. Is it possible to do it as easily on Java ME? Yes, let me show you how.The first restriction we have to face is the reduced number of reflection features available on CLDC. It is not possible to Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-37009082399937185732010-11-09T21:19:00.003-03:002010-11-09T21:27:20.935-03:00Check for updatesCross-posted (in Portuguese) at Technè - Blog de Tecnologia do C.E.S.A.R.Nowadays it is very common to have a "Check for updates" feature on mobile apps. Specially if they are Android or iPhone apps, because their platform already provide this. And what about Java ME apps? Here is a way.First we need an official site and a public file in it. For example, http://mysite.com/myapp.txt. This file Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-46116079128216797572010-11-07T08:11:00.001-03:002010-11-07T08:13:58.086-03:00Adding Crash ReportCross-posted (in Portuguese) at Technè - Blog de Tecnologia do C.E.S.A.R.Using only Twitter API for Java ME it is possible to add Crash Report to a Java ME application.Crash Report is a set of information with details of an issue that made an application stop working.Operating Systems like Microsoft Windows, Mac OS and Linux distros have this feature.We browsers like Mozilla Firefox and Google Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-61399644843198113822010-10-22T16:40:00.001-03:002010-10-22T16:42:42.980-03:00Twitter API for Java MECheck out my first post accepted at Technè - Blog de Tecnologia do C.E.S.A.R.http://techne.cesar.org.br/twitter-api-para-java-me/ (Portuguese)Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-50086532240904149162010-09-25T14:13:00.004-03:002010-09-25T14:20:35.690-03:00Nine Slice ScallingBelow is the public contract (constructor and methods) of my NineSliceImage component. It may be used to draw Buttons, Title bars and Frames.import javax.microedition.lcdui.Graphics;import javax.microedition.lcdui.Image;public class NineSliceImage { public NineSliceImage (Image img, int vMargin, int hMargin) { ... } public void paintFrameAround (Graphics g, int x, int y, int width, int height) Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-39550625607254780752010-08-22T21:28:00.003-03:002010-08-22T21:32:51.994-03:00Manipulate PNG paletteI am not a graphic designer, thus I don't know how to create fancy icons/images for my apps and Microsoft Paint is just enough for my skills.For all my apps I've used black-and-white PNG files without transparency and that is ok, but... black and white?! I should be adding colors.Image class does not have a method to easily change colors. A workaround could be to call getRGB method and iterate Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-1659489185819437342010-07-11T18:11:00.001-03:002010-07-11T18:14:55.745-03:00Blog audience 2T10From 2010 March, 15 to June, 14 this blog had 215 visits from 54 countries.The top 10 countries are:Brazil: 34Indonesia: 25India: 15United States: 11Italy: 7Russia: 7Germany: 6Portugual: 6Poland: 4Romania, United Kingdom, Sweden and Canada has left the top 10 list. New to the list are Italy, Russia and Poland.Related topics:Blog audience 1T10Blog audienceKnow your audienceTelmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-61409491344944985522010-07-10T18:49:00.000-03:002010-07-10T18:52:35.619-03:00Alert setTimeout FOREVERSo you are showing error messages, but no emails are coming in. Is your application faultless? Or all users do not bother to write down some lines and click send?Maybe your users do not have a chance to see the error message because it was automatically dismissed before they could read it. How can it happen? - you ask.Not calling setTimeout method on an Alert object will leave the timeout as the Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-75468228478193488152010-05-31T22:10:00.000-03:002010-05-31T22:13:52.088-03:00Books: version 1.4Yesterday I shared Books version 1.4, new features are listed below on Related Topics.I also updated my blog entry on Books.Related Topics:Using pointerDragged methodAdapting to sizeChangedAvoiding OutOfMemoryErrorTelmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-37147158256934369822010-04-24T16:48:00.000-03:002010-04-24T16:50:07.361-03:00Avoiding OutOfMemoryErrorSome Java ME applications load all their resources from its own jar file, but other apps load resources dinamically, for example, from a network connection.My Books application can open text files using an Open File Dialog I have created. But what happens if a file is too big to open?If the Java Virtual Machine raises an Exception current version (1.3) will show an error message requesting the Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-75619941605355614272010-04-17T08:47:00.000-03:002010-04-17T08:50:14.312-03:00Using pointerDragged methodSome cell phones do not have a keyboard. They only have a touch screen. In this case, if you have a Canvas screen on your application you will have to rely only on pointer methods.This fact came to me because a user of my Books application have such a phone and sent me an email informing that he could not go back to a previous page.I checked the application source code and found out the reason. Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com2tag:blogger.com,1999:blog-5125797420998499820.post-53941607608353293262010-03-15T12:22:00.001-03:002010-03-15T12:27:16.805-03:00Blog audience 1T10Since 2009 December, 15 this blog had 241 visits from 59 countries.The top 10 countries are:Brazil: 37India: 22United States: 18Indonesia: 12Romania: 8Germany: 8United Kingdom: 6Sweden: 6Portugual: 5Canada: 5Poland, Turkey and Russia has left the top 10 list. New to the list are Indonesia, Romania and Canada.Related topics:Blog audienceKnow your audienceTelmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-28081813447314032432010-03-13T22:23:00.000-03:002010-03-13T22:24:50.133-03:00Adapting to sizeChangedCell phones with accelerometers may automatically change the screen orientation from portrait to landscape.If you use LCDUI screens on your application there is nothing to worry.But if you use Canvas these changes are notified by sizeChanged method.At my Books application I show text in fullscreen landscape.The user will need to rotate the handset to read properly.If the cell phone automatically Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-49400255071900062912009-12-17T06:58:00.002-03:002009-12-17T07:12:00.886-03:00Single Jar theoryThis month there was a Sun Tech Days event at São Paulo, Brazil.I could not be there, but I am thankful they shared the slides.The only presentation about Java ME was JavaME: Building Cool Interfaces with the Lightweight UI Toolkit (PDF document). I think there are also other cool things on Java ME, but the event is a lot smaller than Java ONE and there was more interesting stuff on Java StandardTelmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0tag:blogger.com,1999:blog-5125797420998499820.post-41549948368040205952009-12-15T06:40:00.004-03:002009-12-15T07:10:08.856-03:00Blog audienceSince 26 April 2009 I am following this blog statistics with Google Analytics and it had 566 visiting users (855 pageviews).There are days days when I do not have a single visit, but it usually goes from two to six a day.The most interesting part of the statistics for me is the Map Overlay, where we can see from which part of the wordl the visits came from.Below is the world map with all 54 Telmo Pimentel Motahttp://www.blogger.com/profile/04051227500777659491noreply@blogger.com0