Mad Lab Programs: Program 1: Visiting Card
Mad Lab Programs: Program 1: Visiting Card
Mad Lab Programs: Program 1: Visiting Card
<TextView
android:id="@+id/textView"
android:layout_width="149dp"
android:layout_height="80dp"
android:fontFamily="cursive"
android:paddingLeft="5sp"
android:paddingTop="10sp"
android:text="Welcome"
android:textColor="@color/teal_700"
android:textSize="40sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.232"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.196" />
<View
android:id="@+id/divider"
android:layout_width="380dp"
android:layout_height="5dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@color/black"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.282" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:fontFamily="serif"
android:padding="5sp"
android:text="Name:"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.112"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="60dp"
android:fontFamily="serif"
android:text="Class:"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2" />
<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="120dp"
android:layout_marginTop="20dp"
android:fontFamily="sans-serif-smallcaps"
android:padding="5sp"
android:text="Shreesha"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.014"
app:layout_constraintStart_toEndOf="@+id/textView2"
app:layout_constraintTop_toBottomOf="@+id/divider" />
<TextView
android:id="@+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:fontFamily="sans-serif-smallcaps"
android:padding="5sp"
android:text="6B"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/textView3"
app:layout_constraintTop_toBottomOf="@+id/textView4" />
<TextView
android:id="@+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="36dp"
android:layout_marginTop="60dp"
android:fontFamily="serif"
android:text="Phone Number:"
android:textSize="22sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView3" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="60dp"
android:fontFamily="sans-serif-smallcaps"
android:padding="5sp"
android:text="9119119110"
android:textSize="20sp"
android:textStyle="bold|italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.06"
app:layout_constraintStart_toEndOf="@+id/textView6"
app:layout_constraintTop_toBottomOf="@+id/textView5" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click here"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"
app:layout_constraintVertical_bias="0.792" />
<View
android:id="@+id/divider2"
android:layout_width="380dp"
android:layout_height="5dp"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:background="@color/black"
app:layout_constraintBottom_toTopOf="@+id/button1"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.741"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/divider"
app:layout_constraintVertical_bias="0.948" />
<ImageView
android:id="@+id/imageView2"
android:layout_width="168dp"
android:layout_height="173dp"
android:layout_marginStart="40dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintCircleRadius="30sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/textView"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.011"
app:srcCompat="@drawable/index" />
</androidx.constraintlayout.widget.ConstraintLayout>
----------------------------------------------------------------------------------------------------------------------------- --------
PROGRAM 2: CALCUALOTOR
package com.example.calculator_b2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import java.text.DecimalFormat;
import java.util.Stack;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
badd = findViewById(R.id.btn_plus);
bsub = findViewById(R.id.btn_minus);
bmul = findViewById(R.id.btn_mul);
bdiv = findViewById(R.id.btn_div);
bper = findViewById(R.id.btn_per);
bac = findViewById(R.id.btn_ac);
bpm = findViewById(R.id.btn_pm);
beq = findViewById(R.id.btn_eq);
bdec = findViewById(R.id.btn_dec);
b0 = findViewById(R.id.btn0);
b1 = findViewById(R.id.btn1);
b2 = findViewById(R.id.btn2);
b3 = findViewById(R.id.btn3);
b4 = findViewById(R.id.btn4);
b5 = findViewById(R.id.btn5);
b6 = findViewById(R.id.btn6);
b7 = findViewById(R.id.btn7);
b8 = findViewById(R.id.btn8);
b9 = findViewById(R.id.btn9);
textView = findViewById(R.id.txtView);
bpm.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
op1*=-1;
textView.setText(String.valueOf(op1));
}
});
b0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("0");
textView.setText(sb.toString());
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("1");
textView.setText(sb.toString());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("2");
textView.setText(sb.toString());
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("3");
textView.setText(sb.toString());
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("4");
textView.setText(sb.toString());
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("5");
textView.setText(sb.toString());
}
});
b6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("6");
textView.setText(sb.toString());
}
});
b7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("7");
textView.setText(sb.toString());
}
});
b8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("8");
textView.setText(sb.toString());
}
});
b9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("9");
textView.setText(sb.toString());
}
});
badd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
ns.push(op1);
os.push("+");
textView.setText("");
sb.delete(0,sb.length());
decFlag=false;
}
});
bsub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
ns.push(op1);
os.push("-");
textView.setText("");
sb.delete(0,sb.length());
decFlag=false;
}
});
bmul.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
ns.push(op1);
os.push("*");
textView.setText("");
sb.delete(0,sb.length());
decFlag=false;
}
});
bper.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
ns.push(op1);
os.push("%");
textView.setText("");
sb.delete(0,sb.length());
decFlag=false;
}
});
bdiv.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
op1 = Double.parseDouble(textView.getText().toString());
ns.push(op1);
os.push("/");
textView.setText("");
sb.delete(0,sb.length());
decFlag=false;
}
});
bdec.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!decFlag){
decFlag=true;
sb.append(".");
textView.setText(sb.toString());
}
}
});
beq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
operand = os.pop();
op2 = Double.parseDouble(textView.getText().toString());
sb.delete(0,sb.length());
op1 = ns.pop();
switch (operand){
case "+":
res = op1 + op2;
break;
case "-":
res = op1 - op2;
break;
case "/":
res = op1 / op2;
break;
case "*":
res = op1 * op2;
break;
case "%":
res = op1 % op2;
break;
}
textView.setText(String.valueOf(Math.round(res * 100.0) / 100.0));
}
});
bac.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
decFlag=false;
operand = "";
op1 = 0;
op2 = 0;
sb.delete(0,sb.length());
while(!ns.empty()) ns.pop();
while(!os.empty()) os.pop();
textView.setText("");
}
});
}
}
----------------------------------------------------------------------------------------------------------------------------- --------
package com.example.signup_b2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@Override
public void onClick(View view) {
if(validate()) {
package com.example.signup_b2;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.webkit.CookieManager;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.EditText;
@Override
public void onClick(View view) {
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
uname = bundle.getString("name");
upass = bundle.getString("pass");
if(validate()) {
WebView webView = new WebView(this);
setContentView(webView);
webView.loadUrl("https://google.com");
CookieManager.getInstance().removeAllCookies(null);
CookieManager.getInstance().flush();
}
else {
if(count<=0){
signInBtn.setEnabled(false);
return;
}
if (uname.length() != lname.length()) userName.setError("Username is
not there");
if (upass.length() != lpass.length()) {
count--;
password.setError("Number of attempts left: " + count);
}
}
}
PROGRAM 4: WALLPAPER
package com.example.wallpaper_b2;
import androidx.appcompat.app.AppCompatActivity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.BoringLayout;
import android.util.DisplayMetrics;
import android.view.View;
import java.io.IOException;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
}
--------------------------------------------------------------------------------------------------------
PROGRAM 5: COUNTER
package com.example.counter_b2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.view.View;
import android.widget.TextView;
int count=0;
volatile boolean isStopped = true;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView2);
}
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
XmlPullParserFactory pullParserFactory;
XmlPullParser parser;
InputStream is;
RequestQueue requestQueue;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
xmlBtn = findViewById(R.id.XMLbutton);
jsonBtn = findViewById(R.id.JSONbutton);
xmlTV = findViewById(R.id.XMLTextView);
jsonTV = findViewById(R.id.JSONTextView);
xmlBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
parseXMLFile();
}
});
jsonBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
parseJSONFile();
}
});
requestQueue = Volley.newRequestQueue(this);
}
--------------------------------------------------------------------------------------------------------
import androidx.appcompat.app.AppCompatActivity;
import android.content.Context;
import android.media.AudioManager;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.SeekBar;
import java.util.Locale;
speakBtn = findViewById(R.id.button);
pitchSB = findViewById(R.id.seekPitch);
speedSB = findViewById(R.id.seekSpeed);
speechText = findViewById(R.id.editText);
volUp = findViewById(R.id.volumeUp);
volDown = findViewById(R.id.volumeDown);
audioManager = (AudioManager)
getApplicationContext().getSystemService(Context.AUDIO_SERVICE);
textToSpeech = new TextToSpeech(this, new
TextToSpeech.OnInitListener() {
@Override
public void onInit(int i) {
if(i == TextToSpeech.SUCCESS){
int avail = textToSpeech.isLanguageAvailable(Locale.UK);
if(avail!=TextToSpeech.LANG_NOT_SUPPORTED){
speakBtn.setEnabled(true);
}
else {
speakBtn.setEnabled(false);
}
}
}
});
speakBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
speak();
}
});
volUp.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
audioManager.adjustVolume(AudioManager.ADJUST_RAISE,
AudioManager.FLAG_PLAY_SOUND);
}
});
volDown.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
audioManager.adjustVolume(AudioManager.ADJUST_LOWER,
AudioManager.FLAG_PLAY_SOUND);
}
});
}
if(picth<0.1) picth=0.1f;
if(speed<0.1) speed=0.1f;
textToSpeech.setPitch(picth);
textToSpeech.setSpeechRate(speed);
@Override
protected void onDestroy() {
if(textToSpeech!=null){
textToSpeech.stop();
textToSpeech.shutdown();
}
super.onDestroy();
}
}
--------------------------------------------------------------------------------------------------------
import android.Manifest;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
ImageButton imageButton;
EditText editText;
Button b0,b1,b2,b3,b4,b5,b6,b7,b8,b9,bsave,bhash,bstar,bcall;
StringBuilder sb = new StringBuilder();
String phoneNumber;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
imageButton = findViewById(R.id.imageButton);
bsave = findViewById(R.id.save);
bhash = findViewById(R.id.hash);
bcall = findViewById(R.id.callBtn);
bstar = findViewById(R.id.asterisk);
b0 = findViewById(R.id.no0);
b1 = findViewById(R.id.no1);
b2 = findViewById(R.id.no2);
b3 = findViewById(R.id.no3);
b4 = findViewById(R.id.no4);
b5 = findViewById(R.id.no5);
b6 = findViewById(R.id.no6);
b7 = findViewById(R.id.no7);
b8 = findViewById(R.id.no8);
b9 = findViewById(R.id.no9);
editText = findViewById(R.id.number);
if(ContextCompat.checkSelfPermission(MainActivity.this,
Manifest.permission.CALL_PHONE)!=
PackageManager.PERMISSION_GRANTED){
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{Manifest.permission.CALL_PHONE},PackageManager.PERMISSION_GR
ANTED);
}
b0.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("0");
editText.setText(sb.toString());
}
});
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("1");
editText.setText(sb.toString());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("2");
editText.setText(sb.toString());
}
});
b3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("3");
editText.setText(sb.toString());
}
});
b4.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("4");
editText.setText(sb.toString());
}
});
b5.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("5");
editText.setText(sb.toString());
}
});
b6.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("6");
editText.setText(sb.toString());
}
});
b7.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("7");
editText.setText(sb.toString());
}
});
b8.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("8");
editText.setText(sb.toString());
}
});
b9.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("9");
editText.setText(sb.toString());
}
});
bcall.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(validate()){
startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"+
editText.getText().toString())));
}
}
});
bsave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(validate()){
Intent intent = new Intent(ContactsContract.Intents.Insert.ACTION);
intent.setType(ContactsContract.RawContacts.CONTENT_TYPE);
intent.putExtra(ContactsContract.Intents.Insert.PHONE,editText.getText().toStr
ing());
startActivity(intent);
}
}
});
bstar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("*");
editText.setText(sb.toString());
}
});
bhash.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
sb.append("#");
editText.setText(sb.toString());
}
});
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(validate()){
sb = new StringBuilder(phoneNumber);
if(sb.length()==1){
sb.deleteCharAt(0);
}
else {
sb.deleteCharAt(sb.length()-1);
}
editText.setText(sb.toString());
}
}
});
}