User Interface Development

Slides:



Advertisements
Similar presentations
Application Fundamentals. See: developer.android.com/guide/developing/building/index.html.
Advertisements

Who Am I And Why Am I Here I’m professor Stephen Fickas in CIS – you can call me Steve. I have a research group that works with mobile devices (since 1995!)
User Interface Android Applications. Activities An activity presents a visual user interface. Each activity is given a default window to draw in. The.
Android Form Elements. Views Provide common UI functionality Form elements: text area, button, radio button, checkbox, dropdown list, etc. Date and time.
CS378 - Mobile Computing User Interface Basics MIKE!! LOOK HERE FOR intercepting the ListView items:
Android: Layouts David Meredith
Custom Views, Drawing, Styles, Themes, ViewProperties, Animations, oh my!
Creating Android user interfaces using layouts 1Android user interfaces using layouts.
Android Fragments A very brief introduction Android Fragments1.
Android development the first app. Andoid vs iOS which is better? Short answer: neither Proponents on both sides For an iOS side, see this article on.
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.
Chapter 5 Creating User Interfaces GOALS and OBJECTIVES Begin our application by creating our user interface. More than one way to create a user interface.
Android Layouts. Layouts Define the user interface for an activity Layouts are defined in.xml files – within /res/layout folder – different layout can.
ANDROID – INTERFACE AND LAYOUT L. Grewe. Interfaces: Two Alternatives Code or XML  You have two ways you can create the interface(s) of your Application.
Understanding Hello Android 1 CS300. Activity  Similar to a form  Base class for the visual, interactive components of your application  Android API.
Mobile Programming Lecture 6
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.
1/29/ Android Programming: FrameLayout By Dr. Ramji M. Makwana Professor and Head, Computer Engineering Department A.D. Patel.
INTRODUCTION TO ANDROID. Slide 2 Application Components An Android application is made of up one or more of the following components Activities We will.
Programming with Android: Layouts, Widgets and Events Luca Bedogni Marco Di Felice Dipartimento di Scienze dell’Informazione Università di Bologna.
User Interfaces: Part 1 (View Groups and Layouts).
Application Development for mobile Devices
Android – Fragments L. Grewe.
Cosc 4730 Android Fragments. Fragments You can think of a fragment as a modular section of an activity, which has its own lifecycle, receives its own.
ANDROID – DRAWING IMAGES – SIMPLE EXAMPLE IN INTERFACE AND EVENT HANDLING L. Grewe.
Announcements Homework #2 will be posted after class due Thursday Feb 7, 1:30pm you may work with one other person No office hours tonight (sorry!) I will.
HW#9 Clues CSCI 571 Fall, HW#9 Prototype
Copyright© Jeffrey Jongko, Ateneo de Manila University Deconstructing HelloWorld.
Android Application Lifecycle and Menus
CS378 - Mobile Computing User Interface Basics. User Interface Elements View – Control – ViewGroup Layout Widget (Compound Control) Many pre built Views.
Chapter 2 Building User Interfaces and Basic Applications.
Http :// developer. android. com / guide / topics / fundamentals. html.
ANDROID LAYOUTS AND WIDGETS. Slide 2 Introduction Parts of the Android screen Sizing widgets and fonts Layouts and their characteristics Buttons, checkboxes.
School of Engineering and Information and Communication Technology KIT305/KIT607 Mobile Application Development Android OS –Permissions (cont.), Fragments,
Fragments and Menus Chapter 4 1. Objectives Learn three different types of menus: options, context, and popup Learn to configure the ActionBar and Toolbar.
Lab7 – Appendix.
Lecture 3 Zablon Ochomo Android Layouts Lecture 3 Zablon Ochomo
Open Handset Alliance.
Android Application Development 1 6 May 2018
CS240: Advanced Programming Concepts
GUI Programming Fundamentals
Mobile Software Development for Android - I397
CS499 – Mobile Application Development
Mobile Application Development Chapter 3 [Using Eclipse Android Studio for Android Development] IT448-Fall 2017 IT448- Fall2017.
CS499 – Mobile Application Development
Android Widgets 1 7 August 2018
Mobile Application Development Chapter 4 [Android Navigation and Interface Design] IT448-Fall 2017 IT448- Fall2017.
Android Introduction Hello Views Part 1.
ITEC535 – Mobile Programming
Android – Fragments L. Grewe.
ANDROID UI – FRAGMENTS UNIT II.
HNDIT2417 Mobile Application Development
CIS 470 Mobile App Development
Android Programming Lecture 6
Android Layout Basics Topics
CIS 470 Mobile App Development
Chapter 9: Fragments.
CIS 470 Mobile App Development
CIS 470 Mobile App Development
Adding Components to Activity
Activities and Fragments
CS 240 – Advanced Programming Concepts
CS 240 – Advanced Programming Concepts
Android Application Model I
Android Sensor Programming
Android Sensor Programming
Android Sensor Programming
External Services CSE 5236: Mobile Application Development
User Interface Development
Presentation transcript:

User Interface Development CSE 5236: Mobile Application Development Instructor: Adam C. Champion, Ph.D. Course Coordinator: Dr. Rajiv Ramnath Reading: Big Nerd Ranch Guide, Chapter 7 (Fragments)

Outline UI Support in Android Fragments

UI Support in the Android SDK “Inverted” paradigm Each subclass constrains rather than extends functionality Hundreds of methods are exposed – Augh!! Base classes: ViewGroup base class for composite elements View base class for terminal UI components

View Hierarchy # = SDK Version number

ViewGroup Hierarchy Direct Subclasses: 19 indirect subclasses. See: AbsoluteLayout AdapterView<T extends Adapter> FragmentBreadCrumbs FrameLayout GridLayout LinearLayout PagerTitleStrip RelativeLayout SlidingDrawer ViewPager 19 indirect subclasses. See: http://developer.android.com/reference/android/view/ViewGroup.html

Sample Layout, Login Activity <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android” android:background="@color/background" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="20dip"> <LinearLayout android:orientation="vertical ... <TextView android:text="@string/login_title” ... /> <TextView ... /> <EditText android:id="@+id/username_text” ... /> <EditText ... /> <Button ... /> </LinearLayout> </ScrollView>

Layout Configuration ID: android:id="@+id/username_text” Parameters: Used if handle to the widget is needed Parameters: layout_width, layout_height layout_marginTop, ...Right, layout_margin orientation Can be combined: layout_gravity=“bottom|right” Constants: match_parent, wrap_content Width and height specifications: dp, in, mm, px, sp (scaled pixels based on font size) A wide range of LayoutParams Resources – e.g. backgrounds android:background=“@drawable/backdrop” Blank canvases using a (generic) View element in the layout See Android SDK book Chapter 5 for details

Adding Resources Resources can also be added by right-clicking on res directory, selecting New→Android Resource File

Other Layout Parameters and Techniques Inherit parameters from enclosing elements layout_span - to span multiple columns Empty views to add blank canvases to be filled later (see later) Shrink or stretch columns as needed: shrinkColumns, stretchColumns RelativeLayout allows window manager to manage size

Linking a UI to a Fragment: Java // LoginActivity.java public class LoginActivity extends SingleFragmentActivity { @Override protected Fragment createFragment() { return new LoginFragment(); } } // LoginFragment.java @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_login, container, false); // Real code handles rotation mUsernameEditText = (EditText) v.findViewById(R.id.username_text); mPasswordEditText = (EditText) v.findViewById(R.id.password_text); Button loginButton = (Button) v.findViewById(R.id.login_button); loginButton.setOnClickListener(this); // Real code checks for nullity Button cancelButton = (Button) v.findViewById(R.id.cancel_button); cancelButton.setOnClickListener(this); Button newUserButton = (Button) v.findViewById(R.id.new_user_button); newUserButton.setOnClickListener(this); return v; } You can also set up listener objects in Activities using onCreate()

Linking a UI to a Fragment: Kotlin // LoginActivity.kt class LoginActivity : SingleFragmentActivity() { override fun createFragment(): Fragment { return LoginFragment() } } // LoginFragment.kt override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val v: View = inflater.inflate(R.layout.fragment_login, container, false) // Real code handles rotation mUsernameEditText = v.findViewById<EditText>(R.id.username_text) mPasswordEditText = v.findViewById<EditText>(R.id.password_text) val loginButton = v.findViewById<Button>(R.id.login_button) loginButton?.setOnClickListener(this) val cancelButton = v.findViewById<Button>(R.id.cancel_button) cancelButton?.setOnClickListener(this) val newUserButton = v.findViewById<Button>(R.id.new_user_button) newUserButton?.setOnClickListener(this) return v }

Creating a Custom Widget: Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:background="#676767" android:gravity="center_horizontal" android:padding="20dip"> <com.wiley.fordummies.androidsdk.tictactoe.Board android:id="@+id/board" android:layout_height="280dip"/> ... </LinearLayout>

