0% found this document useful (0 votes)
86 views44 pages

Android Animation and Bluetooth Setup

The document describes how to create an Android app to zoom in and out of an image using animations. It includes XML layout code with an ImageView, Java code to load scale up and down animations and apply them on click, and XML files defining the scale animations.

Uploaded by

Faizan Khatik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views44 pages

Android Animation and Bluetooth Setup

The document describes how to create an Android app to zoom in and out of an image using animations. It includes XML layout code with an ImageView, Java code to load scale up and down animations and apply them on click, and XML files defining the scale animations.

Uploaded by

Faizan Khatik
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Animation Zoom in and out

Xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<ImageView
android:id="@+id/imageView"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_centerInParent="true"
android:src="@drawable/ic_launcher_foreground"
android:scaleType="fitCenter"
android:clickable="true"
android:onClick="zoomIn" />

</LinearLayout>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private ImageView imageView;


private Animation scaleUpAnimation;
private Animation scaleDownAnimation;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
imageView = findViewById([Link]);
scaleUpAnimation = [Link](this,
[Link].scale_up);
scaleDownAnimation = [Link](this,
[Link].scale_down);
}

public void zoomIn([Link] view) {


[Link](scaleUpAnimation);
}

public void zoomOut([Link] view) {


[Link](scaleDownAnimation);
}
}
Xml resource file

Scale_up.xml
<scale xmlns:android="[Link]
android:fromXScale="1.0"
android:fromYScale="1.0"
android:toXScale="1.5"
android:toYScale="1.5"
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />

Scale_down.xml
<scale xmlns:android="[Link]
android:fromXScale="1.5"
android:fromYScale="1.5"
android:toXScale="1.0"
android:toYScale="1.0"
android:duration="500"
android:pivotX="50%"
android:pivotY="50%"
android:fillAfter="false" />
Bluetooth program

Xml code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<Button
android:id="@+id/btnEnableBluetooth"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Bluetooth"
android:layout_centerHorizontal="true"
android:layout_marginTop="50dp"/>

<Button
android:id="@+id/btnDiscoverDevices"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Discover Devices"
android:layout_below="@id/btnEnableBluetooth"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>

<Button
android:id="@+id/btnConnectToDevice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Connect to Device"
android:layout_below="@id/btnDiscoverDevices"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"/>

</LinearLayout>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {


private BluetoothAdapter bluetoothAdapter;
private BluetoothSocket btSocket;
private static final UUID MY_UUID = [Link]("00001101-0000-
1000-8000-00805F9B34FB");

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
bluetoothAdapter = [Link]();

Button btnEnableBluetooth =
findViewById([Link]);
Button btnDiscoverDevices =
findViewById([Link]);
Button btnConnectToDevice =
findViewById([Link]);

[Link](new [Link]()
{
@Override
public void onClick(View v) {
enableBluetooth();
}
});

[Link](new [Link]()
{
@Override
public void onClick(View v) {
discoverDevices();
}
});

[Link](new [Link]()
{
@Override
public void onClick(View v) {
connectToDevice();
}
});
}

private void enableBluetooth() {


if (bluetoothAdapter == null) {
showToast("Bluetooth not supported on this device");
return;
}

if (![Link]()) {
Intent enableBtIntent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 1);
} else {
showToast("Bluetooth is already enabled");
}
}

private void discoverDevices() {


if (bluetoothAdapter == null) {
showToast("Bluetooth not supported on this device");
return;
}

if (![Link]()) {
showToast("Enable Bluetooth first");
return;
}

Intent discoverDevicesIntent = new Intent([Link],


[Link]);
startActivity(discoverDevicesIntent);
}

private void connectToDevice() {


// Implement Bluetooth device connection logic here
// You may need to create a separate activity for device list and
connection
}

private void showToast(String message) {


[Link](getApplicationContext(), message,
Toast.LENGTH_SHORT).show();
}
}

Manifest file -:
<uses-permission android:name="[Link]" />
<uses-permission android:name="[Link].BLUETOOTH_ADMIN" />
<uses-permission android:name="[Link].BLUETOOTH_CONNECT" />
Camera app code

Xml code -:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent" />

<Button
android:id="@+id/btnCapture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Capture"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="16dp"
android:onClick="captureImage" />

<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />

</RelativeLayout>

[Link]
package [Link];

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private static final int REQUEST_IMAGE_CAPTURE = 1;

private SurfaceView surfaceView;


private ImageView imageView;
private Button btnCapture;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

