Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
quic-sgalat committed Jan 6, 2023
0 parents commit 3bef2a6
Show file tree
Hide file tree
Showing 20 changed files with 1,005 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
.idea/
build/
captures/
local.properties
*.iml
.gradle
.DS_Store
3 changes: 3 additions & 0 deletions .omniscanignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=gradle/
=gradlew
=gradlew.bat
392 changes: 392 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

101 changes: 101 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
# TPS Location SDK: Quick Start for Android
![Platform](https://img.shields.io/static/v1?label=platform&message=android&color=informational)

The Quick Start project illustrates minimal steps to integrate the SDK into your app.

## Contact TPS

Contact [email protected] to request access to the SDK and get the API key.

## Add SDK to your project

Put the SDK library file under the `app/libs/` subdirectory and add it to the `dependencies` section of your `build.gradle`:
```gradle
dependencies {
implementation files('libs/wpsapi.aar')
}
```

## Import the SDK

Import the Skyhook WPS package:
```java
import com.skyhookwireless.wps;
```

## Initialize API

Create a new instance of the `XPS` class in the `onCreate` method of your activity or application class and set your API key:
```java
private IWPS xps;
...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
xps = new XPS(this);
xps.setKey("YOUR KEY");
...
}
```

Make sure to replace `"YOUR KEY"` with your real API key in the Quick Start app source code (see the `onCreate()` method in `MainActivity.java`).

## Request location permission

In order to be able to start location determination, your app must first obtain the `ACCESS_FINE_LOCATION` permission from the user:
```java
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
ActivityCompat.requestPermissions(
this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
}
```

## Request location

Once the location permission has been granted, you can make a locaton request.

Note that the callback methods are invoked from the background thread, so you have to use `runOnUiThread()` to manipulate the UI.
```java
xps.getLocation(null, WPSStreetAddressLookup.WPS_NO_STREET_ADDRESS_LOOKUP, false, new WPSLocationCallback() {
@Override
public void handleWPSLocation(WPSLocation location) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// display location
}
});
}

@Override
public WPSContinuation handleError(WPSReturnCode error) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// display error
}
});

return WPSContinuation.WPS_CONTINUE;
}

@Override
public void done() {
// after done() returns, you can make more XPS calls
}
});
```

**Note**: [starting with Android 9](https://developer.android.com/guide/topics/connectivity/wifi-scan#wifi-scan-throttling) a fresh Wi-Fi location can only be calculated four times during a 2-minute period.

## Further Read

Please refer to the [full SDK guide](https://quic.github.io/tps-location-sdk-android/) for more information.

# License
![License](https://img.shields.io/static/v1?label=license&message=CC-BY-ND-4.0&color=green)

Copyright (c) 2023 Qualcomm Innovation Center, Inc. All Rights Reserved.

This work is licensed under the [CC BY-ND 4.0 License](https://creativecommons.org/licenses/by-nd/4.0/). See [LICENSE](LICENSE) for more details.
17 changes: 17 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
apply plugin: 'com.android.application'

android {
compileSdkVersion 28
defaultConfig {
applicationId "com.skyhook.locationquickstart"
minSdkVersion 19
targetSdkVersion 28
versionCode 1
versionName "1.0"
}
}

dependencies {
implementation 'com.android.support:appcompat-v7:28.0.0'
implementation files('libs/wpsapi.aar')
}
1 change: 1 addition & 0 deletions app/libs/README
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Put wpsapi.aar here.
21 changes: 21 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="com.skyhook.locationquickstart"
xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:allowBackup="false"
android:icon="@drawable/skyhook_logo"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">

<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>

</application>

</manifest>
118 changes: 118 additions & 0 deletions app/src/main/java/com/skyhook/locationquickstart/MainActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.skyhook.locationquickstart;

import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.skyhookwireless.wps.IWPS;
import com.skyhookwireless.wps.WPSContinuation;
import com.skyhookwireless.wps.WPSLocation;
import com.skyhookwireless.wps.WPSLocationCallback;
import com.skyhookwireless.wps.WPSReturnCode;
import com.skyhookwireless.wps.WPSStreetAddressLookup;
import com.skyhookwireless.wps.XPS;

import java.util.Locale;

public class MainActivity
extends AppCompatActivity
{
private TextView tv;
private ProgressBar progress;
private IWPS xps;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setTitle(String.format(
Locale.ROOT,
"%s (XPS v%s)",
getString(R.string.app_name),
XPS.getVersion()));

tv = findViewById(R.id.tv);
progress = findViewById(R.id.progress);

xps = new XPS(this);

try {
xps.setKey("YOUR KEY");
} catch (IllegalArgumentException e) {
tv.setText("Put your API key in the source code");
}

ActivityCompat.requestPermissions(
this, new String[] { Manifest.permission.ACCESS_FINE_LOCATION }, 0);
}

public void onClick(View view) {
determineLocation();
}

private void determineLocation() {
if (! hasLocationPermission()) {
tv.setText("Permission denied");
return;
}

tv.setVisibility(View.INVISIBLE);
progress.setVisibility(View.VISIBLE);

xps.getLocation(
null,
WPSStreetAddressLookup.WPS_FULL_STREET_ADDRESS_LOOKUP,
true,
new WPSLocationCallback() {
@Override
public void handleWPSLocation(final WPSLocation location) {
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setText(String.format(
Locale.ROOT,
"%.7f %.7f +/-%dm\n\n%s\n\n%s",
location.getLatitude(),
location.getLongitude(),
location.getHPE(),
location.hasTimeZone() ? location.getTimeZone() : "No timezone",
location.hasStreetAddress() ? location.getStreetAddress() : "No address"));
}
});
}

@Override
public void done() {
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setVisibility(View.VISIBLE);
progress.setVisibility(View.INVISIBLE);
}
});
}

@Override
public WPSContinuation handleError(final WPSReturnCode returnCode) {
runOnUiThread(new Runnable() {
@Override
public void run() {
tv.setText(returnCode.toString());
}
});

return WPSContinuation.WPS_CONTINUE;
}
});
}

private boolean hasLocationPermission() {
return checkCallingOrSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED;
}
}
Binary file added app/src/main/res/drawable/skyhook_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:textSize="18dp"
android:text="Tap to determine location"
android:onClick="onClick"/>

<ProgressBar
android:id="@+id/progress"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:visibility="invisible"/>

</FrameLayout>
6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#008577</color>
<color name="colorPrimaryDark">#00574B</color>
<color name="colorAccent">#D81B60</color>
</resources>
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<resources>
<string name="app_name">Quick Start</string>
</resources>
11 changes: 11 additions & 0 deletions app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>

</resources>
22 changes: 22 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
buildscript {
repositories {
google()
jcenter()

}
dependencies {
classpath 'com.android.tools.build:gradle:3.4.0'
}
}

allprojects {
repositories {
google()
jcenter()

}
}

task clean(type: Delete) {
delete rootProject.buildDir
}
15 changes: 15 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Project-wide Gradle settings.
# IDE (e.g. Android Studio) users:
# Gradle settings configured through the IDE *will override*
# any settings specified in this file.
# For more details on how to configure your build environment visit
# http://www.gradle.org/docs/current/userguide/build_environment.html
# Specifies the JVM arguments used for the daemon process.
# The setting is particularly useful for tweaking memory settings.
org.gradle.jvmargs=-Xmx1536m
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true


Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 6 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#Thu May 30 09:05:08 EDT 2019
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.1.1-all.zip
Loading

0 comments on commit 3bef2a6

Please sign in to comment.