0% found this document useful (0 votes)
58 views13 pages

Practical 27, 28, 22

This document contains code for a login screen Android application. It includes XML layout code defining the user interface elements like text views, edit texts and a button. It also includes Java code for the MainActivity class that handles login authentication. The UI contains fields for username and password, a login button and text to display number of login attempts remaining. The Java code checks the input against hardcoded credentials and displays success/failure toasts.
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)
58 views13 pages

Practical 27, 28, 22

This document contains code for a login screen Android application. It includes XML layout code defining the user interface elements like text views, edit texts and a button. It also includes Java code for the MainActivity class that handles login authentication. The UI contains fields for username and password, a login button and text to display number of login attempts remaining. The Java code checks the input against hardcoded credentials and displays success/failure toasts.
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
You are on page 1/ 13

Practical 27: -

<?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="#FFC107"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="serif-monospace"
android:foregroundGravity="center_vertical|clip_horizontal|center"
android:text="LOGIN"
android:textColor="@color/black"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.134"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />

<EditText
android:id="@+id/edt1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="74dp"
android:background="#ECECEC"
android:ems="10"
android:fontFamily="serif-monospace"
android:hint="Username"
android:inputType="textPersonName"
android:padding="12dp"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/edt2"
app:layout_constraintEnd_toEndOf="@+id/edt2"
app:layout_constraintStart_toStartOf="@+id/edt2"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/edt2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginBottom="90dp"
android:background="#ECECEC"
android:ems="10"
android:fontFamily="serif-monospace"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
android:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt1" />

<Button
android:id="@+id/button"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="204dp"
android:backgroundTint="#E91E63"
android:fontFamily="serif-monospace"
android:onClick="formLogin"
android:text="Login"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt2"
app:rippleColor="@color/black" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="78dp"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.828" />
</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.practical27;
import androidx.appcompat.app.AppCompatActivity;
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 {
EditText ed1, ed2;
TextView tv;
Button b1;
int count;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.edt1);
ed2 = findViewById(R.id.edt2);
tv = findViewById(R.id.textView2);
b1 = findViewById(R.id.button);
count = 3;
tv.setText("You have only "+count+" Attempts");
}
public void formLogin(View view){
String uname, passwd;
uname = ed1.getText().toString();
passwd = ed2.getText().toString();
count--;
tv.setText("Attempts left: "+count);
if (count == 0){
b1.setEnabled(false);
}
if (uname.equals("") && passwd.equals("")){
Toast.makeText(MainActivity.this, "Please enter username and password",
Toast.LENGTH_SHORT).show();
} else if (passwd.length() < 8){
Toast.makeText(MainActivity.this, "Password should be 8 charecter long",
Toast.LENGTH_SHORT).show();
} else if (uname.equals("Admin") &&
passwd.equals("12345678")){
Toast.makeText(MainActivity.this, "Login successful", Toast.LENGTH_SHORT).show();
tv.setText("");
}
}
}
Practical no: - 28
<?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="#FFC107"
tools:context=".MainActivity">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="casual"
android:text="LOGIN"
android:textColor="@color/black"
android:textSize="34sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.134"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.134" />

<EditText
android:id="@+id/edt1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="74dp"
android:background="#FFC107"
android:ems="10"
android:fontFamily="casual"
android:hint="Username"
android:inputType="textPersonName"
android:padding="12dp"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/edt2"
app:layout_constraintEnd_toEndOf="@+id/edt2"
app:layout_constraintStart_toStartOf="@+id/edt2"
app:layout_constraintTop_toBottomOf="@+id/textView" />

<EditText
android:id="@+id/edt2"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_marginStart="44dp"
android:layout_marginBottom="90dp"
android:background="#FFC107"
android:ems="10"
android:fontFamily="casual"
android:hint="Password"
android:inputType="textPassword"
android:padding="12dp"
android:textColor="@color/black"
android:textSize="20sp"
app:layout_constraintBottom_toTopOf="@+id/button"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt1" />

<Button
android:id="@+id/button"
android:layout_width="140dp"
android:layout_height="wrap_content"
android:layout_marginBottom="204dp"
android:backgroundTint="#FF5722"
android:fontFamily="casual"
android:onClick="formLogin"
android:text="Login"
android:textColor="@color/black"
android:textSize="24sp"
app:cornerRadius="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edt2" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="78dp"
android:textColor="#000000"
android:textSize="20sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/button"
app:layout_constraintVertical_bias="0.828" />
</androidx.constraintlayout.widget.ConstraintLayout>

package com.example.practicalno28;
import androidx.appcompat.app.AppCompatActivity;
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 {
EditText ed1, ed2;
TextView tv;
Button b1;
int count;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ed1 = findViewById(R.id.edt1);
ed2 = findViewById(R.id.edt2);
tv = findViewById(R.id.textView2);
b1 = findViewById(R.id.button);
count = 3;
tv.setText("You have only "+count+" Attempts");
}
public void formLogin(View view){
String uname, passwd;
uname = ed1.getText().toString();
passwd = ed2.getText().toString();
count--;
tv.setText("Attempts left: "+count);
if (count == 0){
b1.setEnabled(false);
}
if (uname.equals("") && passwd.equals("")){
Toast.makeText(MainActivity.this, "Please enter username and password",
Toast.LENGTH_SHORT).show();
} else if (passwd.length() < 8){
Toast.makeText(MainActivity.this, "Password should be 8 charecter long",
Toast.LENGTH_SHORT).show();
} else if (uname.equals("sejal") &&
passwd.equals("24032005")){
Toast.makeText(MainActivity.this, "Login successful", Toast.LENGTH_SHORT).show();
tv.setText("");
}
}
}
Practical no: - 22
<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:textColor="@color/black"
android:textSize="24sp"
android:textStyle="bold" />

</RelativeLayout>

package com.example.practical22;
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.GREEN);
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.BLACK);

} else {
view.setBackgroundColor(Color.YELLOW);
}
isColor = !isColor;
}
}

@Override
protected void onResume() {
super.onResume();

sensorManager.registerListener(this,sensorManager.getDefaultSensor(Sensor.TYPE_ACCELER
OMETER),
SensorManager.SENSOR_DELAY_NORMAL);
}

@Override
protected void onPause() {

super.onPause();
sensorManager.unregisterListener(this);
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy