Skip to content

Commit

Permalink
Merge pull request #849 from DroidPlanner/fix_event_bus_issue
Browse files Browse the repository at this point in the history
Fix the issue preventing Core from running as a java project.
  • Loading branch information
arthurbenemann committed Jul 2, 2014
2 parents e044f5b + ddb92fc commit cb2068c
Show file tree
Hide file tree
Showing 24 changed files with 77 additions and 139 deletions.
1 change: 0 additions & 1 deletion Android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ dependencies {
compile 'org.slf4j:slf4j-api:1.7.7'
compile 'org.slf4j:slf4j-nop:1.7.7'
compile 'org.osmdroid:osmdroid-android:4.1'
compile 'de.greenrobot:eventbus:2.2.1'

compile files('libs/usbseriallibrary.jar')
compile files('libs/wearable-preview-support.jar')
Expand Down
Binary file removed Android/libs/eventbus-2.2.1.jar
Binary file not shown.
36 changes: 11 additions & 25 deletions Android/src/org/droidplanner/android/DroidPlannerApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,13 @@

import org.droidplanner.android.gcs.FollowMe;
import org.droidplanner.android.utils.analytics.GAUtils;
import org.droidplanner.core.bus.events.DroneConnectedEvent;
import org.droidplanner.core.bus.events.DroneDisconnectedEvent;
import org.droidplanner.android.proxy.mission.MissionProxy;
import org.droidplanner.android.communication.service.MAVLinkClient;
import org.droidplanner.android.communication.service.NetworkStateReceiver;
import org.droidplanner.android.notifications.NotificationHandler;
import org.droidplanner.android.utils.DroidplannerPrefs;
import org.droidplanner.core.MAVLink.MAVLinkStreams;
import org.droidplanner.core.MAVLink.MavLinkMsgHandler;
import org.droidplanner.core.bus.events.DroneEvent;
import org.droidplanner.core.drone.Drone;
import org.droidplanner.core.drone.DroneInterfaces;
import org.droidplanner.core.drone.DroneInterfaces.Clock;
Expand All @@ -23,12 +20,10 @@

import com.MAVLink.Messages.MAVLinkMessage;

import de.greenrobot.event.EventBus;

public class DroidPlannerApp extends ErrorReportApp implements MAVLinkStreams.MavlinkInputStream,
DroneInterfaces.OnDroneListener {

public Drone drone;
private Drone drone;
public FollowMe followMe;
public MissionProxy missionProxy;
private MavLinkMsgHandler mavLinkMsgHandler;
Expand Down Expand Up @@ -68,12 +63,12 @@ public void postDelayed(Runnable thread, long timeout) {

DroidplannerPrefs pref = new DroidplannerPrefs(context);
drone = new Drone(MAVClient, clock, handler, pref);
drone.events.addDroneListener(this);
getDrone().events.addDroneListener(this);

missionProxy = new MissionProxy(drone.mission);
mavLinkMsgHandler = new org.droidplanner.core.MAVLink.MavLinkMsgHandler(drone);
missionProxy = new MissionProxy(getDrone().mission);
mavLinkMsgHandler = new org.droidplanner.core.MAVLink.MavLinkMsgHandler(getDrone());

followMe = new FollowMe(this, drone);
followMe = new FollowMe(this, getDrone());
NetworkStateReceiver.register(context);

GAUtils.initGATracker(this);
Expand All @@ -87,25 +82,12 @@ public void notifyReceivedData(MAVLinkMessage msg) {

@Override
public void notifyConnected() {
drone.events.notifyDroneEvent(DroneEventsType.CONNECTED);

//Broadcast the events
final EventBus bus = EventBus.getDefault();
bus.removeStickyEvent(DroneDisconnectedEvent.class);
bus.postSticky(new DroneConnectedEvent());

getDrone().events.notifyDroneEvent(DroneEventsType.CONNECTED);
}

@Override
public void notifyDisconnected() {
drone.events.notifyDroneEvent(DroneEventsType.DISCONNECTED);

//Broadcast the events
final EventBus bus = EventBus.getDefault();

//Remove all prior drone event broadcasts.
bus.removeStickyEvent(DroneEvent.class);
bus.postSticky(new DroneDisconnectedEvent());
getDrone().events.notifyDroneEvent(DroneEventsType.DISCONNECTED);
}

@Override
Expand All @@ -119,4 +101,8 @@ public void onDroneEvent(DroneEventsType event, Drone drone) {
break;
}
}

public Drone getDrone() {
return drone;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.droidplanner.android.DroidPlannerApp;
import org.droidplanner.android.fragments.helpers.BTDeviceListFragment;
import org.droidplanner.android.maps.providers.google_map.GoogleMapFragment;
import org.droidplanner.android.utils.Constants;
import org.droidplanner.android.utils.DroidplannerPrefs;
import org.droidplanner.android.utils.Utils;
import org.droidplanner.android.widgets.actionProviders.InfoBarActionProvider;
Expand All @@ -23,8 +22,6 @@
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.analytics.Tracker;

public abstract class SuperUI extends FragmentActivity implements OnDroneListener {
private ScreenOrientation screenOrientation = new ScreenOrientation(this);
private InfoBarActionProvider infoBar;
Expand All @@ -47,7 +44,7 @@ public void onCreate(Bundle savedInstanceState) {
}

app = (DroidPlannerApp) getApplication();
this.drone = app.drone;
this.drone = app.getDrone();
gcsHeartbeat = new GCSHeartbeat(drone, 1);
mAppPrefs = new DroidplannerPrefs(getApplicationContext());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,13 @@ public MAVLinkClient(Context context,
this.listener = listener;
}

public void init() {
private void init() {
parent.bindService(new Intent(parent, MAVLinkService.class),
mConnection, Context.BIND_AUTO_CREATE);
mIsBound = true;
}

public void close() {
private void close() {
if (isConnected()) {
// If we have received the service, and hence registered with
// it, then now is the time to unregister.
Expand Down
3 changes: 1 addition & 2 deletions Android/src/org/droidplanner/android/fragments/DroneMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.droidplanner.android.graphic.map.GraphicGuided;
import org.droidplanner.android.maps.DPMap;
import org.droidplanner.android.maps.providers.DPMapProvider;
import org.droidplanner.android.maps.providers.osm.OSMapFragment;
import org.droidplanner.android.proxy.mission.MissionProxy;
import org.droidplanner.android.utils.Utils;
import org.droidplanner.core.drone.Drone;
Expand Down Expand Up @@ -47,7 +46,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup viewGroup, Bundle bu

final Activity activity = getActivity();
final DroidPlannerApp app = ((DroidPlannerApp) activity.getApplication());
drone = app.drone;
drone = app.getDrone();
missionProxy = app.missionProxy;

home = new GraphicHome(drone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
View view = inflater.inflate(R.layout.fragment_editor_list, container, false);

DroidPlannerApp app = ((DroidPlannerApp) getActivity().getApplication());
drone = app.drone;
drone = app.getDrone();
missionProxy = app.missionProxy;
adapter = new MissionItemProxyView(getActivity(), missionProxy.getItems());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.MAVLink.Messages.ApmModes;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

public class FlightActionsFragment extends Fragment implements OnClickListener {

Expand All @@ -38,7 +37,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
View view = inflater.inflate(R.layout.fragment_mission_control, container, false);

DroidPlannerApp droidPlannerApp = (DroidPlannerApp) getActivity().getApplication();
drone = droidPlannerApp.drone;
drone = droidPlannerApp.getDrone();
followMe = droidPlannerApp.followMe;
return view;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void onClick(View view) {
@Override
public void onStart() {
super.onStart();
drone = ((DroidPlannerApp) getActivity().getApplication()).drone;
drone = ((DroidPlannerApp) getActivity().getApplication()).getDrone();
drone.events.addDroneListener(this);
drone.parameters.parameterListener = this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@
import org.droidplanner.android.activities.ConfigurationActivity;
import org.droidplanner.android.activities.helpers.MapPreferencesActivity;
import org.droidplanner.android.maps.providers.DPMapProvider;
import org.droidplanner.core.bus.events.DroneDisconnectedEvent;
import org.droidplanner.core.bus.events.DroneHeartBeatEvent;
import org.droidplanner.core.drone.Drone;
import org.droidplanner.core.drone.DroneInterfaces;
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.android.utils.Constants;
import org.droidplanner.android.utils.file.DirectoryPath;
import org.droidplanner.core.drone.variables.HeartBeat;

import android.content.Context;
import android.content.Intent;
Expand All @@ -18,25 +19,21 @@
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.PreferenceCategory;
import android.preference.PreferenceFragment;
import android.preference.PreferenceManager;
import android.util.Log;

import com.google.android.gms.analytics.GoogleAnalytics;

import java.util.HashSet;

import de.greenrobot.event.EventBus;

/**
* Implements the application settings screen.
*/
public class SettingsFragment extends DpPreferenceFragment implements
OnSharedPreferenceChangeListener {
OnSharedPreferenceChangeListener, DroneInterfaces.OnDroneListener {

/**
* Used as tag for logging.
Expand Down Expand Up @@ -215,7 +212,7 @@ private void updateMavlinkVersionPreference(String version){
mavlinkVersionPref.setSummary(getString(R.string.empty_content));
}
else{
mavlinkVersionPref.setSummary(version);
mavlinkVersionPref.setSummary('v' + version);
}
}
}
Expand Down Expand Up @@ -256,7 +253,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
}

if (key.equals(getString(R.string.pref_vehicle_type_key))) {
((DroidPlannerApp) getActivity().getApplication()).drone.events
((DroidPlannerApp) getActivity().getApplication()).getDrone().events
.notifyDroneEvent(DroneEventsType.TYPE);
}

Expand All @@ -272,20 +269,31 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin
@Override
public void onStart(){
super.onStart();
EventBus.getDefault().registerSticky(this);

final Drone drone = ((DroidPlannerApp)getActivity().getApplication()).getDrone();
final byte mavlinkVersion = drone.heartbeat.getMavlinkVersion();
if(mavlinkVersion != HeartBeat.INVALID_MAVLINK_VERSION){
updateMavlinkVersionPreference(String.valueOf(mavlinkVersion));
}
else{
updateMavlinkVersionPreference(null);
}

drone.events.addDroneListener(this);
}

@Override
public void onStop(){
super.onStop();
EventBus.getDefault().unregister(this);

final Drone drone = ((DroidPlannerApp)getActivity().getApplication()).getDrone();
drone.events.removeDroneListener(this);
}

@Override
public void onResume() {
super.onResume();
getPreferenceScreen().getSharedPreferences()
.registerOnSharedPreferenceChangeListener(this);
getPreferenceScreen().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}

@Override
Expand All @@ -295,26 +303,17 @@ public void onPause() {
.unregisterOnSharedPreferenceChangeListener(this);
}

/*
Event bus handler methods
*/

/**
* Handle update of the settings ui after a drone heartbeat event is received from the event
* bus.
* @param heartbeatEvent drone heartbeat event
*/
public void onEventMainThread(DroneHeartBeatEvent heartbeatEvent){
updateMavlinkVersionPreference(String.valueOf(heartbeatEvent.getHeartBeat()
.mavlink_version));
}

/**
* Handle update of the settings ui after a drone disconnected event is received from the
* event bus.
* @param event drone disconnected event
*/
public void onEventMainThread(DroneDisconnectedEvent event){
updateMavlinkVersionPreference(null);
@Override
public void onDroneEvent(DroneEventsType event, Drone drone) {
switch (event) {
case DISCONNECTED:
updateMavlinkVersionPreference(null);
break;

case HEARTBEAT_FIRST:
case HEARTBEAT_RESTORED:
updateMavlinkVersionPreference(String.valueOf(drone.heartbeat.getMavlinkVersion()));
break;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
altitude = (TextView) view.findViewById(R.id.altitudeValue);
targetAltitude = (TextView) view.findViewById(R.id.targetAltitudeValue);

drone = ((DroidPlannerApp) getActivity().getApplication()).drone;
drone = ((DroidPlannerApp) getActivity().getApplication()).getDrone();
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public class TuningFragment extends Fragment implements OnDroneListener {
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
drone = ((DroidPlannerApp) getActivity().getApplication()).drone;
drone = ((DroidPlannerApp) getActivity().getApplication()).getDrone();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void onItemClick(AdapterView<?> parent, View view, int position,
device.getAddress()).apply();

// Toggle the drone connection
((DroidPlannerApp) activity.getApplication()).drone.MavClient
((DroidPlannerApp) activity.getApplication()).getDrone().MavClient
.toggleConnectionState();

// Dismiss the dialog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
this.drone = ((DroidPlannerApp) getActivity().getApplication()).drone;
this.drone = ((DroidPlannerApp) getActivity().getApplication()).getDrone();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
DroidPlannerApp app = (DroidPlannerApp) getActivity().getApplication();
followMe = app.followMe;
drone = app.drone;
drone = app.getDrone();
View view = inflater.inflate(R.layout.fragment_mode_follow, container,
false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_mode_guided, container,
false);
drone = ((DroidPlannerApp) getActivity().getApplication()).drone;
drone = ((DroidPlannerApp) getActivity().getApplication()).getDrone();
setupViews(view);
setupListener();
updateLabel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ protected int getResource() {
@Override
public void onStart() {
super.onStart();
((DroidPlannerApp)getActivity().getApplication()).drone.events.addDroneListener(this);
((DroidPlannerApp)getActivity().getApplication()).getDrone().events.addDroneListener(this);
}

@Override
public void onStop() {
super.onStop();
((DroidPlannerApp)getActivity().getApplication()).drone.events.removeDroneListener(this);
((DroidPlannerApp)getActivity().getApplication()).getDrone().events.removeDroneListener(this);
}

@Override
Expand Down
1 change: 0 additions & 1 deletion Core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ configurations {
}

dependencies {
compile 'de.greenrobot:eventbus:2.2.1'
compile project(':Mavlink')

//FIXME: hackish implementation
Expand Down
Binary file removed Core/libs/eventbus-2.2.1.jar
Binary file not shown.
Loading

0 comments on commit cb2068c

Please sign in to comment.