2011-05-31 16:50:48 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2011 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.
|
|
|
|
|
*/
|
|
|
|
|
|
2013-06-05 22:57:57 -04:00
|
|
|
package com.android.launcher3;
|
2011-05-31 16:50:48 -07:00
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-03-24 17:28:25 -07:00
|
|
|
import android.text.TextUtils;
|
2011-05-31 16:50:48 -07:00
|
|
|
import android.util.AttributeSet;
|
|
|
|
|
import android.view.View;
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
import com.android.launcher3.accessibility.LauncherAccessibilityDelegate;
|
2016-08-16 15:36:48 -07:00
|
|
|
import com.android.launcher3.dragndrop.DragOptions;
|
2016-02-18 22:09:23 +00:00
|
|
|
import com.android.launcher3.folder.Folder;
|
2018-02-12 14:25:48 -08:00
|
|
|
import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType;
|
2014-04-30 03:02:21 +01:00
|
|
|
|
2011-06-12 15:15:29 -07:00
|
|
|
public class DeleteDropTarget extends ButtonDropTarget {
|
2015-04-10 13:45:42 -07:00
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
public DeleteDropTarget(Context context, AttributeSet attrs) {
|
|
|
|
|
this(context, attrs, 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public DeleteDropTarget(Context context, AttributeSet attrs, int defStyle) {
|
|
|
|
|
super(context, attrs, defStyle);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
protected void onFinishInflate() {
|
|
|
|
|
super.onFinishInflate();
|
|
|
|
|
// Get the hover color
|
2015-04-10 13:45:42 -07:00
|
|
|
mHoverColor = getResources().getColor(R.color.delete_target_hover_tint);
|
2012-03-20 16:19:37 -07:00
|
|
|
|
2017-04-26 22:34:49 -07:00
|
|
|
setDrawable(R.drawable.ic_remove_shadow);
|
2013-06-14 17:42:35 -07:00
|
|
|
}
|
|
|
|
|
|
2015-10-01 13:04:22 -07:00
|
|
|
@Override
|
2016-08-16 15:36:48 -07:00
|
|
|
public void onDragStart(DropTarget.DragObject dragObject, DragOptions options) {
|
|
|
|
|
super.onDragStart(dragObject, options);
|
2017-10-03 16:17:32 -07:00
|
|
|
setTextBasedOnDragSource(dragObject.dragInfo);
|
2015-10-01 13:04:22 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
/**
|
|
|
|
|
* @return true for items that should have a "Remove" action in accessibility.
|
|
|
|
|
*/
|
|
|
|
|
@Override
|
2018-02-12 14:25:48 -08:00
|
|
|
public boolean supportsAccessibilityDrop(ItemInfo info, View view) {
|
2015-04-22 11:29:51 -07:00
|
|
|
return (info instanceof ShortcutInfo)
|
|
|
|
|
|| (info instanceof LauncherAppWidgetInfo)
|
|
|
|
|
|| (info instanceof FolderInfo);
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
2017-10-24 14:54:30 -07:00
|
|
|
@Override
|
|
|
|
|
public int getAccessibilityAction() {
|
|
|
|
|
return LauncherAccessibilityDelegate.REMOVE;
|
|
|
|
|
}
|
|
|
|
|
|
2011-05-31 16:50:48 -07:00
|
|
|
@Override
|
2017-10-03 16:17:32 -07:00
|
|
|
protected boolean supportsDrop(ItemInfo info) {
|
2015-10-01 13:04:22 -07:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2017-10-03 16:17:32 -07:00
|
|
|
* Set the drop target's text to either "Remove" or "Cancel" depending on the drag item.
|
2015-10-01 13:04:22 -07:00
|
|
|
*/
|
2017-10-03 16:17:32 -07:00
|
|
|
private void setTextBasedOnDragSource(ItemInfo item) {
|
2017-08-21 15:31:51 -07:00
|
|
|
if (!TextUtils.isEmpty(mText)) {
|
2017-10-03 16:17:32 -07:00
|
|
|
mText = getResources().getString(item.id != ItemInfo.NO_ID
|
2017-08-21 15:31:51 -07:00
|
|
|
? R.string.remove_drop_target_label
|
2015-10-01 13:04:22 -07:00
|
|
|
: android.R.string.cancel);
|
2017-08-21 15:31:51 -07:00
|
|
|
requestLayout();
|
2015-10-01 13:04:22 -07:00
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
2016-12-13 19:37:10 -08:00
|
|
|
public void completeDrop(DragObject d) {
|
2015-06-12 20:04:41 -07:00
|
|
|
ItemInfo item = d.dragInfo;
|
2015-04-10 13:45:42 -07:00
|
|
|
if ((d.dragSource instanceof Workspace) || (d.dragSource instanceof Folder)) {
|
2017-10-24 14:54:30 -07:00
|
|
|
onAccessibilityDrop(null, item);
|
2015-01-08 16:59:04 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Removes the item from the workspace. If the view is not null, it also removes the view.
|
|
|
|
|
*/
|
2017-10-24 14:54:30 -07:00
|
|
|
@Override
|
|
|
|
|
public void onAccessibilityDrop(View view, ItemInfo item) {
|
2015-09-14 12:01:13 -07:00
|
|
|
// Remove the item from launcher and the db, we can ignore the containerInfo in this call
|
|
|
|
|
// because we already remove the drag view from the folder (if the drag originated from
|
|
|
|
|
// a folder) in Folder.beginDrag()
|
2017-10-24 14:54:30 -07:00
|
|
|
mLauncher.removeItem(view, item, true /* deleteFromDb */);
|
|
|
|
|
mLauncher.getWorkspace().stripEmptyScreens();
|
|
|
|
|
mLauncher.getDragLayer()
|
|
|
|
|
.announceForAccessibility(getContext().getString(R.string.item_removed));
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|
2018-02-12 14:25:48 -08:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public int getControlTypeForLogging() {
|
|
|
|
|
return ControlType.REMOVE_TARGET;
|
|
|
|
|
}
|
2011-05-31 16:50:48 -07:00
|
|
|
}
|