Confused about 9-patch files

by craiget » Tue, 03 Mar 2009 10:26:47 GMT


Sponsored Links
 Can someone please explain or provide examples (links) of some valid 9-
patch files?


As an example, there's a 9-patch located at:  http://www.maladroid.net/test.9.png 

[the same idea, as abad ascii representation]

0 = transparent, 1 = black, 2 = red

010101010
102020200
102020200
102020200
102020200
000000000

So there are 3 single-red-pixel columns, with stretchable areas
defined between them. It seems like this should resize to any aspect
ratio and there will still be 3 single-pixel red columns. My thinking
is that the solid black border on the left means "scale uniformly in
the y-direction" and that a pixel in the top row above the transparent
columns means "scale the transparent area, but leave the red columns
with width=1 pixel".

Is that the correct interpretation of black/transparent pixels?

Using the draw9patch tool, it doesn't scale if I make the left-border
completely black, but if I remove any one pixel, then it scales - why
is that?

When working in Eclipse, after refreshing the /drawables folder,
sometimes my 9-patch doesn't show up in the R.java file, presumably
because it is somehow invalid. Yet, I can still refer to it and use it
in the Layout Editor. Am I correct to assume there's something wrong
with the 9-patch? Or perhaps there's something wrong with my (default
eclipse plugin) build process?

Thank you for any suggestions.



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



Confused about 9-patch files

by deepdr...@googlemail.com » Wed, 04 Mar 2009 02:56:32 GMT


 You can find examples of 9patch files in the SDK, in tools/lib/res/
default/drawable/
The .9.png files are 9patches.

 http://www.deepdroid.com 




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


Sponsored Links


Confused about 9-patch files

by Marco Nelissen » Wed, 04 Mar 2009 04:50:06 GMT


 


Because a ninepatch consists of 9 patches, only 5 of which are scaled,
while the 4 corners are not scaled. An image that has a black top-left
pixel therefore cannot be a ninepatch image. The draw9patch tool
shouldn't even let you set the top-left to black.

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



Confused about 9-patch files

by Romain Guy » Wed, 04 Mar 2009 04:55:42 GMT


 > Because a ninepatch consists of 9 patches, only 5 of which are scaled,

Actually our 9patches really are n-patches. You can have as many
stretchable areas as you want.

-- 
Romain Guy
Android framework engineer
romain...@android.com

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

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



Confused about 9-patch files

by Dianne Hackborn » Wed, 04 Mar 2009 07:29:17 GMT


 A feature unfortunately added after the name itself was pretty set in stone.
:)






-- 
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.  All such questions should be posted on public
forums, where I and others can see and answer them.

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



Confused about 9-patch files

by craiget » Wed, 04 Mar 2009 10:36:45 GMT


 Thank you for the replies.

Maybe what's causing my confusion is a bug in aapt (or my
environment?) rather than misunderstanding the concept of 9-patch. In
which case I may be posting to the wrong place.

I've got two files that demonstrate what's happening:

This first file, Eclipse likes and it successfully gets packaged into
the application and everything is fine.

 http://maladroid.net/b.9.png 

This second file is exactly the same, except it duplicates the pattern
of 1px red bars for one more column. This file seems to cause aapt to
crash. However, it seems like it should be a valid 9-patch.

 http://maladroid.net/c.9.png 

The console shows an error message:

 *** glibc detected *** /home/me/android/android-sdk-linux_x86-1.1_r1/
tools/aapt: realloc(): invalid old size: 0x09a50770 ***
[2009-03-03 21:21:15 - Test] ======= Backtrace: =========
~~~ etc



Any ideas what could be causing that to happen?

Thanks!










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



Confused about 9-patch files

by Dianne Hackborn » Wed, 04 Mar 2009 11:23:26 GMT


 aapt should never crash, so it's a bug in it of some kind.  Unless you want
to dig in and figure out the problem, filing a bug report would probably be
good. :)








-- 
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.  All such questions should be posted on public
forums, where I and others can see and answer them.

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



Confused about 9-patch files

by Marco Nelissen » Thu, 05 Mar 2009 01:07:15 GMT


 Are you sure that b.9.png works correctly? It doesn't seem to stretch
correctly either in the draw9patch tool.







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



Confused about 9-patch files

by Marco Nelissen » Thu, 05 Mar 2009 13:14:59 GMT


 It's a bug in aapt. Where you should normally be able to have up to
