Practical No.
03
Write an application that draws basic graphical primitives on the screen.
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView" />
</RelativeLayout>
[Link]:
package [Link].exno3;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
[Link](savedInstanceState);
setContentView([Link].activity_main);
//Creating a Bitmap
Bitmap bg = [Link](720, 1280, [Link].ARGB_8888);
//Setting the Bitmap as background for the ImageView
ImageView i = (ImageView) findViewById([Link]);
[Link](new BitmapDrawable(bg));
//Creating the Canvas Object
Canvas canvas = new Canvas(bg);
//Creating the Paint Object and set its color & TextSize
Paint paint = new Paint();
[Link]([Link]);
[Link](50);
//To draw a Rectangle
[Link]("Rectangle", 420, 150, paint);
[Link](400, 200, 650, 700, paint);
//To draw a Circle
[Link]("Circle", 120, 150, paint);
[Link](200, 350, 150, paint);
//To draw a Square
[Link]("Square", 120, 800, paint);
[Link](50, 850, 350, 1150, paint);
//To draw a Line [Link]("Line", 480, 800, paint);
[Link](520, 850, 520, 1150, paint);
}}
Practical No. 04
Develop a native application that uses GPS location information.
[Link]
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="[Link]
android:id="@+id/relativeLayout1"
android:layout width="match_parent"
android:layout_height="match_parent" >
<Button
android:id="@+id/show_Location"
android:layout width="wrap_content"
android:layout height="wrap_content"
android:text="Show_Location"
android:layout_centerVertical="true"
android:layout centerHorizontal="true"/>
</RelativeLayout>
[Link]
package [Link];
import [Link];
import [Link];
import [Link]; import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link]; import [Link];
import [Link];
public class GPStrace extends Service implements LocationListener{
private final Context context;
boolean isGPSEnabled=false;
boolean canGetLocation-false;
boolean isNetworkEnabled=false;
Location location:
double latitude:
double longtitude;
private static final long
MIN DISTANCE CHANGE FOR UPDATES-10;
private static final long MIN_TIME_BW_UPDATES-1000*60*1;
protected LocationManager locationManager:
public GPStrace (Context context)
{
[Link]=context; getLocation();
}
public Location getLocation()
{
try{ locationManager=(LocationManager) [Link](LOCATION_SERVICE);
isGPSEnabled=[Link] (Location [Link] PROVIDER);
isNetworkEnabled=[Link] (Locat [Link] PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) (
}else{
[Link]=true;
if(isNetworkEnabled) { [Link] ( [Link]
PROVIDER, MIN
TIME BW UPDATES,
MIN DISTANCE CHANGE FOR UPDATES,this);
if(locationManager!=null){
location=[Link] KnownLocation (LocationMa [Link] PROVIDER);
if(location!=null)(
latitude=[Link]();
[Link]();
if(isGPSEnabled) {
if(location==null){
[Link] (LocationManager.G
PS_PROVIDER, MIN_TIME_BW_UPDATES, MIN DISTANCE CHANGE FOR UPDATES, this);
if (locationManager!=null){
location=[Link] (LocationMa nager.GPS_PROVIDER);
if (location!=null) {
[Link]();
longtitude=[Link]();
}
catch (Exception e)
[Link]();
return location;
}
public void stopUsingGPS () {
if (locationManager!=null) {
[Link] ([Link]);
}
public double getLatitude () {
if (location!=null){
latitude=[Link]();
return latitude;
public double getLongtiude(){
if (location!=null) (
longtitude=[Link]();
} return longtitude;
public boolean canGetLocation()(
return [Link]:
public void showSettingAlert(){
[Link] alertDialog=new [Link](context);
[Link]("GPS is settings");
[Link]("GPS is not enabled. Do you want to go to setting menu?");
[Link]("settings", new
[Link]() {
@Override
public void onClick(DialogInterface dialog, int which) (Intent intent-new Intent ([Link]
LOCATION SOURCE SETTINGS); [Link](intent);
}});
[Link]("cancel", new [Link]() {
@Override
public void onClick(DialogInterface dialog, int
which) {
[Link]();
@Override
public void onLocationChanged (Location location) {
@Override
public void onProviderDisabled(String provider)
}
@Override
public void onProviderEnabled(String provider) {
@Override
public void onStatusChanged (String provider, int status,
Bundle extras) f
@override
public Binder onBind(Intent intent)
// TODO Auto-generated method stub
return null
}
}
Practical No. 05
Design an android application for frame animation
animation_list.xml
<?xml version="1.0" encoding="utf-8"?>
<animation-list xmlns:android="[Link] android:oneshot="false">
<item android:drawable="@drawable/blank" android:duration="210" />
<item android:drawable="@drawable/logo" android:duration="210" />
<item android:drawable="@drawable/logo1" android:duration="210" />
<item android:drawable="@drawable/logo2" android:duration="210" />
<item android:drawable="@drawable/logo3" android:duration="210" />
<item android:drawable="@drawable/logo4" android:duration="210" />
<item android:drawable="@drawable/logo5" android:duration="210" />
<item android:drawable="@drawable/logo6" android:duration="210" />
<item android:drawable="@drawable/logofinal" android:duration="210" />
</animation-list>
activity_main.xml
<span style="font-size: 13px; text-align: center;">Here we are done with the xml part, see the image below
for reference :-
</span>
<p style="text-align: center;"><a href="<a href="[Link]
inandroid/">[Link] target="_blank"><img
class="aligncenter sizefull wp-image-2382" title="XML part in Frame animation" alt="XML part in Frame
animation" src="<a
href="[Link]
[Link]/blog/wpcontent/uploads/2013/02/[Link]</a>" width="845" height="603"
/></a></p>
<strong> </strong>
<h2><span style="font-size: large;"><strong>
Outside the onCreate method :</strong></span></h2>
<strong></strong>
Declare the Image View and Animation Drawable
[code lang="java"]
// Declaring an Image View and an Animation Drawable
ImageView view;
AnimationDrawable frameAnimation;
Step 3- Inside the OnCreate method:
• Typecast the Image view
• Typecast the Animation Drawable
• Set the drawable background on the image view
// Typecasting the Image View
view = (ImageView) findViewById([Link]);
// Setting animation_list.xml as the background of the image view
[Link]([Link].animation_list);
// Typecasting the Animation Drawable
frameAnimation = (AnimationDrawable) [Link]();
Step 4- After the onCreate method :
The animation should only run when it is in focus that is when it is visible to the user. Hence define this
method after the
onCreate method.
// Called when Activity becomes visible or invisible to the user
@Override
public void onWindowFocusChanged(boolean hasFocus) {
[Link](hasFocus);
if (hasFocus) {
// Starting the animation when in Focus
[Link]();
} else {
// Stoping the animation when not in Focus
[Link]();
}
}