diff --git a/res/layout/mpris_control.xml b/res/layout/mpris_control.xml --- a/res/layout/mpris_control.xml +++ b/res/layout/mpris_control.xml @@ -167,19 +167,46 @@ - diff --git a/res/values/strings.xml b/res/values/strings.xml --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -217,4 +217,8 @@ To see phone calls and SMS from the desktop you need to give permission to phone calls and SMS To see a contact name instead of a phone number you need to give access to the phone\'s contacts + System volume: + System volume + Control the system volume of the remote device + diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java @@ -42,6 +42,7 @@ import org.kde.kdeconnect.BackgroundService; import org.kde.kdeconnect.Device; import org.kde.kdeconnect.NetworkPackage; +import org.kde.kdeconnect.Plugins.SystemvolumePlugin.SystemvolumePlugin; import org.kde.kdeconnect_tp.R; import java.util.List; @@ -414,6 +415,32 @@ }); + ((SeekBar)findViewById(R.id.systemvolume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onProgressChanged(final SeekBar seekBar, int i, boolean b) { + BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { + @Override + public void onServiceStart(BackgroundService service) { + Device device = service.getDevice(deviceId); + SystemvolumePlugin volPlugin = device.getPlugin(SystemvolumePlugin.class); + if (volPlugin == null) return; + volPlugin.sendSystemVolumeSet(seekBar.getProgress()); + } + }); + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStopTrackingTouch(final SeekBar seekBar) { + + } + + }); + + positionSeekUpdateRunnable = new Runnable() { @Override public void run() { @@ -472,6 +499,18 @@ protected void onStart() { super.onStart(); BackgroundService.addGuiInUseCounter(this); +// TODO request current system volume +// BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { +// @Override +// public void onServiceStart(BackgroundService service) { +// Device device = service.getDevice(deviceId); +// SystemvolumePlugin volPlugin = device.getPlugin(SystemvolumePlugin.class); +// if (volPlugin != null) { +// volPlugin.askForSystemVolume(); +// } +// } +// }); + } @Override diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -53,10 +53,11 @@ private boolean goNextAllowed = true; private boolean goPreviousAllowed = true; private boolean seekAllowed = true; - private HashMap playerStatusUpdated = new HashMap<>(); + private int systemVolume; + private HashMap playerStatusUpdated = new HashMap<>(); private List playerList = new ArrayList<>(); - private HashMap playerListUpdated = new HashMap<>(); + private HashMap playerListUpdated = new HashMap<>(); @Override public String getDisplayName() { @@ -96,6 +97,7 @@ np.set("action", action); device.sendPackage(np); } + public void sendAction(String action) { sendAction(player, action); } @@ -103,7 +105,7 @@ public void setVolume(int volume) { NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST); np.set("player", player); - np.set("setVolume",volume); + np.set("setVolume", volume); device.sendPackage(np); } @@ -131,7 +133,7 @@ currentSong = np.getString("nowPlaying", currentSong); volume = np.getInt("volume", volume); length = np.getLong("length", length); - if(np.has("pos")){ + if (np.has("pos")) { lastPosition = np.getLong("pos", lastPosition); lastPositionTime = System.currentTimeMillis(); } @@ -144,9 +146,9 @@ for (String key : playerStatusUpdated.keySet()) { try { playerStatusUpdated.get(key).dispatchMessage(new Message()); - } catch(Exception e) { + } catch (Exception e) { e.printStackTrace(); - Log.e("MprisControl","Exception"); + Log.e("MprisControl", "Exception"); playerStatusUpdated.remove(key); } } @@ -158,7 +160,7 @@ boolean equals = false; if (newPlayerList.size() == playerList.size()) { equals = true; - for (int i=0; i + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as + * published by the Free Software Foundation; either version 2 of + * the License or (at your option) version 3 or any later version + * accepted by the membership of KDE e.V. (or its successor approved + * by the membership of KDE e.V.), which shall act as a proxy + * defined in Section 14 of version 3 of the license. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . +*/ + +package org.kde.kdeconnect.Plugins.SystemvolumePlugin; + +import android.util.Log; + +import org.kde.kdeconnect.NetworkPackage; +import org.kde.kdeconnect.Plugins.Plugin; +import org.kde.kdeconnect_tp.R; + + +public class SystemvolumePlugin extends Plugin { + + public final static String PACKAGE_TYPE_SYSTEMVOLUME = "kdeconnect.systemvolume"; + + private int systemVolume; + + @Override + public String getDisplayName() { + return context.getResources().getString(R.string.pref_plugin_systemvolume); + } + + @Override + public String getDescription() { + return context.getResources().getString(R.string.pref_plugin_systemvolume_desc); + } + + @Override + public boolean onPackageReceived(NetworkPackage np) { + + if (np.has("volume")){ + systemVolume = np.getInt("volume"); + } + + return true; + + } + + public void sendSystemVolumeSet(int volume) { + + Log.d("SystemvolumePlugin", "Sending SET package with volume: "+volume); + + NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_SYSTEMVOLUME); + np.set("volume", volume); + np.set("request", false); + device.sendPackage(np); + + } + + public int getSystemvolume() { + return systemVolume; + } + + public void askForSystemVolume(){ + NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_SYSTEMVOLUME); + np.set("request", true); + device.sendPackage(np); + } + + @Override + public boolean hasMainActivity() { + return false; + } + + @Override + public boolean displayInContextMenu() { + return false; + } + + @Override + public String[] getSupportedPackageTypes() { + return new String[]{PACKAGE_TYPE_SYSTEMVOLUME}; + } + + @Override + public String[] getOutgoingPackageTypes() { + return new String[]{PACKAGE_TYPE_SYSTEMVOLUME}; + } + + +}