You are on page 1of 36

EXPERIMENT NO.

:20
//xml part 
//activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Song"
android:textSize="50sp"
android:textStyle="bold"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.054">
</TextView>
<LinearLayout
android:id="@+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.05"
tools:ignore="MissingConstraints">
<Button
android:id="@+id/buttonStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Start Service" />
<Button
android:id="@+id/buttonStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Stop Service" />
</LinearLayout>
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ringtone"
android:textColor="@color/black"
android:textSize="50sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/linearLayout3"
app:layout_constraintVertical_bias="0.154">
</TextView>
<LinearLayout
android:id="@+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.176"
tools:ignore="MissingConstraints">
<Button
android:id="@+id/ringtoneStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Start Ringtone" />
<Button
android:id="@+id/ringtoneStop"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:text="Stop Ringtone" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

//java part 
//MainActivity.java
package com.example.service;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.provider.Settings;
import android.view.View;
import android.widget.Button;
public class MainActivity extends AppCompatActivity implements
View.OnClickListener {
private Button start, stop, starring, storing;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
start = (Button) findViewById( R.id.buttonStart );
stop = (Button) findViewById( R.id.buttonStop );
start.setOnClickListener( this );
stop.setOnClickListener( this );
starring = (Button) findViewById( R.id.ringtoneStart );
storing = (Button) findViewById( R.id.ringtoneStop );
starring.setOnClickListener( this );
storing.setOnClickListener( this );
}
@Override
public void onClick(View v) {
if(v==start){
startService( new Intent( this, MyServices.class ) );
}else if(v==stop){
stopService( new Intent( this, MyServices.class ) );
}
if(v==starring){
startService( new Intent( this, RingtoneServices.class ) );
}else if(v==storing){
stopService( new Intent( this, RingtoneServices.class ) );
}
}
}
EXPERIMENT NO. : 21
//xml part 
//activity_main.xml
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Not recived Anything"
android:textSize="50dp"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

// AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.broadcastreceivers">
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<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/Theme.BroadcastReceivers">
<receiver
android:name=".MyReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.TIMEZONE_CHANGED"/>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
//java part 
//MainActivity.java
package com.example.broadcastreceivers;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tv;
BatteryReceiver batteryReceiver;
MyReceiver myReceiver = new MyReceiver();
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv= findViewById(R.id.tv);
batteryReceiver=new BatteryReceiver(tv);
registerReceiver(batteryReceiver, new
IntentFilter(Intent.ACTION_BATTERY_CHANGED));
}
@Override
protected void onStart() {
super.onStart();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_AIRPLANE_MODE_CHANGED);
intentFilter.addAction(Intent.ACTION_POWER_CONNECTED);
intentFilter.addAction(Intent.ACTION_POWER_DISCONNECTED);
this.registerReceiver(myReceiver, intentFilter);
}
@Override
protected void onStop() {
super.onStop();
this.unregisterReceiver(myReceiver);
unregisterReceiver(batteryReceiver);
}
}
EXPERIMENT NO. :22
//xml part
//activity_main.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@drawable/background"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Use your FingerPrint to Login"
android:textColor="#ffffff"
android:textStyle="bold"
android:textSize="30dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_baseline_fingerprint_24"
android:layout_marginVertical="20dp"/>
<TextView
android:id="@+id/txt_msg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#ff0000"
android:textSize="20dp"
android:textStyle="bold"/>
<Button
android:id="@+id/login_bin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginVertical="12dp"
android:background="#fff"
android:text="Login"
android:visibility="visible" />
</LinearLayout>