Creating a Custom Widget: Java // Board.java public class Board extends View { // . . . public Board(Context context, AttributeSet attributes) { super(context, attributes); // . . . setFocusable(true); setFocusableInTouchMode(true); // . . . } // . . . protected void onSizeChanged(int w, int h, int oldw, int oldh) { // . . . super.onSizeChanged(w, h, oldw, oldh); } @Override protected void onDraw(Canvas canvas) { super.onDraw(canvas); // . . . } } Instantiating the view: // LoginFragment.java, onCreateView() and setupBoard() // onCreateView v = inflater.inflate(R.layout.fragment_game_session, . . .); // setupBoard() mBoard = (Board) v.findViewById(R.id.board);

Creating a Custom Widget: Kotlin // Board.kt class Board(context: Context, attributes: AttributeSet) : View(context, attributes) { init { isFocusable = true isFocusableInTouchMode = true // . . . } override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) { // . . . super.onSizeChanged(w, h, oldw, oldh) } // . . . override fun onDraw(canvas: Canvas) { super.onDraw(canvas) // . . . Instantiating the view: // LoginFragment.kt, onCreateView() and setupBoard() // onCreateView() v = inflater.inflate(R.layout.fragment_game_session, container, false) // setupBoard() mBoard = (Board) v.findViewById(R.id.board)

Creating a Layout via Code // DohActivity.java @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); LinearLayout layout = new LinearLayout(this); Button dohButton = new Button(this); dohButton.setText(“In case of meltdown, Push Me!”); layout.addView(dohButton); setContentView(layout); }

Styles and Themes (1) Use: Definition: Inheritance: <EditText style=”@style/DarkBold” android:text=”Hello” /> Definition: <?xml version=”1.0” encoding=”utf-8”?> <resources> <style name=”DarkBold”> <item name=”android:layout_width”> match_parent </item> <item name=”android:layout_height”> wrap_content ... more parameters ... </style> </resources> Inheritance: <style name=“DarkPhone” parent=”@style/DarkBold”> <item name=”android:phoneNumber”>true</item> </style>

Styles and Themes (2) Stored in res/values/ directory with .xml extension (name not relevant) Can set application-wide and activity-specific styles (aka themes): Set themes in AndroidManifest.xml on <application> tag or <Activity> tag <application android:theme="@style/CustomTheme"> <activity android:theme="@android:style/Theme.Translucent"> Can even create version-specific layout files Ref: http://developer.android.com/guide/topics/ui/themes.html

Outline UI Support in Android Fragments

Fragments and Their Rationale A composite UI component that handles its own UI Multiple Fragments in an Activity A separate class hierarchy: Fragment, DialogFragment, ListFragment, PreferenceFragment, WebViewFragment Goals: Further separate UI from Activity. Separate UI design from Activity design UI should have its own lifecycle and flow Should be able to add or remove UI components while activity is running Primary driver: Tablets!

Example – Login and Account

Portrait Layout: Login <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" ...> <LinearLayout...> <TextView android:text="@string/login_title".../> android:text="@string/enter_username”.../> <EditText android:id="@+id/username_text”.../> android:text="Enter Password".../> android:id="@+id/password_text".../> <Button android:id="@+id/login_button".../> android:id="@+id/cancel_button”.../> android:id="@+id/new_user_button”.../> </LinearLayout> </ScrollView>

Portrait Layout: Account <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...> <FrameLayout .../> ⟸ Placeholder for fragment <Button android:id="@+id/exit_button”.../> </LinearLayout> What happened to Landscape layout of AccountFragment?

Landscape Layout: Login <?xml version="1.0" encoding="utf-8"?> <LinearLayout... android:orientation="horizontal” ...> ⟸ NOTE HORIZONTAL LAYOUT <ScrollView ... > <LinearLayout .. > <TextView ... /> <EditText.../> <TextView.../> <Button.../> </LinearLayout> </ScrollView> <fragment class="com.wiley.fordummies.androidsdk.tictactoe.AccountFragment" android:id="@+id/titles" android:layout_weight="1" android:layout_width="0px" android:layout_height="match_parent" android:background="#00550033"/>

AccountFragment: Portrait Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout ...> <LinearLayout...> <TextView android:text="New Account" .../> <TextView android:text="Username”.../> <EditText android:id="@+id/username”.../> <TextView android:text="Password”.../> <EditText android:id="@+id/password”.../> <TextView android:text="Confirm Password" .../> <EditText android:id="@+id/password_confirm”.../> <Button android:id="@+id/cancel_button” "/> android:id="@+id/done_button”.../> </LinearLayout>

