MAD - RECORD 1-12 Program
MAD - RECORD 1-12 Program
MAD - RECORD 1-12 Program
activity_main.xml :
1
MainActivity.java :
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
EditText i1,i2,i3;
TextView opTxt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
i1 = findViewById(R.id.i1);
i2 = findViewById(R.id.i2);
i3 = findViewById(R.id.i3);
opTxt = findViewById(R.id.outputTxt);
}
public void findMax(View v)
{
int x,y,z,max;
x = Integer.parseInt(i1.getText().toString());
y = Integer.parseInt(i2.getText().toString());
z = Integer.parseInt(i3.getText().toString());
max = Math.max(x,y);
max = Math.max(max,z);
opTxt.setText("Max: "+max+"");
}
}
2
Output :
3
PERSONAL DETAILS
activity_main.xml :
4
Output :
5
RADIO BUTTON
activity_main.xml :
6
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
RadioGroup rG;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rG = findViewById(R.id.rGroup);
}
public void submitClick(View v)
{
int selectedId = rG.getCheckedRadioButtonId();
RadioButton rB = findViewById(selectedId);
Toast.makeText(this,"You are a "+rB.getText().toString()+"",Toast.LENGTH_SHORT).show();
}
}
7
Output :
8
IMAGE BUTTON
activity_main.xml :
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/dog"
android:layout_weight="5"
android:onClick="imageClick"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Click the image above"
android:textSize="20sp"
android:layout_weight="5"
android:layout_gravity="center"/>
</LinearLayout>
9
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void imageClick(View v)
{
Toast.makeText(this,"Dog : Woof! Woof!",Toast.LENGTH_SHORT).show();
}
}
10
Output :
11
ALERT DIALOG BOX
activity_main.xml :
12
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void buttonPressed(View v)
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Dialog").setMessage("This is a basic dialog box. ");
builder.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
dialogInterface.dismiss();
}
});
AlertDialog dialog = builder.create();
dialog.show();
}
}
13
Output :
14
LAYOUT MANAGERS
activity_main.xml :
15
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
LinearLayout linearLayout = findViewById(R.id.linearLayout);
Button button1 = new Button(this);
button1.setText("Button 1");
Button button2 = new Button(this);
button2.setText("Button 2");
linearLayout.addView(button1);
linearLayout.addView(button2);
}
}
16
Output :
17
AUDIO MODE
AndroidManifest.xml :
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AudioModeApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
18
activity_main.xml :
19
MainActivity.java :
package com.example.audiomodeapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
AudioManager audioManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
}
public void normalMode(View view)
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_NORMAL);
Toast.makeText(this,"Normal mode activated",Toast.LENGTH_SHORT).show();
}
public void silentMode(View view)
{
// audioManager.setRingerMode(AudioManager.RINGER_MODE_SILENT); Note:silent mode won't work.
Toast.makeText(this,"Silent mode activated",Toast.LENGTH_SHORT).show();}
public void vibrateMode(View view)
{
audioManager.setRingerMode(AudioManager.RINGER_MODE_VIBRATE);
Toast.makeText(this,"Vibrate mode activated",Toast.LENGTH_SHORT).show();
}
}
20
Output :
21
SMS
AndroidManifest.xml :
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.SmsApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
22
activity_main.xml :
<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="phone"
android:hint="Phone Number"/>
<EditText
android:id="@+id/msg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Message" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEND"
android:onClick="sendSMS"/>
</LinearLayout>
23
MainActivity.java :
package com.example.smsapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
24
Output :
25
SEND EMAIL
AndroidManifest.xml :
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
26
activity_main.xml :
<EditText
android:id="@+id/emailText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textEmailAddress"
android:hint="Mail to :"/>
<EditText
android:id="@+id/subjectText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Subject"/>
<EditText
android:id="@+id/bodyText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="textMultiLine"
android:hint="Body"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="SEND"
android:onClick="sendMail"/>
</LinearLayout>
27
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
28
Output :
29
MOBILE CALL
AndroidManifest.xml :
<!--add here-->
<uses-permission android:name="android.permission.CALL_PHONE"/>
<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:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyApp"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
30
activity_main.xml :
31
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
EditText phoneText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneText = findViewById(R.id.phoneText);
}
32
Output :
33
STUDENT MARK SHEET PROCESSING
activity_main.xml :
35
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
}
public void calculate(View v)
{
String name = nameTxt.getText().toString();
int mark1,mark2,mark3,mark4,totalMark;
mark1 = Integer.parseInt(sub1.getText().toString());
mark2 = Integer.parseInt(sub2.getText().toString());
mark3 = Integer.parseInt(sub3.getText().toString());
mark4 = Integer.parseInt(sub4.getText().toString());
totalMark = mark1+mark2+mark3+mark4;
double percentage = (totalMark/4)*100;
resultOp.setText("\nResult :\nName : "+name+"\nTotal Marks : "+totalMark+"/400\nTotal percentage :
"+percentage+"%\n");
}
}
36
Output :
37
LOGIN PAGE IN DATABASE
activity_main.xml :
<EditText
android:id="@+id/userName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="User Name" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
android:hint="Password"
android:password="true"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="LOGIN"
android:onClick="login"/>
</LinearLayout>
38
MainActivity.java :
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
39
Output :
40