Skip to content

Commit

Permalink
Merge pull request #1190 from ne0fhyk/fix_issue_1179
Browse files Browse the repository at this point in the history
Fix issue 1179
  • Loading branch information
m4gr3d committed Oct 21, 2014
2 parents 08c6dc5 + 1a5ada2 commit ab01ae2
Show file tree
Hide file tree
Showing 8 changed files with 92 additions and 34 deletions.
6 changes: 6 additions & 0 deletions Android/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,4 +223,10 @@
<item>No cameras Available</item>
</string-array>

<string-array name="preference_dialog_entry">
<item>@string/pref_dialog_entry_always</item>
<item>@string/pref_dialog_entry_never</item>
<item>@string/pref_dialog_entry_ask</item>
</string-array>

</resources>
4 changes: 4 additions & 0 deletions Android/res/values/preferences_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ This file is used to store the preferences keys so that it's accessible and modi
<string name="pref_dshare_enabled_key">dshare_enabled</string>
<string name="pref_live_upload_enabled_key">pref_live_upload_enabled</string>

<string name="pref_dialogs_key">pref_dialogs</string>
<string name="pref_warn_on_arm_key">pref_warn_on_arm</string>
<string name="pref_auto_insert_mission_takeoff_rtl_land_key">pref_auto_insert_mission_takeoff_rtl_land</string>

<string name="pref_enable_tts_key">pref_enable_tts</string>
<string name="pref_tts_periodic_key">tts_periodic</string>
<string name="pref_tts_periodic_period_key">tts_periodic_status_period</string>
Expand Down
22 changes: 22 additions & 0 deletions Android/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,28 @@
android:key="@string/pref_request_max_volume_key"
android:title="@string/pref_request_max_volume" />
</PreferenceCategory>

<PreferenceCategory android:title="@string/pref_misc_title">
<PreferenceScreen
android:title="@string/pref_dialogs_title"
android:key="@string/pref_dialogs_key">

<ListPreference
android:key="@string/pref_warn_on_arm_key"
android:title="@string/pref_warn_on_arm_title"
android:entries="@array/preference_dialog_entry"
android:entryValues="@array/preference_dialog_entry"
android:defaultValue="@string/pref_dialog_entry_ask"/>

<ListPreference
android:key="@string/pref_auto_insert_mission_takeoff_rtl_land_key"
android:title="@string/pref_auto_insert_mission_takeoff_rtl_land_title"
android:entries="@array/preference_dialog_entry"
android:defaultValue="@string/pref_dialog_entry_ask"
android:entryValues="@array/preference_dialog_entry"/>

</PreferenceScreen>
</PreferenceCategory>
</PreferenceScreen>

<!-- Droneshare preferences section -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ public abstract class SuperUI extends FragmentActivity implements OnDroneListene

public final static String ACTION_TOGGLE_DRONE_CONNECTION = SuperUI.class.getName()
+ ".ACTION_TOGGLE_DRONE_CONNECTION";
private static final String MISSION_UPLOAD_CHECK_DIALOG = "mission_upload_check_dialog";

private ScreenOrientation screenOrientation = new ScreenOrientation(this);
private InfoBarActionProvider infoBar;
Expand Down Expand Up @@ -224,8 +223,11 @@ public void onNo() {
missionProxy.sendMissionToAPM();
}
},
MISSION_UPLOAD_CHECK_DIALOG);
dialog.show(getSupportFragmentManager(), "Mission Upload check.");
getString(R.string.pref_auto_insert_mission_takeoff_rtl_land_key));

if(dialog != null) {
dialog.show(getSupportFragmentManager(), "Mission Upload check.");
}
}
return true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.Preference;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.Toast;

