Skip to content
Closed
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
753 changes: 531 additions & 222 deletions app/src/main/java/com/openterface/AOS/activity/MainActivity.java

Large diffs are not rendered by default.

200 changes: 82 additions & 118 deletions app/src/main/java/com/openterface/AOS/drawerLayout/DrawerLayoutDeal.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.openterface.AOS.drawerLayout;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.content.Context;
import android.content.pm.PackageInfo;
Expand All @@ -19,43 +18,42 @@
import android.widget.RadioGroup;
import android.widget.TextView;

import androidx.core.content.ContextCompat;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.openterface.AOS.R;
import com.openterface.AOS.activity.MainActivity;
import com.openterface.AOS.serial.CustomTouchListener;
import com.openterface.AOS.serial.UsbDeviceManager;
import com.openterface.AOS.target.MouseMode;
import com.openterface.AOS.target.MouseModeManager;
import com.openterface.AOS.utils.MouseModePreferences;
import com.openterface.AOS.vnc.VncServerConfig;

public class DrawerLayoutDeal extends Fragment {
/**
* Helper that wires the landscape drawer/settings panel.
* <p>
* This is a plain controller, not a fragment: it is only ever created with
* {@code new} and never handed to a FragmentManager. It used to extend
* Fragment without a no-arg constructor, which would have crashed the moment
* anything did try to restore it through the framework.
*/
public class DrawerLayoutDeal {
private static final String TAG = "OP-UI";
private final MainActivity activity;
private final Context context;
private Bundle savedInstanceState;
private final FloatingActionButton set_up_button;
private final DrawerLayout drawer_layout;

private final Drawable Abs_ctrl_default_button_drawable;
// Mouse mode button drawables
private final Drawable btnAbsoluteDrawable;
private final Drawable btnRelativeDrawable;

private final Drawable Abs_ctrl_drag_button_drawable;

private final Drawable Rel_ctrl_button_drawable;

private final Drawable Abs_ctrl_trackpad_button_drawable;

private boolean KeyMouse_state = false;
private boolean keyMouseAbsCtrlState = false;
private boolean mIsRecording;

private final Button Abs_ctrl_default_button;
private final Button Abs_ctrl_drag_button;
private final Button Rel_ctrl_button;
private final Button Abs_ctrl_trackpad_button;
// Mouse mode buttons
private final Button btnAbsolute;
private final Button btnRelative;
private final Button action_device;
private final Button action_safely_eject;
private final Button action_control;
Expand Down Expand Up @@ -88,17 +86,18 @@ public DrawerLayoutDeal(MainActivity activity , Bundle savedInstanceState, boole
set_up_button = activity.findViewById(R.id.set_up_button);
drawer_layout = activity.findViewById(R.id.drawer_layout);

Abs_ctrl_default_button = activity.findViewById(R.id.Abs_ctrl_default_button);
Abs_ctrl_default_button_drawable = Abs_ctrl_default_button.getCompoundDrawables()[1];
Abs_ctrl_drag_button = activity.findViewById(R.id.Abs_ctrl_drag_button);
Abs_ctrl_drag_button_drawable = Abs_ctrl_drag_button.getCompoundDrawables()[1];
Rel_ctrl_button = activity.findViewById(R.id.Rel_ctrl_button);
Rel_ctrl_button_drawable = Rel_ctrl_button.getCompoundDrawables()[1];
Abs_ctrl_trackpad_button = activity.findViewById(R.id.Abs_ctrl_trackpad_button);
Abs_ctrl_trackpad_button_drawable = Abs_ctrl_trackpad_button.getCompoundDrawables()[1];
// Initialize mouse mode buttons
btnAbsolute = activity.findViewById(R.id.btn_absolute);
btnAbsoluteDrawable = btnAbsolute != null ? btnAbsolute.getCompoundDrawables()[1] : null;
btnRelative = activity.findViewById(R.id.btn_relative);
btnRelativeDrawable = btnRelative != null ? btnRelative.getCompoundDrawables()[1] : null;

Rel_ctrl_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.holo_red_light), PorterDuff.Mode.SRC_IN);
Rel_ctrl_button.setTextColor(ContextCompat.getColor(context,android.R.color.holo_red_light));
// Initialize mouse mode from preferences
MouseMode savedMode = MouseModePreferences.loadMode(context);
boolean trackpadSensitivity = MouseModePreferences.loadTrackpadSensitivity(context);
MouseModeManager.setMode(savedMode);
MouseModeManager.setTrackpadSensitivity(trackpadSensitivity);
updateMouseModeUI();

action_device = activity.findViewById(R.id.action_device);
action_safely_eject = activity.findViewById(R.id.action_safely_eject);
Expand Down Expand Up @@ -130,7 +129,7 @@ public DrawerLayoutDeal(MainActivity activity , Bundle savedInstanceState, boole
String appVersion = packageInfo.versionName;
app_version.setText(appVersion);
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
Log.e(TAG, "Cannot read app version: " + e.getMessage(), e);
app_version.setText(R.string.unknown);
}
CameraVideoDeal();
Expand Down Expand Up @@ -174,99 +173,64 @@ public void onClick(View v) {
}
});