surfaceView = findViewById([Link]);
imageView = findViewById([Link]);
btnCapture = findViewById([Link]);

// Initialize the SurfaceHolder and add a callback


SurfaceHolder surfaceHolder = [Link]();
[Link](new [Link]() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
// Initialize the camera here
initializeCamera();
}

@Override
public void surfaceChanged(SurfaceHolder holder, int format,
int width, int height) {
// Handle surface changes, if needed
}

@Override
public void surfaceDestroyed(SurfaceHolder holder) {
// Release the camera here
releaseCamera();
}
});
}

private void initializeCamera() {


// You should implement camera initialization code here
// This may involve using Camera API or CameraX for newer Android
versions
}

private void releaseCamera() {


// You should implement camera release code here
// This may involve releasing Camera API resources or CameraX
}

public void captureImage(View view) {


Intent takePictureIntent = new
Intent(MediaStore.ACTION_IMAGE_CAPTURE);
if ([Link](getPackageManager()) !=
null) {
startActivityForResult(takePictureIntent,
REQUEST_IMAGE_CAPTURE);
}
}

@Override
protected void onActivityResult(int requestCode, int resultCode,
@Nullable Intent data) {
[Link](requestCode, resultCode, data);
if (requestCode == REQUEST_IMAGE_CAPTURE && resultCode ==
RESULT_OK && data != null) {
Bundle extras = [Link]();
if (extras != null) {
Bitmap imageBitmap = (Bitmap) [Link]("data");
if (imageBitmap != null) {
displayCapturedImage(imageBitmap);
}
}
}
}

private void displayCapturedImage(Bitmap imageBitmap) {


[Link]([Link]);
[Link]([Link]);
[Link](imageBitmap);
}
}

Manifest file
<uses-feature android:name="[Link]" />
<uses-permission android:name="[Link]" />
Check box program
Xml code

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<TextView
android:text="Calculator"
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>

<EditText
android:id="@+id/num1"
android:hint="Enter 1st number"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></EditText>

<EditText
android:id="@+id/num2"
android:hint="Enter 2nd number"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></EditText>

<CheckBox
android:text="Add"
android:id="@+id/add_check"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></CheckBox>

<CheckBox
android:text="Sub"
android:id="@+id/sub_check"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></CheckBox>

<Button
android:id="@+id/btn"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:text="Submit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>
<Button
android:id="@+id/reset"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:textSize="20dp"
android:text="reset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></Button>

<TextView
android:id="@+id/result"
android:text=""
android:textSize="30dp"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>

</LinearLayout>

Java code -:

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText number1,number2;
TextView result;
Button btn,reset;

CheckBox add_check,sub_check;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

number1 = findViewById([Link].num1);
number2 = findViewById([Link].num2);
btn = findViewById([Link]);
result = findViewById([Link]);
reset = findViewById([Link]);
add_check = findViewById([Link].add_check);
sub_check = findViewById([Link].sub_check);

[Link](new [Link]() {
@Override
public void onClick(View v) {
StringBuilder finalresult = new StringBuilder();
int num1 =
[Link]([Link]().toString());
int num2 =
[Link]([Link]().toString());
if(add_check.isChecked()){
[Link]("\nAdd "+(num1+num2));
}
if(sub_check.isChecked()){
[Link]("\nSub "+(num1-num2));
}
[Link]([Link]());

}
});
[Link](new [Link]() {
@Override
public void onClick(View v) {
[Link]("");
[Link]("");
[Link]("");
add_check.setChecked(false);
sub_check.setChecked(false);
}
});
}
}
Date picker on button click ( simple )
Xml -:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_marginBottom="102dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:text="Change Date"/>

<DatePicker
android:id="@+id/datePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"

android:layout_marginBottom="36dp" />
</LinearLayout>

Java file -:

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


DatePicker picker;
Button displayDate;
TextView textview1;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
textview1=(TextView)findViewById([Link].textView1);
picker=(DatePicker)findViewById([Link]);
displayDate=(Button)findViewById([Link].button1);

[Link]("Current Date: "+getCurrentDate());

[Link](new [Link](){
@Override
public void onClick(View view) {

[Link]("Change Date: "+getCurrentDate());


}

});

}
public String getCurrentDate(){
StringBuilder builder=new StringBuilder();;
[Link](([Link]() + 1)+"/");//month is 0 based
[Link]([Link]()+"/");
[Link]([Link]());
return [Link]();
}
}
Fragments

