MAD LectureNotes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

Overview of Android

Mobile Application Development

Avinash Chaudhari
History
• Android is an open source and Linux-based Operating System for mobile
devices such as smartphones and tablet computers.

• Android was developed by the Open Handset Alliance, led by Google, and
other companies.

• Android o ers a uni ed approach to application development for mobile


devices which means developers need only develop for Android, and their
applications should be able to run on di erent devices powered by Android.

• The rst beta version of the Android Software Development Kit (SDK) was
released by Google in 2007.

• On 15th August 2022, Google announced the next Android version,


13 Tiramisu.
fi
ff
fi
ff
Why Android?
• Open Source
• Larger Developer and Community Reach
• Increased Marketing
• Inter-App Integration
• Reduced Cost of Development
• Higher Success Ratio
• Rich Development Environment
Features of Android
• Beautiful UI: Android OS basic screen provides a beautiful and intuitive user
interface.

• Connectivity: GSM/EDGE, IDEN, CDMA, EV-DO, UMTS, Bluetooth, Wi-Fi,


LTE, NFC and WiMAX.

• Storage: SQLite, a lightweight relational database, is used for data storage


purposes.

• Media support: H.263, H.264, MPEG-4 SP, AMR, AMR-WB, AAC, HE-AAC,
AAC 5.1, MP3, MIDI, Ogg Vorbis, WAV, JPEG, PNG, GIF, and BMP.

• Messaging: SMS and MMS


Features of Android
• Web browser: Based on the open-source WebKit layout engine, coupled with
Chrome's V8 JavaScript engine supporting HTML5 and CSS3.

• Multi-touch: Android has native support for multi-touch which was initially
made available in handsets such as the HTC Hero.

• Multi-tasking: User can jump from one task to another and same time
various application can run simultaneously.

• Resizable widgets: Widgets are resizable, so users can expand them to


show more content or shrink them to save space.

• Multi-Language: Supports single direction and bi-directional text.



Features of Android
• Wi-Fi Direct: A technology that lets apps discover and pair directly, over a
high-bandwidth peer-to-peer connection.

• Android Beam: A popular NFC-based technology that lets users instantly


share, just by touching two NFC-enabled phones together.
Android Versions
• Android 1.0 • Android Ice Cream • Android Pie
Sandwich
• Android 1.1 • Android 10
• Android Jelly Bean
• Android Cupcake • Android 11
• Android KitKat
• Android Donut • Android 12
• Android Lollipop
• Android Eclair • Android 13
• Android Marshmallow
• Android Froyo
• Android Nougat
• Android Gingerbread
• Android Oreo
• Android Honeycomb
Environment Setup
• Android SDK available for following operating systems:
• Microsoft Windows
• Mac OS X
• Linux
• Tools to develop Android applications are freely available and can be
downloaded from the Web.

• Softwares required for Android application development


• JDK
• Android Studio
Android Architecture
Dalvik Virtual Machine
• As we know the modern JVM is high performance and provides excellent
memory management. But it needs to be optimized for low-powered
handheld devices as well.

• The Dalvik Virtual Machine (DVM) is an android virtual machine optimized


for mobile devices. It optimizes the virtual machine for memory, battery
life and performance.
Android Application Components
• Application components are the essential building blocks of an Android
application.

• These components are loosely coupled by the application manifest


le AndroidManifest.xml that describes each component of the application
and how they interact.

• Four main components:


1. Activities
2. Services
3. Broadcast Receivers
4. Content Providers
fi
Activities
• An activity represents a single screen with a user interface, in-short Activity
performs actions on the screen.

• For example, an email application might have one activity that shows a list of
new emails, another activity to compose an email, and another activity for
reading emails.

• If an application has more than one activity, then one of them should be
marked as the activity that is presented when the application is launched.

• An activity is implemented as a subclass of Activity class as follows


public class MainActivity extends Activity {

}
Services
• A service is a component that runs in the background to perform long-running
operations.

• For example, a service might play music in the background while the user is in
a di erent application,

• or it might fetch data over the network without blocking user interaction with
an activity.

• A service is implemented as a subclass of Service class as follows


public class MyService extends Service {

}
ff
ServicesBroadcast Receivers
• Broadcast Receivers simply respond to broadcast messages from other
applications or from the system.

• For example, applications can also initiate broadcasts to let other applications
know that some data has been downloaded to the device and is available for
them to use, so this is broadcast receiver who will intercept this communication
and will initiate appropriate action.

• A broadcast receiver is implemented as a subclass of BroadcastReceiver class


and each message is broadcaster as an Intent object.

public class MyReceiver extends BroadcastReceiver {

public void onReceive(context,intent){}

}
Content Providers
• A content provider component supplies data from one application to others on
request.

