Skip to content

Commit

Permalink
fix: Launching editor from notification
Browse files Browse the repository at this point in the history
  • Loading branch information
Xtr126 committed Aug 1, 2024
1 parent b3b96c7 commit 985bed4
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 38 deletions.
34 changes: 1 addition & 33 deletions app/src/main/java/xtr/keymapper/TouchPointer.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,9 @@
import android.widget.Toast;

import androidx.annotation.UiThread;
import androidx.appcompat.view.ContextThemeWrapper;

import xtr.keymapper.activity.MainActivity;
import xtr.keymapper.editor.EditorService;
import xtr.keymapper.editor.EditorUI;
import xtr.keymapper.keymap.KeymapConfig;
import xtr.keymapper.keymap.KeymapProfile;
import xtr.keymapper.keymap.KeymapProfiles;
Expand All @@ -41,7 +39,6 @@ public class TouchPointer extends Service {
public String selectedProfile = null;
private final Handler mHandler = new Handler(Looper.getMainLooper());
private boolean activityRemoteCallback = false;
private EditorUI editor;


public class TouchPointerBinder extends Binder {
Expand Down Expand Up @@ -158,23 +155,6 @@ public void onDestroy() {
super.onDestroy();
}

private final EditorUI.OnHideListener onHideListener = new EditorUI.OnHideListener() {
@Override
public void onHideView() {
try {
mService.unregisterOnKeyEventListener(editor);
mService.resumeMouse();
} catch (RemoteException ignored) {
}
editor = null;
}

@Override
public boolean getEvent() {
return true;
}
};

/**
* This implementation is used to receive callbacks from the remote
* service.
Expand All @@ -183,19 +163,7 @@ public boolean getEvent() {

@Override
public void launchEditor() {
mHandler.post(() -> {
Context context = new ContextThemeWrapper(TouchPointer.this, R.style.Theme_XtMapper);
editor = new EditorUI(context, onHideListener, selectedProfile);

try {
mService.registerOnKeyEventListener(editor);
mService.pauseMouse();
} catch (RemoteException e) {
Log.e("editorActivity", e.getMessage(), e);
}

editor.open(true);
});
startService(new Intent(TouchPointer.this, EditorService.class));
}

@Override
Expand Down
49 changes: 45 additions & 4 deletions app/src/main/java/xtr/keymapper/editor/EditorService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,44 @@
import android.content.ServiceConnection;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;

import androidx.appcompat.view.ContextThemeWrapper;

import xtr.keymapper.R;
import xtr.keymapper.TouchPointer;
import xtr.keymapper.server.RemoteServiceHelper;

public class EditorService extends Service {
private EditorUI editor;

private final EditorUI.OnHideListener onHideListener = new EditorUI.OnHideListener() {
@Override
public void onHideView() {
RemoteServiceHelper.getInstance(EditorService.this, service -> {
try {
service.unregisterOnKeyEventListener(editor);
service.resumeMouse();
} catch (RemoteException e) {
throw new RuntimeException(e);
}
});
editor = null;
stopSelf();
}

@Override
public boolean getEvent() {
return true;
}
};


@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.i(this.getClass().getName(), "Launching editor");
bindService(new Intent(this, TouchPointer.class), connection, Context.BIND_AUTO_CREATE);

return super.onStartCommand(intent, flags, startId);
}

Expand All @@ -25,10 +56,20 @@ public void onServiceConnected(ComponentName className,
// We've bound to Service, cast the IBinder and get TouchPointer instance
TouchPointer.TouchPointerBinder binder = (TouchPointer.TouchPointerBinder) service;
TouchPointer pointerOverlay = binder.getService();
try {
if (pointerOverlay.mService != null) pointerOverlay.mCallback.launchEditor();
} catch (RemoteException ignored) {
}

Context context = new ContextThemeWrapper(EditorService.this, R.style.Theme_XtMapper);
editor = new EditorUI(context, onHideListener, pointerOverlay.selectedProfile);

RemoteServiceHelper.getInstance(EditorService.this, remoteService -> {
try {
remoteService.registerOnKeyEventListener(editor);
remoteService.pauseMouse();
} catch (RemoteException e) {
Log.e("editorActivity", e.getMessage(), e);
}
});

editor.open(true);
}
@Override
public void onServiceDisconnected(ComponentName arg0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void onServiceDisconnected(ComponentName name) {
}
}

public static void getInstance(){
private static void getInstance(){
if (service == null) {
// Try tcpip connection first
try {
Expand Down

0 comments on commit 985bed4

Please sign in to comment.