Xml code -:
<?xml version="1.0" encoding="utf-8"?>
<[Link]
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/gotofragments"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Go to fragments"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</[Link]>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

TextView gotofragments;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

gotofragments = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View v) {
Intent intent = new Intent([Link],
[Link]);
startActivity(intent);
}
});
}
}
Create three xml files for different tabs

[Link]

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:text="First Page"
android:textSize="40dp"
android:layout_gravity="center"
android:layout_marginTop="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"></TextView>
</LinearLayout>

Same for [Link] and [Link]

Create java class for all three xml files


package [Link];

import [Link];
import [Link];
import [Link];
import [Link];

import [Link];
import [Link];
import [Link];

import [Link];

public class first extends Fragment {

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
return [Link]([Link],container,false);
}
}

same for [Link] and [Link]

Now add some code to [Link]

package [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link].R;
import [Link];
import [Link];
import [Link];

/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to
* one of the sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {

@StringRes
private static final int[] TAB_TITLES = new
int[]{[Link].tab_text_1, [Link].tab_text_2,[Link].tab_text_3};
private final Context mContext;

public SectionsPagerAdapter(Context context, FragmentManager fm) {


super(fm);
mContext = context;
}

@Override
public Fragment getItem(int position) {
Fragment fragment = null;
switch (position){
case 0:
fragment = new first();
break;
case 1:
fragment = new second();
break;
case 2:
fragment = new third();
break;
}
return fragment;
}

@Nullable
@Override
public CharSequence getPageTitle(int position) {
return [Link]().getString(TAB_TITLES[position]);
}

@Override
public int getCount() {
// Show 2 total pages.
return 3;
}
}
Geocoding and Reverse geocoding

Xml file -:

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
tools:context=".MainActivity">

<EditText
android:id="@+id/editTextAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Address" />

<Button
android:id="@+id/buttonGeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextAddress"
android:layout_marginTop="16dp"
android:text="Geocode" />

<Button
android:id="@+id/buttonReverseGeocode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonGeocode"
android:layout_marginTop="16dp"
android:text="Reverse Geocode" />

<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonReverseGeocode"
android:layout_marginTop="16dp"
android:textColor="@android:color/black"
android:textSize="18sp" />

</RelativeLayout>

Java file -:

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

EditText editTextAddress;
TextView textViewResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

editTextAddress = findViewById([Link]);
textViewResult = findViewById([Link]);

Button buttonGeocode = findViewById([Link]);


[Link](new [Link]() {
@Override
public void onClick(View v) {
String addressString = [Link]().toString();
if (![Link]()) {
geocodeAddress(addressString);
} else {
[Link]("Please enter an address");
}
}
});

Button buttonReverseGeocode = findViewById([Link]);


[Link](new [Link]() {
@Override
public void onClick(View v) {
double latitude = 37.7749; // Example latitude
double longitude = -122.4194; // Example longitude
reverseGeocode(latitude, longitude);
}
});
}

private void geocodeAddress(String addressString) {


Geocoder geocoder = new Geocoder(this, [Link]());
try {
List<Address> addresses = [Link](addressString, 1);
if (addresses != null && ![Link]()) {
Address address = [Link](0);
String result = "Latitude: " + [Link]() + "\nLongitude: " +
[Link]();
[Link](result);
} else {
[Link]("Address not found");
}
} catch (IOException e) {
[Link]();
}
}

private void reverseGeocode(double latitude, double longitude) {


Geocoder geocoder = new Geocoder(this, [Link]());
try {
List<Address> addresses = [Link](latitude, longitude, 1);
if (addresses != null && ![Link]()) {
Address address = [Link](0);
String result = "Address: " + [Link](0);
[Link](result);
} else {
[Link]("Address not found");
}
} catch (IOException e) {
[Link]();
}
}
}

Manifest file -:

<manifest xmlns:android="[Link]
package="[Link]">

<uses-permission android:name="[Link]" />


<uses-permission android:name="[Link].ACCESS_FINE_LOCATION" />
<uses-permission android:name="[Link].ACCESS_COARSE_LOCATION" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]" />
<category android:name="[Link]" />
</intent-filter>
</activity>
</application>

</manifest>
ListView

Xml -:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>

List_view.xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
xmlns:android="[Link]
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="18sp"
android:id="@+id/textView"/>
</LinearLayout>

