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

Commit 6b424e88 authored by Miranda Kephart's avatar Miranda Kephart Committed by Automerger Merge Worker
Browse files

Merge "Remove partial screenshot code" into tm-qpr-dev am: 5caa83b5

parents ec4470be 5caa83b5
Loading
Loading
Loading
Loading
+0 −7
Original line number Original line Diff line number Diff line
@@ -776,12 +776,6 @@ public interface WindowManager extends ViewManager {
     */
     */
    int TAKE_SCREENSHOT_FULLSCREEN = 1;
    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.
     * Invoke screenshot flow with an image provided by the caller.
     * @hide
     * @hide
@@ -794,7 +788,6 @@ public interface WindowManager extends ViewManager {
     * @hide
     * @hide
     */
     */
    @IntDef({TAKE_SCREENSHOT_FULLSCREEN,
    @IntDef({TAKE_SCREENSHOT_FULLSCREEN,
            TAKE_SCREENSHOT_SELECTED_REGION,
            TAKE_SCREENSHOT_PROVIDED_IMAGE})
            TAKE_SCREENSHOT_PROVIDED_IMAGE})
    @interface ScreenshotType {}
    @interface ScreenshotType {}


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


import static android.view.WindowManager.TAKE_SCREENSHOT_FULLSCREEN;
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.assertNull;
import static junit.framework.Assert.fail;
import static junit.framework.Assert.fail;
@@ -84,12 +83,6 @@ public final class ScreenshotHelperTest {
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
                WindowManager.ScreenshotSource.SCREENSHOT_OTHER, mHandler, null);
    }
    }


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

    @Test
    @Test
    public void testProvidedImageScreenshot() {
    public void testProvidedImageScreenshot() {
        mScreenshotHelper.provideScreenshot(
        mScreenshotHelper.provideScreenshot(
+0 −6
Original line number Original line Diff line number Diff line
@@ -35,12 +35,6 @@
        android:visibility="gone"
        android:visibility="gone"
        android:elevation="7dp"
        android:elevation="7dp"
        android:src="@android:color/white"/>
        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"
    <include layout="@layout/screenshot_static"
             android:id="@+id/screenshot_static"/>
             android:id="@+id/screenshot_static"/>
</com.android.systemui.screenshot.ScreenshotView>
</com.android.systemui.screenshot.ScreenshotView>
+0 −18
Original line number Original line Diff line number Diff line
@@ -407,24 +407,6 @@ public class ScreenshotController {
                showFlash, UserHandle.of(userId));
                showFlash, UserHandle.of(userId));
    }
    }


    /**
     * 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
     * Clears current screenshot
     */
     */
+0 −119
Original line number Original line 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