Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 8e8824b6 authored by Tyler Gunn's avatar Tyler Gunn
Browse files

Auto fullscreen mode when starting a video call.

- Added code to VideoCallPresenter to automatically enter fullscreen
mode once a video call starts.

Bug: 19850117
Change-Id: I801433243df556c3398ad82a60fc738bdfb35f79
parent ed848814
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -17,4 +17,11 @@
    <!-- Determines the maximum number of buttons visible on the call card.  Any buttons over this
         count are put into the overflow menu. -->
    <integer name="call_card_max_buttons">5</integer>

    <!-- Determines video calls will automatically enter fullscreen mode after the start of the
         call. -->
    <bool name="video_call_auto_fullscreen">true</bool>
    <!-- The number of milliseconds after which a video call will automatically enter fullscreen
         mode (requires video_call_auto_fullscreen to be true). -->
    <integer name="video_call_auto_fullscreen_timeout">5000</integer>
</resources>
 No newline at end of file
+92 −1
Original line number Diff line number Diff line
@@ -22,6 +22,8 @@ import android.database.Cursor;
import android.graphics.Point;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.Looper;
import android.provider.ContactsContract;
import android.telecom.AudioState;
import android.telecom.CameraCapabilities;
@@ -74,6 +76,22 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi

    public static final boolean DEBUG = false;

    /**
     * Runnable which is posted to schedule automatically entering fullscreen mode.
     */
    private Runnable mAutoFullscreenRunnable =  new Runnable() {
        @Override
        public void run() {
            if (mAutoFullScreenPending) {
                Log.v(this, "Automatically entering fullscreen mode.");
                setFullScreen(true);
                mAutoFullScreenPending = false;
            } else {
                Log.v(this, "Skipping scheduled fullscreen mode.");
            }
        }
    };

    /**
     * Determines the device orientation (portrait/lanscape).
     */
@@ -173,6 +191,29 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
     */
    private ContactInfoCache.ContactCacheEntry mProfileInfo = null;

    /**
     * UI thread handler used for delayed task execution.
     */
    private Handler mHandler;

    /**
     * Determines whether video calls should automatically enter full screen mode after
     * {@link #mAutoFullscreenTimeoutMillis} milliseconds.
     */
    private boolean mIsAutoFullscreenEnabled = false;

    /**
     * Determines the number of milliseconds after which a video call will automatically enter
     * fullscreen mode.  Requires {@link #mIsAutoFullscreenEnabled} to be {@code true}.
     */
    private int mAutoFullscreenTimeoutMillis = 0;

    /**
     * Determines if the countdown is currently running to automatically enter full screen video
     * mode.
     */
    private boolean mAutoFullScreenPending = false;

    /**
     * Initializes the presenter.
     *
@@ -182,6 +223,11 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        mContext = context;
        mMinimumVideoDimension = mContext.getResources().getDimension(
                R.dimen.video_preview_small_dimension);
        mHandler = new Handler(Looper.getMainLooper());
        mIsAutoFullscreenEnabled = mContext.getResources()
                .getBoolean(R.bool.video_call_auto_fullscreen);
        mAutoFullscreenTimeoutMillis = mContext.getResources().getInteger(
                R.integer.video_call_auto_fullscreen_timeout);
    }

    /**
@@ -325,6 +371,21 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi

    private void toggleFullScreen() {
        mIsFullScreen = !mIsFullScreen;

        // Ensure we cancel any scheduled auto activation of fullscreen mode as the user's setting
        // should override any automatic operation.
        cancelAutoFullScreen();
        InCallPresenter.getInstance().setFullScreenVideoState(mIsFullScreen);
    }

    /**
     * Sets the current full screen mode.
     *
     * @param isFullScreen {@code true} if full screen mode should be active, {@code false}
     *      otherwise.
     */
    public void setFullScreen(boolean isFullScreen) {
        mIsFullScreen = isFullScreen;
        InCallPresenter.getInstance().setFullScreenVideoState(mIsFullScreen);
    }

@@ -622,6 +683,8 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        updateAudioMode(true);

        mIsVideoMode = true;

        maybeAutoEnterFullscreen();
    }

    //TODO: Move this into Telecom. InCallUI should not be this close to audio functionality.
@@ -981,7 +1044,6 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
     * @param width peer width
     * @param height peer height
     */

    private void setDisplayVideoSize(int width, int height) {
        Log.d(this, "setDisplayVideoSize:Received peer width=" + width + " peer height=" + height);
        VideoCallUi ui = getUi();
@@ -1003,6 +1065,35 @@ public class VideoCallPresenter extends Presenter<VideoCallPresenter.VideoCallUi
        ui.setDisplayVideoSize(size.x, size.y);
    }

    /**
     * Schedules auto-entering of fullscreen mode.
     */
    public void maybeAutoEnterFullscreen() {
        if (!mIsAutoFullscreenEnabled) {
            return;
        }

        if (mAutoFullScreenPending) {
            Log.v(this, "maybeAutoEnterFullscreen : already pending.");
            return;
        }
        Log.v(this, "maybeAutoEnterFullscreen : scheduled");
        mAutoFullScreenPending = true;
        mHandler.postDelayed(mAutoFullscreenRunnable, mAutoFullscreenTimeoutMillis);
    }

    /**
     * Cancels pending auto fullscreen mode.
     */
    public void cancelAutoFullScreen() {
        if (!mAutoFullScreenPending) {
            Log.v(this, "cancelAutoFullScreen : none pending.");
            return;
        }
        Log.v(this, "cancelAutoFullScreen : cancelling pending");
        mAutoFullScreenPending = false;
    }

    private static boolean isAudioRouteEnabled(int audioRoute, int audioRouteMask) {
        return ((audioRoute & audioRouteMask) != 0);
    }