diff --git a/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/service/LocationService.java b/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/service/LocationService.java index 4bd3c4d..82a6432 100644 --- a/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/service/LocationService.java +++ b/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/service/LocationService.java @@ -49,7 +49,7 @@ public class LocationService extends Service { .putFloat("latitude", (float) locationResult.getLocations().get(0).getLatitude()) .putFloat("longitude", (float) locationResult.getLocations().get(0).getLongitude()) .putFloat("altitude", (float) locationResult.getLocations().get(0).getAltitude()) - .putFloat("accuracy", (float) locationResult.getLocations().get(0).getAccuracy()) + .putFloat("accuracy", locationResult.getLocations().get(0).getAccuracy()) .putFloat("speed", locationResult.getLocations().get(0).getSpeed()).apply(); } @@ -102,7 +102,7 @@ public class LocationService extends Service { notification = new NotificationCompat.Builder(this, CHANNEL_ID) .setContentText("Updating location") .setContentTitle("DailyHelper Location Service") - .setSmallIcon(R.drawable.ic_star) + .setSmallIcon(R.drawable.ic_location_on) .setContentIntent(pendingIntent).build(); } diff --git a/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/ui/fragemnt/HomeFragment.java b/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/ui/fragemnt/HomeFragment.java index 86f7ca0..bfd76e7 100644 --- a/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/ui/fragemnt/HomeFragment.java +++ b/DailyHelper/app/src/main/java/at/fhj/swd/dailyhelper/ui/fragemnt/HomeFragment.java @@ -1,21 +1,67 @@ package at.fhj.swd.dailyhelper.ui.fragemnt; +import android.content.Context; +import android.content.SharedPreferences; import android.os.Bundle; +import android.os.Handler; +import android.preference.PreferenceManager; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.Fragment; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; +import android.widget.TextView; import at.fhj.swd.dailyhelper.R; +import at.fhj.swd.dailyhelper.service.LocationService; public class HomeFragment extends Fragment { + private TextView tvLongitude; + private TextView tvLatitude; + private TextView tvSpeed; + private TextView tvAltitude; + private TextView tvAccuracy; + + + private Context context; + private Handler handler; + private SharedPreferences preferences; + @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = inflater.inflate(R.layout.fragment_home, container, false); + context = this.getContext(); + + preferences = PreferenceManager.getDefaultSharedPreferences(this.getContext()); + + tvLongitude = view.findViewById(R.id.tv_longitude); + tvLatitude = view.findViewById(R.id.tv_latitude); + tvSpeed = view.findViewById(R.id.tv_speed); + tvAltitude = view.findViewById(R.id.tv_altitude); + tvAccuracy = view.findViewById(R.id.tv_accuracy); + + + // Create the Handler object (on the main thread by default) + handler = new Handler(); + // Define the code block to be executed + Runnable runnableCode = new Runnable() { + @Override + public void run() { + + tvLongitude.setText(context.getString(R.string.longitude) +": "+ preferences.getFloat("longitude", -1000)); + tvLatitude.setText(context.getString(R.string.latitude) +": "+ preferences.getFloat("latitude", -1000)); + tvSpeed.setText(context.getString(R.string.speed) +": "+ preferences.getFloat("speed", -1000)); + tvAltitude.setText(context.getString(R.string.altitude) +": "+ preferences.getFloat("altitude", -1000)); + tvAccuracy.setText(context.getString(R.string.accuracy) +": "+ preferences.getFloat("accuracy", -1000)); + + handler.postDelayed(this, 2000); + } + }; + // Start the initial runnable task by posting through the handler + handler.post(runnableCode); return view; } diff --git a/DailyHelper/app/src/main/res/layout/fragment_home.xml b/DailyHelper/app/src/main/res/layout/fragment_home.xml index 433925b..ba1ab07 100644 --- a/DailyHelper/app/src/main/res/layout/fragment_home.xml +++ b/DailyHelper/app/src/main/res/layout/fragment_home.xml @@ -18,36 +18,36 @@ @@ -55,7 +55,7 @@ diff --git a/DailyHelper/app/src/main/res/values/strings.xml b/DailyHelper/app/src/main/res/values/strings.xml index f68dcbe..e6cd234 100644 --- a/DailyHelper/app/src/main/res/values/strings.xml +++ b/DailyHelper/app/src/main/res/values/strings.xml @@ -15,6 +15,12 @@ AIzaSyBQhcmDlyP01yNwTd4RTlatQIAJH3wJHw0 Karte - Satelit + Satellit + Längengrad + Breitengrad + Geschwindigkeit + Seehöhe + Genauigkeit + Position: