-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 'switch to map page' button option (#65)
* Add virtual karoo key; Add switch to map page hook * Add option to switch to map page * Remove empty line * Removed call to new api
- Loading branch information
Showing
6 changed files
with
253 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/valterc/ki2/input/VirtualInputAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.valterc.ki2.input; | ||
|
||
import android.annotation.SuppressLint; | ||
import android.util.Log; | ||
|
||
import com.valterc.ki2.data.input.KarooKey; | ||
import com.valterc.ki2.data.input.KarooKeyEvent; | ||
import com.valterc.ki2.karoo.hooks.RideActivityHook; | ||
|
||
import java.util.HashMap; | ||
import java.util.function.Consumer; | ||
|
||
@SuppressLint("LogNotTimber") | ||
public class VirtualInputAdapter { | ||
|
||
private final HashMap<KarooKey, Consumer<KarooKeyEvent>> keyMapping; | ||
|
||
public VirtualInputAdapter() { | ||
this.keyMapping = new HashMap<>(); | ||
this.keyMapping.put(KarooKey.VIRTUAL_SWITCH_TO_MAP_PAGE, karooKeyEvent -> { | ||
boolean result = RideActivityHook.switchToMapPage(); | ||
if (!result) { | ||
Log.w("KI2", "Unable to switch to map page"); | ||
} | ||
}); | ||
} | ||
|
||
public void handleVirtualKeyEvent(KarooKeyEvent keyEvent) { | ||
if (!keyEvent.getKey().isVirtual()) { | ||
return; | ||
} | ||
|
||
Consumer<KarooKeyEvent> keyEventConsumer = keyMapping.get(keyEvent.getKey()); | ||
if (keyEventConsumer != null) { | ||
keyEventConsumer.accept(keyEvent); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters