0% found this document useful (0 votes)
15 views

PB2 Program 2

The document contains XML code for layouts used in an Android app to display meeting schedule details. It includes code for the main activity layout, two fragments for scheduling meetings and viewing details, and their associated views and widgets. The layouts contain elements like text views, edit texts, buttons and a calendar view to enter and display meeting dates, times, and other details.
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)
15 views

PB2 Program 2

The document contains XML code for layouts used in an Android app to display meeting schedule details. It includes code for the main activity layout, two fragments for scheduling meetings and viewing details, and their associated views and widgets. The layouts contain elements like text views, edit texts, buttons and a calendar view to enter and display meeting dates, times, and other details.
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/ 11

1 Program 9: Meeting Schedule

XML Code:
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/design_default_color_error"
android:theme="@style/Theme.MeetingInfo.AppBarOverlay">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/purple_500"
android:gravity="center"
android:minHeight="?actionBarSize"
android:padding="@dimen/appbar_padding"
android:text="Meeting Details"
android:textAlignment="center"

android:textAppearance="@style/TextAppearance.Widget.AppCompat.Toolbar.Titl
e" />

<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="37dp"
android:background="#FFEA6b"
app:tabIndicatorColor="#00E6FF" />
</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="499dp"
app:layout_behavior="@string/appbar_scrolling_view_behavior">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TextView" />
</androidx.viewpager.widget.ViewPager>

</androidx.coordinatorlayout.widget.CoordinatorLayout>

Mobile Application Development – 18CSMP68


2 Program 9: Meeting Schedule

Fragment.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:text="Schedule Meeting"
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"
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>

Fragment1.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_gravity="center"
android:layout_height="match_parent">

<EditText
android:id="@+id/txtDate"
android:layout_width="212dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:ems="10"
android:hint="DD/MM/YYYY"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/mDate"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/txtTime"
android:layout_width="212dp"
android:layout_height="54dp"
android:layout_marginTop="64dp"
android:layout_marginEnd="8dp"
android:ems="10"
android:hint="hh:mm"

Mobile Application Development – 18CSMP68


3 Program 9: Meeting Schedule

android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/txtDate" />

<TextView
android:id="@+id/mDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:text="Date:"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/txt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Time:"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintEnd_toStartOf="@+id/txtTime"
app:layout_constraintHorizontal_bias="0.117"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/mDate" />

<TextView
android:id="@+id/txt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:text="Meeting Agenda:"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toTopOf="@+id/btn1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt2"
app:layout_constraintVertical_bias="0.131" />

<Button
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Meeting Schedule"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.331"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtAgenda"
app:layout_constraintVertical_bias="0.782" />

<EditText
android:id="@+id/txtAgenda"
android:layout_width="212dp"
android:layout_height="50dp"
android:layout_marginTop="16dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toEndOf="@+id/txt3"
app:layout_constraintTop_toBottomOf="@+id/txtTime" />

<CalendarView
Mobile Application Development – 18CSMP68
4 Program 9: Meeting Schedule

android:id="@+id/mCal"
android:layout_width="385dp"
android:layout_height="305dp"
android:background="#AFB42B"
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.575" />
</androidx.constraintlayout.widget.ConstraintLayout>

Fragment2.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">

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:text="Select Date to get Meeting Details"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<EditText
android:id="@+id/editTextDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="10"
android:inputType="text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.535"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.047" />

<CalendarView
android:id="@+id/calendarView"
android:layout_width="263dp"
android:layout_height="249dp"
android:layout_marginTop="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.679"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editTextDate" />

<Button
android:id="@+id/btn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Search to get Meeting Details"
app:layout_constraintBottom_toBottomOf="parent"

Mobile Application Development – 18CSMP68


5 Program 9: Meeting Schedule

app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/calendarView"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>

Java Code:
package com.example.meetinginfo;

import android.os.Bundle;

import
com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;
import com.google.android.material.tabs.TabLayout;

import androidx.viewpager.widget.ViewPager;
import androidx.appcompat.app.AppCompatActivity;

import android.view.Menu;
import android.view.MenuItem;
import android.view.View;

import com.example.meetinginfo.ui.main.SectionsPagerAdapter;

public class MainActivity extends AppCompatActivity {

@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);
}
}

DataBaseConn.java:
package com.example.meetinginfo;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;
import androidx.fragment.app.FragmentActivity;

