Must say this is a big ball of stress that I can throw back into the void. I began working on the game in October while I had some time off between my old and new job. Always good to take a little time off after giving notice.
If you have an Android phone and like logic puzzles do a search on "Grid Hunt" on the Android Market and give it a shot. The game is free. I decided to go the AdMob route to see how that works. Seems like a good time of the year to release a game. Lots of people will be getting new phones and people will be taking time off so they will have some extra gaming time. I know I hit the market every so often to see if there is something new to play for a few minutes.
Actually writing the game was the easy part. It became a real headache when I tried to tie in AdMob. There is not much in the way of documentation which is very unlike the rest of my Android experience. First off I wrote a game so I was using the full screen. I had forgotten that I plugged my view directly into the activity instead of doing it via the XML file. I put all the AdMob stuff into the XML and of course nothing happened.
I changed the code to use the XML to drive the view which meant a shuffle of some other things as I was not using the XML based constructor. I got that working but no AdMob so I shoved in a simple label and it painted on top of my game screen. I realized my game code was a custom view so I needed to tell the layout manager what my size happened to be. I added the following code:
/**
* We want to take up almost all of the screen
*/
@Override
protected void onMeasure(int width, int height)
{
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int dispWidth = display.getWidth();
int dispHeight = display.getHeight();
setMeasuredDimension(dispWidth, dispHeight - 48);
}
This put the label at the bottom of the screen. I was then able to piddle around with the AdMob code to get it to appear. I really don't remember everything I did to get that to happen. I needed to get some options configured and I finally got some output in the less of reliable Android log window of Eclipse. I was able to get the special code line from the log console to show the test ads.
I configured a private key and used the really handy Eclipse export signed APK menu item and created a nice ready to roll APK.
I wanted to get this rolling tonight but I wanted to clean up the help text and add some separators in the options dialog. I plugged in my phone and it would not install the app! What the heck is going on here? I have been using my phone at work to develop our app there and I have been using IntelliJ. I did find a quick answer on the web. I just need to adjust the time out value in Eclipse. Then it started working again but not until my wife closed the door to the office due to my choice words of "I don't need to to ^%%$# happen to me tonight!"
When I tried to pull up the options screen it crashed. How could this happen? Turns out when I switched to the other XML style view loading I used same variable name hiding the one in the main class. I thought I had that warning enabled in Eclipse but I did not as I had started a new Eclipse workspace when I renamed parts of the project which annoyed SVN. I hate that part of Eclipse, I want my workspaces to all have the same warnings settings. I enabled nearly all warnings, fixed a few of those in the code and did the easy fix for the view issue. Once I figured it out so I was back on my way to having a fully functional app.
The Android Market Website was really easy to use. I plugged in my information and uploaded the file along with screen shots and descriptive text. I knew I had an issue with new ads not appearing but I though that would only happen after it was on the market. I was wrong. Ads still were not working, you got the first one but it never changed. So I checked the AdMob site and set it to override the interval then the ad did not show up at all! I unpublished the app and started doing Google searches.
I found out I have to set the interval which I tried to do in the attrs.xml file but I had no luck there. I never got the other attributes to work via the XML file but I did not really care to override the base colors. Now I needed something to work. I piddled around with that for too long and then found I could just do it directly in code so I set it up for 30 seconds. It worked as I tested the phone via the debug cable so I put it out on the web again after upping the version numbers.
Of course I sent out a note to all my buddies that have Android phones and put an update on my LinkedIn profile. Finally the brain dump on the blog. I sure learned a lot and I still think this is easier than the iPhone hell I have been going through with just getting a developer certificate. I still can't put my iPhone code on a stinking device.
I know I have been using a lot of things I learned from my game development for my work development. I was able to really chug along today at work on the login screen that I am redoing. Now I can take all my market place set up knowledge and use that too. We will not use Ad Mob for the app I am doing at work but if this game makes me a few bucks I am sure I will write a few more apps outside of work and I plan on using ads again. Since I now have real working code to look the next time it should fall into place really easily.
It will be interesting to see what comments I get on the game, how much money I am able to make off of it and how many downloads occur. I have some ideas for a two player mode which would make a really nice update if the games gets a few eyes on it. Always good to have an update after the game has been out a bit and I don't think there are many two player games out there. This will not be two playing at same time but one player solving the board then another player getting the same board and trying to beat the time or each player designing a board for the other to see who can screw the other one up the worst.
Thursday, December 9, 2010
MigLayout Verification plug-in for IntelliJ - what it was like to write it
I am happy to report I have written my first plug-in for IntelliJ. It gets around the issues I reported in a previous post about MigLayout using strings for constraints and those strings are validated at run time. This puts in you the fun situation of writing code, running it, getting an error, fixing it and repeating until you have the constraint syntax correct.
That is no longer an issue if you use the MigLayout Verification plug-in for IntelliJ. I have submitted it to Jet Brains but have not heard back from them as of yet. You can grab it and manually install it from the MigLayout form if you want to give it a shot. Download from MigLayout forum. This will be moved to a permanent spot on his main page soon and hopefully available from JetBrains too.
If you look at the forum you can see the author of MigLayout is an IntelliJ user and is using the plug-in himself. I needed to contact him as I am using MigLayout code in my plug-in and I wanted to make sure that was OK with him per his license agreement. He was very kind and allowed me to use the code meaning the parse logic and errors you get are the exact same as the ones you would get at run time.
What does the plug-in do for you? It allows you to highlight the lines of text in your Java code that use MigLayout, press Alt+Shift+Y and it will find every constraint error in the code showing them to you in a console view. You can click on each error to have it pop to that line of code highlighting the string in error so you can fix it. Notice it is every error so you can quickly clean them all up. It handles layout, row, column and component constraints.
On a side note I am happy I did not try to name this blog based on a language. A lot of blogs are C# Corner or Java Jabbering etc. Since I end up all over the place - Android, iPhone, Java, C#, plug-ins, etc. that would have been pretty misleading.
What was it like to develop an IntelliJ plug-in?
Not easy which is a shame. The big issue was the lack of documentation. I figured IntelliJ had been out for a long time, they are in the process of finalizing the version 10 release and there appear to be a lot of plug-ins so there must be web sites about it and various bits of on-line help. That just was not the case. The only help I found was directly on the IntelliJ forums and a lot of that was many years out of date. See very bottom of this post for code snippets to solve the issues I mention.
I wrote the guts of the program using a MigLayout based test program. A basic text area with a button to parse and a listbox with the errors I found. I needed to get the code processing in place first as I have to skip comments, combine lines of code that span multiple lines, split out the string pieces, do RegEx processing and guess if it really is constraint etc. No need to do all that work with the plug-in overhead. Once I had that running I contacted the MigLayout author to see how he felt about things.
The initial plug-in documentation seemed pretty easy, set up an action, query the editor and parse. I have written Eclipse plug-ins in the past, in fact it was a whole RCP, so I remember how involved that can be. Very powerful but very involved with XML things here and linking three files perfectly via string names to tie it together. This was going to be so much easier.
First thing you can't just developer a plug-in using the out of the box community edition of IntelliJ. You have to install GIT and download the full source project. This is 1g worth of data. It failed on me the first two times. I had to make sure my machine did not come anywhere near going to sleep during the process. After that initial 1g hit was another 1/2g of deltas that got automatically downloaded. GIT is an all or nothing download so it does not restart in the middle if things to awry. It takes a really long time to download. Finally you have to build the program with a simple ant build script. No problem if you have ant installed and configured which I did not but that was easy to do.
It then creates a ZIP file for Windows and the proper images for the other support OS platforms. Honestly if would be nice if they just posted the 80 meg zip file I needed for Windows. This is a fully functional version of IntelliJ along with plug-in SDK support that you install.
You point your running instance to this new instance as the plug-in SDK and you can start code development. So far so good but there is very little sample code to get you started. I did a lot of source code scrounging and using the little bit of on-line help I could fine. I was able to figure out how to get the project, editor and document so I could pull out the selected lines. I found a way to determine what line number I was on and I could run my already functional parser and show the errors in an alert dialog. I wanted a console window.
Others have asked on the forums about the console window and I pieced together various posts to get it working but all I could output was straight text lines. I wanted you to be able to click on them to jump to the spot in the code of the issue. Others had asked the question with no answers. I did my first release to the developers at work without that support. In the end I did figure out how to use the printHyperlink call to do what I wanted.
Hot keys threw me off for a bit too. I misread the dialog and thought you put in two hot keys, a primary and a secondary but it really meant if you put in two the user would have to do them in order. I wanted different hot keys for the default key mapping vs. the Eclipse key mapping I use. I did not figure out how to do that so I finally found Alt+Shift+Y that was free in both mappings. Since access to the feature also appears in the Code menu you can still use it even if that key sequence is not available in your mapping.
Even getting to the name of the currently edited file was not something I was able to find on the forums. I pieced together how to do that too. While doing that I realized there were various deprecation warnings. I like my code to be warning free so I went about fixing those. Remember I said a lot of forum post are years old, many from 2004. I was able to clean up all the warnings and the new code looked better and is easier to read. One clean up just created new deprecation warnings around the console view. I was finally able to piece all that together and ended up with warning free.
The hyperlink stuff into the console window was confusing. Each hyperlink you create needs to implement an interface but the only call you get is public void navigate(Project project). You don't even get the text they clicked on! I was hoping to have one generic link click listener but instead I had to create a new object that implements the interface taking the text of the link in the constructor. From there I had to figure out all the editor document access to pull lines and selection model processing to scroll to and highlight the errors.
I am very happy with the end results and will get a lot of use out of the plug-in as I am sure others in the office and hopefully you will too. I don't have a good code formatter for blogspot so below are my code chunks that may help other plug-in developers.
UPDATE: The plug-in has been accepted by IntelliJ and is available from their website. MigLayout Verifier at JetBrains
Imports I am using for all of the below
import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
Creating an associated console view in actionPerformed(AnActionEvent e) method
if (project != null) {
ToolWindowManager manager = ToolWindowManager.getInstance(project);
ToolWindow window = manager.getToolWindow(id);
if (window == null) {
TextConsoleBuilderFactory factory = TextConsoleBuilderFactory.getInstance();
TextConsoleBuilder builder = factory.createBuilder(project);
view = builder.getConsole();
window = manager.getToolWindow(id);
if (window == null) {
window = manager.registerToolWindow(id, true, ToolWindowAnchor.BOTTOM);
ContentFactory contentFactory = ServiceManager.getService(ContentFactory.class);
Content content = contentFactory.createContent(view.getComponent(), "", false);
window.getContentManager().addContent(content);
window.show(new Runnable(){
public void run() {
// Nothing for us to do here
}
});
}
}
}
Jumping to a line of code and highlighting text on that line
That is no longer an issue if you use the MigLayout Verification plug-in for IntelliJ. I have submitted it to Jet Brains but have not heard back from them as of yet. You can grab it and manually install it from the MigLayout form if you want to give it a shot. Download from MigLayout forum. This will be moved to a permanent spot on his main page soon and hopefully available from JetBrains too.
If you look at the forum you can see the author of MigLayout is an IntelliJ user and is using the plug-in himself. I needed to contact him as I am using MigLayout code in my plug-in and I wanted to make sure that was OK with him per his license agreement. He was very kind and allowed me to use the code meaning the parse logic and errors you get are the exact same as the ones you would get at run time.
What does the plug-in do for you? It allows you to highlight the lines of text in your Java code that use MigLayout, press Alt+Shift+Y and it will find every constraint error in the code showing them to you in a console view. You can click on each error to have it pop to that line of code highlighting the string in error so you can fix it. Notice it is every error so you can quickly clean them all up. It handles layout, row, column and component constraints.
On a side note I am happy I did not try to name this blog based on a language. A lot of blogs are C# Corner or Java Jabbering etc. Since I end up all over the place - Android, iPhone, Java, C#, plug-ins, etc. that would have been pretty misleading.
What was it like to develop an IntelliJ plug-in?
Not easy which is a shame. The big issue was the lack of documentation. I figured IntelliJ had been out for a long time, they are in the process of finalizing the version 10 release and there appear to be a lot of plug-ins so there must be web sites about it and various bits of on-line help. That just was not the case. The only help I found was directly on the IntelliJ forums and a lot of that was many years out of date. See very bottom of this post for code snippets to solve the issues I mention.
I wrote the guts of the program using a MigLayout based test program. A basic text area with a button to parse and a listbox with the errors I found. I needed to get the code processing in place first as I have to skip comments, combine lines of code that span multiple lines, split out the string pieces, do RegEx processing and guess if it really is constraint etc. No need to do all that work with the plug-in overhead. Once I had that running I contacted the MigLayout author to see how he felt about things.
The initial plug-in documentation seemed pretty easy, set up an action, query the editor and parse. I have written Eclipse plug-ins in the past, in fact it was a whole RCP, so I remember how involved that can be. Very powerful but very involved with XML things here and linking three files perfectly via string names to tie it together. This was going to be so much easier.
First thing you can't just developer a plug-in using the out of the box community edition of IntelliJ. You have to install GIT and download the full source project. This is 1g worth of data. It failed on me the first two times. I had to make sure my machine did not come anywhere near going to sleep during the process. After that initial 1g hit was another 1/2g of deltas that got automatically downloaded. GIT is an all or nothing download so it does not restart in the middle if things to awry. It takes a really long time to download. Finally you have to build the program with a simple ant build script. No problem if you have ant installed and configured which I did not but that was easy to do.
It then creates a ZIP file for Windows and the proper images for the other support OS platforms. Honestly if would be nice if they just posted the 80 meg zip file I needed for Windows. This is a fully functional version of IntelliJ along with plug-in SDK support that you install.
You point your running instance to this new instance as the plug-in SDK and you can start code development. So far so good but there is very little sample code to get you started. I did a lot of source code scrounging and using the little bit of on-line help I could fine. I was able to figure out how to get the project, editor and document so I could pull out the selected lines. I found a way to determine what line number I was on and I could run my already functional parser and show the errors in an alert dialog. I wanted a console window.
Others have asked on the forums about the console window and I pieced together various posts to get it working but all I could output was straight text lines. I wanted you to be able to click on them to jump to the spot in the code of the issue. Others had asked the question with no answers. I did my first release to the developers at work without that support. In the end I did figure out how to use the printHyperlink call to do what I wanted.
Hot keys threw me off for a bit too. I misread the dialog and thought you put in two hot keys, a primary and a secondary but it really meant if you put in two the user would have to do them in order. I wanted different hot keys for the default key mapping vs. the Eclipse key mapping I use. I did not figure out how to do that so I finally found Alt+Shift+Y that was free in both mappings. Since access to the feature also appears in the Code menu you can still use it even if that key sequence is not available in your mapping.
Even getting to the name of the currently edited file was not something I was able to find on the forums. I pieced together how to do that too. While doing that I realized there were various deprecation warnings. I like my code to be warning free so I went about fixing those. Remember I said a lot of forum post are years old, many from 2004. I was able to clean up all the warnings and the new code looked better and is easier to read. One clean up just created new deprecation warnings around the console view. I was finally able to piece all that together and ended up with warning free.
The hyperlink stuff into the console window was confusing. Each hyperlink you create needs to implement an interface but the only call you get is public void navigate(Project project). You don't even get the text they clicked on! I was hoping to have one generic link click listener but instead I had to create a new object that implements the interface taking the text of the link in the constructor. From there I had to figure out all the editor document access to pull lines and selection model processing to scroll to and highlight the errors.
I am very happy with the end results and will get a lot of use out of the plug-in as I am sure others in the office and hopefully you will too. I don't have a good code formatter for blogspot so below are my code chunks that may help other plug-in developers.
UPDATE: The plug-in has been accepted by IntelliJ and is available from their website. MigLayout Verifier at JetBrains
Imports I am using for all of the below
import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;
Creating an associated console view in actionPerformed(AnActionEvent e) method
if (project != null) {
ToolWindowManager manager = ToolWindowManager.getInstance(project);
ToolWindow window = manager.getToolWindow(id);
if (window == null) {
TextConsoleBuilderFactory factory = TextConsoleBuilderFactory.getInstance();
TextConsoleBuilder builder = factory.createBuilder(project);
view = builder.getConsole();
window = manager.getToolWindow(id);
if (window == null) {
window = manager.registerToolWindow(id, true, ToolWindowAnchor.BOTTOM);
ContentFactory contentFactory = ServiceManager.getService(ContentFactory.class);
Content content = contentFactory.createContent(view.getComponent(), "", false);
window.getContentManager().addContent(content);
window.show(new Runnable(){
public void run() {
// Nothing for us to do here
}
});
}
}
}
Jumping to a line of code and highlighting text on that line
public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(PlatformDataKeys.EDITOR);
String findMe = "Text to find on line"
int line = {line in document you are processing - 1 based}
int lineStart = editor.getDocument().getLineStartOffset(line - 1);
int lineEnd = editor.getDocument().getLineEndOffset(line - 1);
TextRange textRange = new TextRange(lineStart, lineEnd);
String lineText = editor.getDocument().getText(textRange);
int pos = lineText.indexOf(findMe);
if (pos != -1) {
SelectionModel selModel = editor.getSelectionModel();
selModel.setSelection(lineStart + pos, lineStart + pos + findMe.length());
ScrollingModel scrollModel = editor.getScrollingModel();
scrollModel.scrollTo(new LogicalPosition(line - 1, col), ScrollType.MAKE_VISIBLE);
}
Getting file name of active editor
public void actionPerformed(AnActionEvent e) {
VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
String fileName = virtualFile.getName()
Getting selected text and line where it starts
public void actionPerformed(AnActionEvent e) {
Editor editor = e.getData(PlatformDataKeys.EDITOR);
SelectionModel selModel = editor.getSelectionModel();
int curLine = editor.getDocument().getLineNumber(selModel.getSelectionStart());
String selText = selModel.getSelectedText();
Saturday, November 20, 2010
MigLayout - you really should try it
At my new job they used the NetBeans GUI editor to create their panels / dialog boxes. At some point they started to use MigLayout now want to replace all the existing panels. I started with around 220 and now have about 160 to convert.
So why use MigLayout? Why not GridBagLayout or one of the other Swing layouts? My previous job used GridBayLayout for everything even when a very simple BorderLayout would work. I wanted them to switch to MigLayout but it never happened. I have used MigLayout for a few of my side projects and I really like it.
MigLayout Pros:
setLayout(new MigLayout("ins 5", "[grow]", "[][grow][]");
add(new JLabel("Enter comments:", "wrap");
add(textAreaScrollPane, "growx, growy, wrap");
add(okButton, "gapabove 10, split 2, aligny right, sg btn, tag ok");
add(cancelButton, "sg btn, tag cancel");
This would be a standard comment entry dialog with a label telling you want to enter, a text area in a scrollpane that grows vertically and horizontally to fill the space and the [OK] and [Cancel] buttons that are the same width right justified in the dialog box. The buttons are tagged so each OS can swap the order if needed. I put a 10 pixel gap above the [OK] [Cancel] button area to separate it a bit from the text area. The "sg btn" just puts them both in the same size group named "btn" you can name it whatever you want and have as may different size groups as you need. This is a tiny example. I have layouts at work with over 50 controls in them, everything is handled perfectly and all of it sizes as the user sizes the dialog box with no problems.
See a bunch of funky numbers in there? See me incrementing rows and columns? Nope, pretty clean stuff. Check out the MigLayout website to find out more. I am not associated with the program in any manner other than being a happy user for many years.
So why use MigLayout? Why not GridBagLayout or one of the other Swing layouts? My previous job used GridBayLayout for everything even when a very simple BorderLayout would work. I wanted them to switch to MigLayout but it never happened. I have used MigLayout for a few of my side projects and I really like it.
MigLayout Pros:
- Handles all your layout needs - if you draw it you can lay it out
- Very simple to learn - string driven
- Easy to read even if another developer did the initial layout
- Very concise making for compact code
- Will handle Mac vs. PC differences in button layout ([Cancel] [OK] vs [OK] [Cancel])
- Handles high DPI settings
- Will handle insets for each OS (also a con, see below)
- Easily lets you keep a set of controls to be the same size. You can have all buttons in a panel be the same width by putting them in a size group
- Add special gaps to any side of a control. For some layouts you may want a little extra spacing above or below a control
- Handles insets for each OS but the Mac uses large insets with can throw off look and will cause issues if you use setSize in your code for a dialog box. You can override the insets so you get the same look on every OS
- Since it is string based you will not find out if you typed something in wrong until run time. Of course you are going to run the application anyway to make sure you layout is fine but your code is not validated by the compiler which is something you get used to with the base layouts
- Another JAR file to include in your download
setLayout(new MigLayout("ins 5", "[grow]", "[][grow][]");
add(new JLabel("Enter comments:", "wrap");
add(textAreaScrollPane, "growx, growy, wrap");
add(okButton, "gapabove 10, split 2, aligny right, sg btn, tag ok");
add(cancelButton, "sg btn, tag cancel");
This would be a standard comment entry dialog with a label telling you want to enter, a text area in a scrollpane that grows vertically and horizontally to fill the space and the [OK] and [Cancel] buttons that are the same width right justified in the dialog box. The buttons are tagged so each OS can swap the order if needed. I put a 10 pixel gap above the [OK] [Cancel] button area to separate it a bit from the text area. The "sg btn" just puts them both in the same size group named "btn" you can name it whatever you want and have as may different size groups as you need. This is a tiny example. I have layouts at work with over 50 controls in them, everything is handled perfectly and all of it sizes as the user sizes the dialog box with no problems.
See a bunch of funky numbers in there? See me incrementing rows and columns? Nope, pretty clean stuff. Check out the MigLayout website to find out more. I am not associated with the program in any manner other than being a happy user for many years.
Thursday, November 11, 2010
Objective C is like programming with the dinosaurs
I finally got the HTML / GZIP / XML parsing to work on the Mac. Do you know what the problem was? I was not using the same version of the TouchXML code as the person who did that left. I described some of those issues in the last post.
This morning I downloaded an even newer version of TouchXML figuring that was the issue. It still crashed. I installed Wireshark on my PC and on the Mac. I though maybe the server call was hosed so I looked at the packets and they were fine. That meant it was the code at fault. Another developer and I worked on tracing through things and figuring out the odd way you have to query the contents of variables. If I would have known how to do that earlier I would not have messed with Wireshark.
For me it is hard to fathom why the XCode IDE is so behind the times. It is just not anywhere near as powerful as IntelliJ, Eclipse, NetBeans, Delphi, Borland C++ or Visual Studio. It is not that I am not a Mac guy it is just that I have used a lot of very nice IDEs. Have Mac developers not used other IDEs? Eclipse and IntelliJ are available on the Mac, I have used both on the Mac. They work just as well on that platform as they do on the PC. XCode is crappy. It does not have may hot keys, it does not support tabbed files, it loves to pop up all kinds of windows and the debugger stinks.
I just want to see the contents of my variables but it does not show them even things as simple as string don't show up. I used the GDB window to type "p (char *)[(NSString *)[element data] UTF8String] to see the data in a String! This is just crazy to me. In Java or C# I just hover over the variable and I see the contents. Even if it is just a NSString I still have to do "p (char *)[data UTF8String]. I had some really deep variables and it was a real pain to type all the typecasting to get any data out of them.
The IDE works, the debugger works, it is just a pain to get to your data.
Getting to the actual issue - the debug window was trying to tell me the problem. I thought it was crashing in a method but it turns out the method did not exist. Of course I am used to the compiler telling me with a very obvious compiler error not having this happen at run time in a debugger window. The new version of TouchXML changed from childElements to children and elementCount to childCount. I thought it was crashing in the childElements call getting back 0 elements thus annoying the loop. This is due to Objective C being a dynamic language. Part of my learning experience but man was it an annoying experience.
This is a bizarre situation, I was upgrading by accident as I had no idea what version the original developer used. Normally you would know you are upgrading and when the debugger complained you would spot the problem quickly. I was just happy I was able to get things to compile initially. I thought that meant I had the proper TouchXML code.
Things are not all rosy still. It is giving me back blank strings when I request the "name" for one of my XML items. I will have to chase that down too. Not crashing, just a blank string. No idea what is going on there. Just getting to a variable with no depth is bad but getting to a collection of things is going to be a major hassle. I hope I can find it quickly in the morning. Probably just leads to other issues and I am not going to trust the code until I can run it through all of its paces.
I will check it all in, including the new TouchXML classes tomorrow if I can get the XML strings to display. It is making us wonder if it would have been better to start this application from scratch instead of trying to update the code. That is pretty sad actually. Not something that I have done in other languages in a long time, just punted, unless the code was just super crappy. I think the code is generally OK it is the IDE and the language this is fighting me.
This morning I downloaded an even newer version of TouchXML figuring that was the issue. It still crashed. I installed Wireshark on my PC and on the Mac. I though maybe the server call was hosed so I looked at the packets and they were fine. That meant it was the code at fault. Another developer and I worked on tracing through things and figuring out the odd way you have to query the contents of variables. If I would have known how to do that earlier I would not have messed with Wireshark.
For me it is hard to fathom why the XCode IDE is so behind the times. It is just not anywhere near as powerful as IntelliJ, Eclipse, NetBeans, Delphi, Borland C++ or Visual Studio. It is not that I am not a Mac guy it is just that I have used a lot of very nice IDEs. Have Mac developers not used other IDEs? Eclipse and IntelliJ are available on the Mac, I have used both on the Mac. They work just as well on that platform as they do on the PC. XCode is crappy. It does not have may hot keys, it does not support tabbed files, it loves to pop up all kinds of windows and the debugger stinks.
I just want to see the contents of my variables but it does not show them even things as simple as string don't show up. I used the GDB window to type "p (char *)[(NSString *)[element data] UTF8String] to see the data in a String! This is just crazy to me. In Java or C# I just hover over the variable and I see the contents. Even if it is just a NSString I still have to do "p (char *)[data UTF8String]. I had some really deep variables and it was a real pain to type all the typecasting to get any data out of them.
The IDE works, the debugger works, it is just a pain to get to your data.
Getting to the actual issue - the debug window was trying to tell me the problem. I thought it was crashing in a method but it turns out the method did not exist. Of course I am used to the compiler telling me with a very obvious compiler error not having this happen at run time in a debugger window. The new version of TouchXML changed from childElements to children and elementCount to childCount. I thought it was crashing in the childElements call getting back 0 elements thus annoying the loop. This is due to Objective C being a dynamic language. Part of my learning experience but man was it an annoying experience.
This is a bizarre situation, I was upgrading by accident as I had no idea what version the original developer used. Normally you would know you are upgrading and when the debugger complained you would spot the problem quickly. I was just happy I was able to get things to compile initially. I thought that meant I had the proper TouchXML code.
Things are not all rosy still. It is giving me back blank strings when I request the "name" for one of my XML items. I will have to chase that down too. Not crashing, just a blank string. No idea what is going on there. Just getting to a variable with no depth is bad but getting to a collection of things is going to be a major hassle. I hope I can find it quickly in the morning. Probably just leads to other issues and I am not going to trust the code until I can run it through all of its paces.
I will check it all in, including the new TouchXML classes tomorrow if I can get the XML strings to display. It is making us wonder if it would have been better to start this application from scratch instead of trying to update the code. That is pretty sad actually. Not something that I have done in other languages in a long time, just punted, unless the code was just super crappy. I think the code is generally OK it is the IDE and the language this is fighting me.
Tuesday, November 2, 2010
Initial iPhone Development Experience from a PC Java guy
At my new job I get to do some iPhone development. Not new development but some enhancements to an existing application. So far it has been a real uphill battle.
First all the code was not checked in to SVN. That meant I could not compile things after the initial check out. Once I figured out you can click on a red (ie bad) file and do Get Info to see where it thought it should come from I was able to figure the missing images. Luckily they were checked in to the build directory - not that the build directory should be in SVN but it was. The other files are part of TouchXML. I figured that out using Get Info and was able to locate the files on the web. Then all the frameworks links had to be updated as it was originally done with the 3.1 SDK but I have 3.2 and 4.0 installed on the Mac Mini I am working on so I had to point to newer versions.
First I copied the TouchXML files into the ExtraLibs directory as was suggested on the web but figured that was not really optimal for others to use and get from SVN so I moved them under the project. If we do more than one iPhone app that needs to share them we will move them into a shared project but there are no plans to do that at this time.
Next up was figuring out the xCode IDE. It does not appear to be as full featured as Eclipse or IntelliJ. All the basics are there but it seems to be missing some of the advanced things I am used to like multiple open files in tabs and hot key support for various actions. The keyboard actually drives me bonkers. I have a regular PC keyboard hooked up so at least I have a full set of keys and don't have to press extra FN to get to things I use on a regular basis. Pressing HOME - which I expect to go to the start of the line - takes me to the start of the file. I know, I just need to learn Mac keys but old habits are hard to break. I also have to press the Windows Key a lot to do things. Getting the hang of that.
I was able to get the program running in the debugger once I got all the libraries / frameworks linked properly to the project. It would run but accepted no mouse or keyboard input. I finally figured out I was running the emulator in iPad mode. Switching to iPhone mode and it worked. I thought iPad was just a big iPhone, sure app would maybe look ugly but should run. This is not the case. Don't have time to figure that out right now. It is my understanding the last build for the original developer works fine on the iPad. The IDE keeps switching back to iPad mode though which is really annoying. When I start it up to a rectangular emulator I know it is wrong, shut it down, change the target and start it up again.
Once you are familiar with the Android on screen keyboard the iTouch one seems really limited. All keys show as uppercase on the keyboard, the only way to know you are in uppercase is to see glow around the Shift Arrow. Keys only do one thing so you have to switch to symbol mode to get numbers and another mode to get some symbols. On the Android you can just hold down on a key and get to the associated symbol. Plus I love Swype now that I have started to use it. Finally the keyboard on the iTouch totally covers up where I am typing so I can't even see what I am entering and there is no Next button so I have to type then press ENTER then press on the next entry field and type. Data entry, which I have to do for user name and password really stinks. I have an iTouch at home and have used it a lot in the past. After using my Android phone I am much happier with it for data entry. Personal choice.
I finally got it to log in but now it crashes processing some XML data from my HTTP request. The data is coming back in GZIP format, because that is how I asked for it, but I don't think it is getting converted to plain text. I am in the bowels of code trying to figure that out. Maybe the TouchXML handles it or maybe some other code. I could be I got a newer version of TouchXML. The original author is not at the company and no one else has worked with this code. I don't know Objective C and have not worked on the Mac much so I am pretty handicapped at this point. It is a challenge.
For me the whole Android configuration was much easier and since I already know Java I could get up and running pretty quickly. I also knew Eclipse and the PC keyboard allowing me to start typing and experimenting right away. I started on a clean app so I could learn at an easier pace. Finally I did not get tossed a 3rd party library right at the start which meant I could write tiny bits of code and to see what happens without the worry of multiple frameworks in my way. And I comment my code, none of the iPhone source for this app is commented and it is not using iPhone standards for naming conventions making it extra fun.
The app is working on the iTouch. It is the code from the original author. I don't know if my build will run on the iTouch and it is just the emulator that is screwy. I can't put my code on the iTouch as I don't have the signing certificate set up yet. This was a fresh install of the development environment. It is nice the Android does not care about signing for you to run and debug on your device. Maybe the iTouch does not either, just seemed to be annoyed without that set up during my initial attempts. I need to get that working to see if I have to run that way for things to work but I also hate to kill the one working instance I have of the application.
Interface Builder (IB) is also another new area. Since the iPad version was not working I thought maybe some of the event connections got broken and I decide to hook them back up. They were not broken but I did learn a bit about IB while trying to figure that out. I also saw some on the net needed to remove / re-add connections to make things work so I went through that whole experiment. Threw me off when hitting the (+) button did nothing. It is a dragging starting point and not so much a button. You drag over to your classes and it will pop up things you can connect to. All makes sense once you know what to do.
I will say I was a bit surprised at all the information I could find on the Web. I was under the impression that Apple was keeping a lot of information under lock and key. The whole programming on the iPhone was supposed to be shrouded in mystery. I did not find that to be the case. Pretty much anything I did a search on via Google popped up numerous results with quick answers. My misconception probably came from a few years back when a lot of the SDK talk was NDA making it hard to publish much without raising the ire of Apple.
SVN support in xCode seems workable but again does not work as it does in a lot of other PC based IDEs. I was finally able to check in code - mainly the missing files - but it took some doing. I think part of the issue was the build directory files being checked in which annoyed SVN on both the PC and the Mac side of things. There were temp files with ~ in them which SVN does not care for in the least. I cleaned it up using TortoiseSVN on the PC then the PC and Mac both worked. There just are so many more free tools on the PC to get things done in this area and again I have used them in the past. It was easy for me to quickly give up on the Mac, do it on PC and move back to Mac to move forward on the app again.
Am I saying the Android development environment is totally superior to the iPhone or the PC is better than the Mac? No, I was more familiar with everything about the Android environment - IDE, Windows and Java so it was easier for me. Not being a Mac person I am learning a whole new way of looking at things. I am not saying right or wrong, just different and difficult at this stage. I have learned enough programming languages and frameworks in the past that I figure I can get up to speed in a reasonable amount of time. I will learn the keyboard, various short cuts and all the cool stuff you can do with Interface Builder, xCode, Objective C and the iPhone SDK. Right now I am in the newbie struggle mode but I will enjoy the challenge and hope to find many things on the Mac that I miss on the PC.
Maybe I should port my Android game to the iTouch which would give me a balanced picture of development on both sides. I will have to wait until we give the Mac Mini to QA at work and I start using a Macbook for my iTouch development so I can do that conversion at home on my own time. Of course I still have some performance and other tweaks I want to do to my Android version and I would like to finish them up first but starting a new job has meant I am mentally burnt out by the time I get home so final touch up to a game is really not high on my list. Making money from a game is so I should push myself...
First all the code was not checked in to SVN. That meant I could not compile things after the initial check out. Once I figured out you can click on a red (ie bad) file and do Get Info to see where it thought it should come from I was able to figure the missing images. Luckily they were checked in to the build directory - not that the build directory should be in SVN but it was. The other files are part of TouchXML. I figured that out using Get Info and was able to locate the files on the web. Then all the frameworks links had to be updated as it was originally done with the 3.1 SDK but I have 3.2 and 4.0 installed on the Mac Mini I am working on so I had to point to newer versions.
First I copied the TouchXML files into the ExtraLibs directory as was suggested on the web but figured that was not really optimal for others to use and get from SVN so I moved them under the project. If we do more than one iPhone app that needs to share them we will move them into a shared project but there are no plans to do that at this time.
Next up was figuring out the xCode IDE. It does not appear to be as full featured as Eclipse or IntelliJ. All the basics are there but it seems to be missing some of the advanced things I am used to like multiple open files in tabs and hot key support for various actions. The keyboard actually drives me bonkers. I have a regular PC keyboard hooked up so at least I have a full set of keys and don't have to press extra FN to get to things I use on a regular basis. Pressing HOME - which I expect to go to the start of the line - takes me to the start of the file. I know, I just need to learn Mac keys but old habits are hard to break. I also have to press the Windows Key a lot to do things. Getting the hang of that.
I was able to get the program running in the debugger once I got all the libraries / frameworks linked properly to the project. It would run but accepted no mouse or keyboard input. I finally figured out I was running the emulator in iPad mode. Switching to iPhone mode and it worked. I thought iPad was just a big iPhone, sure app would maybe look ugly but should run. This is not the case. Don't have time to figure that out right now. It is my understanding the last build for the original developer works fine on the iPad. The IDE keeps switching back to iPad mode though which is really annoying. When I start it up to a rectangular emulator I know it is wrong, shut it down, change the target and start it up again.
Once you are familiar with the Android on screen keyboard the iTouch one seems really limited. All keys show as uppercase on the keyboard, the only way to know you are in uppercase is to see glow around the Shift Arrow. Keys only do one thing so you have to switch to symbol mode to get numbers and another mode to get some symbols. On the Android you can just hold down on a key and get to the associated symbol. Plus I love Swype now that I have started to use it. Finally the keyboard on the iTouch totally covers up where I am typing so I can't even see what I am entering and there is no Next button so I have to type then press ENTER then press on the next entry field and type. Data entry, which I have to do for user name and password really stinks. I have an iTouch at home and have used it a lot in the past. After using my Android phone I am much happier with it for data entry. Personal choice.
I finally got it to log in but now it crashes processing some XML data from my HTTP request. The data is coming back in GZIP format, because that is how I asked for it, but I don't think it is getting converted to plain text. I am in the bowels of code trying to figure that out. Maybe the TouchXML handles it or maybe some other code. I could be I got a newer version of TouchXML. The original author is not at the company and no one else has worked with this code. I don't know Objective C and have not worked on the Mac much so I am pretty handicapped at this point. It is a challenge.
For me the whole Android configuration was much easier and since I already know Java I could get up and running pretty quickly. I also knew Eclipse and the PC keyboard allowing me to start typing and experimenting right away. I started on a clean app so I could learn at an easier pace. Finally I did not get tossed a 3rd party library right at the start which meant I could write tiny bits of code and to see what happens without the worry of multiple frameworks in my way. And I comment my code, none of the iPhone source for this app is commented and it is not using iPhone standards for naming conventions making it extra fun.
The app is working on the iTouch. It is the code from the original author. I don't know if my build will run on the iTouch and it is just the emulator that is screwy. I can't put my code on the iTouch as I don't have the signing certificate set up yet. This was a fresh install of the development environment. It is nice the Android does not care about signing for you to run and debug on your device. Maybe the iTouch does not either, just seemed to be annoyed without that set up during my initial attempts. I need to get that working to see if I have to run that way for things to work but I also hate to kill the one working instance I have of the application.
Interface Builder (IB) is also another new area. Since the iPad version was not working I thought maybe some of the event connections got broken and I decide to hook them back up. They were not broken but I did learn a bit about IB while trying to figure that out. I also saw some on the net needed to remove / re-add connections to make things work so I went through that whole experiment. Threw me off when hitting the (+) button did nothing. It is a dragging starting point and not so much a button. You drag over to your classes and it will pop up things you can connect to. All makes sense once you know what to do.
I will say I was a bit surprised at all the information I could find on the Web. I was under the impression that Apple was keeping a lot of information under lock and key. The whole programming on the iPhone was supposed to be shrouded in mystery. I did not find that to be the case. Pretty much anything I did a search on via Google popped up numerous results with quick answers. My misconception probably came from a few years back when a lot of the SDK talk was NDA making it hard to publish much without raising the ire of Apple.
SVN support in xCode seems workable but again does not work as it does in a lot of other PC based IDEs. I was finally able to check in code - mainly the missing files - but it took some doing. I think part of the issue was the build directory files being checked in which annoyed SVN on both the PC and the Mac side of things. There were temp files with ~ in them which SVN does not care for in the least. I cleaned it up using TortoiseSVN on the PC then the PC and Mac both worked. There just are so many more free tools on the PC to get things done in this area and again I have used them in the past. It was easy for me to quickly give up on the Mac, do it on PC and move back to Mac to move forward on the app again.
Am I saying the Android development environment is totally superior to the iPhone or the PC is better than the Mac? No, I was more familiar with everything about the Android environment - IDE, Windows and Java so it was easier for me. Not being a Mac person I am learning a whole new way of looking at things. I am not saying right or wrong, just different and difficult at this stage. I have learned enough programming languages and frameworks in the past that I figure I can get up to speed in a reasonable amount of time. I will learn the keyboard, various short cuts and all the cool stuff you can do with Interface Builder, xCode, Objective C and the iPhone SDK. Right now I am in the newbie struggle mode but I will enjoy the challenge and hope to find many things on the Mac that I miss on the PC.
Maybe I should port my Android game to the iTouch which would give me a balanced picture of development on both sides. I will have to wait until we give the Mac Mini to QA at work and I start using a Macbook for my iTouch development so I can do that conversion at home on my own time. Of course I still have some performance and other tweaks I want to do to my Android version and I would like to finish them up first but starting a new job has meant I am mentally burnt out by the time I get home so final touch up to a game is really not high on my list. Making money from a game is so I should push myself...
Monday, October 18, 2010
My first Android app - 18 things I learned
I have written my first Android application. It is a game and it works pretty well on my phone and the emulator. I still want to tweak the sound effects to match the themes and to maybe add a two player mode. Then I will have to decide how to release it on the market. I could go with a lite free version and a small charge paid version or I could go with an ad supported free version. Leaning toward the ad supported free version at this point.
For this discussion the actual app does not matter. I want to cover what I learned. First off I have been programming in Java for a number of years so this is not about Java programming.
1. If you know Java then Android programming feels pretty natural but there are enough differences that you can't make assumptions. I got burnt more than once.
2. Setting up the environment took more than I expected. Everything is out on the web and I was happy to find a lot of on-line support no matter my question. What took a bit was a lot to download for all the Android flavors from 14. to 2.2. I had a little issue finding the proper USB driver so I could debug on my actual phone.
3. Running directly on the phone is faster than using the emulator. Plus it really shows the experience as you use your finger instead of a mouse. When you drag small things around with the mouse they are easy to see, not so much with the finger. The emulator is pretty solid. I did not find differences between what the phone did and what the emulator did.
4. Eclipse is a really nice IDE. Drop files into the drawable directory and they show up as resource IDs automatically. It does have some issues. It did not install the app 100% of the times when I pressed the run button. Could be the phone's fault. I was not totally consistent in swiping to unlock and getting ready to run. I also had the IDE pause when using intellisense, very annoying.
5. The UI does not stop running when you show an alert dialog. Something you get used to in Swing. Not a big deal, once you know that you just code with it in mind and it does make sense. You don't want to freeze the UI waiting on the user.
6. Rectangle is left, top, right, bottom instead of x, y, width, height. Just something to remember.
7. Checkbox uses isChecked and setChecked. I had code to do isSelected and setSelected. The code compiled but did not do what I expected. Made an assumption. Never understood why Swing did not use the properly named methods. Glad Android does.
8. There is no Combobox but there is a Spinner. When I think Spinner I think numbers but the Android Spinner does the work of the Combobox and it does it just fine.
9. Strings belong in string resources, not in your code. I am familiar with this as the Java code I have written has been internationalized. Of course I was not doing that by default, I was hacking together code to make it work but in the end I moved all the strings into string resources.
10. The canvas is pretty powerful. All the features I needed were supported and well named.
11. Not all phones are equal. Different screen resolution being the big one. I have a new phone so I have a big screen. I set the emulator for a smaller screen. I need to tweak the code even more to fit as many screens as possible and to not leave dead space on big screens.
12. You have to draw a lot of icons. I had an icon in my drawable directory but it was not the one I would see on the phone. I had to drop special sized ones in each of the drawable directories to have the proper one to show up. Even at that the proper one only showed up under applications. I had put a short cut to my app on one of my screens but that icon did not change during the next app install. I had to remove it and re-add it to the screen to get it to change. Icons are not a standard Windows size - 256x256, 128x128, 64x64 but are 72x72, 48x48 and 36x36.
13. Playing sound is easy but they don't always play to the end. I need to figure out why that is happening. The API is really straight forward.
14. The amount of on-line information is impressive. The official Android help pages are a great starting point then I would use what I found there to find some solid example code. I was always able to find what I needed with minimal searching.
15. The preference system is simple. I needed to save the sound, flashing and theme settings. Find a quick sample and 5 minutes later it was in place.
16. The options dialog was harder than I thought it should be. This seems like something that nearly every app will need so I thought there would be base classes to handle it. I found what I needed on the web but I can see where we will not see standardized dialogs.
17. I love the menu button, something I wish the iTouch had, but I had to dig around to find images for that area. These images tend to be gray scale with an indented look. Not typical color icons. I wanted to stay consistent with t;he Android look so I found where they are hidden in the SDK samples.
18. I was worried the game would take a long time to write but I got it done in a few days. I had the game running in Swing so the engine was ready to roll. I took the game to a new level with themes and greatly improved graphics. I also put in a help system using a basic alert dialog. I never did a help system with the Swing version as I did not want to learn RoboHelp or some other HTML based help system. I really could have cheated like I did with Android, just never push myself to do it.
All in all I am very impressed with the Android platform. I am late to the game so others have done the hard stuff and published a ton of code samples for me to use. It appears the SDK team learned from various Swing mistakes and weirdness producing a cleaner API. I am sure I forgot a lot of other things I learned, this is just my first Android app and I don't consider the app done. It is fully functional but like any piece of art it never really feels done. I will have to choose a stopping point and release it one day.
Monday, October 4, 2010
I now own and Android phone
Various things came into play but I decided to buy an Android phone. I have the Samsung Galaxy S via T-Mobile, which was my current carrier. First, my son is doing a lot of things with Boy Scouts so he has needed a phone while out in the neighborhood selling popcorn, trash bags and grocery store coupon books. He has also had to borrow others phones numerous times to get hold of us after camp outs.
Second my wife calls me to get web information while she is out and about. Mainly phone numbers and addresses. She has an older BlackBerry but with the new data plan it also gets web access.
Finally I am going to get to do some coding on a project for the Android and just using the emulator seemed like not the way to go. You always want to run on the real hardware if you have the chance.
I have an iTouch so most of the operation is very familiar. Still learning all the ins and outs. Seems to be a solid phone, very fast and I am happy with it so far. Nice to have the web in your pocket all the time. I was able to monitor NFL scores while out shopping yesterday.
Second my wife calls me to get web information while she is out and about. Mainly phone numbers and addresses. She has an older BlackBerry but with the new data plan it also gets web access.
Finally I am going to get to do some coding on a project for the Android and just using the emulator seemed like not the way to go. You always want to run on the real hardware if you have the chance.
I have an iTouch so most of the operation is very familiar. Still learning all the ins and outs. Seems to be a solid phone, very fast and I am happy with it so far. Nice to have the web in your pocket all the time. I was able to monitor NFL scores while out shopping yesterday.
Subscribe to:
Posts (Atom)