Styles, Dialog Boxes, and Menus. Styles Allow creation of a common format – placed in res/values/styles.xml – file name is incidental Can be applied.

Slides:



Advertisements
Similar presentations
CE881: Mobile and Social Application Programming Simon M. Lucas Menus and Dialogs.
Advertisements

0 UMN 2011 ERP Terapan SAP BASIS General Concept Session # 3.
User Interface Classes.  Design Principles  Views & Layouts  Event Handling  Menus  Dialogs.
Cosc 5/4730 Blackberry and Android: Menus. BLACKBERRY.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Cosc 4730 Android TabActivity and ListView. TabActivity A TabActivity allows for multiple “tabs”. – Each Tab is it’s own activity and the “root” activity.
Android Development (Basics)
CST JavaScript Validating Form Data with JavaScript.
PROG Mobile Java Application Development PROG Mobile Java Application Development Event Handling Creating Menus.
8 Copyright © 2004, Oracle. All rights reserved. Creating LOVs and Editors.
Introducing the Sudoku Example
ANDROID UI – FRAGMENTS. Fragment  An activity is a container for views  When you have a larger screen device than a phone –like a tablet it can look.
ICP Kit 2011 HHC Data Entry Module The World Bank ICP Kit Training African Development Bank.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Chapter 8: Writing Graphical User Interfaces
Copyright © 2007, Oracle. All rights reserved. Managing Concurrent Requests.
Doodlz App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
DUE Hello World on the Android Platform.
@2011 Mihail L. Sichitiu1 Android Introduction GUI Menu Many thanks to Jun Bum Lim for his help with this tutorial.
Mobile Computing Lecture#11 Adapters and Dialogs.
TxEIS Security A role-based solution October 2010.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Chapter One An Introduction to Visual Basic 2010 Programming with Microsoft Visual Basic th Edition.
Chapter 1 - Getting to know Greenfoot
SpotOn Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Programming Mobile Applications with Android September, Albacete, Spain Jesus Martínez-Gómez.
Android Boot Camp for Developers Using Java, 3E
Android – Fragments L. Grewe.
Cosc 5/4730 Dialogs and below 3.0 and above (fragment)
User notification Android Club Agenda Toast Custom Toast Notification Dialog.
Themes and Menus: The Sudoku Example Content taken from book: “Hello, Android” by Ed Burnette Third Edition.
Copyright © Curt Hill More Components Varying the input of Dev-C++ Windows Programs.
Android Using Menus Notes are based on: The Busy Coder's Guide to Android Development by Mark L. Murphy Copyright © CommonsWare, LLC. ISBN:
Working with Multiple Activities. Slide 2 Introduction Working with multiple activities Creating multiple views Introduction to intents Passing data to.
Page Designer Storyboard J. A. Fitzpatrick December 2004.
Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences.
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android Application Lifecycle and Menus
Designing user interfaces using: Simple views 1. Views Basic views – TextView – EditText – Button – ImageButton – CheckBox – ToggleButton – RadioButton.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Android Drawing Units and The.
CS378 - Mobile Computing More UI - Part 2. Special Menus Two special application menus – options menu – context menu Options menu replaced by action bar.
Creating Menus Menu Bar – behaves like standard Windows menus Can be used in place of or in addition to buttons to execute a procedure Menu items are controls.
1 Android Development Lean and mean introduction Based on a presentation by Mihail L. Sichitiu.
Perfecto Mobile Automation
COMP 365 Android Development.  Developing for Android  XML for user interface formatting and other scripting  Java for programming.
Flag Quiz Game App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Lecture 8 the Preference Menu. Settings... Sudoku settings s Music Play background music Hints Show hints during play We add some strings to the strings.xml.
More App Customizations. Overview  Application/ Activity Customizations: Themes  Menu Customizations  Custom Dialogs  Custom Toasts  Custom Buttons.
This screen may be skipped altogether if the user chooses a report from the server and clicks Ad Hoc or Edit or whatever. Also, the next screen would ordinarily.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
The Flag Quiz app tests your ability to correctly identify 10 flags from various countries and territories.
Cosc 5/4730 Support design library. Support Design library Adds (API 9+) back support to a number of 5.0 lollipop widgets and material design pieces –
ANDROID DIALOGS. Slide 2 Dialogs (Introduction) The Dialog class is the base class for all dialogs A dialog is a small window that prompts the user to.
Menus. Menus are a common user interface component in many types of applications. The options menu is the primary collection of menu items for an activity.
Lab7 – Appendix.
Introduction to android
CS240: Advanced Programming Concepts
Activities, Fragments, and Events
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Mobile Application Development BSCS-7 Lecture # 13
Mobile Computing With Android ACST 4550 Alerts
Chapter 3: Coding the GUI Programmatically, Layout Managers
Predefined Dialog Boxes
Android Developer Fundamentals V2
Android Developer Fundamentals V2 Lesson 4
Objects First with Java
ESeries Widgets Justin Kishbaugh.
Implication of Orientation Changes
Mobile Programmming Dr. Mohsin Ali Memon.
Presentation transcript:

Styles, Dialog Boxes, and Menus

Styles