Java -:

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {

String[] list_item;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
String[] stringArray = {"Python", "Android", "Operating System",
"Advance Java"};
list_item = getResources().getStringArray([Link].list_subjects);
// Create an ArrayAdapter
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
[Link].list_item, [Link], list_item);
// Set up the ListView
ListView listView = findViewById([Link]);
[Link](adapter);
}
}

Strings -:

<resources>
<string name="app_name">uefclass</string>
<string-array name="list_subjects">
<item>Prince</item>
<item>Raj</item>
<item>Verma</item>
</string-array>
</resources>
Multimedia program

Xml code -:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<VideoView
android:id="@+id/videoView"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

[Link]
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private VideoView videoView;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

// Initialize VideoView
videoView = findViewById([Link]);

// Set the video URI


Uri videoUri = [Link]("[Link]://" + getPackageName()
+ "/" + [Link].sample_video);
[Link](videoUri);

// Set up MediaController for playback controls


MediaController mediaController = new MediaController(this);
[Link](videoView);
[Link](mediaController);

// Set a completion listener to handle video completion


[Link](new
[Link]() {
@Override
public void onCompletion(MediaPlayer mp) {
// Perform any action when the video playback is complete
}
});
// Start video playback
[Link]();
}
}

Manifest file -:
<uses-permission android:name="[Link]" />
<uses-permission android:name="[Link].READ_EXTERNAL_STORAGE"
/>
<uses-permission android:name="[Link].WRITE_EXTERNAL_STORAGE"
/>
Progress bar ( add two numbers ) -:
Xml -:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<EditText
android:id="@+id/editTextNumber1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Enter number 1"
android:inputType="numberDecimal" />

<EditText
android:id="@+id/editTextNumber2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber1"
android:layout_marginTop="16dp"
android:hint="Enter number 2"
android:inputType="numberDecimal" />

<Button
android:id="@+id/btnAdd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNumber2"
android:layout_marginTop="16dp"
android:text="Add Numbers" />

<ProgressBar
android:id="@+id/progressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/btnAdd"
android:layout_marginTop="16dp"
android:visibility="invisible" />

<TextView
android:id="@+id/textViewResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/progressBar"
android:layout_marginTop="16dp"
android:text=""
android:textSize="18sp" />
</LinearLayout>

Java -:
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private EditText editTextNumber1, editTextNumber2;
private Button btnAdd;
private ProgressBar progressBar;
private TextView textViewResult;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

editTextNumber1 = findViewById([Link].editTextNumber1);
editTextNumber2 = findViewById([Link].editTextNumber2);
btnAdd = findViewById([Link]);
progressBar = findViewById([Link]);
textViewResult = findViewById([Link]);

[Link](new [Link]() {
@Override
public void onClick(View view) {
addNumbers();
}
});
}

private void addNumbers() {


String number1Str = [Link]().toString();
String number2Str = [Link]().toString();

if ([Link]() || [Link]()) {
[Link](this, "Please enter both numbers",
Toast.LENGTH_SHORT).show();
return;
}

final double number1 = [Link](number1Str);


final double number2 = [Link](number2Str);

// Show progress bar


[Link]([Link]);
// Delay for 3 seconds using Handler
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// Calculate the sum
double sum = number1 + number2;

// Hide progress bar


[Link]([Link]);

// Display the result


[Link]("Result: " + sum);
}
}, 3000); // 3 seconds delay

}
Radio button program -:

Xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<RadioGroup
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/radioGroup">

<RadioButton
android:id="@+id/radioMale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Male"
android:layout_marginTop="10dp"
android:checked="false"
android:textSize="20dp" />

<RadioButton
android:id="@+id/radioFemale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=" Female"
android:layout_marginTop="20dp"
android:checked="false"

android:textSize="20dp" />
</RadioGroup>

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show Selected"
android:id="@+id/button"
android:onClick="onclickbuttonMethod"
android:layout_gravity="center_horizontal" />

</LinearLayout>

Java

package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

RadioButton genderradioButton;
RadioGroup radioGroup;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

radioGroup=(RadioGroup)findViewById([Link]);
}
public void onclickbuttonMethod(View v){
int selectedId = [Link]();
genderradioButton = (RadioButton) findViewById(selectedId);
if(selectedId==-1){
[Link]([Link],"Nothing selected",
Toast.LENGTH_SHORT).show();
}
else{
[Link]([Link],[Link](),
Toast.LENGTH_SHORT).show();
}

}
}
SMS Manager class code

Xml -:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter number"
android:inputType="textPersonName" />

<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="Enter message"
android:inputType="textPersonName" />

