lab 6 · 2020-03-08 · 5 android menu: • in android, to define menu, we need to create a new...

43
Done by: L.Rawan ALAmri LAB 6

Upload: others

Post on 17-May-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

1

• Done by:

L.Rawan ALAmri

LAB 6

Page 2: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

OUTLINE

INTRODUCTION

ARRAY REPRESENTATION

Evaluation

2

1

3

How to create your menu

How to insert Location

Page 3: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Exercise1 (Menu)

Page 4: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

4

Android menu type:

• In android, we have a three fundamental type of Menus available to define a set of options and actions in our android applications.

• In android, Menu is a part of the user interface (UI) component which is used to handle some common functionality around the application. By using Menus in our applications, we can provide better and consistent user experience throughout the application.

• The following are the commonly used Menus in android applications:o Options Menu is a primary collection of menu items for an activity and it is useful to implement actions that have

a global impact on the app, such as Settings, Search, etc.

o Context Menu is a floating menu that appears when the user performs a long click on an element and it is useful to implement actions that affect the selected content or context frame.

o Popup Menu is displays a list of items in a vertical list that’s anchored to the view that invoked the menu and it’s useful for providing an overflow of actions that related to specific content.

Page 5: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

5

Android Menu:

• In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML file to build the menu with the following elements.

• See slide 6 and 7.

Element Description

<menu> It’s a root element to define a Menu in XML file and it will hold one or more and elements.

<item> It is used to create a menu item and it represents a single item on the menu. This element may contain a nested <menu> element in order to create a submenu.

<group> It’s an optional and invisible for <item> elements. It is used to categorize the menu items so they share properties such as active state and visibility.

Page 6: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

6

Add new xml file popup_menu.xml:

Page 7: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

7

Choose resource type as menu then name your xml file:

12

3

Page 8: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

8

1- Option Menu:

Attribute Description

android:id It is used to uniquely identify an element in application.

android:icon It is used to set the item's icon from the drawable folder.

android:title It is used to set the item's title

android:showAsAction It is used to specify how the item should appear as an action item in

the app bar.

• Android Options Menu Attributes: following are the some of commonly used attributes related to options menu control in android applications.

Page 9: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

9

2- Context Menu:

• Android context menu appears when user press long click on the element. It is also known as floating menu.

• It affects the selected content while doing action on it.

• It doesn't support item shortcuts and icons.

Page 10: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

10

3- Popup Menu:

• Android Popup Menu displays the menu below the anchor text if space is available otherwise above the anchor text. It disappears if you click outside the popup menu.

• The android.widget.PopupMenu is the direct subclass of java.lang.Object class.

Page 11: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

11Output (1-Option Menu):

Page 12: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 13: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 14: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 15: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

15Output (2-Context Menu):

Page 16: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

16

Add new xml file menu_main.xml (repeat the same steps):

Page 17: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 18: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 19: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 20: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

20Output (3-Popup menu):

Page 21: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 22: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

22

Add new xml file popup_menu.xml:

Page 23: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

23

Choose resource type as menu then name your xml file:

12

3

Page 24: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

24

Add new xml file popup_menu.xml:

Page 25: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 26: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Exercise2 (Map)

Page 27: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

27

Android Google map type:

• Android provides facility to integrate Google map in our application. Google map displays your current location, navigate location direction, search location etc. We can also customize Google map according to our requirement.

• There are four different types of Google maps, as well as an optional to no map at all. Each of them gives different view on map. These maps are as follow:

1. Normal: This type of map displays typical road map, natural features like river and some features build by humans.

2. Hybrid: This type of map displays satellite photograph data with typical road maps. It also displays road and feature labels.

3. Satellite: Satellite type displays satellite photograph data, but doesn't display road and feature labels.

4. Terrain: This type displays photographic data. This includes colors, contour lines and labels and perspective shading.

5. None: This type displays an empty grid with no tiles loaded.

Page 28: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

28Android Google map Methods:

Methods Description

addCircle(CircleOptions options) This method add circle to map.

addPolygon(PolygonOptions options) This method add polygon to map.

addTileOverlay(TileOverlayOptions options) This method add tile overlay to the map.

animateCamera(CameraUpdate update) This method moves the map according to the update with an animation.

clear() This method removes everything from the map.

getMyLocation() This method returns the currently displayed user location.

moveCamera(CameraUpdate update) This method reposition the camera according to the instructions defined in the update.

setTrafficEnabled(boolean enabled) This method set the traffic layer on or off.

snapshot(GoogleMap.SnapshotReadyCallback callback)

This method takes a snapshot of the map.

stopAnimation() This method stops the camera animation if there is any progress.

Page 29: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

29Output (Show specific location):

Page 30: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

30

Choose Google Mapes Activity:

Page 31: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

31Copy the URL from google_map_api.xml file to generate Google map key:

Page 32: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

32Paste the copied URL at the browser, It will open the following page:

Page 33: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

33

Click on Create API key to generate API key:

Page 34: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Copy this generated API key and paste in our google_map_api.xml file

Page 35: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

1- Paste here

2- copy the attribute name

Page 36: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 37: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Add the following user-permission in AndroidManifest.xml file.

Page 38: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Paste here

Page 39: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML
Page 40: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

Evaluation [ /1 Marks]

Page 41: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

41Restaurant Location and items:

Your own logo

Location

Page 42: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

42

Q1) You should follow the lab steps to build the previous output.

• The app should show the restaurant menu and button to show on another activity the restaurant location as on previous slide.

• Each student choose different items for the menu, design color and logo than other colleague, any similarity both will get ZERO.

• You can use any type of android menu.

Page 43: LAB 6 · 2020-03-08 · 5 Android Menu: • In android, to define menu, we need to create a new folder menu inside of our project resource directory (res/menu/) and add a new XML

43

THANKS