Add data file in CSS & Undesired files - codenameone

Two questions:
What are the steps to add a data file to theme.res in a css activated project? When I open the generated theme.res with the resourceEditor, I can see the data file but the code Resources.getGlobalResources().getData("datafile") returns null.
I keep having some multi-image files "SideCommand*.png" from Resources.getGlobalResources() that I have no idea where they are from since they do not appear in the generated theme.res loaded in resourceEditor.
It could sound like the process is broken somewhere or I do not check out the right theme.res but adding an image to the css area works just fine. I can see it in the resource Editor and I can load it using Resources.getGlobalResources().getData("imagefile"). I'm really lost here, any chance you can guide me?
Cheers.
Emmanuel

If you define a border that can't be satisfied by the existing borders in Codename One the CSS plugin generates a 9-piece border for you by using the JavaFX HTML engine to render the CSS and grab a screenshot. That means the css for SideCommand uses a fancy border.
The CSS processor supports images but not data files at this time. You can add an image using this approach: https://www.codenameone.com/blog/using-css-to-import-images.html
Notice you can add additional res files for data.

Related

Codenameone Migrating Legacy Applications to CSS II

I am using Netbeans. I don't know what I'm doing wrong and I'll detail what I've done in sections within the attached image:
Rename theme.res to theme_legacy.res
Delete indicated file and folders.
In the designer create the constant "theme" and save file.
Rename resource file in main class and save file.
Activate CSS file and save.
In section 6 it shows the incomplete CSS file. After executing the project another "theme" is created as shown in section 7.
I appreciate your comments.
To do a "slow migration" just do the following:
Remove the includeNativeBool constant from the CSS - this means we inherit the native theme instead of the old theme (which I assume already inherits the native theme). You can only inherit one theme...
In the code load the legacy theme just like you do right now
Layer the CSS on top by adding the following line:
theme = UIManager.initNamedTheme("/theme", "Theme");
Once you do that the theme will include both the legacy code and the new stuff. This is from the developer guide "Theme Layering" section.

My theme.res is 6x bigger than the theme.css it is generated from, is this normal?

My theme.css is 58K, but the generated theme.res (which does not contain any images or fonts, only the theme generated from css) is 349K.
Since theme.res is a binary format, and probably more compact than a css text file, this seems strange - has anything changed in the format or could something be wrong in my css file?
If on the other it is normal that the theme.res size can be so much bigger than the theme.css, wouldn't it make sense to add an option to just include the css in the distribution and then generate the theme.res on the device on first run of the application?
58k is huge for a CSS theme so this makes sense. Notice that some CSS styles can't be implemented in Codename Ones styling so the CSS tool launches a browser and grabs a screenshot from the browser then generates an image based on that.
To see if this is what happened just open the resource file using the designer tool and go to the images section to see what images were generated. You can then reverse the styles that triggered image generation and see if you can tune the CSS a bit to avoid image creation.

How to reduce the jar size of a codename one app to stay under 50meg

My app is too large for the 50 meg limit so I am looking at some ways to significantly reduce the file size.
If I discard a dpi what happens when it runs on that dpi? I have some HUGE backgrounds making my app very bloated, I was wondering if I can remove them all but say the HD one and it would scale or would it be simply empty? Or would I need to change the background image scaling to make it do this?
Also CN1 seems to use png, can I use jpg for selected items to save space? Backgrounds that are 2.3 meg pngs could be 35k jpgs.. Even if I wrote a script that jpeged them after I press save in the gui designer, this could work I assume?
Any any further final tips for reducing the size of cn1 apps?
A 50mb app is not only big, but prone to be slow on devices (performance wise).
To reduce your App size tremendously, do the following:
All my answers are based on old GUI Builder
For background image, use a single image (not multi-image) and style the form UIID to use the image and type IMAGE_TO_FILL.
Avoid using png image whenever possible, CN1 supports jpg perfectly.
Don't use images for basic icons, use fonticon. Thousand of icons could be made 100kb and of high quality svg image that doesn't pixelate. I will explain at the end of this list how to create your custom fonticons.
Avoid using 9-piece border image where it's not really needed, try to use solid background color if it won't ruin your design.
Delete unused images, they also take a lot of space. On your GUI Builder.
Re-use UIIDs, instead of creating multiple similar UIIDs.
Migrate your GUI Builder forms to code, I posted a sample form Class to answer another question here and also talk about similar thing here.
Delete UIIDs you're not using and in most cases, copy and paste UUID of unselected style to selected, instead of creating similar.
Be Careful with this. Keep your GUI Builder open, make sure Xml team mode is checked under File, save the GUI Builder after deleting Unused Images, without closing the GUI Builder, go to your project folder -> res -> delete theme.xml and the theme folder inside res folder (The name might be different if you've renamed your theme.res file). Now go back to your app and save again. A fresh copy of your res files would be saved in the same folder.
Minimise the amount of background images you use, Modern good looking apps are simple plain background apps. E.g, Facebook, Twitter, Uber, AirBnB, BBC News App and many others. Unless your app is actually a game or necessarily require rich images that have to be static.
Watch this video about performance tuning, It's a bit old but still contains useful information
If your app is bigger than 20 mb on iOS and 5mb on android, you should be worried about it's performance.
Creating fonticons:
Go to fontello.com and check the icons present, if there are icons you need that are not there...
Go to flaticon.com and search for it there, download it as svg and drag'n'drop the svg on fontello webpage. If the icon doesn't look as expected...
Go back to flaticon.com and download the image as black 512px png image and go to online-convert.com, convert the png to Monochrome svg file, this helps you to create a compound image that works well with fontello.
download the fonticon as zip on fontello and follow Shai's chat app example to use it. the zip contains demo html file to preview your icons and also a config.json that can be drag'n'drop on fontello.com to continue where you stopped.

Load content from a dynamically loaded module with MEF

I'm working on a modular Silverlight application and in one of the modules I'd like to display an image on a view. I've added the image file under the module project in the /Resources/Images directory. And than I've changed the image file's Build Action property to Content. I think it's nicer not to embed the image into the dll file. The xap file after build contains the image.
In the View xaml I've inserted the image <Image Source="/Resources/Images/Yoda.jpg" /> and design time it displays correctly but runtime the image is missing.
My question is how to solve this problem? I don't want to embed in the dll (Build Action: Resource).
I've made a small test solution if you want to play with it:
Solution.zip
Thanks in advance
Design time the image displayed correctly:
But runtime the image is missing:
Solution structure:
You could set the Copy to Output Directory property of the image to either:
Copy always, or
Copy if newer
Then at runtime it will be available.

Why Resource (.resx) file added on merely changing Form size and on adding button which is not resource

1- Resource files suppose to be added on adding some resource in application like image or audio or video etc. But if I just change size of form a .resx file incleded under that particular form. Changing size of form does not add any resource so why this .resx file?
2- I dropped a button on form and a resource file is included; again this button is not some kind of resource, it is object having its creation information in designer file?
3- A resource file added on dropping button on form but if I delete this resource file and run application it compile and run with NO error and button is still there. If this button has any relation with resource file then there must by some kind of compile or runtime error AND if .resx file has nothing to do with button then why it was added?
I am using VS 2008.
EDIT:
I have added a picture box and added an image in this now this is resource. i deleted the From1.resx file and I was expecting an error but NO ERROR AGAIN. In designer file picturebox referring image from properties folder which has Resources.resx file. Double click on this and image is there. SO WHAT WAS THE PURPOSE OF From1.resx FILE?
Thanks in advance for the help
AFAIK there isn't a strict requirement, but it is probably one of those things where it is simpler (read: less brittle, more predictable, cheaper to implement, whatever) to generate the resx if there is even the suggestion that one could possibly be required (even if it turns out to be trivial) than it is to fully track the nuances of when one is absolutely demanded.
I agree; in the scenario you describe no resx is required, but it isn't going to upset me.
(it still happens in VS2010, btw - but then I suspect you shouldn't hope for much change to winforms in VS2010)
It seems that the resx file for that form is most likely tied to localization. I.e. For localizing Text content such as the text on the button. When you add a resource such as an image file by default it is placed in the applications resx file that is located in the My Project folder. So if you have the form or projects language set I think that it will always create a local resx file for that form when you add a control that could be localized.

Resources