//java part 
//MainActivity.java
package com.example.sensors;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
import androidx.core.content.ContextCompat;
import android.content.Intent;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;
import java.util.concurrent.Executor;
public class MainActivity extends AppCompatActivity {
public boolean bb = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView msg_txt = findViewById(R.id.txt_msg);
Button login_btn = findViewById(R.id.login_bin);
BiometricManager biometricManager = BiometricManager.from(this);
switch (biometricManager.canAuthenticate()){
case BiometricManager.BIOMETRIC_SUCCESS:
msg_txt.setText("You can use the fingerprint sensor to login");
msg_txt.setTextColor(Color.parseColor("#ffffff"));
break;
case BiometricManager.BIOMETRIC_ERROR_NO_HARDWARE:
msg_txt.setText("The device don't have a fingerprint sensor");
login_btn.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_HW_UNAVAILABLE:
msg_txt.setText("The biometric sensors is currently
unavailable");
login_btn.setVisibility(View.GONE);
break;
case BiometricManager.BIOMETRIC_ERROR_NONE_ENROLLED:
msg_txt.setText("Your device don't have any fingerprint saved,
please check");
login_btn.setVisibility(View.GONE);
break;
}
Executor executor = ContextCompat.getMainExecutor(this);
BiometricPrompt biometricPrompt = new BiometricPrompt(MainActivity.this,
executor, new BiometricPrompt.AuthenticationCallback() {
@Override
public void onAuthenticationError(int errorCode, @NonNull CharSequence
errString) {
super.onAuthenticationError(errorCode, errString);
}
@Override
public void onAuthenticationSucceeded(@NonNull
BiometricPrompt.AuthenticationResult result) {
super.onAuthenticationSucceeded(result);
Toast.makeText(getApplicationContext(), "Login Success
!",Toast.LENGTH_SHORT).show();
}
@Override
public void onAuthenticationFailed() {
super.onAuthenticationFailed();
}
});
BiometricPrompt.PromptInfo promptInfo = new
BiometricPrompt.PromptInfo.Builder()
.setTitle("Login")
.setDescription(" your fingerprint to login to your app")
.setNegativeButtonText("Cancel")
.build();
login_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
biometricPrompt.authenticate(promptInfo);
}
});
}
}

//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Shake to switch color"
android:textSize="30dp"
android:textColor="@color/black"
android:textStyle="bold"
android:gravity="center"/>
</RelativeLayout>

//java part 
//MainActivity.java
package com.example.sensor3;
import android.app.Activity;
import android.graphics.Color;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.Toast;
public class MainActivity extends Activity implements SensorEventListener{
private SensorManager sensorManager;
private boolean isColor = false;
private View view;
private long lastUpdate;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
view = findViewById(R.id.textView);
view.setBackgroundColor(Color.CYAN);
sensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
lastUpdate = System.currentTimeMillis();
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
@Override
public void onSensorChanged(SensorEvent event) {
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
getAccelerometer(event);
}
}
private void getAccelerometer(SensorEvent event) {
float[] values = event.values;
// Movement
float x = values[0];
float y = values[1];
float z = values[2];
float accelationSquareRoot = (x * x + y * y + z * z)
/ (SensorManager.GRAVITY_EARTH * SensorManager.GRAVITY_EARTH);
long actualTime = System.currentTimeMillis();

Toast.makeText(getApplicationContext(),String.valueOf(accelationSquareRoot)+" "+
SensorManager.GRAVITY_EARTH,Toast.LENGTH_SHORT).show();
if (accelationSquareRoot >= 2)
{
if (actualTime - lastUpdate < 200) {
return;
}
lastUpdate = actualTime;
if (isColor) {
view.setBackgroundColor(Color.MAGENTA);
} else {
view.setBackgroundColor(Color.BLUE);
}
isColor = !isColor;
}
EXPERIMENT NO. -23

//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<Button
android:id="@+id/btnTakePicture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Take a Photo"
android:textStyle="bold"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true" />
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/capturedImage"
android:layout_above="@+id/btnTakePicture"/>
</RelativeLayout>

//MainActivity.java
package com.example.camera2;
import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private Button btnCapture;
private ImageView imgCapture;
private static final int Image_Capture_Code = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnCapture =(Button)findViewById(R.id.btnTakePicture);
imgCapture = (ImageView) findViewById(R.id.capturedImage);
btnCapture.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cInt = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cInt,Image_Capture_Code);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == Image_Capture_Code) {
if (resultCode == RESULT_OK) {
Bitmap bp = (Bitmap) data.getExtras().get("data");
imgCapture.setImageBitmap(bp);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Cancelled", Toast.LENGTH_LONG).show();
}
}
}
}
EXPERIMENT NO. 24
//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center_horizontal">
<TextView
android:id="@+id/statuseBluetoothTv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fdg"
android:textAlignment="center"
android:textStyle="bold"
android:textSize="20sp"
android:gravity="center_horizontal"
android:textColor="#000"/>
<ImageView
android:id="@+id/blutooth"
android:layout_width="100dp"
android:layout_height="100dp"/>
<Button
android:id="@+id/onBtn"
android:minWidth="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn On"/>
<Button
android:id="@+id/offBtn"
android:minWidth="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Turn Off"/>
<Button
android:id="@+id/discoverableBtn"
android:minWidth="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Discoverable"/>
<Button
android:id="@+id/paireBtn"
android:minWidth="200dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Get Paired Deviced"/>
<TextView
android:id="@+id/paidTv"
android:minWidth="200dp"
android:text=""
android:textColor="#000"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>

