File indexing completed on 2024-12-22 04:41:40
0001 /* 0002 * SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de> 0003 * 0004 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0005 */ 0006 0007 package org.kde.kdeconnect.Plugins.RunCommandPlugin; 0008 0009 import android.net.Uri; 0010 import android.os.Bundle; 0011 import android.os.Vibrator; 0012 import android.util.Log; 0013 import android.view.Gravity; 0014 import android.widget.TextView; 0015 0016 import androidx.annotation.Nullable; 0017 import androidx.appcompat.app.AppCompatActivity; 0018 0019 import org.kde.kdeconnect.Device; 0020 import org.kde.kdeconnect.KdeConnect; 0021 import org.kde.kdeconnect_tp.R; 0022 0023 public class RunCommandUrlActivity extends AppCompatActivity { 0024 0025 @Override 0026 protected void onCreate(@Nullable Bundle savedInstanceState) { 0027 super.onCreate(savedInstanceState); 0028 0029 if (getIntent().getAction() != null) { 0030 try { 0031 Uri uri = getIntent().getData(); 0032 String deviceId = uri.getPathSegments().get(0); 0033 0034 final Device device = KdeConnect.getInstance().getDevice(deviceId); 0035 0036 if(device == null) { 0037 error(R.string.runcommand_nosuchdevice); 0038 return; 0039 } 0040 0041 if (!device.isPaired()) { 0042 error(R.string.runcommand_notpaired); 0043 return; 0044 } 0045 0046 if (!device.isReachable()) { 0047 error(R.string.runcommand_notreachable); 0048 return; 0049 } 0050 0051 final RunCommandPlugin plugin = device.getPlugin(RunCommandPlugin.class); 0052 if (plugin == null) { 0053 error(R.string.runcommand_noruncommandplugin); 0054 return; 0055 } 0056 0057 plugin.runCommand(uri.getPathSegments().get(1)); 0058 RunCommandUrlActivity.this.finish(); 0059 0060 if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { 0061 Vibrator vibrator = getSystemService(Vibrator.class); 0062 if(vibrator != null && vibrator.hasVibrator()) { 0063 vibrator.vibrate(100); 0064 } 0065 } 0066 } catch (Exception e) { 0067 Log.e("RuncommandPlugin", "Exception", e); 0068 } 0069 } 0070 } 0071 0072 private void error(int message) { 0073 TextView view = new TextView(this); 0074 view.setText(message); 0075 view.setGravity(Gravity.CENTER); 0076 setContentView(view); 0077 } 0078 0079 }