import org.droidplanner.R;
import org.droidplanner.android.utils.prefs.DroidPlannerPrefs;
Expand All @@ -18,10 +19,14 @@
*/
public class YesNoWithPrefsDialog extends YesNoDialog {

private final static int PREFERENCE_ASK_ID = R.string.pref_dialog_entry_ask;
private final static int PREFERENCE_ALWAYS_ID = R.string.pref_dialog_entry_always;
private final static int PREFERENCE_NEVER_ID = R.string.pref_dialog_entry_never;

private final static int DEFAULT_PREFERENCE_ID = PREFERENCE_ASK_ID;

protected final static String EXTRA_PREF_KEY = "extra_dialog_pref_key";

protected final static boolean DEFAULT_DONT_SHOW_DIALOG = false;
private static final boolean DEFAULT_DIALOG_RESPONSE = false;

public static YesNoWithPrefsDialog newInstance(Context context, String title,
String msg, Listener listener, String prefKey) {
Expand All @@ -34,19 +39,19 @@ public static YesNoWithPrefsDialog newInstance(Context context, String title, St
Listener listener, String prefKey){
if (prefKey != null && !prefKey.isEmpty()) {
final DroidPlannerPrefs prefs = new DroidPlannerPrefs(context);
final boolean dontShow = prefs.prefs.getBoolean(getDontShowPrefKey(prefKey),
DEFAULT_DONT_SHOW_DIALOG);
if (dontShow) {
if(listener != null) {
final boolean response = prefs.prefs.getBoolean(getResponsePrefKey(prefKey),
DEFAULT_DIALOG_RESPONSE);
if (response) {
final String preference = prefs.prefs.getString(prefKey,
context.getString(DEFAULT_PREFERENCE_ID));

if(!preference.equals(context.getString(PREFERENCE_ASK_ID))) {
if(listener != null){
if (preference.equals(context.getString(PREFERENCE_ALWAYS_ID))) {
listener.onYes();
}
else{
else if(preference.equals(context.getString(PREFERENCE_NEVER_ID))){
listener.onNo();
}
}

return null;
}
}
Expand Down Expand Up @@ -104,44 +109,44 @@ public void onClick(DialogInterface dialog, int which) {
}

private void savePreferences(final String prefKey, final boolean isPositiveResponse){
final SharedPreferences.Editor editor = mPrefs.prefs.edit();

if(mCheckbox != null) {
editor.putBoolean(getDontShowPrefKey(prefKey), mCheckbox.isChecked());
}
final SharedPreferences.Editor editor = mPrefs.prefs.edit();
if(mCheckbox.isChecked()){
Toast.makeText(getActivity(), R.string.pref_dialog_selection_reset_desc, Toast.LENGTH_LONG).show();
editor.putString(prefKey,
getString(isPositiveResponse ? PREFERENCE_ALWAYS_ID : PREFERENCE_NEVER_ID));
}
else{
editor.putString(prefKey, getString(PREFERENCE_ASK_ID));
}

editor.putBoolean(getResponsePrefKey(prefKey), isPositiveResponse).apply();
editor.apply();
}
}

@Override
protected View generateContentView(Bundle savedInstanceState) {
final View contentView = super.generateContentView(savedInstanceState);
if (contentView == null) {
return contentView;
return null;
}

final String prefKey = getArguments().getString(EXTRA_PREF_KEY);
if (prefKey == null || prefKey.isEmpty()) {
return contentView;
}

final String dontShowPrefKey = getDontShowPrefKey(prefKey);
final boolean isChecked = mPrefs.prefs
.getBoolean(dontShowPrefKey, DEFAULT_DONT_SHOW_DIALOG);

mCheckbox = (CheckBox) contentView.findViewById(R.id.yes_no_dont_show_checkbox);
mCheckbox.setVisibility(View.VISIBLE);
mCheckbox.setChecked(isChecked);
mCheckbox.setChecked(isDontShowEnabled(prefKey));

return contentView;
}

private static String getDontShowPrefKey(String basePrefKey){
return basePrefKey + "_dont_show";
}
private boolean isDontShowEnabled(String prefKey){
final String askSelection = getString(R.string.pref_dialog_entry_ask);
final String preference = mPrefs.prefs.getString(prefKey, askSelection);

private static String getResponsePrefKey(String basePrefKey){
return basePrefKey + "_response";
return !preference.equals(askSelection);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
public class FlightActionsFragment extends Fragment implements OnClickListener, OnDroneListener {

private static final String ACTION_FLIGHT_ACTION_BUTTON = "Flight action button";
private static final String PREF_ARMING_CONFIRMATION_DIALOG = "pref_arming_confirmation_dialog";
private static final double TAKEOFF_ALTITUDE = 10.0;

private Drone drone;
Expand Down Expand Up @@ -234,7 +233,7 @@ public void onYes() {

@Override
public void onNo() {}
}, PREF_ARMING_CONFIRMATION_DIALOG);
}, getString(R.string.pref_warn_on_arm_key));

if(ynd != null) {
ynd.show(getChildFragmentManager(), "Confirm arming");
Expand Down
11 changes: 11 additions & 0 deletions AndroidLib/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -496,4 +496,15 @@
<string name="open_tlog_file">Open Log File</string>
<string name="status_waiting_for_gps">Waiting for GPS...</string>

<!-- Preference dialogs -->
<string name="pref_misc_title">Miscellaneous</string>
<string name="pref_dialogs_title">Preference Dialogs</string>
<string name="pref_warn_on_arm_title">Arming button warning</string>
<string name="pref_auto_insert_mission_takeoff_rtl_land_title">Auto insert \'TakeOff\' and
\'RTL\'/\'Land\' to mission</string>
<string name="pref_dialog_entry_always">Always</string>
<string name="pref_dialog_entry_never">Never</string>
<string name="pref_dialog_entry_ask">Ask</string>
<string name="pref_dialog_selection_reset_desc"><![CDATA[Reset selection through: Settings -> User Interface -> Preference Dialogs]]></string>

</resources>
11 changes: 10 additions & 1 deletion Core/src/org/droidplanner/core/drone/variables/Radio.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package org.droidplanner.core.drone.variables;

import org.droidplanner.core.drone.DroneInterfaces;
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.core.drone.DroneVariable;
import org.droidplanner.core.helpers.math.MathUtil;
import org.droidplanner.core.model.Drone;

public class Radio extends DroneVariable {
public class Radio extends DroneVariable implements DroneInterfaces.OnDroneListener{
public static final int MAX_FADE_MARGIN = 50;
public static final int MIN_FADE_MARGIN = 6;

Expand Down Expand Up @@ -112,4 +113,12 @@ public boolean isValid() {
return isValid;
}

@Override
public void onDroneEvent(DroneEventsType event, Drone drone) {
switch(event){
case DISCONNECTED:
isValid = false;
break;
}
}
}

0 comments on commit ab01ae2

Please sign in to comment.