Drawing image with dynamic text

by Neilz » Wed, 09 Dec 2009 19:50:20 GMT


Sponsored Links
 Hi all.

I understand the principle of a 9Patch image where the image stretches
to fit the text within it. But this all assumes that the image is a
background to a TextView, or similar.

What I want to do is draw an image to the canvas, and set the
contained text at the time (currently I'm using canvas.drawText) - but
here the image has no connection with the text, or with a view, so it
wouldn't know to stretch.

I know this can be done, I've seen it, I'm just not sure how to go
about it... it's a bit like on google maps where you have a marker
with a cloud image containing the info, it is set dynamically. Any
ideas appreciated!

--



Other Threads

1. concurrency of AsyncTasks

Hi,

I am replacing the multithreaded code in my app with the AsyncTask from 1.5.
I found that two AsyncTasks do not work concurrently. I investigated a bit
and found a workaround; I would like second opinion if my solution is right.
OR if there is a better solution.

AsyncTask allows the app to do a task on a thread other than the UI thread.
But IIUC, it only provides a single thread on which a queue of tasks is
performed. Therefore, if one of the task is to wait on some event (n/w or
sleep) then all other tasks will wait for it to finish.

To elaborate with the coding example:
<code>

public class MyTask extends AsyncTask<...>
{ ... }

// On the UI thread execute two tasks
MyTask mt1 = new MyTask().execute(args);

MyTask mt2 = new MyTask().execute(args);

</code>

In the above code both the execute calls will return immediately and free up
the UI thread; however mt1 will be executed first and mt2 will have to wait
until mt1 finishes.

Thanks to the android's open source, we can see implementation of AsyncTask.
http://google.com/codesearch/p?hl=en&sa=N&cd=2&ct=rc#uX1GffpyOZk/core/java/android/os/AsyncTask.java&q=lang:java%20AsyncTask

I copied AsyncTask.java as UserTask.java in my project and changed the value
of CORE_POOL_SIZE to 5. This makes the thread pool to use 5 threads to
multiplex the queued AsyncTasks. This indeed solved my problem. Now if mt1
blocks on a sleep; mt2 goes ahead and finishes its job.

Here are some questions for those who know more about AsyncTask
implementation:

Is this work-around right?
If yes, can the CORE_POOL_SIZE be made configurable in future, via an API
call?
Is there a solution by which multiple thread pools can be used?

Let me add that, I am aware that this is a phone and not a web server - I am
not using 10s of threads to do network I/O. However a single thread is not
sufficient for my app either.

Please let me know. Thanks in advance.

Jayesh

--~--~---------~--~----~------------~-------~--~----~

2. Instrumentaion - running multiple istrumentation simultaneously

Sorry you can only run one instrumentation at a time.








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

3. Android PG

4. How to draw tracks on gmaps in apps

5. Intent.ACTION_SEND and Email

6. Has there been a change in market date listing?

7. Instrumentaion - running multiple istrumentation simultaneously