From 16b5d0d30dd24c44473bd7e42ad882108aa8f058 Mon Sep 17 00:00:00 2001 From: Ren Juan Date: Fri, 20 Aug 2021 08:41:16 +0000 Subject: [PATCH] * --- Ejectable/App.tsx | 9 +- Ejectable/{Coordinate.ts => Coordinate.tsx} | 104 +++++-------------- Ejectable/app.json | 4 +- Ejectable/navigation/BottomTabNavigator.tsx | 2 +- Ejectable/navigation/LinkingConfiguration.ts | 6 +- Ejectable/package-lock.json | 6 +- Ejectable/screens/TripScreen.tsx | 30 ++---- Ejectable/tsconfig.json | 2 +- 8 files changed, 46 insertions(+), 117 deletions(-) rename Ejectable/{Coordinate.ts => Coordinate.tsx} (58%) diff --git a/Ejectable/App.tsx b/Ejectable/App.tsx index 8b17bbfa..416a11de 100644 --- a/Ejectable/App.tsx +++ b/Ejectable/App.tsx @@ -1,16 +1,15 @@ import 'react-native-gesture-handler'; import { StatusBar } from 'expo-status-bar'; import React, { useState, useEffect } from 'react'; -import { Platform, Text, View, Switch, StyleSheet } from 'react-native'; +import { Text } from 'react-native'; import * as Location from 'expo-location'; import { SafeAreaProvider } from 'react-native-safe-area-context'; import useCachedResources from './hooks/useCachedResources'; import useColorScheme from './hooks/useColorScheme'; import Navigation from './navigation'; - -export var debug:boolean = false; +import { GT2 } from './GT2'; +export var debug:boolean = true; export var expoGeoState:any; -export var tripInProgress:boolean = true; export default function App() { const isLoadingComplete = useCachedResources(); @@ -60,5 +59,3 @@ export default function App() { ); } } - -export function toggleTripInProgress() {tripInProgress = !tripInProgress;} \ No newline at end of file diff --git a/Ejectable/Coordinate.ts b/Ejectable/Coordinate.tsx similarity index 58% rename from Ejectable/Coordinate.ts rename to Ejectable/Coordinate.tsx index 41c14c6b..2d3d3530 100644 --- a/Ejectable/Coordinate.ts +++ b/Ejectable/Coordinate.tsx @@ -1,77 +1,27 @@ +/** Class for handling coordinates original by Linus Helgesson */ + export class Coordinate { + mLatitude:number = 0.0; + mLongitude:number = 0.0; + mResults:any = [0, 0]; + PI_OVER_180:number = 0.017453292519943295769236907684886; + EARTH_RADIUS:number = 6371009; -/* Generated from Java with JSweet 3.0.0 - http://www.jsweet.org */ -/** - * Constructor taking a longitude and a latitude - * - * @param {number} longitude - * @param {number} latitude - * @class - * @author Linus Helgesson - */ - var Coordinate = /** @class */ (function () { - function Coordinate(longitude, latitude) { - if (((typeof longitude === 'number') || longitude === null) && ((typeof latitude === 'number') || latitude === null)) { - var __args = arguments; - this.mLongitude = 0; - this.mLatitude = 0; - this.mResults = [0, 0]; + constructor (longitude:number, latitude:number) { this.mLongitude = longitude; this.mLatitude = latitude; - } - else if (longitude === undefined && latitude === undefined) { - var __args = arguments; - this.mLongitude = 0; - this.mLatitude = 0; - this.mResults = [0, 0]; - } - else - throw new Error('invalid overload'); } + getLongitude() { return this.mLongitude; } + setLongitude(longitude:number) { this.mLongitude = longitude; } + getLatitude() { return this.mLatitude; } + setLatitude(latitude:number) { this.mLatitude = latitude; } /** - * Get the longitude part of this coordinate - * - * @return {number} The longitude part of this coordinate - */ - Coordinate.prototype.getLongitude = function () { - return this.mLongitude; - }; - /** - * Set the longitude part of this coordinate - * - * @param {number} longitude The longitude part of this coordinate - */ - Coordinate.prototype.setLongitude = function (longitude) { - this.mLongitude = longitude; - }; - /** - * Get the latitude part of this coordinate - * - * @return {number} The latitude part of this coordinate - */ - Coordinate.prototype.getLatitude = function () { - return this.mLatitude; - }; - /** - * Set the latitude part of this coordinate - * - * @param {number} latitude The latitude part of this coordinate - */ - Coordinate.prototype.setLatitude = function (latitude) { - this.mLatitude = latitude; - }; - /** - * Calculates a bounding box of a certain size arund a coordinate. This is mainly used for a quick check - * in the database for cameras that are close to a coordinate. This function takes a size ion meters as + * Calculates a bounding box of a certain size arund a coordinate.This function takes a size in meters as * a parameter and returns an array of two Coordinate objects. The first Coordinate is the upper left corner - * while the last coordinate is the bottom right corner. - * - * @param {number} side The length of the square side in meters - * - * @return {Coordinate[]} Two cordinates where the first is smaller than the second. + * while the last coordinate is the bottom right corner.er than the second. */ - Coordinate.prototype.getBoundingBox = function (side: number) { - var ret = [null, null]; + getBoundingBox(side: number) { + var ret:any = [Coordinate, Coordinate]; var degLatM:number , degLatM:number, degLongM:number, deltaLat:number, deltaLong:number; @@ -87,18 +37,12 @@ }; /** * Calculates the distance between two Coordinate objects using the Spherical law of cosines found at: - * - * http://www.movable-type.co.uk/scripts/latlong.html - * - * @param coordinate The coordinate to measure the distance to. - * @return {number} the distance in meters - * @param {Coordinate} dest */ - Coordinate.prototype.distanceTo = function (dest) { - Coordinate.computeDistanceAndBearing(this.mLatitude, this.mLongitude, dest.getLatitude(), dest.getLongitude(), this.mResults); + distanceTo(dest:Coordinate) { + this.computeDistanceAndBearing(this.mLatitude, this.mLongitude, dest.getLatitude(), dest.getLongitude(), this.mResults); return this.mResults[0]; }; - /*private*/ Coordinate.computeDistanceAndBearing = function (lat1, lon1, lat2, lon2, results) { + computeDistanceAndBearing(lat1:number, lon1:number, lat2:number, lon2:number, results:any) { var MAXITERS = 20; lat1 *= Math.PI / 180.0; lat2 *= Math.PI / 180.0; @@ -168,8 +112,8 @@ } } }; - Coordinate.PI_OVER_180 = 0.017453292; - Coordinate.EARTH_RADIUS = 6371009; - return Coordinate; -}()); -Coordinate["__class"] = "Coordinate"; + +} + + + diff --git a/Ejectable/app.json b/Ejectable/app.json index 1b6d691e..0a5a8433 100644 --- a/Ejectable/app.json +++ b/Ejectable/app.json @@ -1,8 +1,8 @@ { "expo": { - "name": "Ejectable", + "name": "Green Travel Carbon Calculator", "slug": "Ejectable", - "version": "1.0.0", + "version": "2.0.0", "orientation": "portrait", "icon": "./assets/images/icon.png", "scheme": "myapp", diff --git a/Ejectable/navigation/BottomTabNavigator.tsx b/Ejectable/navigation/BottomTabNavigator.tsx index a8b748be..2ab4bf9d 100644 --- a/Ejectable/navigation/BottomTabNavigator.tsx +++ b/Ejectable/navigation/BottomTabNavigator.tsx @@ -70,7 +70,7 @@ function SplashNavigator() { ); } -const TripStack = createStackNavigator(); +export const TripStack = createStackNavigator(); function TripNavigator() { return ( diff --git a/Ejectable/navigation/LinkingConfiguration.ts b/Ejectable/navigation/LinkingConfiguration.ts index 2b3d9ea5..581a148d 100644 --- a/Ejectable/navigation/LinkingConfiguration.ts +++ b/Ejectable/navigation/LinkingConfiguration.ts @@ -14,17 +14,17 @@ export default { screens: { Splash: { screens: { - SplashScreen: 'one', + SplashScreen: 'home', }, }, Trip: { screens: { - TripScreen: 'two', + TripScreen: 'trip', }, }, Settings: { screens: { - SettingsScreen: 'three', + SettingsScreen: 'settings', }, }, }, diff --git a/Ejectable/package-lock.json b/Ejectable/package-lock.json index 78c6f04c..c607366f 100644 --- a/Ejectable/package-lock.json +++ b/Ejectable/package-lock.json @@ -13006,9 +13006,9 @@ } }, "react-devtools-core": { - "version": "4.15.0", - "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.15.0.tgz", - "integrity": "sha512-Y1NwrWSKRg4TtwcES2upzXFDmccAW9jrGQG2D8EGQrZhK+0hmuhgFnSdKpFc3z04CSeDT5t83RMXcmX5TkR1dA==", + "version": "4.16.0", + "resolved": "https://registry.npmjs.org/react-devtools-core/-/react-devtools-core-4.16.0.tgz", + "integrity": "sha512-fqyVbp+wVVey6O4uVBk5s3J/vTiPludp7lulr6a8asTBm7DIA0vLBbjmAOLCnOlkWcgdy4mjsqOgNCbu8uICWw==", "requires": { "shell-quote": "^1.6.1", "ws": "^7" diff --git a/Ejectable/screens/TripScreen.tsx b/Ejectable/screens/TripScreen.tsx index 04437e00..309d6b20 100644 --- a/Ejectable/screens/TripScreen.tsx +++ b/Ejectable/screens/TripScreen.tsx @@ -1,14 +1,9 @@ import * as React from 'react'; -import { Component } from 'react'; import { Button, StyleSheet, Alert } from 'react-native'; import { Text, View } from '../components/Themed'; import { ScreenInfo2 } from '../components/ScreenInfo'; -import { geocodeAsync } from 'expo-location'; -import * as GT2 from '../App'; -import * as Nav from '../navigation/BottomTabNavigator'; -import Navigation from '../navigation'; - -var elapsed:number, lat:number, long:number, ds:number, v:number; +import { thisTrip } from '../GT2'; +import { TripStack } from '../navigation/BottomTabNavigator'; const styles = StyleSheet.create({ tripText: { @@ -43,16 +38,8 @@ const styles = StyleSheet.create({ function startTrip() { - GT2.toggleTripInProgress(); - - elapsed = 0.0; - lat = 0.0; - long = 0.0; - ds = 0.0; - v = 0.0; - + thisTrip.start(); Alert.alert('Trip Started'); - } @@ -63,13 +50,14 @@ function pauseTrip() { function endTrip() { - GT2.toggleTripInProgress(); + thisTrip.end(); Alert.alert('Trip Ended'); } export default function TripScreen() { - if (!GT2.tripInProgress) + + if (!thisTrip.inProgress) return ( Trip Control @@ -112,9 +100,9 @@ export default function TripScreen() { - {'Elapsed: '}{elapsed}{'\n'} - {'Geo: '}{lat}{long}{'\n'} - {'Vector: '}{ds}{v}{'\n'} + {'Elapsed - '}{thisTrip.elapsed}{' seconds\n'} + {'Geo: '}{'lat: '}{thisTrip.loc.mLatitude}{' long: '}{thisTrip.loc.mLatitude}{'\n'} + {'Vector: '}{'distance: '}{thisTrip.distance}{' velocity: '}{thisTrip.v}{'\n'} diff --git a/Ejectable/tsconfig.json b/Ejectable/tsconfig.json index 92451b4d..f934fa0b 100644 --- a/Ejectable/tsconfig.json +++ b/Ejectable/tsconfig.json @@ -1,4 +1,4 @@ -{ +{ "extends": "expo/tsconfig.base", "compilerOptions": { "strict": true