Commit 08e00bee authored by Solatnik Luka's avatar Solatnik Luka 🏀
Browse files

štima vse

parent 78a6a744
......@@ -25,6 +25,9 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildFeatures {
viewBinding true
}
}
dependencies {
......@@ -32,7 +35,30 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.4.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation 'com.google.android.gms:play-services-maps:17.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
annotationProcessor "androidx.room:room-compiler:$room_version"
// optional - RxJava2 support for Room
implementation "androidx.room:room-rxjava2:$room_version"
// optional - RxJava3 support for Room
implementation "androidx.room:room-rxjava3:$room_version"
// optional - Guava support for Room, including Optional and ListenableFuture
implementation "androidx.room:room-guava:$room_version"
// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"
// optional - Paging 3 Integration
implementation "androidx.room:room-paging:2.5.0-alpha01"
}
\ No newline at end of file
<resources>
<!--
TODO: Before you run your application, you need a Google Maps API key.
To get one, follow this link, follow the directions and press "Create" at the end:
https://console.developers.google.com/flows/enableapi?apiid=maps_android_backend&keyType=CLIENT_SIDE_ANDROID&r=5A:8C:9C:AB:A0:8B:C1:62:29:50:AE:3E:87:E6:AF:E7:40:38:68:A6%3Bcom.example.senzorji
You can also add your credentials to an existing key, using these values:
Package name:
com.example.senzorji
SHA-1 certificate fingerprint:
5A:8C:9C:AB:A0:8B:C1:62:29:50:AE:3E:87:E6:AF:E7:40:38:68:A6
Alternatively, follow the directions here:
https://developers.google.com/maps/documentation/android/start#get-key
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string>
</resources>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.senzorji" >
package="com.example.senzorji">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<!--
The ACCESS_COARSE/FINE_LOCATION permissions are not required to use
Google Maps Android API v2, but you must specify either coarse or fine
location permissions for the "MyLocation" functionality.
-->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<application
android:allowBackup="true"
......@@ -11,27 +16,41 @@
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Senzorji" >
android:theme="@style/Theme.Senzorji">
<!--
The API key for Google Maps-based APIs is defined as a string resource.
(See the file "res/values/google_maps_api.xml").
Note that the API key is linked to the encryption key used to sign the APK.
You need a different API key for each encryption key, including the release key that is used to
sign the APK for publishing.
You can define the keys for the debug and release targets in src/debug/ and src/release/.
-->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyD9yXq7vJ3wMr54EUYmum4weBUqH98S0g8" />
<activity
android:name=".MapsActivity"
android:exported="false"
android:label="@string/title_activity_maps" />
<service
android:name=".GpsTracker"
android:enabled="true"
android:exported="true" >
</service>
android:exported="true"></service>
<activity
android:name=".MainActivity"
android:exported="true" >
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Pospesek" >
</activity>
<activity android:name=".Gps" >
</activity>
<activity android:name=".Pospesek"></activity>
<activity android:name=".Gps"></activity>
</application>
</manifest>
\ No newline at end of file
......@@ -34,11 +34,11 @@ public class Gps extends AppCompatActivity {
broadcastReceiver = new BroadcastReceiver(){
@Override
public void onReceive(Context context, Intent intent){
String lokacija = (String) intent.getExtras().get("Lokacija");
String lokacija = (String) intent.getExtras().get("lokacija");
kord.setText(lokacija);
}
};
registerReceiver(broadcastReceiver, new IntentFilter("updat_lokacija"));
registerReceiver(broadcastReceiver, new IntentFilter("update_lokacija"));
}
}
......@@ -60,7 +60,7 @@ public class GpsTracker extends Service implements LocationListener {
public void onLocationChanged(@NonNull Location location) {
double lat = location.getLatitude();
double lon= location.getLongitude();
Intent intent = new Intent("updat_lokacija");
Intent intent = new Intent("update_lokacija");
intent.putExtra("Lokacija", lat + " " + lon);
sendBroadcast(intent);
......
......@@ -63,6 +63,17 @@ public class MainActivity extends AppCompatActivity {
});
}
if (!dovoljenja()) {
gumb3.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(getApplicationContext(), MapsActivity.class);
startActivity(intent);
}
});
}
}
......
package com.example.senzorji;
import androidx.fragment.app.FragmentActivity;
import androidx.room.Room;
import android.annotation.SuppressLint;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import com.example.senzorji.db.Lokacija;
import com.example.senzorji.db.LokacijaDao;
import com.example.senzorji.db.LokacijaDatabase;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.example.senzorji.databinding.ActivityMapsBinding;
import java.io.IOException;
import java.text.BreakIterator;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Locale;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback {
private GoogleMap mMap;
private ActivityMapsBinding binding;
private BroadcastReceiver broadcastReceiver;
public LokacijaDatabase db;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent intent = new Intent(getApplicationContext(),GpsTracker.class);
startService(intent);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
db = Room.databaseBuilder(getApplicationContext(),
LokacijaDatabase.class, "database-name").build();
}
/**
* Manipulates the map once available.
* This callback is triggered when the map is ready to be used.
* This is where we can add markers or lines, add listeners or move the camera. In this case,
* we just add a marker near Sydney, Australia.
* If Google Play services is not installed on the device, the user will be prompted to install
* it inside the SupportMapFragment. This method will only be triggered once the user has
* installed Google Play services and returned to the app.
*/
@SuppressLint("MissingPermission")
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
mMap.setMyLocationEnabled(true);
mMap.setMapType(GoogleMap.MAP_TYPE_SATELLITE);
mMap.getUiSettings().setZoomGesturesEnabled(true);
mMap.getUiSettings().setMyLocationButtonEnabled(true);
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
@Override
protected void onResume() {
super.onResume();
broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String lokacija = (String) intent.getExtras().get("Lokacija");
String [] ab = lokacija.split(" ");
double lat= Double.parseDouble(ab[0]);
double lon= Double.parseDouble(ab[1]);
Address a = getNaslovLokacije(lat, lon);
String nasl = a.getAddressLine(0);
shraniLokacijo(lat, lon, nasl);
LatLng lok = new LatLng(lat, lon);
mMap.addMarker(new MarkerOptions().position(lok).title("nasl"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(lok));
}
};
registerReceiver(broadcastReceiver, new IntentFilter("update_lokacija"));
}
public void shraniLokacijo(double lat, double lon, String naslov){
String datum= getDatum();
Lokacija lok= new Lokacija(lat, lon, naslov, datum);
new Thread(new Runnable() {
@Override
public void run() {
LokacijaDao lokacijaDao = db.lokacijaDao();
lokacijaDao.vstaviLokacijo(lok);
}
}).start();
}
public String getDatum(){
SimpleDateFormat sdf = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
String currentDateandTime = sdf.format(new Date());
return currentDateandTime;
}
public Address getNaslovLokacije(double lat, double lon){
Geocoder gc = new Geocoder(this, Locale.getDefault());
try {
List<Address> naslov = gc.getFromLocation(lat, lon, 1);
if (naslov.size() > 0){
Address address = naslov.get(0);
return address;
}
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
package com.example.senzorji.db;
import androidx.room.ColumnInfo;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "lokacija")
public class Lokacija {
@PrimaryKey(autoGenerate = true)
@ColumnInfo(name = "id")
public int id;
@ColumnInfo(name = "latitude")
public double latitude;
@ColumnInfo(name = "longitude")
public double longitude;
@ColumnInfo(name = "naslov")
public String naslov;
@ColumnInfo(name = "datum")
public String datum;
public Lokacija(double latitude, double longitude, String naslov, String datum) {
this.latitude = latitude;
this.longitude = longitude;
this.naslov = naslov;
this.datum = datum;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public double getLatitude() {
return latitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public double getLongitude() {
return longitude;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public String getNaslov() {
return naslov;
}
public void setNaslov(String naslov) {
this.naslov = naslov;
}
public String getDatum() {
return datum;
}
public void setDatum(String datum) {
this.datum = datum;
}
}
package com.example.senzorji.db;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.Query;
import java.util.List;
@Dao
public interface LokacijaDao {
@Query("Select * from lokacija")
List<Lokacija> getAll();
@Query("select * from lokacija where naslov like :naslov")
public Lokacija findLokacijaByNaslov(String naslov);
@Insert
void vstaviLokacijo(Lokacija lokacija);
@Delete
void delete(Lokacija l);
}
package com.example.senzorji.db;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
@Database(entities = {Lokacija.class}, version = 1)
public abstract class LokacijaDatabase extends RoomDatabase {
public abstract LokacijaDao lokacijaDao();
}
......@@ -36,7 +36,7 @@
android:layout_width="120dp"
android:layout_height="60dp"
android:layout_marginTop="63dp"
android:text="idk"
android:text="maps"
app:layout_constraintBottom_toBottomOf="@+id/scrollView2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.945"
......
<?xml version="1.0" encoding="utf-8"?>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MapsActivity" />
\ No newline at end of file
<resources>
<string name="app_name">senzorji</string>
<string name="title_activity_maps">MapsActivity</string>
</resources>
\ No newline at end of file
<resources>
<!--
TODO: Before you release your application, you need a Google Maps API key.
To do this, you can either add your release key credentials to your existing
key, or create a new key.
Note that this file specifies the API key for the release build target.
If you have previously set up a key for the debug target with the debug signing certificate,
you will also need to set up a key for your release certificate.
Follow the directions here:
https://developers.google.com/maps/documentation/android/signup
Once you have your key (it starts with "AIza"), replace the "google_maps_key"
string in this file.
-->
<string name="google_maps_key" templateMergeStrategy="preserve" translatable="false">YOUR_KEY_HERE</string>
</resources>
\ 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