Commit 6796aa41 authored by Kavindu Randika's avatar Kavindu Randika

search function 2

parent 4409af39
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
<option name="filePathToZoomLevelMap"> <option name="filePathToZoomLevelMap">
<map> <map>
<entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/drawable/tab_color.xml" value="0.1125" /> <entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/drawable/tab_color.xml" value="0.1125" />
<entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/activity_deasis_show.xml" value="0.1" />
<entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/activity_main.xml" value="0.19270833333333334" /> <entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/activity_main.xml" value="0.19270833333333334" />
<entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/deasisecheck.xml" value="0.22" /> <entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/deasisecheck.xml" value="0.22" />
<entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/fragment_camera.xml" value="0.1" /> <entry key="..\:/Users/wishwa/StudioProjects/Skidndiseaseapp/app/src/main/res/layout/fragment_camera.xml" value="0.1" />
......
...@@ -28,6 +28,10 @@ android { ...@@ -28,6 +28,10 @@ android {
} }
dependencies { dependencies {
implementation 'com.android.volley:volley:1.2.1'
implementation 'com.loopj.android:android-async-http:1.4.9'
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
implementation 'com.google.code.gson:gson:2.8.5' implementation 'com.google.code.gson:gson:2.8.5'
implementation 'androidx.appcompat:appcompat:1.3.1' implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'com.google.android.material:material:1.4.0' implementation 'com.google.android.material:material:1.4.0'
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android" <manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.project.skidn_disease_app"> package="com.project.skidn_disease_app">
<uses-permission android:name="android.permission.INTERNET" />
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"
...@@ -9,6 +11,9 @@ ...@@ -9,6 +11,9 @@
android:roundIcon="@mipmap/ic_launcher_round" android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true" android:supportsRtl="true"
android:theme="@style/Theme.Skidndiseaseapp"> android:theme="@style/Theme.Skidndiseaseapp">
<activity
android:name=".DeasisShow"
android:exported="true" />
<activity <activity
android:name=".MainActivity" android:name=".MainActivity"
android:exported="true"> android:exported="true">
......
package com.project.skidn_disease_app;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class DeasisShow extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_deasis_show);
}
}
\ No newline at end of file
package com.project.skidn_disease_app; package com.project.skidn_disease_app;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
...@@ -7,6 +10,7 @@ import androidx.fragment.app.Fragment; ...@@ -7,6 +10,7 @@ import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu; import android.view.Menu;
import android.view.MenuInflater; import android.view.MenuInflater;
...@@ -15,8 +19,33 @@ import android.view.View; ...@@ -15,8 +19,33 @@ import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Toast; import android.widget.Toast;
import com.android.volley.NetworkResponse;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.VolleyLog;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.JsonRequest;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.google.gson.JsonObject;
import com.project.skidn_disease_app.model.DeasisModal;
import com.project.skidn_disease_app.network.ApiInterFace;
import com.project.skidn_disease_app.network.ArrayListVals;
import com.project.skidn_disease_app.network.RetrofitClientInstance;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Retrofit;
/** /**
* A simple {@link Fragment} subclass. * A simple {@link Fragment} subclass.
...@@ -29,9 +58,9 @@ public class SearchFragment extends Fragment implements QuantityListner{ ...@@ -29,9 +58,9 @@ public class SearchFragment extends Fragment implements QuantityListner{
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER // the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
private static final String ARG_PARAM1 = "param1"; private static final String ARG_PARAM1 = "param1";
private static final String ARG_PARAM2 = "param2"; private static final String ARG_PARAM2 = "param2";
private HashMap<String, Object> map; HashMap<String, String> map = new HashMap<>();
private RecyclerView recyclerView; private RecyclerView recyclerView;
private ArrayList<String> responce_data;
private ArrayList<String> values; private ArrayList<String> values;
// TODO: Rename and change types of parameters // TODO: Rename and change types of parameters
...@@ -166,12 +195,97 @@ public class SearchFragment extends Fragment implements QuantityListner{ ...@@ -166,12 +195,97 @@ public class SearchFragment extends Fragment implements QuantityListner{
public boolean onOptionsItemSelected(@NonNull MenuItem item) { public boolean onOptionsItemSelected(@NonNull MenuItem item) {
int itemThatWasClickedId = item.getItemId(); int itemThatWasClickedId = item.getItemId();
if (itemThatWasClickedId == R.id.action_search) { if (itemThatWasClickedId == R.id.action_search) {
Toast.makeText(this.getContext(),"hello",Toast.LENGTH_LONG).show();
try {
getMap();
if (this.responce_data!= null){
if(!this.responce_data.isEmpty()){
ArrayList<Integer> output= new ArrayList<>();
for (String data:this.responce_data) {
String point = this.map.get(data);
output.add(Integer.parseInt(point));
}
System.out.println("printing---");
System.out.println(output.toString());
ArrayList<String> data_ = justafunction(output.toString());
Intent intent = new Intent(this.getContext(),DeasisShow.class);
intent.putExtra("deasis",data_);
startActivity(intent);
}else{
showAlert("Please Checkout Some symptoms","Warining");
}
}else{
showAlert("Please Checkout Some symptoms","Warining");
Toast.makeText(this.getContext(),"Please Checkout Some symptoms",Toast.LENGTH_LONG).show();
}
} catch (JSONException e) {
e.printStackTrace();
}
return true; return true;
} }
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
public void showAlert(String msg,String title){
AlertDialog.Builder builder1 = new AlertDialog.Builder(this.getContext());
builder1.setMessage(msg);
builder1.setTitle(title);
builder1.setCancelable(true);
builder1.setPositiveButton(
"Ok",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert11 = builder1.create();
alert11.show();
}
public ArrayList<String> justafunction(String data) throws JSONException {
// String url ="https://projects.vishnusivadas.com/testing/write.php";
final String url = "https://nnau7c.deta.dev/api/predictions/symptoms";
final ArrayList<String>[] data_ = new ArrayList[]{new ArrayList<>()};
String quary = "{\"symptoms\": "+data+"}";
final JSONObject jsonBody = new JSONObject(quary);
JsonObjectRequest req = new JsonObjectRequest(url, jsonBody,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
VolleyLog.v("Response:%n %s", response.toString(4));
System.out.println(response);
ArrayList<String> listdata = new ArrayList<String>();
ArrayList<String> data_in = new ArrayList<String>();
JSONArray jsonArray = (JSONArray)response.get("result");
if (jsonArray != null) {
int len = jsonArray.length();
for (int i=0;i<len;i++){
data_in.add(jsonArray.get(i).toString());
}
}
for (String data: (data_in)) {
System.out.println(data);
}
data_[0] = data_in;
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: ", error.getMessage());
}
});
// add the request object to the queue to be executed
RequestQueue queue = Volley.newRequestQueue(this.getContext());
queue.add(req);
System.out.println(data_[0]);
return data_[0];
}
public void getMap() { public void getMap() {
this.map.put("Crusting of skin bumps.","23"); this.map.put("Crusting of skin bumps.","23");
this.map.put(" Cysts.","2"); this.map.put(" Cysts.","2");
...@@ -288,6 +402,7 @@ public class SearchFragment extends Fragment implements QuantityListner{ ...@@ -288,6 +402,7 @@ public class SearchFragment extends Fragment implements QuantityListner{
@Override @Override
public void onQunatiyChange(ArrayList<String> arrayList) { public void onQunatiyChange(ArrayList<String> arrayList) {
this.responce_data = arrayList;
Toast.makeText(this.getContext(),arrayList.toString(),Toast.LENGTH_LONG).show(); Toast.makeText(this.getContext(),arrayList.toString(),Toast.LENGTH_LONG).show();
} }
} }
\ No newline at end of file
package com.project.skidn_disease_app.model;
public class DeasisModal {
private String success;
private String[] result;
public DeasisModal(String success, String[] result) {
this.success = success;
this.result = result;
}
public String getSuccess() {
return success;
}
public void setSuccess(String success) {
this.success = success;
}
public String[] getResult() {
return result;
}
public void setResult(String[] result) {
this.result = result;
}
}
package com.project.skidn_disease_app.network;
import com.google.gson.JsonObject;
import com.project.skidn_disease_app.model.DeasisModal;
import java.util.ArrayList;
import java.util.HashMap;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.Headers;
import retrofit2.http.POST;
public interface ApiInterFace {
// @FormUrlEncoded
@Headers("Content-Type: application/json")
@POST("symptoms")
Call<DeasisModal> postData(@Body String body);
}
package com.project.skidn_disease_app.network;
import java.util.ArrayList;
public class ArrayListVals {
final ArrayList<String> symptoms;
// final String bar;
public ArrayListVals(ArrayList<String> symptoms) {
this.symptoms = symptoms;
}
}
package com.project.skidn_disease_app.network;
import com.loopj.android.http.AsyncHttpClient;
import com.loopj.android.http.AsyncHttpResponseHandler;
import cz.msebera.android.httpclient.Header;
public class Request {
public void funcion(){
AsyncHttpClient client = new AsyncHttpClient();
client.post("https://www.google.com", new AsyncHttpResponseHandler() {
@Override
public void onStart() {
// called before request is started
}
@Override
public void onSuccess(int statusCode, Header[] headers, byte[] response) {
// called when response HTTP status is "200 OK"
}
@Override
public void onFailure(int statusCode, Header[] headers, byte[] errorResponse, Throwable e) {
// called when response HTTP status is "4XX" (eg. 401, 403, 404)
}
@Override
public void onRetry(int retryNo) {
// called when request is retried
}
});}
}
package com.project.skidn_disease_app.network;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClientInstance {
private static Retrofit retrofit;
private static final String BASE_URL = "https://nnau7c.deta.dev/api/predictions/";
public static Retrofit getRetrofitInstance() {
if (retrofit == null) {
retrofit = new retrofit2.Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build();
}
return retrofit;
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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=".DeasisShow">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="409dp"
android:layout_height="729dp"
tools:layout_editor_absoluteX="1dp"
tools:layout_editor_absoluteY="1dp" />
</FrameLayout>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment