Differential D13505 Diff 41919 src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandUrlActivity.java
Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/RunCommandPlugin/RunCommandUrlActivity.java
- This file was added.
1 | package org.kde.kdeconnect.Plugins.RunCommandPlugin; | ||||
---|---|---|---|---|---|
2 | | ||||
3 | import android.net.Uri; | ||||
4 | import android.os.Bundle; | ||||
5 | import android.os.Vibrator; | ||||
6 | import android.support.annotation.Nullable; | ||||
7 | import android.support.v7.app.AppCompatActivity; | ||||
8 | import android.util.Log; | ||||
9 | import android.view.Gravity; | ||||
10 | import android.widget.TextView; | ||||
11 | | ||||
12 | import org.kde.kdeconnect.BackgroundService; | ||||
13 | import org.kde.kdeconnect.Device; | ||||
14 | import org.kde.kdeconnect_tp.R; | ||||
15 | | ||||
16 | public class RunCommandUrlActivity extends AppCompatActivity { | ||||
17 | | ||||
18 | @Override | ||||
19 | protected void onCreate(@Nullable Bundle savedInstanceState) { | ||||
20 | super.onCreate(savedInstanceState); | ||||
21 | | ||||
22 | if (getIntent().getAction() != null) { | ||||
23 | try { | ||||
24 | Uri uri = getIntent().getData(); | ||||
25 | String deviceId = uri.getPathSegments().get(0); | ||||
26 | | ||||
27 | BackgroundService.RunCommand(this, service -> { | ||||
28 | final Device device = service.getDevice(deviceId); | ||||
29 | | ||||
30 | if(device == null) { | ||||
31 | error(R.string.runcommand_nosuchdevice); | ||||
32 | return; | ||||
33 | } | ||||
34 | | ||||
35 | if (!device.isPaired()) { | ||||
36 | error(R.string.runcommand_notpaired); | ||||
37 | return; | ||||
38 | } | ||||
39 | | ||||
40 | if (!device.isReachable()) { | ||||
41 | error(R.string.runcommand_notreachable); | ||||
42 | return; | ||||
43 | } | ||||
44 | | ||||
45 | final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class); | ||||
46 | if (plugin == null) { | ||||
47 | error(R.string.runcommand_noruncommandplugin); | ||||
48 | return; | ||||
49 | } | ||||
50 | | ||||
51 | plugin.runCommand(uri.getPathSegments().get(1)); | ||||
52 | RunCommandUrlActivity.this.finish(); | ||||
53 | | ||||
54 | if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { | ||||
55 | Vibrator vibrator = RunCommandUrlActivity.this.getSystemService(Vibrator.class); | ||||
56 | if(vibrator != null && vibrator.hasVibrator()) { | ||||
57 | vibrator.vibrate(100); | ||||
58 | } | ||||
59 | } | ||||
60 | }); | ||||
61 | } catch (Exception e) { | ||||
62 | Log.e("RuncommandPlugin", "Exception", e); | ||||
63 | } | ||||
64 | } | ||||
65 | } | ||||
66 | | ||||
67 | void error(int message) { | ||||
68 | TextView view = new TextView(this); | ||||
69 | view.setText(message); | ||||
70 | view.setGravity(Gravity.CENTER); | ||||
71 | setContentView(view); | ||||
72 | } | ||||
73 | | ||||
74 | } |