Skip to content

Settings screen #57

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

Merged
merged 3 commits into from
May 21, 2021
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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ dependencies {
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
implementation 'com.google.android.exoplayer:exoplayer:2.13.3'
implementation 'io.sentry:sentry-android:4.3.0'
implementation 'androidx.preference:preference:1.1.1'

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@
android:name=".DataCollectionAgreementPopupActivity"
android:label="@string/title_activity_data_collection"
android:theme="@style/Theme.AppCompat.Dialog"></activity>
<activity
android:name=".SettingsActivity"
android:label="@string/title_activity_settings"></activity>

<activity
android:launchMode="singleTask"
android:name="com.fpvout.digiview.MainActivity"
Expand Down
106 changes: 78 additions & 28 deletions app/src/main/java/com/fpvout/digiview/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,23 @@

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceManager;

import java.util.HashMap;

import io.sentry.SentryLevel;
import io.sentry.android.core.SentryAndroid;

import static com.fpvout.digiview.VideoReaderExoplayer.VideoZoomedIn;

public class MainActivity extends AppCompatActivity implements UsbDeviceListener {
private static final String ACTION_USB_PERMISSION = "com.fpvout.digiview.USB_PERMISSION";
private static final String TAG = "DIGIVIEW";
private static final int VENDOR_ID = 11427;
private static final int PRODUCT_ID = 31;
private int shortAnimationDuration;
private boolean watermarkAnimationInProgress = false;
private float buttonAlpha = 1;
private View settingsButton;
private View watermarkView;
private OverlayView overlayView;
PendingIntent permissionIntent;
Expand All @@ -47,6 +51,8 @@ public class MainActivity extends AppCompatActivity implements UsbDeviceListener
SurfaceView fpvView;
private GestureDetector gestureDetector;
private ScaleGestureDetector scaleGestureDetector;
private SharedPreferences sharedPreferences;
private static final String ShowWatermark = "ShowWatermark";

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -87,15 +93,39 @@ protected void onCreate(Bundle savedInstanceState) {
overlayView = findViewById(R.id.overlayView);
fpvView = findViewById(R.id.fpvView);

settingsButton = findViewById(R.id.settingsButton);
settingsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), SettingsActivity.class);
v.getContext().startActivity(intent);
}
});

sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

// Enable resizing animations
((ViewGroup) findViewById(R.id.mainLayout)).getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);

setupGestureDetectors();

mUsbMaskConnection = new UsbMaskConnection();
mVideoReader = new VideoReaderExoplayer(fpvView, overlayView, this);

if (!usbConnected) {
if (searchDevice()) {
connect();
} else {
overlayView.showOpaque(R.string.waiting_for_usb_device, OverlayStatus.Disconnected);
}
}
}

private void setupGestureDetectors() {
gestureDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() {
@Override
public boolean onSingleTapConfirmed(MotionEvent e) {
if (watermarkView.getVisibility() == View.VISIBLE) {
toggleWatermark();
}
toggleSettingsButton();
return super.onSingleTapConfirmed(e);
}

Expand All @@ -116,19 +146,6 @@ public void onScaleEnd(ScaleGestureDetector detector) {
}
}
});

watermarkView.setVisibility(View.GONE);

mUsbMaskConnection = new UsbMaskConnection();
mVideoReader = new VideoReaderExoplayer(fpvView, overlayView, this);

if (!usbConnected) {
if (searchDevice()) {
connect();
} else {
overlayView.showOpaque(R.string.waiting_for_usb_device, OverlayStatus.Disconnected);
}
}
}

@Override
Expand All @@ -139,28 +156,57 @@ public boolean onTouchEvent(MotionEvent event) {
return super.onTouchEvent(event);
}

private void toggleWatermark() {
if (watermarkAnimationInProgress) {
return;
private void updateWatermark() {
if (sharedPreferences.getBoolean(ShowWatermark, true)) {
watermarkView.setAlpha(0.3F);
} else {
watermarkView.setAlpha(0F);
}
watermarkAnimationInProgress = true;
}

float targetAlpha = 0;
if (watermarkView.getAlpha() == 0) {
targetAlpha = 0.3F;
private void updateVideoZoom() {
if (sharedPreferences.getBoolean(VideoZoomedIn, true)) {
mVideoReader.zoomIn();
} else {
mVideoReader.zoomOut();
}
}

private void toggleSettingsButton() {
// cancel any pending delayed animations first
settingsButton.getHandler().removeCallbacksAndMessages(null);

watermarkView.animate()
.alpha(targetAlpha)
if (buttonAlpha == 1) {
buttonAlpha = 0;
} else {
buttonAlpha = 1;
}

settingsButton.animate()
.alpha(buttonAlpha)
.setDuration(shortAnimationDuration)
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
watermarkAnimationInProgress = false;
autoHideSettingsButton();
}
});
}

private void autoHideSettingsButton() {
if (buttonAlpha == 0) return;

settingsButton.postDelayed(new Runnable() {
@Override
public void run() {
buttonAlpha = 0;
settingsButton.animate()
.alpha(0)
.setDuration(shortAnimationDuration);
}
}, 3000);
}

@Override
public void usbDeviceApproved(UsbDevice device) {
Log.i(TAG, "USB - usbDevice approved");
Expand Down Expand Up @@ -203,7 +249,6 @@ private void connect() {
usbConnected = true;
mUsbMaskConnection.setUsbDevice(usbManager.openDevice(usbDevice), usbDevice);
mVideoReader.setUsbMaskConnection(mUsbMaskConnection);
watermarkView.setVisibility(View.VISIBLE);
overlayView.hide();
mVideoReader.start();
}
Expand All @@ -221,6 +266,11 @@ public void onResume() {
overlayView.showOpaque(R.string.waiting_for_usb_device, OverlayStatus.Disconnected);
}
}

settingsButton.setAlpha(1);
autoHideSettingsButton();
updateWatermark();
updateVideoZoom();
}

@Override
Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/com/fpvout/digiview/SettingsActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.fpvout.digiview;

import android.os.Bundle;
import android.view.MenuItem;

import androidx.annotation.NonNull;
import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
import androidx.preference.PreferenceFragmentCompat;

public class SettingsActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings_activity);
if (savedInstanceState == null) {
getSupportFragmentManager()
.beginTransaction()
.replace(R.id.settings, new SettingsFragment())
.commit();
}
ActionBar actionBar = getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
}
}

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {

if (item.getItemId() == android.R.id.home) {
this.finish();
return true;
}

return super.onOptionsItemSelected(item);
}

public static class SettingsFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
setPreferencesFromResource(R.xml.root_preferences, rootKey);
}
}
}
28 changes: 28 additions & 0 deletions app/src/main/java/com/fpvout/digiview/VersionPreference.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.fpvout.digiview;

import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.util.AttributeSet;

import androidx.preference.Preference;

// From https://stackoverflow.com/a/20157577/877465
public class VersionPreference extends Preference {
public VersionPreference(Context context, AttributeSet attrs) {
super(context, attrs);
String versionName;
final PackageManager packageManager = context.getPackageManager();
if (packageManager != null) {
try {
PackageInfo packageInfo = packageManager.getPackageInfo(context.getPackageName(), 0);
versionName = packageInfo.versionName;
} catch (PackageManager.NameNotFoundException e) {
versionName = null;
}
setSummary(versionName);
}

setSelectable(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.view.SurfaceView;

import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.preference.PreferenceManager;

import com.google.android.exoplayer2.C;
import com.google.android.exoplayer2.DefaultLoadControl;
Expand Down Expand Up @@ -39,13 +40,13 @@ public class VideoReaderExoplayer {
private boolean zoomedIn;
private SharedPreferences sharedPreferences;
private PerformancePreset performancePreset = PerformancePreset.getPreset(PerformancePreset.PresetType.DEFAULT);
private static final String VideoZoomedIn = "VideoZoomedIn";
static final String VideoZoomedIn = "VideoZoomedIn";

VideoReaderExoplayer(SurfaceView videoSurface, OverlayView overlayView, Context c) {
surfaceView = videoSurface;
this.overlayView = overlayView;
context = c;
sharedPreferences = context.getSharedPreferences("DigiView", Context.MODE_PRIVATE);
sharedPreferences = PreferenceManager.getDefaultSharedPreferences(c);
}

VideoReaderExoplayer(SurfaceView videoSurface, OverlayView overlayView, Context c, PerformancePreset p) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,15 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/settingsButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="25dp"
android:layout_marginTop="25dp"
android:clickable="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:srcCompat="@drawable/exo_ic_settings" />

</androidx.constraintlayout.widget.ConstraintLayout>
9 changes: 9 additions & 0 deletions app/src/main/res/layout/settings_activity.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<FrameLayout
android:id="@+id/settings"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
14 changes: 7 additions & 7 deletions app/src/main/res/values-night/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
<!-- Base application theme. -->
<style name="Theme.Digiview" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_200</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/black</item>
<item name="colorPrimary">@color/digiview_blue</item>
<item name="colorPrimaryVariant">@color/digiview_blue_variant</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_200</item>
<item name="colorOnSecondary">@color/black</item>
<item name="colorSecondary">@color/digiview_purple</item>
<item name="colorSecondaryVariant">@color/digiview_purple_variant</item>
<item name="colorOnSecondary">@color/white</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorSecondary</item>
<!-- Customize your theme here. -->
</style>
</resources>
16 changes: 16 additions & 0 deletions app/src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>
<!-- Reply Preference -->
<string-array name="video_preset_titles">
<item>@string/video_preset_default</item>
<item>@string/video_preset_conservative</item>
<item>@string/video_preset_aggressive</item>
<item>@string/video_preset_legacy</item>
</string-array>

<string-array name="video_preset_values">
<item>default</item>
<item>conservative</item>
<item>aggressive</item>
<item>legacy</item>
</string-array>
</resources>
9 changes: 2 additions & 7 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="purple_200">#FFBB86FC</color>
<color name="purple_500">#FF6200EE</color>
<color name="purple_700">#FF3700B3</color>
<color name="teal_200">#FF03DAC5</color>
<color name="teal_700">#FF018786</color>
<color name="black">#FF000000</color>
<color name="shadow">#80000000</color>
<color name="white">#FFFFFFFF</color>
<color name="digiview_blue">#4776e6</color>
<color name="digiview_blue_variant">#5A6CE6</color>
<color name="digiview_purple">#8e54e9</color>


<color name="digiview_purple_variant">#7C5CE8</color>
</resources>
Loading