Allow creation of a common format – placed in res/values/styles.xml – file name is incidental Can be applied to multiple widgets, layouts, etc. – When applied to layout, contained widgets are not affected – If applied to different kinds of widgets, attributes that do not apply are simply ignored One style can inherit another – attributes can be overridden Can be used to set a theme at the application or activity level

Example In styles.xml: wrap_content #FF0000 In Activity’s corresponding.xml file: <TextView android:text="I am using a style template" " />

Example of Inheritance Added to styles.xml: #0000FF 20dp In Activity’s corresponding.xml file: <TextView android:text="I am using an inheriting style template" " />

Example of a theme In styles.xml: #0F0F0F In Manifest file (as an attribute of either the Activity or Application): android:theme="myCustomTheme"

Dialog Boxes

Dialog boxes Presents information to the screen – error message – confirmation of a process – other Overlays another Activity – usually translucent and modal

Dialog Boxes Can be created in XML or programmatically – if created in XML: use an Activity with the Dialog theme onPause and onResume of parent fired off advantage: can be as robust as needed disadvantage: relatively unwieldy to pass information back from Dialog – if created programmatically use AlertDialog class no focus events fired off advantage: low overhead and access to all class entities disadvantage: interface is limited

Creating a DialogBox via xml

Creating DialogBox via xml Create an Activity with DialogBox theme – In Manifest file: <activity android:name=".Dialog" android:label="Data Entry Error"

Creating DialogBox via xml Component is technically an Activity, and all requirements remain the same – Manifest file entry,.xml file, and.java file – launched via the startActivity() method in parent Activity intent must be created – Dialog Activity presented modally ‘in front’ of parent activity – Using an Activity with the Dialog theme allows for added functionality

Creating DialogBox via xml openXMLDialog below is an example of a method within the main Activity public void openXMLDialog () { Intent i = new Intent(this, XMLDialog.class); startActivity(i); }

Creating a DialogBox programmatically

Creating DialogBox programmatically Component is created within the current Activity – No Manifest file entry,.xml file, or.java file – launched via the show() method in AlertDialog class (from a method in the parent Activity) – Dialog Activity presented modally ‘in front’ of parent activity setCancelable method determines if user can cancel the Dialog via the back button on the device – Minimal effort, minimal functionality

Creating DialogBox programmatically Can use one, two, or three buttons – all buttons automatically dismiss the dialog after corresponding code is executed – buttons appear right to left in following order positive neutral negative No difference between the three If none are chosen, program will be stuck with the modal dialog box – no build errors

Creating DialogBox programmatically public void inputError() { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setCancelable(false); builder.setTitle("Data entry error"); builder.setMessage("Please enter a positive number in the number field"); builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { //Functionality goes here } }); ((EditText)findViewById(R.id.etNumField)).requestFocus(); AlertDialog alert = builder.create(); alert.show(); }

Menus

Can be created in xml or programmatically – If created in.xml, placed in res\menu\ folder Menu displayed by means of menu key on phone Must override the following methods in Activity – onCreateOptionsMenu creates the menu ‘inflates’ xml code or programmatically creates menu – onOptionsItemSelected provide the functionality to the menu

Creating a menu via xml

Creating a menu using xml This xml file would reside in the res\menu folder <item android:title="First" android:orderInCategory="1“ android:showAsAction="never" /> <item android:title="Second" android:orderInCategory="2“ android:showAsAction="never" />

Creating a menu using xml onCreateOptionsMenu() overridden in the corresponding Activity – called only once – first time menu is displayed onPrepareOptionsMenu is called every time menu is displayed – here ‘choices’ reflects the name of the menu xml file – a return value of true allows the menu to be public boolean onCreateOptionsMenu(Menu menu) { getMenuInflater().inflate(R.menu.choices, menu); return true; }

onCreateOptionsMenu return value – true menu can displayed – false menu cannot display Scenario – When Activity is displayed, may want the Menu available under certain conditions and not otherwise if (condition met) return true; else return false;

Creating a menu using xml onOptionsItemSelected() overridden in the corresponding Activity – Here ‘miX’ reflects the name of the menu item in the xml public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case (R.id.mi1): //Functionality here case (R.id.mi2): //Functionality here } return true; }

onOptionsMenuItem return value – true consume menu processing here will not call super class’ onOptionsMenuItem – false will call super class’ onOptionsMenuItem Scenario – May have one activity that implements the menu, and others that subclass it if subclass handles subset of cases, handle those and return false in any case that is not handled

Creating a menu programmatically

onCreateOptionsMenu() overridden in the corresponding Activity – Each menu item added via the ‘add’ method in the Menu class parameters are: – group id, item id, order, title – group id useful if actions need to be taken on a group of items » removeGroup(), setGroupVisible(), etc. – item id is the unique id (value returned by getItemId()) – items will appear in numerical order by order parameter public boolean onCreateOptionsMenu(Menu menu) { menu.add(Menu.NONE, 1, 1, "First"); menu.add(Menu.NONE, 2, 2, "Second"); return true; }

Creating a menu programmatically onOptionsItemSelected() overridden in the corresponding Activity – getItemId() matches those set in public boolean onOptionsItemSelected(MenuItem item) { switch(item.getItemId()) { case 1: //Functionality here case 2: //Functionality here } return true; }