Android MobAppDev
Android Debug Bridge,
MobAppDev Best Practices,
UI Development: XML, Views, Containers,
Clicks
Vladimir ...
Outline
●
Android Debug Bridge (ADB) via Command Line
●
MobAppDev Best Practices
●
UI Development
– Views & Containers
– C...
ADB via Command Line
www.vkedco.blogspot.com
ADB is now in /platform-tools
www.vkedco.blogspot.com
ADB is now in /platform-tools
1) List devices connected to
the computer
2) Connect to the device and
list all processes ru...
MobAppDev Best Practices
www.vkedco.blogspot.com
General Remarks
●
In many pedagogical contexts, efficiency is necessarily
compromised for the sake of clarity; this class ...
Hardware Constraints
●
Compared to their desktop & laptop counterparts,
mobile devices have
– Low processing power
– Limit...
Efficiency
●
Mobile device manufacturers generally prefer small
sizes and longer battery lives to processor speed
improvem...
Efficiency
●
Android efficiency tips are in conflict with well
established design practices
●
Example: many OOP books advo...
Limited Storage
●
Most of the available storage on mobile devices goes to music
and movies
●
Android devices require that ...
Small Screens
●
Users are demanding more and more information-rich UI
experience
●
This demand is a challenge for small sc...
Responsiveness
●
Android forces apps to be responsive
●
If it detects an unresponsive application, it displays a Force
Clo...
Responsiveness
●
Android monitors two conditions to determine responsiveness
– App must respond to a user action within fi...
Security Quote
August 28, 2013 —  According to a joint study by the Department of Homeland Security
and the FBI, the Andro...
Security
●
Android basic premise: users take responsibility for the apps
they install
●
Some best AppDev practices
– Requi...
Low Speed, High Latency
●
Mobile connections are not as fast, reliable, or available (3G,
4G, and citywide WiFi are slowly...
Data Costs
●
Data transfer services, such as SMS and Geocoding,
are not free
●
Generic data transfer cost minimization gui...
Respect User's Environment
●
Never assume that your app is the most important feature
on the device: to most users, a smar...
Seamless User Experience (UE)
●
UE is a fuzzy concept
●
In many contexts, it stands for consistency in your
app's starting...
UI Development
www.vkedco.blogspot.com
Android Views
●
Android GUI widgets are called views (text views,
edit texts, buttons, radio buttons, etc)
●
Views are gro...
LinearLayout
●
LinearLayout is one of the most common
containers used in Android UIs (probably because
it provides for sim...
Orientation Property
●
This property specifies whether a View object
functions as a row or as a column
●
If the value of t...
Fill Model Property
●
A View's fill model specifies how much space the view can take
in its parent view
●
Three possibilit...
Weight Property
●
This property indicates the proportion of the free
space the widget should take
●
This property is impor...
Gravity Property
●
The gravity property specifies how the widget should
be aligned on the screen (inside its container)
●
...
Padding Property
●
The padding property comes in handy when widgets are
tightly clustered inside a container
●
android:pad...
Android UI Measurement Units
●
PIXEL – dot on screen
●
IN – inches
●
MM – millimeters
●
PT – point – 1/72 of 1 inch
●
DP –...
DP vs SP
●
DP has constant ratio to PX: DP = PX * RATIO
●
RATIO stays constant regardless of the device
●
SP has scalable ...
Declarative and Procedural UI Development
●
Declarative development consists of specifying GUI element
in some formal lang...
XML-Based UI Design
●
The most important step to mastering XML-Based GUI design is to
relate visual GUIs with XML code tha...
XML Inflation
<Button
android:id=”@+id/button_one”
style=”@style/my_button_style”
android:layout_width=”wrap_content”
andr...
International Date Display Application
www.vkedco.blogspot.com
Android 2.3.3 (Ginger Bread) source
Android 4.2 (Jelly Bean...
App Specs
●
Develop an application that consists of one activity that displays
three buttons: one for US locale, one for I...
Sample Screenshots
Front Screen US Click IT Click FR Click
Development Steps
●
UI XML Specification
– Vertical LinearLayout
– EditText
– Horizontal LinearLayout
– Buttons
●
UI Const...
UI XML Design
www.vkedco.blogspot.com
Activity UI Structure
www.vkedco.blogspot.com
UI: Vertical Linear Layout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent”
android:...
UI: EditText
<EditText
android:id="@+id/edTxtDate"
android:layout_width="match_parent"
android:layout_height="wrap_content...
UI: Horizontal LinearLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android...
UI: Button Style in /res/values/styles.xml
<resources
xmlns:android="http://schemas.android.com/apk/res/android">
<style n...
UI: Button Texts in /res/values/strings.xml
<resources>
<string name="app_name">International Date Display</string>
<strin...
UI: Buttons
<Button
android:id="@+id/btnUS"
style="@style/my_button_style"
android:layout_gravity="left|center_vertical"
a...
UI Construction & Logic
www.vkedco.blogspot.com
UI Construction
// Member Declaration
protected Button mBtnUS = null;
protected Button mBtnIT = null;
protected Button mBt...
Date Formatting: Java Imports
●
java.text.DateFormat
– Abstract class for date/time formatting subclasses
●
java.text.Simp...
Date Formatting: UI Logic
// Member Declaration
protected DateFormat mDateFormatUS = null;
protected DateFormat mDateForma...
Button Click Consumption
import android.view.View.OnClickListener;
public class InterDateDisplayAct extends Activity imple...
Upcoming SlideShare
Loading in …5
×

MobAppDev: Android Debug Bridge (ADB); MobAppDev Best Practices; UI Development: XML, Views, Containers, Clicks

1,048 views
877 views

Published on

Android Debug Bridge (ADB); MobAppDev Best Practices; UI Development: XML, Views, Containers, Clicks

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,048
On SlideShare
0
From Embeds
0
Number of Embeds
212
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

MobAppDev: Android Debug Bridge (ADB); MobAppDev Best Practices; UI Development: XML, Views, Containers, Clicks

  1. 1. Android MobAppDev Android Debug Bridge, MobAppDev Best Practices, UI Development: XML, Views, Containers, Clicks Vladimir Kulyukin www.vkedco.blogspot.com
  2. 2. Outline ● Android Debug Bridge (ADB) via Command Line ● MobAppDev Best Practices ● UI Development – Views & Containers – Common View Properties – Android UI Measurement Units – XML UI Design – International Date Display Application www.vkedco.blogspot.com
  3. 3. ADB via Command Line www.vkedco.blogspot.com
  4. 4. ADB is now in /platform-tools www.vkedco.blogspot.com
  5. 5. ADB is now in /platform-tools 1) List devices connected to the computer 2) Connect to the device and list all processes running on it 3) List contents of the current directory www.vkedco.blogspot.com
  6. 6. MobAppDev Best Practices www.vkedco.blogspot.com
  7. 7. General Remarks ● In many pedagogical contexts, efficiency is necessarily compromised for the sake of clarity; this class is no exception ● The first step toward mastery is understanding; some low level efficiency details must necessarily take the back seat for the sake of conceptual clarity ● There is a great software engineering principle that states that early optimization is the root of all evil: high level objectives and flexibility are often lost when optimization becomes the primary focus early on www.vkedco.blogspot.com
  8. 8. Hardware Constraints ● Compared to their desktop & laptop counterparts, mobile devices have – Low processing power – Limited RAM – Limited permanent storage – Small screens with low resolution – High data transfer costs – Slow data transfer rates – Unreliable data connections – Limited battery life www.vkedco.blogspot.com
  9. 9. Efficiency ● Mobile device manufacturers generally prefer small sizes and longer battery lives to processor speed improvements ● To mobile developers such preferences translate to the occasional invalidity of Moore's law (number of transistors doubles on an integrated circuit every 2 years) ● A safer bet for mobile developers is increased power efficiency without significant increases in processor power www.vkedco.blogspot.com
  10. 10. Efficiency ● Android efficiency tips are in conflict with well established design practices ● Example: many OOP books advocate abstraction via getter and setter methods; Android SE guidelines recommend avoiding setters and getters as much as possible ● Many conventional OOP design practices, such as advocated and practiced by software engineering gurus (e.g., class abstraction), are compromised for the sake of efficiency on mobile platform www.vkedco.blogspot.com
  11. 11. Limited Storage ● Most of the available storage on mobile devices goes to music and movies ● Android devices require that applications be installed in the internal memory (apps cannot run from the external SD card) ● Consequently, the size of compiled apps matters: – Use native Android frameworks (e.g., content providers, SQLite, SharedPreferences) to persist, reuse, and share data – Clean up: do not leave files in the file system or records in a database when they are not needed www.vkedco.blogspot.com
  12. 12. Small Screens ● Users are demanding more and more information-rich UI experience ● This demand is a challenge for small screens ● Several assumptions and recommendations ASSUMPTION RECOMMENDATION User will only glance at your GUI Reduce number of widgets User will relate to intuitive layouts Put most important widgets in the center User will unlikely use a stylus Make your views big enough to support touch User will use different screen resolutions Make your GUIs scale on larger displays www.vkedco.blogspot.com
  13. 13. Responsiveness ● Android forces apps to be responsive ● If it detects an unresponsive application, it displays a Force Close dialog box www.vkedco.blogspot.com
  14. 14. Responsiveness ● Android monitors two conditions to determine responsiveness – App must respond to a user action within five seconds – Broadcast receiver must return from its onReceive() handler within ten seconds ● Likely culprits in low responsiveness – Network downloads – Complex processing (gaming, image processing) – I/O www.vkedco.blogspot.com
  15. 15. Security Quote August 28, 2013 —  According to a joint study by the Department of Homeland Security and the FBI, the Android operating system was the target of 79% of all malware attacks on mobile platforms in 2012. By comparison, Nokia’s Symbian system was the target of about 19% of attacks, iOS accounted for 0.7%, and Windows Mobile and BlackBerry both were targeted at 0.3%, the study found. Rob Marvin, Seventy-Nine Percent of Mobile Malware Attacks Directed at Android OS, SD Times, 08/28/2013 www.vkedco.blogspot.com
  16. 16. Security ● Android basic premise: users take responsibility for the apps they install ● Some best AppDev practices – Require permissions for intents and broadcasts – Handle with care inputs from external resources such as Web, SMS, IM, etc – Avoid exposing access to low-level hardware through your apps – Install Recommended Anti-Virus software ● Caveat: because we are in a classroom, we will take a weak approach to security, but that does not make it any less important www.vkedco.blogspot.com
  17. 17. Low Speed, High Latency ● Mobile connections are not as fast, reliable, or available (3G, 4G, and citywide WiFi are slowly changing this assumption) ● It is still safe to assume that your connection will be slow, intermittent, and expensive (in Eclipse IDE, you can simulate it by opening DDMS perspective, finding Emulator Control, and setting Latency to EDGE) ● It is safe to assume that applications will lose data or will not find it when it is required ● It is sometimes the best to limit the functionality of your application then have many bells and whistles fail at run time www.vkedco.blogspot.com
  18. 18. Data Costs ● Data transfer services, such as SMS and Geocoding, are not free ● Generic data transfer cost minimization guidelines: – Transfer as little data as possible – Cache data – Stop data transfer when your app is invisible – Keep data update rates low – Expose data transfer rates and costs through user preferences www.vkedco.blogspot.com
  19. 19. Respect User's Environment ● Never assume that your app is the most important feature on the device: to most users, a smartphone is firstly a phone, secondly an SMS and email processor, thirdly a camera, and fourthly a media player ● Consequently, your app should be: – Well behaved: does not waste cycles when invisible, switches seamlessly from foreground to background – Polite: does not interrupt current activities – Consistent: presents consistent UIs and data formats – Responsive: does not freeze due to lack of data www.vkedco.blogspot.com
  20. 20. Seamless User Experience (UE) ● UE is a fuzzy concept ● In many contexts, it stands for consistency in your app's starting, stopping, and transitioning without noticeable delays ● Several tips: – Persist data between sessions – Suspend tasks when they are invisible – De-emphasize “revolutionary” and “unfamiliar” and emphasize “cooperative” and “easily recognizable” www.vkedco.blogspot.com
  21. 21. UI Development www.vkedco.blogspot.com
  22. 22. Android Views ● Android GUI widgets are called views (text views, edit texts, buttons, radio buttons, etc) ● Views are grouped into containers (aka box models) ● Common containers are LinearLayout, RelativeLayout, and GridView (aka, a grid) www.vkedco.blogspot.com
  23. 23. LinearLayout ● LinearLayout is one of the most common containers used in Android UIs (probably because it provides for simple, intuitive interfaces consisting of item lists) ● LinearLayout has several properties that the UI designer can manipulate through XML or source code (e.g., orientation, fill, weight, gravity, padding) www.vkedco.blogspot.com
  24. 24. Orientation Property ● This property specifies whether a View object functions as a row or as a column ● If the value of the property is VERTICAL, the object is a column ● If the value of the property is HORIZONTAL, the object is a row www.vkedco.blogspot.com
  25. 25. Fill Model Property ● A View's fill model specifies how much space the view can take in its parent view ● Three possibilities: – hardcoded dimension: 50px – wrap_content: view can fill up its natural space; if it is too big, word wrap will be used – match_parent: fill up all available space in its parent after all other viewss are handled www.vkedco.blogspot.com
  26. 26. Weight Property ● This property indicates the proportion of the free space the widget should take ● This property is important when several widgets must split the available space inside a container ● For example: several buttons inside a LinearLayout www.vkedco.blogspot.com
  27. 27. Gravity Property ● The gravity property specifies how the widget should be aligned on the screen (inside its container) ● Some common gravity values are – left – right – center_horizontal – center_vertical www.vkedco.blogspot.com
  28. 28. Padding Property ● The padding property comes in handy when widgets are tightly clustered inside a container ● android:padding allows you to manipulate the white space between widgets ● You can use – android:paddingLeft – android:paddingRight – android:paddingBottom – android:paddingTop www.vkedco.blogspot.com
  29. 29. Android UI Measurement Units ● PIXEL – dot on screen ● IN – inches ● MM – millimeters ● PT – point – 1/72 of 1 inch ● DP – density independent pixel (DP is a unit on a 160 dpi screen: 1 dp is 1 pixel on a 160 dpi screen) ● DIP – synonym for DP ● SP – scale-independent pixel, similar to DP but scalable by users www.vkedco.blogspot.com
  30. 30. DP vs SP ● DP has constant ratio to PX: DP = PX * RATIO ● RATIO stays constant regardless of the device ● SP has scalable ratio to PX: DP = PX * RATIO * SCALE, where RATIO is constant but SCALE can be set by user ● Usage guideline: use SP for font sizes and DP/DIP for everything else www.vkedco.blogspot.com
  31. 31. Declarative and Procedural UI Development ● Declarative development consists of specifying GUI element in some formal language (XML) and then attaching back end code to consume GUI events (clicks, scrolls, taps, etc.) ● Procedural/Programmatic development consists of coding everything in some programming language (e.g., java.swing.* or java.awt.*) ● Mixed development consists of designing all gadgets in XML and attach code to implement UI logic www.vkedco.blogspot.com
  32. 32. XML-Based UI Design ● The most important step to mastering XML-Based GUI design is to relate visual GUIs with XML code that defines them ● XML specs are used to construct GUI objects they specify via XML inflation ● Why care about XML-Based GUI Design? ● It is not just for Android: – Microsoft's Extensible Application Markup Language (XAML) – Adobe's Flex – Mozilla's XML User Interface Language (XUL) www.vkedco.blogspot.com
  33. 33. XML Inflation <Button android:id=”@+id/button_one” style=”@style/my_button_style” android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:text=”@string/button_one_text” /> // XML inflation of the Button View defined above protected Button mButtonOne = null; mButtonOne = (Button) findViewById(R.id.button_one); www.vkedco.blogspot.com
  34. 34. International Date Display Application www.vkedco.blogspot.com Android 2.3.3 (Ginger Bread) source Android 4.2 (Jelly Bean) source
  35. 35. App Specs ● Develop an application that consists of one activity that displays three buttons: one for US locale, one for Italy locale, and one for France locale ● A click on a button displays in the screen the current date according to the rules of the specific locale ● The app should use a vertical LinearLayout to arrange its components ● Dates should be displayed in an EditText ● Buttons should be arranged in a horizontal LinearLayout ● EditText and LinearLayout with buttons should have image backgrounds www.vkedco.blogspot.com
  36. 36. Sample Screenshots Front Screen US Click IT Click FR Click
  37. 37. Development Steps ● UI XML Specification – Vertical LinearLayout – EditText – Horizontal LinearLayout – Buttons ● UI Construction & Logic – Date Formatting – Button Click Consumption www.vkedco.blogspot.com
  38. 38. UI XML Design www.vkedco.blogspot.com
  39. 39. Activity UI Structure www.vkedco.blogspot.com
  40. 40. UI: Vertical Linear Layout <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent” android:orientation="vertical" > <EditText> … </EditText> <LinearLayout> <Button> … </Button> <Button> … </Button> <Button> … </Button> </lLinearLayout> </LinearLayout> www.vkedco.blogspot.com
  41. 41. UI: EditText <EditText android:id="@+id/edTxtDate" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="1" android:background="@drawable/background_002" android:ems="10" android:inputType="none" android:textSize="30sp" > <requestFocus /> </EditText> 1) Create /res/drawable directory in your project 2) Place background_002.jpg in /res/drawable 3) Press F5 to refresh the project www.vkedco.blogspot.com
  42. 42. UI: Horizontal LinearLayout <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="0.5" android:background="@drawable/background_001" > <Button /> <Button /> <Button /> </LinearLayout> 1) Create /res/drawable directory in your project 2) Place background_001.jpg in /res/drawable 3) Press F5 to refresh the project www.vkedco.blogspot.com
  43. 43. UI: Button Style in /res/values/styles.xml <resources xmlns:android="http://schemas.android.com/apk/res/android"> <style name="AppTheme" parent="android:Theme.Light" /> <!-- This the added button style definition --> <style name="my_button_style"> <item name="android:textSize">20sp</item> <item name="android:layout_width">wrap_content</item> <item name="android:layout_height">wrap_content</item> </style> </resources> www.vkedco.blogspot.com
  44. 44. UI: Button Texts in /res/values/strings.xml <resources> <string name="app_name">International Date Display</string> <string name="hello_world">Hello world!</string> <string name="menu_settings">Settings</string> <string name="title_activity_inter_date_display">International Date Display Screen</string> <string name="btnUSTxt">US</string> <string name="btnITTxt">IT</string> <string name="btnFRTxt">FR</string> </resources> Define string constants for button texts in /res/values/strings.xml www.vkedco.blogspot.com
  45. 45. UI: Buttons <Button android:id="@+id/btnUS" style="@style/my_button_style" android:layout_gravity="left|center_vertical" android:layout_weight="1" android:text="@string/btnUSTxt" /> <Button <!-- same properties as 1st button --> android:text="@string/btnITTxt" /> <Button <!-- same properties as 1st button --> android:text="@string/btnFRTxt" /> www.vkedco.blogspot.com
  46. 46. UI Construction & Logic www.vkedco.blogspot.com
  47. 47. UI Construction // Member Declaration protected Button mBtnUS = null; protected Button mBtnIT = null; protected Button mBtnFR = null; protected EditText mEdTxtDateDisplay = null; // Member Construction via XML Inflation mEdTxtDateDisplay = (EditText) this.findViewById(R.id.edTxtDate); mBtnUS = (Button) this.findViewById(R.id.btnUS); mBtnIT = (Button) this.findViewById(R.id.btnIT); mBtnFR = (Button) this.findViewById(R.id.btnFR); www.vkedco.blogspot.com
  48. 48. Date Formatting: Java Imports ● java.text.DateFormat – Abstract class for date/time formatting subclasses ● java.text.SimpleDateFormat – Concrete class for formatting and parsing dates in locale- sensitive ways ● java.util.Date – specific instant in time, with millisecond precision ● java.util.Locale – Locale objects represent specific geographical, political, or cultural regions www.vkedco.blogspot.com
  49. 49. Date Formatting: UI Logic // Member Declaration protected DateFormat mDateFormatUS = null; protected DateFormat mDateFormatIT = null; protected DateFormat mDateFormatFR = null; // Member Construction mDateFormatUS = SimpleDateFormat .getDateInstance(SimpleDateFormat.LONG, Locale.US); mDateFormatIT = SimpleDateFormat .getDateInstance(SimpleDateFormat.LONG, Locale.ITALY); mDateFormatFR = SimpleDateFormat .getDateInstance(SimpleDateFormat.LONG, Locale.FRANCE); // Run Time String us_date = mDateFormatUS.format(new Date()) String it_date = mDateFormatIT.format(new Date()) String fr_date = mDateFormatFR.format(new Date()) www.vkedco.blogspot.com
  50. 50. Button Click Consumption import android.view.View.OnClickListener; public class InterDateDisplayAct extends Activity implements OnClickListener { public void onCreate(Bundle savedInstanceState) { mBtnUS.setOnClickListener(this); // set this object to be OnClickListener mBtnIT.setOnClickListener(this); // set this object to be OnClickListener mBtnFR.setOnClickListener(this); // set this object to be OnClickListener } public void onClick(View v) { // implementing onClick() of OnClickListener interface int ID = v.getId(); switch ( ID ) { case R.id.btnUS: mEdTxtDateDisplay.setText(this.mDateFormatUS.format(new Date())); break; case R.id.btnIT: mEdTxtDateDisplay.setText(this.mDateFormatIT.format(new Date())); break; case R.id.btnFR: mEdTxtDateDisplay.setText(this.mDateFormatFR.format(new Date()));; break; }}} www.vkedco.blogspot.com

×