Anda di halaman 1dari 11

PACKAGE:

The package name of all java files is “com.myservices.servicingu”

IMPORT:

The source code present below are used to import all the packages, classes, firebase classes in
java. Import statement is used to bring certain classes or the entire packages, into visibility.

Import android classes:

import android.os.Parcel;
import android.os.Parcelable;
import android.app.Activity;
import android.content.Intent;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.TextUtils;
import android.text.method.ScrollingMovementMethod;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.text.Editable;
import android.text.TextWatcher;
import android.text.Layout;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CalendarView;
import android.widget.EditText;
import android.widget.RatingBar;
import android.widget.Spinner;
import android.widget.TableLayout;
import android.widget.TableRow;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

Import firebase classes:

import com.google.firebase.auth.AuthResult;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;
import com.google.firebase.storage.UploadTask;

Import java classes:

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.io.File;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TimeZone;

These are the Google Maps SDK for Android classes:

import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;

MANIFEST FILE:
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API, but we must specify either coarse or fine
location permissions for the 'MyLocation' functionality.

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />


Allows the API to use wifi or mobile cell data (or both) to determine the device's location.
The API returns the location with an accuracy approximately equivalent to a city block.

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"
/>
Allows the API to determine as precise a location as possible from the available location
providers, including the Global Positioning System (GPS) as well as wifi and mobile cell
data.

<uses-permission android:name="android.permission.INTERNET" />


In order to perform network operations in our application, our manifest must include the
above permission:

Google maps:
In order access google maps we need to use the following source code; it contains API key of
google maps. It is stored in “res/values/google_maps_api.xml”

<resources>
<string name="google_maps_key" templateMergeStrategy="preserve"
translatable="false">AIzaSyBWH2zwDfOopkHf0ER79uxgT6c8zw4Mhn0</string>
</resources>

ACTIVITIES:
These are the activities used for the class names. “android:name” are the class names and
android:label are used for label names of buttons.

<activity
android:name=".CreateAccountActivity"
android:label="@string/title_activity_create_account"
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".MyAccountActivity"
android:label="My Account" />
<activity
android:name=".ServicesActivity"
android:label="@string/title_activity_services" />
<activity
android:name=".AvailabilityCalendar"
android:label="My Availability" />
<activity
android:name=".MyServices"
android:label="My Services" />
<activity
android:name=".MyJobs"
android:label="My Jobs" />
<activity
android:name=".BookJobActivity"
android:label="Book A Job" />
<activity
android:name=".BookJobServiceActivity"
android:label="Select Service" />
<activity android:name=".AvailabilityActivity" />
<activity
android:name=".JobOptionsActivity"
android:label="@string/title_activity_job_options" />
<activity
android:name=".JobActivity"
android:theme="@style/AppTheme.NoActionBar" />

GRADLE:
Below code is used to compile and run our application using Android Studio. It is saved as
“build.gradle” file.
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.myservices.servicingu"
minSdkVersion 15
targetSdkVersion 28
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
minifyEnabled false
useProguard false
proguardFiles getDefaultProguardFile('proguard-android.txt'),
'proguard-rules.pro'
}
}
compileOptions {
targetCompatibility 1.8
sourceCompatibility 1.8
}
}
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation 'com.android.support.constraint:constraint-layout:1.1.3'
implementation 'com.android.support:design:28.0.0'
implementation 'com.android.support:support-annotations:28.0.0'

implementation 'com.google.firebase:firebase-auth:16.0.3'
//implementation 'com.google.firebase:firebase-admin:6.5.0'
implementation 'com.google.firebase:firebase-database:16.0.1'
implementation 'com.google.firebase:firebase-storage:16.0.3'
implementation 'com.google.firebase:firebase-core:16.0.4'

implementation 'com.google.android.gms:play-services-location:16.0.0'

implementation 'com.google.android.gms:play-services-maps:16.1.0'
annotationProcessor 'com.google.auto.value:auto-value:1.4'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-
core:3.0.2'

implementation 'com.synnapps:carouselview:0.1.5'

apply plugin: 'com.google.gms.google-services'

CREATE ACCOUNT:
We used LinearLayout to define each requirement such firstName, lastName in Create
Account module using XML markup language. Below code is used to create First Name
layout. In the same way, we create for the rest of the layouts present in this module.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<TextView
android:id="@+id/firstNameText"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/first_name"
/>

<EditText

android:background="@drawable/textfield"
android:id="@+id/fieldFirstName"

android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:ems="10"

android:inputType="textPersonName" />
</LinearLayout>

Below code creates radio buttons in the user type section for the selection of service
provider/Homeowner shown in the above screenshot.

<RadioGroup
android:id="@+id/userTypeRadio"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent">

<RadioButton
android:id="@+id/serviceProvRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/service_provider" />

<RadioButton
android:id="@+id/homeownerRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/homeowner" />

