Professional Documents
Culture Documents
Final MAD Lab V
Final MAD Lab V
PEO2 Graduates will acquire the desire for lifelong learning and ability to work in
multidisciplinary teams for meeting the global challenges
PEO3 Graduates will be able to exhibit professional ethics, skills for management
and responsibility towards societal needs
PSO2 To acquire design skills for conducting domain specific experiments and
interpreting data to synthesize and analyze information
PSO3 To deploy appropriate algorithms, latest open source software and other
related programming engineering applications
311120205061 Vishal M
1) Program:
MainActivity.java:
package com.example.exp1;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button b1, b2;
TextView t;
float font = 20;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.button);
b2 = findViewById(R.id.button2);
t = findViewById(R.id.textView);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
t.setTextSize(font);
font = font + 5;
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
t.setTextColor(Color.BLUE);
}
});
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
311120205061 Vishal M
android:orientation="vertical
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="69dp"
android:text="Hellooo" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change FontSize" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Change Color" />
</LinearLayout>
Output:
311120205061 Vishal M
311120205061 Vishal M
2) Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:visibility="visible"
tools:context=".MainActivity"
tools:visibility="visible">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:text="Name" />
<EditText
android:id="@+id/editTextTextPersonName4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Age" />
<EditText
android:id="@+id/editTextTextPersonName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
311120205061 Vishal M
android:layout_height="wrap_content"
android:text="DOB" />
311120205061 Vishal M
<EditText
android:id="@+id/editTextTextPersonName3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="RegNo" />
<EditText
android:id="@+id/editTextTextPersonName5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<TextView
android:id="@+id/textView6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Department" />
<EditText
android:id="@+id/editTextTextPersonName6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Submit" />
</LinearLayout>
MainActivity.java:
package com.example.app;
import androidx.appcompat.app.AppCompatActivity;
311120205061 Vishal M
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
311120205061 Vishal M
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
Button b1;
TextView t1,t2,t3,t4,t5;
EditText ed1,ed2,ed3,ed4,ed5;
String name,age,dob,regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=findViewById(R.id.button3);
t1=findViewById(R.id.textView);
ed1=findViewById(R.id.editTextTextPersonName4);
t2=findViewById(R.id.textView3);
ed2=findViewById(R.id.editTextTextPersonName2);
t3=findViewById(R.id.textView4);
ed3=findViewById(R.id.editTextTextPersonName3);
t4=findViewById(R.id.textView5);
ed4=findViewById(R.id.editTextTextPersonName5);
t5=findViewById(R.id.textView6);
ed5=findViewById(R.id.editTextTextPersonName6);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
name=ed1.getText().toString();
age=ed2.getText().toString();
dob=ed3.getText().toString();
regno=ed4.getText().toString();
dept=ed5.getText().toString();
Intent i=new Intent(MainActivity.this,MainActivity2.class);
i.putExtra("name_key",name);
i.putExtra("age_key",age);
i.putExtra("dob_key",dob);
i.putExtra("reg_key",regno);
i.putExtra("dep_key",dept);
startActivity(i);
}
});
}
}
311120205061 Vishal M
actitvity_main2.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity2">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView7"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView9"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
<TextView
android:id="@+id/textView10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />
</LinearLayout>
MainActivity2.java:
311120205061 Vishal M
package com.example.app;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity2 extends AppCompatActivity {
311120205061 Vishal M
TextView tv1,tv2,tv3,tv4,tv5;
String name,age,dob,regno,dept;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
tv1=findViewById(R.id.textView2);
name=getIntent().getStringExtra("name_key");
tv1.setText(name);
tv2=findViewById(R.id.textView7);
age=getIntent().getStringExtra("age_key");
tv2.setText(age);
tv3=findViewById(R.id.textView8);
dob=getIntent().getStringExtra("dob_key");
tv3.setText(dob);
tv4=findViewById(R.id.textView9);
regno=getIntent().getStringExtra("reg_key");
tv4.setText(regno);
tv5=findViewById(R.id.textView10);
dept=getIntent().getStringExtra("dep_key");
tv5.setText(dept);
}
}
Output:
311120205061 Vishal M
3) Program:
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:srcCompat="@tools:sample/avatars" />
</LinearLayout>
MainActivity.java
package com.example.myapplication;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Creating a Bitmap
Bitmap bg = Bitmap.createBitmap(720, 1280, Bitmap.Config.ARGB_8888);
//Setting the Bitmap as background for the ImageView
ImageView i = (ImageView) findViewById(R.id.imageView);
311120205061 Vishal M
i.setBackgroundDrawable(new BitmapDrawable(bg));
//Creating the Canvas Object
Canvas canvas = new Canvas(bg);
//Creating the Paint Object and s
Paint paint = new Paint();
311120205061 Vishal M
paint.setColor(Color.BLUE);
paint.setTextSize(50);
//To draw a rectangle
canvas.drawText("Rectangle",420,150,paint);
canvas.drawRect(400,200,650,700,paint);
//To draw a circle
canvas.drawText("Circle",120,150,paint);
canvas.drawCircle(200,300,150,paint);
//To draw a rectangle
canvas.drawText("Square",120,800,paint);
canvas.drawRect(50,850,350,1150,paint);
//To draw a rectangle
canvas.drawText("Line",480,800,paint);
canvas.drawLine(520,850,520,1150,paint);
}
}
Output:
311120205061 Vishal M
5 ) Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<EditText
android:id="@+id/editTextTextPersonName2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Button" />
</LinearLayout>
MainActivity.java:
package com.example.myapplication;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button notify;
EditText e;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
notify = (Button) findViewById(R.id.button2);
311120205061 Vishal M
e = (EditText) findViewById(R.id.editTextTextPersonName2);
311120205061 Vishal M
notify.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, MainActivity.class);
PendingIntent pending =
PendingIntent.getActivity(MainActivity.this, 0, intent, 0);
Notification noti = new
Notification.Builder(MainActivity.this).setContentTitle("New
Message").setContentText(e.getText().toString()).setSmallIcon(R.mipmap.ic_launcher
).setContentIntent(pending).build();
NotificationManager manager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
noti.flags |= Notification.FLAG_AUTO_CANCEL;
manager.notify(0, noti);
}
});
}}
Output:
311120205061 Vishal M
6 )Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
tools:context=".MainActivity">
<ImageView
android:id="@+id/imageView"
android:layout_width="195dp"
android:layout_height="195dp" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image 1" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Image 2" />
</LinearLayout>
MainActivity.java:
package com.example.multithreading;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
ImageView img;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = (Button)findViewById(R.id.button);
b2 = (Button)findViewById(R.id.button2);
img = (ImageView)findViewById(R.id.imageView);
311120205061 Vishal M
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
}
});
}}
public void run() {
img.post(new Runnable() {
@Override
public void run() {
img.setImageResource(R.drawable.sky1);
} }); }
}).start();
} });
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
new Thread(new Runnable() {
@Override
public void run() {
img.post(new Runnable() {
@Override
public void run() {
img.setImageResource(R.drawable.sky2);
} }); } }).start();
Output:
311120205061 Vishal M
311120205061 Vishal M
4 ) Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextTextPersonName5"
android:layout_width="match_parent"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<EditText
android:id="@+id/editTextTextPersonName6"
android:layout_width="match_parent"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Location" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="saveDetails"
android:text="Save" />
<EditText
android:id="@+id/editTextTextPersonName7"
android:layout_width="match_parent"
android:layout_height="48dp"
android:ems="10"
android:inputType="textPersonName"
android:text="Name" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="retrieveDetails"
android:text="Retrieve" />
311120205061 Vishal M
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Display" />
</LinearLayout>
MainActivity.java:
package com.example.myapplication10;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
EditText edName,edLoc,ed;
TextView ans;
String s1,s2;
DBHelper dbh;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edName = findViewById(R.id.editTextTextPersonName5);
edLoc = findViewById(R.id.editTextTextPersonName6);
ed = findViewById(R.id.editTextTextPersonName7);
ans = findViewById(R.id.textView);
dbh = new DBHelper(MainActivity.this);
}
public void saveDetails(View view)
{ s1 =
edName.getText().toString(); s2 =
edLoc.getText().toString();
dbh.savedat(s1,s2);
Toast.makeText(MainActivity.this,"Saved!",Toast.LENGTH_SHORT).show();
}
public void retrieveDetails(View view){
String r1 = ed.getText().toString();
String r2 = dbh.getloc(r1);
ans.setText(r2);
}}
311120205061 Vishal M
DBHelper.java:
package com.example.myapplication10;
import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHelper extends SQLiteOpenHelper {
SQLiteDatabase sqLiteDatabase;
public DBHelper(Context context) {
super(context, "Details.db", null, 1); // db name, version number
sqLiteDatabase=getWritableDatabase();
}
@Override
public void onCreate(SQLiteDatabase db) {
// query for creating table
String qury = "create table Persons (Name text , Location text)";
db.execSQL(qury);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
public long savedat(String s1, String s2) {
ContentValues contentValues = new ContentValues();
contentValues.put("Name",s1);
contentValues.put("Location",s2); // sqlite db
long j = sqLiteDatabase.insert("Persons",null,contentValues);
return j;
}
@SuppressLint("Range")
public String getloc(String name) {
String s;
Cursor c = sqLiteDatabase.query("Persons",null,"Name=?",new String[]{name},null,null,null);
// select * from Persons where Name = name
if(c.getCount()<1) {
return "not exist";
}
c.moveToFirst();
s = c.getString(c.getColumnIndex("Location"));
return s;
}}
311120205061 Vishal M
Output:
311120205061 Vishal M
8 )Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextTextPersonName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textPersonName"
android:text=""
tools:ignore="SpeakableTextPresentCheck" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Read data" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Write data" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Clear" />
</LinearLayout>
MainActivity.java:
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
public class MainActivity extends AppCompatActivity {
EditText e1;
Button r,c,w;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
311120205061 Vishal M
e1=(EditText) findViewById(R.id.editTextTextPersonName);
r=(Button) findViewById(R.id.button);
w=(Button) findViewById(R.id.button2);
c=(Button) findViewById(R.id.button3);
r.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String message;
String buf = "";
try {File f = new File("/sdcard/myfile.txt");
FileInputStream fin = new FileInputStream(f);
BufferedReader br = new BufferedReader(new InputStreamReader(fin));
try {
f.createNewFile();
fout.write(message.getBytes());
fout.close();
Toast.makeText(getBaseContext(),"Data Written in SDCARD",Toast.LENGTH_LONG).show();
} catch (Exception e) {
Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();
} } });
c.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
e1.setText("");
} }); }}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
311120205061 Vishal M
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MYAPP"
tools:targetApi="22">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Output:
Output:
311120205061 Vishal M
11 ) Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/txtTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/txtSub"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Subject"/>
<EditText
android:id="@+id/txtMsg"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="top"
android:hint="Message"/>
<Button
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Send"
android:id="@+id/btnSend"/>
</LinearLayout>
MainActivity.java:
package com.example.mapapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
311120205061 Vishal M
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class MainActivity extends AppCompatActivity
{
private EditText eTo;
private EditText eSubject;
private EditText eMsg;
private Button btn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eTo = (EditText)findViewById(R.id.txtTo);
eSubject = (EditText)findViewById(R.id.txtSub);
eMsg = (EditText)findViewById(R.id.txtMsg);
btn = (Button)findViewById(R.id.btnSend);
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent it = new Intent(Intent.ACTION_SEND);
it.putExtra(Intent.EXTRA_EMAIL, new String[]{eTo.getText().toString()});
it.putExtra(Intent.EXTRA_SUBJECT,eSubject.getText().toString());
it.putExtra(Intent.EXTRA_TEXT,eMsg.getText());
it.setType("message/rfc822");
startActivity(Intent.createChooser(it,"Choose Mail App"));
}
});
}
}
311120205061 Vishal M
Output:
311120205061 Vishal M
7 )Program:
activity.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_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.mygps.MainActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="@+id/button">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/button"
android:gravity="center"
android:text="Coordinates: "
android:textSize="30sp" />
</ScrollView>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Request Location" />
</RelativeLayout>
MainActivity.java:
package com.example.mygps ;
import android.Manifest;
import android.annotation. SuppressLint;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.location. Location;
import android.location.LocationListener;
import android.location.Location Manager;
import android.os.Build;
import android.os.Bundle;
import android.provider.Settings;
311120205061 Vishal M
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
311120205061 Vishal M
public void onRequestPermissions Result(int requestCode, @NonNull String[] permissions,
switch (requestCode) {
case 10:
configure_button();
break;
@NonNull int[] grantResults) {
default:
break;
}
void configure_button() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
requestPermissions(new String[]
{Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission. INTERNET}
}
return;
}
10);
button.setOnClickListener(new View.OnClickListener() {
@SuppressLint("MissingPermission")
@Override
public void onClick(View view) {
locationManager.requestLocationUpdates ("gps", 50000, 0, listener);
}
});
311120205061 Vishal M
Output:
311120205061 Vishal M
9 )Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</LinearLayout>
MainActivity.java:
package com.example.myapplication;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
Button closeButton;
AlertDialog.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
closeButton = (Button) findViewById(R.id.button);
builder = new AlertDialog.Builder(this);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
311120205061 Vishal M
builder.setMessage(R.string.dialog_message)
.setTitle(R.string.dialog_title);
builder.setMessage("Do you want to close this application ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
Toast.makeText(getApplicationContext(),"you choose yes action for alertbox",
Toast.LENGTH_SHORT).show();
} })
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
Toast.makeText(getApplicationContext(),"you choose no action for alertbox",
Toast.LENGTH_SHORT).show();
} });
AlertDialog alert = builder.create();
alert.setTitle("AlertDialogExample");
alert.show();
} }); }}
Output:
311120205061 Vishal M
10 )Program:
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
MainActivity.java:
package com.example.myapplication;
import android.os.Bundle;
import android.app.ListActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends ListActivity {
List headlines;
List links;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
311120205061 Vishal M
new MyAsyncTask().execute();
}
class MyAsyncTask extends AsyncTask<Object,Void,ArrayAdapter> {
@Override
protected ArrayAdapter doInBackground(Object[] params)
{ headlines = new ArrayList();
links = new ArrayList();
try {
URL url = new URL("https://codingconnect.net/feed");
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(false);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput(getInputStream(url), "UTF_8");
boolean insideItem = false;
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{ if (eventType == XmlPullParser.START_TAG) {
if (xpp.getName().equalsIgnoreCase("item")) {
insideItem = true;
}
else if (xpp.getName().equalsIgnoreCase("title"))
{ if (insideItem)
headlines.add(xpp.nextText()); //extract the headline
}
else if (xpp.getName().equalsIgnoreCase("link"))
{ if (insideItem)
links.add(xpp.nextText()); //extract the link of article
}
}
else if(eventType==XmlPullParser.END_TAG &&
xpp.getName().equalsIgnoreCase("item")) {
insideItem=false;
}
eventType = xpp.next(); //move to next element
}
}
catch (MalformedURLException e)
{ e.printStackTrace();
}
catch (XmlPullParserException e) {
e.printStackTrace();
}
catch (IOException e)
{ e.printStackTrace();
}
return null;
311120205061 Vishal M
}
protected void onPostExecute(ArrayAdapter adapter) {
adapter = new ArrayAdapter(MainActivity.this, android.R.layout.simple_list_item_1, headlines);
setListAdapter(adapter);
}
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id)
{ Uri uri = Uri.parse((links.get(position)).toString());
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
public InputStream getInputStream(URL url)
{ try {
return url.openConnection().getInputStream();
}
catch (IOException e)
{ return null;
}
}
}
AndroidManifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/Theme.MyApplication"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
311120205061 Vishal M
Output:
311120205061 Vishal M
12 Program:
Activity_main.xml
<!--title text-->
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="23dp"
android:text="Marshy's XO"
android:textSize="45sp"
android:textStyle="bold"
app:fontFamily="cursive"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="0dp"
android:layout_height="420dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="@+id/imageView"
311120205061 Vishal M
app:layout_constraintEnd_toEndOf="@+id/imageView"
app:layout_constraintStart_toStartOf="@+id/imageView"
app:layout_constraintTop_toTopOf="@+id/imageView">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="1" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="2" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
311120205061 Vishal M
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="3" />
<ImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="4" />
<ImageView
android:id="@+id/imageView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="5" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="6" />
<ImageView
android:id="@+id/imageView7"
311120205061 Vishal M
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="7" />
<ImageView
android:id="@+id/imageView8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:onClick="playerTap"
android:padding="20sp"
android:tag="8" />
</LinearLayout>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.myapplicationd;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
311120205061 Vishal M
public class MainActivity extends AppCompatActivity {
boolean gameActive = true;
int activePlayer = 0;
int[] gameState = {2, 2, 2, 2, 2, 2, 2, 2, 2};
if (!gameActive) {
gameReset(view);
}
if (gameState[tappedImage] == 2) {
counter++;
if (counter == 9) {
gameActive = false;
}
gameState[tappedImage] = activePlayer;
img.setTranslationY(-1000f);
if (activePlayer == 0) {
// set the image of x
img.setImageResource(R.drawable.x);
activePlayer = 1;
TextView status = findViewById(R.id.status);
311120205061 Vishal M
TextView status = findViewById(R.id.status);
status.setText("X's Turn - Tap to play");
}
img.animate().translationYBy(1000f).setDuration(300);
}
int flag = 0;
String winnerStr;
gameActive = false;
if (gameState[winPosition[0]] == 0) {
winnerStr = "X has won";
} else {
winnerStr = "O has won";
}
// Update the status bar for winner announcement
TextView status = findViewById(R.id.status);
status.setText(winnerStr);
}
}
311120205061 Vishal M
((ImageView) findViewById(R.id.imageView6)).setImageResource(0);
((ImageView) findViewById(R.id.imageView7)).setImageResource(0);
((ImageView) findViewById(R.id.imageView8)).setImageResource(0);
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
Output:
311120205061 Vishal M
311120205061 Vishal M