mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-25 19:37:25 +00:00
Use lambdas where possible
Summary: Let Android Studio replace anonymous types with lambdas. No manual code change. Test Plan: Compile and superficial behaviour test Reviewers: #kde_connect, philipc Reviewed By: #kde_connect, philipc Subscribers: philipc, #kde_connect Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D12229
This commit is contained in:
parent
7536eb7427
commit
e712c69e15
@ -23,10 +23,8 @@ android {
|
|||||||
javaMaxHeapSize "2g"
|
javaMaxHeapSize "2g"
|
||||||
}
|
}
|
||||||
compileOptions {
|
compileOptions {
|
||||||
// Use Java 1.7, requires minSdk 8
|
sourceCompatibility JavaVersion.VERSION_1_8
|
||||||
//SSHD requires mina when running on JDK < 7
|
targetCompatibility JavaVersion.VERSION_1_8
|
||||||
sourceCompatibility JavaVersion.VERSION_1_7
|
|
||||||
targetCompatibility JavaVersion.VERSION_1_7
|
|
||||||
}
|
}
|
||||||
sourceSets {
|
sourceSets {
|
||||||
main {
|
main {
|
||||||
|
@ -89,9 +89,7 @@ public class LanLink extends BaseLink {
|
|||||||
|
|
||||||
//Log.e("LanLink", "Start listening");
|
//Log.e("LanLink", "Start listening");
|
||||||
//Create a thread to take care of incoming data for the new socket
|
//Create a thread to take care of incoming data for the new socket
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8));
|
BufferedReader reader = new BufferedReader(new InputStreamReader(newSocket.getInputStream(), StringsHelper.UTF8));
|
||||||
while (true) {
|
while (true) {
|
||||||
@ -118,7 +116,6 @@ public class LanLink extends BaseLink {
|
|||||||
callback.linkDisconnected(LanLink.this);
|
callback.linkDisconnected(LanLink.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
return oldSocket;
|
return oldSocket;
|
||||||
|
@ -221,24 +221,19 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
|
|
||||||
if (isDeviceTrusted && !SslHelper.isCertificateStored(context, deviceId)) {
|
if (isDeviceTrusted && !SslHelper.isCertificateStored(context, deviceId)) {
|
||||||
//Device paired with and old version, we can't use it as we lack the certificate
|
//Device paired with and old version, we can't use it as we lack the certificate
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
if (device == null) return;
|
if (device == null) return;
|
||||||
device.unpair();
|
device.unpair();
|
||||||
//Retry as unpaired
|
//Retry as unpaired
|
||||||
identityPacketReceived(identityPacket, socket, connectionStarted);
|
identityPacketReceived(identityPacket, socket, connectionStarted);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Log.i("KDE/LanLinkProvider", "Starting SSL handshake with " + identityPacket.getString("deviceName") + " trusted:" + isDeviceTrusted);
|
Log.i("KDE/LanLinkProvider", "Starting SSL handshake with " + identityPacket.getString("deviceName") + " trusted:" + isDeviceTrusted);
|
||||||
|
|
||||||
final SSLSocket sslsocket = SslHelper.convertToSslSocket(context, socket, deviceId, isDeviceTrusted, clientMode);
|
final SSLSocket sslsocket = SslHelper.convertToSslSocket(context, socket, deviceId, isDeviceTrusted, clientMode);
|
||||||
sslsocket.addHandshakeCompletedListener(new HandshakeCompletedListener() {
|
sslsocket.addHandshakeCompletedListener(event -> {
|
||||||
@Override
|
|
||||||
public void handshakeCompleted(HandshakeCompletedEvent event) {
|
|
||||||
String mode = clientMode ? "client" : "server";
|
String mode = clientMode ? "client" : "server";
|
||||||
try {
|
try {
|
||||||
Certificate certificate = event.getPeerCertificates()[0];
|
Certificate certificate = event.getPeerCertificates()[0];
|
||||||
@ -248,21 +243,15 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
Log.e("KDE/LanLinkProvider", "Handshake as " + mode + " failed with " + identityPacket.getString("deviceName"));
|
Log.e("KDE/LanLinkProvider", "Handshake as " + mode + " failed with " + identityPacket.getString("deviceName"));
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
if (device == null) return;
|
if (device == null) return;
|
||||||
device.unpair();
|
device.unpair();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
//Handshake is blocking, so do it on another thread and free this thread to keep receiving new connection
|
//Handshake is blocking, so do it on another thread and free this thread to keep receiving new connection
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
sslsocket.startHandshake();
|
sslsocket.startHandshake();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -274,7 +263,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
// Log.i("SupportedCiphers","cipher: " + cipher);
|
// Log.i("SupportedCiphers","cipher: " + cipher);
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
} else {
|
} else {
|
||||||
addLink(identityPacket, socket, connectionStarted);
|
addLink(identityPacket, socket, connectionStarted);
|
||||||
@ -331,9 +319,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (listening) {
|
while (listening) {
|
||||||
final int bufferSize = 1024 * 512;
|
final int bufferSize = 1024 * 512;
|
||||||
byte[] data = new byte[bufferSize];
|
byte[] data = new byte[bufferSize];
|
||||||
@ -347,7 +333,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.w("UdpListener", "Stopping UDP listener");
|
Log.w("UdpListener", "Stopping UDP listener");
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
return server;
|
return server;
|
||||||
}
|
}
|
||||||
@ -356,9 +341,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
tcpServer = openServerSocketOnFreePort(MIN_PORT);
|
tcpServer = openServerSocketOnFreePort(MIN_PORT);
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
while (listening) {
|
while (listening) {
|
||||||
try {
|
try {
|
||||||
Socket socket = tcpServer.accept();
|
Socket socket = tcpServer.accept();
|
||||||
@ -370,7 +353,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.w("TcpListener", "Stopping TCP listener");
|
Log.w("TcpListener", "Stopping TCP listener");
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -401,9 +383,7 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(CustomDevicesActivity.KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
String deviceListPrefs = PreferenceManager.getDefaultSharedPreferences(context).getString(CustomDevicesActivity.KEY_CUSTOM_DEVLIST_PREFERENCE, "");
|
||||||
ArrayList<String> iplist = new ArrayList<>();
|
ArrayList<String> iplist = new ArrayList<>();
|
||||||
@ -445,7 +425,6 @@ public class LanLinkProvider extends BaseLinkProvider implements LanLink.LinkDis
|
|||||||
socket.close();
|
socket.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,24 +87,18 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void addGuiInUseCounter(final Context activity, final boolean forceNetworkRefresh) {
|
public static void addGuiInUseCounter(final Context activity, final boolean forceNetworkRefresh) {
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
boolean refreshed = service.acquireDiscoveryMode(activity);
|
boolean refreshed = service.acquireDiscoveryMode(activity);
|
||||||
if (!refreshed && forceNetworkRefresh) {
|
if (!refreshed && forceNetworkRefresh) {
|
||||||
service.onNetworkChange();
|
service.onNetworkChange();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void removeGuiInUseCounter(final Context activity) {
|
public static void removeGuiInUseCounter(final Context activity) {
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
//If no user interface is open, close the connections open to other devices
|
//If no user interface is open, close the connections open to other devices
|
||||||
service.releaseDiscoveryMode(activity);
|
service.releaseDiscoveryMode(activity);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -167,15 +161,12 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void cleanDevices() {
|
private void cleanDevices() {
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
for (Device d : devices.values()) {
|
for (Device d : devices.values()) {
|
||||||
if (!d.isPaired() && !d.isPairRequested() && !d.isPairRequestedByPeer() && !d.deviceShouldBeKeptAlive()) {
|
if (!d.isPaired() && !d.isPairRequested() && !d.isPairRequestedByPeer() && !d.deviceShouldBeKeptAlive()) {
|
||||||
d.disconnect();
|
d.disconnect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -328,9 +319,7 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void RunCommand(final Context c, final InstanceCallback callback) {
|
public static void RunCommand(final Context c, final InstanceCallback callback) {
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (callback != null) {
|
if (callback != null) {
|
||||||
mutex.lock();
|
mutex.lock();
|
||||||
try {
|
try {
|
||||||
@ -341,7 +330,6 @@ public class BackgroundService extends Service {
|
|||||||
}
|
}
|
||||||
Intent serviceIntent = new Intent(c, BackgroundService.class);
|
Intent serviceIntent = new Intent(c, BackgroundService.class);
|
||||||
c.startService(serviceIntent);
|
c.startService(serviceIntent);
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -638,12 +638,7 @@ public class Device implements BaseLink.PacketReceiver {
|
|||||||
|
|
||||||
//Async
|
//Async
|
||||||
public void sendPacket(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
public void sendPacket(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> sendPacketBlocking(np, callback)).start();
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
sendPacketBlocking(np, callback);
|
|
||||||
}
|
|
||||||
}).start();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean sendPacketBlocking(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
public boolean sendPacketBlocking(final NetworkPacket np, final SendPacketStatusCallback callback) {
|
||||||
|
@ -43,41 +43,27 @@ public class KdeConnectBroadcastReceiver extends BroadcastReceiver {
|
|||||||
Log.i("KdeConnect", "Ignoring, it's not me!");
|
Log.i("KdeConnect", "Ignoring, it's not me!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_BOOT_COMPLETED:
|
case Intent.ACTION_BOOT_COMPLETED:
|
||||||
Log.i("KdeConnect", "KdeConnectBroadcastReceiver");
|
Log.i("KdeConnect", "KdeConnectBroadcastReceiver");
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION:
|
case WifiManager.SUPPLICANT_CONNECTION_CHANGE_ACTION:
|
||||||
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
case WifiManager.WIFI_STATE_CHANGED_ACTION:
|
||||||
case ConnectivityManager.CONNECTIVITY_ACTION:
|
case ConnectivityManager.CONNECTIVITY_ACTION:
|
||||||
Log.i("KdeConnect", "Connection state changed, trying to connect");
|
Log.i("KdeConnect", "Connection state changed, trying to connect");
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.onDeviceListChanged();
|
service.onDeviceListChanged();
|
||||||
service.onNetworkChange();
|
service.onNetworkChange();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case Intent.ACTION_SCREEN_ON:
|
case Intent.ACTION_SCREEN_ON:
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, BackgroundService::onNetworkChange);
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Log.i("BroadcastReceiver", "Ignoring broadcast event: " + intent.getAction());
|
Log.i("BroadcastReceiver", "Ignoring broadcast event: " + intent.getAction());
|
||||||
|
@ -69,13 +69,9 @@ public class ClipboardListener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
new Handler(Looper.getMainLooper()).post(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
cm = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
|
||||||
listener = new ClipboardManager.OnPrimaryClipChangedListener() {
|
listener = () -> {
|
||||||
@Override
|
|
||||||
public void onPrimaryClipChanged() {
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
ClipData.Item item = cm.getPrimaryClip().getItemAt(0);
|
||||||
@ -94,10 +90,8 @@ public class ClipboardListener {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
//Probably clipboard was not text
|
//Probably clipboard was not text
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
cm.addPrimaryClipChangedListener(listener);
|
cm.addPrimaryClipChangedListener(listener);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,13 +53,10 @@ public class ClipboardPlugin extends Plugin {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ClipboardListener.ClipboardObserver observer = new ClipboardListener.ClipboardObserver() {
|
private ClipboardListener.ClipboardObserver observer = content -> {
|
||||||
@Override
|
|
||||||
public void clipboardChanged(String content) {
|
|
||||||
NetworkPacket np = new NetworkPacket(ClipboardPlugin.PACKET_TYPE_CLIPBOARD);
|
NetworkPacket np = new NetworkPacket(ClipboardPlugin.PACKET_TYPE_CLIPBOARD);
|
||||||
np.set("content", content);
|
np.set("content", content);
|
||||||
device.sendPacket(np);
|
device.sendPacket(np);
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -67,12 +67,7 @@ public class FindMyPhoneActivity extends Activity {
|
|||||||
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED |
|
||||||
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
|
||||||
|
|
||||||
findViewById(R.id.bFindMyPhone).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.bFindMyPhone).setOnClickListener(view -> finish());
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -109,14 +109,11 @@ public class KeyListenerView extends View {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendKeyPressPacket(final NetworkPacket np) {
|
private void sendKeyPressPacket(final NetworkPacket np) {
|
||||||
BackgroundService.RunCommand(getContext(), new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(getContext(), service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendKeyboardPacket(np);
|
mousePadPlugin.sendKeyboardPacket(np);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,9 +135,7 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
|
||||||
final View decorView = getWindow().getDecorView();
|
final View decorView = getWindow().getDecorView();
|
||||||
decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
|
decorView.setOnSystemUiVisibilityChangeListener(visibility -> {
|
||||||
@Override
|
|
||||||
public void onSystemUiVisibilityChange(int visibility) {
|
|
||||||
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
|
||||||
|
|
||||||
int fullscreenType = 0;
|
int fullscreenType = 0;
|
||||||
@ -156,7 +154,6 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
getWindow().getDecorView().setSystemUiVisibility(fullscreenType);
|
getWindow().getDecorView().setSystemUiVisibility(fullscreenType);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -214,16 +211,13 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
case MotionEvent.ACTION_MOVE:
|
case MotionEvent.ACTION_MOVE:
|
||||||
mCurrentX = event.getX();
|
mCurrentX = event.getX();
|
||||||
mCurrentY = event.getY();
|
mCurrentY = event.getY();
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY, mCurrentSensitivity);
|
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY, mCurrentSensitivity);
|
||||||
mPrevX = mCurrentX;
|
mPrevX = mCurrentX;
|
||||||
mPrevY = mCurrentY;
|
mPrevY = mCurrentY;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -287,14 +281,11 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
getWindow().getDecorView().performHapticFeedback(HapticFeedbackConstants.VIRTUAL_KEY);
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleHold();
|
mousePadPlugin.sendSingleHold();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -305,28 +296,22 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onSingleTapConfirmed(MotionEvent e) {
|
public boolean onSingleTapConfirmed(MotionEvent e) {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleClick();
|
mousePadPlugin.sendSingleClick();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onDoubleTap(MotionEvent e) {
|
public boolean onDoubleTap(MotionEvent e) {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendDoubleClick();
|
mousePadPlugin.sendDoubleClick();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -366,50 +351,38 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
|
|||||||
|
|
||||||
|
|
||||||
private void sendMiddleClick() {
|
private void sendMiddleClick() {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendMiddleClick();
|
mousePadPlugin.sendMiddleClick();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendRightClick() {
|
private void sendRightClick() {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendRightClick();
|
mousePadPlugin.sendRightClick();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendSingleHold() {
|
private void sendSingleHold() {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendSingleHold();
|
mousePadPlugin.sendSingleHold();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sendScroll(final float y) {
|
private void sendScroll(final float y) {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
|
||||||
if (mousePadPlugin == null) return;
|
if (mousePadPlugin == null) return;
|
||||||
mousePadPlugin.sendScroll(0, y);
|
mousePadPlugin.sendScroll(0, y);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,9 +78,7 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
protected void connectToPlugin(final String targetPlayerName) {
|
protected void connectToPlugin(final String targetPlayerName) {
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
final MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
final MprisPlugin mpris = device.getPlugin(MprisPlugin.class);
|
||||||
@ -93,12 +91,7 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
mpris.setPlayerStatusUpdatedHandler("activity", new Handler() {
|
mpris.setPlayerStatusUpdatedHandler("activity", new Handler() {
|
||||||
@Override
|
@Override
|
||||||
public void handleMessage(Message msg) {
|
public void handleMessage(Message msg) {
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> updatePlayerStatus(mpris));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
updatePlayerStatus(mpris);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -112,9 +105,7 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
);
|
);
|
||||||
|
|
||||||
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
Spinner spinner = (Spinner) findViewById(R.id.player_spinner);
|
Spinner spinner = (Spinner) findViewById(R.id.player_spinner);
|
||||||
//String prevPlayer = (String)spinner.getSelectedItem();
|
//String prevPlayer = (String)spinner.getSelectedItem();
|
||||||
spinner.setAdapter(adapter);
|
spinner.setAdapter(adapter);
|
||||||
@ -171,12 +162,10 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
spinner.setSelection(0);
|
spinner.setSelection(0);
|
||||||
}
|
}
|
||||||
updatePlayerStatus(mpris);
|
updatePlayerStatus(mpris);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -196,12 +185,7 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
@Override
|
@Override
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MprisActivity.this, service -> service.removeConnectionListener(connectionReceiver));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.removeConnectionListener(connectionReceiver);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updatePlayerStatus(MprisPlugin mpris) {
|
private void updatePlayerStatus(MprisPlugin mpris) {
|
||||||
@ -327,78 +311,33 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
getString(R.string.mpris_time_default));
|
getString(R.string.mpris_time_default));
|
||||||
final int interval_time = Integer.parseInt(interval_time_str);
|
final int interval_time = Integer.parseInt(interval_time_str);
|
||||||
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MprisActivity.this, service -> service.addConnectionListener(connectionReceiver));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.addConnectionListener(connectionReceiver);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
connectToPlugin(targetPlayerName);
|
connectToPlugin(targetPlayerName);
|
||||||
|
|
||||||
findViewById(R.id.play_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.play_button).setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.playPause();
|
targetPlayer.playPause();
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.prev_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.prev_button).setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.previous();
|
targetPlayer.previous();
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.rew_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.rew_button).setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.seek(interval_time * -1);
|
targetPlayer.seek(interval_time * -1);
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.ff_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.ff_button).setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.seek(interval_time);
|
targetPlayer.seek(interval_time);
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
findViewById(R.id.next_button).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.next_button).setOnClickListener(view -> BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.next();
|
targetPlayer.next();
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
((SeekBar) findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
((SeekBar) findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -411,33 +350,23 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(final SeekBar seekBar) {
|
public void onStopTrackingTouch(final SeekBar seekBar) {
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer == null) return;
|
if (targetPlayer == null) return;
|
||||||
targetPlayer.setVolume(seekBar.getProgress());
|
targetPlayer.setVolume(seekBar.getProgress());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
positionSeekUpdateRunnable = new Runnable() {
|
positionSeekUpdateRunnable = () -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
final SeekBar positionSeek = (SeekBar) findViewById(R.id.positionSeek);
|
final SeekBar positionSeek = (SeekBar) findViewById(R.id.positionSeek);
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer != null) {
|
if (targetPlayer != null) {
|
||||||
positionSeek.setProgress((int) (targetPlayer.getPosition()));
|
positionSeek.setProgress((int) (targetPlayer.getPosition()));
|
||||||
}
|
}
|
||||||
positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable);
|
positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable);
|
||||||
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000);
|
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
};
|
};
|
||||||
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
|
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
|
||||||
|
|
||||||
@ -454,14 +383,11 @@ public class MprisActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStopTrackingTouch(final SeekBar seekBar) {
|
public void onStopTrackingTouch(final SeekBar seekBar) {
|
||||||
BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MprisActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (targetPlayer != null) {
|
if (targetPlayer != null) {
|
||||||
targetPlayer.setPosition(seekBar.getProgress());
|
targetPlayer.setPosition(seekBar.getProgress());
|
||||||
}
|
}
|
||||||
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
|
positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -211,9 +211,7 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh
|
|||||||
* Update the media control notification
|
* Update the media control notification
|
||||||
*/
|
*/
|
||||||
private void updateMediaNotification() {
|
private void updateMediaNotification() {
|
||||||
BackgroundService.RunCommand(context, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
//If the user disabled the media notification, do not show it
|
//If the user disabled the media notification, do not show it
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||||
if (!prefs.getBoolean(context.getString(R.string.mpris_notification_key), true)) {
|
if (!prefs.getBoolean(context.getString(R.string.mpris_notification_key), true)) {
|
||||||
@ -394,7 +392,6 @@ public class MprisMediaSession implements SharedPreferences.OnSharedPreferenceCh
|
|||||||
mediaSession.setActive(true);
|
mediaSession.setActive(true);
|
||||||
final NotificationManager nm = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
|
final NotificationManager nm = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
|
||||||
nm.notify(MPRIS_MEDIA_NOTIFICATION_ID, notification.build());
|
nm.notify(MPRIS_MEDIA_NOTIFICATION_ID, notification.build());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -98,9 +98,7 @@ public class NotificationFilterActivity extends AppCompatActivity {
|
|||||||
setContentView(R.layout.activity_notification_filter);
|
setContentView(R.layout.activity_notification_filter);
|
||||||
appDatabase = new AppDatabase(NotificationFilterActivity.this, false);
|
appDatabase = new AppDatabase(NotificationFilterActivity.this, false);
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
PackageManager packageManager = getPackageManager();
|
PackageManager packageManager = getPackageManager();
|
||||||
List<ApplicationInfo> appList = packageManager.getInstalledApplications(0);
|
List<ApplicationInfo> appList = packageManager.getInstalledApplications(0);
|
||||||
@ -116,20 +114,9 @@ public class NotificationFilterActivity extends AppCompatActivity {
|
|||||||
apps[i].isEnabled = appDatabase.isEnabled(appInfo.packageName);
|
apps[i].isEnabled = appDatabase.isEnabled(appInfo.packageName);
|
||||||
}
|
}
|
||||||
|
|
||||||
Arrays.sort(apps, new Comparator<AppListInfo>() {
|
Arrays.sort(apps, (lhs, rhs) -> StringsHelper.compare(lhs.name, rhs.name));
|
||||||
@Override
|
|
||||||
public int compare(AppListInfo lhs, AppListInfo rhs) {
|
|
||||||
return StringsHelper.compare(lhs.name, rhs.name);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(this::displayAppList);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
displayAppList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -140,13 +127,10 @@ public class NotificationFilterActivity extends AppCompatActivity {
|
|||||||
AppListAdapter adapter = new AppListAdapter();
|
AppListAdapter adapter = new AppListAdapter();
|
||||||
listView.setAdapter(adapter);
|
listView.setAdapter(adapter);
|
||||||
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
|
||||||
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
listView.setOnItemClickListener((adapterView, view, i, l) -> {
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
boolean checked = listView.isItemChecked(i);
|
boolean checked = listView.isItemChecked(i);
|
||||||
appDatabase.setEnabled(apps[i].pkg, checked);
|
appDatabase.setEnabled(apps[i].pkg, checked);
|
||||||
apps[i].isEnabled = checked;
|
apps[i].isEnabled = checked;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
for (int i = 0; i < apps.length; i++) {
|
for (int i = 0; i < apps.length; i++) {
|
||||||
|
@ -108,9 +108,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
|
|
||||||
appDatabase = new AppDatabase(context, true);
|
appDatabase = new AppDatabase(context, true);
|
||||||
|
|
||||||
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
NotificationReceiver.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(NotificationReceiver service) {
|
|
||||||
|
|
||||||
service.addListener(NotificationsPlugin.this);
|
service.addListener(NotificationsPlugin.this);
|
||||||
|
|
||||||
@ -119,7 +117,6 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
if (serviceReady) {
|
if (serviceReady) {
|
||||||
sendCurrentNotifications(service);
|
sendCurrentNotifications(service);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -128,12 +125,7 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
|
|
||||||
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
NotificationReceiver.RunCommand(context, service -> service.removeListener(NotificationsPlugin.this));
|
||||||
@Override
|
|
||||||
public void onServiceStart(NotificationReceiver service) {
|
|
||||||
service.removeListener(NotificationsPlugin.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -461,22 +453,14 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
if (np.getBoolean("request")) {
|
if (np.getBoolean("request")) {
|
||||||
|
|
||||||
if (serviceReady) {
|
if (serviceReady) {
|
||||||
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
NotificationReceiver.RunCommand(context, this::sendCurrentNotifications);
|
||||||
@Override
|
|
||||||
public void onServiceStart(NotificationReceiver service) {
|
|
||||||
sendCurrentNotifications(service);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} else if (np.has("cancel")) {
|
} else if (np.has("cancel")) {
|
||||||
|
|
||||||
NotificationReceiver.RunCommand(context, new NotificationReceiver.InstanceCallback() {
|
NotificationReceiver.RunCommand(context, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(NotificationReceiver service) {
|
|
||||||
String dismissedId = np.getString("cancel");
|
String dismissedId = np.getString("cancel");
|
||||||
cancelNotificationCompat(service, dismissedId);
|
cancelNotificationCompat(service, dismissedId);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
} else if (np.has("requestReplyId") && np.has("message")) {
|
} else if (np.has("requestReplyId") && np.has("message")) {
|
||||||
@ -497,18 +481,12 @@ public class NotificationsPlugin extends Plugin implements NotificationReceiver.
|
|||||||
return new AlertDialog.Builder(deviceActivity)
|
return new AlertDialog.Builder(deviceActivity)
|
||||||
.setTitle(R.string.pref_plugin_notifications)
|
.setTitle(R.string.pref_plugin_notifications)
|
||||||
.setMessage(R.string.no_permissions)
|
.setMessage(R.string.no_permissions)
|
||||||
.setPositiveButton(R.string.open_settings, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.open_settings, (dialogInterface, i) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
Intent intent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
|
||||||
deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD);
|
deviceActivity.startActivityForResult(intent, MainActivity.RESULT_NEEDS_RELOAD);
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
//Do nothing
|
//Do nothing
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
|
|
||||||
|
@ -202,12 +202,7 @@ public abstract class Plugin {
|
|||||||
if (!hasMainActivity()) return null;
|
if (!hasMainActivity()) return null;
|
||||||
Button b = new Button(activity);
|
Button b = new Button(activity);
|
||||||
b.setText(getActionName());
|
b.setText(getActionName());
|
||||||
b.setOnClickListener(new View.OnClickListener() {
|
b.setOnClickListener(view -> startMainActivity(activity));
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
startMainActivity(activity);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return b;
|
return b;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -242,17 +237,9 @@ public abstract class Plugin {
|
|||||||
return new AlertDialog.Builder(activity)
|
return new AlertDialog.Builder(activity)
|
||||||
.setTitle(getDisplayName())
|
.setTitle(getDisplayName())
|
||||||
.setMessage(reason)
|
.setMessage(reason)
|
||||||
.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.ok, (dialogInterface, i) -> ActivityCompat.requestPermissions(activity, permissions, 0))
|
||||||
@Override
|
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
ActivityCompat.requestPermissions(activity, permissions, 0);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialogInterface, int i) {
|
|
||||||
//Do nothing
|
//Do nothing
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.create();
|
.create();
|
||||||
}
|
}
|
||||||
|
@ -121,12 +121,7 @@ public class RemoteKeyboardPlugin extends Plugin {
|
|||||||
releaseInstances();
|
releaseInstances();
|
||||||
}
|
}
|
||||||
if (RemoteKeyboardService.instance != null)
|
if (RemoteKeyboardService.instance != null)
|
||||||
RemoteKeyboardService.instance.handler.post(new Runnable() {
|
RemoteKeyboardService.instance.handler.post(() -> RemoteKeyboardService.instance.updateInputView());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
RemoteKeyboardService.instance.updateInputView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -137,12 +132,7 @@ public class RemoteKeyboardPlugin extends Plugin {
|
|||||||
if (instances.contains(this)) {
|
if (instances.contains(this)) {
|
||||||
instances.remove(this);
|
instances.remove(this);
|
||||||
if (instances.size() < 1 && RemoteKeyboardService.instance != null)
|
if (instances.size() < 1 && RemoteKeyboardService.instance != null)
|
||||||
RemoteKeyboardService.instance.handler.post(new Runnable() {
|
RemoteKeyboardService.instance.handler.post(() -> RemoteKeyboardService.instance.updateInputView());
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
RemoteKeyboardService.instance.updateInputView();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
releaseInstances();
|
releaseInstances();
|
||||||
|
@ -35,8 +35,7 @@ public class AddCommandDialog extends DialogFragment {
|
|||||||
|
|
||||||
builder.setView(view);
|
builder.setView(view);
|
||||||
|
|
||||||
builder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.ok, (dialog, id) -> {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
|
|
||||||
if (getActivity() instanceof RunCommandActivity) {
|
if (getActivity() instanceof RunCommandActivity) {
|
||||||
|
|
||||||
@ -45,11 +44,8 @@ public class AddCommandDialog extends DialogFragment {
|
|||||||
|
|
||||||
((RunCommandActivity) getActivity()).dialogResult(name, command);
|
((RunCommandActivity) getActivity()).dialogResult(name, command);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
builder.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
builder.setNegativeButton(R.string.cancel, (dialog, id) -> {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return builder.create();
|
return builder.create();
|
||||||
|
@ -45,17 +45,10 @@ import java.util.Comparator;
|
|||||||
public class RunCommandActivity extends AppCompatActivity {
|
public class RunCommandActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private String deviceId;
|
private String deviceId;
|
||||||
private final RunCommandPlugin.CommandsChangedCallback commandsChangedCallback = new RunCommandPlugin.CommandsChangedCallback() {
|
private final RunCommandPlugin.CommandsChangedCallback commandsChangedCallback = this::updateView;
|
||||||
@Override
|
|
||||||
public void update() {
|
|
||||||
updateView();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
private void updateView() {
|
private void updateView() {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
||||||
@ -64,9 +57,7 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ListView view = (ListView) findViewById(R.id.runcommandslist);
|
ListView view = (ListView) findViewById(R.id.runcommandslist);
|
||||||
|
|
||||||
final ArrayList<ListAdapter.Item> commandItems = new ArrayList<>();
|
final ArrayList<ListAdapter.Item> commandItems = new ArrayList<>();
|
||||||
@ -79,24 +70,18 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Collections.sort(commandItems, new Comparator<ListAdapter.Item>() {
|
Collections.sort(commandItems, (lhs, rhs) -> {
|
||||||
@Override
|
|
||||||
public int compare(ListAdapter.Item lhs, ListAdapter.Item rhs) {
|
|
||||||
String lName = ((CommandEntry) lhs).getName();
|
String lName = ((CommandEntry) lhs).getName();
|
||||||
String rName = ((CommandEntry) rhs).getName();
|
String rName = ((CommandEntry) rhs).getName();
|
||||||
return lName.compareTo(rName);
|
return lName.compareTo(rName);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
ListAdapter adapter = new ListAdapter(RunCommandActivity.this, commandItems);
|
ListAdapter adapter = new ListAdapter(RunCommandActivity.this, commandItems);
|
||||||
|
|
||||||
view.setAdapter(adapter);
|
view.setAdapter(adapter);
|
||||||
view.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
view.setOnItemClickListener((adapterView, view1, i, l) -> {
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
CommandEntry entry = (CommandEntry) commandItems.get(i);
|
CommandEntry entry = (CommandEntry) commandItems.get(i);
|
||||||
plugin.runCommand(entry.getKey());
|
plugin.runCommand(entry.getKey());
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@ -107,9 +92,7 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
explanation.setText(text);
|
explanation.setText(text);
|
||||||
explanation.setVisibility(commandItems.isEmpty() ? View.VISIBLE : View.GONE);
|
explanation.setVisibility(commandItems.isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -125,12 +108,7 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
FloatingActionButton addCommandButton = (FloatingActionButton) findViewById(R.id.add_command_button);
|
FloatingActionButton addCommandButton = (FloatingActionButton) findViewById(R.id.add_command_button);
|
||||||
addCommandButton.setVisibility(canAddCommands ? View.VISIBLE : View.GONE);
|
addCommandButton.setVisibility(canAddCommands ? View.VISIBLE : View.GONE);
|
||||||
addCommandButton.setOnClickListener(new View.OnClickListener() {
|
addCommandButton.setOnClickListener(view -> new AddCommandDialog().show(getSupportFragmentManager(), "addcommanddialog"));
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
new AddCommandDialog().show(getSupportFragmentManager(), "addcommanddialog");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
updateView();
|
updateView();
|
||||||
}
|
}
|
||||||
@ -139,9 +117,7 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
||||||
@ -150,7 +126,6 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.addCommandsUpdatedCallback(commandsChangedCallback);
|
plugin.addCommandsUpdatedCallback(commandsChangedCallback);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -158,9 +133,7 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
||||||
@ -169,20 +142,16 @@ public class RunCommandActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
plugin.removeCommandsUpdatedCallback(commandsChangedCallback);
|
plugin.removeCommandsUpdatedCallback(commandsChangedCallback);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void dialogResult(final String cmdName, final String cmdCmd) {
|
public void dialogResult(final String cmdName, final String cmdCmd) {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class);
|
||||||
if(!cmdName.isEmpty() && !cmdCmd.isEmpty()) {
|
if(!cmdName.isEmpty() && !cmdCmd.isEmpty()) {
|
||||||
plugin.addCommand(cmdName, cmdCmd);
|
plugin.addCommand(cmdName, cmdCmd);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -89,9 +89,7 @@ public class SendFileActivity extends AppCompatActivity {
|
|||||||
if (uris.isEmpty()) {
|
if (uris.isEmpty()) {
|
||||||
Log.w("SendFileActivity", "No files to send?");
|
Log.w("SendFileActivity", "No files to send?");
|
||||||
} else {
|
} else {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(mDeviceId);
|
Device device = service.getDevice(mDeviceId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
Log.e("SendFileActivity", "Device is null");
|
Log.e("SendFileActivity", "Device is null");
|
||||||
@ -99,7 +97,6 @@ public class SendFileActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SharePlugin.queuedSendUriList(getApplicationContext(), device, uris);
|
SharePlugin.queuedSendUriList(getApplicationContext(), device, uris);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,28 +70,15 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
private void updateComputerListAction() {
|
private void updateComputerListAction() {
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
BackgroundService.RunCommand(ShareActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(ShareActivity.this, BackgroundService::onNetworkChange);
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> mSwipeRefreshLayout.setRefreshing(false));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +92,7 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
|
|
||||||
Collection<Device> devices = service.getDevices().values();
|
Collection<Device> devices = service.getDevices().values();
|
||||||
final ArrayList<Device> devicesList = new ArrayList<>();
|
final ArrayList<Device> devicesList = new ArrayList<>();
|
||||||
@ -122,24 +107,17 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runOnUiThread(new Runnable() {
|
runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
ListView list = (ListView) findViewById(R.id.devices_list);
|
ListView list = (ListView) findViewById(R.id.devices_list);
|
||||||
list.setAdapter(new ListAdapter(ShareActivity.this, items));
|
list.setAdapter(new ListAdapter(ShareActivity.this, items));
|
||||||
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
|
list.setOnItemClickListener((adapterView, view, i, l) -> {
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
|
|
||||||
|
|
||||||
Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!
|
Device device = devicesList.get(i - 1); //NOTE: -1 because of the title!
|
||||||
SharePlugin.share(intent, device);
|
SharePlugin.share(intent, device);
|
||||||
finish();
|
finish();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,12 +132,7 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
ActionBar actionBar = getSupportActionBar();
|
ActionBar actionBar = getSupportActionBar();
|
||||||
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_list_layout);
|
mSwipeRefreshLayout = (SwipeRefreshLayout) findViewById(R.id.refresh_list_layout);
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(
|
mSwipeRefreshLayout.setOnRefreshListener(
|
||||||
new SwipeRefreshLayout.OnRefreshListener() {
|
this::updateComputerListAction
|
||||||
@Override
|
|
||||||
public void onRefresh() {
|
|
||||||
updateComputerListAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
if (actionBar != null) {
|
if (actionBar != null) {
|
||||||
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_HOME | ActionBar.DISPLAY_SHOW_TITLE | ActionBar.DISPLAY_SHOW_CUSTOM);
|
||||||
@ -176,32 +149,20 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (deviceId != null) {
|
if (deviceId != null) {
|
||||||
|
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Log.d("DirectShare", "sharing to " + service.getDevice(deviceId).getName());
|
Log.d("DirectShare", "sharing to " + service.getDevice(deviceId).getName());
|
||||||
Device device = service.getDevice(deviceId);
|
Device device = service.getDevice(deviceId);
|
||||||
if (device.isReachable() && device.isPaired()) {
|
if (device.isReachable() && device.isPaired()) {
|
||||||
SharePlugin.share(intent, device);
|
SharePlugin.share(intent, device);
|
||||||
}
|
}
|
||||||
finish();
|
finish();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
BackgroundService.addGuiInUseCounter(this);
|
BackgroundService.addGuiInUseCounter(this);
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.onNetworkChange();
|
service.onNetworkChange();
|
||||||
service.addDeviceListChangedCallback("ShareActivity", new BackgroundService.DeviceListChangedCallback() {
|
service.addDeviceListChangedCallback("ShareActivity", this::updateComputerList);
|
||||||
@Override
|
|
||||||
public void onDeviceListChanged() {
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
@ -210,12 +171,7 @@ public class ShareActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> service.removeDeviceListChangedCallback("ShareActivity"));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.removeDeviceListChangedCallback("ShareActivity");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
BackgroundService.removeGuiInUseCounter(this);
|
BackgroundService.removeGuiInUseCounter(this);
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
@ -219,9 +219,7 @@ public class SharePlugin extends Plugin {
|
|||||||
final ShareNotification notification = new ShareNotification(device, filename);
|
final ShareNotification notification = new ShareNotification(device, filename);
|
||||||
notification.show();
|
notification.show();
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
byte data[] = new byte[4096];
|
byte data[] = new byte[4096];
|
||||||
long progress = 0, prevProgressPercentage = -1;
|
long progress = 0, prevProgressPercentage = -1;
|
||||||
@ -278,7 +276,6 @@ public class SharePlugin extends Plugin {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -302,9 +299,7 @@ public class SharePlugin extends Plugin {
|
|||||||
final NotificationUpdateCallback notificationUpdateCallback = new NotificationUpdateCallback(context, device, toSend);
|
final NotificationUpdateCallback notificationUpdateCallback = new NotificationUpdateCallback(context, device, toSend);
|
||||||
|
|
||||||
//Do the sending in background
|
//Do the sending in background
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
//Actually send the files
|
//Actually send the files
|
||||||
try {
|
try {
|
||||||
for (NetworkPacket np : toSend) {
|
for (NetworkPacket np : toSend) {
|
||||||
@ -317,7 +312,6 @@ public class SharePlugin extends Plugin {
|
|||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -36,20 +36,14 @@ public class ShareSettingsActivity extends PluginSettingsActivity {
|
|||||||
filePicker = findPreference("share_destination_folder_preference");
|
filePicker = findPreference("share_destination_folder_preference");
|
||||||
|
|
||||||
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
|
if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP)) {
|
||||||
customDownloads.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
customDownloads.setOnPreferenceChangeListener((preference, newValue) -> {
|
||||||
@Override
|
|
||||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
|
||||||
updateFilePickerStatus((Boolean) newValue);
|
updateFilePickerStatus((Boolean) newValue);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
filePicker.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
filePicker.setOnPreferenceClickListener(preference -> {
|
||||||
@Override
|
|
||||||
public boolean onPreferenceClick(Preference preference) {
|
|
||||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
|
||||||
startActivityForResult(intent, RESULT_PICKER);
|
startActivityForResult(intent, RESULT_PICKER);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
customDownloads.setEnabled(false);
|
customDownloads.setEnabled(false);
|
||||||
|
@ -65,38 +65,27 @@ public class CustomDevicesActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList));
|
list.setAdapter(new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, ipAddressList));
|
||||||
|
|
||||||
findViewById(android.R.id.button1).setOnClickListener(new View.OnClickListener() {
|
findViewById(android.R.id.button1).setOnClickListener(v -> addNewDevice());
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
addNewDevice();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext);
|
EditText ipEntryBox = (EditText) findViewById(R.id.ip_edittext);
|
||||||
ipEntryBox.setOnEditorActionListener(new TextView.OnEditorActionListener() {
|
ipEntryBox.setOnEditorActionListener((v, actionId, event) -> {
|
||||||
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
|
|
||||||
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
if (actionId == EditorInfo.IME_ACTION_SEND) {
|
||||||
addNewDevice();
|
addNewDevice();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean dialogAlreadyShown = false;
|
boolean dialogAlreadyShown = false;
|
||||||
private AdapterView.OnItemClickListener onClickListener = new AdapterView.OnItemClickListener() {
|
private AdapterView.OnItemClickListener onClickListener = (parent, view, position, id) -> {
|
||||||
@Override
|
|
||||||
public void onItemClick(AdapterView<?> parent, View view, final int position, final long id) {
|
|
||||||
|
|
||||||
if (dialogAlreadyShown) {
|
if (dialogAlreadyShown) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove touched item after confirmation
|
// remove touched item after confirmation
|
||||||
DialogInterface.OnClickListener confirmationListener = new DialogInterface.OnClickListener() {
|
DialogInterface.OnClickListener confirmationListener = (dialog, which) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
switch (which) {
|
switch (which) {
|
||||||
case DialogInterface.BUTTON_POSITIVE:
|
case DialogInterface.BUTTON_POSITIVE:
|
||||||
ipAddressList.remove(position);
|
ipAddressList.remove(position);
|
||||||
@ -105,7 +94,6 @@ public class CustomDevicesActivity extends AppCompatActivity {
|
|||||||
case DialogInterface.BUTTON_NEGATIVE:
|
case DialogInterface.BUTTON_NEGATIVE:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this);
|
AlertDialog.Builder builder = new AlertDialog.Builder(CustomDevicesActivity.this);
|
||||||
@ -115,16 +103,10 @@ public class CustomDevicesActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { //DismissListener
|
||||||
dialogAlreadyShown = true;
|
dialogAlreadyShown = true;
|
||||||
builder.setOnDismissListener(new DialogInterface.OnDismissListener() {
|
builder.setOnDismissListener(dialog -> dialogAlreadyShown = false);
|
||||||
@Override
|
|
||||||
public void onDismiss(DialogInterface dialog) {
|
|
||||||
dialogAlreadyShown = false;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.show();
|
builder.show();
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
private void addNewDevice() {
|
private void addNewDevice() {
|
||||||
|
@ -110,9 +110,7 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
//Log.e("DeviceFragment", "device: " + deviceId);
|
//Log.e("DeviceFragment", "device: " + deviceId);
|
||||||
|
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
device = service.getDevice(mDeviceId);
|
device = service.getDevice(mDeviceId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
Log.e("DeviceFragment", "Trying to display a device fragment but the device is not present");
|
Log.e("DeviceFragment", "Trying to display a device fragment but the device is not present");
|
||||||
@ -127,48 +125,28 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
refreshUI();
|
refreshUI();
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
final Button pairButton = (Button) rootView.findViewById(R.id.pair_button);
|
final Button pairButton = (Button) rootView.findViewById(R.id.pair_button);
|
||||||
pairButton.setOnClickListener(new View.OnClickListener() {
|
pairButton.setOnClickListener(view -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
pairButton.setVisibility(View.GONE);
|
pairButton.setVisibility(View.GONE);
|
||||||
((TextView) rootView.findViewById(R.id.pair_message)).setText("");
|
((TextView) rootView.findViewById(R.id.pair_message)).setText("");
|
||||||
rootView.findViewById(R.id.pair_progress).setVisibility(View.VISIBLE);
|
rootView.findViewById(R.id.pair_progress).setVisibility(View.VISIBLE);
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
device = service.getDevice(deviceId);
|
device = service.getDevice(deviceId);
|
||||||
if (device == null) return;
|
if (device == null) return;
|
||||||
device.requestPairing();
|
device.requestPairing();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
rootView.findViewById(R.id.accept_button).setOnClickListener(new View.OnClickListener() {
|
rootView.findViewById(R.id.accept_button).setOnClickListener(view -> BackgroundService.RunCommand(mActivity, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
device.acceptPairing();
|
device.acceptPairing();
|
||||||
rootView.findViewById(R.id.pairing_buttons).setVisibility(View.GONE);
|
rootView.findViewById(R.id.pairing_buttons).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
rootView.findViewById(R.id.reject_button).setOnClickListener(new View.OnClickListener() {
|
rootView.findViewById(R.id.reject_button).setOnClickListener(view -> BackgroundService.RunCommand(mActivity, service -> {
|
||||||
@Override
|
|
||||||
public void onClick(View view) {
|
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
//Remove listener so buttons don't show for a while before changing the view
|
//Remove listener so buttons don't show for a while before changing the view
|
||||||
device.removePluginsChangedListener(pluginsChangedListener);
|
device.removePluginsChangedListener(pluginsChangedListener);
|
||||||
@ -176,31 +154,20 @@ public class DeviceFragment extends Fragment {
|
|||||||
device.rejectPairing();
|
device.rejectPairing();
|
||||||
}
|
}
|
||||||
mActivity.onDeviceSelected(null);
|
mActivity.onDeviceSelected(null);
|
||||||
}
|
}));
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return rootView;
|
return rootView;
|
||||||
}
|
}
|
||||||
|
|
||||||
final Device.PluginsChangedListener pluginsChangedListener = new Device.PluginsChangedListener() {
|
final Device.PluginsChangedListener pluginsChangedListener = device -> refreshUI();
|
||||||
@Override
|
|
||||||
public void onPluginsChanged(final Device device) {
|
|
||||||
refreshUI();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroyView() {
|
public void onDestroyView() {
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(mDeviceId);
|
Device device = service.getDevice(mDeviceId);
|
||||||
if (device == null) return;
|
if (device == null) return;
|
||||||
device.removePluginsChangedListener(pluginsChangedListener);
|
device.removePluginsChangedListener(pluginsChangedListener);
|
||||||
device.removePairingCallback(pairingCallback);
|
device.removePairingCallback(pairingCallback);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
super.onDestroyView();
|
super.onDestroyView();
|
||||||
}
|
}
|
||||||
@ -223,38 +190,26 @@ public class DeviceFragment extends Fragment {
|
|||||||
if (!p.displayInContextMenu()) {
|
if (!p.displayInContextMenu()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
menu.add(p.getActionName()).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
menu.add(p.getActionName()).setOnMenuItemClickListener(item -> {
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem item) {
|
|
||||||
p.startMainActivity(mActivity);
|
p.startMainActivity(mActivity);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
menu.add(R.string.device_menu_plugins).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
menu.add(R.string.device_menu_plugins).setOnMenuItemClickListener(menuItem -> {
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
|
||||||
Intent intent = new Intent(mActivity, SettingsActivity.class);
|
Intent intent = new Intent(mActivity, SettingsActivity.class);
|
||||||
intent.putExtra("deviceId", mDeviceId);
|
intent.putExtra("deviceId", mDeviceId);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (device.isReachable()) {
|
if (device.isReachable()) {
|
||||||
|
|
||||||
menu.add(R.string.encryption_info_title).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
menu.add(R.string.encryption_info_title).setOnMenuItemClickListener(menuItem -> {
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
|
||||||
Context context = mActivity;
|
Context context = mActivity;
|
||||||
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
AlertDialog.Builder builder = new AlertDialog.Builder(context);
|
||||||
builder.setTitle(context.getResources().getString(R.string.encryption_info_title));
|
builder.setTitle(context.getResources().getString(R.string.encryption_info_title));
|
||||||
builder.setPositiveButton(context.getResources().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(context.getResources().getString(R.string.ok), (dialog, id) -> dialog.dismiss());
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
|
||||||
dialog.dismiss();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if (device.certificate == null) {
|
if (device.certificate == null) {
|
||||||
builder.setMessage(R.string.encryption_info_msg_no_ssl);
|
builder.setMessage(R.string.encryption_info_msg_no_ssl);
|
||||||
@ -264,22 +219,18 @@ public class DeviceFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
builder.create().show();
|
builder.create().show();
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (device.isPaired()) {
|
if (device.isPaired()) {
|
||||||
|
|
||||||
menu.add(R.string.device_menu_unpair).setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
|
menu.add(R.string.device_menu_unpair).setOnMenuItemClickListener(menuItem -> {
|
||||||
@Override
|
|
||||||
public boolean onMenuItemClick(MenuItem menuItem) {
|
|
||||||
//Remove listener so buttons don't show for a while before changing the view
|
//Remove listener so buttons don't show for a while before changing the view
|
||||||
device.removePluginsChangedListener(pluginsChangedListener);
|
device.removePluginsChangedListener(pluginsChangedListener);
|
||||||
device.removePairingCallback(pairingCallback);
|
device.removePairingCallback(pairingCallback);
|
||||||
device.unpair();
|
device.unpair();
|
||||||
mActivity.onDeviceSelected(null);
|
mActivity.onDeviceSelected(null);
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -291,9 +242,7 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
getView().setFocusableInTouchMode(true);
|
getView().setFocusableInTouchMode(true);
|
||||||
getView().requestFocus();
|
getView().requestFocus();
|
||||||
getView().setOnKeyListener(new View.OnKeyListener() {
|
getView().setOnKeyListener((v, keyCode, event) -> {
|
||||||
@Override
|
|
||||||
public boolean onKey(View v, int keyCode, KeyEvent event) {
|
|
||||||
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
|
if (event.getAction() == KeyEvent.ACTION_UP && keyCode == KeyEvent.KEYCODE_BACK) {
|
||||||
boolean fromDeviceList = getArguments().getBoolean(ARG_FROM_DEVICE_LIST, false);
|
boolean fromDeviceList = getArguments().getBoolean(ARG_FROM_DEVICE_LIST, false);
|
||||||
// Handle back button so we go to the list of devices in case we came from there
|
// Handle back button so we go to the list of devices in case we came from there
|
||||||
@ -303,7 +252,6 @@ public class DeviceFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -347,12 +295,7 @@ public class DeviceFragment extends Fragment {
|
|||||||
if (!p.hasMainActivity()) continue;
|
if (!p.hasMainActivity()) continue;
|
||||||
if (p.displayInContextMenu()) continue;
|
if (p.displayInContextMenu()) continue;
|
||||||
|
|
||||||
pluginListItems.add(new PluginItem(p, new View.OnClickListener() {
|
pluginListItems.add(new PluginItem(p, v -> p.startMainActivity(mActivity)));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
p.startMainActivity(mActivity);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
createPluginsList(device.getFailedPlugins(), R.string.plugins_failed_to_load, new PluginClickListener() {
|
createPluginsList(device.getFailedPlugins(), R.string.plugins_failed_to_load, new PluginClickListener() {
|
||||||
@ -408,31 +351,25 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void pairingFailed(final String error) {
|
public void pairingFailed(final String error) {
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
mActivity.runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (rootView == null) return;
|
if (rootView == null) return;
|
||||||
((TextView) rootView.findViewById(R.id.pair_message)).setText(error);
|
((TextView) rootView.findViewById(R.id.pair_message)).setText(error);
|
||||||
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
|
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
|
||||||
rootView.findViewById(R.id.pair_button).setVisibility(View.VISIBLE);
|
rootView.findViewById(R.id.pair_button).setVisibility(View.VISIBLE);
|
||||||
rootView.findViewById(R.id.pair_request).setVisibility(View.GONE);
|
rootView.findViewById(R.id.pair_request).setVisibility(View.GONE);
|
||||||
refreshUI();
|
refreshUI();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void unpaired() {
|
public void unpaired() {
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
mActivity.runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (rootView == null) return;
|
if (rootView == null) return;
|
||||||
((TextView) rootView.findViewById(R.id.pair_message)).setText(R.string.device_not_paired);
|
((TextView) rootView.findViewById(R.id.pair_message)).setText(R.string.device_not_paired);
|
||||||
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
|
rootView.findViewById(R.id.pair_progress).setVisibility(View.GONE);
|
||||||
rootView.findViewById(R.id.pair_button).setVisibility(View.VISIBLE);
|
rootView.findViewById(R.id.pair_button).setVisibility(View.VISIBLE);
|
||||||
rootView.findViewById(R.id.pair_request).setVisibility(View.GONE);
|
rootView.findViewById(R.id.pair_request).setVisibility(View.GONE);
|
||||||
refreshUI();
|
refreshUI();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -440,8 +377,7 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
public static void acceptPairing(final String devId, final MainActivity activity) {
|
public static void acceptPairing(final String devId, final MainActivity activity) {
|
||||||
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, service -> {
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device dev = service.getDevice(devId);
|
Device dev = service.getDevice(devId);
|
||||||
if (dev == null) {
|
if (dev == null) {
|
||||||
Log.w("rejectPairing", "Device no longer exists: " + devId);
|
Log.w("rejectPairing", "Device no longer exists: " + devId);
|
||||||
@ -457,14 +393,12 @@ public class DeviceFragment extends Fragment {
|
|||||||
|
|
||||||
frag.refreshUI();
|
frag.refreshUI();
|
||||||
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void rejectPairing(final String devId, final MainActivity activity) {
|
public static void rejectPairing(final String devId, final MainActivity activity) {
|
||||||
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
final DeviceFragment frag = new DeviceFragment(devId, activity);
|
||||||
BackgroundService.RunCommand(activity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(activity, service -> {
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device dev = service.getDevice(devId);
|
Device dev = service.getDevice(devId);
|
||||||
if (dev == null) {
|
if (dev == null) {
|
||||||
Log.w("rejectPairing", "Device no longer exists: " + devId);
|
Log.w("rejectPairing", "Device no longer exists: " + devId);
|
||||||
@ -484,7 +418,6 @@ public class DeviceFragment extends Fragment {
|
|||||||
activity.onDeviceSelected(null);
|
activity.onDeviceSelected(null);
|
||||||
|
|
||||||
frag.refreshUI();
|
frag.refreshUI();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,12 +74,7 @@ public class PairingDeviceItem implements ListAdapter.Item {
|
|||||||
v.findViewById(R.id.list_item_entry_summary).setVisibility(View.GONE);
|
v.findViewById(R.id.list_item_entry_summary).setVisibility(View.GONE);
|
||||||
}
|
}
|
||||||
|
|
||||||
v.setOnClickListener(new View.OnClickListener() {
|
v.setOnClickListener(v1 -> callback.pairingClicked(device));
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
callback.pairingClicked(device);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
@ -92,12 +92,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
TextView nameView = (TextView) mDrawerHeader.findViewById(R.id.device_name);
|
TextView nameView = (TextView) mDrawerHeader.findViewById(R.id.device_name);
|
||||||
nameView.setText(deviceName);
|
nameView.setText(deviceName);
|
||||||
|
|
||||||
View.OnClickListener renameListener = new View.OnClickListener() {
|
View.OnClickListener renameListener = v -> renameDevice();
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
renameDevice();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
mDrawerHeader.findViewById(R.id.kdeconnect_label).setOnClickListener(renameListener);
|
mDrawerHeader.findViewById(R.id.kdeconnect_label).setOnClickListener(renameListener);
|
||||||
mDrawerHeader.findViewById(R.id.device_name).setOnClickListener(renameListener);
|
mDrawerHeader.findViewById(R.id.device_name).setOnClickListener(renameListener);
|
||||||
|
|
||||||
@ -105,9 +100,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
addDarkModeSwitch((ViewGroup) mDrawerHeader);
|
addDarkModeSwitch((ViewGroup) mDrawerHeader);
|
||||||
}
|
}
|
||||||
|
|
||||||
mNavigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
|
mNavigationView.setNavigationItemSelectedListener(menuItem -> {
|
||||||
@Override
|
|
||||||
public boolean onNavigationItemSelected(MenuItem menuItem) {
|
|
||||||
|
|
||||||
String deviceId = mMapMenuToDeviceId.get(menuItem);
|
String deviceId = mMapMenuToDeviceId.get(menuItem);
|
||||||
onDeviceSelected(deviceId);
|
onDeviceSelected(deviceId);
|
||||||
@ -115,7 +108,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
mDrawerLayout.closeDrawer(mNavigationView);
|
mDrawerLayout.closeDrawer(mNavigationView);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
preferences = getSharedPreferences(STATE_SELECTED_DEVICE, Context.MODE_PRIVATE);
|
preferences = getSharedPreferences(STATE_SELECTED_DEVICE, Context.MODE_PRIVATE);
|
||||||
@ -218,9 +210,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
//Log.e("MainActivity", "UpdateComputerList");
|
//Log.e("MainActivity", "UpdateComputerList");
|
||||||
|
|
||||||
BackgroundService.RunCommand(MainActivity.this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(MainActivity.this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
|
|
||||||
Menu menu = mNavigationView.getMenu();
|
Menu menu = mNavigationView.getMenu();
|
||||||
|
|
||||||
@ -244,7 +234,6 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
item.setCheckable(true);
|
item.setCheckable(true);
|
||||||
item.setChecked(mCurrentDevice == null);
|
item.setChecked(mCurrentDevice == null);
|
||||||
mMapMenuToDeviceId.put(item, null);
|
mMapMenuToDeviceId.put(item, null);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,29 +241,14 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
BackgroundService.addGuiInUseCounter(this, true);
|
BackgroundService.addGuiInUseCounter(this, true);
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> service.addDeviceListChangedCallback("MainActivity", this::updateComputerList));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.addDeviceListChangedCallback("MainActivity", new BackgroundService.DeviceListChangedCallback() {
|
|
||||||
@Override
|
|
||||||
public void onDeviceListChanged() {
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
BackgroundService.removeGuiInUseCounter(this);
|
BackgroundService.removeGuiInUseCounter(this);
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> service.removeDeviceListChangedCallback("MainActivity"));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.removeDeviceListChangedCallback("MainActivity");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -326,12 +300,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
switch (requestCode) {
|
switch (requestCode) {
|
||||||
case RESULT_NEEDS_RELOAD:
|
case RESULT_NEEDS_RELOAD:
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(mCurrentDevice);
|
Device device = service.getDevice(mCurrentDevice);
|
||||||
device.reloadPluginsFromSettings();
|
device.reloadPluginsFromSettings();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -344,12 +315,9 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
for (int result : grantResults) {
|
for (int result : grantResults) {
|
||||||
if (result == PackageManager.PERMISSION_GRANTED) {
|
if (result == PackageManager.PERMISSION_GRANTED) {
|
||||||
//New permission granted, reload plugins
|
//New permission granted, reload plugins
|
||||||
BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(this, service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
Device device = service.getDevice(mCurrentDevice);
|
Device device = service.getDevice(mCurrentDevice);
|
||||||
device.reloadPluginsFromSettings();
|
device.reloadPluginsFromSettings();
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,24 +336,13 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
);
|
);
|
||||||
new AlertDialog.Builder(MainActivity.this)
|
new AlertDialog.Builder(MainActivity.this)
|
||||||
.setView(deviceNameEdit)
|
.setView(deviceNameEdit)
|
||||||
.setPositiveButton(R.string.device_rename_confirm, new DialogInterface.OnClickListener() {
|
.setPositiveButton(R.string.device_rename_confirm, (dialog, which) -> {
|
||||||
@Override
|
String deviceName1 = deviceNameEdit.getText().toString();
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
DeviceHelper.setDeviceName(MainActivity.this, deviceName1);
|
||||||
String deviceName = deviceNameEdit.getText().toString();
|
nameView.setText(deviceName1);
|
||||||
DeviceHelper.setDeviceName(MainActivity.this, deviceName);
|
BackgroundService.RunCommand(MainActivity.this, BackgroundService::onNetworkChange);
|
||||||
nameView.setText(deviceName);
|
|
||||||
BackgroundService.RunCommand(MainActivity.this, new BackgroundService.InstanceCallback() {
|
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
|
.setNegativeButton(R.string.cancel, (dialog, which) -> {
|
||||||
@Override
|
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.setTitle(R.string.device_rename_title)
|
.setTitle(R.string.device_rename_title)
|
||||||
.show();
|
.show();
|
||||||
|
@ -79,12 +79,7 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
View listRootView = rootView.findViewById(R.id.devices_list);
|
View listRootView = rootView.findViewById(R.id.devices_list);
|
||||||
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_list_layout);
|
mSwipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.refresh_list_layout);
|
||||||
mSwipeRefreshLayout.setOnRefreshListener(
|
mSwipeRefreshLayout.setOnRefreshListener(
|
||||||
new SwipeRefreshLayout.OnRefreshListener() {
|
this::updateComputerListAction
|
||||||
@Override
|
|
||||||
public void onRefresh() {
|
|
||||||
updateComputerListAction();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
);
|
);
|
||||||
headerText = new TextView(inflater.getContext());
|
headerText = new TextView(inflater.getContext());
|
||||||
headerText.setText(getString(R.string.pairing_description));
|
headerText.setText(getString(R.string.pairing_description));
|
||||||
@ -102,37 +97,19 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
|
|
||||||
private void updateComputerListAction() {
|
private void updateComputerListAction() {
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, BackgroundService::onNetworkChange);
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.onNetworkChange();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mSwipeRefreshLayout.setRefreshing(true);
|
mSwipeRefreshLayout.setRefreshing(true);
|
||||||
new Thread(new Runnable() {
|
new Thread(() -> {
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
try {
|
try {
|
||||||
Thread.sleep(1500);
|
Thread.sleep(1500);
|
||||||
} catch (InterruptedException ignored) {
|
} catch (InterruptedException ignored) {
|
||||||
}
|
}
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
mActivity.runOnUiThread(() -> mSwipeRefreshLayout.setRefreshing(false));
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
mSwipeRefreshLayout.setRefreshing(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}).start();
|
}).start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateComputerList() {
|
private void updateComputerList() {
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> mActivity.runOnUiThread(() -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(final BackgroundService service) {
|
|
||||||
mActivity.runOnUiThread(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
|
|
||||||
if (!isAdded()) {
|
if (!isAdded()) {
|
||||||
//Fragment is not attached to an activity. We will crash if we try to do anything here.
|
//Fragment is not attached to an activity. We will crash if we try to do anything here.
|
||||||
@ -212,28 +189,14 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
} finally {
|
} finally {
|
||||||
listRefreshCalledThisFrame = false;
|
listRefreshCalledThisFrame = false;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
}));
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onStart() {
|
public void onStart() {
|
||||||
super.onStart();
|
super.onStart();
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> service.addDeviceListChangedCallback("PairingFragment", this::updateComputerList));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.addDeviceListChangedCallback("PairingFragment", new BackgroundService.DeviceListChangedCallback() {
|
|
||||||
@Override
|
|
||||||
public void onDeviceListChanged() {
|
|
||||||
updateComputerList();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
updateComputerList();
|
updateComputerList();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -241,12 +204,7 @@ public class PairingFragment extends Fragment implements PairingDeviceItem.Callb
|
|||||||
public void onStop() {
|
public void onStop() {
|
||||||
super.onStop();
|
super.onStop();
|
||||||
mSwipeRefreshLayout.setEnabled(false);
|
mSwipeRefreshLayout.setEnabled(false);
|
||||||
BackgroundService.RunCommand(mActivity, new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(mActivity, service -> service.removeDeviceListChangedCallback("PairingFragment"));
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
service.removeDeviceListChangedCallback("PairingFragment");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -29,16 +29,13 @@ public class PluginPreference extends CheckBoxPreference {
|
|||||||
|
|
||||||
Plugin plugin = device.getPlugin(pluginKey, true);
|
Plugin plugin = device.getPlugin(pluginKey, true);
|
||||||
if (info.hasSettings() && plugin != null) {
|
if (info.hasSettings() && plugin != null) {
|
||||||
this.listener = new View.OnClickListener() {
|
this.listener = v -> {
|
||||||
@Override
|
Plugin plugin1 = device.getPlugin(pluginKey, true);
|
||||||
public void onClick(View v) {
|
if (plugin1 != null) {
|
||||||
Plugin plugin = device.getPlugin(pluginKey, true);
|
plugin1.startPreferencesActivity(activity);
|
||||||
if (plugin != null) {
|
|
||||||
plugin.startPreferencesActivity(activity);
|
|
||||||
} else { //Could happen if the device is not connected anymore
|
} else { //Could happen if the device is not connected anymore
|
||||||
activity.finish(); //End this activity so we go to the "device not reachable" screen
|
activity.finish(); //End this activity so we go to the "device not reachable" screen
|
||||||
}
|
}
|
||||||
}
|
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
this.listener = null;
|
this.listener = null;
|
||||||
@ -58,14 +55,11 @@ public class PluginPreference extends CheckBoxPreference {
|
|||||||
button.setOnClickListener(listener);
|
button.setOnClickListener(listener);
|
||||||
}
|
}
|
||||||
|
|
||||||
root.setOnClickListener(new View.OnClickListener() {
|
root.setOnClickListener(v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
boolean newState = !device.isPluginEnabled(pluginKey);
|
boolean newState = !device.isPluginEnabled(pluginKey);
|
||||||
setChecked(newState); //It actually works on API<14
|
setChecked(newState); //It actually works on API<14
|
||||||
button.setEnabled(newState);
|
button.setEnabled(newState);
|
||||||
device.setPluginEnabled(pluginKey, newState);
|
device.setPluginEnabled(pluginKey, newState);
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,17 +44,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
deviceId = getIntent().getStringExtra("deviceId");
|
deviceId = getIntent().getStringExtra("deviceId");
|
||||||
}
|
}
|
||||||
|
|
||||||
BackgroundService.RunCommand(getApplicationContext(), new BackgroundService.InstanceCallback() {
|
BackgroundService.RunCommand(getApplicationContext(), service -> {
|
||||||
@Override
|
|
||||||
public void onServiceStart(BackgroundService service) {
|
|
||||||
final Device device = service.getDevice(deviceId);
|
final Device device = service.getDevice(deviceId);
|
||||||
if (device == null) {
|
if (device == null) {
|
||||||
SettingsActivity.this.runOnUiThread(new Runnable() {
|
SettingsActivity.this.runOnUiThread(SettingsActivity.this::finish);
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
SettingsActivity.this.finish();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
List<String> plugins = device.getSupportedPlugins();
|
List<String> plugins = device.getSupportedPlugins();
|
||||||
@ -62,7 +55,6 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
|||||||
PluginPreference pref = new PluginPreference(SettingsActivity.this, pluginKey, device);
|
PluginPreference pref = new PluginPreference(SettingsActivity.this, pluginKey, device);
|
||||||
preferenceScreen.addPreference(pref);
|
preferenceScreen.addPreference(pref);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -204,33 +204,18 @@ public class LanLinkTest extends AndroidTestCase {
|
|||||||
Mockito.when(sharePacket.getType()).thenReturn("kdeconnect.share");
|
Mockito.when(sharePacket.getType()).thenReturn("kdeconnect.share");
|
||||||
Mockito.when(sharePacket.hasPayload()).thenReturn(true);
|
Mockito.when(sharePacket.hasPayload()).thenReturn(true);
|
||||||
Mockito.when(sharePacket.hasPayloadTransferInfo()).thenReturn(true);
|
Mockito.when(sharePacket.hasPayloadTransferInfo()).thenReturn(true);
|
||||||
Mockito.doAnswer(new Answer() {
|
Mockito.doAnswer(invocationOnMock -> sharePacketJson.toString()).when(sharePacket).serialize();
|
||||||
@Override
|
|
||||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
return sharePacketJson.toString();
|
|
||||||
}
|
|
||||||
}).when(sharePacket).serialize();
|
|
||||||
Mockito.when(sharePacket.getPayload()).thenReturn(new ByteArrayInputStream(data));
|
Mockito.when(sharePacket.getPayload()).thenReturn(new ByteArrayInputStream(data));
|
||||||
Mockito.when(sharePacket.getPayloadSize()).thenReturn((long) data.length);
|
Mockito.when(sharePacket.getPayloadSize()).thenReturn((long) data.length);
|
||||||
Mockito.doAnswer(new Answer() {
|
Mockito.doAnswer(invocationOnMock -> sharePacketJson.getJSONObject("payloadTransferInfo")).when(sharePacket).getPayloadTransferInfo();
|
||||||
@Override
|
Mockito.doAnswer(invocationOnMock -> {
|
||||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
return sharePacketJson.getJSONObject("payloadTransferInfo");
|
|
||||||
}
|
|
||||||
}).when(sharePacket).getPayloadTransferInfo();
|
|
||||||
Mockito.doAnswer(new Answer() {
|
|
||||||
@Override
|
|
||||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
JSONObject object = (JSONObject) invocationOnMock.getArguments()[0];
|
JSONObject object = (JSONObject) invocationOnMock.getArguments()[0];
|
||||||
|
|
||||||
sharePacketJson.put("payloadTransferInfo", object);
|
sharePacketJson.put("payloadTransferInfo", object);
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}).when(sharePacket).setPayloadTransferInfo(Mockito.any(JSONObject.class));
|
}).when(sharePacket).setPayloadTransferInfo(Mockito.any(JSONObject.class));
|
||||||
|
|
||||||
Mockito.doAnswer(new Answer() {
|
Mockito.doAnswer(invocationOnMock -> {
|
||||||
@Override
|
|
||||||
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
|
|
||||||
|
|
||||||
Log.e("LanLinkTest", "Write to stream");
|
Log.e("LanLinkTest", "Write to stream");
|
||||||
String stringNetworkPacket = new String((byte[]) invocationOnMock.getArguments()[0]);
|
String stringNetworkPacket = new String((byte[]) invocationOnMock.getArguments()[0]);
|
||||||
@ -240,7 +225,6 @@ public class LanLinkTest extends AndroidTestCase {
|
|||||||
downloader.start();
|
downloader.start();
|
||||||
|
|
||||||
return stringNetworkPacket.length();
|
return stringNetworkPacket.length();
|
||||||
}
|
|
||||||
}).when(goodOutputStream).write(Mockito.any(byte[].class));
|
}).when(goodOutputStream).write(Mockito.any(byte[].class));
|
||||||
|
|
||||||
goodLanLink.sendPacket(sharePacket, callback);
|
goodLanLink.sendPacket(sharePacket, callback);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user