use of org.kde.kdeconnect.Helpers.SafeTextChecker in project kdeconnect-android by KDE.
the class SendKeystrokesToHostActivity method onStart.
// needed for this.getReferrer()
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP_MR1)
@Override
protected void onStart() {
super.onStart();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (!prefs.getBoolean(getString(R.string.pref_sendkeystrokes_enabled), true)) {
Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_disabled_toast, Toast.LENGTH_LONG).show();
finish();
} else {
final Intent intent = getIntent();
String type = intent.getType();
if ("text/x-keystrokes".equals(type)) {
String toSend = intent.getStringExtra(Intent.EXTRA_TEXT);
binding.textToSend.setText(toSend);
// (contentIsOkay gets used in updateComputerList again)
if (prefs.getBoolean(getString(R.string.pref_send_safe_text_immediately), true)) {
SafeTextChecker safeTextChecker = new SafeTextChecker(SAFE_CHARS, MAX_SAFE_LENGTH);
contentIsOkay = safeTextChecker.isSafe(toSend);
} else {
contentIsOkay = false;
}
// If we trust the sending app, check if there is only one device paired / reachable...
if (contentIsOkay) {
List<Device> reachableDevices = BackgroundService.getInstance().getDevices().values().stream().filter(Device::isReachable).limit(// we only need the first two; if its more than one, we need to show the user the device-selection
2).collect(Collectors.toList());
// if its exactly one just send the text to it
if (reachableDevices.size() == 1) {
// send the text and close this activity
sendKeys(reachableDevices.get(0));
this.finish();
return;
}
}
// subscribe to new connected devices
BackgroundService.RunCommand(this, service -> {
service.onNetworkChange();
service.addDeviceListChangedCallback("SendKeystrokesToHostActivity", this::updateComputerList);
});
// list all currently connected devices
updateComputerList();
} else {
Toast.makeText(getApplicationContext(), R.string.sendkeystrokes_wrong_data, Toast.LENGTH_LONG).show();
finish();
}
}
}
Aggregations