AccountFragment: Landscape Layout <?xml version="1.0" encoding="utf-8"?> <LinearLayout...> <TextView android:text="New Account”.../> <TextView android:text="Username”.../> <EditText android:id="@+id/username”...”/> <TextView android:text="Password" .../> <EditText android:id="@+id/password”.../> <TextView android:text="Confirm Password" .../> <EditText android:id="@+id/password_confirm”.../> <LinearLayout ... > <Button android:id="@+id/cancel_button”.../> <Button android:id="@+id/done_button”.../> </LinearLayout>

LoginFragment: Java @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View v; int rotation = getActivity().getWindowManager().getDefaultDisplay().getRotation(); if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { v = inflater.inflate(R.layout.fragment_login_land, container, false); } else { v = inflater.inflate(R.layout.fragment_login, container, false); } mUsernameEditText = (EditText) v.findViewById(R.id.username_text); mPasswordEditText = (EditText) v.findViewById(R.id.password_text); Button loginButton = (Button) v.findViewById(R.id.login_button); if (loginButton != null) { loginButton.setOnClickListener(this); } Button cancelButton = (Button) v.findViewById(R.id.cancel_button); if (cancelButton != null) { cancelButton.setOnClickListener(this); } Button newUserButton = (Button) v.findViewById(R.id.new_user_button); if (newUserButton != null) { newUserButton.setOnClickListener(this); } return v; }

LoginFragment: Kotlin override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val v: View val rotation = activity.windowManager.defaultDisplay.rotation if (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270) { v = inflater.inflate(R.layout.fragment_login_land, container, false) } else { v = inflater.inflate(R.layout.fragment_login, container, false) } mUsernameEditText = v.findViewById<EditText>(R.id.username_text) mPasswordEditText = v.findViewById<EditText>(R.id.password_text) val loginButton = v.findViewById<Button>(R.id.login_button) loginButton?.setOnClickListener(this) val cancelButton = v.findViewById<Button>(R.id.cancel_button) cancelButton?.setOnClickListener(this) val newUserButton = v.findViewById<Button>(R.id.new_user_button) newUserButton?.setOnClickListener(this) return v }

AccountFragment: onCreateView(): Java public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Inflate the layout for this fragment View v = inflater.inflate(R.layout.accountfragment, container, false); Activity activity = getActivity(); if (activity != null){ int rotation = activity.getWindowManager().getDefaultDisplay().getRotation(); mEtUsername = v.findViewById(R.id.username); mEtPassword = v.findViewById(R.id.password); mEtConfirm = v.findViewById(R.id.password_confirm); Button btnAdd = v.findViewById(R.id.done_button); btnAdd.setOnClickListener(this); Button btnCancel = v.findViewById(R.id.cancel_button); btnCancel.setOnClickListener(this); Button btnExit = v.findViewById(R.id.exit_button); if (rotation == Surface.ROTATION_0 || rotation == Surface.ROTATION_180) { btnExit.setOnClickListener(this); } else { btnExit.setVisibility(View.GONE); } return v; }

AccountFragment: onCreateView(): Kotlin override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { val v = inflater.inflate(R.layout.fragment_account, container, false) mEtUsername = v.findViewById(R.id.username) mEtPassword = v.findViewById (R.id.password) mEtConfirm = v.findViewById (R.id.password_confirm) val btnAdd = v.findViewById (R.id.done_button) btnAdd.setOnClickListener(this) val btnCancel = v.findViewById(R.id.cancel_button) btnCancel.setOnClickListener(this) return v }

AccountFragment: onClick(): Java @Override public void onClick(View view) { switch (view.getId()) { case R.id.done_button: createAccount(); break; case R.id.cancel_button: mEtUsername.setText(""); mEtPassword.setText(""); mEtConfirm.setText(""); break; case R.id.exit_button: FragmentActivity activity = getActivity(); if (activity != null) { activity.getSupportFragmentManager().popBackStack(); } } }

AccountFragment: onClick(): Kotlin override fun onClick(view: View) { when (view.id) { R.id.done_button -> createAccount() R.id.cancel_button -> { mEtUsername.setText("") mEtPassword.setText("") mEtConfirm.setText("") } } }

Questions and comments? Thank You Questions and comments?