Sushant Poojary 2067 MAD-Journal Sybsc Cs-A: Certificate
Sushant Poojary 2067 MAD-Journal Sybsc Cs-A: Certificate
Sushant Poojary 2067 MAD-Journal Sybsc Cs-A: Certificate
Sushant Poojary
2067
MAD-Journal
SYBSc CS-A
Sushant Poojary MAD 2067
CERTIFICATE
Date:30/03/21
Place: Mumbai
Examiner
DATE TOPIC
SR
NO.
2 22/01/21 Create an android app with Interactive User Interface using Relative
Layouts. (e.g. simple calculator)
4 05/02/21 Create an android app that demonstrates the use of Keyboards, Input
Controls, Alerts, and Pickers.
5 12/02/21 Create an android app that demonstrates the use of an Options Menu.
6 26/02/21 Create an android app that demonstrate Screen Navigation Using the
App Bar and Tabs.
9 19/03/21 Create an android app to save user data in a database and use of
different queries.
10 26/03/21 Create an android app that uses MySQL Server using suitable
server side scripting programs.
15/01/21
Practical 1
Sushant Poojary MAD 2067 Aim: Install Android Studio and Run Hello World Program.
INSTALLATION:
1:
2:
3:
Sushant Poojary MAD 2067
4:
5:
Sushant Poojary MAD 2067
6:
7:
Sushant Poojary MAD 2067
8:
9:
Sushant Poojary MAD 2067
10:
11:
Sushant Poojary MAD 2067
12:
13:
Sushant Poojary MAD 2067
14:
15:
Sushant Poojary MAD 2067
16:
2:
3:
Sushant Poojary MAD 2067
Conclusion:
22/01/21
Sushant Poojary MAD 2067 Practical 2
Aim: Create an android app with Interactive User Interface using Relative Layouts.
(e.g. simple calculator)
Code:
Actitvity_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"
tools:context=".MainActivity">
<EditText
android:id="@+id/etNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.252" />
<EditText
android:id="@+id/etNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.362" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="addNumber"
android:text="Addition"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.169"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
Sushant Poojary MAD 2067
app:layout_constraintVertical_bias="0.512" />
<Button
android:id="@+id/btnSub"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="subNumber"
android:text="Subtration"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.183"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.632" />
<Button
android:id="@+id/btnMul"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="mulNumber"
android:text="Multiplication"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.75"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.512" />
<Button
android:id="@+id/btnDiv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="divNumber"
android:text="Division"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.759"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.642" />
<EditText
android:id="@+id/editTextTextPersonName2"
android:layout_width="163dp"
android:layout_height="50dp"
android:ems="10"
android:inputType="textPersonName"
android:text="@string/developer_name"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.846"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.951" />
<TextView
android:id="@+id/tVResult"
android:layout_width="81dp"
android:layout_height="39dp"
Sushant Poojary MAD 2067
android:text="Ans"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.545"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.744" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java :
package com.srs.calculator;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
TextView tVResult;
EditText etNum1,etNum2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tVResult = findViewById(R.id.tVResult);
etNum1 = findViewById(R.id.etNum1);
etNum2 = findViewById(R.id.etNum2);
}
public void addNumber(android.view.View view) {
double n1,n2,result;
n1 = Double.parseDouble(etNum1.getText().toString()); n2 =
Double.parseDouble(etNum2.getText().toString());
result = n1+n2;
tVResult.setText(String.valueOf(result));
}
public void subNumber(android.view.View view) {
double n1,n2,result;
n1 = Double.parseDouble(etNum1.getText().toString()); n2 =
Double.parseDouble(etNum2.getText().toString()); result = n1-n2;
tVResult.setText(String.valueOf(result));
}
public void mulNumber(android.view.View view) {
double n1,n2,result;
n1 = Double.parseDouble(etNum1.getText().toString()); n2 =
Double.parseDouble(etNum2.getText().toString()); result = n1*n2;
tVResult.setText(String.valueOf(result));
}
public void divNumber(android.view.View view) {
double n1,n2,result;
n1 = Double.parseDouble(etNum1.getText().toString()); n2 =
Double.parseDouble(etNum2.getText().toString()); result = n1/n2;
tVResult.setText(String.valueOf(result));
Sushant Poojary MAD 2067
}
}
Colors.xml :
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
</resources>
String.xml :
<resources>
<string name="app_name">Calculator</string>
</resources>
Themes.xml :
<resources xmlns:tools="http://schemas.android.com/tools">
<style name="Theme.Calculator"
parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<item name="colorPrimary">@color/purple_200</item>
Sushant Poojary MAD 2067
<item name="android:statusBarColor"
tools:targetApi="l">?attr/colorPrimaryVariant</item> <!-- Customize your theme here. --> </style>
</resources>
Output:
Outputs :
Android Studio View :
Mobile View :
Sushant Poojary MAD 2067
Addition : Subtraction :
Sushant Poojary MAD 2067
Multiplication : Division:
Conclusion:
Therefore , an android app with Interactive User Interface using Relative Layouts is Created.
Sushant Poojary MAD 2067
29/01/21
Practical 3
Aim: Create an android app that demonstrates Activity Lifecycle and Instance State.
Code:
Actitvity_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"
tools:context=".MainActivity"/>
MainActivity.java :
package com.srs.myapplication22;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
@Override
Sushant Poojary MAD 2067
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("lifecycle","onCreate invoked");
@Override
super.onStart();
Log.d("lifecycle","onStart invoked");
}
@Override
super.onResume();
Log.d("lifecycle","onResume invoked");
@Override
super.onPause();
Log.d("lifecycle","onPause invoked");
@Override
super.onStop();
Log.d("lifecycle","onStop invoked");
@Override
super.onRestart();
Log.d("lifecycle","onRestart invoked");
Sushant Poojary MAD 2067
@Override
super.onDestroy();
Log.d("lifecycle","onDestroy invoked"); }
Output:
Coclusion:
05/02/21
Practical 4
Aim: Create an android app that demonstrates the use of Keyboards, Input Controls,
Alerts, and Pickers.
Code:
ACTIVITY_MAIN.XML
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPersonName"
android:textSize="20sp"
android:hint="Enter Name"/>
<EditText
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:textSize="20dp"
android:hint="Enter Phone Number"/>
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
Sushant Poojary MAD 2067
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:textSize="20dp"
android:hint=" Enter E-mail Address"/>
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textPassword"
android:textSize="20dp"
android:hint="Password"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="D.O.B. :"
android:textSize="20dp" />
<EditText
android:id="@+id/dob"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:hint="Double-Click to select"/>
</LinearLayout>
<RadioGroup
android:id="@+id/rg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Gender"
android:textSize="20dp" />
<RadioButton
android:id="@+id/r1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:textSize="20dp" />
<RadioButton
android:id="@+id/r2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female"
android:textSize="20dp" />
Sushant Poojary MAD 2067
</RadioGroup>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="I AM "
android:textSize="20dp"/>
<Spinner
android:id="@+id/sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</Spinner>
</LinearLayout>
<Button
android:id="@+id/bb"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:text="Submit"
android:textSize="30dp" />
</LinearLayout>
MAINACTIVITY.JAVA
package com.srs.myapplication22;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.Calendar;
Sushant Poojary MAD 2067
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = (EditText) findViewById(R.id.name);
phone = (EditText) findViewById(R.id.number);
email = (EditText) findViewById(R.id.email);
dob = (EditText) findViewById(R.id.dob);
sp = (Spinner) findViewById(R.id.sp);
rg = (RadioGroup) findViewById(R.id.rg);
b1 = (Button) findViewById(R.id.bb);
dob.setOnClickListener(v -> {
Calendar cal = Calendar.getInstance();
int year = cal.get(Calendar.YEAR);
int month = cal.get(Calendar.MONTH);
int day = cal.get(Calendar.DAY_OF_MONTH );
//we need third parameter as on click listener
sp.setOnItemSelectedListener(this);
ArrayAdapter aa = new ArrayAdapter(
this,R.layout.support_simple_spinner_dropdown_item,data);
aa.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
sp.setAdapter(aa);
Sushant Poojary MAD 2067
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rr = rg.getCheckedRadioButtonId();
if(rr != -1);
{
r = (RadioButton) findViewById(rr);
rb = r.getText().toString();
}
myalert.setPositiveButton("ok", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String Display = "name" + name.getText().toString() + "\n phone"+phone.getText().toString()+
"\n email"+email.getText().toString()+"\n gender"+rb+"\n dob "+date+"\n Who am
I"+mspinner;
Toast.makeText(MainActivity.this,Display,Toast.LENGTH_LONG).show(); }
});
myalert.setPositiveButton("cancel", new
DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
Toast.makeText(MainActivity.this, "YOU
CANCELLED",Toast.LENGTH_LONG).show();
}
});
myalert.show();
}
});
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
mspinner = sp.getSelectedItem().toString();
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
}
Sushant Poojary MAD 2067
OUTPUT
MOBILE VIEW:
Sushant Poojary MAD 2067
Sushant Poojary MAD 2067
Conclusion:
12/02/21
Sushant Poojary MAD 2067 Practical 5
Aim: Create an android app that demonstrates the use of an Options Menu.
Code:
My_menu.XML
<item
android:title="Settings"
android:label="ic_baseline_settings_24"
android:id="@+id/settings"
app:showAsAction="never"/>
<item
android:title="Bluetooth"
android:label="ic_baseline_bluetooth_24"
android:id="@+id/bluetooth"
app:showAsAction="never"/>
<item
android:title="Refresh"
android:label="ic_baseline_refresh_24"
android:id="@+id/refresh"
app:showAsAction="never"/>
</menu>
MAINACTIVITY.JAVA
package com.srs.myapplication22;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.app.AlertDialog;
import android.app.DatePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
Sushant Poojary MAD 2067
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import java.util.Calendar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.my_menu, menu);
return super.onCreateOptionsMenu(menu);
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
switch (item.getItemId())
{
case R.id.search_icon:
Toast.makeText(this,"Search", Toast.LENGTH_SHORT).show(); return true;
case R.id.settings:
Toast.makeText(this,"Settings", Toast.LENGTH_SHORT).show(); return true;
case R.id.bluetooth:
Toast.makeText(this,"Bluetooth", Toast.LENGTH_SHORT).show(); return true;
case R.id.refresh:
Toast.makeText(this,"Refresh", Toast.LENGTH_SHORT).show(); return true;
default:
return super.onOptionsItemSelected(item);
}
}
}
OUTPUT:
Sushant Poojary MAD 2067
MOBILE VIEW:
Sushant Poojary MAD 2067
Sushant Poojary MAD 2067
Conclusion:
Practical 6
Aim: Create an android app that demonstrate Screen Navigation Using the App Bar
MainActivity.java
package com.srs.practical6;
import android.os.Bundle;
import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import com.srs.practical6.ui.main.SectionsPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(this,
getSupportFragmentManager());
ViewPager viewPager = findViewById(R.id.view_pager);
viewPager.setAdapter(sectionsPagerAdapter);
TabLayout tabs = findViewById(R.id.tabs);
tabs.setupWithViewPager(viewPager);
FloatingActionButton fab = findViewById(R.id.fab);
Sushant Poojary MAD 2067
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
}
}
PageViewModel.java
package com.srs.practical6.ui.main;
import androidx.arch.core.util.Function;
import androidx.lifecycle.LiveData;
import androidx.lifecycle.MutableLiveData;
import androidx.lifecycle.Transformations;
import androidx.lifecycle.ViewModel;
PlaceHolderFragment.java
package com.srs.practical6.ui.main;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.NonNull;
Sushant Poojary MAD 2067
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import com.srs.practical6.R;
/**
* A placeholder fragment containing a simple view.
*/
public class PlaceholderFragment extends Fragment {
PageViewModel pageViewModel;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
pageViewModel = new ViewModelProvider(this).get(PageViewModel.class); int index = 1;
if (getArguments() != null) {
index = getArguments().getInt(ARG_SECTION_NUMBER); }
pageViewModel.setIndex(index);
}
@Override
public View onCreateView(
@NonNull LayoutInflater inflater, ViewGroup container, Bundle
savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_main, container, false); final TextView textView =
root.findViewById(R.id.section_label); pageViewModel.getText().observe(this, new
Observer<String>() { @Override
public void onChanged(@Nullable String s) {
textView.setText(s);
}
});
return root;
}
}
SectionsPageAdapter.java
package com.srs.practical6.ui.main;
import android.content.Context;
Sushant Poojary MAD 2067
import androidx.annotation.Nullable;
import androidx.annotation.StringRes;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import com.srs.practical6.R;
/**
* A [FragmentPagerAdapter] that returns a fragment corresponding to * one of the
sections/tabs/pages.
*/
public class SectionsPagerAdapter extends FragmentPagerAdapter {
@StringRes
private static final int[] TAB_TITLES = new int[]{R.string.tab_text_1, R.string.tab_text_2};
private final Context mContext;
@Override
public Fragment getItem(int position) {
// getItem is called to instantiate the fragment for the given page. // Return a PlaceholderFragment
(defined as a static inner class below). return PlaceholderFragment.newInstance(position + 1); }
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return mContext.getResources().getString(TAB_TITLES[position]); }
@Override
public int getCount() {
// Show 2 total pages.
return 2;
}
}
activity_main.xml:
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.Practical6.AppBarOverlay">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="@dimen/appbar_padding"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Title" />
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="63dp"
android:background="?attr/colorPrimary"
app:tabTextColor="#FFFFFF" />
</com.google.android.material.appbar.AppBarLayout>
<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
app:srcCompat="@android:drawable/ic_dialog_email" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Fragment_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:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ui.main.PlaceholderFragment">
<TextView
android:id="@+id/section_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/activity_horizontal_margin"
android:layout_marginTop="@dimen/activity_vertical_margin"
android:layout_marginEnd="@dimen/activity_horizontal_margin"
Sushant Poojary MAD 2067
android:layout_marginBottom="@dimen/activity_vertical_margin"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/constraintLayout"
tools:layout_constraintLeft_creator="1"
tools:layout_constraintTop_creator="1" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output:
Practical 7
Aim: Create an android app to Connect to the Internet and use
BroadcastReceiver. Code:
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.srs.practical7">
<uses-permission android:name="android.permission.INTERNET"/> <uses-permission
android:name="android.permission.ACCESS_NETWORK_STATE"/> <uses-permission
android:name="android.permission.ACCESS_WIFI_STATE"/>
<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.Practical7">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
MainActivity.java
Sushant Poojary MAD 2067
package com.srs.practical7;
import androidx.appcompat.app.AppCompatActivity;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
checkConnection();
}
if(null!=activeNetwork){
if(activeNetwork.getType() == ConnectivityManager.TYPE_WIFI){ Toast.makeText(this,
"Internet Connection Established ", Toast.LENGTH_SHORT).show();
}
}
else {
Toast.makeText(this, "Please Check Internet Connection",
Toast.LENGTH_SHORT).show();
}
}
}
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"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
Sushant Poojary MAD 2067
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Output:
12/03/21
Practical 8
Sushant Poojary MAD 2067 Aim: Create an android app to show Notifications and
Alarm manager.
Code:
Actitvity_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"
tools:context=".MainActivity">
<Button
android:id="@+id/notify"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/notify_me"
app:layout_constraintBottom_toTopOf="@+id/update"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/update"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/update_me"
app:layout_constraintBottom_toTopOf="@+id/cancel"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/notify" />
<Button
android:id="@+id/cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel_me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/update" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java :
package com.srs.myapplication32;
import androidx.appcompat.app.AppCompatActivity;
Sushant Poojary MAD 2067
import androidx.core.app.NotificationCompat;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
createNotificationChannel();
button_notify = findViewById(R.id.notify);
button_notify.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
sendNotification();
}
});
updateNotification();
}
});
@Override
protected void onDestroy() {
unregisterReceiver(mReceiver);
super.onDestroy();
}
mNotifyManager = (NotificationManager)
getSystemService(NOTIFICATION_SERVICE);
if (android.os.Build.VERSION.SDK_INT >=
android.os.Build.VERSION_CODES.O) {
notificationChannel.enableLights(true);
notificationChannel.setLightColor(Color.RED);
notificationChannel.enableVibration(true);
notificationChannel.setDescription(getString(R.string.notification_channel_descrip tion));
mNotifyManager.createNotificationChannel(notificationChannel); }
}
notifyBuilder.addAction(R.drawable.ic_update, getString(R.string.update),
updatePendingIntent);
Sushant Poojary MAD 2067
mNotifyManager.notify(NOTIFICATION_ID, notifyBuilder.build());
notifyBuilder = getNotificationBuilder();
notifyBuilder.setStyle(new NotificationCompat.BigPictureStyle()
.bigPicture(androidImage)
.setBigContentTitle(getString(R.string.notification_updated)));
mNotifyManager.notify(NOTIFICATION_ID, notifyBuilder.build());
public NotificationReceiver() {
}
@Override
public void onReceive(Context context, Intent intent) { updateNotification();
}
}
Outputs :
Mobile View :
Conclusion:
Android app to show Notifications and Alarm manager is made.
19/03/21
Practical 9
Aim: Create an android app to save user data in a database and use of different queries.
Sushant Poojary MAD 2067
Code:
MainActivity.java:
package com.srs.practical9;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
name = findViewById(R.id.name);
contact = findViewById(R.id.contact);
dob = findViewById(R.id.dob);
insert = findViewById(R.id.btnInsert);
update = findViewById(R.id.btnUpdate);
delete = findViewById(R.id.btnDelete);
view = findViewById(R.id.btnView);
DB = new DBHelper(this);
insert.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
String nameTXT = name.getText().toString();
String contactTXT = contact.getText().toString(); String dobTXT =
dob.getText().toString();
dobTXT);
if(checkupdatedata==true)
Toast.makeText(MainActivity.this, "Entry Updated", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "New Entry Not Updated", Toast.LENGTH_SHORT).show();
} });
delete.setOnClickListener(new View.OnClickListener() { @Override
public void onClick(View view) {
String nameTXT = name.getText().toString();
Boolean checkudeletedata = DB.deletedata(nameTXT);
if(checkudeletedata==true)
Toast.makeText(MainActivity.this, "Entry Deleted", Toast.LENGTH_SHORT).show();
else
Toast.makeText(MainActivity.this, "Entry Not Deleted", Toast.LENGTH_SHORT).show();
} });
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Cursor res = DB.getdata();
if(res.getCount()==0){
Toast.makeText(MainActivity.this, "No Entry Exists", Toast.LENGTH_SHORT).show();
return;
}
StringBuffer buffer = new StringBuffer();
while(res.moveToNext()){
buffer.append("Name :"+res.getString(0)+"\n"); buffer.append("Contact :"+res.getString(1)+"\n");
buffer.append("Date of Birth :"+res.getString(2)+"\n\n"); }
DBHelper.java:
package com.srs.practical9;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
Sushant Poojary MAD 2067
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
@Override
public void onUpgrade(SQLiteDatabase DB, int i, int i1) {
DB.execSQL("drop Table if exists Userdetails");
}
new String[]{name});
if (cursor.getCount() > 0) {
long result = DB.delete("Userdetails", "name=?", new String[]{name}); if (result == -1) {
return false;
} else {
return true;
}
} else {
return false;
}
}
}
}
Activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:padding="10dp"
tools:context=".MainActivity">
<TextView
android:id="@+id/texttitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please enter the details below"
android:textSize="24dp"
android:layout_marginTop="20dp"
/>
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:textSize="24dp"
android:layout_below="@+id/texttitle"
android:inputType="textPersonName"/>
<EditText
android:id="@+id/contact"
android:layout_width="match_parent"
Sushant Poojary MAD 2067
android:layout_height="wrap_content"
android:hint="Contact"
android:textSize="24dp"
android:layout_below="@+id/name"
android:inputType="number"/>
<EditText
android:id="@+id/dob"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Date of Birth"
android:textSize="24dp"
android:layout_below="@+id/contact"
android:inputType="number"/>
<Button
android:id="@+id/btnInsert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="Insert New Data"
android:layout_marginTop="30dp"
android:layout_below="@id/dob"/>
<Button
android:id="@+id/btnUpdate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="Update Data"
android:layout_below="@id/btnInsert"/>
<Button
android:id="@+id/btnDelete"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="Delete Existing Data"
android:layout_below="@id/btnUpdate"/>
<Button
android:id="@+id/btnView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
android:text="View Data"
android:layout_below="@id/btnDelete"/>
</RelativeLayout>
OUTPUT:
Mobile View:
Sushant Poojary MAD 2067
Inserting Data
Sushant Poojary MAD 2067
View Data
Sushant Poojary MAD 2067
Deleting Data
Sushant Poojary MAD 2067
View Data
Sushant Poojary MAD 2067
Conclusion:
Android app to save user data in a database and use of different
queries is created
26/03/21
Sushant Poojary MAD 2067 Practical 10
Aim: Create an android app that uses MySQL Server using suitable server side
scripting programs.
Code:
MainActivity.java:
package com.srs.practical10;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import java.sql.Connection;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
RegisterActivity:
package com.srs.practical10;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.StrictMode;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.srs.practical10.Connection.ConnectionClass;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;
Statement stmt;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_register);
name = (EditText)findViewById(R.id.name);
email = (EditText)findViewById(R.id.email);
password = (EditText)findViewById(R.id.password);
registerbtn = (Button)findViewById(R.id.registerbtn); status =
(TextView)findViewById(R.id.status);
String z = "";
Boolean isSuccess = false;
@Override
protected void onPreExecute() {
status.setText("Sending Data to Database");
}
@Override
protected void onPostExecute(String s) {
status.setText("Registration Successful");
name.setText("");
email.setText("");
password.setText("");
}
@Override
protected String doInBackground(String... strings) {
try{
con =
connectionClass(ConnectionClass.un.toString(),ConnectionClass.pass.toString(),Conn
ectionClass.db.toString(),ConnectionClass.ip.toString());
if(con == null){
z = "Check Your Internet Connection";
}
else{
String sql = "INSERT INTO register (name,email,password) VALUES
('"+name.getText()+"','"+email.getText()+"','"+password.getText()+"')"; stmt =
con.createStatement();
stmt.executeUpdate(sql);
}
@SuppressLint("NewApi")
public Connection connectionClass(String user, String password, String database, String
server){
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
Connection connection = null;
String connectionURL = null;
try{
Class.forName("net.sourceforge.jtds.jdbc.Driver"); connectionURL = "jdbc:jtds:sqlserver://" +
server+"/" + database + ";user=" + user + ";password=" + password + ";";
connection = DriverManager.getConnection(connectionURL); }catch (Exception e){
Log.e("SQL Connection Error : ", e.getMessage()); }
return connection;
}
}
activity_register:
<?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=".RegisterActivity">
<EditText
android:id="@+id/name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:textSize="25dp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
android:id="@+id/email"
android:hint="Email"
android:inputType="textEmailAddress"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="25dp"
Sushant Poojary MAD 2067
android:id="@+id/password"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/registerbtn" android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Register"
android:textColorLink="#171616" app:backgroundTint="#EA0505" />
<TextView
android:id="@+id/status" android:layout_width="match_parent" android:layout_height="318dp"
android:layout_marginTop="20dp" android:text="Register"
android:textSize="25dp" />
</LinearLayout>
Output:
Sushant Poojary MAD 2067
Conclusion:
Android app that uses MySQL Server using suitable server side
scripting programs is made and executed successfully.