[android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Alok Kulkarni
Hi ,
I am having the following code for drawing buttons in my project.
I am having a button which has three images for 1 button .Namely one image
for the rectangle and 2 images for the left and right side curves
respectively.
When the button has focus , there is another three images for focus and
similarly 3 images when button is pressed.
Following is the code.

public void setButtonStyle(Button btn) {

//The middle rectangle
StateListDrawable drawables = new StateListDrawable();
drawables.addState(new int[] { stateFocused, -statePressed },
dButtonMidOverImage);
drawables.addState(new int[] { stateFocused, statePressed },
dButtonMidDownImage);
drawables.addState(new int[] { -stateFocused, statePressed },
dButtonMidDownImage);
drawables.addState(new int[] { -stateChecked }, dButtonMidUpImage);

btn.setBackgroundDrawable(drawables);

//The left curve
StateListDrawable drawablesLeft = new StateListDrawable();
drawablesLeft.addState(new int[] { stateFocused, -statePressed },
dButtonLeftOverImage);
drawablesLeft.addState(new int[] { stateFocused, statePressed },
dButtonLeftDownImage);
drawablesLeft.addState(new int[] { -stateFocused, statePressed },
dButtonLeftDownImage);
drawablesLeft.addState(new int[] { -stateChecked },
dButtonLeftUpImage);

StateListDrawable drawablesRight = new StateListDrawable();
drawablesRight.addState(new int[] { stateFocused, -statePressed },
dButtonRightOverImage);

//The right curve
drawablesRight.addState(new int[] { stateFocused, statePressed },
dButtonRightDownImage);
drawablesRight.addState(new int[] { -stateFocused, statePressed },
dButtonRightDownImage);
drawablesRight.addState(new int[] { -stateChecked },
dButtonRightUpImage);

//Compound drawables set for left and right side.
btn.setCompoundDrawablesWithIntrinsicBounds(drawablesLeft, null,
drawablesRight, null);


}
This thing which i have done runtime can be done in the XML too , but i want
to change themes runtime so my images for button will also change runtime.
If i do the code in the XML it works fine on both Android 1.5 as well as
Android 1.6 .But doing it in code distorts the images for 1.6 emulator.
I have attached the screen shot of the buttons on both 1.5 and 1.6
emulators.As you can see, the left and right curve images come almost to the
center and the centre image is expanded in 1.6 emulator. The same problem is
seen on HTC Desire (Android2.1)
Is there something wrong that i am doing . Is there any workaround for this
problem.
Thanks ,
Alok.,

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=enattachment: Android1.5 Emulator_Button.JPGattachment: Android1.6 Emulator_Button.JPGattachment: Button Seperation.JPG

Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread skink


Alok Kulkarni wrote:
 Hi ,
 I am having the following code for drawing buttons in my project.
 I am having a button which has three images for 1 button .Namely one image
 for the rectangle and 2 images for the left and right side curves
 respectively.

use nine-patch-drawables instead

search for *.9.png files under SDK/platforms/*/data/res to see how
they look like

pskink

-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Alok Kulkarni
For 9 patch images i suppose they need to be stored under drawable folder. I
need to change the images according to theme at runtime.

On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:



 Alok Kulkarni wrote:
  Hi ,
  I am having the following code for drawing buttons in my project.
  I am having a button which has three images for 1 button .Namely one
 image
  for the rectangle and 2 images for the left and right side curves
  respectively.

 use nine-patch-drawables instead

 search for *.9.png files under SDK/platforms/*/data/res to see how
 they look like

 pskink

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Kostya Vasilyev

Nine-patch described here:

http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

-- Kostya

Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May  
2010 12:25:11 +0400:


For 9 patch images i suppose they need to be stored under drawable  
folder. I

need to change the images according to theme at runtime.

On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:




Alok Kulkarni wrote:
 Hi ,
 I am having the following code for drawing buttons in my project.
 I am having a button which has three images for 1 button .Namely one
image
 for the rectangle and 2 images for the left and right side curves
 respectively.

use nine-patch-drawables instead

search for *.9.png files under SDK/platforms/*/data/res to see how
they look like

pskink

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en






--
Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Alok Kulkarni
Thanks for the link Kostya,
But my problem is that i cannot have my images under drawable folder and
also cannot specify the image path in my XML for layout  as and when the
user wishes to change the theme , a new theme will be downloaded from the
server and the new set of images will be loaded at runtime ,, So if my
button has a yellow color when it has focus it might become red when user
changes theme.So all the three images for a button will change at
runtime..So all my drawables need to be kept in the runtime application
folder ie data/data/appPackage/themes which i am doing curently..
Is the 9 patch image logic useful in this case ?
The statelistdrawable works fine if i have only one image for a Widget.But
in case of button i have three images which is not working 1.6 onwards..
Thanks,
Alok.


2010/5/5 Kostya Vasilyev kmans...@gmail.com

 Nine-patch described here:


 http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

 -- Kostya

 Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May
 2010 12:25:11 +0400:

  For 9 patch images i suppose they need to be stored under drawable folder.
 I
 need to change the images according to theme at runtime.

 On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:



 Alok Kulkarni wrote:
  Hi ,
  I am having the following code for drawing buttons in my project.
  I am having a button which has three images for 1 button .Namely one
 image
  for the rectangle and 2 images for the left and right side curves
  respectively.

 use nine-patch-drawables instead

 search for *.9.png files under SDK/platforms/*/data/res to see how
 they look like

 pskink

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com
 

 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 --
 Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en


-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Alok Kulkarni
thanks skink , i will look into it .. and will update it over here..


2010/5/5 Alok Kulkarni kulsu...@gmail.com

 Thanks for the link Kostya,
 But my problem is that i cannot have my images under drawable folder and
 also cannot specify the image path in my XML for layout  as and when the
 user wishes to change the theme , a new theme will be downloaded from the
 server and the new set of images will be loaded at runtime ,, So if my
 button has a yellow color when it has focus it might become red when user
 changes theme.So all the three images for a button will change at
 runtime..So all my drawables need to be kept in the runtime application
 folder ie data/data/appPackage/themes which i am doing curently..
 Is the 9 patch image logic useful in this case ?
 The statelistdrawable works fine if i have only one image for a Widget.But
 in case of button i have three images which is not working 1.6 onwards..
 Thanks,
 Alok.


 2010/5/5 Kostya Vasilyev kmans...@gmail.com

 Nine-patch described here:


 http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

 -- Kostya

 Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May
 2010 12:25:11 +0400:

  For 9 patch images i suppose they need to be stored under drawable
 folder. I
 need to change the images according to theme at runtime.

 On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:



 Alok Kulkarni wrote:
  Hi ,
  I am having the following code for drawing buttons in my project.
  I am having a button which has three images for 1 button .Namely one
 image
  for the rectangle and 2 images for the left and right side curves
  respectively.

 use nine-patch-drawables instead

 search for *.9.png files under SDK/platforms/*/data/res to see how
 they look like

 pskink

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to
 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com
 

 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 --
 Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Alok Kulkarni
Can you show me an example if possible ?

2010/5/5 Alok Kulkarni kulsu...@gmail.com

 thanks skink , i will look into it .. and will update it over here..


 2010/5/5 Alok Kulkarni kulsu...@gmail.com

 Thanks for the link Kostya,
 But my problem is that i cannot have my images under drawable folder and
 also cannot specify the image path in my XML for layout  as and when the
 user wishes to change the theme , a new theme will be downloaded from the
 server and the new set of images will be loaded at runtime ,, So if my
 button has a yellow color when it has focus it might become red when user
 changes theme.So all the three images for a button will change at
 runtime..So all my drawables need to be kept in the runtime application
 folder ie data/data/appPackage/themes which i am doing curently..
 Is the 9 patch image logic useful in this case ?
 The statelistdrawable works fine if i have only one image for a Widget.But
 in case of button i have three images which is not working 1.6 onwards..
 Thanks,
 Alok.


 2010/5/5 Kostya Vasilyev kmans...@gmail.com

 Nine-patch described here:


 http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

 -- Kostya

 Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May
 2010 12:25:11 +0400:

  For 9 patch images i suppose they need to be stored under drawable
 folder. I
 need to change the images according to theme at runtime.

 On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:



 Alok Kulkarni wrote:
  Hi ,
  I am having the following code for drawing buttons in my project.
  I am having a button which has three images for 1 button .Namely one
 image
  for the rectangle and 2 images for the left and right side curves
  respectively.

 use nine-patch-drawables instead

 search for *.9.png files under SDK/platforms/*/data/res to see how
 they look like

 pskink

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to
 android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com
 

 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en




 --
 Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

 --
 You received this message because you are subscribed to the Google
 Groups Android Developers group.
 To post to this group, send email to android-developers@googlegroups.com
 To unsubscribe from this group, send email to
 android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/android-developers?hl=en





-- 
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Re: [android-developers] Problem with StateListDrawables not found in 1.5 but there from 1.6 onwards

2010-05-05 Thread Kostya Vasilyev

Ah, this is different. Nine patches are great for smart scaling of images.

What you need is an additional abstraction layer: drawables with state  
selectors, like so:



?xml version=1.0 encoding=utf-8?
selector xmlns:android=http://schemas.android.com/apk/res/android;
 item android:state_enabled=false
   android:drawable=@drawable/search__disabled /
 item android:drawable=@drawable/search_normal /
 /selector

Normally, you save this under drawable (say,  
res/drawable/search_button.xml) and references in your layout file, just  
like any drawable.


In your case, it's necessary to create these drawables at runtime. Looks  
like StateListDrawable and its addState() method should do the job.


-- Kostya

Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May  
2010 12:43:46 +0400:



Thanks for the link Kostya,
But my problem is that i cannot have my images under drawable folder and
also cannot specify the image path in my XML for layout  as and when the
user wishes to change the theme , a new theme will be downloaded from the
server and the new set of images will be loaded at runtime ,, So if my
button has a yellow color when it has focus it might become red when user
changes theme.So all the three images for a button will change at
runtime..So all my drawables need to be kept in the runtime application
folder ie data/data/appPackage/themes which i am doing curently..
Is the 9 patch image logic useful in this case ?
The statelistdrawable works fine if i have only one image for a  
Widget.But

in case of button i have three images which is not working 1.6 onwards..
Thanks,
Alok.


2010/5/5 Kostya Vasilyev kmans...@gmail.com


Nine-patch described here:


http://developer.android.com/guide/topics/graphics/2d-graphics.html#nine-patch

-- Kostya

Alok Kulkarni kulsu...@gmail.com писал(а) в своём письме Wed, 05 May
2010 12:25:11 +0400:

 For 9 patch images i suppose they need to be stored under drawable  
folder.

I
need to change the images according to theme at runtime.

On Wed, May 5, 2010 at 12:52 PM, skink psk...@gmail.com wrote:




Alok Kulkarni wrote:
 Hi ,
 I am having the following code for drawing buttons in my project.
 I am having a button which has three images for 1 button .Namely one
image
 for the rectangle and 2 images for the left and right side curves
 respectively.

use nine-patch-drawables instead

search for *.9.png files under SDK/platforms/*/data/res to see how
they look like

pskink

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to  
android-developers@googlegroups.com

To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
android-developers%2bunsubscr...@googlegroups.comandroid-developers%252bunsubscr...@googlegroups.com


For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en






--
Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.comandroid-developers%2bunsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en






--
Написано в почтовом клиенте браузера Opera: http://www.opera.com/mail/

--
You received this message because you are subscribed to the Google
Groups Android Developers group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en