Sie sind auf Seite 1von 9

Assignment 2

Mobile Technology-Banking (CSE-BFSI-6th Semester)

Q.1 Write structure and XML code for the following: CO2/CO3
(i) Linear Layout
(ii) Relative Layout
(iii) Frame Layout

Ans 1. The structure and xml code for the following is:

1.Linear Layout: A Layout that arranges its children during a single column or one row. The direction
of the row are often set by calling setOrientation()/android orientation=”verticle”. you'll also specify
gravity, which specifies the alignment of all the kid elements by calling setGravity() or specify that
specific children grow to refill any remaining space within the layout by setting the load member of
LinearLayout.LayoutParams. The default orientation is horizontal.

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:orientation="vertical" >
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/to" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/subject" />
<EditText
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="@string/message" />
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="@string/send" />
</LinearLayout>

2. Relative Layout: Relative Layout may be a view group that displays child views in relative
positions. The position of each view are often specified as relative to sibling elements (such on the
left-of or below another view) or in positions relative to the parent Relative Layout area (such as
aligned to rock bottom , left or centre )

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/reminder" />
<Spinner
android:id="@+id/dates"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@+id/times" />
<Spinner
android:id="@id/times"
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/name"
android:layout_alignParentRight="true" />
<Button
android:layout_width="96dp"
android:layout_height="wrap_content"
android:layout_below="@id/times"
android:layout_alignParentRight="true"
android:text="@string/done" />
</RelativeLayout>

3. Frame Layout: FrameLayout is meant to dam out a neighborhood on the screen to display one
item. Generally, FrameLayout should be wont to hold one child view, because it'll be difficult to
rearrange child views during how that's scalable to different screen sizes without the youngsters
overlapping one another . You can, however, add multiple children to a FrameLayout and control
their position within the FrameLayout by assigning gravity to each child, using the
android:layout_gravity attribute.

Child views are drawn during a stack, with the foremost recently added child on top. the dimensions
of the FrameLayout is that the dimensions of its largest child (plus padding), visible or not (if the
FrameLayout's parent permits). Views that are View.GONE are used for sizing as long as
setConsiderGoneChildrenWhenMeasuring() is close to true
.

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/imgvw1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/flimg" />
<TextView
android:id="@+id/txtvw1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:background="#4C374A"
android:padding="10dp"
android:text="Grand Palace, Bangkok"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/txtvw2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|bottom"
android:background="#AA000000"
android:padding="10dp"
android:text="21/Aug/2017"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</FrameLayout>

Q.2 Write steps to a notification and how to add sound to the Notification

 Follow these steps to send a Notification:

1.Get a reference to the Notification Manager


NotificationManager nm=(NotificationManager)
getSystemService(Context.NOTIFICATION_SERVICE)

2. Build the Notification message


public Notification (int icon, CharSequence tickerText, long when)
public void setLatestEvent(Context context, CharSequence contentTitle, CharSequence
contentText, PendingIntent intent)

3. Send the notification to the Notification Manager


public void notify (int id, Notification notification)

Add a sound to the notification –

// Use a default sound


notification.defaults |= Notification.DEFAULT_SOUND;
Pass an URI to the sound field to set a different sound
notification.sound = Uri.parse(file://sdcard/path/ringer.mp3);
Use FLAG_INSISTENT to play the sound till notification is handled
notification.flags |= Notification.FLAG_INSISTENT

Add vibration to the notification


// Use a default vibration
notification.defaults |= Notification.DEFAULT_VIBRATE;

CO4

Q.3 What are the different types of dialogues used in android.


CO5
A dialog is usually a small window that appears in front of the current Activity The underlying Activity
loses focus and the dialog accepts all user interaction Dialogs are normally used for notifications and
short activities that directly relate to the application in progress.
4 types of dialogs are there
1. Alert Dialog
2. Progress Dialog
3. Date Picker Dialog
4. Time Picker Dialog

Alert Dialog
•A dialog that can manage zero, one, two or three buttons.
•It can also manage a list of selectable items that can include checkboxes or radio buttons.
•The Alert Dialog is capable of constructing most dialog user interfaces and is the suggested dialog
type. •Alert Dialog class is a subclass of Dialog class and has a nested subclass.
•AlertDialog.Builder to construct a dialog.

Progress Dialog
A Progress Dialog is an extension of the Alert Dialog class that can display a progress animation in
the form of a spinning wheel The dialog can also provide buttons, such as one to cancel a download
Progress Dialog dialog = ProgressDialog.show) MyActivity.this,"" , "Loading .Please wait"..., true);

Time picker dialog


