Merge pull request #8 from LinlyBoi/api-time

Api time
This commit is contained in:
Linly
2023-12-20 13:01:17 +02:00
committed by GitHub
19 changed files with 281 additions and 154 deletions

View File

@@ -9,7 +9,7 @@ android {
defaultConfig {
applicationId = "com.example.myapp_1"
minSdk = 24
targetSdk = 33
targetSdk = 34
versionCode = 1
versionName = "1.0"
@@ -31,7 +31,7 @@ android {
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.10.0")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.gms:play-services-maps:18.2.0")
implementation("com.google.code.gson:gson:2.10.1")

View File

@@ -2,10 +2,17 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp_1">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<service
android:name=".FetchArrival"
android:enabled="true"
android:exported="true"></service>
<activity
android:name=".Predict"
android:exported="false" />

View File

@@ -0,0 +1,20 @@
package com.example.myapp_1.DB;
public class Arrival
{
public String getArrivalTime()
{
return arrivalTime;
}
public void setArrivalTime(String arrivalTime)
{
this.arrivalTime = arrivalTime;
}
private String arrivalTime;
Arrival(String time) {
this.arrivalTime = time;
}
}

View File

@@ -0,0 +1,17 @@
package com.example.myapp_1.DB;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.GET;
public interface GetArrivals
{
//Specify the request type and pass the relative URL//
@GET("/arrivals/all")
//Wrap the response in a Call object with the type of the expected result//
Call<List<Arrival>> getAllArrivals();
}

View File

@@ -0,0 +1,31 @@
package com.example.myapp_1.DB;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;
public class RetrofitClient {
private static Retrofit retrofit;
//Define the base URL//
private static final String BASE_URL = "https://localhost:8080";
//Create the Retrofit instance//
public static Retrofit getRetrofitInstance() {
if (retrofit == null) {
retrofit = new retrofit2.Retrofit.Builder()
.baseUrl(BASE_URL)
//Add the converter//
.addConverterFactory(GsonConverterFactory.create())
//Build the Retrofit instance//
.build();
}
return retrofit;
}
}

View File

@@ -0,0 +1,63 @@
package com.example.myapp_1;
import android.app.Service;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
import com.example.myapp_1.DB.Arrival;
import com.example.myapp_1.DB.GetArrivals;
import com.example.myapp_1.DB.RetrofitClient;
import java.util.List;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
public class FetchArrival extends Service
{
private static final String TAG = "MyActivity";
@Override
public int onStartCommand(Intent intent, int flags, int Startid) {
GetArrivals apiService = RetrofitClient.getRetrofitInstance().create(GetArrivals.class);
Call<List<Arrival>> call = apiService.getAllArrivals();
//Execute the request asynchronously//
call.enqueue(new Callback<List<Arrival>>() {
//Handle a successful response//
@Override
public void onResponse(Call<List<Arrival>> call, Response<List<Arrival>> response) {
SharedPreferences sp = getApplicationContext().getSharedPreferences("UserData", MODE_PRIVATE);
SharedPreferences.Editor editor = sp.edit();
// Log.d(TAG, response.body().toString());
editor.putString("response", response.body().toString());
}
//Handle execution failures//
public void onFailure(Call<List<Arrival>> call, Throwable throwable) {
System.out.println("A");
}
});
//Display the retrieved data as a list//
return START_NOT_STICKY;
}
@Override
public IBinder onBind(Intent intent)
{
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
}

View File

@@ -1,8 +1,11 @@
package com.example.myapp_1;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
@@ -20,6 +23,7 @@ public class HomeActivity extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
ImageView vec_back = findViewById(R.id.homeBackButton);
BottomNavigationView bottomNavigationView = findViewById(R.id.homeBottomView);
bottomNavigationView.setOnNavigationItemSelectedListener(
new BottomNavigationView.OnNavigationItemSelectedListener() {
@@ -42,6 +46,20 @@ public class HomeActivity extends AppCompatActivity {
return true;
}
});
TextView userGreeting = findViewById(R.id.userGreeting);
SharedPreferences currentUserThings = getApplicationContext().getSharedPreferences("UserData", MODE_PRIVATE);
String user = currentUserThings.getString("username", "");
if (user != null)
userGreeting.setText("Welcome " + user + "!");
String response = currentUserThings.getString("response", "");
TextView prediction = findViewById(R.id.prediction);
prediction.setText(response);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), LoginActivity.class);
startActivity(newScreen);
});
}
}

View File

