• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Mobile Application Development: Lecture 11
 

Mobile Application Development: Lecture 11

on

  • 706 views

 

Statistics

Views

Total Views
706
Views on SlideShare
405
Embed Views
301

Actions

Likes
0
Downloads
0
Comments
0

23 Embeds 301

http://vkedco.blogspot.com 130
http://www.vkedco.blogspot.com 116
http://vkedco.blogspot.in 10
http://www.vkedco.blogspot.in 6
http://vkedco.blogspot.de 5
http://vkedco.blogspot.co.il 5
http://vkedco.blogspot.jp 3
http://vkedco.blogspot.com.es 3
http://vkedco.blogspot.fr 3
http://vkedco.blogspot.co.uk 3
http://www.vkedco.blogspot.ro 3
http://vkedco.blogspot.hu 2
http://www.vkedco.blogspot.co.il 2
http://www.blogger.com 1
http://vkedco.blogspot.kr 1
http://www.vkedco.blogspot.co.uk 1
http://vkedco.blogspot.com.br 1
http://vkedco.blogspot.mx 1
http://www.vkedco.blogspot.com.es 1
http://www.vkedco.blogspot.jp 1
http://www.vkedco.blogspot.ch 1
http://www.vkedco.blogspot.fr 1
http://vkedco.blogspot.ae 1
More...

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Mobile Application Development: Lecture 11 Mobile Application Development: Lecture 11 Presentation Transcript

    • Mobile Application Development Lecture 11 Vladimir Kulyukin Department of Computer Science Utah State Universityhttp://www.youtube.com/vkedco www.vkedco.blogspot.com
    • Outline ● Working with Resources ● Custom Views ● Custom Array Adaptershttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Working with Resourceshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Compiled and Non-compiled Resources ● Most resources are compiled into binary files before deployment ● Two types of resource files: XML and raw (image, video, audio) ● String and layout resources are compiled into binary format ● XML files placed in /res/raw/ are not compiled into binary format ● Audio and video also go into /res/raw/http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Common Resource Sub-directories ● anim – compiled animation files ● drawable - .bmp, .png, jpg, etc. ● layout – view specifications ● values – arrays, colors, dimensions, strings, styles ● xml – compiled XML ● raw – non-compiled raw fileshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Resource Compilation ● The resource compiler is part of the Android Packaging Tool (AAPT) ● The resource compiler compiles all resources except those in /res/raw/ and places them into the .apk file ● The .apk file is similar to the Java .jar file and contains all the applications code and resources ● The .apk file is installed on the devicehttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Resource Compilation Colors / Color codes; exposed res/values/some_ in R.java as R.color.* file.xml Dimensions / Sizes of various res/values/some_ elements in pixels, file.xml inches, millimeters; exposed in R.java as R.dimen.* Images / Image resources (.jpg, res/drawable/so .gif, .png); Exposed me- through R.java as subfolder/some_f R.drawable.* ile.xmlhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Raw Assets ● Project directory /assets/ contains raw files ● Unlike /res/ directory, /assets/ may contain arbitrarily many sub-directories ● Unlike files in /res/ directory, /assets/ directory do not generate resource IDs ● Relative path names must be used to access files in /assets/http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Color Resources ● Android color constants are available in android.R.color namespace ● You can also specify your own colors in /res/values/ <resources> <color name=”red_clr”>#f00</color> <color name=”blue_clr”>#0000ff</color> </resources>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Color Resources ● Color resource files are placed in /res/values/ ● Here is how to access color resources in Java and define them in XML: // Java Access int color = getResources().getColor(R.color.my_color); // XML Definition <TextView android:textColor=”@color/blue_clr” android:text=”Blue Text” />http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Raw Resources ● Place audio, video, text that you need in your application in /res/raw/ ● These files are not compiled but moved to the .apk ● These files are referenced through R.java ● Example: /res/raw/david_hilbert_bio.txt can be referenced as R.raw.david_hilbert_biohttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Raw Resources: Example private String processRawTextFile() { Resources res = getResources(); InputStream instrm = res.openRawResource(R.raw.david_hilbert_bio); processRawStream(instrm); }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Assets ● Directories /assets/ and /res/ are at the same level of the project tree hierarchy ● Files placed in /assets/ do not generate IDs in R.java ● Files in /assets/ are accessed through relative paths starting at /assets/ ● The AssetManager class is used to access assetshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Assets Example private String processAssetsTextFile() { AssetManager amngr = getAssets(); // process /assets/church_bio.txt InputStream instrm = amngr.open(“hilbert_bio.txt”); processAssetsStream(instrm); }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Viewshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views ● Views can be customized to change the look and feel of your applications ● Views can be are typically customized by extending either View or SurfaceView classes ● View is a lightweight solution for 2D graphics ● SurfaceView can be used for 3D graphicshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 1http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 1 ● What Do We Need To Do To Construct Custom View 1? ● Step 1: Specify the mathematicians names in an XML file (famous_mathematicians.xml) ● Step 2: Create an ArrayAdapter<String> ● Step 3: Connect the ArrayAdapter<String> to the activitys ListViewhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Example 1 Code Highlightshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 1: Step 1 <resources> <string-array name="list_of_famous_mathematicians"> <item>Alonzo Church</item> <item>Kurt Gödel</item> <item>David Hilbert</item> <item>Giuseppe Peano</item> <item>Georg Cantor</item> <item>Muhammad al-Khwarizmi</item> <item>Blaise Pascal</item> <item>Isaac Newton</item> <item>Johannes Kepler</item> <item>Nikolaus Kopernikus</item> <item>Omar Khayyam</item> </string-array> </resources>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 1: Steps 2 & 3 private static String[] mListOfMathematicians = null; private static Resources mRes = null; private void populateListViewOne() { mListOfMathematicians = mRes.getStringArray(R.array.list_of_famous_mathematicians); getListView().setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, mListOfMathematicians)); }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2 ● What Do We Need To Do To Construct Custom View 2? ● Step 1: Specify the mathematicians names in XML (famous_mathematicians.xml) (Same as in Example 1) ● Step 2: Design and develop a mathematician class Mathematician.java ● Step 3: Design and develop a mathematicians view in Java (MathematicianView.java) and in XML (colors.xml, dimens.xml mathematician_view_1.xml) ● Step 4: Create an ArrayAdapter<Mathematician> ● Step 5: Connect ArrayAdapter<Mathematician> to the activitys ListViewhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Example 2 Code Highlightshttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2: Step 2 Define a Custom Data Type that Needs a Custom View (See Mathematician.java and MathematicianView.java in ListOfMathematicians Project)http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2: Step 3 (colors.xml) <?xml version="1.0" encoding="utf-8"?> <resources> <color name="background_clr">#AAFFFF99</color> <color name="line_clr">#FF0000FF</color> <color name="margin_clr">#90FF0000</color> <color name="text_clr">#AA0000FF</color> </resources>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2: Step 3 (dimens.xml) <?xml version="1.0" encoding="utf-8"?> <resources> <dimen name="left_margin">50dp</dimen> <dimen name="right_margin">30dp</dimen> </resources>http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2: Step 3 (mathematician_view_1.xml) <?xml version="1.0" encoding="utf-8"?> <org.vkedco.android.listofmathematicians.MathematicianView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="10dp" android:scrollbars="vertical" android:textColor="@color/text_clr" android:textSize="20dp" android:fadingEdge="vertical" />http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Custom Views: Example 2: Steps 4 & 5 private void populateListViewTwo() { mListOfMathematicians = mRes.getStringArray(R.array.list_of_famous_mathematicians); ArrayList<Mathematician> mathematicians = new ArrayList<Mathematician>(); for(String name : mListOfMathematicians) { String[] fnln = name.trim().split(" "); mathematicians.add(new Mathematician(fnln[0],fnln[1])); } getListView().setAdapter(new ArrayAdapter<Mathematician>(this, R.layout.mathematician_view_1, mathematicians)); }http://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • References ● http://developer.android.com/training/custom-views/index.htmlhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com
    • Feedback Bugs to vladimir dot kulyukin at gmail dot comhttp://www.youtube.com/vkedco http://www.vkedco.blogspot.com