Codename One: How to localize styled components - codenameone

I am trying to add an Arabic bundle using this code:
resourceBudle = new HashMap<String, String>();
resourceBudle.put("Ok", "موافق");
resourceBudle.put("#rtl", "true");
resourceBudle.put("MainTitle", "عربتي");
UIManager.getInstance().setBundle(resourceBudle);
Now the MainTitle is a label which I have styled using a UIID in the theme designer. I have set font to large and alignment to center. Now when I try to create a form with a toolbar and set the titlecomponent of the tolbar to this label I dont get the Arabix text. Instead I get for each character a box with "X" inside it. It looks like there is an encoding issue but I am not sure why. Can You please help??!!

Ok Sorry i think the problem was with the system font that I used. I had to change the font to monospace for example or any other font that supports Arabic.
Thanks.

Related

How do I change the colours of the Switch component?

I want to change the colour of the thumb of the Switch component to green instead of the standard black.
According to the documentation "You can customize the look and feel of a switch using styles, either directly in the theme.res file or in CSS." and "The thumb will be rendered using Switch's Style.getFgColor(). It will use the selected style, when in the "on" position, the unselected style when in the "off" position,"
https://www.codenameone.com/javadoc/com/codename1/components/Switch.html
I have tried adding a "Switch" style to the theme.res file. In the theme preview I see my changes. When I run the app in the simulator, there is no change.
I also tried changing the style in code:
swPrdp.setUIID("Switch");
I still get the standard black thumb.
I also tried:
swPrdp.getAllStyles().setBgColor(0xcccccc, true);
swPrdp.getSelectedStyle().setFgColor( 0x59925A, true);
with and without the second argument (true). Still no change.
I am trying to keep the app size to a minimum, so I don't want to go the route of specifying images.
Where am I going wrong?
This should work in the theme too and works for me in the style object (which is easier to write here:
Form hi = new Form("Switch", BoxLayout.y());
Switch s = new Switch();
s.getAllStyles().setFgColor(0xff0000);
s.getAllStyles().setBgColor(0xff);
hi.add(s);
hi.show();

Change span label font size in codenameone

I want to show a multiline text so I use a span label. I am trying to set the font size from the gui but it does not change.
I also trying to set the color dynamicaly using the next code:
this.gui_Span_Info.getAllStyles().setFgColor(HTMLElement.COLOR_RED);
but nothing happens.
What should I do?
SpanLabel is a composite component which means it's built from 2 or more separate components one of which is a Container.
You can determine the UIID of the text using setTextUIID it defaults to the Label UIID.

Finite Icon Colors in Draftail Editor

I am trying to implement a finite number of colors (like square icons) on the Draftail editor itself. What will be the best way to approach this?
It should be similar to how Microsoft Word displays the font color or something along those lines.
Thanks in advance.
I'm not sure if it's the best approach but here is what I came up with:
https://gist.github.com/benoitvogel/46022124d46de03ed2078603fb24ca97
This defines a new inline style which encloses the selected text between <span class="mycustomclass"></span> (change feature_name according to the CSS class you want to use).
Then, you just have to define the corresponding .mycustomstyle CSS class in your frontend as usual:
.mycustomstyle {
color: purple;
}
You can also modify control['style'] to change the way this style will be displayed in the editor.
You will get 1 icon/label per CSS class, so it's not really like in Word as you won't get a proper selector. I haven't tried it myself, but according to Wagtail docs icon can reference SVG, so you might be able to display color squares instead of labels.
Hope it fits your needs.

Slider in codenameone

Can any one please tell me how i can add slider and moving form in codename one (with sample lines of code) and also want to know are these features supported by all types of devices?
Regards,
Megha
I think you mean how to animate forms changes
Form.setTransitionInAnimator(CommonTransitions.somthing)
Form.setTransitionOutAnimator(CommonTransitions.somthing)
Next, you should handle some "finger slide" event.
To add a slider you can use the following code
Slider jSlider = new Slider();
jSlider.setMaxValue(255);
jSlider.setMinValue(0);
jSlider.setProgress(50); // Set the starting value
jSlider.setEditable(true); // To it works as a slider instead of a progress bar
Now you have created a slider which you can add to your component like you would in Swing. You can type 'jSlider.' in eclipse to find out which other methods you can use, or you can go to the API: http://codenameone.googlecode.com/svn/trunk/CodenameOne/javadoc/com/codename1/ui/Slider.html
I think min/maxValue are selfexplenatory though :)
If you want to open a new form, simply create a new class extending form or do it in code like
Form form = new Form();
form.animate(); // To make it "slide in"
form.show();
Also noteworthy, the slider doesn't work with the lumia skin per default, though you can make it work. I actually asked this question on here as well:
Slider doesn't draw (CodeName One) with Windows phone skin

In CQ5, how do I configure an extJS component?

This question is specific to Adobe CQ5, so ExtJS answers by themselves won't be that helpful.
I have a custom text component with a menu option to change the background color. We're referencing a colorfield component in our dialog.xml, and so far everything works. The color menu appears with the default set of colors in the palette and can be clicked. So far so good.
I would now like to customize the palette and only show a select set of colors specific to our client. How do I achieve this?
Here's the relevant dialog.xml snippet so far:
<bgcolor
jcr:primaryType="cq:Widget"
fieldLabel="Background color"
name="./bgColor"
showHexValue="true"
xtype="colorfield"/>
For future reference, you could probably get by creating a custom ColorField to call a custom ColorMenu which sets a custom ColorPalette. If ColorField had configurable options, these would probably be mentioned in the Ext docs or found in the JS file itself in /libs/cq/ui/widgets/..
Found it on dev.day.com - http://dev.day.com/content/kb/home/cq5/Development/HowToCreateCustomClientLib.html
Simply put, override the ExtJS widget with your own. Not ideal but it'll do.

Resources