<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="60dp"
android:layout_marginRight="60dp"
android:text="SEND" />
</LinearLayout>

Java
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


EditText phonenumber,message;
Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

send=findViewById([Link]);
phonenumber=findViewById([Link]);
message=findViewById([Link].editText2);
[Link](new [Link]() {

public void onClick(View view) {


String number=[Link]().toString();
String msg=[Link]().toString();
try {
SmsManager smsManager=[Link]();

[Link](number,null,msg,null,null);
[Link](getApplicationContext(),"Message
Sent",Toast.LENGTH_LONG).show();
}catch (Exception e)
{

[Link](getApplicationContext(),"Failed",Toast.LENGTH_LONG).show()
;
}
}
});

}
}

Manifest file -:
<uses-permission android:name="[Link].SEND_SMS"/>
<uses-permission android:name="[Link].READ_PHONE_STATE"/>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<EditText
android:id="@+id/et_phone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Phone Number"
android:padding="12dp"
android:maxLength="10"
android:inputType="phone"
android:background="@color/white"/>
<EditText
android:id="@+id/et_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Message"
android:padding="12dp"
android:minLines="6"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_marginTop="8dp" />
<Button
android:id="@+id/bt_send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Send SMS"
android:layout_marginTop="32dp"/>
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Executed By Leonhard Dsouza"
android:textAlignment="center"
android:textSize="20dp"/>
</LinearLayout>

MainActivity

package [Link].practicect2;

import [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
public class MainActivity extends AppCompatActivity {
EditText etPhone, etMessage;
Button btSend;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState );
setContentView([Link].activity_main );
etPhone = findViewById([Link].et_phone);
etMessage = findViewById([Link].et_message);
btSend = findViewById([Link].bt_send);
[Link]( new [Link]() {
@Override
public void onClick(View view) {
if ([Link]([Link],
[Link].SEND_SMS) == PackageManager.PERMISSION_GRANTED){
sendMessage();
}else{

[Link]([Link], new
String[]{[Link].SEND_SMS}, 100);
}
}
} );
}
private void sendMessage() {
String sPhone = [Link]().toString().trim();
String sMessage = [Link]().toString().trim();
if (![Link]("") && ![Link]("")){
SmsManager smsManager = [Link]();
[Link](sPhone, null, sMessage, null, null);
[Link](getApplicationContext(), "SMS sent successfully!",
Toast.LENGTH_LONG).show();
}else{
[Link](getApplicationContext(),"Enter value first.",
Toast.LENGTH_SHORT).show();
}
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions, @NonNull int[] grantResults) {
[Link](requestCode, permissions,
grantResults);
if (requestCode == 100 && [Link] > 0 && grantResults[0]
== PackageManager.PERMISSION_GRANTED){
sendMessage();
}else{
[Link](getApplicationContext(), "Permission Denied",
Toast.LENGTH_SHORT).show();
}
}
}
SQL program

Xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter a name"
android:layout_margin="16dp"/>

<Button
android:id="@+id/addButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Name"

android:layout_marginTop="8dp"/>

<Button
android:id="@+id/displayButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Display All Data"

android:layout_marginTop="8dp"/>

<TextView
android:id="@+id/displayTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""

android:layout_marginTop="16dp"/>

</LinearLayout>

Java
package [Link];
import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


private EditText nameEditText;
private DatabaseHelper databaseHelper;
private TextView displayTextView;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
nameEditText = findViewById([Link]);
displayTextView = findViewById([Link]);
Button addButton = findViewById([Link]);
Button displayButton = findViewById([Link]);

databaseHelper = new DatabaseHelper(this);

[Link](new [Link]() {
@Override
public void onClick(View v) {
addName();
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
displayAllData();
}
});
}

private void addName() {


String name = [Link]().toString().trim();

if (![Link]()) {
long result = [Link](name);

if (result != -1) {
[Link](this, "Name added successfully",
Toast.LENGTH_SHORT).show();
[Link]("");
} else {
[Link](this, "Failed to add name",
Toast.LENGTH_SHORT).show();
}
} else {
[Link](this, "Please enter a name",
Toast.LENGTH_SHORT).show();
}
}
private void displayAllData() {
String allData = [Link]();
[Link](allData);
}
}

