lab 6 · 2020-03-08 · 5 android menu: • in android, to define menu, we need to create a new...
TRANSCRIPT
1
• Done by:
L.Rawan ALAmri
LAB 6
OUTLINE
INTRODUCTION
ARRAY REPRESENTATION
Evaluation
2
1
3
How to create your menu
How to insert Location
Exercise1 (Menu)
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.
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.
6
Add new xml file popup_menu.xml:
7
Choose resource type as menu then name your xml file:
12
3
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.
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.
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.
11Output (1-Option Menu):
15Output (2-Context Menu):
16
Add new xml file menu_main.xml (repeat the same steps):
20Output (3-Popup menu):
22
Add new xml file popup_menu.xml:
23
Choose resource type as menu then name your xml file:
12
3
24
Add new xml file popup_menu.xml:
Exercise2 (Map)
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.
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.
29Output (Show specific location):
30
Choose Google Mapes Activity:
31Copy the URL from google_map_api.xml file to generate Google map key:
32Paste the copied URL at the browser, It will open the following page:
33
Click on Create API key to generate API key:
Copy this generated API key and paste in our google_map_api.xml file
1- Paste here
2- copy the attribute name
Add the following user-permission in AndroidManifest.xml file.
Paste here
Evaluation [ /1 Marks]
41Restaurant Location and items:
Your own logo
Location
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.
43
THANKS