Skip to content
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
19 changes: 18 additions & 1 deletion app/src/main/java/com/openipc/pixelpilot/osd/OSDElement.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,29 @@
package com.openipc.pixelpilot.osd;

import android.view.View;

public class OSDElement {
public String name;
public MovableLayout layout;
public MovableLayout layout; // null for a fixed item
public View fixedView; // fixed item, e.g. the centre dot
public boolean defaultEnabled;

public OSDElement(String n, MovableLayout l) {
name = n;
layout = l;
fixedView = null;
defaultEnabled = false;
}

public OSDElement(String n, View fixed, boolean enabledByDefault) {
name = n;
layout = null;
fixedView = fixed;
defaultEnabled = enabledByDefault;
}

public View view() {
return layout != null ? layout : fixedView;
}

public String prefName() {
Expand Down
19 changes: 12 additions & 7 deletions app/src/main/java/com/openipc/pixelpilot/osd/OSDManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public OSDManager(Context context, ActivityVideoBinding binding) {

public void lockOSD(Boolean isLocked) {
for (int i = 0; i < listOSDItems.size(); i++) {
listOSDItems.get(i).layout.setMovable(!isLocked);
MovableLayout layout = listOSDItems.get(i).layout;
if (layout != null) layout.setMovable(!isLocked);
}
osdLocked = isLocked;
}
Expand All @@ -52,8 +53,12 @@ public String getTitle() {
}

public void onOSDItemCheckChanged(OSDElement element, boolean isChecked) {
// Show or hide the ImageView corresponding to the checkbox position
element.layout.setVisibility(isChecked ? View.VISIBLE : View.GONE);
// Show or hide the ImageView corresponding to the checkbox position.
// The centre dot stays hidden in VR mode, where there is no single video view.
boolean show = isChecked && (element.layout != null
|| binding.mainVideoSurface.getVisibility() == View.VISIBLE
|| binding.mainVideo.getVisibility() == View.VISIBLE);
element.view().setVisibility(show ? View.VISIBLE : View.GONE);
SharedPreferences prefs = context.getSharedPreferences("osd_config", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putBoolean(element.prefName() + "_enabled", isChecked);
Expand Down Expand Up @@ -81,6 +86,7 @@ public void onFinish() {
listOSDItems.add(new OSDElement("Battery Air", binding.itemBat));
listOSDItems.add(new OSDElement("Battery Cell Air", binding.itemBatCell));
listOSDItems.add(new OSDElement("Battery GS", binding.itemGSBattery));
listOSDItems.add(new OSDElement("Center Dot", binding.imgCenterDot, true));
listOSDItems.add(new OSDElement("Current", binding.itemCurrent));
listOSDItems.add(new OSDElement("Flight Mode", binding.itemFlightMode));
listOSDItems.add(new OSDElement("Ground Speed", binding.itemGndSpeed));
Expand All @@ -106,14 +112,13 @@ public void onFinish() {

public boolean isElementEnabled(OSDElement elem) {
SharedPreferences prefs = context.getSharedPreferences("osd_config", MODE_PRIVATE);
return prefs.getBoolean(elem.prefName() + "_enabled", false);
return prefs.getBoolean(elem.prefName() + "_enabled", elem.defaultEnabled);
}

public void restoreOSDConfig() {
SharedPreferences prefs = context.getSharedPreferences("osd_config", MODE_PRIVATE);
for (OSDElement element : listOSDItems) {
boolean enabled = prefs.getBoolean(element.prefName() + "_enabled", false);
onOSDItemCheckChanged(element, enabled);
onOSDItemCheckChanged(element, isElementEnabled(element));
if (element.layout == null) continue; // fixed item: no saved position
element.layout.restorePosition(element.prefName());
element.layout.setMovable(!isOSDLocked());
}
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/drawable/osd_center_dot.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Red dot with a dark rim, so it stays visible on bright backgrounds. -->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#FFFF2A2A" />
<stroke
android:width="1dp"
android:color="#99000000" />
<size
android:width="8dp"
android:height="8dp" />
</shape>
14 changes: 14 additions & 0 deletions app/src/main/res/layout/activity_video.xml
Original file line number Diff line number Diff line change
Expand Up @@ -733,4 +733,18 @@
</com.openipc.pixelpilot.osd.MovableLayout>
</FrameLayout>

<!-- Centre dot. Both video views are 16:9 and centred in the parent, so the
parent's centre is the video centre. Not movable. -->
<View
android:id="@+id/imgCenterDot"
android:layout_width="8dp"
android:layout_height="8dp"
android:background="@drawable/osd_center_dot"
android:translationZ="16dp"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>
Loading