Skip to content

Commit

Permalink
[zhenhui] TheWidlarzGroup#697 add previous and next control
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhenhuiDev committed Feb 16, 2022
1 parent d8917b5 commit 2f299b8
Showing 1 changed file with 31 additions and 26 deletions.
Original file line number Diff line number Diff line change
@@ -1,30 +1,27 @@
package com.brentvatne.lockscreen;

import android.app.NotificationManager;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.ComponentCallbacks2;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.Context;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.media.AudioManager;
import android.os.SystemClock;
import android.os.Build;

import androidx.annotation.RequiresApi;

import android.os.SystemClock;
import android.support.v4.media.MediaMetadataCompat;
import android.support.v4.media.session.MediaSessionCompat;
import android.support.v4.media.session.PlaybackStateCompat;
import android.util.Log;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;
import androidx.media.app.NotificationCompat.MediaStyle;

import android.util.Log;

import com.brentvatne.react.R;
import com.facebook.common.executors.UiThreadImmediateExecutorService;
import com.facebook.common.references.CloseableReference;
Expand Down Expand Up @@ -109,6 +106,7 @@ private void createChannel(ReactApplicationContext context) {
mChannel.setLockscreenVisibility(NotificationCompat.VISIBILITY_PUBLIC);
mNotificationManager.createNotificationChannel(mChannel);
}

private boolean hasControl(long control) {
return (controls & control) == control;
}
Expand All @@ -120,26 +118,33 @@ private void updateNotificationMediaStyle() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
style.setMediaSession(session.getSessionToken());
}
int controlCount = 0;
if(hasControl(PlaybackStateCompat.ACTION_PLAY)
|| hasControl(PlaybackStateCompat.ACTION_PAUSE)
|| hasControl(PlaybackStateCompat.ACTION_PLAY_PAUSE)) {
controlCount += 1;
}
if(hasControl(PlaybackStateCompat.ACTION_FAST_FORWARD)) {
controlCount += 1;
}
if(hasControl(PlaybackStateCompat.ACTION_REWIND)) {
controlCount += 1;
}
int[] actions = new int[controlCount];
for(int i=0; i<actions.length; i++) {
actions[i] = i;
if (hasControl(PlaybackStateCompat.ACTION_SKIP_TO_NEXT)
|| hasControl(PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS)) {
// according to LockScreenView enableControl()
style.setShowActionsInCompactView(0, 2, 4);
} else {
int controlCount = 0;
if (hasControl(PlaybackStateCompat.ACTION_PLAY)
|| hasControl(PlaybackStateCompat.ACTION_PAUSE)
|| hasControl(PlaybackStateCompat.ACTION_PLAY_PAUSE)) {
controlCount += 1;
}
if (hasControl(PlaybackStateCompat.ACTION_FAST_FORWARD)) {
controlCount += 1;
}
if (hasControl(PlaybackStateCompat.ACTION_REWIND)) {
controlCount += 1;
}
int[] actions = new int[controlCount];
for (int i = 0; i < actions.length; i++) {
actions[i] = i;
}
style.setShowActionsInCompactView(actions);
}
style.setShowActionsInCompactView(actions);
nb.setStyle(style);
}
}

private void init() {
if (init) {
return;
Expand Down Expand Up @@ -256,7 +261,7 @@ synchronized public void setNowPlaying(ReadableMap metadata) {
// If a color is supplied, we need to clear the MediaStyle set during init().
// Otherwise, the color will not be used for the notification's background.
boolean removeFade = metadata.hasKey("color");
if(removeFade) {
if (removeFade) {
nb.setStyle(new MediaStyle());
}

Expand Down Expand Up @@ -365,7 +370,7 @@ synchronized public void updatePlayback(ReadableMap info) {
state = pb.build();
session.setPlaybackState(state);

if(session.isActive()) {
if (session.isActive()) {
notification.show(nb, isPlaying);
}

Expand Down

0 comments on commit 2f299b8

Please sign in to comment.