public class DataBaseConn extends SQLiteOpenHelper {


public DataBaseConn(Context context) {
super(context,"MeetingDB.db",null,1);
}

Mobile Application Development – 18CSMP68


6 Program 9: Meeting Schedule

@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL("create Table meetingTbl(date TEXT,time TEXT, agenda
TEXT)");

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("drop Table if exists meetingTbl");

}
public boolean insertvalue(String d, String t, String agd){
SQLiteDatabase DB=this.getWritableDatabase();
ContentValues cv = new ContentValues();
cv.put("date",d);
cv.put("time",t);
cv.put("agenda",agd);
long res=DB.insert("meetingTbl",null,cv); //query to insert
if(res==-1){
return false;
}
else
return true;
}
public Cursor fetch(String d){

SQLiteDatabase DB=this.getReadableDatabase();
// String sqlquery="select name from MDTbl where date='19/3/21' AND
time='Afternoon'";
// Cursor c = DB.rawQuery(sqlquery,null);
Cursor c = DB.rawQuery("Select time,agenda from meetingTbl where
date='"+d+"' ",null);
return c;
}

DBMS.java:
package com.example.meetinginfo;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DBMS extends SQLiteOpenHelper {


public DBMS(@Nullable Context context, @Nullable String name, @Nullable
SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
}

@Override
public void onCreate(SQLiteDatabase db) {

Mobile Application Development – 18CSMP68


7 Program 9: Meeting Schedule

@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {

}
}

Fragment1.java:
package com.example.meetinginfo;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import static androidx.core.content.ContextCompat.getSystemService;

public class Fragment1 extends Fragment {


EditText date,time,agenda;
DataBaseConn dbc;
CalendarView calendarView;
Button btn;
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
View
view=inflater.inflate(R.layout.fragment_layout1,container,false);
date=view.findViewById(R.id.txtDate);
time=view.findViewById(R.id.txtTime);
agenda=view.findViewById(R.id.txtAgenda);
btn=view.findViewById(R.id.btn1);
calendarView=view.findViewById(R.id.mCal);
dbc=new DataBaseConn(getActivity()); //need to initialize here
only
calendarView.setVisibility(View.INVISIBLE);
date.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
closeKeyBoard();
calendarView.setVisibility(View.VISIBLE);
calendarView.setOnDateChangeListener(new
CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView
view, int year, int month, int dayOfMonth) {
String d=dayOfMonth+"/"+(month+1)+"/"+year;
date.setText(d);
calendarView.setVisibility(View.INVISIBLE);
}

Mobile Application Development – 18CSMP68


8 Program 9: Meeting Schedule

});
}
});
btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String mdate,mTime,mAgenda;
mdate=date.getText().toString();
mTime=time.getText().toString();
mAgenda=agenda.getText().toString();

Boolean insert=dbc.insertvalue(mdate,mTime,mAgenda);
if(insert==true){
Toast.makeText(getActivity(),"Data
Inserted",Toast.LENGTH_SHORT).show();

}
else
Toast.makeText(getActivity(),"Data NOT
Inserted",Toast.LENGTH_SHORT).show();
//txt.setText("NOT INSERTED");

});

return view;
}
private void closeKeyBoard(){
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)

getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}

Fragment2.java:
package com.example.meetinginfo;

import android.database.Cursor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.CalendarView;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

Mobile Application Development – 18CSMP68


9 Program 9: Meeting Schedule

import androidx.appcompat.app.AppCompatDialogFragment;
import androidx.fragment.app.Fragment;

import com.example.meetinginfo.R;

import java.util.Calendar;

public class Fragment2 extends Fragment {


EditText date;
CalendarView cal;
Button btn1;
DataBaseConn dbc;
TextView t;
// String med="";
// String med1="";
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable
ViewGroup container, @Nullable Bundle savedInstanceState) {
View
view=inflater.inflate(R.layout.fragment2_layout,container,false);
date=view.findViewById(R.id.editTextDate);
cal=view.findViewById(R.id.calendarView);
btn1=view.findViewById(R.id.btn2);
dbc=new DataBaseConn(getActivity());
// t=()

cal.setOnDateChangeListener(new CalendarView.OnDateChangeListener()
{
@Override
public void onSelectedDayChange(@NonNull CalendarView view, int
year, int month, int dayOfMonth) {
String d=dayOfMonth+"/"+(month+1)+"/"+year;
date.setText(d);
}
});

btn1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String d1=date.getText().toString();
StringBuffer res=new StringBuffer();
Cursor c=dbc.fetch(d1);
int count=c.getCount();
c.moveToFirst();
if(count>0) {
do {

res.append(c.getString(c.getColumnIndex("agenda"))+"\t"+"at"+"\t"+c.getStri
ng(c.getColumnIndex("time")));
res.append("\n");

//med =
(String.valueOf(c.getString(c.getColumnIndex("agenda"))));
//med1 =
(String.valueOf(c.getString(c.getColumnIndex("time"))));
}while (c.moveToNext());
Toast.makeText(getActivity(), res,
Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(getActivity(), "No Meeting on This
Day....", Toast.LENGTH_LONG).show();
Mobile Application Development – 18CSMP68
10 Program 9: Meeting Schedule

}
});
return view;
}

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

}
}

Mobile Application Development – 18CSMP68


11 Program 9: Meeting Schedule

Output:

Mobile Application Development – 18CSMP68

You might also like