Professional Documents
Culture Documents
PAM Lab 6 Rotaru Dan
PAM Lab 6 Rotaru Dan
RAPORT
Lucrare de laborator Nr.6
Disciplina: Programarea
aplicațiilor mobile
Tema: Telemedicine – SPRINT2
Chișinău 2021
Scopul lucrării de laborator
Pentru designul ofert in laboratorul nr. 5 să se implementeze partea funcțională a proiectului conform
serviciului API descris mai jos.
Metodele oferite de Servicu:
Auth (autentificare)
Reg (inregistrare)
UserProfie (extragerea avansată despre utilizatorul curent autentificat)
UpdateUserProfile (NotImplemented) - nu cred că o voi implementa
GetDocList (vizualizarea listei de medici activi in sistem)
GetDoc (vizualizarea unui anumit medici activ in sistem)
UserRequestConsultation (Adaugarea unei programari la medic)
package com.danrotaru.pamlab5;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.util.Log;
import android.view.View;
import android.widget.Toast;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
if(email.isEmpty() || password.isEmpty()){
log("Email or password are empty!", 2, context);
return;
}
if(!isNetworkAvailable(context)){
log("You are offline!", 2, context);
return;
}
JSONObject obj;
try {
obj = new JSONObject(res);
String token = obj.getString("Message");
if(obj.getString("Status").equals("SUCCESS")){
log("Success!", 2, context);
setToken(token, context);
openIntent(HomeActivity.class, context);
}
} catch (JSONException e) {
e.printStackTrace();
}
},
error -> {
try {
String res = new String( error.networkResponse.data,
StandardCharsets.UTF_8);
JSONObject obj = new JSONObject(res);
if(obj.getString("Status").equals("ERROR")){
log(obj.getString("Message"), 2, context);
}
else{
log("Error while interact with API!", 2, context);
}
} catch (JSONException e ) {
e.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams(){
Map<String, String> params = new HashMap<>();
params.put("Email", email);
params.put("Password", password);
return params;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
HomeActivity
package com.danrotaru.pamlab5;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Base64;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
BottomNavigationView navigation;
Context context;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
context = this;
navigation = findViewById(R.id.navigation);
navigation.setOnNavigationItemSelectedListener(menuItem -> {
int id = menuItem.getItemId();
if(id == R.id.menu_home) {
replaceFragment(new Home());
return true;
}
else if(id == R.id.menu_notification) {
replaceFragment(new NotificationActivity());
return true;
}
else if(id == R.id.add) {
return true;
}
else if(id == R.id.menu_schedule) {
replaceFragment(new DoctorListActivity());
DoctorList();
return true;
}
else if(id == R.id.menu_profile) {
replaceFragment(new Profile());
getProfile();
return true;
}
return true;
});
Fragment oldFragment =
fragmentManager.findFragmentByTag(fragment.getClass().getName());
if (oldFragment != null) {
fragment = oldFragment;
}
fragmentTransaction.replace(R.id.mainFragment, fragment,
fragment.getClass().getName());
fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
fragmentTransaction.commit();
}
log(res, 1, this);
JSONArray obj;
try {
obj = new JSONArray(res);
doc_layout_id = getResources().getIdentifier("doctor_layout" +
i, "id", getPackageName());
LinearLayout layout = findViewById(doc_layout_id);
layout.setVisibility(View.VISIBLE);
setVal("fullname" + i, nobj.getString("FullName"));
setVal("mark" + i, doctor_stars);
setVal("speciality" + i, doctor_specs);
setVal("location" + i, nobj.getString("Address"));
} catch (JSONException e) {
e.printStackTrace();
}
},
error -> {
String res = new String( error.networkResponse.data,
StandardCharsets.UTF_8);
System.out.println("Volley Request Error = "+res);
if(res.equals("\"ERROR\"")){
log("Error!", 2, this);
}
else{
log("Error while interact with API!", 2, this);
}
}){
@Override
protected Map<String, String> getParams(){
return new HashMap<>();
}
@Override
public Map<String, String> getHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("TOKEN", getToken(context));
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
log(res, 1, this);
JSONObject obj;
try {
obj = new JSONObject(res);
String profile_name = obj.getString("FullName");
String profile_email = obj.getString("Email");
String profile_phone = obj.getString("Phone");
String profile_address = obj.getString("Address");
String profile_username = obj.getString("Username");
String profile_birthday = obj.getString("Birthday");
String profile_avatar = obj.getString("Base64Photo");
setVal("profile_name", profile_name);
setVal("profile_username", profile_username);
setVal("profile_email", profile_email);
setVal("profile_phone", profile_phone);
setVal("profile_location", profile_address);
setVal("profile_birthday", profile_birthday);
ImageView av = findViewById(R.id.profile_avatar);
byte[] decodedString = Base64.decode(profile_avatar,
Base64.DEFAULT);
Bitmap decodedByte = BitmapFactory.decodeByteArray(decodedString,
0,decodedString.length);
av.setImageBitmap(decodedByte);
} catch (JSONException e) {
e.printStackTrace();
}
},
error -> {
try {
String res = new String( error.networkResponse.data,
StandardCharsets.UTF_8);
JSONObject obj = new JSONObject(res);
if(obj.getString("Status").equals("ERROR")){
log(obj.getString("Message"), 2, this);
}
else{
log("Error while interact with API!", 2, this);
}
} catch (JSONException e ) {
e.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams(){
return new HashMap<>();
}
@Override
public Map<String, String> getHeaders(){
Map<String, String> headers = new HashMap<>();
headers.put("TOKEN", getToken(context));
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
}
HomeFragment
package com.danrotaru.pamlab5;
import android.content.Context;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.util.HashMap;
import java.util.Map;
public Home() {
// Required empty public constructor
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
Button requestBtn = view.findViewById(R.id.request);
@RequiresApi(api = Build.VERSION_CODES.O)
public void addConsultation(View view){
Context context = getContext();
if(!isNetworkAvailable(context)){
log("You are offline!", 2, context);
return;
}
if(res.equals("\"Error\"")) {
log("Eroare la adăugarea programarii!", 2, context);
return;
}
JSONObject obj;
try {
obj = new JSONObject(res);
System.out.println(obj);
String notification_fullname = obj.getString("Name");
String notification_disease = obj.getString("Disease");
String notification_address = obj.getString("Address");
String notification_description = obj.getString("Description");
String notification_ConsId = obj.getString("ConsId");
String notification_DocId = obj.getString("DocId");
// TextView tt = view.findViewById(R.id.notification_name);
// tt.setText(obj.getString("Name"));
NotificationActivity nextFrag= new
NotificationActivity(notification_fullname, notification_disease, notification_address,
notification_description, notification_ConsId, notification_DocId);
getActivity().getSupportFragmentManager().beginTransaction()
.replace(R.id.mainFragment, nextFrag, "findThisFragment")
.addToBackStack(null)
.commit();
} catch (JSONException e) {
e.printStackTrace();
}
},
error -> {
String res = new String( error.networkResponse.data,
StandardCharsets.UTF_8);
int code = error.networkResponse.statusCode;
// if(code == 401){
// retryAuth(context, view);
// }
log(res + " with code " + code, 1, context);
if(res.equals("\"ERROR\"")){
log("Eroare la adăugarea programarii!", 2, context);
}
else{
log("Error while interact with API!", 2, context);
}
}){
@Override
protected Map<String, String> getParams(){
Map<String, String> params = new HashMap<>();
params.put("Name", name);
params.put("Disease", disease);
params.put("Address", location);
params.put("Description", description);
return params;
}
@Override
public Map<String, String> getHeaders(){
Map<String, String> headers = new HashMap<String, String>();
headers.put("TOKEN", getToken(context));
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(context);
requestQueue.add(stringRequest);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_home, container, false);
}
}
DoctorDetails Fragment
package com.danrotaru.pamlab5;
import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import android.util.Base64;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
String doctor_name;
String doctor_specs;
String doctor_address;
String doctor_description;
String doctor_stars;
String doctor_photo;
public DoctorDetails() {
// Required empty public constructor
}
public DoctorDetails(String name, String specs, String address, String description,
String stars, String photo) {
doctor_name = name;
doctor_specs = specs;
doctor_address = address;
doctor_description = description;
doctor_stars = stars;
doctor_photo = photo;
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@SuppressLint("ClickableViewAccessibility")
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
TextView name = view.findViewById(R.id.doctor_details_name);
TextView specs = view.findViewById(R.id.doctor_details_specs);
TextView address = view.findViewById(R.id.doctor_details_address);
TextView description = view.findViewById(R.id.doctor_details_description);
TextView stars = view.findViewById(R.id.doctor_details_stars);
ImageView photo = view.findViewById(R.id.doctor_details_photo);
name.setText(doctor_name);
specs.setText(doctor_specs);
address.setText(doctor_address);
description.setText(doctor_description);
stars.setText(doctor_stars);
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_doctor_details, container, false);
}
}
SplashScreen
package com.danrotaru.pamlab5;
import androidx.appcompat.app.AppCompatActivity;
@SuppressLint("CustomSplashScreen")
public class SplashActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
//delay = 0;
finish();
}, delay);
WelcomeActivity
package com.danrotaru.pamlab5;
import androidx.appcompat.app.AppCompatActivity;
import static com.danrotaru.pamlab5.Helpers.*;
import android.os.Bundle;
import android.widget.Button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_welcome);
Button signUp = findViewById(R.id.button);
Button login = findViewById(R.id.button1);