add missing file, add osmand license note to readme

This commit is contained in:
Andreas Shimokawa 2021-10-19 14:41:25 +02:00
parent 6126f32366
commit 6504c50af7
2 changed files with 139 additions and 0 deletions

View File

@ -21,6 +21,12 @@ vendor's servers.
[![Total Alerts](https://img.shields.io/lgtm/alerts/g/Freeyourgadget/Gadgetbridge.svg?logo=lgtm&logoWidth=18)](https://lgtm.com/projects/g/Freeyourgadget/Gadgetbridge/alerts)
[![Translate](https://hosted.weblate.org/widgets/freeyourgadget/-/gadgetbridge/svg-badge.svg)](https://hosted.weblate.org/projects/freeyourgadget/gadgetbridge)
## Code Licenses
* Gadgetbrige is licensed under the AGPLv3
* Files in app/src/main/java/net/osmand/ and app/src/main/aidl/net/osmand/ are licensed under the GPLv3 by OsmAnd BV
## Download
[<img src="https://f-droid.org/badge/get-it-on.png" alt="Get it on F-Droid" height="80">](https://f-droid.org/app/nodomain.freeyourgadget.gadgetbridge)

View File

@ -0,0 +1,133 @@
package nodomain.freeyourgadget.gadgetbridge.externalevents;
import android.app.Application;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.view.KeyEvent;
import android.widget.Toast;
import net.osmand.aidlapi.IOsmAndAidlCallback;
import net.osmand.aidlapi.IOsmAndAidlInterface;
import net.osmand.aidlapi.gpx.AGpxBitmap;
import net.osmand.aidlapi.navigation.ADirectionInfo;
import net.osmand.aidlapi.navigation.ANavigationUpdateParams;
import net.osmand.aidlapi.navigation.OnVoiceNavigationParams;
import net.osmand.aidlapi.search.SearchResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.List;
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public class OsmandEventReceiver {
private static final Logger LOG = LoggerFactory.getLogger(OsmandEventReceiver.class);
private static final String OSMAND_PLUS_PACKAGE_NAME = "net.osmand.plus";
private static final String OSMAND_PACKAGE_NAME = OSMAND_PLUS_PACKAGE_NAME;
private final Application app;
private IOsmAndAidlInterface mIOsmAndAidlInterface;
private final IOsmAndAidlCallback.Stub mIOsmAndAidlCallback = new IOsmAndAidlCallback.Stub() {
@Override
public void onSearchComplete(List<SearchResult> resultSet) {
}
@Override
public void onUpdate() {
}
@Override
public void onAppInitialized() {
}
@Override
public void onGpxBitmapCreated(AGpxBitmap bitmap) {
}
@Override
public void updateNavigationInfo(ADirectionInfo directionInfo) {
LOG.error("Distance: " + directionInfo.getDistanceTo());
}
@Override
public void onContextMenuButtonClicked(int buttonId, String pointId, String layerId) {
}
@Override
public void onVoiceRouterNotify(OnVoiceNavigationParams params) {
}
@Override
public void onKeyEvent(KeyEvent keyEvent) {
}
};
private final ServiceConnection mConnection = new ServiceConnection() {
public void onServiceConnected(ComponentName className,
IBinder service) {
mIOsmAndAidlInterface = IOsmAndAidlInterface.Stub.asInterface(service);
GB.toast("OsmAnd service conncted", Toast.LENGTH_SHORT, GB.INFO);
registerForNavigationUpdates(true, 6666); // what is this id for?
}
public void onServiceDisconnected(ComponentName className) {
mIOsmAndAidlInterface = null;
GB.toast("OsmAnd service disconnected", Toast.LENGTH_SHORT, GB.INFO);
}
};
public OsmandEventReceiver(Application application) {
this.app = application;
if (!bindService()) {
LOG.warn("Could not bind to OsmAnd");
}
}
private boolean bindService() {
if (mIOsmAndAidlInterface == null) {
Intent intent = new Intent("net.osmand.aidl.OsmandAidlServiceV2");
intent.setPackage(OSMAND_PACKAGE_NAME);
boolean res = app.bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
if (res) {
GB.toast("bound to OsmAnd service", Toast.LENGTH_SHORT, GB.INFO);
return true;
} else {
GB.toast("could not bind to OsmAnd service", Toast.LENGTH_SHORT, GB.INFO);
return false;
}
} else {
return true;
}
}
public void cleanupResources() {
if (mIOsmAndAidlInterface != null) {
app.unbindService(mConnection);
}
}
public long registerForNavigationUpdates(boolean subscribeToUpdates, long callbackId) {
if (mIOsmAndAidlInterface != null) {
try {
ANavigationUpdateParams params = new ANavigationUpdateParams();
params.setCallbackId(callbackId);
params.setSubscribeToUpdates(subscribeToUpdates);
return mIOsmAndAidlInterface.registerForNavigationUpdates(params, mIOsmAndAidlCallback);
} catch (RemoteException e) {
LOG.error("could not subscribe to navication updates", e);
}
}
return -1L;
}
}