//java part 
//MainActivity.java
package com.example.bluetooth2;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.time.Year;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVER_BT = 1;
TextView mStatusBlueTv, mPairedTv;
ImageView mBlueIv;
Button mOnBtn, mOffBtn, mDiscoverBtn, mPairedBtn;
BluetoothAdapter mBlueAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStatusBlueTv = findViewById(R.id.statuseBluetoothTv);
mPairedTv = findViewById(R.id.paidTv);
mBlueIv = findViewById(R.id.blutooth);
mOnBtn = findViewById(R.id.onBtn);
mOffBtn = findViewById(R.id.offBtn);
mDiscoverBtn= findViewById(R.id.discoverableBtn);
mPairedBtn = findViewById(R.id.paireBtn);
mBlueAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBlueAdapter == null) {
mStatusBlueTv.setText("Bluetooth is not available");
} else {
mStatusBlueTv.setText("Blutooth is available");
}
if (mBlueAdapter.isEnabled()) {
} else {
mBlueIv.setImageResource(R.drawable.ic_action_off);
}
//on btn
mOnBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBlueAdapter.isEnabled()) {
showToast("Turn On Bluetooth...");
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, REQUEST_ENABLE_BT);
} else {
showToast("Bluetooth is already on");
}
}
});
//discover
mDiscoverBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBlueAdapter.isDiscovering()) {
showToast("Making Your Device Discoverable");
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(intent, REQUEST_DISCOVER_BT);
}
}
});
//off btn
mOffBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mBlueAdapter.isEnabled()) {
mBlueAdapter.disable();
showToast("Turning Bluetooth Off");
mBlueIv.setImageResource(R.drawable.ic_action_off);
} else {
showToast("Bluetooth is already Off");
}
}
});
//get paired
mPairedBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (mBlueAdapter.isEnabled()) {
mPairedTv.setText("Paired Devices");
Set<BluetoothDevice> devices =
mBlueAdapter.getBondedDevices();
for (BluetoothDevice device: devices) {
mPairedTv.append("\nDevice: " + device.getName()+ "," +
device);
}
} else {
showToast("Turn on bluetooth to get paired devides");
}
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable
Intent data) {
switch (requestCode) {
case REQUEST_ENABLE_BT:
if (resultCode == RESULT_OK) {
mBlueIv.setImageResource(R.drawable.ic_action_name);
showToast("Bluetooth is on");
} else {
showToast("could't on bluetooth");
}
break;
}
super.onActivityResult(requestCode, resultCode, data);
}
private void showToast (String msg) {
Toast.makeText(this, msg, Toast.LENGTH_SHORT).show();
}
}
EXPERIMENT NO. :26

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextViewandroid:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Async Task"
android:textSize="50dp"
android:textColor="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:layout_gravity="center"/>
<Button
android:id="@+id/adddata"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add data"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="50dp"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:onClick="addProduct"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View data"
android:textStyle="bold"
android:textSize="20sp"
android:layout_marginTop="40dp"
android:layout_marginRight="50dp"
android:layout_marginLeft="50dp"
android:onClick="displayProducts"/>
</LinearLayout>

