Skip to content

Commit

Permalink
Issues geosolutions-it#115 add NFC support geosolutions-it#116 add QR…
Browse files Browse the repository at this point in the history
…code support geosolutions-it#119 Add the possibility to push notification for bike found
  • Loading branch information
taba90 committed Oct 7, 2020
1 parent 8d0ae77 commit 754edf7
Show file tree
Hide file tree
Showing 33 changed files with 2,500 additions and 1,136 deletions.
9 changes: 7 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ android {
compileSdkVersion 27
defaultConfig {
applicationId "it.geosolutions.savemybike"
minSdkVersion 23
minSdkVersion 26
targetSdkVersion 27
versionCode 14
versionName "0.9.1"
versionName "2.9.1"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true

Expand Down Expand Up @@ -98,6 +98,11 @@ dependencies {
implementation 'com.pacioianu.david:ink-page-indicator:1.3.0'
implementation 'com.google.firebase:firebase-core:16.0.4'
implementation 'com.google.firebase:firebase-messaging:17.3.4'

implementation 'me.dm7.barcodescanner:zxing:1.9.13'
implementation 'com.journeyapps:zxing-android-embedded:3.6.0@aar'
implementation 'com.google.zxing:core:3.3.3'

}

configurations.all {
Expand Down
39 changes: 39 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.NFC" />
<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />

<uses-feature android:name="android.hardware.bluetooth_le" />
<uses-feature android:name="android.hardware.camera2"/>

<uses-feature
android:glEsVersion="0x00020000"
Expand Down Expand Up @@ -53,6 +62,18 @@
android:screenOrientation="portrait"
android:theme="@style/AppTheme"
android:windowSoftInputMode="adjustPan">
<intent-filter>
<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
<category android:name="android.intent.category.DEFAULT"/>
<data android:mimeType="text/plain" />
</intent-filter>
<intent-filter>
<action android:name="android.nfc.action.TECH_DISCOVERED" />
</intent-filter>

<meta-data
android:name="android.nfc.action.TECH_DISCOVERED"
android:resource="@xml/nfc_tech_filter" />

<!--
NOTE: android:windowSoftInputMode="adjustPan" is required to allow the user to see the text when editing "bike lost" message.
Expand Down Expand Up @@ -88,6 +109,24 @@
android:label="@string/title_activity_complete_profile"
android:screenOrientation="portrait"
android:theme="@style/AppTheme"></activity>


<!-- Bluetooth -->
<service
android:name=".data.service.BluetoothService"
android:enabled="true" />
<service android:name=".sensors.bluetooth.BluetoothJobService"
android:enabled="true"
android:permission="android.permission.BIND_JOB_SERVICE" >
</service>

<receiver android:name=".sensors.bluetooth.BluetoothJobReceiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="it.geosolutions.savemybike.APP_STARTED" />
<action android:name="it.geosolutions.savemybike.bluetooth.STOP_BLE"/>
</intent-filter>
</receiver>
</application>

</manifest>
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package it.geosolutions.savemybike;

import android.app.PendingIntent;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
Expand All @@ -10,11 +9,8 @@
import com.google.firebase.messaging.FirebaseMessagingService;
import com.google.firebase.messaging.RemoteMessage;

import java.util.Map;

import it.geosolutions.savemybike.data.Constants;
import it.geosolutions.savemybike.data.service.UserNotificationManager;
import it.geosolutions.savemybike.ui.activity.LoginActivity;

/**
* Manages Firebase messages
Expand Down Expand Up @@ -49,12 +45,13 @@ public static final class NOTIFICATION_KEYS {
@Override
public void onNewToken(String token) {
Log.d(TAG, "Refreshed token: " + token);

// If you want to send messages to this application instance or
// manage this apps subscriptions on the server side, send the
// Instance ID token to your app server.
storeRegistration(token);
}


@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
// ...
Expand Down Expand Up @@ -107,6 +104,7 @@ private void handleBikeObserved(String bikeId, String observationId) {
getUserNotificationManager().notifyBikeObserved(bikeId, observationId);
}


/**
* Handles a notification of an invalid track error
* @param errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,12 @@ public static final class Channels {
public static final String BIKE_OBSERVATION_NAME = "Bike Observations";
}

public static final String APP_STARTED ="it.geosolutions.savemybike.APP_STARTED";

public static final String BOOT_EVENT ="android.intent.action.BOOT_COMPLETED";

public static final String STOP_BLE = "it.geosolutions.savemybike.bluetooth.STOP_BLE";



}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import it.geosolutions.savemybike.model.Bike;
import it.geosolutions.savemybike.model.Configuration;
import it.geosolutions.savemybike.model.CurrentStatus;
import it.geosolutions.savemybike.model.Observation;
import it.geosolutions.savemybike.model.PaginatedResult;
import it.geosolutions.savemybike.model.Track;
import it.geosolutions.savemybike.model.TrackItem;
Expand Down Expand Up @@ -50,11 +51,20 @@ Call<ResponseBody> upload(
@GET("api/my-bike-observations/")
Call<ResponseBody> getBikeObservations(@Query("bike") String id);

@POST("api/bike-observations/")
Call<Object> sendNewBikeObservations(@Body Observation observation);

@POST("api/my-bike-statuses/")
Call<Object> sendNewBikeStatus(
@Body CurrentStatus newStatus
);

@GET("api/tagged-bike/")
Call<ResponseBody> getTaggedBike(@Query("epc") String epc);

@GET("api/my-tagged-bike/")
Call<ResponseBody> getMyTaggedBike(@Query("epc") String epc);

@GET("api/my-tracks/?format=json")
Call<PaginatedResult<TrackItem>> getTracks();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,15 @@
import android.content.Intent;
import android.support.v4.app.NotificationCompat;

import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;

import it.geosolutions.savemybike.R;
import it.geosolutions.savemybike.data.Constants;
import it.geosolutions.savemybike.ui.activity.LoginActivity;
import it.geosolutions.savemybike.ui.activity.SaveMyBikeActivity;
import it.geosolutions.savemybike.ui.adapters.BadgeAdapter;
import it.geosolutions.savemybike.ui.utils.BadgeUtils;

import static it.geosolutions.savemybike.ui.activity.SaveMyBikeActivity.EXTRA_BIKE_FOUND;

/**
* Manager for user notification (tracks status update, badges, prizes).
* TODO: merge with existing @see {@link it.geosolutions.savemybike.data.service.NotificationManager} that manages the permanent notification
Expand Down Expand Up @@ -177,4 +176,23 @@ public void notifyBikeObserved(String bikeId, String observationId) {
mNotificationManager.notify(getID(), mBuilder.build());
}
}

public void notifyNearLostBike(String bike) {
android.app.NotificationManager mNotificationManager =
(android.app.NotificationManager) (android.app.NotificationManager) mCtx.getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(mCtx, Constants.Channels.BIKE_OBSERVATION)
.setSmallIcon(R.mipmap.ic_launcher_foreground)
.setBadgeIconType(R.drawable.ic_directions_bike)
.setContentTitle(mCtx.getResources().getString(R.string.lost_bike_found_notification))
.setAutoCancel(true);
Intent resultIntent = new Intent(mCtx, SaveMyBikeActivity.class);
resultIntent.putExtra(SaveMyBikeActivity.EXTRA_PAGE, EXTRA_BIKE_FOUND);
resultIntent.putExtra(SaveMyBikeActivity.EXTRA_DATA, bike);
PendingIntent pendingIntent = PendingIntent.getActivity(mCtx, getID(), resultIntent, PendingIntent.FLAG_CANCEL_CURRENT);
mBuilder.setContentIntent(pendingIntent);
if (mNotificationManager != null) {
mNotificationManager.notify(getID(), mBuilder.build());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,23 @@

import android.util.Log;

import com.google.gson.JsonObject;

import org.json.JSONException;
import org.json.JSONObject;

/**
*
*/
public class Observation {
public String id;
public String observedAt;
public String address;
private String id;
private String observedAt;
private String address;
private String reporter_type;
private String reporter_name;
private String position;
private String details;
private String bike;
private String reporter_id;

public Observation(JSONObject obj) {
try {
id = obj.getString("id");
Expand All @@ -27,4 +32,82 @@ public Observation(JSONObject obj) {
}
}

public Observation (String bikeUUID, String reporter_type, String details, String reporter_id){
this.bike=bikeUUID;
this.reporter_type=reporter_type;
this.details=details;
this.reporter_id=reporter_id;
}

public String getId() {
return id;
}

public void setId(String id) {
this.id = id;
}

public String getObservedAt() {
return observedAt;
}

public void setObservedAt(String observedAt) {
this.observedAt = observedAt;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public String getReporter_type() {
return reporter_type;
}

public void setReporter_type(String reporter_type) {
this.reporter_type = reporter_type;
}

public String getReporter_name() {
return reporter_name;
}

public void setReporter_name(String reporter_name) {
this.reporter_name = reporter_name;
}

public String getPosition() {
return position;
}

public void setPosition(String position) {
this.position = position;
}

public String getDetails() {
return details;
}

public void setDetails(String details) {
this.details = details;
}

public String getBike() {
return bike;
}

public void setBike(String bike) {
this.bike = bike;
}

public String getReporter_id() {
return reporter_id;
}

public void setReporter_id(String reporter_id) {
this.reporter_id = reporter_id;
}
}
Loading

0 comments on commit 754edf7

Please sign in to comment.