 My name is Tushar Sharma and here I am going to discuss video about app resources and supporting multiple screen. In this session, we will cover app resource definition, type of resources, resource directory tree structure, then type of resource directories and assets. After that, we will see one example to see the implementation of different type of resources. Then, we will cover supporting multiple screens, density independence and screen compatibility example. Now, first of all app resources. What are app resources? Resources are additional declarative files and static contents means these are external files in which we declare our resources once and use in our Java program at Java code and XML file at any time. But all the modification will be saved at the compilation time only, but no changes and no changes occur at the runtime. So, Android creates the resource ID for using them in Java programs. So, for assessing these resources, we need to assess the R-class file. As we had discussed in the previous session, R-class file is used to create the different IDs for the different type of resources. Now, type of resources. There are different type of resources which can be possible in the Android is string resources. String resources is used to provide the text string and these can be assessed by the r-string.string name. This r is the class file name. Then after the dot, we need to pass the type of resources which we want to refer. Then among those resources, we need to select the particular resource name by using the resource name. Then color resources. Color resources are used to define the color set for the project and we can refer them by the r dot color dot color name. Then style and theme resources are used to define the look and format for the project. They can be assessed by the r dot style dot style name. Then dimension resources carries the unit of the measure of the dimension or the size. And now dimension can be of different types like points, inches, scale independent pixel, density independent pixel. These are defined by the Android libraries. So we need to follow only those dimension which are defined in Android only. Now another is the color drawable resources. Color drawable resources is used to define the, to fill the canvas or we can define the, declare the, we can create the color rectangle using the color drawable resources. Now color drawable resources are assessed by the r dot drawable dot rectangle green which is the name of the particular color drawable. And then another way to assess the color drawable is r dot values dot rectangle green because the color drawable resources can be stored in a drawable or the value subdirectory. Now another is the drawable resources. Drawable resources are used to define the bit mass, nine patches and other XML file. And they can be assessed by the r dot drawable dot image name or the file name, any file name. Now layout resources are used to define the application user interface as we discussed in a previous session. Then if they are referred by the r dot layout dot layout name, there the layout name is the app resources. Now another is the manus resources, manus resources are used to define the application manus which is appear on the layout by clicking the menu option as we discussed. Then they are referred by the r dot manu dot manu name. Another is the animation, animation resources can be categorized, animation resources is used to put the animation on the object. And they can be categorized as the property animation, frame animation and view animation. Actually the animation can be, animation is only of two types which is the property animation and twin animation. For more clarification this twin animation is categorized as frame animation and view animation. Now they can be referred by the r dot animations subdirectory. We need to create the separate subdirectories for defining the animation, then dot the animation file name. Now for understanding how and these resources are stored in our project, have a look at the resource directory tree structure. On the top of the tree structure you can see this is the resource, this is the root directory of the project. Under this root directory there are different types of folder are created. Between these folder there is a assets also which we will discuss in our next slide. Then there is a resource folder, resource folder is used to contain the different type of resource subdirectories like drawbell resource subdirectory, layout resource subdirectory, new resource subdirectory, value subdirectory and the drawbell subdirectory and the value subdirectories are further classified, further categorized. Now drawbell subdirectory can be categorized as sdpi, ldpi, mdpi, xsdpi. In sdpi the images of high density are stored. Then drawbell ldpi is used to store the devices images of the low density. Then mdpi is used to store the images of the medium density and xsdpi is used to store the images of the extra high density. Depend upon your screen configuration you have to store the drawbell resources into their particular subdirectories. Now layout subdirectory is used to store the layout resources only and menu subdirectory is used to store the menu resources. Value subdirectory is used to store the multiple type of resources like string resources, style resources, color resources, color drawbell resources and dimension resources and some other kind of the resources are possible in the values subdirectory which are like the Boolean and some other. Now here you can see the value is also categorized as the three folders. Values folder is used to store the XML files of the resource file which are used by default. Then values v11 is used to store the style XML file which is used to support the Android 3.0 or the below version. Then values v14 is used to support the XML file which is support the XML file of the Android version above than 3.0. This is the resource directory tree structure which is created by default but we can use some other subdirectories to create in this folder for using the other type of resources like the animation XML and the raw. We can include this in by manually creating the file subdirectories. Now the other different type of resource directory which can be possible in an Android project are animes subdirectory, animators subdirectory, drawbell subdirectory, layouts subdirectory, menus subdirectory, raw subdirectory, then the values subdirectory and the XML subdirectory. Animes subdirectory is used to store the view animation and animators subdirectory is used to store the property animation. Actually animes subdirectory can be used to store any kind of the twin animation. Now drawbell subdirectory is used to store the drawbell resources or the color drawbell resources. Then layouts subdirectory is used to store the XML files which is used to define the layout layout for the project, menus subdirectories are used to define the XML file or the resource file for the menu resources. Then draw subdirectory is used to store the raw files. Raw files are actually the any read only files like the audio or the video. Values subdirectory is used to define is used to store the multiple type of resources like color resources, color drawbell resources, dimension resources, string resources, style resources and some other as we discussed earlier. Now XML folder, XML folder is used to store the XML file which is used at the run time only. So that is why we have created the XML file, XML folder also in our resource directories. Here is the assets, assets as we had seen in a previous pre-structure is defined is created by default when you create any indirect project for storing the raw assets files and file saved in the assets directories are not given the resource ID. The main difference between the raw and the assets are this that assets resources are not given the resource ID. So we cannot assess the assets by referring to the class file. So we can refer them by we can refer them by the like the normal file system file by passing the URL into the location and it reads the raw data using the assets manager. While the raw resources are created manually in the resource subdirectory and they are given the resource ID for assessing the any kind of the resources defined in the raw folder. The raw folder is also used to store the read-only files like the assets and file that save in the assets are used at the are compiled into the .apk file. Then assets you then assets are more flexible and functionally provide the more functionality than the raw. We can list the assets subfolders into the assets directory and we cannot list the raw files in a raw subdirectory. Now assets can be assessed by using the assets manager. So here by these two lines of code we can assess the assets in our project. Assets are assessed by the creating the object of the asset manager which called the get assets function. Then this object called the open function and in this open function we pass the parameter as a some file some raw file which we want to read. This store the approximately maximum size of 1 MB file. Now after this we are going to see the implementation of these different type of resources. Then we will cover supporting multiple screen and I will explain each code. So this is the resource directory this is the tree structure of the resource directory as I had shown you in the snapshot. Then under this go to the resource directory under this resource directory different type of resources of directories are created like anim drawbell layout menu values here drawbell layout menu and values are by default created but anim we have to create manually for using the animation resources. Now for creating the first we are going to see the use of the layout resources. So this is the eclipse view of the project. So in this is the project root directory under this root directory there is a resource directory. In this resource directory different type of resources of directory we can create like anim drawbell layout menu values in between this the drawbell layout menu and values are by default created but for the other type of resources we need to create the sub directories like anim we have to create manually xml folder we have to we can create manually. Now first we are going to see the use of the layout resources layout resources for layout resources go to the resource directory under this resource directory find the layouts sub directory under this layout sub directory you can create your own xml file by right click and adding the xml file to this for creating your layout resources we are going to see the only the use of the application user interface. So we are not going to discuss very much about the layout as we had discussed in a previous session. So have a look at the app resource dot xml which is the main dot xml main dot xml or the app resource dot xml is used to define the application user interface when we go inside this xml file we can see relative layout is by default present relative layout is used to define the project properties or the feature which will first appear when you click the apk file under this we define the project properties like under this resource file in the under this relative layout different type of project properties are defined like text view text view is the one properties of the project which we want to display in a relative layout then another text view is also present here then button after that image view these items are displayed this item will be displayed in a relative layout as a output. So whenever we run the project this image view button and the text view are appear as a output on the relative layout as we had discussed in a previous session of the widgets and the layout so we are not going to discuss their properties so in this way but app resource dot xml is by default created so we need not to create application user interface we define only the properties of the app resource dot xml. Now for using the app resource dot xml or the main layout as a output for the project go to the app resource directory root directory under this root directory go to the source directory in this you can find the package is defined in this package go to the app resource dot java so for assessing the main layout xml file as a output of the application user interface so set the content view set the content view function as a reference of this relative layout. Now set content view is in under this set content view function we had passed the reference of the relative layout in this function in this reference r is the class file in which different resource id's are created then layout is the particular type of resource which we want to display like here I want to display the layout resources layout resources then app resource is the particular layout resources which I want to display as a output so in this way I had displays my app resource dot xml as a output of the application user interface so whenever we click our apk file this app resource dot xml content are displayed as a output so by calling the function set content view. Now another kind of the resources is the string resources for string resources go to the values of directory under the resource directory and you can add your own xml file for creating the string resources or here by default strings dot xml is present so I am using this strings dot xml for creating the resources when you click this strings dot xml the two kind of the tab is present here resources and the string dot xml means there are two possible ways for creating the xml resources in your project one is the by using the resource element resource file and another is the strings dot xml file in this resource in this resource file you can find different types of the resource element are defined this is the icon for the string resources then color resources color resources then drabel then dimension then style item string array and the integer array element and this is another for the plural of the string now for creating using the resource element resource element is provided by the android libraries to create your project without writing any code so just click the add button select the select the resource which you want to create like color dimension drabel integer array item and different type of resources are present to which we can create now for creating the string resources select the string and click the ok in the right side of the right side of the page you can find two text fields are defined first is the name text field in name text field you have to pass the name of the resource name of the resource is actually used to refer the project means by the name we can only assess the project like in the widgets we at find that we are assessing by the ids in this resources we are we can assess by the resource name then string is the resource name then pass the value of the string which you want to display as a output like I want to display this is string using the resource element so in this way we can create the string resources by using the resource element another way is by using the strings.xml for string.xml I do not use this resource for the output so I can delete this so just I remove this so I am going to show you the creating the resources by using the string.xml the same string I can create using the string.xml in a string.xml just open the tag and pass the particular tag name which you want to use for the resources like I want to create the string resources so I created the string tag into this string tag first set the properties of the tag by name which we required to refer the project so I set the name for the this particular string as a as a android and android workshop then pass the value in between the tags which you want to display as a output like this is a android workshop now in this way we can create the string resources by using the string.xml and another way we had seen that by using the resource element in the resource element this name tag is provided name text field is provided to create the name and the value is provided value field is provided to pass the value but here we are doing different thing different by a different way for creating the same resources so we do not use this string as a output so I can delete this so this is the two way for two ways for creating the particular string for particular resources using the resource element and using the xml file of that resource now for using the string resources two ways are possible app resource dot xml and app resource dot java app in app resource dot xml let's say I want to display this string on a text view so so I want I want to display this string in a text view for this purpose I set the text property text property of the text view as a reference to the particular string where at the rate is used for pass for reference purpose and here we can pass the particular type of resource which we want to assess like I want to assess the string resource so I write the string then after the slash you will need to pass the name of the particular string which you want to display as a output so three things we need to pass into this text into this text property at the rate then at the rate for reference purpose then type of resource then name of the resource so in this way we can assess the particular string and that is the another string which we have defined in a string dot xml file and this value is android workshop now another way is by using the app resource dot java you can see the app resource dot in app resource dot xml I had also created the another text view in this text view I had passed the reference for the another string string resources that both the same string are present so I just change the one string name so one string is displaying the this is a string as a output and another is another will display the android workshop as a output so another way for referring the using that this string dot xml is app resource dot java for this purpose I will change this name so both the name is so both that text view will display the same output which is the android workshop so go to the app resource dot java in this for displaying the output in a text view we need to first assess the text view so in this way we can assess the text view as we had discussed in a previous session so for assessing the string resources we need to first create the string variable in a string variable we need to store the string resources in a string resources for storing the string resources into this variable we need to first assess the different type of resources which can be used in a android project by using the get resources function get resources function is used to assess the all the type of resources in a project among get resource function is used to assess the all the different kind of resources which is created in a project then among those different type of resources I have to select the string resources so I need to pass the get string function we need to just write the get and type the type of the string resources like I want to assess the string resources so pass the get string function so into this get string function just pass the reference to the particular string which you want to appear as a output so r dot r is the class file name as we discussed then string is the particular type of resource like string resource here then name of the particular string which you want to display as the output so we need to pass the reference to the particular string in a get string function so in this way we had assess the get string function and store this into the string variable now if I want to display this string as a output on a text view one so I set the text view one I call the text view one property which is set text and pass the parameter as a variable of the string resources then this particular string is replaced into the text view like we had seen previously that in both the text view I had defined the same string like android workshop so now I had replaced the this string by string resources which will display this is a string as a output in this particular text view now if we run this project then this will appear as a output I had already run this project for saving the time so you can see this the one is the first is the android workshop string I had written using the app resource dot XML and another is also written by using the app resource dot XML but that value is the android workshop but using the app resource dot java I change this value as a this is a string so another this text view will change to the this is a string as a output using the app resource dot java so in this way you can as create and use the string resources so they are the similar way for creating and using the different type of resources now we are going to see the use of the color resource color resources color resources are also stored in a values of directory so create the XML file for the color resources in a values of directory for this go to the color dot XML I am using the same file which is present in a values of directory in colors of directory color dot XML open the color tag for the color using the color resources in this color resources in this color tag pass the name which you want to refer for this particular color then between this color tag pass the value of the color which you want to display like here we have defined the hash 0 ff it is defined by the and it is defined by the predefined format of the android which support the some hash rgb format hash rgb ggb format and some other format which is defined by the android only so this is the hash rgb format in this format for using the particular resources you need to set the value is f and for not using the particular color pass the value as a 0 like hash rgb is using the green and blue color so it is the mixture of the green and blue color but we are not using the red color so put the value of the red is 0 so in this way and right this way we can create the different type of color combination another way is by resource element in a resource element the similar way is for creating the resources click the add button and just add the particular type of resources but here you can see the these are the predefined format in which we can declare which in which we can use the value of the color resources like hash rgb hash a rgb hash rrgb or hash a a rrgb so we can in this way we can implement different type of color in our project so this is this is the two way for both the ways for creating the color dot xml or color resources so for another way for creating the color dot xml is we can also create the color dot xml into the any xml file which is present in a value sub-directly because values color dot because color resources are defined in only the values sub-directly so we can use any xml file for creating the color resources like string dot xml I am creating the color in a string dot xml just you need to only keep that in mind that color tag is used for the color resources for creating the color resources in color tag you need to pass the name of the particular color for you for referencing purpose then pass the value of the color as I had told earlier so we can I had created here yellow and a red green color for yellow I used the mixture of the red and green and this is the another color now for using the color resources go to the either you can go to the app resource dot xml or app resource dot java as I had told you that two ways are possible for now app resource dot xml I want to set the text view color as I had which I had defined in a color dot xml set the text color property of the text view for changing the color of the text like at the rate color at the rate is used for reference then color is the type of resource then green blue is the particular color name which I want to display on this text view so this text view output this will appear as in the will appear in this color format now another is the app resource dot java by using app resource dot java by using app resource dot java you can also use the color resources but color resources are only stored in a integer variable so I need to create the integer variable for storing the color resources in this integer variable I first called the get resource function for assessing the different type of resources among those resources I called the get resource function for assessing the color resources this is used for selecting the particular resources among the different type of resources then pass the parameter into this function as a reference to the particular color like r dot color dot color name which where color is defining the color resources now if I want to set this color in a background of a layout so I need to first assess the relative layout for this purpose this code will assess the relative layout we have discussed in a previous session of the layouts by using the view we can assess the relative layout then set the background of the relative layout by the color which we had defined so for setting the background we need to call the set background color function because we are changing the background color so pass the color variable into this background color function so now the color is changed to yellow so yellow may not look good so I can change the color here by 0 f as I had told I had asked to change the color of this so I am just changing the color and if I run the project just save the file and just you can see the output of this project the color is changed to the pink now it is look fine now another type of resources are dimension resources for creating the dimension resources create the resource file in a values of directly only because the dimension resources is also stored in a values of directly so in values of directly create the xml file for dimension and into this dimension xml file you can create the dimension by either using the resource element and or using the dimension dot x or the xml file so I am only going to show the use of the dimension dot xml because the time is less so for creating the dimension resources open the dimension tag into this dimension tag set the name which you want to refer for the particular dimension then pass the value of a dimension in a defined format of the dimension in a android like pixel this is for density independent pixel then scale independent pixel and there is a and pass the magnitude before these units now I had created the three type of dimension here now for using this dimension go to the app resource dot xml in app resource dot xml I want to change the dimension of the text view text view one so text view one property text size is changed to this particular dimension into this particular dimension into this text size property pass the reference to the particular dimension which you want to display as a output so at the rate dimension is used for assessing the dimension here dimension is using for assessing the dimension resource because the dimension we had used in a project then pass the name of the dimension which you want to display so in this way you can implement the dimension in your on your text view so this text view object will appear in the in this particular dimension format now another way is the app resource dot java now dimension resources are only stored in a float type variable so float into this float type variable pass the reference to the dimension resources by get resource function and get dimension for assessing the dimension the similar way for like the different resources we had used then pass the reference to the particular dimension which you want to implement then set the text view one text size by calling the text set text size function and pass the parameter as a reference to the particular dimension so in this way you had a implement the dimension resources you have seen the both the way of implementing the dimension resources now another kind of the resource is the style dot xml style is the another resource file which is present in a values of directory by default we are we can either create our own xml file but I am using this xml file for creating my another style resource I am just showing the style dot xml implementation or the resource implementation so for creating the style open the style tag pass the name of the style which you want to refer then style is the only type of resource which has the property of the inheritance it will inherit the characteristic of its parent by passing the parent name into the parent function so it can inherit the property of the office parent as you have defined the parent is app based theme so we can define the properties different properties of the particular style like text color text size and text style these are different property some other properties we we can use for the styling like text color is set to has 00F in a defined format of the color then size is set in a defined format like the scale independent pixel then text style is set to bold so in this way we had created the style dot style resources another way is by using the resource element in this you need to first click the resource click the add button then create a new element new type of resources for new style resources click the new element at the top level in resources then set the style or theme then pass the name of the style style android then parent name which you want to inherit like I want to inherit app based theme which is defined here this parent I want this style I want to use as a parent then after creating this style you can implement the different properties into this style by just click the add button and select create a new element in the selected element only means in this style you are inserting the item to define the properties of this style then set the name and the properties as we had seen in the style dot xml different properties like text color text size then I am not going to use so I have to remove this also so in this way you can create your own style resources now for using the style resources either go to the resource dot xml or in a text view if you want to use this style resources set that text set the style property of a text view and pass the difference to this to the particular type of style resources in a similar way as we discussed for the another kind of the resources now another is the app resource dot java using the app resource dot java you also can you can also implement the style resources by calling the set text appearance function onto the app resource the particular text view in which you want to implement the style resource then into this we need to pass the two parameter first is the get application context context is used for assessing the different application support resources and the class and other file name proper file properties then another is the r dot style dot style name which is the difference to the particular type of resources so in this way I had said set that style on this particular text view so another is another is the so values all the values resources are over but color draw bell is left so let us see the color draw bell but we are going to use the color draw bell resources color draw bell resources I had defined in a color dot xml file color dot xml I had told that color draw bell resources is used for creating the color rectangle so for creating the color draw bell resources we need to create open the draw bell tag but the draw bell tag value is set to some color value so it is used for defining the color color rectangle and the name we need to pass for assessing the particular color draw bell resources so in this way we had created the color draw bell resources for assessing the color draw bell resources go to the app resource dot java and set call the color create the color draw bell object here and we need to type we need to type cast it because we are assessing the draw bell tag so this is used for specifying that this is color draw bell resource only and get resource function is used for assessing the color different type of resources then get draw bell is for assessing this color draw bell resources or the color draw bell resources then pass the parameter into this function as a reference to the particular color draw bell resources then set this color draw bell on to the background of the particular text so set background draw bell as the reference to the particular color draw bell object then another is the in this way we had implemented the color draw bell resources now another is the manual resources for manual resources we have seen in a previous session so I am not going to discuss it very much just see the xml file we need to just create the item as we have seen in a previous session and set its properties like id for assessing the particular item title is which we want to display on a output which is about and help two item I had created in a menu then in this way we had created the menu dot xml so go to the app resource dot java for assessing the menu resources and go to the on create option menu function and now we are going into this function parameter is the menu object then call the get menu inflator function for using the menu resources and call its inflate function to invoke this menu resources on your application manners then we need to pass the two reference to two parameter like reference to the particular menu and the object of the this function and this is the Boolean type function so it will return true we need to define the true after creating all the type of menu which we want to display so another type kind of the resources the draw bell resources draw bell resources for draw bell resources at the images into the particular draw bell sub directive depend upon your screen size configuration use the draw bell resources by this app resource and by this code the similar code is present so we need not to discuss after that so in this way we had used the draw bell resources so last is the animation is left so animation will be more explained in a next presentation on a particular animation only so as a limit on a time so I am not going to discuss animation resources but I had created that two xml file for animation this is for view animation and this is for frame animation into this just set the animation view animation frame animation property which display the sequence of images and view animation is used to rotate scale or translate the object so now we can see the object output that the rotating button is showing the view animation by just setting the rotate property into the view animation file then when we click the button then in this particular image view this is displaying the sequence of images as a output which is used by the frame animation in frame animation we had declared the several type of images in a item tag and so in this way we can use the different type of resources now we are going to quickly see the supporting multiple screen properties so as the android runs on a variety of the devices so it suppose the multiple screen depends upon the screen characteristics like size, density, aspect ratio and orientation now size is the size of the layout density is the physical measure of the layout then aspect ratio is the nothing but a resolution only orientation is the alignment when we rotate the device so size can be small, normal or large small size is range from 426 dp into 320 dp where dp is the density independent pixel then normal is the range from 470 dp into 320 dp and large size screen is range from 640 dp into 480 dp you can say follow this chart for analyzing the ranges of the different screen support properties now another is the we can set the screen support property by modifying the manifest dot xml and the screen support some screen support properties are large screen, normal screen, small screen, this size well and any density for android version 3.0 or below these are set to true but for the above these are set to any density is set to false for below version now density independence, density independence is used to express the layout dimension or a position in a density independent way we can see these three images first is high density, second is low density, second is medium density and third is low density for more explanation you can go to this link now screen compatibility example in first is in first image you can see the normal size normal density normal size means the layout size is normal means any image of the large size is completely fit to the screen and normal density means the less number of the pixel is present in a display area then the large density you can see the another image of the normal size and high density both the image of normal size means both cover the same both cover the full screen then the density is in the first image normal density and the second image is the high density in normal density it will cover less number of the dots per inches then another will cover more points in this display area now you can see third image in the third image and the first image you can see the difference normal size and the large size normal size means normal size means layout size is normal so any image will completely cover the whole area of the layout but the if the layout size is large so image is not able to completely fit to the layout then in a high density and the high density as I discussed it will cover more points so it will cover the maximum area than the normal density large size now summary as we had discussed earlier resources are declarative files and static contents then resource directory structure we had discussed then supporting multiple screen properties and density independence for the more explanation go to these links and this books this book for more explanation so thank you everyone