//activity_save_info.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ic_launcher_background"
tools:context=".SaveInfo"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Add Data"
android:textSize="30dp"
android:textColor="@color/black"
android:gravity="center"/>
<EditText
android:id="@+id/id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Id"
android:textSize="28dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="40dp"/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Product Name"
android:textSize="28dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="40dp"/>
<EditText
android:id="@+id/price"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Price"
android:textSize="28dp"
android:layout_marginTop="40dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"/>
<EditText
android:id="@+id/qty"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Quantity"
android:textSize="28dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="40dp"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="50dp"
android:layout_marginTop="40dp"
android:layout_marginRight="50dp"
android:onClick="saveData"
android:text="save"
android:textColor="@color/design_default_color_on_secondary"
android:textSize="40dp"
android:textStyle="bold"
app:backgroundTint="#3D5AFE"
app:iconTint="#8F1E1E" />
</LinearLayout>

//java part
//MainActivity.java
package com.example.asynctask3;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void addProduct(View view){
startActivity(new Intent(this,SaveInfo.class));
}
public void displayProducts(View view){
startActivity(new Intent(this,DisplayProduct.class));
}
}

public ProdectAdapter(@NonNull Context context, int resource) {


super(context, resource);
}

@Override
public void add(@Nullable Object object) {
list.add(object);
super.add(object);
}
@Override
public int getCount() {
return list.size();
}
@Nullable
@Override
public Object getItem(int position) {
return list.get(position);
}
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull
ViewGroup parent) {
View row = convertView;
ProductHolder productHolder;
if(row == null){
LayoutInflater layoutInflater =
(LayoutInflater)this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE
);
row =
layoutInflater.inflate(R.layout.display_product_row,parent,false);
productHolder = new ProductHolder();
productHolder.tx_id = (TextView) row.findViewById(R.id.t_id);
productHolder.tx_name = (TextView) row.findViewById(R.id.t_name);
productHolder.tx_price = (TextView) row.findViewById(R.id.t_price);
productHolder.tx_qty = (TextView) row.findViewById(R.id.t_qty);
row.setTag(productHolder);
}
else
{
productHolder = (ProductHolder) row.getTag();
}
Product product = (Product) getItem(position);
productHolder.tx_id.setText(product.getId().toString());
productHolder.tx_name.setText(product.getName().toString());
productHolder.tx_price.setText(Integer.toString(product.getPrice()));
productHolder.tx_qty.setText(Integer.toString(product.getQty()));
return row;
}
static class ProductHolder{
TextView tx_id,tx_name,tx_price,tx_qty;
}
}

EXPERIMENT NO. :27

//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="#FFFFFF"
android:textSize="50sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />
<EditText
android:id="@+id/userid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:ems="10"
android:hint="Username"
android:textColorHint="#ffffff"
android:inputType="textPersonName"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.146" />
<EditText
android:id="@+id/passwordid"
android:layout_width="363dp"
android:layout_height="96dp"
android:layout_marginTop="60dp"
android:ems="10"
android:hint="Password"
android:textColorHint="#ffffff"
android:inputType="textPassword"
android:textColor="#FFFFFF
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/userid"
app:layout_constraintVertical_bias="0.017" />
<Button
android:id="@+id/loginid"
android:layout_width="193dp"
android:layout_height="52dp"
android:text="Login"
android:textSize="25sp"
app:backgroundTint="#FF3D00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordid"
app:layout_constraintVertical_bias="0.291" />
<TextView
android:id="@+id/AttemptsInfoid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No. of attempts remaining: 5"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.611"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/loginid"
app:layout_constraintVertical_bias="0.256" />
</androidx.constraintlayout.widget.ConstraintLayout>