@@ -1,11 +1,10 @@
package com.example.myapp_1;
import android.content.Intent;
import android.content.SharedPreferences;
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;
@@ -13,10 +12,10 @@ import androidx.appcompat.app.AppCompatActivity;
import com.example.myapp_1.DB.DBOperations;
public class LoginActivity extends AppCompatActivity {
SharedPreferences currentUserThings;
EditText username;
EditText password;
TextView forgetpassword;
Button login;
Button signup;
@@ -27,64 +26,52 @@ public class LoginActivity extends AppCompatActivity {
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
currentUserThings = getSharedPreferences("UserData", MODE_PRIVATE);
username = findViewById(R.id.editTextText);
password = findViewById(R.id.editTextTextPassword);
// forgetpassword = findViewById(R.id.forgetpass);
login = findViewById(R.id.button);
signup = findViewById(R.id.button2);
guestLogin= findViewById(R.id.button3);
// forgetpassword.setOnClickListener(new View.OnClickListener() {
// @Override
// public void onClick(View v) {
// Intent newScreen = new Intent(getApplicationContext(), PasswordResetActivity.class);
// startActivity(newScreen);
// }
// });
signup.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent newScreen = new Intent(getApplicationContext(), SigninActivity.class);
startActivity(newScreen);
}
login = findViewById(R.id.loginButton);
signup = findViewById(R.id.signupButton);
guestLogin= findViewById(R.id.guestButton);
SharedPreferences.Editor editor = currentUserThings.edit();
signup.setOnClickListener(v -> {
Intent newScreen = new Intent(getApplicationContext(), SigninActivity.class);
startActivity(newScreen);
});
guestLogin.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
}
guestLogin.setOnClickListener(v -> {
editor.putString("username", "Guest");
editor.apply();
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login.setOnClickListener(v -> {
String username_data = username.getText().toString();
String password_data = password.getText().toString();
String username_data = username.getText().toString();
String password_data = password.getText().toString();
if(username_data.isEmpty() || password_data.isEmpty()){
Toast.makeText(LoginActivity.this,"Please fill your data!", Toast.LENGTH_LONG).show();
}else{
if (dbOperations.checkLoginCredentials(username_data, password_data)) {
// Login successful
// Proceed to the next screen or perform other actions
Toast.makeText(LoginActivity.this,"Welcome", Toast.LENGTH_LONG).show();
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
if(username_data.isEmpty() || password_data.isEmpty()){
Toast.makeText(LoginActivity.this,"Please fill your data!", Toast.LENGTH_LONG).show();
}else{
if (dbOperations.checkLoginCredentials(username_data, password_data)) {
// Login successful
// Proceed to the next screen or perform other actions
Toast.makeText(LoginActivity.this,"Welcome", Toast.LENGTH_LONG).show();
editor.putString("username", username_data);
editor.apply();
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
} else {
// Login failed
} else {
// Login failed
Toast.makeText(LoginActivity.this,"Invalid Iformation", Toast.LENGTH_LONG).show();
}
Toast.makeText(LoginActivity.this,"Invalid Iformation", Toast.LENGTH_LONG).show();
}
}
});
}
}

View File

@@ -1,14 +1,21 @@
package com.example.myapp_1;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class NotificationActivity extends AppCompatActivity {
ImageView vec_back;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notification);
vec_back = findViewById(R.id.notificationBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
}
}

View File

@@ -20,7 +20,7 @@ public class PasswordResetActivity extends AppCompatActivity {
setContentView(R.layout.activity_password_reset);
email = findViewById(R.id.editTextTextEmailAddress);
reset = findViewById(R.id.button3);
reset = findViewById(R.id.guestButton);
reset.setOnClickListener(new View.OnClickListener() {

View File

@@ -33,55 +33,52 @@ public class Predict extends AppCompatActivity {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_predict);
vec_back = findViewById(R.id.imageView2);
vec_back = findViewById(R.id.predictBackButton);
edi_station = findViewById(R.id.editTextText);
edi_weather = findViewById(R.id.editTextText2);
btn_pred = findViewById(R.id.button4);
prog_bar = findViewById(R.id.progressBar);
txt_station = findViewById(R.id.textView4);
txt_station = findViewById(R.id.prediction);
txt_pred_time = findViewById(R.id.predicted_time);
vec_back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
}
vec_back = findViewById(R.id.predictBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
btn_pred.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String station = edi_station.getText().toString();
String weather = edi_weather.getText().toString();
btn_pred.setOnClickListener(view -> {
String station = edi_station.getText().toString();
String weather = edi_weather.getText().toString();
if(station.isEmpty() || weather.isEmpty()) {
Toast.makeText(Predict.this, "Please enter something", Toast.LENGTH_SHORT).show();
}else{
// we will pass the input features to the model to predict
// then display predictions
if(station.isEmpty() || weather.isEmpty()) {
Toast.makeText(Predict.this, "Please enter something", Toast.LENGTH_SHORT).show();
}else{
// we will pass the input features to the model to predict
// then display predictions
txt_station.setText(station);
txt_station.setText(station);
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 10; i++){
prog_bar.incrementProgressBy(10);
SystemClock.sleep(500);
}
prog_bar.setVisibility(View.GONE);
long currentTimeMillis = System.currentTimeMillis();
// Create a SimpleDateFormat object to format the time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Format the time and set it to the TextView
txt_pred_time.setText(sdf.format(new Date(currentTimeMillis)));
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
for(int i = 0; i < 10; i++){
prog_bar.incrementProgressBy(10);
SystemClock.sleep(500);
}
});
thread.start();
prog_bar.setVisibility(View.GONE);
long currentTimeMillis = System.currentTimeMillis();
// Create a SimpleDateFormat object to format the time
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
// Format the time and set it to the TextView
txt_pred_time.setText(sdf.format(new Date(currentTimeMillis)));
}
});
Intent apiService = new Intent(this, FetchArrival.class);
startService(apiService);
thread.start();
}
}
});
}

