Changeset View
Changeset View
Standalone View
Standalone View
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
Show First 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | |||||
53 | public class MprisActivity extends AppCompatActivity { | 53 | public class MprisActivity extends AppCompatActivity { | ||
54 | 54 | | |||
55 | private String deviceId; | 55 | private String deviceId; | ||
56 | private final Handler positionSeekUpdateHandler = new Handler(); | 56 | private final Handler positionSeekUpdateHandler = new Handler(); | ||
57 | private Runnable positionSeekUpdateRunnable = null; | 57 | private Runnable positionSeekUpdateRunnable = null; | ||
58 | private MprisPlugin.MprisPlayer targetPlayer = null; | 58 | private MprisPlugin.MprisPlayer targetPlayer = null; | ||
59 | 59 | | |||
60 | private static String milisToProgress(long milis) { | 60 | private static String milisToProgress(long milis) { | ||
61 | int length = (int)(milis / 1000); //From milis to seconds | 61 | int length = (int) (milis / 1000); //From milis to seconds | ||
62 | StringBuilder text = new StringBuilder(); | 62 | StringBuilder text = new StringBuilder(); | ||
63 | int minutes = length / 60; | 63 | int minutes = length / 60; | ||
64 | if (minutes > 60) { | 64 | if (minutes > 60) { | ||
65 | int hours = minutes / 60; | 65 | int hours = minutes / 60; | ||
66 | minutes = minutes % 60; | 66 | minutes = minutes % 60; | ||
67 | text.append(hours).append(':'); | 67 | text.append(hours).append(':'); | ||
68 | if (minutes < 10) text.append('0'); | 68 | if (minutes < 10) text.append('0'); | ||
69 | } | 69 | } | ||
70 | text.append(minutes).append(':'); | 70 | text.append(minutes).append(':'); | ||
71 | int seconds = (length % 60); | 71 | int seconds = (length % 60); | ||
72 | if(seconds < 10) text.append('0'); // needed to show length properly (eg 4:05 instead of 4:5) | 72 | if (seconds < 10) | ||
73 | text.append('0'); // needed to show length properly (eg 4:05 instead of 4:5) | ||||
73 | text.append(seconds); | 74 | text.append(seconds); | ||
74 | return text.toString(); | 75 | return text.toString(); | ||
75 | } | 76 | } | ||
77 | | ||||
76 | protected void connectToPlugin(final String targetPlayerName) { | 78 | protected void connectToPlugin(final String targetPlayerName) { | ||
77 | 79 | | |||
78 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | 80 | BackgroundService.RunCommand(this, new BackgroundService.InstanceCallback() { | ||
79 | @Override | 81 | @Override | ||
80 | public void onServiceStart(BackgroundService service) { | 82 | public void onServiceStart(BackgroundService service) { | ||
81 | 83 | | |||
82 | final Device device = service.getDevice(deviceId); | 84 | final Device device = service.getDevice(deviceId); | ||
83 | final MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | 85 | final MprisPlugin mpris = device.getPlugin(MprisPlugin.class); | ||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 216 | if (albumArt == null) { | |||
216 | DrawableCompat.setTint(placeholder_art, getResources().getColor(R.color.primary)); | 218 | DrawableCompat.setTint(placeholder_art, getResources().getColor(R.color.primary)); | ||
217 | ((ImageView) findViewById(R.id.album_art)).setImageDrawable(placeholder_art); | 219 | ((ImageView) findViewById(R.id.album_art)).setImageDrawable(placeholder_art); | ||
218 | } else { | 220 | } else { | ||
219 | ((ImageView) findViewById(R.id.album_art)).setImageBitmap(albumArt); | 221 | ((ImageView) findViewById(R.id.album_art)).setImageBitmap(albumArt); | ||
220 | } | 222 | } | ||
221 | 223 | | |||
222 | if (playerStatus.isSeekAllowed()) { | 224 | if (playerStatus.isSeekAllowed()) { | ||
223 | ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(playerStatus.getLength())); | 225 | ((TextView) findViewById(R.id.time_textview)).setText(milisToProgress(playerStatus.getLength())); | ||
224 | SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | 226 | SeekBar positionSeek = (SeekBar) findViewById(R.id.positionSeek); | ||
225 | positionSeek.setMax((int)(playerStatus.getLength())); | 227 | positionSeek.setMax((int) (playerStatus.getLength())); | ||
226 | positionSeek.setProgress((int)(playerStatus.getPosition())); | 228 | positionSeek.setProgress((int) (playerStatus.getPosition())); | ||
227 | findViewById(R.id.progress_slider).setVisibility(View.VISIBLE); | 229 | findViewById(R.id.progress_slider).setVisibility(View.VISIBLE); | ||
228 | } else { | 230 | } else { | ||
229 | findViewById(R.id.progress_slider).setVisibility(View.GONE); | 231 | findViewById(R.id.progress_slider).setVisibility(View.GONE); | ||
230 | } | 232 | } | ||
231 | 233 | | |||
232 | int volume = playerStatus.getVolume(); | 234 | int volume = playerStatus.getVolume(); | ||
233 | ((SeekBar) findViewById(R.id.volume_seek)).setProgress(volume); | 235 | ((SeekBar) findViewById(R.id.volume_seek)).setProgress(volume); | ||
234 | 236 | | |||
Show All 11 Lines | |||||
246 | findViewById(R.id.ff_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | 248 | findViewById(R.id.ff_button).setVisibility(playerStatus.isSeekAllowed() ? View.VISIBLE : View.GONE); | ||
247 | findViewById(R.id.next_button).setVisibility(playerStatus.isGoNextAllowed() ? View.VISIBLE : View.GONE); | 249 | findViewById(R.id.next_button).setVisibility(playerStatus.isGoNextAllowed() ? View.VISIBLE : View.GONE); | ||
248 | findViewById(R.id.prev_button).setVisibility(playerStatus.isGoPreviousAllowed() ? View.VISIBLE : View.GONE); | 250 | findViewById(R.id.prev_button).setVisibility(playerStatus.isGoPreviousAllowed() ? View.VISIBLE : View.GONE); | ||
249 | } | 251 | } | ||
250 | 252 | | |||
251 | /** | 253 | /** | ||
252 | * Change current volume with provided step. | 254 | * Change current volume with provided step. | ||
253 | * | 255 | * | ||
254 | * @param step step size volume change | 256 | * @param step step size volume change | ||
255 | */ | 257 | */ | ||
256 | private void updateVolume(int step) { | 258 | private void updateVolume(int step) { | ||
257 | if (targetPlayer == null) { | 259 | if (targetPlayer == null) { | ||
258 | return; | 260 | return; | ||
259 | } | 261 | } | ||
260 | final int currentVolume = targetPlayer.getVolume(); | 262 | final int currentVolume = targetPlayer.getVolume(); | ||
261 | 263 | | |||
262 | if(currentVolume < 100 || currentVolume > 0) { | 264 | if (currentVolume < 100 || currentVolume > 0) { | ||
263 | int newVolume = currentVolume + step; | 265 | int newVolume = currentVolume + step; | ||
264 | if(newVolume > 100) { | 266 | if (newVolume > 100) { | ||
265 | newVolume = 100; | 267 | newVolume = 100; | ||
266 | } else if (newVolume <0 ) { | 268 | } else if (newVolume < 0) { | ||
267 | newVolume = 0; | 269 | newVolume = 0; | ||
268 | } | 270 | } | ||
269 | targetPlayer.setVolume(newVolume); | 271 | targetPlayer.setVolume(newVolume); | ||
270 | } | 272 | } | ||
271 | } | 273 | } | ||
272 | 274 | | |||
273 | @Override | 275 | @Override | ||
274 | public boolean onKeyDown(int keyCode, KeyEvent event) { | 276 | public boolean onKeyDown(int keyCode, KeyEvent event) { | ||
▲ Show 20 Lines • Show All 103 Lines • ▼ Show 20 Line(s) | 378 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | |||
378 | public void onServiceStart(BackgroundService service) { | 380 | public void onServiceStart(BackgroundService service) { | ||
379 | if (targetPlayer == null) return; | 381 | if (targetPlayer == null) return; | ||
380 | targetPlayer.next(); | 382 | targetPlayer.next(); | ||
381 | } | 383 | } | ||
382 | }); | 384 | }); | ||
383 | } | 385 | } | ||
384 | }); | 386 | }); | ||
385 | 387 | | |||
386 | ((SeekBar)findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | 388 | ((SeekBar) findViewById(R.id.volume_seek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||
387 | @Override | 389 | @Override | ||
388 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | 390 | public void onProgressChanged(SeekBar seekBar, int i, boolean b) { | ||
389 | } | 391 | } | ||
390 | 392 | | |||
391 | @Override | 393 | @Override | ||
392 | public void onStartTrackingTouch(SeekBar seekBar) { | 394 | public void onStartTrackingTouch(SeekBar seekBar) { | ||
393 | } | 395 | } | ||
394 | 396 | | |||
395 | @Override | 397 | @Override | ||
396 | public void onStopTrackingTouch(final SeekBar seekBar) { | 398 | public void onStopTrackingTouch(final SeekBar seekBar) { | ||
397 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 399 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
398 | @Override | 400 | @Override | ||
399 | public void onServiceStart(BackgroundService service) { | 401 | public void onServiceStart(BackgroundService service) { | ||
400 | if (targetPlayer == null) return; | 402 | if (targetPlayer == null) return; | ||
401 | targetPlayer.setVolume(seekBar.getProgress()); | 403 | targetPlayer.setVolume(seekBar.getProgress()); | ||
402 | } | 404 | } | ||
403 | }); | 405 | }); | ||
404 | } | 406 | } | ||
405 | 407 | | |||
406 | }); | 408 | }); | ||
407 | 409 | | |||
408 | positionSeekUpdateRunnable = new Runnable() { | 410 | positionSeekUpdateRunnable = new Runnable() { | ||
409 | @Override | 411 | @Override | ||
410 | public void run() { | 412 | public void run() { | ||
411 | final SeekBar positionSeek = (SeekBar)findViewById(R.id.positionSeek); | 413 | final SeekBar positionSeek = (SeekBar) findViewById(R.id.positionSeek); | ||
412 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | 414 | BackgroundService.RunCommand(MprisActivity.this, new BackgroundService.InstanceCallback() { | ||
413 | @Override | 415 | @Override | ||
414 | public void onServiceStart(BackgroundService service) { | 416 | public void onServiceStart(BackgroundService service) { | ||
415 | if (targetPlayer != null) { | 417 | if (targetPlayer != null) { | ||
416 | positionSeek.setProgress((int) (targetPlayer.getPosition())); | 418 | positionSeek.setProgress((int) (targetPlayer.getPosition())); | ||
417 | } | 419 | } | ||
418 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | 420 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | ||
419 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000); | 421 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 1000); | ||
420 | } | 422 | } | ||
421 | }); | 423 | }); | ||
422 | } | 424 | } | ||
423 | 425 | | |||
424 | }; | 426 | }; | ||
425 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200); | 427 | positionSeekUpdateHandler.postDelayed(positionSeekUpdateRunnable, 200); | ||
426 | 428 | | |||
427 | ((SeekBar)findViewById(R.id.positionSeek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | 429 | ((SeekBar) findViewById(R.id.positionSeek)).setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { | ||
428 | @Override | 430 | @Override | ||
429 | public void onProgressChanged(SeekBar seekBar, int progress, boolean byUser) { | 431 | public void onProgressChanged(SeekBar seekBar, int progress, boolean byUser) { | ||
430 | ((TextView)findViewById(R.id.progress_textview)).setText(milisToProgress(progress)); | 432 | ((TextView) findViewById(R.id.progress_textview)).setText(milisToProgress(progress)); | ||
431 | } | 433 | } | ||
432 | 434 | | |||
433 | @Override | 435 | @Override | ||
434 | public void onStartTrackingTouch(SeekBar seekBar) { | 436 | public void onStartTrackingTouch(SeekBar seekBar) { | ||
435 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | 437 | positionSeekUpdateHandler.removeCallbacks(positionSeekUpdateRunnable); | ||
436 | } | 438 | } | ||
437 | 439 | | |||
438 | @Override | 440 | @Override | ||
Show All 30 Lines |