Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
Show All 22 Lines | |||||
23 | import android.content.SharedPreferences; | 23 | import android.content.SharedPreferences; | ||
24 | import android.graphics.Bitmap; | 24 | import android.graphics.Bitmap; | ||
25 | import android.graphics.drawable.Drawable; | 25 | import android.graphics.drawable.Drawable; | ||
26 | import android.os.Bundle; | 26 | import android.os.Bundle; | ||
27 | import android.os.Handler; | 27 | import android.os.Handler; | ||
28 | import android.os.Message; | 28 | import android.os.Message; | ||
29 | import android.preference.PreferenceManager; | 29 | import android.preference.PreferenceManager; | ||
30 | import android.support.annotation.NonNull; | 30 | import android.support.annotation.NonNull; | ||
31 | import android.support.v4.app.FragmentManager; | ||||
31 | import android.support.v4.graphics.drawable.DrawableCompat; | 32 | import android.support.v4.graphics.drawable.DrawableCompat; | ||
32 | import android.support.v7.app.AppCompatActivity; | 33 | import android.support.v7.app.AppCompatActivity; | ||
33 | import android.util.Log; | 34 | import android.util.Log; | ||
34 | import android.view.KeyEvent; | 35 | import android.view.KeyEvent; | ||
35 | import android.view.View; | 36 | import android.view.View; | ||
36 | import android.widget.AdapterView; | 37 | import android.widget.AdapterView; | ||
37 | import android.widget.ArrayAdapter; | 38 | import android.widget.ArrayAdapter; | ||
38 | import android.widget.ImageButton; | 39 | import android.widget.ImageButton; | ||
39 | import android.widget.ImageView; | 40 | import android.widget.ImageView; | ||
40 | import android.widget.SeekBar; | 41 | import android.widget.SeekBar; | ||
41 | import android.widget.Spinner; | 42 | import android.widget.Spinner; | ||
42 | import android.widget.TextView; | 43 | import android.widget.TextView; | ||
43 | 44 | | |||
44 | import org.kde.kdeconnect.Backends.BaseLink; | 45 | import org.kde.kdeconnect.Backends.BaseLink; | ||
45 | import org.kde.kdeconnect.Backends.BaseLinkProvider; | 46 | import org.kde.kdeconnect.Backends.BaseLinkProvider; | ||
46 | import org.kde.kdeconnect.BackgroundService; | 47 | import org.kde.kdeconnect.BackgroundService; | ||
47 | import org.kde.kdeconnect.Device; | 48 | import org.kde.kdeconnect.Device; | ||
49 | import org.kde.kdeconnect.Plugins.SystemvolumePlugin.SystemvolumeFragment; | ||||
48 | import org.kde.kdeconnect.NetworkPacket; | 50 | import org.kde.kdeconnect.NetworkPacket; | ||
49 | import org.kde.kdeconnect.UserInterface.ThemeUtil; | 51 | import org.kde.kdeconnect.UserInterface.ThemeUtil; | ||
50 | import org.kde.kdeconnect_tp.R; | 52 | import org.kde.kdeconnect_tp.R; | ||
51 | 53 | | |||
52 | import java.util.List; | 54 | import java.util.List; | ||
53 | 55 | | |||
54 | public class MprisActivity extends AppCompatActivity { | 56 | public class MprisActivity extends AppCompatActivity { | ||
55 | 57 | | |||
Show All 27 Lines | 83 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | |||
83 | public void onServiceStart(BackgroundService service) { | 85 | public void onServiceStart(BackgroundService service) { | ||
84 | 86 | | |||
85 | final Device device = service.getDevice(deviceId); | 87 | final Device device = service.getDevice(deviceId); | ||
86 | final MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 88 | final MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
87 | if (mpris == null) { | 89 | if (mpris == null) { | ||
88 | Log.e("MprisActivity", "device has no mpris plugin!"); | 90 | Log.e("MprisActivity", "device has no mpris plugin!"); | ||
89 | return; | 91 | return; | ||
90 | } | 92 | } | ||
93 | | ||||
91 | targetPlayer = mpris.getPlayerStatus(targetPlayerName); | 94 | targetPlayer = mpris.getPlayerStatus(targetPlayerName); | ||
92 | 95 | | |||
96 | addSytemvolumeFragment(); | ||||
mtijink: Should use a check if it's available. | |||||
nicolasfella: I do that in the fragment | |||||
mtijink: Yeah, but now the fragment is added even if it won't do anything. | |||||
97 | | ||||
93 | mpris.setPlayerStatusUpdatedHandler("activity", new Handler() { | 98 | mpris.setPlayerStatusUpdatedHandler("activity", new Handler() { | ||
94 | @Override | 99 | @Override | ||
95 | public void handleMessage(Message msg) { | 100 | public void handleMessage(Message msg) { | ||
96 | runOnUiThread(new Runnable() { | 101 | runOnUiThread(new Runnable() { | ||
97 | @Override | 102 | @Override | ||
98 | public void run() { | 103 | public void run() { | ||
99 | updatePlayerStatus(mpris); | 104 | updatePlayerStatus(mpris); | ||
100 | } | 105 | } | ||
▲ Show 20 Lines • Show All 75 Lines • ▼ Show 20 Line(s) | 110 | mpris.setPlayerListUpdatedHandler("activity", new Handler() { | |||
176 | } | 181 | } | ||
177 | }); | 182 | }); | ||
178 | 183 | | |||
179 | } | 184 | } | ||
180 | }); | 185 | }); | ||
181 | 186 | | |||
182 | } | 187 | } | ||
183 | 188 | | |||
189 | private void addSytemvolumeFragment() { | ||||
190 | | ||||
191 | FragmentManager fragmentManager = getSupportFragmentManager(); | ||||
192 | ((SystemvolumeFragment) fragmentManager.findFragmentById(R.id.systemvolume_fragment)).connectToPlugin(deviceId); | ||||
193 | | ||||
194 | } | ||||
195 | | ||||
184 | private final BaseLinkProvider.ConnectionReceiver connectionReceiver = new BaseLinkProvider.ConnectionReceiver() { | 196 | private final BaseLinkProvider.ConnectionReceiver connectionReceiver = new BaseLinkProvider.ConnectionReceiver() { | ||
185 | @Override | 197 | @Override | ||
186 | public void onConnectionReceived(NetworkPacket identityPacket, BaseLink link) { | 198 | public void onConnectionReceived(NetworkPacket identityPacket, BaseLink link) { | ||
187 | connectToPlugin(null); | 199 | connectToPlugin(null); | ||
188 | } | 200 | } | ||
189 | 201 | | |||
190 | @Override | 202 | @Override | ||
191 | public void onConnectionLost(BaseLink link) { | 203 | public void onConnectionLost(BaseLink link) { | ||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Line(s) | 219 | private void updatePlayerStatus(MprisPlugin mpris) { | |||
243 | if (isPlaying) { | 255 | if (isPlaying) { | ||
244 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(R.drawable.ic_pause_black); | 256 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(R.drawable.ic_pause_black); | ||
245 | findViewById(R.id.play_button).setEnabled(playerStatus.isPauseAllowed()); | 257 | findViewById(R.id.play_button).setEnabled(playerStatus.isPauseAllowed()); | ||
246 | } else { | 258 | } else { | ||
247 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(R.drawable.ic_play_black); | 259 | ((ImageButton) findViewById(R.id.play_button)).setImageResource(R.drawable.ic_play_black); | ||
248 | findViewById(R.id.play_button).setEnabled(playerStatus.isPlayAllowed()); | 260 | findViewById(R.id.play_button).setEnabled(playerStatus.isPlayAllowed()); | ||
249 | } | 261 | } | ||
250 | 262 | | |||
251 | findViewById(R.id.volume_layout).setVisibility(playerStatus.isSetVolumeAllowed() ? View.VISIBLE : View.INVISIBLE); | 263 | findViewById(R.id.volume_layout).setVisibility(playerStatus.isSetVolumeAllowed() ? View.VISIBLE : View.GONE); | ||
252 | findViewById(R.id.rew_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | 264 | findViewById(R.id.rew_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | ||
253 | findViewById(R.id.ff_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | 265 | findViewById(R.id.ff_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | ||
254 | 266 | | |||
255 | //Show and hide previous/next buttons simultaneously | 267 | //Show and hide previous/next buttons simultaneously | ||
256 | if (playerStatus.isGoPreviousAllowed() || playerStatus.isGoNextAllowed()) { | 268 | if (playerStatus.isGoPreviousAllowed() || playerStatus.isGoNextAllowed()) { | ||
257 | findViewById(R.id.prev_button).setVisibility(View.VISIBLE); | 269 | findViewById(R.id.prev_button).setVisibility(View.VISIBLE); | ||
258 | findViewById(R.id.prev_button).setEnabled(playerStatus.isGoPreviousAllowed()); | 270 | findViewById(R.id.prev_button).setEnabled(playerStatus.isGoPreviousAllowed()); | ||
259 | findViewById(R.id.next_button).setVisibility(View.VISIBLE); | 271 | findViewById(R.id.next_button).setVisibility(View.VISIBLE); | ||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Line(s) | 405 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | |||
398 | } | 410 | } | ||
399 | }); | 411 | }); | ||
400 | } | 412 | } | ||
401 | }); | 413 | }); | ||
402 | 414 | | |||
403 | ((SeekBar) findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | 415 | ((SeekBar) findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||
404 | @Override | 416 | @Override | ||
405 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | 417 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | ||
406 | } | 418 | } | ||
Some code should be added to hide the "set system volume" controls if the plugin is not available. mtijink: Some code should be added to hide the "set system volume" controls if the plugin is not… | |||||
407 | 419 | | |||
408 | @Override | 420 | @Override | ||
409 | public void onStartTrackingTouch(SeekBar seekBar) { | 421 | public void onStartTrackingTouch(SeekBar seekBar) { | ||
410 | } | 422 | } | ||
411 | 423 | | |||
412 | @Override | 424 | @Override | ||
413 | public void onStopTrackingTouch(final SeekBar seekBar) { | 425 | public void onStopTrackingTouch(final SeekBar seekBar) { | ||
414 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 426 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
▲ Show 20 Lines • Show All 71 Lines • Show Last 20 Lines |
Should use a check if it's available.