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

Commit 657bf0fc authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Adding support for drag and drop for requestPinItem." into ub-launcher3-master

parents ab45ec0c b38fab75
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -81,6 +81,8 @@

        <activity android:name="com.android.launcher3.dragndrop.AddItemActivity"
            android:theme="@android:style/Theme.DeviceDefault.Light.Dialog.Alert"
            android:excludeFromRecents="true"
            android:autoRemoveFromRecents="true"
            android:label="@string/action_add_to_workspace" >
            <intent-filter>
                <action android:name="android.content.pm.action.CONFIRM_PIN_ITEM" />
+0 −61
Original line number Diff line number Diff line
/*
 * Copyright (C) 2015 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.launcher3;

import android.content.Context;
import android.graphics.PointF;
import android.graphics.Rect;

/**
 * Drop target used when another window (i.e. another process) has accepted a global system drag.
 * If the accepted item was a shortcut, we delete it from Launcher.
 */
public class AnotherWindowDropTarget implements DropTarget {
    final Launcher mLauncher;

    public AnotherWindowDropTarget (Context context) { mLauncher = Launcher.getLauncher(context); }

    @Override
    public boolean isDropEnabled() { return true; }

    @Override
    public void onDrop(DragObject dragObject) {
        dragObject.deferDragViewCleanupPostAnimation = false;
        LauncherModel.deleteItemFromDatabase(mLauncher, (ShortcutInfo) dragObject.dragInfo);
    }

    @Override
    public void onDragEnter(DragObject dragObject) {}

    @Override
    public void onDragOver(DragObject dragObject) {}

    @Override
    public void onDragExit(DragObject dragObject) {}

    @Override
    public boolean acceptDrop(DragObject dragObject) {
        return dragObject.dragInfo instanceof ShortcutInfo;
    }

    @Override
    public void prepareAccessibilityDrop() {}

    // These methods are implemented in Views
    @Override
    public void getHitRectRelativeToDragLayer(Rect outRect) {}
}
+11 −1
Original line number Diff line number Diff line
@@ -49,6 +49,7 @@ import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.os.Parcelable;
import android.os.Process;
import android.os.StrictMode;
import android.os.SystemClock;
@@ -94,6 +95,7 @@ import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.PinItemDragListener;
import com.android.launcher3.dynamicui.ExtractedColors;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
@@ -826,7 +828,7 @@ public class Launcher extends BaseActivity
    }

    @Override
    protected void onActivityResult(
    public void onActivityResult(
            final int requestCode, final int resultCode, final Intent data) {
        handleActivityResult(requestCode, resultCode, data);
        if (mLauncherCallbacks != null) {
@@ -1752,6 +1754,14 @@ public class Launcher extends BaseActivity
            if (mLauncherCallbacks != null) {
                mLauncherCallbacks.onHomeIntent();
            }

            Parcelable dragExtra = intent
                    .getParcelableExtra(PinItemDragListener.EXTRA_PIN_ITEM_DRAG_LISTENER);
            if (dragExtra instanceof PinItemDragListener) {
                PinItemDragListener dragListener = (PinItemDragListener) dragExtra;
                dragListener.setLauncher(this);
                mDragLayer.setOnDragListener(dragListener);
            }
        }

        if (mLauncherCallbacks != null) {
+28 −1
Original line number Diff line number Diff line
@@ -21,13 +21,14 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.os.Bundle;
import android.os.Parcel;
import android.os.Parcelable;

/**
 * A wrapper around platform implementation of PinItemRequestCompat until the
 * updated SDK is available.
 */
public class PinItemRequestCompat {
public class PinItemRequestCompat implements Parcelable {

    public static final String EXTRA_PIN_ITEM_REQUEST = "android.content.pm.extra.PIN_ITEM_REQUEST";

@@ -83,6 +84,32 @@ public class PinItemRequestCompat {
        }
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeParcelable(mObject, i);
    }

    public Intent toIntent() {
        return new Intent().putExtra(EXTRA_PIN_ITEM_REQUEST, mObject);
    }

    public static final Parcelable.Creator<PinItemRequestCompat> CREATOR =
            new Parcelable.Creator<PinItemRequestCompat>() {
                public PinItemRequestCompat createFromParcel(Parcel source) {
                    Parcelable object = source.readParcelable(null);
                    return new PinItemRequestCompat(object);
                }

                public PinItemRequestCompat[] newArray(int size) {
                    return new PinItemRequestCompat[size];
                }
            };

    public static PinItemRequestCompat getPinItemRequest(Intent intent) {
        Parcelable extra = intent.getParcelableExtra(EXTRA_PIN_ITEM_REQUEST);
        return extra == null ? null : new PinItemRequestCompat(extra);
+3 −2
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import android.util.Log;
import android.widget.Toast;

import com.android.launcher3.IconCache;
import com.android.launcher3.Launcher;
import com.android.launcher3.R;
import com.android.launcher3.Utilities;

@@ -67,7 +68,7 @@ public abstract class ShortcutConfigActivityInfo {

    public abstract Drawable getFullResIcon(IconCache cache);

    public boolean startConfigActivity(Activity activity, int requestCode) {
    public boolean startConfigActivity(Launcher activity, int requestCode) {
        Intent intent = new Intent(Intent.ACTION_CREATE_SHORTCUT)
                .setComponent(getComponent());
        try {
@@ -136,7 +137,7 @@ public abstract class ShortcutConfigActivityInfo {
        }

        @Override
        public boolean startConfigActivity(Activity activity, int requestCode) {
        public boolean startConfigActivity(Launcher activity, int requestCode) {
            if (getUser().equals(Process.myUserHandle())) {
                return super.startConfigActivity(activity, requestCode);
            }
Loading