Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
nikosavola committed Jul 14, 2019
0 parents commit 91f9bb8
Show file tree
Hide file tree
Showing 21 changed files with 5,944 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .expo-shared/assets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"f9155ac790fd02fadcdeca367b02581c04a353aa6d5aa84409a59f6804c87acd": true,
"89ed26367cdb9b771858e026f2eb95bfdb90e5ae943e716575327ec325f39c44": true,
"2a74234a88689f1b5e89be3bab52b8c895a195b49bf8a694f9729e0637eee599": true,
"f765856d473f9ad66803df77ff7f7c7c1e78fa75f4b04428f7013d56fa5896be": true,
"cab078b5104d3f5e24a10ed37037b7e6943271b93e0514110a181599931d6e7e": true,
"442c347a87ad8048e3786f9dc8804380fb93e22357c51a9875b75991c20b1b1f": true,
"4f4701853ff27341463ba57a0d614f237115bca2c69defa8efcc1abe3421f669": true
}
14 changes: 14 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
node_modules/**/*
.expo/*
npm-debug.*
*.jks
*.p12
*.key
*.mobileprovision
*.orig.*
*.ai
*.indd
*.apk
desktop.ini
web-build/
web-report/
1 change: 1 addition & 0 deletions .watchmanconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
134 changes: 134 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
// Begin: spaghetti code
import React, { Component } from 'react';
import { StyleSheet, Text, View, Image, ImageBackground, Alert, TouchableOpacity } from 'react-native';
import * as Location from 'expo-location';
import * as Permissions from 'expo-permissions';


export default class App extends Component {

// init states
state = {
locationLat: null,
locationLon: null,
errorMessage: null,
flagImage: true,
textColour: '#FA5695'
};


// location functions

_getLocationPerms = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
this.setState({
errorMessage: 'Permissions to access location was denied',
});
}
};

findCoordinates = async () => {
navigator.geolocation.getCurrentPosition(
position => {
const locationLat = JSON.stringify(position.coords.latitude);
const locationLon = JSON.stringify(position.coords.longitude);

this.setState({ locationLat });
this.setState({ locationLon });
},
error => Alert.alert(error.message),
{ enableHighAccuracy: false, maximumAge: 10 }
);
};

changeImage() {
if (this.state.textColour === 'white') {
var textColour = '#FA5695';
} else {
var textColour = 'white';
}
this.setState({
flagImage:!this.state.flagImage,
textColour: textColour
});
};

tekstiStyle = function(options) {
return {
fontFamily: 'sans-serif', // android default font
fontSize: 30,
textAlign: "center",
margin: 10,
color: this.state.textColour // muuhun #F80160
}
};

render() {

const haversine = require('haversine');

setTimeout(this._getLocationPerms, 1000); // 2s
setTimeout(this.findCoordinates, 1000);

let toripolliisiLocation = {
latitude: 65.0126795,
longitude: 25.4649844
};

let start = {
latitude: this.state.locationLat,
longitude: this.state.locationLon
};

return (
<ImageBackground source={ this.state.flagImage === true ?
require('./assets/backgroundWhite.png') :
require('./assets/backgroundPink.png')}
style={{flex: 1, width: '100%', height: '100%'}}>
<View style={styles.container}>

<TouchableOpacity onPress={ this.changeImage.bind(this) }>
<Image source={ this.state.flagImage === true ?
require('./assets/ToripolliisiPink.png') :
require('./assets/ToripolliisiWhite.png')}
style={{width: 400, height: 500, resizeMode: 'center'}} />
</TouchableOpacity>

<Text style={this.tekstiStyle()}>
{"\n"}Etäisyys Toripolliisiin on
</Text>
<Text style={styles.etaisyys}>
{String(haversine(start, toripolliisiLocation)).substring(0,6)} km
</Text>

</View>
</ImageBackground>
);
}
}

const styles = StyleSheet.create({
container: {
flex: 1,
// backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},

teksti: {
fontFamily: 'sans-serif', // android default font
fontSize: 30,
textAlign: "center",
margin: 10,
color: '#FA5695' // muuhun #F80160
},

etaisyys: {
fontFamily: 'sans-serif-medium',
fontSize: 42,
textAlign: "center",
fontWeight: 'bold',
color: 'black'
},
});
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# ToripolliisiApp

Android app for showing the current distance to Toripolliisi in Oulu marketplace using React Native and GPS.

## Prerequisities
* Android 6.0+
* Location data

## Setup
* Download and install the .apk

## Features to add
* Better performance
* About menu and settings

## Screenshots
<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%"/>

## Special thanks
* Aalto University Guild of Physics (especially their coffee machine)
33 changes: 33 additions & 0 deletions app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"expo": {
"name": "Etäisyyspolliisi",
"slug": "toripolliisiApp",
"privacy": "public",
"sdkVersion": "33.0.0",
"platforms": [
"ios",
"android",
"web"
],
"android": {
"package": "com.nikodg.toripolliisiapp"
},
"version": "4.2.0",
"orientation": "portrait",
"icon": "./assets/icon2.png",
"splash": {
"image": "./assets/splash2.png",
"resizeMode": "contain",
"backgroundColor": "#F80160"
},
"updates": {
"fallbackToCacheTimeout": 0
},
"assetBundlePatterns": [
"**/*"
],
"ios": {
"supportsTablet": true
}
}
}
Binary file added assets/ToripolliisiCropped.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ToripolliisiPink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/ToripolliisiWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/backgroundPink.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/backgroundWhite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/fonts/Lato-Bold.ttf
Binary file not shown.
Binary file added assets/fonts/Lato-Regular.ttf
Binary file not shown.
Binary file added assets/icon1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/splash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/splash2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/väripaletti.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = function(api) {
api.cache(true);
return {
presets: ['babel-preset-expo'],
};
};
23 changes: 23 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web",
"eject": "expo eject"
},
"dependencies": {
"expo": "^33.0.0",
"haversine": "^1.1.1",
"react": "16.8.3",
"react-dom": "^16.8.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
"react-native-material-menu": "^0.6.3",
"react-native-web": "^0.11.4"
},
"devDependencies": {
"babel-preset-expo": "^5.1.1"
},
"private": true
}
Loading

0 comments on commit 91f9bb8

Please sign in to comment.