• Such requests are handled by the methods of the ContentResolver class.


• The data may be stored in the le system, the database or somewhere else entirely.
• A content provider is implemented as a subclass of ContentProvider class and
must implement a standard set of APIs that enable other applications to perform
transactions.

public class MyContentProvider extends ContentProvider{

public void onCreate(){}

}
fi
Additional Components
• Fragments: Represents a portion of user interface in an Activity.
• Views: UI elements that are drawn on-screen including buttons, lists forms
etc.

• Layouts: View hierarchies that control screen format and appearance of the
views.

• Intents: Messages wiring components together.


• Resources: External elements, such as strings, constants and drawable
pictures.

• Manifest: Con guration le for the application.


fi
fi
Android Layout
Mobile Application Development

Avinash Chaudhari
Android UI
• Android provides a variety of Pre-built UI components.
• Layout objects and UI controls that allow you to build the graphical user
interface for your app.

• Android also provides other UI modules for special interfaces such as dialogs,
noti cations, and menus.
fi
View Group
• A ViewGroup is a special view that can contain other views (called children.)
• The view group is the base class for layouts and views containers.
• It’s child can be Views or View Group.
Views
• View class represents the basic building block for user interface components.
• A View occupies a rectangular area on the screen and is responsible for
drawing and event handling.

• All of the views in a window are arranged in a single tree.


• View is the base class for widgets, which are used to create interactive UI
components (buttons, text elds, etc.)
fi
Layouts
• A layout de nes the structure for a user interface in your activity.
• All elements in the layout are built using a hierarchy of View and ViewGroup
objects.

• A View usually draws something the user can see and interact with.
• Layout(View Group) is an invisible container that de nes the layout structure
for View and other Layout(View Group) objects.

• It provides a di erent layout structure, such as LinearLayout or


ConstraintLayout.
fi
ff
fi
Linear Layout
• LinearLayout is a view group that aligns all children in a single direction,
vertically or horizontally.

• You can specify the layout direction with the android:orientation attribute.
• Linear Layout can be created in two direction: Horizontal &
Vertical.

• LinearLayout also supports assigning a weight to individual


children with the android:layout_weight attribute.

• This attribute assigns an important value to a view in terms


of how much space it should occupy on the screen.

• A larger weight value allows it to expand to ll any


remaining space in the parent view.

fi
Relative Layout
• RelativeLayout is a view group that displays child views in relative positions.
• The position of each view can be speci ed as relative to sibling elements or in
positions relative to the parent RelativeLayout area.

• As it allows us to position the component anywhere, it is considered as most


exible layout.
• Relative layout is the most used layout after the
Linear Layout in Android.

• In Relative Layout, you can use “above, below, left


and right” to arrange the component’s position in
relation to other component.

• In this view group child views can be layered on top


of each other.
fl
fi
Frame Layout
• Frame Layout is designed to block out an area on the
screen to display a single item.

• It is used to specify the position of Views.


• It contains Views on the top of each other to display only
single View inside the FrameLayout.

• You can, add multiple children to a FrameLayout and


control their position by using gravity attribute.

• In this the child views are added in a stack and the most
recently added child will show on the top.
Table Layout
• Android TableLayout arranges groups of views into rows
and columns.

• <TableRow> element is used to build a row in the table.


Each row has zero or more cells; each cell can hold one
View object.
Grid Layout
• Android TableLayout arranges groups of views into rows
and columns.

• <TableRow> element is used to build a row in the table.


Each row has zero or more cells; each cell can hold one
View object.
Absolute Layout
• An Absolute Layout lets you specify exact locations (x/y
coordinates) of its children.

• Absolute layouts are less exible and harder to maintain


than other types of layouts without absolute positioning.

fl
Constraint Layout
Attribute Description

Android:id This is used to give a unique id to the layout.

app:layout_constraintBottom_toBottomOf This is used to constrain the view with respect


to the bottom position.
app:layout_constraintLeft_toLeftOf This attribute is used to constrain the view with
respect to the left position.

app:layout_constraintRight_toRightOf This attribute is used to constrain the view with


respect to the right position.

app:layout_constraintTop_toTopOf This attribute is used to constrain the view with


respect to the top position.
Constraint Layout
Constraint Layout
TextView
• TextView is a UI Component that displays the text to the user on their Display Screen.
Attribution Description

android:id This is the ID which uniquely identifies the control.

android:fontFamily Font family (named by string) for the text.


android:gravity Specifies how to align the text when the text is smaller than the view.
android:maxHeight Makes the TextView be at most this many pixels tall.
android:maxWidth Makes the TextView be at most this many pixels wide.
android:text Text to display in view.
android:textAllCaps Make the text in Capital. Possible value either "true" or "false".
android:textColor Text color. May be a color value, in the form of "#rgb", "#argb", "#rrggbb", or "#aarrggbb".
android:textStyle Style (bold, italic, bolditalic) for the text. You can use or more of the values separated by '|'. normal – 0,
bold – 1, italic - 2