//activity_home_page.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomePageActivity">
<TextView
android:id="@+id/textView"
android:layout_width="272dp"
android:layout_height="98dp"
android:text="login successfully"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

//background.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="@color/design_default_color_primary"
android:endColor="@color/cardview_dark_background"
android:angle="-90"/>
</shape>

//java part 
//MainActivity.java
package com.example.login;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
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 {
private EditText eUser;
private EditText ePassword;
private Button eLogin;
private TextView eAttemptsInfo;
public static String Username = "Rajib";
private String Password = "rajib";
boolean isValid = false;
private int counter = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eUser = findViewById(R.id.userid);
ePassword = findViewById(R.id.passwordid);
eLogin = findViewById(R.id.loginid);
eAttemptsInfo = findViewById(R.id.AttemptsInfoid);
eLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String inputUser = eUser.getText().toString();
String inputPassword = ePassword.getText().toString();
if(inputUser.isEmpty() || inputPassword.isEmpty())
{
Toast.makeText(MainActivity.this, "Please enter all the
details correctly!", Toast.LENGTH_SHORT).show();
}else{
isValid = validate(inputUser, inputPassword);
if(!isValid){
counter--;
Toast.makeText(MainActivity.this, "Login fail.",
Toast.LENGTH_SHORT).show();
eAttemptsInfo.setText("No. of attempts remaining: "
+counter);
if(counter == 0){
eLogin.setEnabled(false);
}
}else {
Toast.makeText(MainActivity.this, "Login successfully..",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,
HomePageActivity.class);
startActivity(intent);
}
}
}
});
}
private boolean validate(String user, String password){
if(user.equals(Username) && password.equals(Password)){
return true;
}
return false;
}
}

//HomePageActivity.java
package com.example.login;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import static com.example.login.MainActivity.Username;
public class HomePageActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
textView=findViewById(R.id.textView);
//textView.setText("Login successfully", (CharSequence) eUser);
textView.setText("Login successfully " + Username);
}
}
EXPERIMENT NO. :28
//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background"
tools:context=".MainActivity"
android:id="@+id/k">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:textColor="#FFFFFF"
android:textSize="50sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.042" />
<EditText
android:id="@+id/userid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="56dp"
android:ems="10"
android:hint="Username"
android:textColorHint="#ffffff"
android:inputType="textPersonName"
android:textAllCaps="false"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.491"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
app:layout_constraintVertical_bias="0.146" />
<EditText
android:id="@+id/passwordid"
android:layout_width="363dp"
android:layout_height="96dp"
android:layout_marginTop="60dp"
android:ems="10"
android:hint="Password"
android:textColorHint="#ffffff"
android:inputType="textPassword"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/userid"
app:layout_constraintVertical_bias="0.017" />
<Button
android:id="@+id/loginid"
android:layout_width="193dp"
android:layout_height="52dp"
android:saveEnabled="false"
android:text="Login"
android:textSize="25sp"
app:backgroundTint="#FF3D00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/passwordid"
app:layout_constraintVertical_bias="0.291" />
</androidx.constraintlayout.widget.ConstraintLayout>

widget.ConstraintLayout>

//java part 
//MainActivity.java
package com.example.login;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowInsets;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
private EditText eUser;
private EditText ePassword;
private Button eLogin;
private ConstraintLayout constraintLayout;
public static String Username = "Kush";
private String Password = "Bala";
boolean isValid = false;
private int counter = 5;
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eUser = findViewById(R.id.userid);
ePassword = findViewById(R.id.passwordid);
eLogin = findViewById(R.id.loginid);
constraintLayout = findViewById(R.id.k);
eLogin.setEnabled(false);
ePassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {String inputUser = eUser.getText().toString();
String inputPassword = ePassword.getText().toString();
if(inputUser.isEmpty() || inputPassword.isEmpty())
{
Toast.makeText(MainActivity.this, "Please enter all the
details correctly!", Toast.LENGTH_SHORT).show();
}else{
isValid = validate(inputUser, inputPassword);
if(!isValid){
Toast.makeText(MainActivity.this, "Invalidate username or
password", Toast.LENGTH_SHORT).show();
eLogin.setEnabled(false);
}else {
eLogin.setEnabled(true);
Toast.makeText(MainActivity.this, "validate username and
password", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void afterTextChanged(Editable s) {
}
});
eLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this, "Login successfully..",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(MainActivity.this,
HomePageActivity.class);
startActivity(intent);
}
});
}
private boolean validate(String user, String password){
if(user.equals(Username) && password.equals(Password)){
return true;
}
return false;
}

