How to use <if> <else> <endif> (OR SIMILAR) in xml files ?
#1
Question 
Hi,

In order to avoid code duplication in my PM3-HD skin modification, I would like to use the same defined button with two different settings that will result in a 32x28px button OR in a 64x56px button.

As my English is far from perfect, to avoid confusion, here is a complete example I would like to do. In the "includes.xml", there is this code :

Code:
<control type="button" id="600">
    <posx>0</posx>
    <posy>2</posy>
    <width>32</width>
    <height>28</height>
    <label>-</label>
    <texturefocus>PlayerControls-PrevFO.png</texturefocus>
    <texturenofocus>PlayerControls-PrevNF.png</texturenofocus>
    <onleft>50</onleft>
    <onright>601</onright>
    <onup>610</onup>
    <ondown>607</ondown>
    <onclick>XBMC.PlayerControl(Previous)</onclick>
</control>
Depending on the bolean condition, I would like to change few parameters ONLY. Like this :

Code:
<control type="button" id="600">
    <posx>0</posx>
    <posy>2</posy>

    [color=red]<if>[/color]!Skin.HasSetting(double_size)
        <width>32</width>
        <height>28</height>
    [color=red]<else>[/color]
        <width>64</width>
        <height>56</height>
    [color=red]<endif>[/color]

    <label>-</label>
    <texturefocus>PlayerControls-PrevFO.png</texturefocus>
    <texturenofocus>PlayerControls-PrevNF.png</texturenofocus>
    <onleft>50</onleft>
    <onright>601</onright>
    <onup>610</onup>
    <ondown>607</ondown>
    <onclick>XBMC.PlayerControl(Previous)</onclick>
</control>

Any help would be really appreciated, thanks !
Reply
#2
Use 2 separate buttons is one way to do it. If this skin setting can't be changed from the home page, you could do it via conditional includes.

The other way to do it is to use a conditional zoom animation.
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#3
Thank you Jonathan for your answer. May I ask you to be a little more explicit for "conditional includes" (as the only help I found was this thread and he posted because something seems to be wrong.

I was not able to find anything in the wiki too Confused

Regards,
Reply
#4
I believe it's:

Code:
<include condition="skin.setting(foo)">name_of_include</include>

Cheers,
Jonathan
Always read the XBMC online-manual, FAQ and search the forum before posting.
Do not e-mail XBMC-Team members directly asking for support. Read/follow the forum rules.
For troubleshooting and bug reporting please make sure you read this first.


Image
Reply
#5
jmarshall Wrote:I believe it's:

Code:
<include condition="skin.setting(foo)">name_of_include</include>

Cheers,
Jonathan
Thank you Jonathan, but it is not enough explicit for me unfortunately. And even after seaching for hours, I can not find some exemples.
Moreover I do not have a working DSL connection since monday, so I can not post from home No
I am sorry but I am completely lost ! Is the way similar to this ?

Code:
<control type="button" id="600">
    <posx>0</posx>
    <posy>2</posy>
    <label>-</label>
    <texturefocus>PlayerControls-PrevFO.png</texturefocus>
    <texturenofocus>PlayerControls-PrevNF.png</texturenofocus>
    <onleft>50</onleft>
    <onright>601</onright>
    <onup>610</onup>
    <ondown>607</ondown>
    <onclick>XBMC.PlayerControl(Previous)</onclick>
[b]    <include condition="skin.setting(double_size)">double_size</include>[/b]
        <width>32</width>
        <height>28</height>
[b]    <include condition="skin.setting(single_size)">single_size</include>[/b]
        <width>64</width>
        <height>56</height>
</control>
Reply
#6
First you must define the includes
then you can call the includes on different conditions
Code:
[color=Green]<include name="double">
   <width>32</width>
   <height>28</height>
</include>

<include name="single">
   <width>64</width>
   <height>56</height>
</include>[/color]

<control type="button" id="600">
    <posx>0</posx>
    <posy>2</posy>
    <label>-</label>
    <texturefocus>PlayerControls-PrevFO.png</texturefocus>
    <texturenofocus>PlayerControls-PrevNF.png</texturenofocus>
    <onleft>50</onleft>
    <onright>601</onright>
    <onup>610</onup>
    <ondown>607</ondown>
    <onclick>XBMC.PlayerControl(Previous)</onclick>
    [color=SeaGreen]<include condition="!Skin.HasSetting(double_size)">double</include>
    <include condition="Skin.HasSetting(double_size)">single</include>[/color]
</control>
once the condition is negated with an !
Reply
#7
Thank you eumel for taking the time to give me a complete exemple...

I love this forum !

Can't wait to try it Big Grin I am not at home Sad
Reply
#8
Hi eumel,
are you sure? I've wroten it, but some error occured: Sad
Code:
<LinearLayout
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >
                 <include name = "Color1">
                 android:color="@color/grey05"
              </include>

        <Button          
        android:id="@+id/btn_level_1"          
        android:layout_width="wrap_content"          
        android:layout_height="55dp"
        android:text="@string/btn_level_1"          
        android:layout_weight="1"
       <include condition = "My condition" >Color1></include>           
        />
        
    </LinearLayout>


How should I define the condition? Can I import a parameter of my java project? How should I adress it in XML?
but I think it has problem independently of condition, perhaps with syntax.
Thx a lot,
Grüße Wink
Reply
#9
android skinning got what exactly to do with xbmc skinning?
Reply

Logout Mark Read Team Forum Stats Members Help
How to use <if> <else> <endif> (OR SIMILAR) in xml files ?0