android:typeface Typeface (normal, sans, serif, monospace) for the text. You can use or more of the values separated by
'|'. normal – 0, sans – 1, serif – 2, monospace – 3.
EditText
• An EditText is an overlay over TextView that con gures itself to be editable.
• It is the prede ned subclass of TextView that includes rich editing capabilities.
Attribute Description

android:autoText TextView has a textual input method and automatically corrects some common
spelling errors.

android:drawableBottom This is the drawable to be drawn below the text.

android:editable If set, specifies that this TextView has an input method.

android:background This is a drawable to use as the background.

android:inputType The type of data being placed in a text field. Phone, Date, Time, Number, Password
etc.
android:hint Hint text to display when the text is empty.

android:focusable It specifies that this edittext gets auto focus or not.


fi
fi
Button
• A Button which can be pressed, or clicked, by the user to perform an action.
• To specify an action when the button is pressed, set a click listener on the button object
in the corresponding activity code.

• Every button is styled using the system's default button background it can customize.
Attribute Description

android:text This is used to display text on button.

android:background This is a drawable to use as the background.

android:id This supplies an identifier name for this view.

android:onClick This is the name of the method in this View's context to invoke when the view is
clicked.
Toast
• Android Toast can be used to display information for a short period of time.
• A toast contains a message to be displayed quickly and disappears after some time.
• It doesn't block user interaction.

Toast.makeText(getApplicationContext(),"Hello World”,Toast.LENGTH_SHORT)

.show();
ToggleButton
• Android Toggle Button can be used to display checked/unchecked (On/O ) state on
the button.

• It is bene cial if user have to change the setting between two states. It can be used to
On/O Sound, Wi , Bluetooth etc.

Method Description

CharSequence getTextO () Returns the text when button is not in the checked state.

CharSequence getText() Returns the text of the current state

CharSequence getTextOn() Returns the text for when button is in the checked state.

void setChecked(boolean checked) Changes the checked state of this button.


ff
fi
fi
ff
ff
Audio, Video, Camera
Mobile Application Development

Avinash Chaudhari
Audio, Video, Camera
MediaPlayer

• MediaPlayer - Control playback of audio/video les and streams.


• Can be implemented in main or background thread.
• Not thread-safe.
• Creation and access to player instances should be on same thread.
• If registering callbacks, thread must have looper.

fi
MediaPlayer
Audio, Video, Camera

• The ovals represent the states a MediaPlayer object may reside in.
• The arcs represent the playback control operations that drive the object state
transition.

• The arcs with a single arrow head represent synchronous method calls.
• The double arrow head represent asynchronous method calls.
• setOnBu eringUpdateListener()
• seekTo(long, int)
ff
Methods

mediaPlayer = MediaPlayer.create(this,R.raw.kalimba);

mediaPlayer.start();
mediaPlayer.pause();
mediaPlayer.reset();

mediaPlayer.isPlaying();
mediaPlayer.seekTo(position);
mediaPlayer.getCurrentPosition();
mediaPlayer.getDuration();

mediaPlayer.setDataSource(R.raw.kalimba);
mediaPlayer.selectTrack(index);

mediaPlayer.release();
Video Player

• Using MediaController and VideoView classes, we can play the video les in
android.

• MediaController is a view that contains media controls like play/pause,


previous, next, fast-forward, rewind etc.

• VideoView class provides methods to play and control the video player.

fi
Methods of VideoView

• setMediaController(MediaController controller)
• setVideoUri(Uri uri)
• start()
• stopplayback()
• pause()
• suspend()
• resume()
• seekTo()
VideoView

<VideoView
android:id="@+id/videoView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
Activity

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

VideoView videoView =(VideoView) ndViewById(R.id.videoView1);

//Creating MediaController
MediaController mediaController= new MediaController(this);
mediaController.setAnchorView(videoView);

//specify the location of media le


Uri uri=Uri.parse(R.raw.video);

//Setting MediaController and URI, then starting the videoView


videoView.setMediaController(mediaController);
videoView.setVideoURI(uri);
videoView.requestFocus();
videoView.start();
}
fi
fi
Media Recorder

File dir = Environment.getExternalStorageDirectory();


try {
audio le = File.createTempFile("sound", ".3gp", dir);
} catch (IOException e) {
Log.e(TAG, "external storage access error");
return;
}
//Creating MediaRecorder and specifying audio source, output format, encoder & output format
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.setOutputFile(audio le.getAbsolutePath());
recorder.prepare();
recorder.start();
fi
fi

You might also like