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

Unverified Commit 82916a58 authored by ganeshi4u's avatar ganeshi4u Committed by Michael Bestas
Browse files

SystemUI: screenshot: Add delete action chip intent



Co-authored-by: default avatarAdithya R <gh0strider.2k18.reborn@gmail.com>
Co-authored-by: default avatarIdo Ben-Hur <idoybh2@gmail.com>
Co-authored-by: default avatarPranav Vashi <neobuddy89@gmail.com>
Co-authored-by: default avatarsomeone5678 <someone5678@users.noreply.github.com>
Change-Id: Ia55ac91c2db2f44062674a699f8df63c96e1de5c
parent bc9a3382
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -571,6 +571,10 @@
            </intent-filter>
        </activity-alias>

        <!-- Callback for deleting screenshot notification -->
        <receiver android:name=".screenshot.DeleteScreenshotReceiver"
            android:exported="false" />

        <!-- Callback for invoking a smart action from the screenshot notification. -->
        <receiver android:name=".screenshot.SmartActionsReceiver"
                  android:exported="false"/>
+5 −0
Original line number Diff line number Diff line
@@ -124,4 +124,9 @@

    <!-- Channel name for Battery notifications -->
    <string name="battery_notification_channel_tv">Battery warning</string>

    <!-- Label for UI element which allows deleting the screenshot [CHAR LIMIT=30] -->
    <string name="screenshot_delete_label">Delete</string>
    <!-- Content description indicating that tapping the element will allow deleting the screenshot [CHAR LIMIT=NONE] -->
    <string name="screenshot_delete_description">Delete screenshot</string>
</resources>
+10 −0
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import com.android.systemui.accessibility.hearingaid.HearingDevicesDialogReceive
import com.android.systemui.media.dialog.MediaOutputDialogReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetPinnedReceiver;
import com.android.systemui.people.widget.PeopleSpaceWidgetProvider;
import com.android.systemui.screenshot.DeleteScreenshotReceiver;
import com.android.systemui.screenshot.SmartActionsReceiver;

import dagger.Binds;
@@ -36,6 +37,15 @@ import dagger.multibindings.IntoMap;
 */
@Module
public abstract class DefaultBroadcastReceiverBinder {
    /**
     *
     */
    @Binds
    @IntoMap
    @ClassKey(DeleteScreenshotReceiver.class)
    public abstract BroadcastReceiver bindDeleteScreenshotReceiver(
            DeleteScreenshotReceiver broadcastReceiver);

    /**
     *
     */
+12 −0
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@

package com.android.systemui.screenshot

import android.app.PendingIntent
import android.content.ClipData
import android.content.ClipDescription
import android.content.ComponentName
@@ -26,6 +27,7 @@ import android.net.Uri
import android.os.UserHandle
import com.android.systemui.res.R
import com.android.systemui.screenshot.scroll.LongScreenshotActivity
import com.android.systemui.screenshot.DeleteScreenshotReceiver.EXTRA_SCREENSHOT_URI_ID

object ActionIntentCreator {
    /** @return a chooser intent to share the given URI. */
@@ -102,6 +104,16 @@ object ActionIntentCreator {
            .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK)
    }

    fun createDelete(rawUri: Uri, context: Context): PendingIntent {
        return PendingIntent.getBroadcast(context, rawUri.toString().hashCode(),
                Intent(context, DeleteScreenshotReceiver::class.java)
                        .putExtra(EXTRA_SCREENSHOT_URI_ID, rawUri.toString())
                        .addFlags(Intent.FLAG_RECEIVER_FOREGROUND),
                        (PendingIntent.FLAG_CANCEL_CURRENT
                        or PendingIntent.FLAG_ONE_SHOT
                        or PendingIntent.FLAG_IMMUTABLE))
    }

    /** @return an Intent to start the LongScreenshotActivity */
    fun createLongScreenshotIntent(owner: UserHandle, context: Context): Intent {
        return Intent(context, LongScreenshotActivity::class.java)
+70 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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 static com.android.systemui.screenshot.DeleteScreenshotReceiver.EXTRA_SCREENSHOT_URI_ID;
import static com.android.systemui.screenshot.SmartActionsReceiver.EXTRA_ACTION_TYPE;
import static com.android.systemui.screenshot.SmartActionsReceiver.EXTRA_ID;
import static com.android.systemui.screenshot.SmartActionsReceiver.EXTRA_SMART_ACTIONS_ENABLED;

import android.content.BroadcastReceiver;
import android.content.ContentResolver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.android.systemui.dagger.qualifiers.Background;

import java.util.concurrent.Executor;

import javax.inject.Inject;

/**
 * Removes the file at a provided URI.
 */
public class DeleteScreenshotReceiver extends BroadcastReceiver {
    public static final String EXTRA_SCREENSHOT_URI_ID = "android:screenshot_uri_id";

    private final ScreenshotSmartActions mScreenshotSmartActions;
    private final Executor mBackgroundExecutor;

    @Inject
    public DeleteScreenshotReceiver(ScreenshotSmartActions screenshotSmartActions,
            @Background Executor backgroundExecutor) {
        mScreenshotSmartActions = screenshotSmartActions;
        mBackgroundExecutor = backgroundExecutor;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (!intent.hasExtra(EXTRA_SCREENSHOT_URI_ID)) {
            return;
        }

        // And delete the image from the media store
        final Uri uri = Uri.parse(intent.getStringExtra(EXTRA_SCREENSHOT_URI_ID));
        mBackgroundExecutor.execute(() -> {
            ContentResolver resolver = context.getContentResolver();
            resolver.delete(uri, null, null);
        });
        if (intent.getBooleanExtra(EXTRA_SMART_ACTIONS_ENABLED, false)) {
            mScreenshotSmartActions.notifyScreenshotAction(
                    intent.getStringExtra(EXTRA_ID), intent.getStringExtra(EXTRA_ACTION_TYPE),
                    false, null);
        }
    }
}
Loading