|
| 1 | +package io.agora.agora_rtc_ng; |
| 2 | + |
| 3 | +import io.flutter.embedding.android.FlutterActivity; |
| 4 | + |
| 5 | +import android.app.PictureInPictureParams; |
| 6 | +import android.app.PictureInPictureUiState; |
| 7 | +import android.content.Context; |
| 8 | +import android.content.res.Configuration; |
| 9 | +import android.os.Build; |
| 10 | + |
| 11 | +import androidx.annotation.NonNull; |
| 12 | +import androidx.annotation.RequiresApi; |
| 13 | + |
| 14 | +import java.lang.ref.WeakReference; |
| 15 | + |
| 16 | +import io.agora.pip.AgoraPIPActivityProxy; |
| 17 | +import io.agora.pip.AgoraPIPActivityListener; |
| 18 | + |
| 19 | +public class AgoraPIPFlutterActivity extends FlutterActivity implements AgoraPIPActivityProxy { |
| 20 | + private WeakReference<AgoraPIPActivityListener> mListener; |
| 21 | + |
| 22 | + @Override |
| 23 | + public Context getApplicationContext() { |
| 24 | + return super.getApplicationContext(); |
| 25 | + } |
| 26 | + |
| 27 | + @Override |
| 28 | + public void setAgoraPIPActivityListener(AgoraPIPActivityListener listener) { |
| 29 | + mListener = new WeakReference<>(listener); |
| 30 | + } |
| 31 | + |
| 32 | + @Override |
| 33 | + public boolean isInPictureInPictureMode() { |
| 34 | + return super.isInPictureInPictureMode(); |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public void setPictureInPictureParams(@NonNull PictureInPictureParams params) { |
| 39 | + super.setPictureInPictureParams(params); |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public boolean enterPictureInPictureMode(@NonNull PictureInPictureParams params) { |
| 44 | + return super.enterPictureInPictureMode(params); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void enterPictureInPictureMode() { |
| 49 | + super.enterPictureInPictureMode(); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public boolean moveTaskToBack(boolean nonRoot) { |
| 54 | + return super.moveTaskToBack(nonRoot); |
| 55 | + } |
| 56 | + |
| 57 | + // only available in API level 26 and above |
| 58 | + @RequiresApi(Build.VERSION_CODES.O) |
| 59 | + @Override |
| 60 | + public void onPictureInPictureModeChanged(boolean isInPictureInPictureMode, |
| 61 | + Configuration newConfig) { |
| 62 | + super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig); |
| 63 | + if (mListener == null) { |
| 64 | + return; |
| 65 | + } |
| 66 | + |
| 67 | + AgoraPIPActivityListener listener = mListener.get(); |
| 68 | + if (listener != null) { |
| 69 | + listener.onPictureInPictureModeChanged(isInPictureInPictureMode, |
| 70 | + newConfig); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + // only available in API level 30 and above |
| 75 | + @RequiresApi(Build.VERSION_CODES.R) |
| 76 | + @Override |
| 77 | + public boolean onPictureInPictureRequested() { |
| 78 | + if (mListener != null) { |
| 79 | + AgoraPIPActivityListener listener = mListener.get(); |
| 80 | + if (listener != null) { |
| 81 | + return listener.onPictureInPictureRequested(); |
| 82 | + } |
| 83 | + } |
| 84 | + |
| 85 | + |
| 86 | + return super.onPictureInPictureRequested(); |
| 87 | + } |
| 88 | + |
| 89 | + // only available in API level 31 and above |
| 90 | + @RequiresApi(Build.VERSION_CODES.S) |
| 91 | + @Override |
| 92 | + public void |
| 93 | + onPictureInPictureUiStateChanged(@NonNull PictureInPictureUiState state) { |
| 94 | + super.onPictureInPictureUiStateChanged(state); |
| 95 | + if (mListener == null) { |
| 96 | + return; |
| 97 | + } |
| 98 | + |
| 99 | + AgoraPIPActivityListener listener = mListener.get(); |
| 100 | + if (listener != null) { |
| 101 | + listener.onPictureInPictureUiStateChanged(state); |
| 102 | + } |
| 103 | + } |
| 104 | + |
| 105 | + @Override |
| 106 | + public void onUserLeaveHint() { |
| 107 | + super.onUserLeaveHint(); |
| 108 | + if (mListener == null) { |
| 109 | + return; |
| 110 | + } |
| 111 | + |
| 112 | + AgoraPIPActivityListener listener = mListener.get(); |
| 113 | + if (listener != null) { |
| 114 | + listener.onUserLeaveHint(); |
| 115 | + } |
| 116 | + } |
| 117 | +} |
0 commit comments