mirror of
https://github.com/KDE/kdeconnect-android
synced 2025-08-31 06:05:12 +00:00
Add more ways to send clipboard
Add the ability to send the clipboard to the device via the quick settings tile and via the menu on the device page BUG: 439951
This commit is contained in:
committed by
Albert Vaca Cintora
parent
b3a3884333
commit
492555ab9b
@@ -386,6 +386,16 @@
|
||||
android:name="android.support.PARENT_ACTIVITY"
|
||||
android:value="org.kde.kdeconnect.UserInterface.MainActivity" />
|
||||
</activity>
|
||||
|
||||
<service
|
||||
android:name="org.kde.kdeconnect.Plugins.ClibpoardPlugin.ClipboardTileService"
|
||||
android:icon="@drawable/ic_baseline_content_paste_24"
|
||||
android:label="@string/send_clipboard"
|
||||
android:permission="android.permission.BIND_QUICK_SETTINGS_TILE">
|
||||
<intent-filter>
|
||||
<action android:name="android.service.quicksettings.action.QS_TILE" />
|
||||
</intent-filter>
|
||||
</service>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
|
10
res/drawable/ic_baseline_content_paste_24.xml
Normal file
10
res/drawable/ic_baseline_content_paste_24.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="?attr/colorControlNormal">
|
||||
<path
|
||||
android:fillColor="@android:color/white"
|
||||
android:pathData="M19,2h-4.18C14.4,0.84 13.3,0 12,0c-1.3,0 -2.4,0.84 -2.82,2L5,2c-1.1,0 -2,0.9 -2,2v16c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2L21,4c0,-1.1 -0.9,-2 -2,-2zM12,2c0.55,0 1,0.45 1,1s-0.45,1 -1,1 -1,-0.45 -1,-1 0.45,-1 1,-1zM19,20L5,20L5,4h2v3h10L17,4h2v16z"/>
|
||||
</vector>
|
@@ -528,4 +528,6 @@
|
||||
<string name="saikrishna_arcot_task">Support for using the keyboard in the remote input plugin, bug fixes and general improvements</string>
|
||||
<string name="everyone_else">Everyone else who has contributed to KDE Connect over the years</string>
|
||||
|
||||
<string name="send_clipboard">Send clipboard</string>
|
||||
|
||||
</resources>
|
||||
|
@@ -31,7 +31,7 @@ import java.util.ArrayList;
|
||||
This permission can be gained by only from the adb by the user.
|
||||
https://www.reddit.com/r/AndroidBusters/comments/fh60lt/how_to_solve_a_problem_with_the_clipboard_on/
|
||||
|
||||
Currently this activity is bering triggered from a button in Foreground Notification.
|
||||
Currently this activity is bering triggered from a button in Foreground Notification or quick settings tile.
|
||||
* */
|
||||
public class ClipboardFloatingActivity extends AppCompatActivity {
|
||||
|
||||
|
@@ -8,6 +8,13 @@ package org.kde.kdeconnect.Plugins.ClibpoardPlugin;
|
||||
|
||||
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import org.kde.kdeconnect.NetworkPacket;
|
||||
import org.kde.kdeconnect.Plugins.Plugin;
|
||||
import org.kde.kdeconnect.Plugins.PluginFactory;
|
||||
@@ -111,5 +118,34 @@ public class ClipboardPlugin extends Plugin {
|
||||
return new String[]{PACKET_TYPE_CLIPBOARD, PACKET_TYPE_CLIPBOARD_CONNECT};
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getActionName() {
|
||||
return context.getString(R.string.send_clipboard);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasMainActivity() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean displayInContextMenu() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void startMainActivity(Activity activity) {
|
||||
if (device != null) {
|
||||
ClipboardManager clipboardManager = ContextCompat.getSystemService(this.context,
|
||||
ClipboardManager.class);
|
||||
ClipData.Item item;
|
||||
if (clipboardManager.hasPrimaryClip()) {
|
||||
item = clipboardManager.getPrimaryClip().getItemAt(0);
|
||||
String content = item.coerceToText(this.context).toString();
|
||||
this.propagateClipboard(content);
|
||||
Toast.makeText(this.context, R.string.pref_plugin_clipboard_sent, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Maxim Leshchenko <cnmaks90@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
|
||||
*/
|
||||
|
||||
package org.kde.kdeconnect.Plugins.ClibpoardPlugin
|
||||
|
||||
import android.content.Intent
|
||||
import android.os.Build
|
||||
import android.service.quicksettings.TileService
|
||||
import androidx.annotation.RequiresApi
|
||||
import org.kde.kdeconnect.BackgroundService
|
||||
|
||||
@RequiresApi(Build.VERSION_CODES.N)
|
||||
class ClipboardTileService : TileService() {
|
||||
override fun onClick() {
|
||||
super.onClick()
|
||||
|
||||
startActivityAndCollapse(Intent(this, ClipboardFloatingActivity::class.java).apply {
|
||||
flags = Intent.FLAG_ACTIVITY_CLEAR_TASK or Intent.FLAG_ACTIVITY_NEW_TASK
|
||||
putExtra("connectedDeviceIds", ArrayList(BackgroundService.getInstance().devices.values
|
||||
.filter { it.isReachable && it.isPaired }
|
||||
.map { it.deviceId })
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user