Handling resource xml files - java

I'm new to development and would like to clarify a couple of simple points,
When I create a new drawable xml file I place it in the "drawable-hdpi" folder and only that folder, I can access it fine like so....
android:src="#drawable/button_border"
but is that the correct correct way? or should they be in their own folder in the res folder, or just the file placed in the res folder and not in any particular sub-folder?
also if I wanted to create a arrays.xml file what folder should that be created in.
Thank you.

Your arrays should go to the values folder, so res/values/arrays.xml, as per the documentation.
As for the images, it is a good practice to provide relevant images in each drawable folder according to the screen sizes you plan to support for your app, or some of your users will end up seeing badly sized images, more details here. You can use the Android Asset Studio to generate icons, for example.

The different xml file like attr.xml, colors.xml, arrays.xml, dimens.xml, font.xml, strings.xml, styles.xml should be kept in the res/values folder.
The others custom xml file should be keep in the drawable folder.

Related

How to use SceneBuilder's DarkTheme in my application

Firstly, is it legal to use the dark theme of JavaFX's SceneBuilder 2 in my application? Since it is open source now here: SceneBuilder/css
Secondly, how to do this if legal? Or just for training purposes if not legal?
I tried to download the ThemeDark.css file from the link above and add it to my fxml file, but i see no change applied.
Any ideas ?
Edit (what I did):
I have downloaded the .css file and pasted it in package css.
Then I added these lines in my .fxml file (with the <> symbols but I removed them in this question as they hid the text if present) :
stylesheets
URL value="#/css/ThemeDark.css"
/stylesheets
See below resulting screenshot: (themeDark not applied)
If you are using SceneBuilder you can add a global css sheet to it and be happy with the new look.
Alternative, if you want to set it within your code you can use
scene.getStylesheets().clear();
scene.getStylesheets().add("path/stylesheet.css"); // Modify to your path
to add a style-sheet. Notice that you should put your style-sheet in a resource folder in your application, just to keep everything cleaned up.

Maven build copy files form a common folder to specific folders

I have a folder in the file system were I have saved all the Javascripts, css and images and I am building a website with different themes. Therefore in the common folder I have all the common files that have to be copied under the specifc folders at build time.
For example I have the common folder under c:user\common with this structure
/common
--/css
----myglobal.css
--/img
----common.png
--/js
----mycommonjavascripts.js
And given a theme like this And a give theme is:
/my-theme
--/css
----mycss.css
--/img
----brand.png
----logo.jpg
--/js
----specific.js
As result I would like to have, if unzipped:
/my-theme
--/css
----myglobal.css
----mycss.css
--/img
----common.png
----brand.png
----logo.jpg
--/js
----specific.js
----mycommonjavascripts.js
Does anybody have an idea how I can achieve a result as shown above with maven?

How to group a folder structure in a common navigator view in an eclipse-rcp application?

I have a question concerning the folder structure of a common navigator view (package explorer) in an eclipse-rcp application.
My goal is to group the source folder of a project.
As you can see in the picture above the source folder of the project “Sample” is src + main + resources. I would like to group that source folder so that there is only one line displaying the text “src.main.resources”. This should not be reached by changing the folder structure in the file system.
So my question is: Is it possible to group the source folder programmatically without touching the physical folder structure?
Any help would be appreciated!
Cheers!
After doing a lot of research, I'm trying a different approach. I am using a decorator class to modify the label of the source folder.
To reach the goal of the original question, I would like to hide the first two levels of the source folder so that there is only one line displaying "src/main/resources". Sadly, IFolder.setHidden(true) does not work because it also would hide the children of the node.
Is there a possibility to hide these two folders by using a filter for example? Or do I have to modify the Tree of the Navigator?
Thank you in advance!
There are a number of resources and articles you can look into:
http://help.eclipse.org/juno/index.jsp?topic=%2Forg.eclipse.platform.doc.isv%2Fguide%2Fcnf_config.htm
http://scribbledideas.blogspot.dk/2006/05/building-common-navigator-based-viewer.html
http://scribbledideas.blogspot.dk/2006/05/building-common-navigator-based-viewer_22.html
http://scribbledideas.blogspot.dk/2006/06/building-common-navigator-based-viewer.html
http://scribbledideas.blogspot.dk/2006/06/building-common-navigator-based-viewer_18.html
http://scribbledideas.blogspot.dk/2006/06/building-common-navigator-_115067357450703178.html
With this information, you should be able to do everything with CNF :-)

