output part 1 - Google Docs
output part 1 - Google Docs
age: 66
P
JAVA CODE:
package com.example.circularprogressbar;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rogressBar = findViewById(R.id.progressBar);
p
progressText = findViewById(R.id.progressText);
XML CODE:
_________________________________________________________________________
_________________________________________________________________________
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp" >
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
style="?android:attr/progressBarStyleLarge"
android:max="100"/>
<TextView
android:id="@+id/progressText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0%"
android:textSize="20sp"
android:layout_centerInParent="true"/>
</RelativeLayout>
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
Page: 91
J AVA CODE:
package com.example.demo;
import android.os.Bundle;
import android.util.Log;
import androidx.appcompat.app.AppCompatActivity;
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d(TAG, "onCreate: Activity is being created");
}
Override
@
protected void onStart() {
super.onStart();
Log.d(TAG, "onStart: Activity is becoming visible");
}
Override
@
protected void onResume() {
super.onResume();
Log.d(TAG, "onResume: Activity is now interactive");
}
Override
@
protected void onPause() {
super.onPause();
Log.d(TAG, "onPause: Activity is partially obscured");
}
Override
@
protected void onStop() {
super.onStop();
Log.d(TAG, "onStop: Activity is no longer visible");
}
Override
@
protected void onRestart() {
super.onRestart();
Log.d(TAG, "onRestart: Activity is restarting");
}
Override
@
protected void onDestroy() {
super.onDestroy();
_________________________________________________________________________
_________________________________________________________________________
ML CODE:
X
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:layout_gravity="center"
android:layout_marginTop="16dp" />
</LinearLayout>
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
Page: 38
JAVA CODE:
ackage com.example.demo;
p
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a list of initial suggestions (replace with your actual data)
suggestionList = new ArrayList<>();
suggestionList.add("Java Programming");
suggestionList.add("Android Development");
suggestionList.add("Python for Data Science");
suggestionList.add("Web Development Tutorial");
suggestionList.add("Machine Learning Basics");
suggestionList.add("Artificial Intelligence Course");
suggestionList.add("Mobile App Design");
suggestionList.add("Database Management Systems");
suggestionList.add("Competitive Programming");
// You can optionally set a threshold for when suggestions start appearing
// Default is 1, meaning suggestions appear after the first character is typed.
// searchAutoCompleteTextView.setThreshold(2);
} }
ML CODE:
X
_________________________________________________________________________
_________________________________________________________________________
x mlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search Engine"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp" />
<AutoCompleteTextView
android:id="@+id/searchAutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter your search query"
android:completionThreshold="1" />
</LinearLayout>
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
Page: 39
J AVA CODE:
package com.example.demo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import java.util.ArrayList;
import java.util.List;
public class MainActivity extends AppCompatActivity {
private AutoCompleteTextView subjectAutoCompleteTextView;
private List<String> sixthSemesterSubjects;
private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Create a list of sixth semester subjects (replace with your actual subjects)
sixthSemesterSubjects = new ArrayList<>();
sixthSemesterSubjects.add("Software Engineering");
sixthSemesterSubjects.add("Computer Networks");
sixthSemesterSubjects.add("Database Management Systems");
sixthSemesterSubjects.add("Operating Systems");
sixthSemesterSubjects.add("Web Technology");
sixthSemesterSubjects.add("Data Mining and Warehousing");
sixthSemesterSubjects.add("Mobile Application Development");
sixthSemesterSubjects.add("Cryptography and Network Security");
sixthSemesterSubjects.add("Artificial Intelligence");
sixthSemesterSubjects.add("Cloud Computing");
_________________________________________________________________________
_________________________________________________________________________
ndroid:layout_height="match_parent"
a
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sixth Semester Subjects"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp" />
<AutoCompleteTextView
android:id="@+id/subjectAutoCompleteTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter subject name"
android:completionThreshold="1" />
</LinearLayout>
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
Page: 45
J AVA CODE:
package com.example.bluetoothtoggle;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.content.Intent;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.ToggleButton;
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
luetoothToggleButton = findViewById(R.id.bluetoothToggleButton);
b
bluetoothStatusTextView = findViewById(R.id.bluetoothStatusTextView);
bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
_________________________________________________________________________
_________________________________________________________________________
Override
@
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_ENABLE_BT) {
if (resultCode == RESULT_OK) {
// Bluetooth has been enabled
updateBluetoothState();
} else if (resultCode == RESULT_CANCELED) {
// User declined to enable Bluetooth, revert the toggle state
bluetoothToggleButton.setChecked(false);
bluetoothStatusTextView.setText("Bluetooth enabling was cancelled.");
}
}
}
ML CODE:
X
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
_________________________________________________________________________
_________________________________________________________________________
ndroid:gravity="center"
a
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Bluetooth Toggle"
android:textSize="24sp"
android:layout_marginBottom="32dp" />
<ToggleButton
android:id="@+id/bluetoothToggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff="OFF"
android:textOn="ON"
android:textAllCaps="true" />
<TextView
android:id="@+id/bluetoothStatusTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="Bluetooth Status: Unknown"
android:textSize="18sp" />
</LinearLayout>
OUTPUT:
J AVA CODE:
package com.example.simplecalculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity implements View.OnClickListener {
_________________________________________________________________________
_________________________________________________________________________
ditTextFirstNumber = findViewById(R.id.editTextFirstNumber);
e
editTextSecondNumber = findViewById(R.id.editTextSecondNumber);
buttonAdd = findViewById(R.id.buttonAdd);
buttonSubtract = findViewById(R.id.buttonSubtract);
buttonMultiply = findViewById(R.id.buttonMultiply);
buttonDivide = findViewById(R.id.buttonDivide);
textViewResult = findViewById(R.id.textViewResult);
uttonAdd.setOnClickListener(this);
b
buttonSubtract.setOnClickListener(this);
buttonMultiply.setOnClickListener(this);
buttonDivide.setOnClickListener(this);
}
Override
@
public void onClick(View v) {
String num1Str = editTextFirstNumber.getText().toString();
String num2Str = editTextSecondNumber.getText().toString();
int id = v.getId();
_________________________________________________________________________
_________________________________________________________________________
}
result = num1 / num2;
}
textViewResult.setText("Result: " + String.format("%.2f", result)); // Format to 2 decimal places
}
}
ML CODE:
X
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Simple Calculator"
android:textSize="24sp"
android:layout_gravity="center_horizontal"
android:layout_marginBottom="16dp" />
<EditText
android:id="@+id/editTextFirstNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter First Number"
android:inputType="numberDecimal"
android:layout_marginBottom="8dp" />
<EditText
android:id="@+id/editTextSecondNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Second Number"
android:inputType="numberDecimal"
android:layout_marginBottom="16dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center">
<Button
android:id="@+id/buttonAdd"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="+"
android:layout_marginEnd="4dp" />
<Button
android:id="@+id/buttonSubtract"
_________________________________________________________________________
_________________________________________________________________________
ndroid:layout_width="0dp"
a
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="-"
android:layout_marginEnd="4dp"
android:layout_marginStart="4dp" />
<Button
android:id="@+id/buttonMultiply"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="x"
android:layout_marginEnd="4dp"
android:layout_marginStart="4dp" />
<Button
android:id="@+id/buttonDivide"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="/"
android:layout_marginStart="4dp" />
</LinearLayout>
<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Result: "
android:textSize="18sp"
android:layout_marginTop="24dp" />
/LinearLayout>
<
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
Page: 56
J AVA CODE:
package com.example.checkboxexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
_________________________________________________________________________
_________________________________________________________________________
ML CODE:
X
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<CheckBox
android:id="@+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<CheckBox
android:id="@+id/checkBox2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 2" />
<CheckBox
android:id="@+id/checkBox3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 3" />
<CheckBox
android:id="@+id/checkBox4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 4" />
<CheckBox
android:id="@+id/checkBox5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 5" />
<Button
android:id="@+id/submitButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Submit"
android:layout_marginTop="16dp" />
</LinearLayout>
OUTPUT:
_________________________________________________________________________
_________________________________________________________________________
age: 79
P
JAVA CODE:
package com.example.toastmessage;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s howToastButton = findViewById(R.id.showToastButton);
showToastButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCustomToast("Message for you:\nYou have got mail!");
}
});
}
_________________________________________________________________________
_________________________________________________________________________
XML CODE:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Toast Example"
android:textSize="24sp"
android:layout_marginBottom="16dp" />
<Button
android:id="@+id/showToastButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Toast" />
</LinearLayout>
_________________________________________________________________________
_________________________________________________________________________
Page: 85
J AVA CODE:
package com.example.datetimepicker;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Locale;
Override
@
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
s electedDateTextView = findViewById(R.id.selectedDateTextView);
selectDateButton = findViewById(R.id.selectDateButton);
selectedTimeTextView = findViewById(R.id.selectedTimeTextView);
selectTimeButton = findViewById(R.id.selectTimeButton);
calendar = Calendar.getInstance();
dateFormatter = new SimpleDateFormat("dd-MM-yyyy", Locale.getDefault());
timeFormatter = new SimpleDateFormat("hh:mm a", Locale.getDefault());
selectDateButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DatePickerDialog datePickerDialog = new DatePickerDialog(MainActivity.this,
(view, year, monthOfYear, dayOfMonth) -> {
calendar.set(year, monthOfYear, dayOfMonth);
selectedDateTextView.setText(dateFormatter.format(calendar.getTime()));
},
calendar.get(Calendar.YEAR),
calendar.get(Calendar.MONTH),
_________________________________________________________________________
_________________________________________________________________________
calendar.get(Calendar.DAY_OF_MONTH));
datePickerDialog.show();
}
});
selectTimeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
TimePickerDialog timePickerDialog = new TimePickerDialog(MainActivity.this,
(view, hourOfDay, minute) -> {
calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
selectedTimeTextView.setText(timeFormatter.format(calendar.getTime()));
},
calendar.get(Calendar.HOUR_OF_DAY),
calendar.get(Calendar.MINUTE),
false); // Set true for 24-hour format, false for 12-hour format
timePickerDialog.show();
}
});
}
}
ML CODE:
X
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Selected Date:"
android:textSize="18sp" />
<TextView
android:id="@+id/selectedDateTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
_________________________________________________________________________
_________________________________________________________________________
android:textSize="18sp" />
<Button
android:id="@+id/selectDateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT DATE" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center_vertical">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Selected Time:"
android:textSize="18sp" />
<TextView
android:id="@+id/selectedTimeTextView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text=""
android:textSize="18sp" />
<Button
android:id="@+id/selectTimeButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SELECT TIME" />
</LinearLayout>
</LinearLayout>
_________________________________________________________________________