//HomePageActivity.java
package com.example.login;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import static com.example.login.MainActivity.Username;
public class HomePageActivity extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
textView=findViewById(R.id.textView);
//textView.setText("Login successfully", (CharSequence) eUser);
textView.setText("Login successfully " + Username);
EXPERIMENT NO. :29

//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:padding="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_phone"
android:hint="Enter phone number"
android:padding="12dp"
android:maxLength="15"
android:inputType="phone"
android:background="@android:drawable/editbox_background"/>

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@android:drawable/editbox_background">
<EditText
android:id="@+id/viewmsg"
android:layout_width="match_parent"
android:layout_height="400dp"
android:textColor="#000000"
android:textSize="30dp"
android:enabled="false"
android:foregroundGravity="bottom"
android:freezesText="true"
android:gravity="bottom"
android:layout_weight="1"
android:textIsSelectable="false"/>
<EditText
android:id="@+id/viewme"
android:layout_width="match_parent"
android:layout_height="400dp"
android:textColor="#000000"
android:textSize="30dp"
android:layout_weight="1"
android:enabled="false"
android:foregroundGravity="bottom"
android:freezesText="true"
android:gravity="bottom"
android:textIsSelectable="false"/>
</LinearLayout>
<EditText
android:layout_width="match_parent"
android:layout_height="90dp"
android:id="@+id/et_massage"
android:padding="12dp"
android:minLines="6"
android:inputType="textMultiLine"
android:gravity="top"
android:layout_marginBottom="8dp"
android:hint="Enter Text"
android:background="@android:drawable/editbox_background"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/bt_send"
android:text="Send"
android:layout_gravity="center"
android:layout_marginTop="3dp" />
</LinearLayout

//java part 
//MainActivity.java
package com.example.smsr;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Switch;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
public static EditText etPhone,etMessage,etme;
Button btSend;
public static EditText mm;
public static TextView m;
private static final int MY_PERMISSIONS_REQUEST_RECEIVE_SMS = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mm = findViewById(R.id.viewmsg);
etPhone = findViewById(R.id.et_phone);
etMessage = findViewById(R.id.et_massage);
etme = findViewById(R.id.viewme);
btSend = findViewById(R.id.bt_send);
btSend.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (ContextCompat.checkSelfPermission(MainActivity.this
, Manifest.permission.SEND_SMS)
== PackageManager.PERMISSION_GRANTED){
sendMessage();
}else {
ActivityCompat.requestPermissions(MainActivity.this
,new String[]{Manifest.permission.SEND_SMS}
,100);
}
}
});
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.RECEIVE_SMS) != PackageManager.PERMISSION_GRANTED)
{
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.RECEIVE_SMS))
{
}
else
{
ActivityCompat.requestPermissions(this, new String[]
{Manifest.permission.RECEIVE_SMS}, MY_PERMISSIONS_REQUEST_RECEIVE_SMS);
}
}
}
@Override
public void onRequestPermissionsResult (int requestCode, String permissions[],
int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode)
{
case MY_PERMISSIONS_REQUEST_RECEIVE_SMS:
{
if (grantResults.length>0 &&
grantResults[0]==PackageManager.PERMISSION_GRANTED)
{
Toast.makeText(this,"Thankyou for
permitting!",Toast.LENGTH_SHORT).show();
}
else
{
Toast.makeText(this,"Well I can't do anything until you permit
me", Toast.LENGTH_SHORT).show();
}
}
}
if (requestCode == 100 && grantResults.length > 0 && grantResults[0]
== PackageManager.PERMISSION_GRANTED){
sendMessage();
}else {
Toast.makeText(getApplicationContext()
,"Permission Denied!", Toast.LENGTH_SHORT).show();
}
}
private void sendMessage() {
String sPhone = etPhone.getText().toString().trim();
String sMessage = etMessage.getText().toString().trim();
etme.setText(sMessage);
if (!sPhone.equals("") && !sMessage.equals("")){
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(sPhone,null,sMessage
,null,null);
Toast.makeText(getApplicationContext()
, "SMS sent successfully!",Toast.LENGTH_SHORT).show();
etMessage.setText("");
}else {
Toast.makeText(getApplicationContext()
,"Enter number first.",Toast.LENGTH_SHORT).show();
}
}

}
EXPERIMENT NO. 31

