Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Major Components of My First App – Lab 1 Demos Jan. 19, 2017 Smartphone Screen Size Support, http://developer.android.com/guide/practices/screens_support.html • Screen size: small, normal, large, extra-large • Screen density (unit: dot per inch, or dpi): six densities – low, medium, high, extra-high, extra-extra-high, and extra-extra-extra high • Orientation (landscape, portrait) • Resolution (total number of physical pixels) • Density-independent pixel (dp) o A virtual pixel unit – used to express layout dimensions or position in a densityindependent way. o 1 dp is equivalent to one physical pixel on a 160 dpi screen, which is the baseline density assumed by system for a “medium” density screen. o The conversion of dp units to screen pixels px = dp *( dpi/160) o For example, on 240 dpi screen, 1 dp equals 1.5 physical pixel • A set of six generalized densities: o ldpi (low) ~ 120 dpi o mdpi (medium) ~ 160 dpi o hdpi (high) ~ 240 dpi o xhdpi (extra-high) ~ 320 dpi o xxhdpi (extra-extra-high) ~ 480 dpi o xxxhdpi (extra-extra-extra-high) ~ 640 dpi Major components of an Android app inside Android Project • manifests o AndroidManifest.xml • java o com.example.yourcompany.myfirstapp MyActivity.java o com.example.yourcompany.myfirstapp • res o drawable o layout activity_my.xml o mipmap ic_launcher.png (5) • ic_launcher.png (hdpi) • ic_launcher.png (mdpi) • ic_launcher.png (xhdpi) • • • o values Gradle Scripts ic_launcher.png (xxhdpi) ic_launcher.png (xxxhdpi) colors.xml dimens.xml strings.xml styles.xml App Manifest, http://developer.android.com/guide/topics/manifest/manifest-intro.html • Each app must have an AndroidManifest.xml file in its root directory. • Manifest file presents essential info about your app to the Android system • It serves the following purposes: It o Names the Java package for the app o Describes the components of the application o Determine which processes will host application components – the activities, services, broadcast receivers, and content providers that the app is composed of. o Declares which permissions the app must have in order to access protected parts of the API and interact with other applications o Declares which permissions that others are required to have in order to interact with the application’s components. o Lists the Instrumentation classes that provide profiling and other information as the application is running. o Declares the minimum level of the Android API o Lists the libraries that the application must be linked AndroidManifest.xml <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lin.myfirstapp"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".MyActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest> res.layout activity_my_my.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:id="@+id/activity_my" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.example.lin.myfirstapp.MyActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Hello World!" /> </RelativeLayout> res.values colors.xml <?xml version="1.0" encoding="utf-8"?> <resources> <color name="colorPrimary">#3F51B5</color> <color name="colorPrimaryDark">#303F9F</color> <color name="colorAccent">#FF4081</color> </resources> dimens.xml <resources> <!-- Default screen margins, per the Android Design guidelines. --> <dimen name="activity_horizontal_margin">16dp</dimen> <dimen name="activity_vertical_margin">16dp</dimen> <dimen name="fab_margin">16dp</dimen> </resources> strings.xml <resources> <string name="app_name">MyFirstApp</string> </resources> styles.xml <resources> <!-- Base application theme. --> <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> <!-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> </style> </resources> XML tags and nodes within AndroidManifest.xml, http://developer.android.com/guide/topics/manifest/manifest-intro.html <manifest> <uses-permission /> <uses-sdk /> <uses-configuration /> <uses-feature /> o audio o Bluetooth o Camera o Location o Microphone o NFC o Sensors o Telephony (GSM or CDMA) o USB o Wi-Fi <application /> a manifest can contain only one application node; a container for o activity o service o content provider o broadcast receiver </manifest>