//program 2 calculator package com.girish.simplecalculator; 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; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button but_Add,but_Sub,but_Mul,but_Div; EditText txt_Num1,txt_Num2; TextView txt_Res; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); but_Add = (Button) findViewById(R.id.butAdd); but_Sub = (Button) findViewById(R.id.butSub); but_Mul = (Button) findViewById(R.id.butMul); but_Div = (Button) findViewById(R.id.butDiv); txt_Num1 = (EditText) findViewById(R.id.txtNum1); txt_Num2 = (EditText) findViewById(R.id.txtNum2); txt_Res = (TextView) findViewById(R.id.txtResult1); but_Add.setOnClickListener(this); but_Sub.setOnClickListener(this); but_Mul.setOnClickListener(this); but_Div.setOnClickListener(this); } @Override public void onClick(View v) { double op1 = Double.parseDouble(txt_Num1.getText().toString()); double op2 = Double.parseDouble(txt_Num2.getText().toString()); double Res; if(v.equals(but_Add)) Res = op1 + op2; else if(v.equals(but_Sub)) Res = op1 - op2; else if(v.equals(but_Mul)) Res = op1 * op2; else if(v.equals(but_Div)) Res = op1 / op2; else Res = 0; txt_Res.setText(String.valueOf(Res)); } } //prog 3 signup # login.java package com.girish.signup; 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.Toast; import java.util.regex.Matcher; import java.util.regex.Pattern; public class MainActivity extends AppCompatActivity implements View.OnClickListener { EditText txtUsername; EditText txtPassword; Button btnSignup; String regularExpression = "^(?=.*[A-Z])(?=.*[a-z])(?=.*\\d)(?=.*[@$!])[A-Za-z\\d@$!]{8,}$"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txtUsername = (EditText) findViewById(R.id.txt_login_username); txtPassword = (EditText) findViewById(R.id.txt_login_password); btnSignup = (Button) findViewById(R.id.btn_login_signup); btnSignup.setOnClickListener(this); } public void onClick(View v) { String username = txtUsername.getText().toString(); String password = txtPassword.getText().toString(); if (validatePassword(password)) { Bundle bundle = new Bundle(); bundle.putString("user", username); bundle.putString("pass", password); Intent it = new Intent(this, Login.class); it.putExtra("data", bundle); startActivity(it); } else { Toast.makeText(getBaseContext(), "Invalid Password", Toast.LENGTH_LONG).show(); } } private boolean validatePassword(String password) { Pattern pattern = Pattern.compile(regularExpression); Matcher matcher = pattern.matcher(password); return matcher.matches(); } } #login.java package com.girish.signup; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.Toast; public class Login extends AppCompatActivity implements View.OnClickListener { EditText txtLoginUsername,txtLoginPassword; Button btnLogin; String user,pass; int count = 0; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); txtLoginUsername = (EditText) findViewById(R.id.txt_login_username); txtLoginPassword = (EditText) findViewById(R.id.txt_login_password); btnLogin = (Button) findViewById(R.id.btn_login_signup); btnLogin.setOnClickListener(this); Bundle bundle = getIntent().getBundleExtra("data"); user = bundle.getString("user"); pass = bundle.getString("pass"); } @Override public void onClick(View v) { String user1 = txtLoginUsername.getText().toString(); String pass1 = txtLoginPassword.getText().toString(); if(user.equals(user1)&&pass.equals(pass1)) { Toast.makeText(this,"Login Successful",Toast.LENGTH_LONG).show(); } else { count++; if(count == 3) { btnLogin.setEnabled(false); Toast.makeText(this,"Failed Login Attempts",Toast.LENGTH_LONG).show(); } else { Toast.makeText(this,"Login Failed"+count,Toast.LENGTH_LONG).show(); } } } } //prog4 wallpaper package com.girish.wallpaper; import androidx.appcompat.app.AppCompatActivity; import android.app.WallpaperManager; import android.graphics.BitmapFactory; import android.os.Bundle; import android.view.View; import android.widget.Button; import java.io.IOException; import java.util.Random; import java.util.Timer; import java.util.TimerTask; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button btn; boolean running; int[] ia = new int[]{R.drawable.img1,R.drawable.img2,R.drawable.img3,R.drawable.img4,R.drawable.img5}; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btn = (Button) findViewById(R.id.btn_wall); btn.setOnClickListener(this); } @Override public void onClick(View v) { if(!running){ new Timer().schedule(new MyTimer(),0,1000); running = true; } } private class MyTimer extends TimerTask { @Override public void run() { try{ WallpaperManager wallpaperManager = WallpaperManager.getInstance(getBaseContext()); Random random = new Random(); wallpaperManager.setBitmap(BitmapFactory.decodeResource(getResources(),ia[random.nextInt(5)])); } catch (IOException e) { } } } } //prog5 counter package com.girish.counterapplication; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.View; import android.widget.Button; import android.widget.TextView; public class MainActivity extends AppCompatActivity implements View.OnClickListener { TextView lblCounter; Button btnStart,btnStop; int counter = 0; boolean running = false; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); lblCounter = (TextView) findViewById(R.id.lbl_text); btnStart = (Button) findViewById(R.id.btn_start); btnStop = (Button) findViewById(R.id.btn_stop); btnStart.setOnClickListener(this); btnStop.setOnClickListener(this); } @Override public void onClick(View v) { if(v.equals(btnStart)){ counter = 0; running = true; new MyCounter().start(); } else if (v.equals(btnStop)) { running = false; } } Handler handler = new Handler() { public void handleMessage(Message m) { lblCounter.setText(String.valueOf(m.what)); } }; class MyCounter extends Thread{ public void run(){ while(running){ counter++; handler.sendEmptyMessage(counter); try{ Thread.sleep(1000); } catch (Exception e){ } } } } } //prog6 xml & json #mainactiviy.JAVA package com.girish.parsingxmljson; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.Button; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button btnParseXml,btnParseJson; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnParseXml = (Button) findViewById(R.id.btn_parsexml); btnParseJson = (Button) findViewById(R.id.btn_parsejson); btnParseXml.setOnClickListener(this); btnParseJson.setOnClickListener(this); } @Override public void onClick(View v) { if(v.equals(btnParseJson)){ Intent it = new Intent(this,ViewActivity.class); it.putExtra("mode",1); startActivity(it); } else if(v.equals(btnParseXml)){ Intent it = new Intent(this,ViewActivity.class); it.putExtra("mode",2); startActivity(it); } } } #viewactiviy.java package com.girish.parsingxmljson; import androidx.appcompat.app.AppCompatActivity; import android.annotation.SuppressLint; import android.os.Bundle; import android.widget.TextView; import org.json.JSONException; import org.json.JSONObject; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import java.io.IOException; import java.io.InputStream; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; public class ViewActivity extends AppCompatActivity { TextView lblXmlData,lblJsonData; int mode = 0; @SuppressLint("MissingInflatedId") @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_view); lblXmlData = (TextView) findViewById(R.id.lbl_xml_data); lblJsonData = (TextView) findViewById(R.id.lbl_json_data); mode = getIntent().getIntExtra("mode",0); if(mode == 1) parseJson(); else parseXml(); } private void parseXml() { try{ InputStream is = getAssets().open("input.xml"); DocumentBuilderFactory db = DocumentBuilderFactory.newInstance(); DocumentBuilder b = db.newDocumentBuilder(); Document doc = b.parse(is); Element e = doc.getDocumentElement(); e.normalize(); NodeList list = doc.getElementsByTagName("weather"); for(int i = 0; i Ballari 12.295 76.639 22 90% //prog7 text to speech #mainactivity.java package com.girish.texttospeech; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.speech.tts.TextToSpeech; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; import java.util.Locale; public class MainActivity extends AppCompatActivity implements View.OnClickListener, TextToSpeech.OnInitListener { EditText txt; Button btnSp; TextToSpeech txtSp; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); txt = (EditText) findViewById(R.id.editText); btnSp = (Button) findViewById(R.id.btn_speak); btnSp.setOnClickListener(this); txtSp = new TextToSpeech(getBaseContext(),this); txtSp.setLanguage(Locale.UK); } @Override public void onClick(View v) { String text = txt.getText().toString(); txtSp.speak(text,TextToSpeech.QUEUE_FLUSH,null); } @Override public void onInit(int status) { if(status!= TextToSpeech.ERROR){ Toast.makeText(getBaseContext(),"Success",Toast.LENGTH_LONG).show(); } } } //prog8 call & save #mainactivity.java package com.girish.cs; import androidx.appcompat.app.AppCompatActivity; import android.content.Intent; import android.net.Uri; import android.os.Bundle; import android.provider.ContactsContract; import android.view.View; import android.widget.Button; import android.widget.EditText; public class MainActivity extends AppCompatActivity implements View.OnClickListener { Button btnOne, btnTwo, btnThree, btnFour, btnFive, btnSix, btnSeven, btnEight, btnNine, btnZero; Button btnSave, btnDel, btnStar, btnHash, btnCall; EditText txtPhone; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnOne = (Button) findViewById(R.id.btn_one); btnOne.setOnClickListener(this); btnTwo = (Button) findViewById(R.id.btn_two); btnTwo.setOnClickListener(this); btnThree = (Button) findViewById(R.id.btn_three); btnThree.setOnClickListener(this); btnFour = (Button) findViewById(R.id.btn_four); btnFour.setOnClickListener(this); btnFive = (Button) findViewById(R.id.btn_five); btnFive.setOnClickListener(this); btnSix = (Button) findViewById(R.id.btn_six); btnSix.setOnClickListener(this); btnSeven = (Button) findViewById(R.id.btn_seven); btnSeven.setOnClickListener(this); btnEight = (Button) findViewById(R.id.btn_eight); btnEight.setOnClickListener(this); btnNine = (Button) findViewById(R.id.btn_nine); btnNine.setOnClickListener(this); btnZero = (Button) findViewById(R.id.btn_zero); btnZero.setOnClickListener(this); btnSave = (Button) findViewById(R.id.btn_save); btnSave.setOnClickListener(this); btnCall = (Button) findViewById(R.id.btn_call); btnCall.setOnClickListener(this); btnHash = (Button) findViewById(R.id.btn_hash); btnHash.setOnClickListener(this); btnStar = (Button) findViewById(R.id.btn_star); btnStar.setOnClickListener(this); btnDel = (Button) findViewById(R.id.btn_delete); btnDel.setOnClickListener(this); txtPhone = (EditText) findViewById(R.id.txt_phonenumber); txtPhone.setText(""); } @Override public void onClick(View v) { if (v.equals(btnOne)) txtPhone.append("1"); else if (v.equals(btnTwo)) txtPhone.append("2"); else if (v.equals(btnThree)) txtPhone.append("3"); else if (v.equals(btnFour)) txtPhone.append("4"); else if (v.equals(btnFive)) txtPhone.append("5"); else if (v.equals(btnSix)) txtPhone.append("6"); else if (v.equals(btnSeven)) txtPhone.append("7"); else if (v.equals(btnEight)) txtPhone.append("8"); else if (v.equals(btnNine)) txtPhone.append("9"); else if (v.equals(btnZero)) txtPhone.append("0"); else if (v.equals(btnHash)) txtPhone.append("#"); else if (v.equals(btnStar)) txtPhone.append("*"); else if (v.equals(btnSave)) { Intent contactIntent = new Intent(ContactsContract.Intents.Insert.ACTION); contactIntent.setType(ContactsContract.RawContacts.CONTENT_TYPE); contactIntent.putExtra(ContactsContract.Intents.Insert.NAME, "Parveen"); contactIntent.putExtra(ContactsContract.Intents.Insert.PHONE, txtPhone.getText().toString()); startActivity(contactIntent); } else if (v.equals(btnDel)) { String data = txtPhone.getText().toString(); if (data.length() > 0) txtPhone.setText(data.substring(0, data.length() - 1)); else txtPhone.setText(""); } btnCall.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { String data = txtPhone.getText().toString(); Intent i = new Intent(Intent.ACTION_DIAL); i.setData(Uri.parse("tel:" + data)); startActivity(i); } }); } }