Skip to content

Commit

Permalink
Added vehicle specific icons and also added the option (under advance…
Browse files Browse the repository at this point in the history
…d settings) for the user to choose between newly added icons and old arrow
  • Loading branch information
preet90 authored and billbonney committed Oct 25, 2017
1 parent 90d1951 commit 959112e
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 6 deletions.
Binary file added Android/res/drawable/redcopter.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable/redplane.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Android/res/drawable/redrover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@
<string name="pref_advance_menu_title">Advanced Menu Options</string>
<string name="pref_enable_kill_switch_summary">If enabled, a Kill Switch option will appear in the menu, allowing immediate vehicle disarming. Only supported on multi-rotor vehicles</string>
<string name="pref_enable_kill_switch_title">Enable Kill Switch</string>
<string name="pref_enable_vehicle_specific_icon_title">Enable Vehicle Specific Icons</string>
<string name="pref_enable_vehicle_specific_icon_summary">Enable Vehicle Specific Icons for Copter, Plane and Rover</string>
<string name="pref_enable_udp_server_title">Enable UDP server ping</string>
<string name="pref_udp_server_ping_summary">Enable to allow the app to periodically ping the udp server.</string>
<string name="pref_udp_ping_receiver_ip_title">UDP ping receiver ip</string>
Expand Down
6 changes: 6 additions & 0 deletions Android/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@
android:key="pref_enable_kill_switch"
android:summary="@string/pref_enable_kill_switch_summary"
android:title="@string/pref_enable_kill_switch_title" />

<CheckBoxPreference
android:defaultValue="false"
android:key="pref_enable_vehicle_specific_icons"
android:summary="@string/pref_enable_vehicle_specific_icon_summary"
android:title="@string/pref_enable_vehicle_specific_icon_title" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_alt_title">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ public void onApiConnected() {
home = new GraphicHome(drone, getContext());
mMapFragment.addMarker(home);

graphicDrone = new GraphicDrone(drone);
graphicDrone = new GraphicDrone(drone, context);
mMapFragment.addMarker(graphicDrone);

guided = new GraphicGuided(drone);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public class SettingsFragment extends PreferenceFragment implements OnSharedPref
public static final String ACTION_WIDGET_PREFERENCE_UPDATED = PACKAGE_NAME + ".ACTION_WIDGET_PREFERENCE_UPDATED";
public static final String EXTRA_ADD_WIDGET = "extra_add_widget";
public static final String EXTRA_WIDGET_PREF_KEY = "extra_widget_pref_key";

public static final String VEHICLE_SPECIFIC_ICON_PREF_KEY = "vehicle_specific_icon_pref_key";
private static final IntentFilter intentFilter = new IntentFilter();

static {
Expand Down Expand Up @@ -288,6 +288,21 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
}
});
}

final CheckBoxPreference vehicleSpecificIcons = (CheckBoxPreference) findPreference(DroidPlannerPrefs.PREF_ENABLE_VEHICLE_SPECIFIC_ICONS);
if(vehicleSpecificIcons != null) {
vehicleSpecificIcons.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
boolean showVehicleSpecificIcons = Boolean.valueOf(newValue.toString());
SharedPreferences prefs = getContext().getSharedPreferences("towerPrefsKey", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(VEHICLE_SPECIFIC_ICON_PREF_KEY, showVehicleSpecificIcons);
editor.commit();
return true;
}
});
}
}

private void setupUnitSystemPreferences(){
Expand Down Expand Up @@ -721,4 +736,4 @@ private void openWebUrl(String url) {
Toast.makeText(getContext(), R.string.warning_unable_to_open_web_url, Toast.LENGTH_LONG).show();
}
}
}
}
46 changes: 43 additions & 3 deletions Android/src/org/droidplanner/android/graphic/map/GraphicDrone.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package org.droidplanner.android.graphic.map;

import android.content.Context;
import android.content.SharedPreferences;
import com.o3dr.services.android.lib.drone.property.Type;
import org.droidplanner.android.R;
import org.droidplanner.android.fragments.SettingsFragment;
import org.droidplanner.android.maps.MarkerInfo;

import android.content.res.Resources;
Expand All @@ -16,11 +20,18 @@
public class GraphicDrone extends MarkerInfo {

private Drone drone;
private SharedPreferences preferences;

public GraphicDrone(Drone drone) {
this.drone = drone;
}

public GraphicDrone(Drone drone, Context context) {
this.drone = drone;
preferences = context.getSharedPreferences
("towerPrefsKey", android.content.Context.MODE_PRIVATE);
}

@Override
public float getAnchorU() {
return 0.5f;
Expand All @@ -39,11 +50,17 @@ public LatLong getPosition() {

@Override
public Bitmap getIcon(Resources res) {
boolean showVehicleSpecificIcons = preferences.getBoolean
(SettingsFragment.VEHICLE_SPECIFIC_ICON_PREF_KEY, false);
if (drone.isConnected()) {
return BitmapFactory.decodeResource(res, R.drawable.quad);
if(showVehicleSpecificIcons) {
Type droneType = drone.getAttribute(AttributeType.TYPE);
return BitmapFactory.decodeResource(res, updateIcon(droneType));
} else {
return BitmapFactory.decodeResource(res, R.drawable.quad);
}
}
return BitmapFactory.decodeResource(res, R.drawable.quad_disconnect);

}

@Override
Expand All @@ -66,4 +83,27 @@ public boolean isValid() {
Gps droneGps = drone.getAttribute(AttributeType.GPS);
return droneGps != null && droneGps.isValid();
}
}

private int updateIcon(Type droneType) {
int drawable;
switch (droneType.getDroneType()) {
case Type.TYPE_COPTER:
drawable = R.drawable.redcopter;
break;

case Type.TYPE_PLANE:
drawable = R.drawable.redplane;
break;

case Type.TYPE_ROVER:
drawable = R.drawable.redrover;
break;

case Type.TYPE_UNKNOWN:
default:
drawable = R.drawable.quad;
break;
}
return drawable;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ public class DroidPlannerPrefs {
public static final String PREF_ENABLE_KILL_SWITCH = "pref_enable_kill_switch";
private static final boolean DEFAULT_ENABLE_KILL_SWITCH = false;

public static final String PREF_ENABLE_VEHICLE_SPECIFIC_ICONS = "pref_enable_vehicle_specific_icons";

public static final String PREF_ENABLE_UDP_PING = "pref_enable_udp_server_ping";
private static final boolean DEFAULT_ENABLE_UDP_PING = false;

Expand Down

0 comments on commit 959112e

Please sign in to comment.