Skip to content

Commit 5266572

Browse files
author
Mantas Palaima
committed
Merge branch 'location_module' into dev
2 parents 79d03fa + ea60c3d commit 5266572

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+535
-17
lines changed

app/build.gradle

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ dependencies {
3838
compile 'com.android.support:appcompat-v7:22.1.1'
3939
compile 'com.squareup.picasso:picasso:2.5.2'
4040
compile 'com.squareup.okhttp:okhttp:2.2.0'
41-
compile 'com.jakewharton.scalpel:scalpel:1.1.2'
41+
compile 'com.google.android.gms:play-services-location:7.3.0'
4242
/*compile 'io.palaima.debugdrawer:debugdrawer:0.2.1'
4343
compile 'io.palaima.debugdrawer:debugdrawer-okhttp:0.2.1'
4444
compile 'io.palaima.debugdrawer:debugdrawer-scalpel:0.2.1'
@@ -47,5 +47,6 @@ dependencies {
4747
compile project(':debugdrawer-picasso')
4848
compile project(':debugdrawer-okhttp')
4949
compile project(':debugdrawer-scalpel')
50+
compile project(':debugdrawer-location')
5051
}
5152

app/src/main/java/io/palaima/debugdrawer/app/MainActivity.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.util.concurrent.TimeUnit;
2323

2424
import io.palaima.debugdrawer.DebugDrawer;
25+
import io.palaima.debugdrawer.location.LocationModule;
2526
import io.palaima.debugdrawer.module.BuildModule;
2627
import io.palaima.debugdrawer.module.DeviceModule;
2728
import io.palaima.debugdrawer.module.NetworkModule;
@@ -30,7 +31,6 @@
3031
import io.palaima.debugdrawer.picasso.PicassoModule;
3132
import io.palaima.debugdrawer.scalpel.ScalpelModule;
3233

33-
3434
public class MainActivity extends AppCompatActivity {
3535

3636
private Toolbar mToolbar;
@@ -64,6 +64,7 @@ public void onImageLoadFailed(Picasso picasso, Uri uri, Exception e) {
6464
}*/
6565
if (BuildConfig.DEBUG) {
6666
mDebugDrawer = new DebugDrawer.Builder(this).modules(
67+
new LocationModule(this),
6768
new ScalpelModule(this),
6869
new OkHttpModule(mOkHttpClient),
6970
new PicassoModule(mPicasso),

debugdrawer-location/.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

debugdrawer-location/build.gradle

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.library'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "22.0.1"
6+
7+
defaultConfig {
8+
minSdkVersion 15
9+
targetSdkVersion 22
10+
versionCode 1
11+
versionName "1.0"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
compile fileTree(dir: 'libs', include: ['*.jar'])
23+
compile 'com.android.support:appcompat-v7:22.1.1'
24+
compile 'com.google.android.gms:play-services-location:7.3.0'
25+
compile project(':debugdrawer')
26+
}
27+
28+
apply from: 'https://raw.github.com/chrisbanes/gradle-mvn-push/master/gradle-mvn-push.gradle'
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Project-wide Gradle settings.
2+
3+
# IDE (e.g. Android Studio) users:
4+
# Gradle settings configured through the IDE *will override*
5+
# any settings specified in this file.
6+
7+
# For more details on how to configure your build environment visit
8+
# http://www.gradle.org/docs/current/userguide/build_environment.html
9+
10+
# Specifies the JVM arguments used for the daemon process.
11+
# The setting is particularly useful for tweaking memory settings.
12+
# Default value: -Xmx10248m -XX:MaxPermSize=256m
13+
# org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
14+
15+
# When configured, Gradle will run in incubating parallel mode.
16+
# This option should only be used with decoupled projects. More details, visit
17+
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
18+
# org.gradle.parallel=true
19+
20+
POM_NAME=Debug Drawer Location Module
21+
POM_ARTIFACT_ID=debugdrawer-location
22+
POM_PACKAGING=aar
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in C:\android-sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package io.palaima.debugdrawer.picasso;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
11+
public ApplicationTest() {
12+
super(Application.class);
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<manifest package="io.palaima.debugdrawer.location"
2+
xmlns:android="http://schemas.android.com/apk/res/android">
3+
4+
<application android:allowBackup="true"/>
5+
6+
</manifest>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
/*
2+
* Copyright (C) 2015 Mantas Palaima
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.palaima.debugdrawer.location;
18+
19+
import com.google.android.gms.common.ConnectionResult;
20+
import com.google.android.gms.common.api.GoogleApiClient;
21+
import com.google.android.gms.location.LocationListener;
22+
import com.google.android.gms.location.LocationRequest;
23+
import com.google.android.gms.location.LocationServices;
24+
25+
import android.content.Context;
26+
import android.location.Location;
27+
import android.os.Bundle;
28+
import android.util.Log;
29+
30+
public class LocationController implements GoogleApiClient.ConnectionCallbacks,
31+
GoogleApiClient.OnConnectionFailedListener {
32+
33+
private LocationListener mLocationListener;
34+
35+
private static LocationController instance;
36+
37+
38+
private GoogleApiClient mGoogleApiClient;
39+
40+
private LocationRequest mLocationRequest;
41+
42+
private boolean mIsStarted;
43+
44+
private boolean mConnected;
45+
46+
public static LocationController newInstance(Context context) {
47+
if (instance == null)
48+
instance = new LocationController(context);
49+
return instance;
50+
}
51+
52+
private LocationController(Context context) {
53+
buildGoogleApiClient(context);
54+
}
55+
56+
public void setLocationListener(LocationListener listener) {
57+
mLocationListener = listener;
58+
}
59+
60+
@Override
61+
public void onConnected(Bundle bundle) {
62+
Log.d("LocationModule", "onConnected ");
63+
mConnected = true;
64+
if (!mIsStarted) {
65+
startLocationUpdates();
66+
}
67+
}
68+
69+
@Override
70+
public void onConnectionSuspended(int i) {
71+
Log.d("LocationModule", "onConnectionSuspended ");
72+
mConnected = false;
73+
}
74+
75+
@Override
76+
public void onConnectionFailed(ConnectionResult connectionResult) {
77+
Log.d("LocationModule", "onConnectionFailed ");
78+
mConnected = false;
79+
}
80+
81+
/**
82+
* Get last known location
83+
*
84+
* @return Location
85+
*/
86+
public Location getLastLocation() {
87+
return LocationServices.FusedLocationApi.getLastLocation(
88+
mGoogleApiClient);
89+
}
90+
91+
protected synchronized void buildGoogleApiClient(Context context) {
92+
mGoogleApiClient = new GoogleApiClient.Builder(context)
93+
.addConnectionCallbacks(this)
94+
.addOnConnectionFailedListener(this)
95+
.addApi(LocationServices.API)
96+
.build();
97+
}
98+
99+
/* protected void createLocationRequest() {
100+
mLocationRequest = new LocationRequest();
101+
mLocationRequest.setInterval(TimeUnit.SECONDS.toMillis(10));
102+
mLocationRequest.setFastestInterval(TimeUnit.SECONDS.toMillis(5));
103+
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
104+
}*/
105+
106+
public void setLocationRequest(LocationRequest locationRequest) {
107+
mLocationRequest = locationRequest;
108+
}
109+
110+
public void startLocationUpdates() {
111+
mGoogleApiClient.connect();
112+
if (mConnected && mLocationRequest != null) {
113+
mIsStarted = true;
114+
LocationServices.FusedLocationApi.requestLocationUpdates(
115+
mGoogleApiClient, mLocationRequest, mLocationListener);
116+
}
117+
}
118+
119+
public void stopLocationUpdates() {
120+
if (mConnected && mLocationRequest != null) {
121+
LocationServices.FusedLocationApi.removeLocationUpdates(
122+
mGoogleApiClient, mLocationListener);
123+
mGoogleApiClient.disconnect();
124+
mConnected = false;
125+
mIsStarted = false;
126+
}
127+
}
128+
}

0 commit comments

Comments
 (0)