//xml part 
//activity_maps.xml
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.map">
<uses-permission android:name="android.permission.ACCESS_FINE_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/Theme.Map">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

//java part 
//MainActivity.java
package com.example.map;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is ready to
be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(20.5937, 78.9629);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in
India"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

EXPERIMENT NO. 30
//xml part 
//activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity"
android:padding="20dp">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/et_phone"
android:hint="Enter phone number"
android:padding="12dp"
android:maxLength="15"
android:inputType="phone"
android:background="@android:drawable/editbox_background"/>
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/Theme.Map">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity> protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
eUser = findViewById(R.id.userid);
ePassword = findViewById(R.id.passwordid);
eLogin = findViewById(R.id.loginid);
constraintLayout = findViewById(R.id.k);
eLogin.setEnabled(false);
ePassword.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int
count) {String inputUser = eUser.getText().toString();
String inputPassword = ePassword.getText().toString();
if(inputUser.isEmpty() || inputPassword.isEmpty())
{
Toast.makeText(MainActivity.this, "Please enter all the
details correctly!", Toast.LENGTH_SHORT).show();
}else{
isValid = validate(inputUser, inputPassword);
if(!isValid){
Toast.makeText(MainActivity.this, "Invalidate username or
password", Toast.LENGTH_SHORT).show();
eLogin.setEnabled(false);
}else
{ //java part 
//MainActivity.java
package com.example.bluetooth2;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import java.time.Year;
import java.util.Set;
public class MainActivity extends AppCompatActivity {
private static final int REQUEST_ENABLE_BT = 0;
private static final int REQUEST_DISCOVER_BT = 1;
TextView mStatusBlueTv, mPairedTv;
ImageView mBlueIv;
Button mOnBtn, mOffBtn, mDiscoverBtn, mPairedBtn;
BluetoothAdapter mBlueAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mStatusBlueTv = findViewById(R.id.statuseBluetoothTv);
mPairedTv = findViewById(R.id.paidTv);
mBlueIv = findViewById(R.id.blutooth);
mOnBtn = findViewById(R.id.onBtn);
mOffBtn = findViewById(R.id.offBtn);
mDiscoverBtn= findViewById(R.id.discoverableBtn);
mPairedBtn = findViewById(R.id.paireBtn);
mBlueAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBlueAdapter == null) {
mStatusBlueTv.setText("Bluetooth is not available");
} else {
mStatusBlueTv.setText("Blutooth is available");
}
if (mBlueAdapter.isEnabled()) {
} else {
mBlueIv.setImageResource(R.drawable.ic_action_off);
}
//on btn
mOnBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBlueAdapter.isEnabled()) {
showToast("Turn On Bluetooth...");
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(intent, REQUEST_ENABLE_BT);
} else {
showToast("Bluetooth is already on");
}
}
});
//discover
mDiscoverBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!mBlueAdapter.isDiscovering()) {
showToast("Making Your Device Discoverable");
Intent intent = new
Intent(BluetoothAdapter.ACTION_REQUEST_DISCOVERABLE);
startActivityForResult(intent, REQUEST_DISCOVER_BT);
}
}

You might also like