Copyright© Jeffrey Jongko, Ateneo de Manila University Dialogs, Custom Dialogs, Toasts.

Slides:



Advertisements
Similar presentations
Slides 4/22 COP Topics Final Exam Review Final Exam The final exam is Friday, April 29 th at 10:00 AM in the usual room No notes, books, calculators,
Advertisements

 User Interface - Raeha Sandalwala.  Introduction to UI  Layouts  UI Controls  Menus and ‘Toasts’  Notifications  Other interesting UIs ◦ ListView.
User Interface Classes.  Design Principles  Views & Layouts  Event Handling  Menus  Dialogs.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Cosc 4730 Android Dialogs and notifications. Notifications There are a couple of ways to notify users without interrupting what they are doing The first.
By: Jeremy Smith.  Introduction  Droid Draw  Add XML file  Layouts  LinearLayout  RelativeLayout  Objects  Notifications  Toast  Status Bar.
Microsoft ® Office PowerPoint ® 2003 Training Playing movies [Your company name] presents:
@2011 Mihail L. Sichitiu1 Android Introduction Hello Views Part 1.
McGraw-Hill/Irwin The Interactive Computing Series © 2002 The McGraw-Hill Companies, Inc. All rights reserved. Microsoft Excel 2002 Exploring Formulas.
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.
Computer Science 1000 Spreadsheets II Permission to redistribute these slides is strictly prohibited without permission.
REQUIREMENTS CAPTURE 1 ASU Course Registration System User Interface Specifification UI Elements Register for courses Use Case.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Introduction to Android (Part.
Favorite Twitter® Searches App Android How to Program © by Pearson Education, Inc. All Rights Reserved.
Hello world Follow steps under the sections “Create an AVD” and “Create a New Android Project” at
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Integrating with Android Services. Introduction  Android has numerous built-in functionality that can be called from within your applications  SMS/MMS.
1 Announcements Homework #2 due Feb 7 at 1:30pm Submit the entire Eclipse project in Blackboard Please fill out the when2meets when your Project Manager.
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
Mobile Computing Lecture#11 Adapters and Dialogs.
Programming Handheld and Mobile devices 1 Programming of Handheld and Mobile Devices Lecture 12 lcdui Rob Pooley
Photo Story 3 Importing Pictures. When you create a new Photo Story, the first thing that you will do is import pictures. You can import pictures from.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Cosc 5/4730 Dialogs and below 3.0 and above (fragment)
5-1 More UI CSNB544 Mobile Application Development Thanks to Utexas Austin.
Visual Basic Programming Chapter Six Notes Repetition and the Do Statement ADDING ICONS TO YOUR FORM –It is possible to add an ______________ to your title.
User notification Android Club Agenda Toast Custom Toast Notification Dialog.
Copyright© Jeffrey Jongko, Ateneo de Manila University Basic Views and Layouts.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Copyright© Jeffrey Jongko, Ateneo de Manila University Editing ListAdapter Data part 2.
Copyright© Jeffrey Jongko, Ateneo de Manila University Custom ListAdapters.
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:
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
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.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
Data Structures and Java CS /14/2015 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L6:
Mobile Programming Lecture 7 Dialogs, Menus, and SharedPreferences.
Office of Housing Choice Voucher Program Voucher Management System – VMS Version Released October 2011.
CHAPTER 6 LESSON B Creating Custom Forms. Lesson B Objectives  Suppress default system messages  Create alerts and messages to provide system feedback.
Introduction to Drafting and Design In order to begin our drawing we have to set the drawing limits or the paper size.
© 2016 Cengage Learning®. May not be scanned, copied or duplicated, or posted to a publicly accessible website, in whole or in part. Android Boot Camp.
Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved Android Drawing Units and The.
More about Java Classes Writing your own Java Classes More about constructors and creating objects.
Frank Xu Gannon University. A dialog is always created and displayed as a part of an Activity. You should normally create dialogs from within.
CS378 - Mobile Computing More UI. UI Review Containers – more formally ViewGroups – store widgets and other containers – examples: LinearLayout, RelativeLayout,
Android Alert Dialog. Alert Dialog Place Button to open the dialog. public class MainActivity extends ActionBarActivity { private static Button button_sbm;
More App Customizations. Overview  Application/ Activity Customizations: Themes  Menu Customizations  Custom Dialogs  Custom Toasts  Custom Buttons.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
FILES AND EXCEPTIONS Topics Introduction to File Input and Output Using Loops to Process Files Processing Records Exceptions.
Java for android Development Nasrullah Khan. Using instanceof in Android Development the classes such as Button, TextView, and CheckBox, which represent.
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.
Software Overview How to… Review Video and Data  Review the Journal Review the Journal  Simple Search Simple Search  Advanced Search Advanced Search.
Android Programming - Features
CS499 – Mobile Application Development
Topics Graphical User Interfaces Using the tkinter Module
Further android gui programming
Mobile Application Development BSCS-7 Lecture # 8
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Android Introduction Hello Views Part 1.
Working with Dialogs and Controls
Mobile Computing With Android ACST 4550 Alerts
Predefined Dialog Boxes
Mobile Computing With Android ACST 4550 Toast
Android Developer Fundamentals V2 Lesson 4
Implication of Orientation Changes
Presentation transcript:

Copyright© Jeffrey Jongko, Ateneo de Manila University Dialogs, Custom Dialogs, Toasts

Overview  Dialog concepts  Built-in Dialogs  Custom Dialogs  Toasts

Copyright© Jeffrey Jongko, Ateneo de Manila University Dialogs Concepts

Dialogs  A dialog is a modal input type  You must finish with the dialog before proceeding with anything else  Android provides Activity instances with a way to automatically manage dialogs and their life-cycle

showDialog()  Dialogs are triggered using the showDialog(int id) method  The Dialog ID is an arbitrary integer used to identify a specific dialog usually stored as a constant  E.g. DATE_DIALOG_ID

Dialog ID  Each dialog that shows from an Activity must have a unique dialog id  This id will be used in onCreateDialog(int id) and onPrepareDialog(int id) methods  These will be used in switch() statements to handle specific dialogs

onCreateDialog()  When a dialog is created for the first time onCreateDialog(int id) is called  This method returns the specific Dialog instance that will displayed  Once a dialog has been created, the instance is kept by the Activity  Any changes done to the dialog’s state is preserved

Example  For every dialog type and entry should appear here  Note the use of constants protected Dialog onCreateDialog(int id) { Dialog dialog; switch(id) { case DIALOG_PAUSED_ID: // do the work to define the pause Dialog break; case DIALOG_GAMEOVER_ID: // do the work to define the game over Dialog break; default: dialog = null; } return dialog; }

onPrepareDialog()  Once a dialog is created the instance is kept by the Activity until it is dismissed (see later)  However, there are times you will want to reset the state of the existing dialog  onPrepareDialog(int id, Dialog d) is called every time a dialog is activated  You can then typecast and adjust the Dialog supplied accordingly each time it is opened

Example  If you need to reset the state of an existing dialog, place an entry here for the dialogs that need it protected void onPrepareDialog(int id, Dialog d) { switch(id) { case DIALOG_PAUSED_ID: // adjust pause Dialog break; case DIALOG_GAMEOVER_ID: // adjust the game over Dialog break; } }

Copyright© Jeffrey Jongko, Ateneo de Manila University Built-in Dialogs

 Built-in Dialogs  DatePickerDialog  TimePickerDialog  AlertDialog  ProgressDialog

DatePickerDialog  Standard widget for selecting a date, use the DatePicker widget (usable from the GraphicalEditor), which allows the user to select the month, day, and year, in a familiar interface.DatePicker  A Dialog-based version is also available, DatePickerDialog

DatePickerDialog  DatePickerDialog follows the same basic principles of dialogs  Define an ID representing this dialog  Use showDialog(id)  Instantiate the dialog in onCreateDialog(id)  In addition define its close behaviour  Prep the dialog in onPrepareDialog(id, dialog)

OnDateSetListener  You need to define the close behaviour of a DatePickerDialog  This is the DatePickerDialog.OnDateSetListener  Defines one method  public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth)

Example private DatePickerDialog.OnDateSetListener mDateSetListener = new DatePickerDialog.OnDateSetListener() { public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) { mYear = year; mMonth = monthOfYear; mDay = dayOfMonth; updateDisplay(); } }; protected Dialog onCreateDialog(int id) { switch (id) { case DATE_DIALOG_ID: return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay); } return null; }

Calendar objects  Java’s basic date/time handling class is the Calendar object  Allows for the setting and retrieving information about date/time using simple constants Calendar c = Calendar.getInstance(); mYear = c.get(Calendar.YEAR); mMonth = c.get(Calendar.MONTH); mDay = c.get(Calendar.DAY_OF_MONTH);

Calendar  A detailed description of Calendar’s methods and constants can be found here  file:///C:/android-sdk- windows/docs/reference/java/util/Calendar.html file:///C:/android-sdk- windows/docs/reference/java/util/Calendar.html

TimePickerDialog  TimePicker is similar to the DatePicker except it is used to handle hour/minute, time of day  TimePickerDialog is the dialog version of the TimePicker  Just like with the DatePickerDialog you can use a Calendar object to hold data received from this dialog

OnTimeSetListener private TimePickerDialog.OnTimeSetListener mTimeSetListener = new TimePickerDialog.OnTimeSetListener() { public void onTimeSet(TimePicker view, int hourOfDay, int minute) { mHour = hourOfDay; mMinute = minute; updateDisplay(); } }; protected Dialog onCreateDialog(int id) { switch (id) { case TIME_DIALOG_ID: return new TimePickerDialog(this, mTimeSetListener, mHour, mMinute, false); } return null; }

Copyright© Jeffrey Jongko, Ateneo de Manila University AlertDialog

AlertDialog  An AlertDialog is an extension of the Dialog class. It is capable of constructing most dialog user interfaces and is the suggested dialog type. You should use it for dialogs that use any of the following features:AlertDialogDialog  A title  A text message  One, two, or three buttons  A list of selectable items (with optional checkboxes or radio buttons)

AlertDialog.Builder  AlertDialogs are created using the AlertDialog.Builder class  Using the builder you may supply the required information  Title, button names, etc.  The final Dialog instance is built using the create() method

Example 1 AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("Are you sure you want to exit?").setCancelable(false).setPositiveButton("Yes", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // positive action exit() } }).setNegativeButton("No", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { // negative action dialog.cancel(); } }); AlertDialog alert = builder.create();

Example 2 final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Pick a color"); builder.setItems(items, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show(); } }); AlertDialog alert = builder.create();

Example 3 final CharSequence[] items = {"Red", "Green", "Blue"}; AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setTitle("Pick a color"); builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { // do something } }); AlertDialog alert = builder.create();  To use checkboxes, use setMultiChoiceItems() instead

Notes:  Note the getApplicationContext() calls in defining DialogInterface.OnClickListener  Retrieves the Activity instance  Can’t use this since it will refer to the DialogInterface.OnClickListener instance  Lists of strings do not need to be hard-coded, they can also be placed in the values

ProgressDialog  A ProgressDialog is an extension of the AlertDialog class that can display a progress animation in the form of a spinning wheel, for a task with progress that's undefined, or a progress bar, for a task that has a defined progressionProgressDialogAlertDialog  Used in conjunction with Threads  This will be discussed in later topics

Copyright© Jeffrey Jongko, Ateneo de Manila University Custom Dialogs

CustomDialogs  Generally AlertDialog is all you will need for most Dialog requirements  If you can get away with AlertDialog use it  If AlertDialog does not provide what you need, it is possible to define your own Dialog layout  The process is similar to defining an Activity layout

Making your own Dialog  If you want a customized design for a dialog, you can create your own layout for the dialog window with layout and widget elements.  After you've defined your layout, pass the root View object or layout resource ID to setContentView(View).setContentView(View)  Use a LayoutInflator similar to a MenuInflator to create a ViewGroup from a layout XML  Use the ViewGroup’s findViewById(id) to edit individual widgets

dismiss() / dismissDialog()  When you're ready to close your dialog, you can dismiss it by calling dismiss() on the Dialog object.dismiss()  Alternatively, you can also call dismissDialog(int) from the Activity, which effectively calls dismiss() on the Dialog for you. dismissDialog(int)dismiss()

OnDismissListener  Sometimes you want to do something as a result of dismissing a dialog  First define the DialogInterface.OnDismissListener interface.DialogInterface.OnDismissListener  This interface has just one method,onDismiss(DialogInterface), which will be called when the dialog is dismissed.onDismiss(DialogInterface)  pass your OnDismissListener implementation to setOnDismissListener() of the dialog when you create itsetOnDismissListener()

Cancelling a Dialog  However, note that dialogs can also be "cancelled."  This is a special case that indicates the dialog was explicitly cancelled by the user. This will occur if  the user presses the "back" button to close the dialog  if the dialog explicitly calls cancel() (perhaps from a "Cancel" button in the dialog).cancel()

OnCancelListener  When a dialog is cancelled, the OnDismissListener will still be notified, but if you'd like to be informed that the dialog was explicitly cancelled (and not dismissed normally), then you should register an DialogInterface.OnCancelListener with setOnCancelListener()DialogInterface.OnCancelListener setOnCancelListener()

removeDialog()  If you are using onCreateDialog(int) to manage the state of your dialogs, then every time your dialog is dismissed, the state of the Dialog object is retained by the Activity.onCreateDialog(int)  If you decide that you will no longer need this object or it's important that the state is cleared, then you should call removeDialog(int)removeDialog(int)

More Info  More details on custom dialogs can be found here  file:///C:/android-sdk- windows/docs/guide/topics/ui/dialogs.html

Copyright© Jeffrey Jongko, Ateneo de Manila University Toasts

Toasts  A Toast what is used to represent a “pop-up” message  Toasts cannot be interacted with  They just display the message embedded in them for a specified amount of time then disappear  Cancel and other button do not do anything

Creating a Toast  To instantiate a Toast object use one of the makeText() methods.ToastmakeText()  This method takes three parameters: the application Context (usually the Activity), the text message, and the duration for the toast.Context  It returns a properly initialized Toast object.

Toasts  Toasts are usually used to display simple messages  E.g. Validation errors  Toasts have two possible fixed durations  Toast.LENGTH_LONG  Toast.LENGTH_SHORT  Messages should be short enough to read in this time frame

Example  Once a Toast instance is created you may make it appear using show()  The context parameter is the enclosing Activity Toast toast = Toast.makeText(this, “Hello”, Toast.LENGTH_SHORT); toast.show();

Positioning Toasts  A standard toast notification appears near the bottom of the screen, centered horizontally.  You can change this position with the setGravity(int, int, int) method. setGravity(int, int, int)  This accepts three parameters: a Gravity constant (anchor), an x-position offset, and a y-position offset from the upper left.Gravity toast.setGravity(Gravity.TOP|Gravity.LEFT, 0, 0);

Custom Toasts  Custom toasts can be created  The process is similar to creating a custom dialog  file:///C:/android-sdk- windows/docs/guide/topics/ui/notifi ers/toasts.html file:///C:/android-sdk- windows/docs/guide/topics/ui/notifi ers/toasts.html