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

Commit 8fa1bc8d authored by meganukebmp's avatar meganukebmp Committed by Michael Bestas
Browse files

SystemUI: Fix crash when taking screenshot in partial screenshot view

Bug caused by the region selector and the animation using the same view.
This fix makes a dedicated view for the selector.

Change-Id: I12532ece4b3a742cba8f5c3852813fa339a04341
parent 28bc3b45
Loading
Loading
Loading
Loading
+11 −7
Original line number Original line Diff line number Diff line
@@ -435,6 +435,7 @@ class GlobalScreenshot {


    private Bitmap mScreenBitmap;
    private Bitmap mScreenBitmap;
    private View mScreenshotLayout;
    private View mScreenshotLayout;
    private View mScreenshotSelectorLayout;
    private ScreenshotSelectorView mScreenshotSelectorView;
    private ScreenshotSelectorView mScreenshotSelectorView;
    private ImageView mBackgroundView;
    private ImageView mBackgroundView;
    private ImageView mScreenshotView;
    private ImageView mScreenshotView;
@@ -464,15 +465,17 @@ class GlobalScreenshot {
        // Inflate the screenshot layout
        // Inflate the screenshot layout
        mDisplayMatrix = new Matrix();
        mDisplayMatrix = new Matrix();
        mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
        mScreenshotLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
        mScreenshotSelectorLayout = layoutInflater.inflate(R.layout.global_screenshot, null);
        mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background);
        mBackgroundView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_background);
        mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
        mScreenshotView = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot);
        mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
        mScreenshotFlash = (ImageView) mScreenshotLayout.findViewById(R.id.global_screenshot_flash);
        mScreenshotSelectorView = (ScreenshotSelectorView) mScreenshotLayout.findViewById(
        mScreenshotSelectorView = (ScreenshotSelectorView) mScreenshotSelectorLayout.findViewById(
                R.id.global_screenshot_selector);
                R.id.global_screenshot_selector);
        mScreenshotLayout.setFocusable(true);
        mScreenshotLayout.setFocusable(true);
        mScreenshotSelectorLayout.setFocusable(true);
        mScreenshotSelectorView.setFocusable(true);
        mScreenshotSelectorView.setFocusable(true);
        mScreenshotSelectorView.setFocusableInTouchMode(true);
        mScreenshotSelectorView.setFocusableInTouchMode(true);
        mScreenshotLayout.setOnTouchListener(new View.OnTouchListener() {
        mScreenshotSelectorLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            @Override
            public boolean onTouch(View v, MotionEvent event) {
            public boolean onTouch(View v, MotionEvent event) {
                // Intercept and ignore all touch events
                // Intercept and ignore all touch events
@@ -633,7 +636,7 @@ class GlobalScreenshot {
     */
     */
    void takeScreenshotPartial(final Runnable finisher, final boolean statusBarVisible,
    void takeScreenshotPartial(final Runnable finisher, final boolean statusBarVisible,
            final boolean navBarVisible) {
            final boolean navBarVisible) {
        mWindowManager.addView(mScreenshotLayout, mWindowLayoutParams);
        mWindowManager.addView(mScreenshotSelectorLayout, mWindowLayoutParams);
        mScreenshotSelectorView.setOnTouchListener(new View.OnTouchListener() {
        mScreenshotSelectorView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            @Override
            public boolean onTouch(View v, MotionEvent event) {
            public boolean onTouch(View v, MotionEvent event) {
@@ -647,12 +650,12 @@ class GlobalScreenshot {
                        return true;
                        return true;
                    case MotionEvent.ACTION_UP:
                    case MotionEvent.ACTION_UP:
                        view.setVisibility(View.GONE);
                        view.setVisibility(View.GONE);
                        mWindowManager.removeView(mScreenshotLayout);
                        mWindowManager.removeView(mScreenshotSelectorLayout);
                        final Rect rect = view.getSelectionRect();
                        final Rect rect = view.getSelectionRect();
                        if (rect != null) {
                        if (rect != null) {
                            if (rect.width() != 0 && rect.height() != 0) {
                            if (rect.width() != 0 && rect.height() != 0) {
                                // Need mScreenshotLayout to handle it after the view disappears
                                // Need mScreenshotSelectorLayout to handle it after the view disappears
                                mScreenshotLayout.post(new Runnable() {
                                mScreenshotSelectorLayout.post(new Runnable() {
                                    public void run() {
                                    public void run() {
                                        takeScreenshot(finisher, statusBarVisible, navBarVisible,
                                        takeScreenshot(finisher, statusBarVisible, navBarVisible,
                                                rect.left, rect.top, rect.width(), rect.height());
                                                rect.left, rect.top, rect.width(), rect.height());
@@ -668,7 +671,7 @@ class GlobalScreenshot {
                return false;
                return false;
            }
            }
        });
        });
        mScreenshotLayout.post(new Runnable() {
        mScreenshotSelectorLayout.post(new Runnable() {
            @Override
            @Override
            public void run() {
            public void run() {
                mScreenshotSelectorView.setVisibility(View.VISIBLE);
                mScreenshotSelectorView.setVisibility(View.VISIBLE);
@@ -684,6 +687,7 @@ class GlobalScreenshot {
        // If the selector layer still presents on screen, we remove it and resets its state.
        // If the selector layer still presents on screen, we remove it and resets its state.
        if (mScreenshotSelectorView.getSelectionRect() != null) {
        if (mScreenshotSelectorView.getSelectionRect() != null) {
            mWindowManager.removeView(mScreenshotLayout);
            mWindowManager.removeView(mScreenshotLayout);
            mWindowManager.removeView(mScreenshotSelectorLayout);
            mScreenshotSelectorView.stopSelection();
            mScreenshotSelectorView.stopSelection();
        }
        }
    }
    }