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

Commit 76140601 authored by Miranda Kephart's avatar Miranda Kephart
Browse files

Remove partial screenshot code

It's broken currently, is extremely difficult to access, and will
need to be heavily rewritten/refactored anyway if we decide to
bring it back.

Fix: 249325548
Test: adb shell input keycombination -t 300 META_LEFT CTRL_LEFT
SHIFT_LEFT S
(now takes a regular screenshot)

Change-Id: I2cde564f6369b88bd4c6b20a9eecf8172fae7e7a
parent f5170368
Loading
Loading
Loading
Loading
+0 −7
Original line number Diff line number Diff line
@@ -776,12 +776,6 @@ public interface WindowManager extends ViewManager {
     */
    int TAKE_SCREENSHOT_FULLSCREEN = 1;

    /**
     * Invoke screenshot flow allowing the user to select a region.
     * @hide
     */
    int TAKE_SCREENSHOT_SELECTED_REGION = 2;

    /**
     * Invoke screenshot flow with an image provided by the caller.
     * @hide
@@ -794,7 +788,6 @@ public interface WindowManager extends ViewManager {
     * @hide
     */
    @IntDef({TAKE_SCREENSHOT_FULLSCREEN,
            TAKE_SCREENSHOT_SELECTED_REGION,
            TAKE_SCREENSHOT_PROVIDED_IMAGE})
    @interface ScreenshotType {}

+0 −7
Original line number Diff line number Diff line
@@ -17,7 +17,6 @@
package com.android.internal.util;

import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
import static android.view.WindowManager.TAKE_SCREENSHOT_SELECTED_REGION;

import static junit.framework.Assert.assertNull;
import static junit.framework.Assert.fail;
@@ -84,12 +83,6 @@ public final class ScreenshotHelperTest {
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
    }

    @Test
    public void testSelectedRegionScreenshot() {
        mScreenshotHelper.takeScreenshot(TAKE_SCREENSHOT_SELECTED_REGION,
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
    }

    @Test
    public void testProvidedImageScreenshot() {
        mScreenshotHelper.provideScreenshot(
+0 −6
Original line number Diff line number Diff line
@@ -35,12 +35,6 @@
        android:visibility="gone"
        android:elevation="7dp"
        android:src="@android:color/white"/>
    <com.android.systemui.screenshot.ScreenshotSelectorView
        android:id="@+id/screenshot_selector"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:visibility="gone"
        android:pointerIcon="crosshair"/>
    <include layout="@layout/screenshot_static"
             android:id="@+id/screenshot_static"/>
</com.android.systemui.screenshot.ScreenshotView>
+0 −18
Original line number Diff line number Diff line
@@ -398,24 +398,6 @@ public class ScreenshotController {
                showFlash);
    }

    /**
     * Displays a screenshot selector
     */
    @MainThread
    void takeScreenshotPartial(ComponentName topComponent,
            final Consumer<Uri> finisher, RequestCallback requestCallback) {
        Assert.isMainThread();
        mScreenshotView.reset();
        mCurrentRequestCallback = requestCallback;

        attachWindow();
        mWindow.setContentView(mScreenshotView);
        mScreenshotView.requestApplyInsets();

        mScreenshotView.takePartialScreenshot(
                rect -> takeScreenshotInternal(topComponent, finisher, rect));
    }

    /**
     * Clears current screenshot
     */
+0 −119
Original line number Diff line number Diff line
/*
 * Copyright (C) 2016 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License
 */

package com.android.systemui.screenshot;

import android.annotation.Nullable;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.Rect;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;

import java.util.function.Consumer;

/**
 * Draws a selection rectangle while taking screenshot
 */
public class ScreenshotSelectorView extends View {
    private Point mStartPoint;
    private Rect mSelectionRect;
    private final Paint mPaintSelection, mPaintBackground;

    private Consumer<Rect> mOnScreenshotSelected;

    public ScreenshotSelectorView(Context context) {
        this(context, null);
    }

    public ScreenshotSelectorView(Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
        mPaintBackground = new Paint(Color.BLACK);
        mPaintBackground.setAlpha(160);
        mPaintSelection = new Paint(Color.TRANSPARENT);
        mPaintSelection.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));

        setOnTouchListener((v, event) -> {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    startSelection((int) event.getX(), (int) event.getY());
                    return true;
                case MotionEvent.ACTION_MOVE:
                    updateSelection((int) event.getX(), (int) event.getY());
                    return true;
                case MotionEvent.ACTION_UP:
                    setVisibility(View.GONE);
                    final Rect rect = getSelectionRect();
                    if (mOnScreenshotSelected != null
                            && rect != null
                            && rect.width() != 0 && rect.height() != 0) {
                        mOnScreenshotSelected.accept(rect);
                    }
                    stopSelection();
                    return true;
            }
            return false;
        });
    }

    @Override
    public void draw(Canvas canvas) {
        canvas.drawRect(mLeft, mTop, mRight, mBottom, mPaintBackground);
        if (mSelectionRect != null) {
            canvas.drawRect(mSelectionRect, mPaintSelection);
        }
    }

    void setOnScreenshotSelected(Consumer<Rect> onScreenshotSelected) {
        mOnScreenshotSelected = onScreenshotSelected;
    }

    void stop() {
        if (getSelectionRect() != null) {
            stopSelection();
        }
    }

    private void startSelection(int x, int y) {
        mStartPoint = new Point(x, y);
        mSelectionRect = new Rect(x, y, x, y);
    }

    private void updateSelection(int x, int y) {
        if (mSelectionRect != null) {
            mSelectionRect.left = Math.min(mStartPoint.x, x);
            mSelectionRect.right = Math.max(mStartPoint.x, x);
            mSelectionRect.top = Math.min(mStartPoint.y, y);
            mSelectionRect.bottom = Math.max(mStartPoint.y, y);
            invalidate();
        }
    }

    private Rect getSelectionRect() {
        return mSelectionRect;
    }

    private void stopSelection() {
        mStartPoint = null;
        mSelectionRect = null;
    }
}
Loading