Differential D6743 Diff 17349 src/org/kde/kdeconnect/Plugins/SharePlugin/ShareChooserTargetService.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/SharePlugin/ShareChooserTargetService.java
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * Copyright 2017 Nicolas Fella <nicolas.fella@gmx.de> | ||||
3 | * | ||||
4 | * This program is free software; you can redistribute it and/or | ||||
5 | * modify it under the terms of the GNU General Public License as | ||||
6 | * published by the Free Software Foundation; either version 2 of | ||||
7 | * the License or (at your option) version 3 or any later version | ||||
8 | * accepted by the membership of KDE e.V. (or its successor approved | ||||
9 | * by the membership of KDE e.V.), which shall act as a proxy | ||||
10 | * defined in Section 14 of version 3 of the license. | ||||
11 | * | ||||
12 | * This program is distributed in the hope that it will be useful, | ||||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
15 | * GNU General Public License for more details. | ||||
16 | * | ||||
17 | * You should have received a copy of the GNU General Public License | ||||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | package org.kde.kdeconnect.Plugins.SharePlugin; | ||||
22 | | ||||
23 | import android.annotation.TargetApi; | ||||
24 | import android.content.ComponentName; | ||||
25 | import android.content.IntentFilter; | ||||
26 | import android.graphics.drawable.Icon; | ||||
27 | import android.os.Bundle; | ||||
28 | import android.service.chooser.ChooserTarget; | ||||
29 | import android.service.chooser.ChooserTargetService; | ||||
30 | import android.util.Log; | ||||
31 | | ||||
32 | import org.kde.kdeconnect.BackgroundService; | ||||
33 | import org.kde.kdeconnect.Device; | ||||
34 | import org.kde.kdeconnect_tp.R; | ||||
35 | | ||||
36 | import java.util.ArrayList; | ||||
37 | import java.util.List; | ||||
38 | | ||||
39 | @TargetApi(23) | ||||
40 | public class ShareChooserTargetService extends ChooserTargetService { | ||||
41 | @Override | ||||
42 | public List<ChooserTarget> onGetChooserTargets(ComponentName targetActivityName, IntentFilter matchedFilter) { | ||||
43 | Log.d("DirectShare", "invoked"); | ||||
44 | final List<ChooserTarget> targets = new ArrayList<>(); | ||||
45 | for(Device d: BackgroundService.getInstance().getDevices().values()){ | ||||
46 | if(d.isReachable() && d.isPaired()) { | ||||
47 | Log.d("DirectShare", d.getName()); | ||||
48 | final String targetName = d.getName(); | ||||
49 | final Icon targetIcon = Icon.createWithResource(this, R.drawable.icon); | ||||
50 | final float targetRanking = 1; | ||||
51 | final ComponentName targetComponentName = new ComponentName(getPackageName(), | ||||
52 | ShareActivity.class.getCanonicalName()); | ||||
53 | final Bundle targetExtras = new Bundle(); | ||||
54 | targetExtras.putString("deviceId", d.getDeviceId()); | ||||
55 | targets.add(new ChooserTarget( | ||||
56 | targetName, targetIcon, targetRanking, targetComponentName, targetExtras | ||||
57 | )); | ||||
58 | } | ||||
59 | } | ||||
60 | | ||||
61 | return targets; | ||||
62 | } | ||||
63 | } | ||||
64 | No newline at end of file |