Posts

Showing posts from August, 2011

Sending mock GPS locations from telnet on Windows 7

I was finding it awkward to send GPS mock locations to my emulator when I was debugging with eclipse. I looked up the command line version and it looks pretty nice. I am using windows 7, so you need to enable the telnet client first . Then start a command line (windows, not cygwin or something else). Enter this: telnet localhost 5554 Entering help gives you a list of commands that you can send to your emulator. You can for example simulate calls. Very handy. Enter this: geo fix 10 20 where 10 and 20 in the example are latitude and longitude of a point you want to mock. This format takes altitude too, but it's optional. Simple as that and a bit nicer than having to switch perspectives (ctrl-f8) in eclipse and then clicking the button - which has probably scrolled off the screen somewhere. The telnet client text processing is a bit naff, no history or even cursor keys. Deleting does not work - does on the screen, but muck gets sent to the command processor and you have to s

Refreshing a ListView following a confirm delete dialog

I have started building a database viewer Activity . This will hopefully become something useful for developing and debugging on devices as well as maybe a way to quickly throw CRUD screens together in the future. One of the features I have added is that tapping on an item brings up a confirm delete dialog. If the user clicks Yes  a row from the db is deleted and the underlying activity comes to the front again. The problem I had was that I could not get the list data to refresh. I tried using SimpleCursorAdapter.notifyDataSetChanged() which did not seem to do anything. Same result for ListActivity.onContentChanged() . I decided to pull the cursor and adapter code out of the onResume() (which does not get called when the 'Activity' in front was only a Dialog) and put it in a private method. I then called this from onResume and after I had done my delete - once the user had clicked the Yes  button to confirm. This works fine. I think these problems came down to me using

Google Maps for Android

Made good progress on this today. I had fiddled with it a bit last year, but had not gotten around to it for a long time and expected all to be lost, but not so. This is roughly the learning approach that I used: Here is the Google page for location and maps. I worked along with the simple example and soon got it working. Make sure GPS is enabled on your emulator (if you are using one) - think this is the default, but you never know what the story will be with other emulator packages. Next is Hello, MapView. Same drill, work through it and bit by bit it gets ironed out. Then I reviewed the documentation on the Google API for Android. All of these classes concern maps, but there is supposed to be other stuff to the APIs. Not sure how this works out. Ok, maybe it was not that linear, a bit of scrambling all over the place at the beginning until I knew where I was. I am paranoid about leaving sensors and other juice gobblers running inadvertently, so I took some time to go t

Library projects

I have been using a library for the last week to keep source that I want to reuse handy. The details are here . It is working out very well, but it turns out that library projects will also allow you to share resources. For example styles. If you are putting a lot of applications out this takes away the need to reinvent the look of your app every time you start. So far I can't seem to get a jar file that is used in the lib project to be visible in the using projects. The jar in question is from AChartEngine. I have written some basic charting classes to get me up and running with a chart in a new app nice and quickly. Bit awkward to have to create a lib folder in each new project, drop the jar in there and then change the project props to pick this up. If I work out a way of getting a library project to handle this I will post here.

Resources for styling Android apps

Here are some notes I took while looking at styles and themes on Android: First I read the commonsware pdf section on styles and themes: Android 3.6.pdf page 319 - 326. I find this set of PDFs very useful. Well worth the money. Android developer docs: http://developer.android.com/guide/topics/ui/themes.html This section is very short for such a complicated topic, but it does give a link to the locations on GIT where the source of theme.xml and style.xml are stored. Looking through these takes a while, but it worth the effort. For example to find out what styles are available for progress bars go to this URL: http://developer.android.com/reference/android/R.attr.html and search for progressbar. (Possibles are horizontal, title, small and large. Inverse used black on white background.) Inheritance is a very useful aspect of styles too. Usually you don't want to start from scratch. Just use the parent attribute to point to a style that you want to inherit from (Theme.Ligh

ProgressBars and AsyncTasks

I was playing around with styling a ProgressBar and needed a thread type mechanism to update it. My goal was for the ProgressBar to do its thing and then disappear from the layout once it reached 100%. Initially I used a Thread, but this left me unable to get at the UI thread. Instead I created an AsyncTask. This is a very flexible mechanism for running background processes in Android. In order to use AsyncTask in Android you extend the class like this: class MyAsyncTask extends AsyncTask   Those three types (Void, Integer and Void in my case) represent the parameters sent into the task, the progress of the task (which can be published periodically if you like) and the results of the task. The parameters and the progress are Varargs, although I only used the first slot of each in my simple example. My doInBackground looks like this: @Override protected Void doInBackground(Void... params) { while (mProgressStatus < 100) { publishProgress(doWork()); }

Getting started with charting

I started using the  http://www.achartengine.org  library in my app today. Have not integrated it properly yet. So far I have just shoved the demo activity into my existing app. This is the jar and what goes where part of the job out of the way, so now I just have to get the hang of the renderers and pick a nice looking chart. More on this as I use it, but so far it looks nice. Tons of places to use charts in just about any app. Fixed a bunch of problems related to how activities are kicked off when you are expecting a result. Using startActivityForResult and calling finish from the target Activity means that your user does not end up meandering through no longer relevant Activities as they press the back button. The overall flow is now much improved. Still getting tripped up by the upgrade path for a modified database. I reckon this should be a straightforward, almost mechanical method to write (the override of SQLiteOpenHelper.onUpgrade()), but I keep getting knotted up in it. On

Improving my ListViews

A more productive day today. I was using an ArrayList of custom objects to back my ListView. This was fine for a short list of items, but got fiddly once I allowed the user to make changes to the list (check a box). This required me to update the ArrayList content and the db. Turned into a mess and never really got anywhere with it. That was yesterday. Today I changed my implementation to be backed by a Cursor directly. Had to work out how to use newView and bindView, but it was worth the effort. This implementation will be much more portable in other implementations. Got tripped up by this line: daysRemaining.setText(DateFactory.dateDiff(todaysDate, endDate)); This was trying to set the text value to be an int. A nice type error would result in straight java, but in Android the system was looking for a resource id equivalent to the value returned by DateFactory. A fiddly bug to find, but all done now. Getting more comfortable with the basics now, so hopefully will get to a point

Slow progress and fighting with sqlite

Second day at the (home) office was harder than the first. Fiddling with queries on sqlite took up a lot of the day. I have been doing sql for years, but I think I will just have to test the stuff out more thoroughly before I put it into an android program. The cycle between develop, deploy and test is too long and fiddly to be working out why your where clause is eliminating all of your rows. Outer join - I added an outer join to my code today. Not exactly rocket science, but very handy all the same. The app I am developing allows people pick 30 day challenges. They enter their progress against these items as they go along. It is supposed to be a way to get into new, productive habits. I got the idea here: http://www.youtube.com/watch?v=JnfBXjWm7hc Its early days yet, but I like these kind of apps, so it seemed like as good a place as any to start. The outer join is useful for pulling back the tasks that the user has in their list. It is outer as I want to show them the ones th

Getting started

I finished up my normal job last Friday. Time to get started on some of the stuff that I really want to do. First day over now. Some rules: Backup all of my work at the end of each day - drop box for this. Put a bit on the blog so that I can see progress - along with anyone else who cares to. Avoid distractions. I read this at the weekend: One of those kick in the pants books. Not a lot of content in there, but what is there is good. Gave me a bit of a push anyway. Managed to stick to all of them today. Really just getting my toolset organised. SQL query tools, eclipse and the docs that I need. A little bit of outline planning and I got stuck in. Will post more about the project as it progresses.