Commit 941b5018 authored by Weesinghe W.M.P.D's avatar Weesinghe W.M.P.D

Merge branch 'IT20019204_Activity_Recognition' into 'master'

Change Styles Merge

See merge request !3
parents 19531a4d a7a78c1c
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.StringRequest;
import com.android.volley.toolbox.Volley;
import com.example.thetrek.R;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.HashMap;
import java.util.Map;
public class PredictReward extends AppCompatActivity {
EditText Latitude, Longitude, Elevation;
Button predict;
TextView Reward;
String url = "https://trek-7f4725930ac3.herokuapp.com/predict";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.predict_reward);
Latitude = findViewById(R.id.latitude);
Longitude = findViewById(R.id.longitude);
Elevation = findViewById(R.id.elevation);
predict = findViewById(R.id.predict);
Reward = findViewById(R.id.reward);
predict.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// hit the API -> Volley
StringRequest stringRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
String data = jsonObject.getString("predict");
// switch (data) {
// case "0":
// Reward.setText("Reward level 0 can get!");
// break;
// case "1":
// Reward.setText("Reward level 1 can get!");
// break;
// case "2":
// Reward.setText("Reward level 2 can get!");
// break;
// case "3":
// Reward.setText("Reward level 3 can get!");
// break;
// case "4":
// Reward.setText("Reward level 4 can get!");
// break;
// case "5":
// Reward.setText("Reward level 5 can get!");
// break;
// default:
// Reward.setText("No any reward can get!");
// break;
// }
// } catch (JSONException e) {
// e.printStackTrace();
// }
//
// }
// },
if(data.equals("0")){
Reward.setText("Reward level 0 can get!");
}else if(data.equals("1")){
Reward.setText("Reward level 1 can get!");
}else if(data.equals("2")){
Reward.setText("Reward level 2 can get!");
}else if(data.equals("3")){
Reward.setText("Reward level 3 can get!");
}else if(data.equals("4")){
Reward.setText("Reward level 4 can get!");
}else if(data.equals("5")){
Reward.setText("Reward level 5 can get!");
}else{
Reward.setText("No any reward can get!");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PredictReward.this, error.getMessage(), Toast.LENGTH_SHORT).show();
}
}){
@Override
protected Map<String,String> getParams(){
Map<String,String> params = new HashMap<String,String>();
params.put("Latitude",Latitude.getText().toString());
params.put("Longitude",Longitude.getText().toString());
params.put("Elevation",Elevation.getText().toString());
return params;
}
};
RequestQueue queue = Volley.newRequestQueue(PredictReward.this);
queue.add(stringRequest);
}
});
}
}
...@@ -11,6 +11,7 @@ import android.widget.Toast; ...@@ -11,6 +11,7 @@ import android.widget.Toast;
import com.example.thetrek.R; import com.example.thetrek.R;
import com.example.thetrek.db.LocationDAO; import com.example.thetrek.db.LocationDAO;
import com.example.thetrek.screens.findPlaces.FindPlacesActivity;
public class AddLocations extends AppCompatActivity { public class AddLocations extends AppCompatActivity {
private EditText editTextLatitude; private EditText editTextLatitude;
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:padding="16dp" android:padding="16dp"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/home" android:background="@drawable/background"
tools:context=".activities.CreateActivity"> tools:context=".activities.CreateActivity">
<TextView <TextView
...@@ -14,7 +14,8 @@ ...@@ -14,7 +14,8 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/profile_info" android:text="@string/profile_info"
android:textSize="20sp" android:textSize="20sp"
android:textColor="@color/white" android:textColor="@color/black"
android:textStyle="bold"
android:paddingBottom="12dp" android:paddingBottom="12dp"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".SuggestActivity" tools:context=".SuggestActivity"
android:background="@drawable/background"
android:orientation="vertical"> android:orientation="vertical">
<TextView <TextView
...@@ -78,7 +79,7 @@ ...@@ -78,7 +79,7 @@
<Button <Button
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="65dp" android:layout_height="65dp"
android:text="Predict" android:text="Click For Predict"
android:layout_marginTop="20dp" android:layout_marginTop="20dp"
android:textStyle="bold" android:textStyle="bold"
android:id="@+id/predict" android:id="@+id/predict"
......
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