Skip to content

Commit edd6665

Browse files
update docs
1 parent 6e81d9d commit edd6665

File tree

4 files changed

+442
-195
lines changed

4 files changed

+442
-195
lines changed

README.md

Lines changed: 7 additions & 195 deletions
Original file line numberDiff line numberDiff line change
@@ -21,203 +21,15 @@ dependencies {
2121

2222

2323
## Setting Up in Kotlin
24-
```kotlin
25-
/** ## First you will need to create service interactor object,
26-
* as a proxy for Live Location services **/
27-
private val liveLocationServiceInteractor =
28-
object : LiveLocationServiceInteractorAbs() {
29-
30-
/** Define Your Context **/
31-
override val context: Context = this@MainActivity
32-
33-
/** GPS Configuration Block **/
34-
override val gpsConfig: GPSConfig =
35-
object : GPSConfig {
36-
override val samplingRate: Long = 10000
37-
}
38-
39-
/** Notification Configuration Block **/
40-
override val notificationConfig: NotificationConfig =
41-
object : NotificationConfig {
42-
override val foregroundServiceID: Int = 1003
43-
override val notificationChannelID: String = CHANNEL_ID
44-
override val notificationChannelName: String = CHANNEL_NAME
45-
override val notificationChannelDescription: String = CHANNEL_DESCRIPTION
46-
override val notificationPriority: Int = NotificationCompat.PRIORITY_DEFAULT
47-
override val iconRes: Int? = null
48-
}
49-
50-
/** Network Configuration Block **/
51-
override val networkConfiguration: LiveLocationNetworkConfiguration =
52-
object : LiveLocationNetworkConfiguration {
53-
override val url: String = "http://websocket.company.com"
54-
/** You can define whether using Socket Communication or RESTFUL Api **/
55-
override val networkMethod: NetworkMethod = NetworkMethod.RESTFULL
56-
/** You can put static payload such athorizations and other header what ever you needed **/
57-
override val headers: HashMap<String, String> = hashMapOf(
58-
"Header1" to "Bearer aasdasdadadadaa",
59-
"Header2" to "Bearer 23423094029u40932"
60-
)
61-
/** Add descriptor to your message **/
62-
override val messageDescriptor: String by lazy {
63-
val desc = hashMapOf<String, String>(
64-
"userID" to userID.toString(),
65-
"messagingToken" to messagingToken
66-
)
67-
68-
Gson().toJson(desc)
69-
}
70-
}
71-
72-
/** Bellows are the interfaces you can use to get respond in realtime to your application **/
73-
override fun onServiceStatusChanged(
74-
serviceStatus: LiveLocationServiceInteractor.ServiceStatus
75-
) {
76-
lifecycleScope.launch {
77-
liveLocationRunning.emit(
78-
when (serviceStatus) {
79-
LiveLocationServiceInteractor.ServiceStatus.RUNNING ->
80-
true
81-
82-
LiveLocationServiceInteractor.ServiceStatus.DEAD ->
83-
false
84-
}
85-
)
86-
}
87-
}
88-
89-
override fun onError(
90-
message: String?
91-
) {
92-
lifecycleScope.launch {
93-
liveLocationError.emit(
94-
message
95-
)
96-
}
97-
}
98-
99-
override fun onReceiveUpdate(
100-
latitude: Double,
101-
longitude: Double,
102-
accuracy: Float,
103-
updateTime: Long
104-
) {
105-
lifecycleScope.launch {
106-
location.emit(
107-
LatLng(
108-
latitude,
109-
longitude
110-
)
111-
)
112-
}
113-
}
114-
115-
}
116-
```
24+
See [SetupKotlin.md](docs%2FSetupKotlin.md).
11725

11826
## Setting Up in Java
119-
```java
120-
private String userID = "USER ID";
121-
private String messagingToken = "Dummy Messaging Token";
122-
123-
private LiveLocationServiceInteractor liveLocationServiceInteractor = new LiveLocationServiceInteractorAbs() {
124-
@Override
125-
public Context getContext() {
126-
return Main2Activity.this;
127-
}
128-
129-
@Override
130-
public GPSConfig getGpsConfig() {
131-
return new GPSConfig() {
132-
@Override
133-
public long getSamplingRate() {
134-
return 10000;
135-
}
136-
};
137-
}
27+
See [SetupJava.md](docs%2FSetupJava.md).
13828

139-
@Override
140-
public NotificationConfig getNotificationConfig() {
141-
return new NotificationConfig() {
142-
@Override
143-
public int getForegroundServiceID() {
144-
return 1003;
145-
}
146-
147-
@Override
148-
public String getNotificationChannelID() {
149-
return CHANNEL_ID;
150-
}
151-
152-
@Override
153-
public String getNotificationChannelName() {
154-
return CHANNEL_NAME;
155-
}
156-
157-
@Override
158-
public String getNotificationChannelDescription() {
159-
return CHANNEL_DESCRIPTION;
160-
}
161-
162-
@Override
163-
public int getNotificationPriority() {
164-
return NotificationCompat.PRIORITY_DEFAULT;
165-
}
166-
167-
@Override
168-
public Integer getIconRes() {
169-
return null;
170-
}
171-
};
172-
}
173-
174-
@Override
175-
public LiveLocationNetworkConfiguration getNetworkConfiguration() {
176-
return new LiveLocationNetworkConfiguration() {
177-
@Override
178-
public String getUrl() {
179-
return "http://websocket.company.com;
180-
}
181-
182-
@Override
183-
public NetworkMethod getNetworkMethod() {
184-
return NetworkMethod.WEBSOCKET;
185-
}
186-
187-
@Override
188-
public HashMap<String, String> getHeaders() {
189-
HashMap<String, String> headers = new HashMap<>();
190-
headers.put("Header1", "Bearer aasdasdadadadaa");
191-
headers.put("Header2", "Bearer 23423094029u40932");
192-
return headers;
193-
}
194-
195-
@Override
196-
public String getMessageDescriptor() {
197-
HashMap<String, String> desc = new HashMap<>();
198-
desc.put("userID", String.valueOf(userID));
199-
desc.put("messagingToken", messagingToken);
200-
return new Gson().toJson(desc);
201-
}
202-
};
203-
}
204-
205-
@Override
206-
public void onServiceStatusChanged(LiveLocationServiceInteractor.ServiceStatus serviceStatus) {
207-
// TODO : Do what you need
208-
}
209-
210-
@Override
211-
public void onError(String message) {
212-
// TODO : Do what you need
213-
}
214-
215-
@Override
216-
public void onReceiveUpdate(double latitude, double longitude, float accuracy, long updateTime) {
217-
// TODO : Do what you need
218-
}
219-
};
220-
```
29+
## Setup Alien
30+
If you are using alien technology such Xamarin/Unity, C++ and other non java platform,
31+
you can create a portal interaction using AlienPortal object.
32+
See [SetupAlien.md](docs%2FSetupAlien.md).
22133

22234
## Networking
22335
This library will automatically sync your data to network, the body request will be
@@ -249,7 +61,7 @@ So the permission request should be done in 2 steps:
24961
- You can use java or kotlin, the syntax won't have a lot different, you can contact me for more help.
25062

25163
## Build AAR Libray
252-
To build the library just run the `build-library.sh` in the project root directory.
64+
If you need the aar file, to build the library just run the `build-library.sh` in the project root directory.
25365

25466
## Design and Developed by :
25567
- [Stefanus Ayudha](https://github.com/stefanusayudha)

docs/SetupAlien.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Setup for Alien
2+
If you are using alien technology such Xamarin/Unity, C++ and other non java platform,
3+
you can use AlienPortal object to interact with the service.
4+
5+
You can see the example here [JavaAlienActivity](..%2Fapp%2Fsrc%2Fmain%2Fjava%2Fcom%2Fsingularity_code%2Fgpstracker%2Factivity%2FJavaAlienActivity.java).
6+
7+
# 1. Get Instance
8+
You can get the instance this way:
9+
```java
10+
private final AlienPortal alienPortal = AlienPortal.INSTANCE;
11+
```
12+
13+
# 2. Setup
14+
```java
15+
private void startLiveLocationService() {
16+
17+
alienPortal.setGPSSamplingRate(1000L);
18+
19+
alienPortal.setContext(this);
20+
21+
alienPortal.setChannelId("Alien Notification");
22+
23+
alienPortal.setChannelName("Alien Notification");
24+
25+
alienPortal.setChannelDescription("Notification from alien app");
26+
27+
alienPortal.setupAPIorSocketURL("http://websocket.company.com?id=" + "userID-" + (Math.random() * 100));
28+
29+
alienPortal.setNotificationTitle("Live Location");
30+
31+
alienPortal.setNotificationMessage("Live Location is Running");
32+
33+
// 0 -> RESTFUL
34+
// 1 -> Web Socket
35+
alienPortal.setupNetworkMethod(1);
36+
37+
// clear previous headers
38+
alienPortal.clearHeader();
39+
alienPortal.addHeader("Authentication", "Bearer alsdkmlam");
40+
41+
alienPortal.setMessageDescriptor(
42+
"You can parse anything here to describe your message. " +
43+
"For example sender user id, and user name, and anything, " +
44+
"in formats that you can decode."
45+
);
46+
}
47+
```
48+
49+
# 3. Start and Stop
50+
```java
51+
alienPortal.start();
52+
alienPortal.stop();
53+
```
54+
55+
# 4. Observing
56+
You will need to update the data manually using thread or something else like thread.
57+
```java
58+
/** # Observer **/
59+
private Thread observerThread;
60+
61+
private boolean stopDebug = false;
62+
63+
private void observeUpdate() {
64+
observerThread = new Thread() {
65+
66+
@Override
67+
public void run() {
68+
69+
StringBuilder sb;
70+
71+
while (!stopDebug) {
72+
73+
String status = alienPortal.getStatus();
74+
String latitude = alienPortal.getLatitude();
75+
String longitude = alienPortal.getLongitude();
76+
String accuracy = alienPortal.getAccuracy();
77+
String updatedTime = alienPortal.getUpdatedTime();
78+
79+
sb = new StringBuilder();
80+
sb.append("status : ").append(status).append("\n");
81+
sb.append("latitude : ").append(latitude).append("\n");
82+
sb.append("longitude : ").append(longitude).append("\n");
83+
sb.append("accuracy : ").append(accuracy).append("\n");
84+
sb.append("updatedTime : ").append(updatedTime).append("\n");
85+
86+
Log.d("LiveLocation", "Current: " + sb);
87+
88+
try {
89+
Thread.sleep(1000L);
90+
} catch (InterruptedException e) {
91+
throw new RuntimeException(e);
92+
}
93+
}
94+
}
95+
};
96+
97+
stopDebug = false;
98+
observerThread.start();
99+
}
100+
101+
private void stopObservingUpdate() {
102+
stopDebug = true;
103+
104+
try {
105+
observerThread.stop();
106+
observerThread.destroy();
107+
}catch (Throwable e) {
108+
// nothing to do
109+
}
110+
}
111+
```

0 commit comments

Comments
 (0)