1 00:00:00,000 --> 00:00:04,840 [MUSIC] 2 00:00:04,840 --> 00:00:05,970 Hey there. 3 00:00:05,970 --> 00:00:10,180 I'm Ben, and in this workshop we're going to learn how to use the options menu. 4 00:00:10,180 --> 00:00:14,430 The options menu is the set of options you usually see at the top of an application, 5 00:00:14,430 --> 00:00:18,300 and it's where you should place any actions related to the current activity. 6 00:00:18,300 --> 00:00:20,860 Let's take a look at the app we'll be making to get acquainted with 7 00:00:20,860 --> 00:00:22,130 the options menu. 8 00:00:22,130 --> 00:00:25,450 In this workshop we'll be making an app to let us change the colors 9 00:00:25,450 --> 00:00:27,610 of a few preloaded images. 10 00:00:27,610 --> 00:00:32,710 Up here is the options menu, where we have two items being displayed, and 11 00:00:32,710 --> 00:00:34,470 four more in the overflow menu. 12 00:00:35,560 --> 00:00:39,848 The first item lets us cycle through the three images. 13 00:00:39,848 --> 00:00:43,810 And the second one toggles the image between color, and black and white. 14 00:00:45,230 --> 00:00:48,950 In the overflow menu we have a check box for each color channel. 15 00:00:48,950 --> 00:00:53,010 And if we uncheck one, that color is removed from the image. 16 00:00:53,010 --> 00:00:56,470 Finally, the Reset button just resets the image to normal. 17 00:00:57,700 --> 00:00:59,710 And one more thing, if we have a black and 18 00:00:59,710 --> 00:01:04,090 white image, it doesn't really make sense to remove color from it. 19 00:01:04,090 --> 00:01:07,140 So we're not going to show the color options unless it's 20 00:01:07,140 --> 00:01:08,700 actually a color image. 21 00:01:08,700 --> 00:01:12,350 That's enough about the project for now, let's start making it. 22 00:01:12,350 --> 00:01:14,537 If you'd like to follow along, pause me and 23 00:01:14,537 --> 00:01:17,738 download the starter project from the teacher's notes below. 24 00:01:17,738 --> 00:01:20,964 All right, now that we've got our project, let's open up MainActivity and 25 00:01:20,964 --> 00:01:22,265 see what we're working with. 26 00:01:27,948 --> 00:01:30,450 At the top we've got a few fields. 27 00:01:30,450 --> 00:01:35,119 There's one for our imageView, followed by an array to store our resource IDs, and 28 00:01:35,119 --> 00:01:39,180 an imageIndex to store which resource ID we're using. 29 00:01:39,180 --> 00:01:43,740 Then there's a boolean variable to determine if the image is in color. 30 00:01:43,740 --> 00:01:47,460 And finally three more booleans to determine whether each color 31 00:01:47,460 --> 00:01:48,720 should be on or off. 32 00:01:50,410 --> 00:01:53,239 In the onCreate method, we just set our layout, 33 00:01:53,239 --> 00:01:57,800 populate the imageView field, and then call the loadImage method. 34 00:01:57,800 --> 00:02:01,080 If you try to load a large image into an imageView, 35 00:02:01,080 --> 00:02:03,590 Android will throw an out of memory error. 36 00:02:03,590 --> 00:02:07,740 However, by using the Glide library, we don't have to worry about that, and 37 00:02:07,740 --> 00:02:11,275 we can just load the image right into the imageView. 38 00:02:11,275 --> 00:02:15,085 At the bottom of the class, we have two more functions that aren't being used yet. 39 00:02:15,085 --> 00:02:19,575 The first is updateSaturation, which will toggle the image between color, and 40 00:02:19,575 --> 00:02:22,755 black and white, depending on the value of our color field. 41 00:02:23,765 --> 00:02:26,390 The second method is updateColors. 42 00:02:27,520 --> 00:02:32,050 This method will set the colors of our image based on the values of the red, 43 00:02:32,050 --> 00:02:33,720 green, and blue fields. 44 00:02:33,720 --> 00:02:36,190 All right, that should be enough to get us started. 45 00:02:36,190 --> 00:02:38,980 In the next video we'll start implementing our options menu.