Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add trait navigation to Volume button options #721

Merged
merged 6 commits into from
Sep 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1609,17 +1609,28 @@ private void showSummary() {
public boolean dispatchKeyEvent(KeyEvent event) {
int action = event.getAction();
int keyCode = event.getKeyCode();
String volumeNavigation = ep.getString(GeneralKeys.VOLUME_NAVIGATION, "0");
switch (keyCode) {
case KeyEvent.KEYCODE_VOLUME_UP:
if (ep.getBoolean(GeneralKeys.VOLUME_NAVIGATION, false)) {
if (volumeNavigation.equals("1")) {
if (action == KeyEvent.ACTION_UP) {
traitBox.moveTrait("right");
}
return true;
} else if (volumeNavigation.equals("2")) {
if (action == KeyEvent.ACTION_UP) {
rangeBox.moveEntryRight();
}
return true;
}
return false;
case KeyEvent.KEYCODE_VOLUME_DOWN:
if (ep.getBoolean(GeneralKeys.VOLUME_NAVIGATION, false)) {
if (volumeNavigation.equals("1")) {
if (action == KeyEvent.ACTION_UP) {
traitBox.moveTrait("left");
}
return true;
} else if (volumeNavigation.equals("2")) {
if (action == KeyEvent.ACTION_UP) {
rangeBox.moveEntryLeft();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.Nullable;
import androidx.preference.Preference;
Expand Down Expand Up @@ -49,6 +50,20 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

}

Preference switchVolumePref = this.findPreference(GeneralKeys.VOLUME_NAVIGATION);

if (switchVolumePref != null) {

//set preference change listener to change summary when needed
switchVolumePref.setOnPreferenceChangeListener(this);

//also initialize the summary whenever the fragment is opened, or else it defaults to "disabled"
String switchMode = prefMgr.getSharedPreferences().getString(GeneralKeys.VOLUME_NAVIGATION, "0");

switchVolumePreferenceMode(switchMode, switchVolumePref);

}

((PreferencesActivity) this.getActivity()).getSupportActionBar().setTitle(getString(R.string.preferences_behavior_title));

//add click action on pair rover device to search for bt devices
Expand Down Expand Up @@ -94,15 +109,19 @@ public void onAttach(Context context) {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {


//When the skip entries preference is changed, update the summary that is defined in string.xml.
if (preference.hasKey()) {

if (preference.getKey().equals(GeneralKeys.HIDE_ENTRIES_WITH_DATA)) {

switchSkipPreferenceMode((String) newValue, preference);

} else if (preference.getKey().equals(GeneralKeys.VOLUME_NAVIGATION)) {

switchVolumePreferenceMode((String) newValue, preference);

}

}

return true;
Expand Down Expand Up @@ -138,6 +157,34 @@ private void switchSkipPreferenceMode(String mode, Preference preference) {
}
}

private void switchVolumePreferenceMode(String mode, Preference preference) {

switch (mode) {

case "1": {
preference.setSummary(R.string.preferences_behavior_volume_buttons_navigate_traits_description);

break;

}

case "2": {
preference.setSummary(R.string.preferences_behavior_volume_buttons_navigate_entries_description);

break;

}

default: {

preference.setSummary(R.string.preferences_behavior_volume_buttons_navigate_description);

break;

}
}
}

/**
* Checks if the bluetooth adapter is enabled.
* If the adapter is enabled, checks for all bonded devices that the user has made.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public class GeneralKeys {

// Behavior
public static final String RETURN_CHARACTER = "RETURN_CHARACTER";
public static final String VOLUME_NAVIGATION = "VOLUME_NAVIGATION";
public static final String VOLUME_NAVIGATION = "com.fieldbook.tracker.VOLUME_NAVIGATION";
public static final String CYCLING_TRAITS_ADVANCES = "CycleTraits";
public static final String RETURN_FIRST_TRAIT = "ReturnFirst";
public static final String DISABLE_ENTRY_ARROW_NO_DATA = "DISABLE_ENTRY_ARROW_NO_DATA";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {

Preference moveToUniqueIdPref = this.findPreference(GeneralKeys.MOVE_TO_UNIQUE_ID);

if (skipEntriesPref != null) {
if (moveToUniqueIdPref != null) {

//set preference change listener to change summary when needed
moveToUniqueIdPref.setOnPreferenceChangeListener(this);
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/raw/changelog.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<changelog>

<release
date="2023-08-01"
date="2023-09-13"
versionCode="550"
versionName="v5.5">
<new>New GoPro Trait (Hero 11)</new>
Expand All @@ -10,6 +10,7 @@
<new>Updates available from About</new>
<new>Added Vietnamese and Swedish translations</new>
<new>Added option to return to first trait on entry navigation</new>
<new>Volume buttons can be remapped to move to next trait or plot</new>
<info>Merged barcode and text unique ID search setting</info>
<info>Numerous GeoNav improvements</info>
<info>Merged duplicate settings</info>
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/values/array.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
<item>lockData</item>
</string-array>

<string-array name="pref_remap_volume_buttons">
<item>@string/preferences_behavior_volume_buttons_navigate_disabled</item>
<item>@string/preferences_behavior_volume_buttons_navigate_traits</item>
<item>@string/preferences_behavior_volume_buttons_navigate_entries</item>
</string-array>

<string-array name="pref_remap_volume_buttons_values">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>

<string-array name="pref_return_character">
<item>@string/preferences_behavior_return_character_next_plot</item>
<item>@string/preferences_behavior_return_character_next_trait</item>
Expand Down
12 changes: 9 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -587,12 +587,18 @@
<string name="preferences_behavior_cycle_traits">Cycling traits advances entry</string>
<string name="preferences_behavior_cycle_traits_description">After going through all traits, Field Book goes to the next entry</string>

<string name="preferences_behavior_volume_buttons_navigate">Map volume keys to trait or entry arrows</string>
<string name="preferences_behavior_volume_buttons_navigate_description">Volume keys duplicate selected navigation type</string>
<string name="preferences_behavior_volume_buttons_navigate_traits_description">Volume keys duplicate trait navigation arrows</string>
<string name="preferences_behavior_volume_buttons_navigate_entries_description">Volume keys duplicate entry navigation arrows</string>

<string name="preferences_behavior_volume_buttons_navigate_disabled">Disabled</string>
<string name="preferences_behavior_volume_buttons_navigate_traits">Navigate traits</string>
<string name="preferences_behavior_volume_buttons_navigate_entries">Navigate entries</string>

<string name="preferences_behavior_return_to_first_trait">Advancing entry returns to first trait</string>
<string name="preferences_behavior_return_to_first_trait_description">When moving to the next entry, Field Book also returns to the first trait</string>

<string name="preferences_behavior_volume_buttons_navigate">Map volume keys to entry navigation</string>
<string name="preferences_behavior_volume_buttons_navigate_description">Volume keys go to next or previous entry</string>

<string name="preferences_behavior_return_character">Return key signal</string>
<string name="preferences_behavior_return_character_next_plot">Next plot</string>
<string name="preferences_behavior_return_character_next_trait">Next trait</string>
Expand Down
12 changes: 7 additions & 5 deletions app/src/main/res/xml/preferences_behavior.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,20 @@
android:key="CycleTraits"
android:summary="@string/preferences_behavior_cycle_traits_description"
android:title="@string/preferences_behavior_cycle_traits" />

<CheckBoxPreference
android:defaultValue="false"
android:icon="@drawable/ic_adv_return_first_trait"
android:key="ReturnFirst"
android:summary="@string/preferences_behavior_return_to_first_trait_description"
android:title="@string/preferences_behavior_return_to_first_trait" />

<CheckBoxPreference
android:defaultValue="false"

<ListPreference
android:defaultValue="0"
android:entries="@array/pref_remap_volume_buttons"
android:entryValues="@array/pref_remap_volume_buttons_values"
android:icon="@drawable/ic_remap_volume_buttons"
android:key="VOLUME_NAVIGATION"
android:key="com.fieldbook.tracker.VOLUME_NAVIGATION"
android:summary="@string/preferences_behavior_volume_buttons_navigate_description"
android:title="@string/preferences_behavior_volume_buttons_navigate" />

Expand Down
Loading