These components are used to select date and time in a customised user interface.
public TimePickerDialog
( Context context,
TimePickerDialog.OnTimeSetListener callback,
Int hourOfDay,
int minute,
boolean is24HourView)
How parent is notified.callBack The initial hour. hourOfDay The initial minute. minute Whether this is
a 24 hour view, or AM/PM. is24HourView .

DatePickerDialog

The DatePickerDialog class consists of a 5 argument constructor with the parameters listed below.

1. Context: It requires the application context


2. CallBack Function: onDateSet() is invoked when the user sets the date with the following
parameters:

 int year : It will be store the current selected year from the dialog
 int monthOfYear : It will be store the current selected month from the dialog
 int dayOfMonth : It will be store the current selected day from the dialog

1. int mYear : It shows the the current year that’s visible when the dialog pops up
2. int mMonth : It shows the the current month that’s visible when the dialog pops up
3. int mDay : It shows the the current day that’s visible when the dialog pops up

code-

Public DatePickerDialog

( Context context,

DatePickerDialog.OnDateSetListener callback,

int year,

int monthOfYear,

int dayOfMonth )

Q.4 Describe how to add menu in an android application with


example. What are the kinds of menus supported by android?
CO4

Ans 4.

Menus Items are often grouped together by assigning all a group ID.

• Multiple menu items that carry an equivalent group ID are considered


a part of an equivalent group

• The order of menu items within a menu is defined by the sortorder ID


property

• Some of those order-number ranges are reserved surely sorts of menus.

• Secondary menu items: considered smaller start at 0x30000 and are


defined by the constant Menu.CATEGORY_SECONDARY

• System menus, alternative menus, and container menus—have different


order-number ranges

ADDING MENU ITEMS


@Override
public boolean onCreateOptionsMenu(Menu menu)
{ //call the bottom class to incorporate system menus
super.onCreateOptionsMenu(menu);
menu.add(0 // Group id
,1 // item id
,0 // sort order id
,”menu item 1"); // title
menu.add(0,2,1,”menu item 2");
menu.add(0,3,2,”menu item 3");
return true;
}

Kinds of menus supported by android are:

1. Optional Menus: the choices menu is that the primary collection of menu items for an activity.
It's where you ought to place actions that have a worldwide impact on the app, like "Search,"
"Compose email," and "Settings."
2. Sub Menus: Sub menu may be a floating menu, it are often a toddler menu of options menu
or context menu. - It supports checkboxes, radio buttons and shortcut keys. - It doesn't
support item icons, or nested sub menus.
3. Context Menu: A context menu may be a floating menu that appears when the user
performs a long-click on a component . It provides actions that affect the chosen content or
context frame.

Q.5 What classes are provided by Android framework to play audio and
video files? What are the uses of these classes? How audio file can be
played through media player? Where these audio file need to be kept?

Android provides some ways to regulate playback of audio/video files and streams. One of this
manner is through a category called MediaPlayer.Android is providing MediaPlayer class to
access built-in mediaplayer services like playing audio,video e.t.c. In order to use
MediaPlayer, we've to call a static Method create() of this class. This method returns an
instance of MediaPlayer class. Its syntax is as follows –

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


The second parameter is that the name of the song that you simply want to play.

Once Mediaplayer object is created. These methods can call some methods to start or stop the are
listed below.
mediaPlayer.start();
mediaPlayer.pause();
On call to start() method, the music will start playing from the start . If this method is
named again after the pause() method, the music would start playing from where  it's left and
not from the start .

In order to start out music from the start , you've got to call reset() method.


1. isPlaying()- This method just returns true/false indicating the song is playing or not

2. seekTo(position)- This method takes an integer, and move song thereto particular position


millisecond

3. getCurrentPosition()- This method returns the present position of song in milliseconds

4. getDuration()- This method returns the entire time duration of song in milliseconds

5. reset()- This method resets the media player

6.release()- This method releases any resource attached with MediaPlayer object

7. setVolume(float leftVolume, float rightVolume)- This method sets the up down volume for
this player

8. setDataSource(FileDescriptor fd)-This method sets the info source of audio/video file

9. selectTrack(int index)- This method takes an integer, and choose the track from the
list thereon particular index

10. getTrackInfo()- This method returns an array of track information

We can play and control the audio files in android by the assistance of MediaPlayer class.
The android.media.MediaPlayer class is employed to regulate the audio or video files.
The audio files are often moved to a folder named raw which should be created within the res
folder.

It can be accessed by the following code:

MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.soundclip);


mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.start();

Das könnte Ihnen auch gefallen