Thursday, March 27, 2014

Androis AS IS

Android Emulator


The Android SDK includes a mobile device emulator — a virtual mobile device that runs on your computer. The emulator lets you develop and test Android applications without using a physical device.

This document is a reference to the available command line options and the keyboard mapping to device keys. For a complete guide to using the Android Emulator, see Using the Android Emulator.

Android Application Development


Create Android project  on the Android Development Tools Plugin ( ADT ) installed , you must log
a wizard called New Project Wizard by clicking on the menu File - > New - > Android Application Project , once finished this wizard the following structure of files and directories are created in the new project:
src /     
Directory for application source files.
gene /   
The directory containing the Java files generated by ADT as the R.java and AIDL files.
assets /   
Empty directory , can be used to store raw data files ( raw )
res /       
Directory for application resources such as drawable files , layout files , string values ​​, etc.
organized into sub directories:
           drawable - hdpi /
Directory for drawable objects (such as images ) that are designed for high-density screens ( hdpi ) . There are other directories that start with " drawable - " may contain elements designed by densities of other screens.

layout /
Directory for files that define the user interface of the application.
values ​​/
Directory for other XML files that contain a collection of resources such as brands , styles, etc. .
libs /
 Book the project needs .
bin /
 It contains among other things the. Apk , installable on Android device .
AndroidManifest.xml
The AndroidManifest.xml file for the project .
default.properties
File containing the project properties as the API target construction (build target) .

App Manifest

Each application must have a file named specifically, AndroidManifest.xml in the root directory, which presents essential information to the Android system, it needs before running each component and code any of the App  the information in this file is:

  • Set any permit application requires the user to use network functions or elements  hardware such as camera, bluetooth, etc.. The end user must approve these permissions for the application of  security features of Android. 
  • Declare the minimum API level the application requires. 
  • Declares features software and hardware required for the implementation. 
  • Describe the components of the application: Activities, Services, Broadcast receivers and Content providers. 
  • The libraries that the application requires are listed.

Example:
<manifest . . . >
    <permission android:name="com.example.project.DEBIT_ACCT" . . . />
    <uses-permission android:name="com.example.project.DEBIT_ACCT" />
    . . .
    <application . . .>
        <activity android:name="com.example.project.FreneticActivity"
                  android:permission="com.example.project.DEBIT_ACCT"
                  . . . >
            . . .
        </activity>
    </application>
</manifest>
The main activity for your app must be declared in the manifest with an <intent-filter> that includes theMAIN action and LAUNCHER category. For example:
<activity android:name=".MainActivity" android:label="@string/app_name">
    <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
    </intent-filter>
</activity>

Creating and Managing Activities

Create a user interface for an Android application , it must be designed using a hierarchy structure
views ( views ) and groups of views ( ViewGroup ) . The views are usually graphical elements like buttons or fields text, and are invisible containers ViewGroups defined as views are presented . The ViewGroup class is the basis for layout manager , of which there are several types class :

● Linear Layout : Position the views daughters in a single row or column , depending on the selected orientation .
● Frame Layout : Its purpose is to allocate an area of the screen.
● Table Layout : Arranges views daughters in a grid format of rows and columns.
● Grid Layout : (inserted as part of Android 4.0) A GridLayout object is divided into invisible lines that form a grid containing rows and columns of cells. The views daughters can occupy one or more cells in a horizontal or vertical
● Absolute Layout ( Obsolete since API 3) Allows daughters views be positioned at specific coordinates X and Y.
● Relative Layout : Possibly the most powerful and flexible , allows , daughters views , position relative to other views and own container.

There are some others like :
● List View : A view that shows items in a vertical list scroll bar.
● Grid View : A ViewGroup that displays items in a two-dimensional table with scrollbar
● Layout Tab : Create a tabbed user interface , which can contain views within a
Activity alone or use tabs for switching between different Activities .

Example layout by code

public class HelloWorld extends Activity { 
 //global var
 Button myButton ; 
 @Override 
 public void onCreate(Bundle savedInstanceState) { 
 super.onCreate(savedInstanceState); 
 //new layout by code
 LinearLayout myLayout = new LinearLayout(this); 
 myLayout.setOrientation(LinearLayout.VERTICAL); 
 //create a new instance of button
 myButton = new Button(this); 
 //Button's label
 myButton.setText("Map"); 
 //design's params
 myButton.setLayoutParams(new LinearLayout.LayoutParams( 
 LinearLayout.LayoutParams.WRAP_CONTENT, 
LinearLayout.LayoutParams.WRAP_CONTENT)); 
 //set one listener by the event click
 myButton.setOnClickListener(mgClick); 
 //Add myButton to myLayout
 myLayout.addView(myButton); 
 // set the layout to the current activity
 setContentView(myLayout); 
 } 
//method of button's listener
 private View.OnClickListener mgClick = new View.OnClickListener() { 
 @Override 
 public void onClick(View v) { 
 if( v == myButton ){ 
 //say hello
 } 
 } 
 } 

Using XML

Example layout using XML

TextView mTextView; // Member variable for text view in the layout
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Set the user interface layout for this Activity
    // The layout file is defined in the project res/layout/main_activity.xml file
    setContentView(R.layout.main_activity);
    
    // Initialize member TextView so we can manipulate it later
    mTextView = (TextView) findViewById(R.id.text_message);
    
    // Make sure we're running on Honeycomb or higher to use ActionBar APIs
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        // For the main activity, make sure the app icon in the action bar
        // does not behave as a button
        ActionBar actionBar = getActionBar();
        actionBar.setHomeButtonEnabled(false);
    }
}


more information

No comments:

Post a Comment