Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/mmichal10/OBD-II
Browse files Browse the repository at this point in the history
  • Loading branch information
rogl committed Dec 2, 2018
2 parents 1601865 + 2bf2f14 commit d0d709e
Show file tree
Hide file tree
Showing 45 changed files with 941 additions and 164 deletions.
73 changes: 73 additions & 0 deletions .idea/assetWizardSettings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified .idea/caches/build_file_checksums.ser
Binary file not shown.
1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,19 @@ dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
implementation 'com.github.pires:obd-java-api:1.0'
implementation 'org.mapsforge:mapsforge-map-android:0.9.1'
implementation 'com.caverock:androidsvg:1.3'
implementation 'com.google.android.gms:play-services-maps:16.0.0'
implementation 'org.mapsforge:mapsforge-core:0.9.1'
implementation 'org.mapsforge:mapsforge-map:0.9.1'
implementation(group: 'com.graphhopper', name: 'graphhopper-core', version: '0.11.0') {
exclude group: 'com.google.protobuf', module: 'protobuf-java'
exclude group: 'org.openstreetmap.osmosis', module: 'osmosis-osm-binary'
exclude group: 'org.apache.xmlgraphics', module: 'xmlgraphics-commons'
}
implementation 'org.nd4j:nd4j-backends:0.9.1'
implementation 'org.mapsforge:vtm:0.9.2'
implementation 'com.google.code.gson:gson:2.8.0'
implementation 'com.android.volley:volley:1.0.0'

}
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
Expand All @@ -18,7 +22,8 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".bt_connection.BluetoothConnectionService" android:enabled="true"/>
<service android:name=".networking.BluetoothConnectionService" android:enabled="true"/>
<receiver android:name=".networking.ServerConnection" android:enabled="true"/>
</application>

</manifest>
112 changes: 112 additions & 0 deletions app/src/main/java/com/example/michal/inz/Location.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
package com.example.michal.inz;

import android.content.Context;
import android.content.pm.PackageManager;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import com.example.michal.inz.fragments.MapsFragment;

import static android.Manifest.permission.ACCESS_FINE_LOCATION;


public class Location implements LocationListener {

private Context applicationContext;
public LocationManager locationManager;
boolean canGetLocation = false;
android.location.Location location;
double latitude;
MapsFragment mapa;
public double longitude;
private static final long MIN_DISTANCE_CHANGE_FOR_UPDATES = 1; // 1 meter
private static final long MIN_TIME_BW_UPDATES = 1; // 1 sec

public Location(Context context, MapsFragment mapsFragment){
this.applicationContext = context;
this.mapa = mapsFragment;
getLocation();
}

@Override
public void onLocationChanged(android.location.Location location) {
setLatitude(location.getLatitude());
setLongitude(location.getLongitude());
mapa.updateLocation();
}

public android.location.Location getLocation() {

try {
locationManager = (LocationManager) applicationContext.getSystemService(Context.LOCATION_SERVICE);
// getting GPS status
boolean checkGPS = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);

Log.v("isGPSEnabled", "=" + checkGPS);

if (!checkGPS) {
// no network provider is enabled
} else {
this.canGetLocation = true;
// if GPS Enabled get lat/long using GPS Services
if (checkGPS) {
location = null;
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}

} catch (Exception e) {
e.printStackTrace();
}

return location;
}

@Override
public void onStatusChanged(String s, int i, Bundle bundle) {

}

@Override
public void onProviderEnabled(String s) {

}

@Override
public void onProviderDisabled(String s) {

}

public double getLatitude() {
return latitude;
}

public void setLatitude(double latitude) {
this.latitude = latitude;
}

public double getLongitude() {
return longitude;
}

private void setLongitude(double longitude) {
this.longitude = longitude;
}
}
59 changes: 59 additions & 0 deletions app/src/main/java/com/example/michal/inz/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,23 @@
package com.example.michal.inz;

import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.ActivityCompat;
import android.support.v4.content.ContextCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;

import com.example.michal.inz.fragments.ViewPagerAdapter;
import com.example.michal.inz.networking.Stats;

import static android.Manifest.permission.ACCESS_FINE_LOCATION;
import static android.Manifest.permission.BLUETOOTH;
import static android.Manifest.permission.BLUETOOTH_ADMIN;
import static android.Manifest.permission.INTERNET;
import static android.Manifest.permission.READ_EXTERNAL_STORAGE;
import static android.Manifest.permission.WRITE_EXTERNAL_STORAGE;

public class MainActivity extends AppCompatActivity {

Expand All @@ -31,5 +42,53 @@ protected void onCreate(Bundle savedInstanceState) {

tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);

checkPermissions();
}

private void checkPermissions() {
//read external storage
if (ContextCompat.checkSelfPermission(this, READ_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{READ_EXTERNAL_STORAGE},
1);
}

//bluetooth
if (ContextCompat.checkSelfPermission(this, BLUETOOTH) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{BLUETOOTH},
2);
}

//BLUETOOTH_ADMIN
if (ContextCompat.checkSelfPermission(this, BLUETOOTH_ADMIN) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{BLUETOOTH_ADMIN},
3);
}

//GPS
if (ContextCompat.checkSelfPermission(this, ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{ACCESS_FINE_LOCATION},
4);
}

//Internet
if (ContextCompat.checkSelfPermission(this, INTERNET) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{INTERNET},
5);
}

if (ContextCompat.checkSelfPermission(this, WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{WRITE_EXTERNAL_STORAGE},
5);
} else {
// Permission has already been granted
}

}
}
36 changes: 36 additions & 0 deletions app/src/main/java/com/example/michal/inz/MyMapView.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.example.michal.inz;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import com.example.michal.inz.fragments.MapsFragment;
import org.mapsforge.map.android.view.MapView;

public class MyMapView extends MapView {

public boolean centerLock = false;
MapsFragment parentFragment;

public void setParentFragment(MapsFragment parentFragment) {
this.parentFragment = parentFragment;
}

public MyMapView(Context context) {
super(context);
}

public MyMapView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
}

@Override
public boolean onTouchEvent(MotionEvent event) {
if (event.getAction() == MotionEvent.ACTION_MOVE) {
centerLock = true;
parentFragment.updateLocation();
// this.myMap = new AndroidMap(this);
}
return super.onTouchEvent(event);
}
}

Loading

0 comments on commit d0d709e

Please sign in to comment.