File indexing completed on 2024-12-22 04:41:38

0001 /*
0002  * SPDX-FileCopyrightText: 2014 Ahmed I. Khalil <ahmedibrahimkhali@gmail.com>
0003  * SPDX-FileCopyrightText: 2020 Sylvia van Os <sylvia@hackerchick.me>
0004  *
0005  * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
0006 */
0007 
0008 package org.kde.kdeconnect.Plugins.BigscreenPlugin;
0009 
0010 
0011 import static org.kde.kdeconnect.Plugins.MousePadPlugin.KeyListenerView.SpecialKeysMap;
0012 
0013 import android.Manifest;
0014 import android.app.Activity;
0015 import android.content.Context;
0016 import android.content.Intent;
0017 import android.view.KeyEvent;
0018 
0019 import androidx.annotation.DrawableRes;
0020 import androidx.annotation.NonNull;
0021 
0022 import org.kde.kdeconnect.DeviceType;
0023 import org.kde.kdeconnect.NetworkPacket;
0024 import org.kde.kdeconnect.Plugins.Plugin;
0025 import org.kde.kdeconnect.Plugins.PluginFactory;
0026 import org.kde.kdeconnect_tp.R;
0027 
0028 @PluginFactory.LoadablePlugin
0029 public class BigscreenPlugin extends Plugin {
0030 
0031     private final static String PACKET_TYPE_MOUSEPAD_REQUEST = "kdeconnect.mousepad.request";
0032     private final static String PACKET_TYPE_BIGSCREEN_STT = "kdeconnect.bigscreen.stt";
0033 
0034     @Override
0035     public boolean isCompatible() {
0036         return device.getDeviceType().equals(DeviceType.TV) && super.isCompatible();
0037     }
0038 
0039     @Override
0040     protected int getOptionalPermissionExplanation() {
0041         return R.string.bigscreen_optional_permission_explanation;
0042     }
0043 
0044     @Override
0045     public @NonNull String getDisplayName() {
0046         return context.getString(R.string.pref_plugin_bigscreen);
0047     }
0048 
0049     @Override
0050     public @NonNull String getDescription() {
0051         return context.getString(R.string.pref_plugin_bigscreen_desc);
0052     }
0053 
0054     @Override
0055     public @DrawableRes int getIcon() {
0056         return R.drawable.ic_presenter_24dp;
0057     }
0058 
0059     @Override
0060     public boolean isEnabledByDefault() {
0061         return true;
0062     }
0063 
0064     @Override
0065     public boolean hasSettings() {
0066         return false;
0067     }
0068 
0069     @Override
0070     public boolean displayAsButton(Context context) {
0071         return true;
0072     }
0073 
0074     @Override
0075     public void startMainActivity(Activity parentActivity) {
0076         Intent intent = new Intent(parentActivity, BigscreenActivity.class);
0077         intent.putExtra("deviceId", device.getDeviceId());
0078         parentActivity.startActivity(intent);
0079     }
0080 
0081     @Override
0082     public @NonNull String[] getSupportedPacketTypes() {  return new String[]{PACKET_TYPE_BIGSCREEN_STT}; }
0083 
0084     @Override
0085     public @NonNull String[] getOutgoingPacketTypes() {
0086         return new String[]{PACKET_TYPE_MOUSEPAD_REQUEST, PACKET_TYPE_BIGSCREEN_STT};
0087     }
0088 
0089     @Override
0090     public @NonNull String getActionName() {
0091         return context.getString(R.string.pref_plugin_bigscreen);
0092     }
0093 
0094     public @NonNull String[] getOptionalPermissions() {
0095         return new String[]{Manifest.permission.RECORD_AUDIO};
0096     }
0097 
0098     public Boolean hasMicPermission() {
0099         return isPermissionGranted(Manifest.permission.RECORD_AUDIO);
0100     }
0101 
0102 
0103     public void sendLeft() {
0104         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0105         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_DPAD_LEFT));
0106         device.sendPacket(np);
0107     }
0108 
0109     public void sendRight() {
0110         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0111         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_DPAD_RIGHT));
0112         device.sendPacket(np);
0113     }
0114 
0115     public void sendUp() {
0116         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0117         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_DPAD_UP));
0118         device.sendPacket(np);
0119     }
0120 
0121     public void sendDown() {
0122         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0123         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_DPAD_DOWN));
0124         device.sendPacket(np);
0125     }
0126 
0127     public void sendSelect() {
0128         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0129         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_ENTER));
0130         device.sendPacket(np);
0131     }
0132 
0133     public void sendHome() {
0134         NetworkPacket np = new NetworkPacket(PACKET_TYPE_MOUSEPAD_REQUEST);
0135         np.set("alt", true);
0136         np.set("specialKey", SpecialKeysMap.get(KeyEvent.KEYCODE_F4));
0137         device.sendPacket(np);
0138     }
0139 
0140     public void sendSTT(String content) {
0141         NetworkPacket np = new NetworkPacket(PACKET_TYPE_BIGSCREEN_STT);
0142         np.set("type", "stt");
0143         np.set("content", content);
0144         device.sendPacket(np);
0145     }
0146 }