Skip to content

Commit

Permalink
Improved the ScLocationService class
Browse files Browse the repository at this point in the history
  • Loading branch information
paroca72 committed Aug 7, 2016
1 parent 8d8420a commit f96d7e9
Show file tree
Hide file tree
Showing 12 changed files with 359 additions and 86 deletions.
3 changes: 0 additions & 3 deletions .idea/dictionaries/Samuele.xml

This file was deleted.

19 changes: 0 additions & 19 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ Add the dependency
```java
dependencies {
...
compile 'com.github.paroca72:sc-utils:1.2.1'
compile 'com.github.paroca72:sc-utils:1.2.5'
}
```

Expand Down
17 changes: 17 additions & 0 deletions ScLocationService.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@
This class can be used for retrieve the location manager and for maintain checked the location accessibility.
This class inherit from the [ScChecker](ScChecker.md).
<br />
Now base on <code>FusedLocationApi</code> can tracking the location updates using <code>startLocationTracking(...)</code> method.
<br />
Through the listener implementation you can know when the location accessibility status changed.


#### Methods
- **ConnectivityManager getConnectivityManager()**<br />
Return the connectivity manager when available.
Expand All @@ -13,6 +16,20 @@ Return the connectivity manager when available.
<code>true</code> if able to find the location by the GPS.
- **boolean check()**<br />
<code>true</code> if is possible to retrieve the current location.
- **boolean isLocationTrackerEnabled()**<br />
Check if the location tracker is enabled
- **boolean isGoogleAPIAvailable()**<br />
Check is the google API is available.
The google API needed for the focused location tracker.
- **void startLocationTracking(LocationListener listener)**<br />
Start the location tracking.
- **void stopLocationTracking()**<br />
Stop the location tracking.
- **Location getLocation()**<br />
Get the last known location.
- **LocationRequest getLocationRequest()**<br />
Get the location request settings object.


### Example
For an example please take a look the demo section in the project structure.
Expand Down
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ apply plugin: 'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '24.0.1'

defaultConfig {
applicationId "com.sccomponents.utils.demo"
minSdkVersion 15
targetSdkVersion 23
versionCode 1
versionName "1.0"
multiDexEnabled true
}
buildTypes {
release {
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/com/sccomponents/utils/demo/LocationChecker.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
package com.sccomponents.utils.demo;

import android.location.Location;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;

import com.google.android.gms.location.LocationListener;
import com.sccomponents.utils.ScChecker;
import com.sccomponents.utils.ScLocationService;

Expand Down Expand Up @@ -37,6 +39,17 @@ public void onChangeState(boolean result) {
LocationChecker.this.write();
}
});
this.mService.startLocationTracking(new LocationListener() {
@Override
public void onLocationChanged(Location location) {
TextView text = (TextView) LocationChecker.this.findViewById(R.id.txtLocation);
if (location == null) {
text.setText("Unknown location");
} else {
text.setText(location.getLatitude() + " : " + location.getLongitude());
}
}
});

// Write
this.write();
Expand Down
127 changes: 82 additions & 45 deletions app/src/main/res/layout/activity_location_checker.xml
Original file line number Diff line number Diff line change
@@ -1,69 +1,106 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<LinearLayout 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"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="scapps.com.sccheckerdemo.MainActivity"
android:orientation="vertical"
android:gravity="center_vertical|center_horizontal">
android:paddingTop="@dimen/activity_vertical_margin">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check every 1 seconds the ability to find the current location"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal"
android:layout_marginBottom="20dp"/>
android:text="Check every 1 seconds the ability to find the current location" />

<TextView
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Network"
/>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OFF"
android:textColor="#000000"
android:textSize="30dp"
android:id="@+id/txtNetwork"
android:gravity="center_horizontal"
android:layout_marginBottom="10dp"/>
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPS"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="OFF"
android:textColor="#000000"
android:textSize="30dp"
android:id="@+id/txtGPS"
android:gravity="center_horizontal"
android:layout_marginBottom="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Network" />

<TextView
<TextView
android:id="@+id/txtNetwork"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="10dp"
android:gravity="center_horizontal"
android:text="OFF"
android:textColor="#000000"
android:textSize="30dp" />

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="GPS" />

<TextView
android:id="@+id/txtGPS"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:gravity="center_horizontal"
android:text="OFF"
android:textColor="#000000"
android:textSize="30dp" />

</LinearLayout>

</LinearLayout>

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current location available"
/>
android:gravity="center_vertical|center_horizontal"
android:orientation="vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="NO"
android:textColor="#000000"
android:textSize="30dp"
android:id="@+id/txtAvailable"
android:gravity="center_horizontal"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Current location available" />

<TextView
android:id="@+id/txtAvailable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:text="NO"
android:textColor="#000000"
android:textSize="30dp" />

<TextView
android:id="@+id/txtLocation"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="" />

</LinearLayout>

</LinearLayout>
1 change: 1 addition & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# The setting is particularly useful for tweaking memory settings.
# Default value: -Xmx10248m -XX:MaxPermSize=256m
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.jvmargs=-Xmx2048m

# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
Expand Down
8 changes: 5 additions & 3 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ group='com.github.Paroca72'

android {
compileSdkVersion 23
buildToolsVersion "23.0.2"
buildToolsVersion '24.0.1'
defaultConfig {
minSdkVersion 15
targetSdkVersion 23
versionCode 5
versionName '1.2.1'
versionCode 10
versionName '1.2.5'
multiDexEnabled true
}
buildTypes {
release {
Expand All @@ -24,4 +25,5 @@ android {

dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.google.android.gms:play-services:9.4.0'
}
4 changes: 4 additions & 0 deletions library/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<manifest package="com.sccomponents.utils"
xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:allowBackup="true"
android:supportsRtl="true"
Expand Down
Loading

0 comments on commit f96d7e9

Please sign in to comment.