Skip to content

Commit ecaa227

Browse files
authored
Merge pull request #21 from scottlandis/master
Heatmap and beginning of OGC SOS
2 parents ffcffec + b92431b commit ecaa227

51 files changed

Lines changed: 1717 additions & 49 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

sample/TORGIListener/.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/libraries
5+
/.idea/modules.xml
6+
/.idea/workspace.xml
7+
.DS_Store
8+
/build
9+
/captures
10+
.externalNativeBuild
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 28
5+
defaultConfig {
6+
applicationId "tech.plugs.torgilistener"
7+
minSdkVersion 21
8+
targetSdkVersion 28
9+
versionCode 1
10+
versionName "1.0"
11+
}
12+
buildTypes {
13+
release {
14+
minifyEnabled false
15+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
16+
}
17+
}
18+
19+
compileOptions {
20+
targetCompatibility 1.8
21+
sourceCompatibility 1.8
22+
}
23+
}
24+
25+
dependencies {
26+
implementation fileTree(dir: 'libs', include: ['*.jar'])
27+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"app-release.apk","fullName":"release","baseName":"release"},"path":"app-release.apk","properties":{}}]
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="tech.plugs.torgilistener">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".MainActivity">
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
package tech.plugs.torgilistener;
2+
3+
import android.content.BroadcastReceiver;
4+
import android.content.Context;
5+
import android.content.Intent;
6+
import android.util.Log;
7+
8+
import java.io.StringWriter;
9+
import java.text.ParseException;
10+
import java.text.SimpleDateFormat;
11+
import java.util.Date;
12+
13+
/**
14+
* Implements the OGC Sensor Observation Service and provides a means for other processes
15+
* to communicate with the service. To use, extend this class then add:
16+
*
17+
* <receiver android:name=".YourBroadcastTransceiver">
18+
* <intent-filter>
19+
* <action android:name="org.sofwerx.torgi.ogc.ACTION_SOS"/>
20+
* </intent-filter>
21+
* </receiver>
22+
*
23+
* to <application> in your manifest. You can send requests to the SOS by using the
24+
* broadcast message and you will receive responses back through the onMessageReceived method.
25+
* See the TorgiSOSBroadcastTransceiver for an example of how to use this
26+
*
27+
*/
28+
public abstract class AbstractSOSBroadcastTransceiver extends BroadcastReceiver {
29+
private final static SimpleDateFormat dateFormatISO8601 = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSXXX");
30+
protected final static String TAG = "OGC.SOS";
31+
public static final String ACTION_SOS = "org.sofwerx.torgi.ogc.ACTION_SOS";
32+
private static final String EXTRA_PAYLOAD = "SOS";
33+
private static final String EXTRA_ORIGIN = "src";
34+
35+
@Override
36+
public void onReceive(Context context, Intent intent) {
37+
if ((context != null) && (intent != null)) {
38+
if (ACTION_SOS.equals(intent.getAction()))
39+
onMessageReceived(context,intent.getStringExtra(EXTRA_ORIGIN),intent.getStringExtra(EXTRA_PAYLOAD));
40+
else
41+
Log.e(TAG, "Unexpected action message received: " + intent.getAction());
42+
}
43+
}
44+
45+
/**
46+
* Broadcast an SOS Operation
47+
* @param context
48+
* @param sosOperation
49+
*/
50+
public static void broadcast(Context context, String sosOperation) {
51+
if (context == null) {
52+
Log.d(TAG,"Context needed to broadcast an SOS Operation");
53+
return;
54+
}
55+
if (sosOperation == null) {
56+
Log.e(TAG, "Cannot broadcast an empty SOS Operation");
57+
return;
58+
}
59+
Intent intent = new Intent(ACTION_SOS);
60+
intent.putExtra(EXTRA_ORIGIN, BuildConfig.APPLICATION_ID);
61+
intent.putExtra(EXTRA_PAYLOAD,sosOperation);
62+
63+
context.sendBroadcast(intent);
64+
Log.d(TAG,"Broadcast: "+sosOperation);
65+
}
66+
67+
/**
68+
* Handles the message received from the SOS Broadcast; extend this method to handle the input
69+
* @param source the application that sent the request; mostly to prevent circular reporting
70+
* @param input the SOS operation received
71+
*/
72+
public void onMessageReceived(Context context,String source,String input) {
73+
if (source == null) {
74+
Log.e(TAG,"SOS broadcasts from anonymous senders is not supported");
75+
return;
76+
}
77+
}
78+
79+
public final static String getOperationDescribeSensor() {
80+
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><DescribeSensor version=\"1.0.0\" service=\"SOS\" mobileEnabled=\"true\" xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0 http://schemas.opengis.net/sos/1.0.0/sosDescribeSensor.xsd\" outputFormat=\"text/xml;subtype=&quot;sensorML/1.0.1&quot;\"><procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure></DescribeSensor>";
81+
}
82+
83+
public final static String getOperationGetCapabilities() {
84+
return "<?xml version=\"1.0\" encoding=\"UTF-8\"?><GetCapabilities xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0http://schemas.opengis.net/sos/1.0.0/sosGetCapabilities.xsd\" service=\"SOS\" updateSequence=\"\"><ows:AcceptVersions><ows:Version>1.0.0</ows:Version></ows:AcceptVersions><ows:Sections><ows:Section>OperationsMetadata</ows:Section><ows:Section>ServiceIdentification</ows:Section><ows:Section>Filter_Capabilities</ows:Section><ows:Section>Contents</ows:Section></ows:Sections></GetCapabilities>";
85+
}
86+
87+
public static long parseTime(String time) {
88+
if (time != null) {
89+
try {
90+
Date date = dateFormatISO8601.parse(time);
91+
return date.getTime();
92+
} catch (ParseException e) {
93+
e.printStackTrace();
94+
}
95+
}
96+
return Long.MIN_VALUE;
97+
}
98+
99+
public static String formatTime(long time) {
100+
return dateFormatISO8601.format(time);
101+
}
102+
103+
/**
104+
* Gets the recent observations
105+
* @return
106+
*/
107+
public static String getOperationGetObservations() {
108+
return getOperationGetObservations(Long.MIN_VALUE, Long.MIN_VALUE);
109+
}
110+
111+
/**
112+
* Gets a range of observations
113+
* @param start start time
114+
* @param end end time
115+
* @return
116+
*/
117+
public static String getOperationGetObservations(long start, long end) {
118+
StringWriter writer = new StringWriter();
119+
writer.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
120+
"<GetObservation xmlns=\"http://www.opengis.net/sos/1.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:om=\"http://www.opengis.net/om/1.0\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.opengis.net/sos/1.0\n" +
121+
"http://schemas.opengis.net/sos/1.0.0/sosGetObservation.xsd\" service=\"SOS\" version=\"1.0.0\" srsName=\"urn:ogc:def:crs:EPSG:4326\">\n" +
122+
" <offering>TORGI</offering>\n"); //TODO change this type of offering
123+
if (end > Long.MIN_VALUE) {
124+
writer.append(" <eventTime>\n" +
125+
" <ogc:TM_During>\n" +
126+
" <ogc:PropertyName>urn:ogc:data:time:iso8601</ogc:PropertyName>\n" +
127+
" <gml:TimePeriod>\n" +
128+
" <gml:beginPosition>");
129+
writer.append(formatTime(start));
130+
writer.append("</gml:beginPosition>\n" +
131+
" <gml:endPosition>");
132+
writer.append(formatTime(end));
133+
writer.append("</gml:endPosition>\n" +
134+
" </gml:TimePeriod>\n" +
135+
" </ogc:TM_During>\n" +
136+
" </eventTime>\n");
137+
}
138+
//TODO need to implement " <procedure>urn:ogc:object:feature:Sensor:IFGI:ifgi-sensor-1</procedure>\n" +
139+
//TODO need to implement " <observedProperty>urn:ogc:def:phenomenon:OGC:1.0.30:waterlevel</observedProperty>\n" +
140+
writer.append(" <responseFormat>text/xml;subtype=&quot;om/1.0.0&quot;</responseFormat>\n" +
141+
"</GetObservation>");
142+
143+
return writer.toString();
144+
}
145+
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package tech.plugs.torgilistener;
2+
3+
import android.app.Activity;
4+
import android.content.ClipData;
5+
import android.content.ClipboardManager;
6+
import android.content.IntentFilter;
7+
import android.os.Bundle;
8+
import android.view.View;
9+
import android.widget.Button;
10+
import android.widget.TextView;
11+
import android.widget.Toast;
12+
13+
public class MainActivity extends Activity implements SampleTransceiver.MessageReceiveListener {
14+
private SampleTransceiver transceiver = null;
15+
private TextView response;
16+
private Button bDescribeSensor, bGetCapabilities, bGetObservations;
17+
18+
@Override
19+
protected void onCreate(Bundle savedInstanceState) {
20+
super.onCreate(savedInstanceState);
21+
setContentView(R.layout.activity_main);
22+
response = findViewById(R.id.messgage);
23+
response.setOnClickListener(view -> {
24+
ClipboardManager clipboard = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
25+
ClipData clip = ClipData.newPlainText("SOS", response.getText().toString());
26+
clipboard.setPrimaryClip(clip);
27+
Toast.makeText(MainActivity.this,"Response copied to clipboard",Toast.LENGTH_SHORT).show();
28+
});
29+
bDescribeSensor = findViewById(R.id.sendDescribeSensor);
30+
bGetCapabilities = findViewById(R.id.sendGetCapabilities);
31+
bGetObservations = findViewById(R.id.sendGetObservations);
32+
bDescribeSensor.setOnClickListener(view -> AbstractSOSBroadcastTransceiver.broadcast(MainActivity.this,AbstractSOSBroadcastTransceiver.getOperationDescribeSensor()));
33+
bGetCapabilities.setOnClickListener(view -> AbstractSOSBroadcastTransceiver.broadcast(MainActivity.this,AbstractSOSBroadcastTransceiver.getOperationGetCapabilities()));
34+
bGetObservations.setOnClickListener(view -> AbstractSOSBroadcastTransceiver.broadcast(MainActivity.this,AbstractSOSBroadcastTransceiver.getOperationGetObservations()));
35+
transceiver = new SampleTransceiver();
36+
IntentFilter intentFilter = new IntentFilter(AbstractSOSBroadcastTransceiver.ACTION_SOS);
37+
registerReceiver(transceiver, intentFilter);
38+
39+
}
40+
41+
@Override
42+
public void onResume() {
43+
super.onResume();
44+
transceiver.setListener(this);
45+
}
46+
47+
@Override
48+
public void onPause() {
49+
transceiver.setListener(null);
50+
super.onPause();
51+
}
52+
53+
@Override
54+
public void onDestroy() {
55+
if (transceiver != null) {
56+
try {
57+
unregisterReceiver(transceiver);
58+
} catch (Exception e) {
59+
e.printStackTrace();
60+
}
61+
transceiver = null;
62+
}
63+
super.onDestroy();
64+
}
65+
66+
@Override
67+
public void onMessageReceived(String input) {
68+
response.setText(input);
69+
}
70+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package tech.plugs.torgilistener;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
6+
public class SampleTransceiver extends AbstractSOSBroadcastTransceiver {
7+
private MessageReceiveListener listener = null;
8+
9+
public void setListener(MessageReceiveListener listener) {
10+
this.listener = listener;
11+
}
12+
13+
@Override
14+
public void onMessageReceived(Context context, String source, String input) {
15+
super.onMessageReceived(context,source,input);
16+
if (BuildConfig.APPLICATION_ID.equalsIgnoreCase(source))
17+
return; //messages are ignored by their sender
18+
if (input == null)
19+
Log.e(TAG,"Emtpy SOS message received");
20+
else {
21+
if (listener != null)
22+
listener.onMessageReceived(input);
23+
}
24+
}
25+
26+
public interface MessageReceiveListener {
27+
void onMessageReceived(String input);
28+
}
29+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportHeight="108"
6+
android:viewportWidth="108">
7+
<path
8+
android:fillType="evenOdd"
9+
android:pathData="M32,64C32,64 38.39,52.99 44.13,50.95C51.37,48.37 70.14,49.57 70.14,49.57L108.26,87.69L108,109.01L75.97,107.97L32,64Z"
10+
android:strokeColor="#00000000"
11+
android:strokeWidth="1">
12+
<aapt:attr name="android:fillColor">
13+
<gradient
14+
android:endX="78.5885"
15+
android:endY="90.9159"
16+
android:startX="48.7653"
17+
android:startY="61.0927"
18+
android:type="linear">
19+
<item
20+
android:color="#44000000"
21+
android:offset="0.0" />
22+
<item
23+
android:color="#00000000"
24+
android:offset="1.0" />
25+
</gradient>
26+
</aapt:attr>
27+
</path>
28+
<path
29+
android:fillColor="#FFFFFF"
30+
android:fillType="nonZero"
31+
android:pathData="M66.94,46.02L66.94,46.02C72.44,50.07 76,56.61 76,64L32,64C32,56.61 35.56,50.11 40.98,46.06L36.18,41.19C35.45,40.45 35.45,39.3 36.18,38.56C36.91,37.81 38.05,37.81 38.78,38.56L44.25,44.05C47.18,42.57 50.48,41.71 54,41.71C57.48,41.71 60.78,42.57 63.68,44.05L69.11,38.56C69.84,37.81 70.98,37.81 71.71,38.56C72.44,39.3 72.44,40.45 71.71,41.19L66.94,46.02ZM62.94,56.92C64.08,56.92 65,56.01 65,54.88C65,53.76 64.08,52.85 62.94,52.85C61.8,52.85 60.88,53.76 60.88,54.88C60.88,56.01 61.8,56.92 62.94,56.92ZM45.06,56.92C46.2,56.92 47.13,56.01 47.13,54.88C47.13,53.76 46.2,52.85 45.06,52.85C43.92,52.85 43,53.76 43,54.88C43,56.01 43.92,56.92 45.06,56.92Z"
32+
android:strokeColor="#00000000"
33+
android:strokeWidth="1" />
34+
</vector>

0 commit comments

Comments
 (0)