Skip to content

Commit

Permalink
emit last known location when new textview is attached
Browse files Browse the repository at this point in the history
  • Loading branch information
omegaes committed Feb 1, 2018
1 parent 9a5efa2 commit a561a03
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Add it in your root build.gradle at the end of repositories:
Add the dependency
```
dependencies {
compile 'com.github.omegaes:FarAwayTextView:1.0.2'
compile 'com.github.omegaes:FarAwayTextView:1.0.3'
}
````
Expand Down
4 changes: 2 additions & 2 deletions farawaytextview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 14
targetSdkVersion 25
versionCode 2
versionName "1.0.1"
versionCode 4
versionName "1.0.3"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.widget.TextView;

import java.util.Observable;
import java.util.Observer;
Expand Down Expand Up @@ -68,6 +69,23 @@ public synchronized void deleteObserver(Observer o) {
}
}

@Override
public synchronized void addObserver(Observer o) {
super.addObserver(o);
if(o instanceof FarAwayTextView){
FarAwayTextView textView = (FarAwayTextView)o;
if (textView.getContext() == null)
return;
if (ActivityCompat.checkSelfPermission(textView.getContext(), Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(textView.getContext(), Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
notifyObservers(locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER));
notifyObservers(locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER));
}


}

private void shutDown() {
locationManager.removeUpdates(this);
instance = null;
Expand Down

0 comments on commit a561a03

Please sign in to comment.