Abs_ctrl_default_button.setOnClickListener(v -> {

if (Abs_ctrl_default_button_drawable != null) {

Abs_ctrl_default_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.holo_red_light), PorterDuff.Mode.SRC_IN);
Abs_ctrl_default_button.setTextColor(ContextCompat.getColor(context,android.R.color.holo_red_light));

Abs_ctrl_drag_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_drag_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Rel_ctrl_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Rel_ctrl_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Abs_ctrl_trackpad_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_trackpad_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

KeyMouse_state = true;
keyMouseAbsCtrlState = false;
CustomTouchListener.KeyMouse_state(KeyMouse_state, keyMouseAbsCtrlState);
CustomTouchListener.setVirtualTrackpadMode(false);

}
});

Abs_ctrl_drag_button.setOnClickListener(v -> {

if (Abs_ctrl_drag_button_drawable != null) {

Abs_ctrl_drag_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.holo_red_light), PorterDuff.Mode.SRC_IN);
Abs_ctrl_drag_button.setTextColor(ContextCompat.getColor(context,android.R.color.holo_red_light));

Abs_ctrl_default_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_default_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Rel_ctrl_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Rel_ctrl_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Abs_ctrl_trackpad_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_trackpad_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

KeyMouse_state = true;
keyMouseAbsCtrlState = true;
CustomTouchListener.KeyMouse_state(KeyMouse_state, keyMouseAbsCtrlState);
CustomTouchListener.setVirtualTrackpadMode(false);

}
});

Rel_ctrl_button.setOnClickListener(v -> {
// Absolute mode button click handler
if (btnAbsolute != null) {
btnAbsolute.setOnClickListener(v -> {
MouseModeManager.setMode(MouseMode.ABSOLUTE);
MouseModePreferences.save(context, MouseMode.ABSOLUTE,
MouseModeManager.isTrackpadSensitivityEnabled());
updateMouseModeUI();
Log.d(TAG, "Switched to absolute mode");
});
}

if (Rel_ctrl_button_drawable != null) {
Log.d(TAG,"in this rel button");
Rel_ctrl_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.holo_red_light), PorterDuff.Mode.SRC_IN);
Rel_ctrl_button.setTextColor(ContextCompat.getColor(context,android.R.color.holo_red_light));
// Relative mode button click handler
if (btnRelative != null) {
btnRelative.setOnClickListener(v -> {
MouseModeManager.setMode(MouseMode.RELATIVE);
MouseModePreferences.save(context, MouseMode.RELATIVE,
MouseModeManager.isTrackpadSensitivityEnabled());
updateMouseModeUI();
Log.d(TAG, "Switched to relative mode");
});
}
}

Abs_ctrl_drag_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_drag_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));
/**
* Update the mouse mode button UI to highlight the selected mode.
* Uses MouseModeManager as the single source of truth.
*/
private void updateMouseModeUI() {
if (btnAbsolute == null || btnRelative == null) {
return;
}

Abs_ctrl_default_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_default_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));
int white = context.getResources().getColor(android.R.color.white);
int highlight = context.getResources().getColor(android.R.color.holo_red_light);

Abs_ctrl_trackpad_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_trackpad_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));
// Reset both buttons to white. The drawables come from the layout and may be
// absent, in which case only the label colour carries the state.
if (btnAbsoluteDrawable != null) {
btnAbsoluteDrawable.setColorFilter(white, PorterDuff.Mode.SRC_IN);
}
btnAbsolute.setTextColor(white);
if (btnRelativeDrawable != null) {
btnRelativeDrawable.setColorFilter(white, PorterDuff.Mode.SRC_IN);
}
btnRelative.setTextColor(white);

KeyMouse_state = false;
keyMouseAbsCtrlState = false;
CustomTouchListener.KeyMouse_state(KeyMouse_state, keyMouseAbsCtrlState);
CustomTouchListener.setVirtualTrackpadMode(false);
// Highlight the active mode
if (MouseModeManager.isAbsoluteMode()) {
if (btnAbsoluteDrawable != null) {
btnAbsoluteDrawable.setColorFilter(highlight, PorterDuff.Mode.SRC_IN);
}
});

Abs_ctrl_trackpad_button.setOnClickListener(v -> {

if (Abs_ctrl_trackpad_button_drawable != null) {
Log.d(TAG,"in this trackpad button");
Abs_ctrl_trackpad_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.holo_red_light), PorterDuff.Mode.SRC_IN);
Abs_ctrl_trackpad_button.setTextColor(ContextCompat.getColor(context,android.R.color.holo_red_light));

Abs_ctrl_default_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_default_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Abs_ctrl_drag_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Abs_ctrl_drag_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

Rel_ctrl_button_drawable.setColorFilter(ContextCompat.getColor(context,android.R.color.white), PorterDuff.Mode.SRC_IN);
Rel_ctrl_button.setTextColor(ContextCompat.getColor(context,android.R.color.white));

KeyMouse_state = false;
keyMouseAbsCtrlState = false;
CustomTouchListener.KeyMouse_state(KeyMouse_state, keyMouseAbsCtrlState);
CustomTouchListener.setVirtualTrackpadMode(true);
btnAbsolute.setTextColor(highlight);
} else {
if (btnRelativeDrawable != null) {
btnRelativeDrawable.setColorFilter(highlight, PorterDuff.Mode.SRC_IN);
}
});
btnRelative.setTextColor(highlight);
}
}

private void CameraVideoDeal(){
Expand Down Expand Up @@ -346,7 +310,7 @@ private void showBaudrateDialog() {
if (currentBaudrate > 0) {
currentText = context.getString(R.string.baudrate_current, String.valueOf(currentBaudrate));
} else {
currentText = "Current: Not connected";
currentText = context.getString(R.string.baudrate_not_connected);
}
currentBaudrateText.setText(currentText);

Expand Down
Loading
Loading