-
Notifications
You must be signed in to change notification settings - Fork 545
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/videoCapture
- Loading branch information
Showing
93 changed files
with
3,230 additions
and
1,504 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# This workflow will check the python code using black | ||
|
||
name: Python style check | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
paths: | ||
- 'controller/**' | ||
- 'policy/**' | ||
- '.github/workflows/python.yml' | ||
pull_request: | ||
branches: [ master ] | ||
paths: | ||
- 'controller/**' | ||
- 'policy/**' | ||
- '.github/workflows/python.yml' | ||
|
||
jobs: | ||
style-check: | ||
name: Python style check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
- name: Set up python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: 3.7 | ||
- name: Install dependencies | ||
run: | | ||
python -m pip install 'black[jupyter]' | ||
- name: Check style | ||
run: | | ||
black --check . |
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
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
124 changes: 124 additions & 0 deletions
124
android/app/src/main/java/org/openbot/env/ControllerConfig.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,124 @@ | ||
package org.openbot.env; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.util.Log; | ||
import androidx.preference.PreferenceManager; | ||
import org.openbot.utils.ConnectionUtils; | ||
|
||
public class ControllerConfig { | ||
private static ControllerConfig _controllerConfig; | ||
SharedPreferences preferences; | ||
|
||
enum VIDEO_SERVER_TYPE { | ||
WEBRTC, | ||
RTSP | ||
} | ||
|
||
private final boolean isMirrored = true; | ||
private final boolean mute = true; | ||
|
||
private String currentServerType; | ||
|
||
public static ControllerConfig getInstance() { | ||
if (_controllerConfig == null) { | ||
synchronized (PhoneController.class) { | ||
if (_controllerConfig == null) _controllerConfig = new ControllerConfig(); | ||
} | ||
} | ||
|
||
return _controllerConfig; | ||
} | ||
|
||
void init(Context context) { | ||
preferences = PreferenceManager.getDefaultSharedPreferences(context); | ||
currentServerType = get("video_server", "WEBRTC"); | ||
monitorSettingUpdates(); | ||
} | ||
|
||
private void set(String name, String value) { | ||
SharedPreferences.Editor editor = preferences.edit(); | ||
editor.putString(name, value); | ||
editor.apply(); | ||
} | ||
|
||
private String get(String name, String defaultValue) { | ||
try { | ||
return preferences.getString(name, defaultValue); | ||
} catch (ClassCastException e) { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
private Boolean getBoolean(String name, Boolean defaultValue) { | ||
try { | ||
return preferences.getBoolean(name, defaultValue); | ||
} catch (ClassCastException e) { | ||
return defaultValue; | ||
} | ||
} | ||
|
||
private void setBoolean(String name, boolean value) { | ||
SharedPreferences.Editor editor = preferences.edit(); | ||
editor.putBoolean(name, value); | ||
editor.apply(); | ||
} | ||
|
||
// specific settings | ||
public boolean isMirrored() { | ||
return getBoolean("MIRRORED", true); | ||
} | ||
|
||
public void setMirrored(boolean mirrored) { | ||
setBoolean("MIRRORED", mirrored); | ||
} | ||
|
||
public boolean isMute() { | ||
return getBoolean("MUTE", true); | ||
} | ||
|
||
public void setMute(boolean mute) { | ||
setBoolean("MUTE", mute); | ||
} | ||
|
||
public String getVideoServerType() { | ||
return get("video_server", "WEBRTC"); | ||
} | ||
|
||
public void setVideoServerType(String type) { | ||
set("video_server", type); | ||
} | ||
|
||
private void monitorSettingUpdates() { | ||
ControllerToBotEventBus.subscribe( | ||
this.getClass().getSimpleName(), | ||
event -> { | ||
String commandType = event.getString("command"); | ||
|
||
switch (commandType) { | ||
case "TOGGLE_MIRROR": | ||
setMirrored(!isMirrored()); | ||
|
||
// inform the controller of current state | ||
BotToControllerEventBus.emitEvent( | ||
ConnectionUtils.createStatus("TOGGLE_MIRROR", isMirrored())); | ||
break; | ||
|
||
case "TOGGLE_SOUND": | ||
setMute(!isMute()); | ||
|
||
// inform the controller of current state | ||
BotToControllerEventBus.emitEvent( | ||
ConnectionUtils.createStatus("TOGGLE_SOUND", isMute())); | ||
break; | ||
} | ||
}, | ||
error -> { | ||
Log.d(null, "Error occurred in monitorConnection: " + error); | ||
}, | ||
event -> | ||
event.has("command") | ||
&& (event.getString("command").contains("TOGGLE_MIRROR") | ||
|| event.getString("command").contains("TOGGLE_SOUND"))); | ||
} | ||
} |
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
Oops, something went wrong.