Reading Assets in Eclipse

I am developing a little game where I use some pictures for the sprites etc etc.
It works just fine when I load it from the disc like this
Image image = new Image("C:\\AppleMan.png");
but how can I load it from a foloder within the project. I am using eclipse as IDE and the language is Java :)
I took a screenshot of a sample project so you can see how I have importet the picture
So I want to load the picture from that resource folder like this pseudo code
Image image = getResource("Resources/AppleMan.png");
but that simply doesn't work.
Any help appreciated :)
1) You should add Resources folder to classpath
2) You should locate file absolutely, i.e. "/Resources/AppleMan.png"
P.S.
3) Sorry, also note that getResource returns URL: http://docs.oracle.com/javase/6/docs/api/java/lang/Class.html#getResource%28java.lang.String
You're passing a relative path when you were passing a absolute path before. Add the path of the Eclipse workspace.
For example, if your workspace is at C:\Workspace, you need to put
Image image = getResource("C:\\Workspace\\HowToGetResources\\Resources\\AppleMan.png");

Images are not displaying in jar but displaying in compiler?

I know, I know, this has been asked before. But every resource I've looked at uses IconImages while I just have plain Images.
Is there a different solution? Please help as I've been stuck researching and trying to figure this out for days now with no progress.
Image Floor = Toolkit.getDefaultToolkit().getImage("Floor.PNG");
EDIT: If I was to make sure the jar wouldn't compress and I created a seperate directory in the jar for images and put the correct file path, would this code work?
Toolkit#getImage(String s) looks for a file and likely your image is in the Jar and is now a resource not a file. Look to using resources for this.
Note that ImageIO.read(...) can accept an InputStream parameter the Class class has a method, getResourceAsStream(...) which can put the resource into a Stream that ImageIO can read. Give that a try.
Also, are you getting any error messages when you try what you're doing?
Make sure you know what your current directory is, and how it relates to the position of the files in your jar.
Here's how I would handle it.
1) Require there to be a file called "images.txt" in the directory with your jar (or bundle it into the jar.)
2) Make a file called "images.txt" with a format like `FLOOR:C:\\images\\floor.png`
3) Load this file into memory on load.
4) Load your images based on the entries in the file
This will give you the advantage of changing your images without changing your code if it's defined outside the jar :)
It's not loading because you're not putting the path to the images in the declaration. It expects the images to be wherever the jar is (notice there's no directories there)
You need to offload the definition of the file names to a file, or at the very least guarantee the relative position of the files.
Another good option is to put the images in the jar itself, say in an img directory, and reference them there. But then changes to the images require a new jar, which may not be desired for development purposes.
The getImage call is looking in the file system working directory, not inside the Jar file. This is why the jar file loads the images successfully when they are placed in the same directory outside the jar file. If the images are bundled in the jar file, they are no longer file system files to be accessed, but rather Jar file resources. There is a different way to load these, but sorry, I don't know it off the top of my head.
Check the extension of files. I had this problem because the extension was "PNG", when I changed it to "png", everything was ok.
You can't expect a JAR file to magically know where your images are. If you put a JAR file alone on the desktop, it's going to look for the files on the desktop! The code
getImage("Floor.png")
searches the current directory of the JAR (or source project) by default and you'd expect that if the JAR was in the same directory, it would work. If the JAR is on the desktop how does it know where Floor.png is? Of course, you can specify a hard-coded path
getImage("C:\Some Folder Path\Floor.png")
but then Floor.png has to be in C:\Some Folder Path\ for the JAR to work properly.
It sounds like what you really want to do is keep the images in the JAR file (which acts like a ZIP file). The tutorial on doing that is here:
http://download.oracle.com/javase/tutorial/uiswing/components/icon.html#getresource
And I know for ImageIcon you use: new javax.swing.ImageIcon(getClass().getResource("myimage.jpeg") but I have not found anything similar for plain Image.
<head-desk /> You should really get into reading the JavaDocs. Otherwise you are 'coding by magic'. Which generally won't work.
URL urlToImage = getClass().getResource("myimage.jpeg");
// If you need to support Java 1.3
Image image = Toolkit.getDefaultToolKit().getImage(urlToImage);
// If your users have dragged their JRE into this millennium
BufferedImage bufferedImage = ImageIO.read(urlToImage);

Categories

Resources