width/2 horizontal stretch regions, it only allocates enough space for
width/4. Your image was 36 pixels wide, so you can have 9, and it
would crash on 10 (like your c.9.png image).
The issue with draw9patch you mentioned earlier is separate issue,
which only affects rendering in draw9patch, but doesn't affect how
your ninepatch will look in your app.







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



Other Threads

1. ListView with XML files strategy

Hi all.  I need some advice on how to best proceed.

First, a little background.  I have an application that uses a
ListView as it's main activity to display all of the XML files from
the /data/data/package.name/files directory.  There may be hundreds of
these files as the app gets used, so I pass the job of scanning the
directory and loading the files into the ArrayAdapter using an
AsyncTask that fires up a 'Loading...' ProgressDialog onPreExecute(),
and closes it down onPostExecute().  In doInBackground(), I iterate
through the files returned from a listFiles() call, storing the file
names into the ArrayAdapter.

In terms of the AsyncTask, I've taken some direction here from Romain
Guy's Shelves application in terms of the AsyncTask properly pausing/
storing, etc when it gets interrupted, and killed on Application
termination.  Everything here works OK, except that the ArrayAdapter
can only tie in a single value (the filename in this case) to the
View, and I's like to tie in multiple values/views pairs (in my case,
filename, modified date).

I've seen this done in the Notepad sample application, but that uses
the SimpleCursorAdapter, but my understanding is that is exclusively
tied to Cursors, and thus the SQLite database, which I don't need.

So, here are my issues as I try to extend the very basic app:

1) How do I bind multiple values to multiple Views in the adapter.
ArrayAdapter can't do it, is there another more appropriate option, or
am I looking at creating my own custom adapter?  If so, any example
and/or suggestions on how to best proceed?

2) Am I going down the completely wrong path here with how I am tying
files into the List... is there some 'hybrid' way to tie files to a
Cursor such that I could use the SimpleCursorAdapter to handle all of
this?

3) As a follow-up to that, in terms of adding items, I have an
OptionsMenu that launches a Note Editing function (very similar to the
Notepad example).  I can create XML files via this method, but on
going back to the ListView, the new items are not in the List,
unsurprisingly.  Notepad does this via the ContentResolver.insert()
method, but with physical files scanned from the directory, I'm just
not sure how I should be proceeding to update the List... I'd rather
not have to re-scan every time a new note is added, but that may be my
only option, as far as I know.  Again, any help here is much
appreciated.  I see ArrayAdapter has insert/remove methods, but when
in the child Editing activity, I'm not sure how I can access these
(ContentResolver?).  Thanks for any clarification here.

3) In terms of the Uri I define for each item, I am generating it from
the absolute filepath, due to the fact that it may be possible in
future versions to move/store files on the SD card, and I'm trying to
maintain the Uniqueness of the Uri.  Anyone see any issues with this
solution?

A very broad question, I hope the basic gist is clear...  just trying
to determine the best way to star so that I can move forward in the
most efficient and correct way.

Thanks in advance,

Paul

-- 

2. WakeLock/Services and sleep

Hi all -

I've got an app that starts a service in order to receive location
updates from the LocationManager.    The use case is the service needs
to be running all the time and as such it acquires a
PowerManager.PARTIAL_WAKE_LOCK in the onCreate() of the Service.

But it seems from testing on several different phones and user
feedback that the Service is still being put to sleep as the location
notifications will stop if the application isn't in the foreground.
This effectively renders the app ineffective for the task at hand.
I've read posts about using an Alarm to simulate a pseudo cron job but
I don't really need to be woken up in order to do a task, the app
needs to run code based on the location manager calling
onLocationChanged the service that the users position has changed.

I'm pretty sure I've coded this service and application according to
the best practices for this sort of application yet the fact that it
effectively stops running in some cases is causing problems for the
users.

Any tips on how to keep a service going given the Android OS's
tendency to put things to sleep?  PowerManager.PARTIAL_WAKE_LOCK
seemingly isn't a guarantee about anything which I can sort of
understand but I've seen cases where the only app that I've launched
after restarting the phone is my application and it still gets put to
sleep.

Thanks for any help.

mike

-- 

3. Cell ID format

4. What is the best way to display OpenGL graphics with Camera preview background?

5. How to start build my device with Android...

6. GestureOverlayView preventing OnSingletap/onDoubletap methods to be called

7. Camera/Capture in Rowboat froyo