MAD Practical Codes
MAD Practical Codes
2
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World"
android:textSize="24sp"/>
</LinearLayout>
[Link]
M
package [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
}}
.
4 import [Link];
Activity_main.xml import [Link];
<?xml version="1.0" encoding="utf-8"?> import [Link];
<[Link] import [Link];
xmlns:android="[Link] public class MainActivity extends AppCompatActivity {
xmlns:app="[Link] EditText editText;
android:layout_width="match_parent" @Override
android:layout_height="match_parent"> protected void onCreate(Bundle savedInstanceState) {
<!-- TextView --> [Link](savedInstanceState);
<TextView setContentView([Link].activity_main);
android:id="@+id/textView" editText = findViewById([Link]);
android:layout_width="wrap_content" // When user presses Enter key
android:layout_height="wrap_content" [Link](new [Link]()
android:text="enter your name" {
android:textSize="20sp" @Override
app:layout_constraintTop_toTopOf="parent" public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
app:layout_constraintBottom_toTopOf="@+id/editText" if (actionId == EditorInfo.IME_ACTION_DONE ||
app:layout_constraintStart_toStartOf="parent" (event != null && [Link]() == KeyEvent.KEYCODE_ENTER)) {
app:layout_constraintEnd_toEndOf="parent" String name = [Link]().toString();
app:layout_constraintVertical_bias="0.3"/> if ([Link]()) {
<!-- EditText --> [Link]([Link],
<EditText "Please enter your name",
android:id="@+id/editText" Toast.LENGTH_SHORT).show();
android:layout_width="250dp" } else {
android:layout_height="wrap_content" [Link]([Link],
android:hint="type name here" "Hello " + name,
android:inputType="text" Toast.LENGTH_SHORT).show();
app:layout_constraintTop_toBottomOf="@id/textView" }
app:layout_constraintStart_toStartOf="parent" return true;
app:layout_constraintEnd_toEndOf="parent"/> }
</[Link]> return false;
}
[Link]
M });
package [Link]; }
import [Link]; }
import [Link];
import [Link];
ndroid:layout_width="wrap_content"
a
.
5 android:layout_height="wrap_content"
Activity_main.xml android:text="submit"
<?xml version="1.0" encoding="utf-8"?> app:layout_constraintTop_toBottomOf="@id/toggleButton"
<[Link] app:layout_constraintStart_toStartOf="parent"
xmlns:android="[Link] app:layout_constraintEnd_toEndOf="parent"
xmlns:app="[Link] app:layout_constraintVertical_bias="0.1"/>
android:layout_width="match_parent"
android:layout_height="match_parent"> </[Link]>
[Link](new [Link]() {
@Override
public void onClick(View v) {
progressStatus = 0;
[Link](new Runnable() {
@Override
public void run() {
[Link](progressStatus);
}
});
try {
[Link](200);
} catch (InterruptedException e) {
[Link]();
}
}
}
}).start();
}
});
}
}
<EditText
.
8 android:id="@+id/password"
Activity_main.xml android:layout_width="250dp"
android:layout_height="wrap_content"
?xml version="1.0" encoding="utf-8"?>
< android:hint="password"
<[Link] android:inputType="textPassword"
xmlns:android="[Link] app:layout_constraintTop_toBottomOf="@id/username"
xmlns:app="[Link] app:layout_constraintStart_toStartOf="parent"
android:layout_width="match_parent" app:layout_constraintEnd_toEndOf="parent"/>
android:layout_height="match_parent">
!-- Remember Me -->
<
!-- Title -->
< <CheckBox
<TextView android:id="@+id/checkBox"
android:id="@+id/title" android:layout_width="wrap_content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Remember me"
android:text="login" app:layout_constraintTop_toBottomOf="@id/password"
android:textSize="24sp" app:layout_constraintStart_toStartOf="@id/password"/>
android:textStyle="bold"
app:layout_constraintTop_toTopOf="parent" !-- Login As Text -->
<
app:layout_constraintStart_toStartOf="parent" <TextView
app:layout_constraintEnd_toEndOf="parent" android:id="@+id/loginAs"
app:layout_constraintVertical_bias="0.1"/> android:layout_width="wrap_content"
android:layout_height="wrap_content"
!-- Username -->
< android:text="Login as"
<EditText app:layout_constraintTop_toBottomOf="@id/checkBox"
android:id="@+id/username" app:layout_constraintStart_toStartOf="@id/password"/>
android:layout_width="250dp"
android:layout_height="wrap_content" !-- Radio Group -->
<
android:hint="username" <RadioGroup
android:inputType="text" android:id="@+id/radioGroup"
app:layout_constraintTop_toBottomOf="@id/title" android:layout_width="wrap_content"
app:layout_constraintStart_toStartOf="parent" android:layout_height="wrap_content"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintTop_toBottomOf="@id/loginAs"
app:layout_constraintVertical_bias="0.1"/> app:layout_constraintStart_toStartOf="@id/password">
<RadioButton Override
@
android:id="@+id/user" protected void onCreate(Bundle savedInstanceState) {
android:layout_width="wrap_content" [Link](savedInstanceState);
android:layout_height="wrap_content" setContentView([Link].activity_main);
android:text="user"/>
/RadioGroup>
< sername = findViewById([Link]);
u
password = findViewById([Link]);
!-- Submit Button -->
< checkBox = findViewById([Link]);
<Button radioGroup = findViewById([Link]);
android:id="@+id/submit" submit = findViewById([Link]);
android:layout_width="wrap_content"
android:layout_height="wrap_content" [Link](new [Link]() {
android:text=""Submit" @Override
app:layout_constraintTop_toBottomOf="@id/radioGroup" public void onClick(View v) {
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent" tring user = [Link]().toString();
S
app:layout_constraintVertical_bias="0.2"/> String pass = [Link]().toString();
if ([Link]()) {
message += "\nRemembered";
}
[Link]([Link],
message,
Toast.LENGTH_LONG).show();
}
}
});
}
}
android:layout_marginBottom="15dp"/>
.
9
Activity_main.xml !-- Password -->
<
<EditText
?xml version="1.0" encoding="utf-8"?>
< android:id="@+id/editPassword"
<LinearLayout android:layout_width="match_parent"
xmlns:android="[Link] android:layout_height="wrap_content"
android:layout_width="match_parent" android:hint="Enter Password"
android:layout_height="match_parent" android:inputType="textPassword"
android:orientation="vertical" android:layout_marginBottom="20dp"/>
android:padding="24dp"
android:gravity="center"> !-- Register Button -->
<
<Button
!-- Title -->
< android:id="@+id/registerBtn"
<TextView android:layout_width="match_parent"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Register"/>
android:text="Registration Form"
android:textSize="22sp" </LinearLayout>
android:textStyle="bold"
android:layout_marginBottom="20dp"/> [Link]
ame = findViewById([Link]);
n
email = findViewById([Link]);
password = findViewById([Link]);
registerBtn = findViewById([Link]);
[Link](new [Link]() {
@Override
public void onClick(View v) {
Override
@ Override
@
protected void onCreate(Bundle savedInstanceState) { public View getView(int position, View convertView, ViewGroup
[Link](savedInstanceState); parent) {
setContentView([Link].activity_main);
ImageView imageView = new ImageView([Link]);
// ListView Implementation [Link](images[position]);
ListView listView = findViewById([Link]);
[Link](new [Link](300,
300));
[Link]([Link].CENTER_CROP);
return imageView;
}
}
}
2.
1 Button android:text="3"/>
<
Activity_main.xml <Button android:text="-"/>
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="[Link] !-- Row 4 -->
<
android:layout_width="match_parent" <Button android:text="0"/>
android:layout_height="match_parent" <Button android:text="C"/>
android:columnCount="4" <Button android:text="="/>
android:rowCount="6" <Button android:text="+"/>
android:padding="10dp">
</GridLayout>
!-- Display Screen -->
<
<EditText [Link]
M
android:id="@+id/display" package [Link];
android:layout_width="match_parent"
android:layout_height="80dp" import [Link];
android:layout_columnSpan="4" import [Link];
android:gravity="end" import [Link];
android:textSize="28sp" import [Link];
android:background="@android:color/darker_gray"
android:enabled="false" import [Link];
android:padding="10dp"/>
public class MainActivity extends AppCompatActivity {
!-- Row 1 -->
<
<Button android:text="7"/> ditText display;
E
<Button android:text="8"/> String currentInput = "";
<Button android:text="9"/>
<Button android:text="/"/> Override
@
protected void onCreate(Bundle savedInstanceState) {
!-- Row 2 -->
< [Link](savedInstanceState);
<Button android:text="4"/> setContentView([Link].activity_main);
<Button android:text="5"/>
<Button android:text="6"/> display = findViewById([Link]);
<Button android:text="*"/>
// Set Click Listener for All Buttons
!-- Row 3 -->
< for (int i = 0; i <
<Button android:text="1"/> ((ViewGroup)findViewById([Link])).getChildCount(); i++) {
<Button android:text="2"/>
View view = }
((ViewGroup)findViewById([Link])).getChildAt(i); else if ([Link]("=")) {
} try {
double result = evaluateExpression(currentInput);
int childCount = [Link]([Link](result));
((GridLayout)findViewById([Link]).getRootView() currentInput = [Link](result);
.findViewById([Link])).getChildCount(); } catch (Exception e) {
[Link]("Error");
// Manual approach for clarity (recommended for practical) }
setButtonClickListeners(); }
} else {
currentInput += value;
private void setButtonClickListeners() { [Link](currentInput);
}
int gridChildCount = (([Link]) });
findViewById([Link]) }
.getRootView() }
.findViewById([Link])).getChildCount(); }
return 0;
}
}
3.
1 ndroid:orientation="vertical"
a
Activity_main.xml android:gravity="center"
<?xml version="1.0" encoding="utf-8"?> android:visibility="gone">
<FrameLayout
xmlns:android="[Link] <TextView
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent"> android:layout_height="wrap_content"
android:text="Welcome to the Application"
!-- Splash Layout -->
< android:textSize="22sp"
<LinearLayout android:textStyle="bold"/>
android:id="@+id/splashLayout"
android:layout_width="match_parent" </LinearLayout>
android:layout_height="match_parent"
android:orientation="vertical" </FrameLayout>
android:gravity="center"
android:background="#3F51B5"> [Link]
M
package [Link];
<ImageView
android:layout_width="150dp" import [Link];
android:layout_height="150dp" import [Link];
android:src="@drawable/ic_launcher_foreground" import [Link];
android:layout_marginBottom="20dp"/> import [Link];
import [Link];
<TextView
android:layout_width="wrap_content" import [Link];
android:layout_height="wrap_content"
android:text="Library Management App" public class MainActivity extends AppCompatActivity {
android:textSize="22sp"
android:textColor="#FFFFFF" private static final int SPLASH_TIME = 3000; // 3 seconds
android:textStyle="bold"/>
/LinearLayout>
< Override
@
protected void onCreate(Bundle savedInstanceState) {
!-- Main Content Layout (Initially Hidden) -->
< [Link](savedInstanceState);
<LinearLayout setContentView([Link].activity_main);
android:id="@+id/mainLayout"
android:layout_width="match_parent" inearLayout splashLayout = findViewById([Link]);
L
android:layout_height="match_parent" LinearLayout mainLayout = findViewById([Link]);
// Delay for splash screen
new Handler([Link]()).postDelayed(() -> {
[Link]([Link]);
s
[Link]([Link]);
}, SPLASH_TIME);
}
}
4.
1 ndroid:layout_height="wrap_content"
a
Activity_main.xml android:text="Fahrenheit to Celsius"
<?xml version="1.0" encoding="utf-8"?> android:layout_marginBottom="15dp"/>
<LinearLayout
xmlns:android="[Link] <TextView
android:layout_width="match_parent" android:id="@+id/resultText"
android:layout_height="match_parent" android:layout_width="wrap_content"
android:orientation="vertical" android:layout_height="wrap_content"
android:padding="20dp" android:text="Result:"
android:gravity="center"> android:textSize="18sp"
android:textStyle="bold"/>
<TextView
android:layout_width="wrap_content" </LinearLayout>
android:layout_height="wrap_content"
android:text="Temperature Converter" [Link]
M
android:textSize="22sp" package [Link];
android:textStyle="bold"
android:layout_marginBottom="20dp"/> import [Link];
import [Link];
<EditText import [Link];
android:id="@+id/inputTemp" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="wrap_content" import [Link];
android:hint="Enter Temperature"
android:inputType="numberDecimal" import [Link];
android:layout_marginBottom="15dp"/>
public class MainActivity extends AppCompatActivity {
<Button
android:id="@+id/btnCtoF" ditText inputTemp;
E
android:layout_width="match_parent" Button btnCtoF, btnFtoC;
android:layout_height="wrap_content" TextView resultText;
android:text="Celsius to Fahrenheit"
android:layout_marginBottom="10dp"/> Override
@
protected void onCreate(Bundle savedInstanceState) {
<Button [Link](savedInstanceState);
android:id="@+id/btnFtoC" setContentView([Link].activity_main);
android:layout_width="match_parent"
inputTemp = findViewById([Link]);
btnCtoF = findViewById([Link]); [Link]("Result: " + celsius + " °C");
btnFtoC = findViewById([Link]); }
resultText = findViewById([Link]); }
if ([Link]()) {
[Link](this, "Please enter temperature",
Toast.LENGTH_SHORT).show();
return;
}
if ([Link]()) {
[Link](this, "Please enter temperature",
Toast.LENGTH_SHORT).show();
return;
}
if ([Link]()) {
[Link](this, "Enter time in seconds",
Toast.LENGTH_SHORT).show();
return;
}
Override
@
public void onTick(long millisUntilFinished) {
long secondsRemaining = millisUntilFinished / 1000;
[Link]([Link](secondsRemaining));
}
Override
@
public void onFinish() {
[Link]("Done!");
}
}.start();
6.
1 [Link]
M
Activity_main.xml package [Link];
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout import [Link];
xmlns:android="[Link] import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical"
android:gravity="center" import [Link];
android:padding="20dp">
import [Link];
<TextView
android:layout_width="wrap_content" public class MainActivity extends AppCompatActivity {
android:layout_height="wrap_content"
android:text="Date Picker Application" ditText editTextDate;
E
android:textSize="22sp" Button btnPickDate;
android:textStyle="bold"
android:layout_marginBottom="20dp"/> Override
@
protected void onCreate(Bundle savedInstanceState) {
<EditText [Link](savedInstanceState);
android:id="@+id/editTextDate" setContentView([Link].activity_main);
android:layout_width="match_parent"
android:layout_height="wrap_content" ditTextDate = findViewById([Link]);
e
android:hint="Select Date" btnPickDate = findViewById([Link]);
android:focusable="false"
android:clickable="true" [Link](v -> showDatePicker());
android:layout_marginBottom="20dp"/>
// Also open picker when EditText is clicked
<Button [Link](v -> showDatePicker());
android:id="@+id/btnPickDate" }
android:layout_width="match_parent"
android:layout_height="wrap_content" private void showDatePicker() {
android:text="Pick Date"/>
Calendar calendar = [Link]();
</LinearLayout>
int year = [Link]([Link]);
int month = [Link]([Link]);
int day = [Link](Calendar.DAY_OF_MONTH);
[Link]();
}
}
7.
1 [Link]
M
Activity_main.xml package [Link];
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout import [Link];
xmlns:android="[Link] import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical"
android:gravity="center" import [Link];
android:padding="20dp">
import [Link];
<TextView
android:layout_width="wrap_content" public class MainActivity extends AppCompatActivity {
android:layout_height="wrap_content"
android:text="Time Picker Application" ditText editTextTime;
E
android:textSize="22sp" Button btnPickTime;
android:textStyle="bold"
android:layout_marginBottom="20dp"/> Override
@
protected void onCreate(Bundle savedInstanceState) {
<EditText [Link](savedInstanceState);
android:id="@+id/editTextTime" setContentView([Link].activity_main);
android:layout_width="match_parent"
android:layout_height="wrap_content" ditTextTime = findViewById([Link]);
e
android:hint="Select Time" btnPickTime = findViewById([Link]);
android:focusable="false"
android:clickable="true" [Link](v -> showTimePicker());
b
android:layout_marginBottom="20dp"/> [Link](v -> showTimePicker());
}
<Button
android:id="@+id/btnPickTime" private void showTimePicker() {
android:layout_width="match_parent"
android:layout_height="wrap_content" Calendar calendar = [Link]();
android:text="Pick Time"/>
int hour = [Link](Calendar.HOUR_OF_DAY);
</LinearLayout> int minute = [Link]([Link]);
[Link](formattedTime);
} ,
hour,
minute,
true // true = 24-hour format
);
[Link]();
}
}
8.
1 ndroid:layout_height="wrap_content"
a
Activity_main.xml android:text="Login"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout </LinearLayout>
xmlns:android="[Link]
android:layout_width="match_parent" [Link]
M
android:layout_height="match_parent" package [Link];
android:orientation="vertical"
android:gravity="center" import [Link];
android:padding="20dp"> import [Link];
import [Link];
<TextView import [Link];
android:layout_width="wrap_content" import [Link];
android:layout_height="wrap_content" import [Link];
android:text="Login Application"
android:textSize="22sp" import [Link];
android:textStyle="bold"
android:layout_marginBottom="20dp"/> /* ---------------------- */
/* Activity 1 : Login */
<EditText /* ---------------------- */
android:id="@+id/username" public class MainActivity extends AppCompatActivity {
android:layout_width="match_parent"
android:layout_height="wrap_content" ditText username, password;
E
android:hint="Enter Username" Button btnLogin;
android:layout_marginBottom="15dp"/>
Override
@
<EditText protected void onCreate(Bundle savedInstanceState) {
android:id="@+id/password" [Link](savedInstanceState);
android:layout_width="match_parent" setContentView([Link].activity_main);
android:layout_height="wrap_content"
android:hint="Enter Password" sername = findViewById([Link]);
u
android:inputType="textPassword" password = findViewById([Link]);
android:layout_marginBottom="20dp"/> btnLogin = findViewById([Link]);
} else {
[Link](this, "Invalid Credentials",
Toast.LENGTH_SHORT).show();
}
});
}
}
Override
@
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView(textView);
}
}
9.
1 [Link]
M
Activity_main.xml package [Link];
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout import [Link];
xmlns:android="[Link] import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical" import [Link];
android:gravity="center"
android:padding="20dp"> import [Link];
Override
@
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView(textView);
}
}
0.
2 android:text="Turn OFF Bluetooth"/>
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?> </LinearLayout>
<LinearLayout
xmlns:android="[Link] [Link]
M
android:layout_width="match_parent" package [Link];
android:layout_height="match_parent"
android:orientation="vertical" import [Link];
android:gravity="center" import [Link];
android:padding="20dp"> import [Link];
import [Link];
<TextView import [Link];
android:layout_width="wrap_content"
android:layout_height="wrap_content" import [Link];
android:text="Bluetooth Service Application"
android:textSize="22sp" public class MainActivity extends AppCompatActivity {
android:textStyle="bold"
android:layout_marginBottom="30dp"/> luetoothAdapter bluetoothAdapter;
B
Button btnStatus, btnOn, btnOff;
<Button
android:id="@+id/btnStatus" Override
@
android:layout_width="match_parent" protected void onCreate(Bundle savedInstanceState) {
android:layout_height="wrap_content" [Link](savedInstanceState);
android:text="Check Bluetooth Status" setContentView([Link].activity_main);
android:layout_marginBottom="15dp"/>
bluetoothAdapter = [Link]();
<Button
android:id="@+id/btnOn" tnStatus = findViewById([Link]);
b
android:layout_width="match_parent" btnOn = findViewById([Link]);
android:layout_height="wrap_content" btnOff = findViewById([Link]);
android:text="Turn ON Bluetooth"
android:layout_marginBottom="15dp"/> [Link](v -> checkStatus());
b
[Link](v -> turnOnBluetooth());
<Button [Link](v -> turnOffBluetooth());
android:id="@+id/btnOff" }
android:layout_width="match_parent"
android:layout_height="wrap_content" private void checkStatus() {
[Link](this, "Bluetooth turned OFF",
if (bluetoothAdapter == null) { Toast.LENGTH_SHORT).show();
[Link](this, "Bluetooth not supported", } else {
Toast.LENGTH_SHORT).show(); [Link](this, "Bluetooth already OFF",
} Toast.LENGTH_SHORT).show();
else if ([Link]()) { }
[Link](this, "Bluetooth is ON", }
Toast.LENGTH_SHORT).show(); }
}
else {
[Link](this, "Bluetooth is OFF",
Toast.LENGTH_SHORT).show();
}
}
if (![Link]()) {
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivity(intent);
} else {
[Link](this, "Bluetooth already ON",
Toast.LENGTH_SHORT).show();
}
}
if (isOn) {
[Link]("Airplane Mode ON");
} else {
[Link]("Airplane Mode OFF");
}
}
if
(AudioManager.RINGER_MODE_CHANGED_ACTION.equals([Link]
tion())) {
AudioManager audioManager =
(AudioManager)
getSystemService(Context.AUDIO_SERVICE);
<EditText [Link]
M
android:id="@+id/etName" package [Link];
android:layout_width="match_parent"
android:layout_height="wrap_content" import [Link];
android:hint="Enter Name"/> import [Link];
import [Link];
<EditText import [Link];
android:id="@+id/etEmail" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="wrap_content" import [Link].*;
android:hint="Enter Email"
android:layout_marginTop="10dp"/> import [Link];
QLiteDatabase db = [Link]();
S
ContentValues values = new ContentValues();
[Link]("name", name);
[Link]("email", email);
QLiteDatabase db = [Link]();
S
return [Link]("SELECT * FROM " + TABLE_NAME, null);
}
}
}
3.
2 ndroid:layout_width="match_parent"
a
Activity_main.xml android:layout_height="wrap_content"
<?xml version="1.0" encoding="utf-8"?> android:text="Register"
<ScrollView xmlns:android="[Link] android:layout_marginTop="15dp"/>
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/btnLogin"
<LinearLayout android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Login"
android:orientation="vertical" android:layout_marginTop="10dp"/>
android:padding="20dp">
<TextView
<TextView android:id="@+id/tvResult"
android:layout_width="wrap_content" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="User Authentication" android:textSize="16sp"
android:textSize="22sp" android:layout_marginTop="20dp"/>
android:textStyle="bold"
android:layout_marginBottom="20dp"/> </LinearLayout>
</ScrollView>
<EditText
android:id="@+id/etUsername" [Link]
M
android:layout_width="match_parent" package [Link];
android:layout_height="wrap_content"
android:hint="Enter Username"/> import [Link];
import [Link];
<EditText import [Link];
android:id="@+id/etPassword" import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="wrap_content" import [Link].*;
android:hint="Enter Password"
android:inputType="textPassword" import [Link];
android:layout_marginTop="10dp"/>
public class MainActivity extends AppCompatActivity {
<Button
android:id="@+id/btnRegister" EditText etUsername, etPassword;
utton btnRegister, btnLogin;
B }
TextView tvResult;
DBHelper dbHelper; private void loginUser() {
Override
@ tring username = [Link]().toString();
S
protected void onCreate(Bundle savedInstanceState) { String password = [Link]().toString();
[Link](savedInstanceState);
setContentView([Link].activity_main); boolean valid = [Link](username, password);
tUsername = findViewById([Link]);
e if(valid)
etPassword = findViewById([Link]); [Link]("Login Successful");
btnRegister = findViewById([Link]); else
btnLogin = findViewById([Link]); [Link]("Invalid Username or Password");
tvResult = findViewById([Link]); }
QLiteDatabase db = [Link]();
S
ContentValues values = new ContentValues();
[Link]("username", username);
[Link]("password", password);
SQLiteDatabase db = [Link]();
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:inputType="phone"
android:layout_marginTop="10dp"/>
<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Contact"
android:layout_marginTop="15dp"/>
<Button
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View Contacts"
android:layout_marginTop="10dp"/>
<TextView
android:id="@+id/tvResult"
android:layout_width="match_parent"
android:layout_height="wrap_content"
5.
2 import [Link];
Activity_main.xml import [Link];
<?xml version="1.0" encoding="utf-8"?> import [Link];
<LinearLayout import [Link];
xmlns:android="[Link] import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical" import [Link];
android:gravity="center" import [Link];
android:padding="20dp">
import [Link];
<TextView import [Link];
android:layout_width="wrap_content" import [Link];
android:layout_height="wrap_content" import [Link];
android:text="Camera Application"
android:textSize="22sp" public class MainActivity extends AppCompatActivity {
android:textStyle="bold"
android:layout_marginBottom="20dp"/> rivate static final int CAMERA_REQUEST = 100;
p
private static final int CAMERA_PERMISSION_CODE = 101;
<ImageView
android:id="@+id/imageView" ImageView imageView;
android:layout_width="250dp" Button btnCamera;
android:layout_height="250dp"
android:background="@android:color/darker_gray" Override
@
android:layout_marginBottom="20dp"/> protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
<Button setContentView([Link].activity_main);
android:id="@+id/btnCamera"
android:layout_width="match_parent" imageView = findViewById([Link]);
android:layout_height="wrap_content" btnCamera = findViewById([Link]);
android:text="Open Camera"/>
[Link](v -> {
</LinearLayout>
if ([Link](this,
[Link]
M [Link])
package [Link]; != PackageManager.PERMISSION_GRANTED) {
[Link](this, & [Link] > 0
&
new String[]{[Link]}, && grantResults[0] ==
CAMERA_PERMISSION_CODE); PackageManager.PERMISSION_GRANTED) {
} else {
openCamera(); penCamera();
o
} } else {
}); [Link](this,
} "Camera Permission Denied",
Toast.LENGTH_SHORT).show();
private void openCamera() { }
Intent cameraIntent = new }
Intent(MediaStore.ACTION_IMAGE_CAPTURE); }
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
Override
@
protected void onActivityResult(int requestCode,
int resultCode,
@Nullable Intent data) {
[Link](requestCode, resultCode, data);
Override
@
public void onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) {
[Link](requestCode,
permissions, grantResults);
<EditText <TextView
android:id="@+id/etNumber" android:layout_width="wrap_content"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="SMS Application"
android:hint="Enter Mobile Number" android:textSize="22sp"
android:inputType="phone"/> android:textStyle="bold"
android:layout_marginBottom="20dp"/>
<EditText
android:id="@+id/etMessage" <EditText
android:layout_width="match_parent" android:id="@+id/etNumber"
android:layout_height="wrap_content" android:layout_width="match_parent"
android:hint="Enter Message" android:layout_height="wrap_content"
android:layout_marginTop="10dp" android:hint="Enter Mobile Number"
android:inputType="textMultiLine"/> android:inputType="phone"/>
<Button <EditText
ndroid:id="@+id/etMessage"
a
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:layout_marginTop="10dp"
android:inputType="textMultiLine"/>
<Button
android:id="@+id/btnSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_marginTop="15dp"/>
</LinearLayout>
</ScrollView>
7.
2 ndroid:layout_height="wrap_content"
a
Activity_main.xml android:hint="Message"
<?xml version="1.0" encoding="utf-8"?> android:layout_marginTop="10dp"
<ScrollView xmlns:android="[Link] android:inputType="textMultiLine"/>
android:layout_width="match_parent"
android:layout_height="match_parent"> <Button
android:id="@+id/btnSend"
<LinearLayout android:layout_width="match_parent"
android:layout_width="match_parent" android:layout_height="wrap_content"
android:layout_height="wrap_content" android:text="Send Email"
android:orientation="vertical" android:layout_marginTop="15dp"/>
android:padding="20dp">
/LinearLayout>
<
<TextView /ScrollView>
<
android:layout_width="wrap_content"
android:layout_height="wrap_content" [Link]
M
android:text="Email Application" package [Link];
android:textSize="22sp"
android:textStyle="bold" import [Link];
android:layout_marginBottom="20dp"/> import [Link];
import [Link];
<EditText import [Link];
android:id="@+id/etTo" import [Link];
android:layout_width="match_parent"
android:layout_height="wrap_content" import [Link];
android:hint="Recipient Email"/>
public class MainActivity extends AppCompatActivity {
<EditText
android:id="@+id/etSubject" ditText etTo, etSubject, etMessage;
E
android:layout_width="match_parent" Button btnSend;
android:layout_height="wrap_content"
android:hint="Subject" Override
@
android:layout_marginTop="10dp"/> protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
<EditText setContentView([Link].activity_main);
android:id="@+id/etMessage"
android:layout_width="match_parent" etTo = findViewById([Link]);
tSubject = findViewById([Link]);
e
etMessage = findViewById([Link]);
btnSend = findViewById([Link]);
tring to = [Link]().toString();
S
String subject = [Link]().toString();
String message = [Link]().toString();
try {
startActivity([Link](intent, "Send Email"));
} catch (Exception e) {
[Link](this,
"No Email App Found",
Toast.LENGTH_SHORT).show();
}
}
}
8.
2
Activity_main.xml import [Link];
<?xml version="1.0" encoding="utf-8"?> import [Link];
<LinearLayout import [Link];
xmlns:android="[Link] import [Link];
android:layout_width="match_parent" import [Link];
android:layout_height="match_parent" import [Link];
android:orientation="vertical" import [Link];
android:gravity="center" import [Link];
android:padding="20dp"> import [Link];
[Link]
M [Link](v -> checkPermission());
package [Link]; }
}
private void checkPermission() { });
}
if ([Link](this,
[Link].ACCESS_FINE_LOCATION) Override
@
!= PackageManager.PERMISSION_GRANTED) { public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
[Link](this, @NonNull int[] grantResults) {
new
String[]{[Link].ACCESS_FINE_LOCATION}, [Link](requestCode,
LOCATION_PERMISSION_CODE); permissions, grantResults);
} else {
getLocation(); if (requestCode == LOCATION_PERMISSION_CODE
} && [Link] > 0
} && grantResults[0] ==
ackageManager.PERMISSION_GRANTED) {
P
private void getLocation() {
getLocation();
if ([Link](this, } else {
[Link].ACCESS_FINE_LOCATION) [Link](this,
!= PackageManager.PERMISSION_GRANTED) { "Location Permission Denied",
return; Toast.LENGTH_SHORT).show();
} }
}
[Link]( }
LocationManager.GPS_PROVIDER,
0,
0,
new LocationListener() {
@Override
public void onLocationChanged(@NonNull Location location) {
[Link]
A import [Link];
package [Link];
import [Link];
import [Link];
import [Link]; public class MainActivity extends AppCompatActivity {
import [Link];
import [Link]; rawerLayout drawerLayout;
D
import [Link]; NavigationView navigationView;
Toolbar toolbar;
import [Link];
Override
@
public class AboutFragment extends Fragment { protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
Override
@ setContentView([Link].activity_main);
public View onCreateView(LayoutInflater inflater,
ViewGroup container, rawerLayout = findViewById([Link]);
d
Bundle savedInstanceState) { navigationView = findViewById([Link]);
toolbar = findViewById([Link]);
extView textView = new TextView(getContext());
T
[Link]("About Fragment"); setSupportActionBar(toolbar);
[Link](22);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
return textView; this, drawerLayout, toolbar,
} [Link], [Link]);
}
[Link](toggle);
d
[Link]
M [Link]();
package [Link];
loadFragment(new HomeFragment());
import [Link];
import [Link]; [Link](item -> {
Fragment selectedFragment = null;
[Link]();
d
return true;
});
}
Override
@
public void onRequestPermissionsResult(int requestCode,
String[] permissions,
int[] grantResults) {
[Link](requestCode,
permissions, grantResults);