Database Helper
package [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class DatabaseHelper extends SQLiteOpenHelper {

private static final String DATABASE_NAME = "name_database.db";


private static final String TABLE_NAME = "name_table";
public static final String COL_ID = "ID";
public static final String COL_NAME = "NAME";

public DatabaseHelper(Context context) {


super(context, DATABASE_NAME, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {
String createTableQuery = "CREATE TABLE " + TABLE_NAME + " (" +
COL_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " +
COL_NAME + " TEXT)";
[Link](createTableQuery);
}

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
[Link]("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}

public long insertName(String name) {


SQLiteDatabase db = [Link]();
ContentValues contentValues = new ContentValues();
[Link](COL_NAME, name);

try {
return [Link](TABLE_NAME, null, contentValues);
} catch (SQLException e) {
[Link]();
return -1;
} finally {
[Link]();
}
}
public String getAllData() {
SQLiteDatabase db = [Link]();
Cursor cursor = [Link]("SELECT * FROM " + TABLE_NAME, null);
StringBuilder data = new StringBuilder();

if ([Link]() == 0) {
[Link]("No data available.");
} else {
while ([Link]()) {
int id = [Link]([Link](COL_ID));
String name =
[Link]([Link](COL_NAME));
[Link]("ID: ").append(id).append(", Name:
").append(name).append("\n");
}
}

[Link]();
[Link]();
return [Link]();
}
}
Text to speech

Xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter text to convert"
android:layout_margin="16dp"/>

<Button
android:id="@+id/speakButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editText"
android:layout_centerHorizontal="true"
android:text="Speak"/>

</LinearLayout>

Java
package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

import [Link];

public class MainActivity extends AppCompatActivity {


private TextToSpeech textToSpeech;
private EditText editText;
private Button speakButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

editText = findViewById([Link]);
speakButton = findViewById([Link]);
textToSpeech = new TextToSpeech(getApplicationContext(), new
[Link]() {
@Override
public void onInit(int status) {
if (status != [Link]) {
[Link]([Link]);
} else {
Log.e("TTS", "Initialization failed");
}
}
});

[Link](new [Link]() {
@Override
public void onClick(View v) {
String text = [Link]().toString();
[Link](text, TextToSpeech.QUEUE_FLUSH, null);
}
});
}

@Override
protected void onDestroy() {
if (textToSpeech != null) {
[Link]();
[Link]();
}
[Link]();
}
}

Manifest
<uses-permission android:name="[Link]"/>
<uses-permission android:name="[Link].ACCESS_NETWORK_STATE"/>
<uses-permission
android:name="[Link].WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="[Link].READ_PHONE_STATE"/>
<uses-permission
android:name="[Link].READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="[Link].WAKE_LOCK"/>
<uses-permission
android:name="[Link].MODIFY_AUDIO_SETTINGS"/>
Time picker -:
Xml -:

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="102dp"
android:layout_marginLeft="30dp"
android:layout_marginStart="30dp"
android:text="" />

<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Change Time" />

<TimePicker
android:id="@+id/timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="36dp" />
</LinearLayout>

Java -:

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {


TextView textview1;
TimePicker timepicker;
Button changetime;
@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);
textview1=(TextView)findViewById([Link].textView1);
timepicker=(TimePicker)findViewById([Link]);
//Uncomment the below line of code for 24 hour view
timepicker.setIs24HourView(true);
changetime=(Button)findViewById([Link].button1);

[Link](getCurrentTime());

[Link](new [Link](){
@Override
public void onClick(View view) {
[Link](getCurrentTime());
}
});

public String getCurrentTime(){


String currentTime="Current Time:
"+[Link]()+":"+[Link]();
return currentTime;
}
}
Toggle Button -:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="[Link]
xmlns:app="[Link]
xmlns:tools="[Link]
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
>

<ToggleButton
android:textOn="Hide"
android:textOff="Show"
android:id="@+id/toggleButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Toggle Button"/>

</LinearLayout>

Java file

package [Link];

import [Link];

import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];

public class MainActivity extends AppCompatActivity {

private ToggleButton toggleButton;

@Override
protected void onCreate(Bundle savedInstanceState) {
[Link](savedInstanceState);
setContentView([Link].activity_main);

toggleButton = findViewById([Link]);

// Set a listener for the toggle button


[Link](new [Link]() {
@Override
public void onClick(View v) {
// Display a message based on the toggle button's state
if ([Link]()) {
[Link]([Link], "Toggle Button is
ON", Toast.LENGTH_SHORT).show();
} else {
[Link]([Link], "Toggle Button is
OFF", Toast.LENGTH_SHORT).show();
}
}
});
}
}

You might also like