use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class ContactsPlugin method handleRequestVCardsByUIDs.
private boolean handleRequestVCardsByUIDs(NetworkPacket np) {
if (!np.has("uids")) {
Log.e("ContactsPlugin", "handleRequestNamesByUIDs received a malformed packet with no uids key");
return false;
}
List<String> uIDsAsStrings = np.getStringList("uids");
// Convert to Collection<uIDs> to call getVCardsForContactIDs
Set<uID> uIDs = new HashSet<>(uIDsAsStrings.size());
for (String uID : uIDsAsStrings) {
uIDs.add(new uID(uID));
}
Map<uID, VCardBuilder> uIDsToVCards = ContactsHelper.getVCardsForContactIDs(context, uIDs);
// ContactsHelper.getVCardsForContactIDs(..) is allowed to reply without
// some of the requested uIDs if they were not in the database, so update our list
uIDsAsStrings = new ArrayList<>(uIDsToVCards.size());
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_CONTACTS_RESPONSE_VCARDS);
// Add the vcards to the packet
for (uID uID : uIDsToVCards.keySet()) {
VCardBuilder vcard = uIDsToVCards.get(uID);
try {
vcard = this.addVCardMetadata(vcard, uID);
// Store this as a valid uID
uIDsAsStrings.add(uID.toString());
// Add the uid -> vcard pairing to the packet
reply.set(uID.toString(), vcard.toString());
} catch (ContactsHelper.ContactNotFoundException e) {
e.printStackTrace();
}
}
// Add the valid uIDs to the packet
reply.set("uids", uIDsAsStrings);
device.sendPacket(reply);
return true;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class ContactsPlugin method handleRequestAllUIDsTimestamps.
/**
* Return a unique identifier (Contacts.LOOKUP_KEY) for all contacts in the Contacts database
* <p>
* The identifiers returned can be used in future requests to get more information
* about the contact
*
* @param np The package containing the request
* @return true if successfully handled, false otherwise
*/
@SuppressWarnings("SameReturnValue")
private boolean handleRequestAllUIDsTimestamps(@SuppressWarnings("unused") NetworkPacket np) {
NetworkPacket reply = new NetworkPacket(PACKET_TYPE_CONTACTS_RESPONSE_UIDS_TIMESTAMPS);
Map<uID, Long> uIDsToTimestamps = ContactsHelper.getAllContactTimestamps(context);
int contactCount = uIDsToTimestamps.size();
List<String> uIDs = new ArrayList<>(contactCount);
for (uID contactID : uIDsToTimestamps.keySet()) {
Long timestamp = uIDsToTimestamps.get(contactID);
reply.set(contactID.toString(), timestamp);
uIDs.add(contactID.toString());
}
reply.set("uids", uIDs);
device.sendPacket(reply);
return true;
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class ComposeSendActivity method sendChars.
public void sendChars(CharSequence chars) {
final NetworkPacket np = new NetworkPacket(MousePadPlugin.PACKET_TYPE_MOUSEPAD_REQUEST);
np.set("key", chars.toString());
sendKeyPressPacket(np);
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SharePlugin method sendUriList.
void sendUriList(final ArrayList<Uri> uriList) {
CompositeUploadFileJob job;
if (uploadFileJob == null) {
job = new CompositeUploadFileJob(device, this.receiveFileJobCallback);
} else {
job = uploadFileJob;
}
// Read all the data early, as we only have permissions to do it while the activity is alive
for (Uri uri : uriList) {
NetworkPacket np = FilesHelper.uriToNetworkPacket(context, uri, PACKET_TYPE_SHARE_REQUEST);
if (np != null) {
job.addNetworkPacket(np);
}
}
if (job != uploadFileJob) {
uploadFileJob = job;
backgroundJobHandler.runJob(uploadFileJob);
}
}
use of org.kde.kdeconnect.NetworkPacket in project kdeconnect-android by KDE.
the class SharePlugin method share.
public void share(Intent intent) {
Bundle extras = intent.getExtras();
if (extras != null) {
if (extras.containsKey(Intent.EXTRA_STREAM)) {
try {
ArrayList<Uri> uriList;
if (!Intent.ACTION_SEND.equals(intent.getAction())) {
uriList = intent.getParcelableArrayListExtra(Intent.EXTRA_STREAM);
} else {
Uri uri = extras.getParcelable(Intent.EXTRA_STREAM);
uriList = new ArrayList<>();
uriList.add(uri);
}
sendUriList(uriList);
} catch (Exception e) {
Log.e("ShareActivity", "Exception");
e.printStackTrace();
}
} else if (extras.containsKey(Intent.EXTRA_TEXT)) {
String text = extras.getString(Intent.EXTRA_TEXT);
String subject = extras.getString(Intent.EXTRA_SUBJECT);
// Hack: Detect shared youtube videos, so we can open them in the browser instead of as text
if (StringUtils.endsWith(subject, "YouTube")) {
int index = text.indexOf(": http://youtu.be/");
if (index > 0) {
// Skip ": "
text = text.substring(index + 2);
}
}
boolean isUrl;
try {
new URL(text);
isUrl = true;
} catch (Exception e) {
isUrl = false;
}
NetworkPacket np = new NetworkPacket(SharePlugin.PACKET_TYPE_SHARE_REQUEST);
if (isUrl) {
np.set("url", text);
} else {
np.set("text", text);
}
device.sendPacket(np);
}
}
}
Aggregations