</RadioGroup>

Adding user’s information to database:

public void addUserToDatabase(FirebaseUser user){

String userid = user.getUid();


//String email = user.getEmail();

//get name
String firstName = ((EditText)
findViewById(R.id.fieldFirstName)).getText().toString().trim();
String lastName = ((EditText)
findViewById(R.id.fieldLastName)).getText().toString().trim();

//get phone
String phoneNumber = ((EditText)
findViewById(R.id.fieldPhone)).getText().toString();

//get usertype
String userType = "none";
RadioButton homeOwner, serviceProvider;

homeOwner = (RadioButton) findViewById(R.id.homeownerRadioBtn);


serviceProvider = (RadioButton) findViewById(R.id.serviceProvRadioBtn);

if(homeOwner.isChecked()){
userType = "homeowner";
}
if(serviceProvider.isChecked()){
userType = "service provider";
}

//get address
String address = ((EditText)
findViewById(R.id.fieldAddress)).getText().toString();

String aadhar = ((EditText)findViewById(R.id.etaadhar)).getText().toString();


String lat = ((EditText)findViewById(R.id.etlat)).getText().toString();
String lon = ((EditText)findViewById(R.id.etlon)).getText().toString();

//add new user


User newUser = new User(userid, firstName, lastName, userType, phoneNumber,
address, aadhar, lat, lon);
databaseUsers.child(userid).setValue(newUser);
}

Services:
These are all the services admin can add and can set the cost of each service. Image at right
hand side
SOURCE CODE:
<string-array name="service_type_array">
<item>Cable/Internet</item>
<item>Carpentry</item>
<item>Cleaning</item>
<item>Delivery</item>
<item>Electrical</item>
<item>Interior Design</item>
<item>IT</item>
<item>Landscaping</item>
<item>Logistics</item>
<item>Painting</item>
<item>Plumbing</item>
<item>Security</item>
<item>Misc</item>
</string-array>

SOURCE CODE:

<string-array name="time_slots">
<item>06:00</item>
<item>06:30</item>
<item>07:00</item>
<item>07:30</item>
<item>08:00</item>
<item>08:30</item>
<item>09:00</item>
<item>09:30</item>
<item>10:00</item>
<item>10:30</item>
<item>11:00</item>
<item>11:30</item>
<item>12:00</item>
<item>12:30</item>
<item>13:00</item>
<item>13:30</item>
<item>14:00</item>
<item>14:30</item>
<item>15:00</item>
<item>15:30</item>
<item>16:00</item>
<item>16:30</item>
<item>17:00</item>
<item>17:30</item>
<item>18:00</item>
<item>18:30</item>
<item>19:00</item>
</string-array>
Book A Job activity:
We used TableRow to define each row in Book A Job module using XML markup language
Below code is used to create Sunday row. In the same way, we create for the rest of the days.

<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:id="@+id/sunday"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="Sunday" />

<CheckBox
android:id="@+id/sundayMorningCB"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="@string/morning" />

<CheckBox

android:id="@+id/sundayAfternoonCB"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="@string/afternoon"
/>

<CheckBox
android:id="@+id/sundayEveningCB"

android:layout_width="wrap_content"

android:layout_height="wrap_content"
android:text="@string/evening" />
</TableRow>

ASSOCIATING SERVICES:
Below code allows service provider to associate his services
public void associateServices(View view){

Service service;

for (int i = 0; i <


listAllServices.getChildCount(); i++) {
LinearLayout ll = (LinearLayout)
listAllServices.getChildAt(i);
CheckBox cb = (CheckBox) ll.getChildAt(0);

service = allServices.get(i);

if (cb.isChecked()){
if (!myServices.contains(service)) {
myServices.add(service);
}
} else {
myServices.remove(service);
}

Log.v("dbTAG", "Associating services: " +


myServices.toString());

FirebaseUser user = mAuth.getCurrentUser();

databaseUsers.child(user.getUid()).child("services").
setValue(myServices);

finish();
}

JOB APPROVAL:
When customer book a service provider then service provider approves the job. The source
code used for approving the job in java is

public void ApproveJob(View view) {

databaseJobs.child(jobID).addListenerForSingleValueEvent(new
ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
Job job = dataSnapshot.getValue(Job.class);
job.stAtus="Approved";
DatabaseReference dR = databaseJobs.child(jobID);
dR.setValue(job);

GPS enabling:

Method to check gps is enable or not:


private Boolean displayGpsStatus() {
ContentResolver contentResolver = getBaseContext()
.getContentResolver();
boolean gpsStatus = Settings.Secure
.isLocationProviderEnabled(contentResolver,
LocationManager.GPS_PROVIDER);
if (gpsStatus) {
Toast.makeText(this, "gps on", Toast.LENGTH_SHORT).show();
return true;

} else {
return false;
}
}

Anda mungkin juga menyukai