View File

@@ -2,13 +2,21 @@ package com.example.myapp_1;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.ImageView;
public class Schedule extends AppCompatActivity {
ImageView vec_back;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_schedule);
vec_back = findViewById(R.id.ScheduleBackButton);
vec_back.setOnClickListener(view -> {
Intent newScreen = new Intent(getApplicationContext(), HomeActivity.class);
startActivity(newScreen);
});
}
}

View File

@@ -29,19 +29,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/homeToolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
<ImageView
android:id="@+id/homeBackButton"
android:layout_width="46dp"
android:layout_height="48dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_arrow_back_ios"
app:title="Home"
app:titleCentered="true" />
app:srcCompat="@drawable/_vector" />
<TextView
android:id="@+id/userGreeting"
@@ -59,7 +55,7 @@
app:layout_constraintTop_toBottomOf="@+id/train_image" />
<TextView
android:id="@+id/textView4"
android:id="@+id/prediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"

View File

@@ -43,7 +43,7 @@
android:inputType="textPassword" />
<Button
android:id="@+id/button"
android:id="@+id/loginButton"
style="@android:style/Widget.Material.Button.Inset"
android:layout_width="311dp"
android:layout_height="60dp"
@@ -63,7 +63,7 @@
<Button
android:id="@+id/button3"
android:id="@+id/guestButton"
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="150dp"
android:layout_height="60dp"
@@ -74,7 +74,7 @@
android:text="Guest Login" />
<Button
android:id="@+id/button2"
android:id="@+id/signupButton"
style="@style/Widget.MaterialComponents.Button.UnelevatedButton"
android:layout_width="150dp"
android:layout_height="60dp"

View File

@@ -5,40 +5,23 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:id="@+id/notifBottomView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:menu="@menu/botton_menu" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
<ImageView
android:id="@+id/notificationBackButton"
android:layout_width="42dp"
android:layout_height="40dp"
android:layout_marginStart="16dp"
android:layout_marginTop="72dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_arrow_back_ios"
app:title="Notification"
app:titleCentered="true" />
app:srcCompat="@drawable/_vector" />
<ListView
android:layout_width="409dp"
android:layout_height="471dp"
app:layout_constraintBottom_toTopOf="@+id/notifBottomView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar3"
app:layout_constraintVertical_bias="0.0" />
tools:layout_editor_absoluteY="188dp" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -52,7 +52,7 @@
app:layout_constraintTop_toBottomOf="@+id/editTextTextMultiLine" />
<Button
android:id="@+id/button3"
android:id="@+id/guestButton"
android:layout_width="184dp"
android:layout_height="50dp"
android:layout_marginTop="32dp"

View File

@@ -7,7 +7,7 @@
tools:context=".Predict">
<ImageView
android:id="@+id/imageView2"
android:id="@+id/predictBackButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="25dp"
@@ -135,7 +135,7 @@
app:layout_constraintTop_toBottomOf="@+id/userGreeting" />
<TextView
android:id="@+id/textView4"
android:id="@+id/prediction"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"

View File

@@ -6,33 +6,27 @@
android:layout_height="match_parent"
tools:context=".Schedule">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/material_dynamic_primary60"
android:minHeight="?attr/actionBarSize"
android:theme="?attr/actionBarTheme"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
<ImageView
android:id="@+id/ScheduleBackButton"
android:layout_width="55dp"
android:layout_height="48dp"
android:layout_marginStart="4dp"
android:layout_marginTop="24dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:navigationIcon="@drawable/baseline_arrow_back_ios"
app:title="Schedule"
app:titleCentered="true" />
app:srcCompat="@drawable/_vector" />
<TextView
android:id="@+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="40dp"
android:layout_marginTop="36dp"
android:text="Start Startion:"
android:textColor="@color/black"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar" />
tools:layout_editor_absoluteY="92dp" />
<TextView
android:id="@+id/textView9"
@@ -167,13 +161,12 @@
android:id="@+id/button7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="44dp"
android:text="Search Tram"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/toolbar"
app:layout_constraintVertical_bias="0.931" />
app:layout_constraintHorizontal_bias="0.486"
app:layout_constraintStart_toStartOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -20,7 +20,7 @@
app:titleCentered="true" />
<ImageView
android:id="@+id/imageView2"
android:id="@+id/predictBackButton"
android:layout_width="159dp"
android:layout_height="104dp"
android:layout_marginTop="100dp"
@@ -50,10 +50,10 @@
android:drawablePadding="16dp"
android:ems="10"
android:inputType="text"
app:layout_constraintEnd_toEndOf="@+id/imageView2"
app:layout_constraintEnd_toEndOf="@+id/predictBackButton"
app:layout_constraintHorizontal_bias="0.483"
app:layout_constraintStart_toStartOf="@+id/imageView2"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
app:layout_constraintStart_toStartOf="@+id/predictBackButton"
app:layout_constraintTop_toBottomOf="@+id/predictBackButton" />
<EditText
android:id="@+id/editTextText3"