Skip to content

Commit 91f9bb8

Browse files
committed
Initial commit
0 parents  commit 91f9bb8

21 files changed

+5944
-0
lines changed

.expo-shared/assets.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"f9155ac790fd02fadcdeca367b02581c04a353aa6d5aa84409a59f6804c87acd": true,
3+
"89ed26367cdb9b771858e026f2eb95bfdb90e5ae943e716575327ec325f39c44": true,
4+
"2a74234a88689f1b5e89be3bab52b8c895a195b49bf8a694f9729e0637eee599": true,
5+
"f765856d473f9ad66803df77ff7f7c7c1e78fa75f4b04428f7013d56fa5896be": true,
6+
"cab078b5104d3f5e24a10ed37037b7e6943271b93e0514110a181599931d6e7e": true,
7+
"442c347a87ad8048e3786f9dc8804380fb93e22357c51a9875b75991c20b1b1f": true,
8+
"4f4701853ff27341463ba57a0d614f237115bca2c69defa8efcc1abe3421f669": true
9+
}

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
node_modules/**/*
2+
.expo/*
3+
npm-debug.*
4+
*.jks
5+
*.p12
6+
*.key
7+
*.mobileprovision
8+
*.orig.*
9+
*.ai
10+
*.indd
11+
*.apk
12+
desktop.ini
13+
web-build/
14+
web-report/

.watchmanconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{}

App.js

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// Begin: spaghetti code
2+
import React, { Component } from 'react';
3+
import { StyleSheet, Text, View, Image, ImageBackground, Alert, TouchableOpacity } from 'react-native';
4+
import * as Location from 'expo-location';
5+
import * as Permissions from 'expo-permissions';
6+
7+
8+
export default class App extends Component {
9+
10+
// init states
11+
state = {
12+
locationLat: null,
13+
locationLon: null,
14+
errorMessage: null,
15+
flagImage: true,
16+
textColour: '#FA5695'
17+
};
18+
19+
20+
// location functions
21+
22+
_getLocationPerms = async () => {
23+
let { status } = await Permissions.askAsync(Permissions.LOCATION);
24+
if (status !== 'granted') {
25+
this.setState({
26+
errorMessage: 'Permissions to access location was denied',
27+
});
28+
}
29+
};
30+
31+
findCoordinates = async () => {
32+
navigator.geolocation.getCurrentPosition(
33+
position => {
34+
const locationLat = JSON.stringify(position.coords.latitude);
35+
const locationLon = JSON.stringify(position.coords.longitude);
36+
37+
this.setState({ locationLat });
38+
this.setState({ locationLon });
39+
},
40+
error => Alert.alert(error.message),
41+
{ enableHighAccuracy: false, maximumAge: 10 }
42+
);
43+
};
44+
45+
changeImage() {
46+
if (this.state.textColour === 'white') {
47+
var textColour = '#FA5695';
48+
} else {
49+
var textColour = 'white';
50+
}
51+
this.setState({
52+
flagImage:!this.state.flagImage,
53+
textColour: textColour
54+
});
55+
};
56+
57+
tekstiStyle = function(options) {
58+
return {
59+
fontFamily: 'sans-serif', // android default font
60+
fontSize: 30,
61+
textAlign: "center",
62+
margin: 10,
63+
color: this.state.textColour // muuhun #F80160
64+
}
65+
};
66+
67+
render() {
68+
69+
const haversine = require('haversine');
70+
71+
setTimeout(this._getLocationPerms, 1000); // 2s
72+
setTimeout(this.findCoordinates, 1000);
73+
74+
let toripolliisiLocation = {
75+
latitude: 65.0126795,
76+
longitude: 25.4649844
77+
};
78+
79+
let start = {
80+
latitude: this.state.locationLat,
81+
longitude: this.state.locationLon
82+
};
83+
84+
return (
85+
<ImageBackground source={ this.state.flagImage === true ?
86+
require('./assets/backgroundWhite.png') :
87+
require('./assets/backgroundPink.png')}
88+
style={{flex: 1, width: '100%', height: '100%'}}>
89+
<View style={styles.container}>
90+
91+
<TouchableOpacity onPress={ this.changeImage.bind(this) }>
92+
<Image source={ this.state.flagImage === true ?
93+
require('./assets/ToripolliisiPink.png') :
94+
require('./assets/ToripolliisiWhite.png')}
95+
style={{width: 400, height: 500, resizeMode: 'center'}} />
96+
</TouchableOpacity>
97+
98+
<Text style={this.tekstiStyle()}>
99+
{"\n"}Etäisyys Toripolliisiin on
100+
</Text>
101+
<Text style={styles.etaisyys}>
102+
{String(haversine(start, toripolliisiLocation)).substring(0,6)} km
103+
</Text>
104+
105+
</View>
106+
</ImageBackground>
107+
);
108+
}
109+
}
110+
111+
const styles = StyleSheet.create({
112+
container: {
113+
flex: 1,
114+
// backgroundColor: '#fff',
115+
alignItems: 'center',
116+
justifyContent: 'center',
117+
},
118+
119+
teksti: {
120+
fontFamily: 'sans-serif', // android default font
121+
fontSize: 30,
122+
textAlign: "center",
123+
margin: 10,
124+
color: '#FA5695' // muuhun #F80160
125+
},
126+
127+
etaisyys: {
128+
fontFamily: 'sans-serif-medium',
129+
fontSize: 42,
130+
textAlign: "center",
131+
fontWeight: 'bold',
132+
color: 'black'
133+
},
134+
});

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# ToripolliisiApp
2+
3+
Android app for showing the current distance to Toripolliisi in Oulu marketplace using React Native and GPS.
4+
5+
## Prerequisities
6+
* Android 6.0+
7+
* Location data
8+
9+
## Setup
10+
* Download and install the .apk
11+
12+
## Features to add
13+
* Better performance
14+
* About menu and settings
15+
16+
## Screenshots
17+
<img src="https://i.imgur.com/QvNfOTT.png" alt="White Toripolliisi" width="50%" height="50%"/><img src="https://i.imgur.com/lbMHYD9.png" alt="Pink Toripolliisi" width="50%" height="50%"/>
18+
19+
## Special thanks
20+
* Aalto University Guild of Physics (especially their coffee machine)

app.json

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"expo": {
3+
"name": "Etäisyyspolliisi",
4+
"slug": "toripolliisiApp",
5+
"privacy": "public",
6+
"sdkVersion": "33.0.0",
7+
"platforms": [
8+
"ios",
9+
"android",
10+
"web"
11+
],
12+
"android": {
13+
"package": "com.nikodg.toripolliisiapp"
14+
},
15+
"version": "4.2.0",
16+
"orientation": "portrait",
17+
"icon": "./assets/icon2.png",
18+
"splash": {
19+
"image": "./assets/splash2.png",
20+
"resizeMode": "contain",
21+
"backgroundColor": "#F80160"
22+
},
23+
"updates": {
24+
"fallbackToCacheTimeout": 0
25+
},
26+
"assetBundlePatterns": [
27+
"**/*"
28+
],
29+
"ios": {
30+
"supportsTablet": true
31+
}
32+
}
33+
}

assets/ToripolliisiCropped.png

153 KB
Loading

assets/ToripolliisiPink.png

26.1 KB
Loading

assets/ToripolliisiWhite.png

25 KB
Loading

assets/background.png

8.62 KB
Loading

0 commit comments

Comments
 (0)