change package name to uiuios
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.android.uiuios.CellLayout;
|
||||
import com.android.uiuios.DropTarget.DragObject;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.dragndrop.DragController.DragListener;
|
||||
import com.android.uiuios.dragndrop.DragOptions;
|
||||
|
||||
/**
|
||||
* Utility listener to enable/disable accessibility drag flags for a ViewGroup
|
||||
* containing CellLayouts
|
||||
*/
|
||||
public class AccessibleDragListenerAdapter implements DragListener {
|
||||
|
||||
private final ViewGroup mViewGroup;
|
||||
private final int mDragType;
|
||||
|
||||
/**
|
||||
* @param parent
|
||||
* @param dragType either {@link CellLayout#WORKSPACE_ACCESSIBILITY_DRAG} or
|
||||
* {@link CellLayout#FOLDER_ACCESSIBILITY_DRAG}
|
||||
*/
|
||||
public AccessibleDragListenerAdapter(ViewGroup parent, int dragType) {
|
||||
mViewGroup = parent;
|
||||
mDragType = dragType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragStart(DragObject dragObject, DragOptions options) {
|
||||
enableAccessibleDrag(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragEnd() {
|
||||
enableAccessibleDrag(false);
|
||||
Launcher.getLauncher(mViewGroup.getContext()).getDragController().removeDragListener(this);
|
||||
}
|
||||
|
||||
protected void enableAccessibleDrag(boolean enable) {
|
||||
for (int i = 0; i < mViewGroup.getChildCount(); i++) {
|
||||
setEnableForLayout((CellLayout) mViewGroup.getChildAt(i), enable);
|
||||
}
|
||||
}
|
||||
|
||||
protected final void setEnableForLayout(CellLayout layout, boolean enable) {
|
||||
layout.enableAccessibleDrag(enable, mDragType);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.view.View.OnClickListener;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.android.uiuios.CellLayout;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.R;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
import androidx.customview.widget.ExploreByTouchHelper;
|
||||
|
||||
/**
|
||||
* Helper class to make drag-and-drop in a {@link CellLayout} accessible.
|
||||
*/
|
||||
public abstract class DragAndDropAccessibilityDelegate extends ExploreByTouchHelper
|
||||
implements OnClickListener {
|
||||
protected static final int INVALID_POSITION = -1;
|
||||
|
||||
private static final int[] sTempArray = new int[2];
|
||||
|
||||
protected final CellLayout mView;
|
||||
protected final Context mContext;
|
||||
protected final LauncherAccessibilityDelegate mDelegate;
|
||||
|
||||
private final Rect mTempRect = new Rect();
|
||||
|
||||
public DragAndDropAccessibilityDelegate(CellLayout forView) {
|
||||
super(forView);
|
||||
mView = forView;
|
||||
mContext = mView.getContext();
|
||||
mDelegate = Launcher.getLauncher(mContext).getAccessibilityDelegate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getVirtualViewAt(float x, float y) {
|
||||
if (x < 0 || y < 0 || x > mView.getMeasuredWidth() || y > mView.getMeasuredHeight()) {
|
||||
return INVALID_ID;
|
||||
}
|
||||
mView.pointToCellExact((int) x, (int) y, sTempArray);
|
||||
|
||||
// Map cell to id
|
||||
int id = sTempArray[0] + sTempArray[1] * mView.getCountX();
|
||||
return intersectsValidDropTarget(id);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the view id of the top left corner of a valid drop region or
|
||||
* {@link #INVALID_POSITION} if there is no such valid region.
|
||||
*/
|
||||
protected abstract int intersectsValidDropTarget(int id);
|
||||
|
||||
@Override
|
||||
protected void getVisibleVirtualViews(List<Integer> virtualViews) {
|
||||
// We create a virtual view for each cell of the grid
|
||||
// The cell ids correspond to cells in reading order.
|
||||
int nCells = mView.getCountX() * mView.getCountY();
|
||||
|
||||
for (int i = 0; i < nCells; i++) {
|
||||
if (intersectsValidDropTarget(i) == i) {
|
||||
virtualViews.add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean onPerformActionForVirtualView(int viewId, int action, Bundle args) {
|
||||
if (action == AccessibilityNodeInfoCompat.ACTION_CLICK && viewId != INVALID_ID) {
|
||||
String confirmation = getConfirmationForIconDrop(viewId);
|
||||
mDelegate.handleAccessibleDrop(mView, getItemBounds(viewId), confirmation);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onPerformActionForVirtualView(getFocusedVirtualView(),
|
||||
AccessibilityNodeInfoCompat.ACTION_CLICK, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateEventForVirtualView(int id, AccessibilityEvent event) {
|
||||
if (id == INVALID_ID) {
|
||||
throw new IllegalArgumentException("Invalid virtual view id");
|
||||
}
|
||||
event.setContentDescription(mContext.getString(R.string.action_move_here));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) {
|
||||
if (id == INVALID_ID) {
|
||||
throw new IllegalArgumentException("Invalid virtual view id");
|
||||
}
|
||||
|
||||
node.setContentDescription(getLocationDescriptionForIconDrop(id));
|
||||
node.setBoundsInParent(getItemBounds(id));
|
||||
|
||||
node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK);
|
||||
node.setClickable(true);
|
||||
node.setFocusable(true);
|
||||
}
|
||||
|
||||
protected abstract String getLocationDescriptionForIconDrop(int id);
|
||||
|
||||
protected abstract String getConfirmationForIconDrop(int id);
|
||||
|
||||
private Rect getItemBounds(int id) {
|
||||
int cellX = id % mView.getCountX();
|
||||
int cellY = id / mView.getCountX();
|
||||
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
|
||||
mView.cellToRect(cellX, cellY, dragInfo.info.spanX, dragInfo.info.spanY, mTempRect);
|
||||
return mTempRect;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import static com.android.uiuios.compat.AccessibilityManagerCompat.isAccessibilityEnabled;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
|
||||
import com.android.uiuios.Launcher;
|
||||
|
||||
/**
|
||||
* Periodically sends accessibility events to announce ongoing state changed. Based on the
|
||||
* implementation in ProgressBar.
|
||||
*/
|
||||
public class DragViewStateAnnouncer implements Runnable {
|
||||
|
||||
private static final int TIMEOUT_SEND_ACCESSIBILITY_EVENT = 200;
|
||||
|
||||
private final View mTargetView;
|
||||
|
||||
private DragViewStateAnnouncer(View view) {
|
||||
mTargetView = view;
|
||||
}
|
||||
|
||||
public void announce(CharSequence msg) {
|
||||
mTargetView.setContentDescription(msg);
|
||||
mTargetView.removeCallbacks(this);
|
||||
mTargetView.postDelayed(this, TIMEOUT_SEND_ACCESSIBILITY_EVENT);
|
||||
}
|
||||
|
||||
public void cancel() {
|
||||
mTargetView.removeCallbacks(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
mTargetView.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED);
|
||||
}
|
||||
|
||||
public void completeAction(int announceResId) {
|
||||
cancel();
|
||||
Launcher launcher = Launcher.getLauncher(mTargetView.getContext());
|
||||
launcher.getDragLayer().announceForAccessibility(launcher.getText(announceResId));
|
||||
}
|
||||
|
||||
public static DragViewStateAnnouncer createFor(View v) {
|
||||
return isAccessibilityEnabled(v.getContext()) ? new DragViewStateAnnouncer(v) : null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import com.android.uiuios.CellLayout;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.folder.FolderPagedView;
|
||||
|
||||
/**
|
||||
* Implementation of {@link DragAndDropAccessibilityDelegate} to support DnD in a folder.
|
||||
*/
|
||||
public class FolderAccessibilityHelper extends DragAndDropAccessibilityDelegate {
|
||||
|
||||
/**
|
||||
* 0-index position for the first cell in {@link #mView} in {@link #mParent}.
|
||||
*/
|
||||
private final int mStartPosition;
|
||||
|
||||
private final FolderPagedView mParent;
|
||||
|
||||
public FolderAccessibilityHelper(CellLayout layout) {
|
||||
super(layout);
|
||||
mParent = (FolderPagedView) layout.getParent();
|
||||
|
||||
int index = mParent.indexOfChild(layout);
|
||||
mStartPosition = index * layout.getCountX() * layout.getCountY();
|
||||
}
|
||||
@Override
|
||||
protected int intersectsValidDropTarget(int id) {
|
||||
return Math.min(id, mParent.getAllocatedContentSize() - mStartPosition - 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocationDescriptionForIconDrop(int id) {
|
||||
return mContext.getString(R.string.move_to_position, id + mStartPosition + 1);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationForIconDrop(int id) {
|
||||
return mContext.getString(R.string.item_moved);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,436 @@
|
||||
package com.android.uiuios.accessibility;
|
||||
|
||||
import static com.android.uiuios.LauncherState.NORMAL;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.appwidget.AppWidgetProviderInfo;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Rect;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.util.SparseArray;
|
||||
import android.view.View;
|
||||
import android.view.View.AccessibilityDelegate;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
|
||||
|
||||
import com.android.uiuios.AppInfo;
|
||||
import com.android.uiuios.AppWidgetResizeFrame;
|
||||
import com.android.uiuios.BubbleTextView;
|
||||
import com.android.uiuios.ButtonDropTarget;
|
||||
import com.android.uiuios.CellLayout;
|
||||
import com.android.uiuios.DropTarget.DragObject;
|
||||
import com.android.uiuios.FolderInfo;
|
||||
import com.android.uiuios.ItemInfo;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.LauncherAppWidgetInfo;
|
||||
import com.android.uiuios.LauncherSettings;
|
||||
import com.android.uiuios.LauncherSettings.Favorites;
|
||||
import com.android.uiuios.PendingAddItemInfo;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.WorkspaceItemInfo;
|
||||
import com.android.uiuios.Workspace;
|
||||
import com.android.uiuios.dragndrop.DragController.DragListener;
|
||||
import com.android.uiuios.dragndrop.DragOptions;
|
||||
import com.android.uiuios.folder.Folder;
|
||||
import com.android.uiuios.notification.NotificationListener;
|
||||
import com.android.uiuios.popup.PopupContainerWithArrow;
|
||||
import com.android.uiuios.shortcuts.DeepShortcutManager;
|
||||
import com.android.uiuios.touch.ItemLongClickListener;
|
||||
import com.android.uiuios.util.IntArray;
|
||||
import com.android.uiuios.util.Thunk;
|
||||
import com.android.uiuios.widget.LauncherAppWidgetHostView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class LauncherAccessibilityDelegate extends AccessibilityDelegate implements DragListener {
|
||||
|
||||
private static final String TAG = "LauncherAccessibilityDelegate";
|
||||
|
||||
public static final int REMOVE = R.id.action_remove;
|
||||
public static final int UNINSTALL = R.id.action_uninstall;
|
||||
public static final int RECONFIGURE = R.id.action_reconfigure;
|
||||
protected static final int ADD_TO_WORKSPACE = R.id.action_add_to_workspace;
|
||||
protected static final int MOVE = R.id.action_move;
|
||||
protected static final int MOVE_TO_WORKSPACE = R.id.action_move_to_workspace;
|
||||
protected static final int RESIZE = R.id.action_resize;
|
||||
public static final int DEEP_SHORTCUTS = R.id.action_deep_shortcuts;
|
||||
public static final int SHORTCUTS_AND_NOTIFICATIONS = R.id.action_shortcuts_and_notifications;
|
||||
|
||||
public enum DragType {
|
||||
ICON,
|
||||
FOLDER,
|
||||
WIDGET
|
||||
}
|
||||
|
||||
public static class DragInfo {
|
||||
public DragType dragType;
|
||||
public ItemInfo info;
|
||||
public View item;
|
||||
}
|
||||
|
||||
protected final SparseArray<AccessibilityAction> mActions = new SparseArray<>();
|
||||
@Thunk final Launcher mLauncher;
|
||||
|
||||
private DragInfo mDragInfo = null;
|
||||
|
||||
public LauncherAccessibilityDelegate(Launcher launcher) {
|
||||
mLauncher = launcher;
|
||||
|
||||
mActions.put(REMOVE, new AccessibilityAction(REMOVE,
|
||||
launcher.getText(R.string.remove_drop_target_label)));
|
||||
mActions.put(UNINSTALL, new AccessibilityAction(UNINSTALL,
|
||||
launcher.getText(R.string.uninstall_drop_target_label)));
|
||||
mActions.put(RECONFIGURE, new AccessibilityAction(RECONFIGURE,
|
||||
launcher.getText(R.string.gadget_setup_text)));
|
||||
mActions.put(ADD_TO_WORKSPACE, new AccessibilityAction(ADD_TO_WORKSPACE,
|
||||
launcher.getText(R.string.action_add_to_workspace)));
|
||||
mActions.put(MOVE, new AccessibilityAction(MOVE,
|
||||
launcher.getText(R.string.action_move)));
|
||||
mActions.put(MOVE_TO_WORKSPACE, new AccessibilityAction(MOVE_TO_WORKSPACE,
|
||||
launcher.getText(R.string.action_move_to_workspace)));
|
||||
mActions.put(RESIZE, new AccessibilityAction(RESIZE,
|
||||
launcher.getText(R.string.action_resize)));
|
||||
mActions.put(DEEP_SHORTCUTS, new AccessibilityAction(DEEP_SHORTCUTS,
|
||||
launcher.getText(R.string.action_deep_shortcut)));
|
||||
mActions.put(SHORTCUTS_AND_NOTIFICATIONS, new AccessibilityAction(DEEP_SHORTCUTS,
|
||||
launcher.getText(R.string.shortcuts_menu_with_notifications_description)));
|
||||
}
|
||||
|
||||
public void addAccessibilityAction(int action, int actionLabel) {
|
||||
mActions.put(action, new AccessibilityAction(action, mLauncher.getText(actionLabel)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfo info) {
|
||||
super.onInitializeAccessibilityNodeInfo(host, info);
|
||||
addSupportedActions(host, info, false);
|
||||
}
|
||||
|
||||
public void addSupportedActions(View host, AccessibilityNodeInfo info, boolean fromKeyboard) {
|
||||
if (!(host.getTag() instanceof ItemInfo)) return;
|
||||
ItemInfo item = (ItemInfo) host.getTag();
|
||||
|
||||
// If the request came from keyboard, do not add custom shortcuts as that is already
|
||||
// exposed as a direct shortcut
|
||||
if (!fromKeyboard && DeepShortcutManager.supportsShortcuts(item)) {
|
||||
info.addAction(mActions.get(NotificationListener.getInstanceIfConnected() != null
|
||||
? SHORTCUTS_AND_NOTIFICATIONS : DEEP_SHORTCUTS));
|
||||
}
|
||||
|
||||
for (ButtonDropTarget target : mLauncher.getDropTargetBar().getDropTargets()) {
|
||||
if (target.supportsAccessibilityDrop(item, host)) {
|
||||
info.addAction(mActions.get(target.getAccessibilityAction()));
|
||||
}
|
||||
}
|
||||
|
||||
// Do not add move actions for keyboard request as this uses virtual nodes.
|
||||
if (!fromKeyboard && itemSupportsAccessibleDrag(item)) {
|
||||
info.addAction(mActions.get(MOVE));
|
||||
|
||||
if (item.container >= 0) {
|
||||
info.addAction(mActions.get(MOVE_TO_WORKSPACE));
|
||||
} else if (item instanceof LauncherAppWidgetInfo) {
|
||||
if (!getSupportedResizeActions(host, (LauncherAppWidgetInfo) item).isEmpty()) {
|
||||
info.addAction(mActions.get(RESIZE));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ((item instanceof AppInfo) || (item instanceof PendingAddItemInfo)) {
|
||||
info.addAction(mActions.get(ADD_TO_WORKSPACE));
|
||||
}
|
||||
}
|
||||
|
||||
private boolean itemSupportsAccessibleDrag(ItemInfo item) {
|
||||
if (item instanceof WorkspaceItemInfo) {
|
||||
// Support the action unless the item is in a context menu.
|
||||
return item.screenId >= 0;
|
||||
}
|
||||
return (item instanceof LauncherAppWidgetInfo)
|
||||
|| (item instanceof FolderInfo);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAccessibilityAction(View host, int action, Bundle args) {
|
||||
if ((host.getTag() instanceof ItemInfo)
|
||||
&& performAction(host, (ItemInfo) host.getTag(), action)) {
|
||||
return true;
|
||||
}
|
||||
return super.performAccessibilityAction(host, action, args);
|
||||
}
|
||||
|
||||
public boolean performAction(final View host, final ItemInfo item, int action) {
|
||||
if (action == MOVE) {
|
||||
beginAccessibleDrag(host, item);
|
||||
} else if (action == ADD_TO_WORKSPACE) {
|
||||
final int[] coordinates = new int[2];
|
||||
final int screenId = findSpaceOnWorkspace(item, coordinates);
|
||||
mLauncher.getStateManager().goToState(NORMAL, true, new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
if (item instanceof AppInfo) {
|
||||
WorkspaceItemInfo info = ((AppInfo) item).makeWorkspaceItem();
|
||||
mLauncher.getModelWriter().addItemToDatabase(info,
|
||||
Favorites.CONTAINER_DESKTOP,
|
||||
screenId, coordinates[0], coordinates[1]);
|
||||
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(info);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
} else if (item instanceof PendingAddItemInfo) {
|
||||
PendingAddItemInfo info = (PendingAddItemInfo) item;
|
||||
Workspace workspace = mLauncher.getWorkspace();
|
||||
workspace.snapToPage(workspace.getPageIndexForScreenId(screenId));
|
||||
mLauncher.addPendingItem(info, Favorites.CONTAINER_DESKTOP,
|
||||
screenId, coordinates, info.spanX, info.spanY);
|
||||
}
|
||||
announceConfirmation(R.string.item_added_to_workspace);
|
||||
}
|
||||
});
|
||||
return true;
|
||||
} else if (action == MOVE_TO_WORKSPACE) {
|
||||
Folder folder = Folder.getOpen(mLauncher);
|
||||
folder.close(true);
|
||||
WorkspaceItemInfo info = (WorkspaceItemInfo) item;
|
||||
folder.getInfo().remove(info, false);
|
||||
|
||||
final int[] coordinates = new int[2];
|
||||
final int screenId = findSpaceOnWorkspace(item, coordinates);
|
||||
mLauncher.getModelWriter().moveItemInDatabase(info,
|
||||
LauncherSettings.Favorites.CONTAINER_DESKTOP,
|
||||
screenId, coordinates[0], coordinates[1]);
|
||||
|
||||
// Bind the item in next frame so that if a new workspace page was created,
|
||||
// it will get laid out.
|
||||
new Handler().post(new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(item);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
announceConfirmation(R.string.item_moved);
|
||||
}
|
||||
});
|
||||
} else if (action == RESIZE) {
|
||||
final LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) item;
|
||||
final IntArray actions = getSupportedResizeActions(host, info);
|
||||
CharSequence[] labels = new CharSequence[actions.size()];
|
||||
for (int i = 0; i < actions.size(); i++) {
|
||||
labels[i] = mLauncher.getText(actions.get(i));
|
||||
}
|
||||
|
||||
new AlertDialog.Builder(mLauncher)
|
||||
.setTitle(R.string.action_resize)
|
||||
.setItems(labels, new DialogInterface.OnClickListener() {
|
||||
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
performResizeAction(actions.get(which), host, info);
|
||||
dialog.dismiss();
|
||||
}
|
||||
})
|
||||
.show();
|
||||
return true;
|
||||
} else if (action == DEEP_SHORTCUTS) {
|
||||
return PopupContainerWithArrow.showForIcon((BubbleTextView) host) != null;
|
||||
} else {
|
||||
for (ButtonDropTarget dropTarget : mLauncher.getDropTargetBar().getDropTargets()) {
|
||||
if (dropTarget.supportsAccessibilityDrop(item, host) &&
|
||||
action == dropTarget.getAccessibilityAction()) {
|
||||
dropTarget.onAccessibilityDrop(host, item);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private IntArray getSupportedResizeActions(View host, LauncherAppWidgetInfo info) {
|
||||
IntArray actions = new IntArray();
|
||||
|
||||
AppWidgetProviderInfo providerInfo = ((LauncherAppWidgetHostView) host).getAppWidgetInfo();
|
||||
if (providerInfo == null) {
|
||||
return actions;
|
||||
}
|
||||
|
||||
CellLayout layout = (CellLayout) host.getParent().getParent();
|
||||
if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0) {
|
||||
if (layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY) ||
|
||||
layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY)) {
|
||||
actions.add(R.string.action_increase_width);
|
||||
}
|
||||
|
||||
if (info.spanX > info.minSpanX && info.spanX > 1) {
|
||||
actions.add(R.string.action_decrease_width);
|
||||
}
|
||||
}
|
||||
|
||||
if ((providerInfo.resizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0) {
|
||||
if (layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1) ||
|
||||
layout.isRegionVacant(info.cellX, info.cellY - 1, info.spanX, 1)) {
|
||||
actions.add(R.string.action_increase_height);
|
||||
}
|
||||
|
||||
if (info.spanY > info.minSpanY && info.spanY > 1) {
|
||||
actions.add(R.string.action_decrease_height);
|
||||
}
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Thunk void performResizeAction(int action, View host, LauncherAppWidgetInfo info) {
|
||||
CellLayout.LayoutParams lp = (CellLayout.LayoutParams) host.getLayoutParams();
|
||||
CellLayout layout = (CellLayout) host.getParent().getParent();
|
||||
layout.markCellsAsUnoccupiedForView(host);
|
||||
|
||||
if (action == R.string.action_increase_width) {
|
||||
if (((host.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL)
|
||||
&& layout.isRegionVacant(info.cellX - 1, info.cellY, 1, info.spanY))
|
||||
|| !layout.isRegionVacant(info.cellX + info.spanX, info.cellY, 1, info.spanY)) {
|
||||
lp.cellX --;
|
||||
info.cellX --;
|
||||
}
|
||||
lp.cellHSpan ++;
|
||||
info.spanX ++;
|
||||
} else if (action == R.string.action_decrease_width) {
|
||||
lp.cellHSpan --;
|
||||
info.spanX --;
|
||||
} else if (action == R.string.action_increase_height) {
|
||||
if (!layout.isRegionVacant(info.cellX, info.cellY + info.spanY, info.spanX, 1)) {
|
||||
lp.cellY --;
|
||||
info.cellY --;
|
||||
}
|
||||
lp.cellVSpan ++;
|
||||
info.spanY ++;
|
||||
} else if (action == R.string.action_decrease_height) {
|
||||
lp.cellVSpan --;
|
||||
info.spanY --;
|
||||
}
|
||||
|
||||
layout.markCellsAsOccupiedForView(host);
|
||||
Rect sizeRange = new Rect();
|
||||
AppWidgetResizeFrame.getWidgetSizeRanges(mLauncher, info.spanX, info.spanY, sizeRange);
|
||||
((LauncherAppWidgetHostView) host).updateAppWidgetSize(null,
|
||||
sizeRange.left, sizeRange.top, sizeRange.right, sizeRange.bottom);
|
||||
host.requestLayout();
|
||||
mLauncher.getModelWriter().updateItemInDatabase(info);
|
||||
announceConfirmation(mLauncher.getString(R.string.widget_resized, info.spanX, info.spanY));
|
||||
}
|
||||
|
||||
@Thunk void announceConfirmation(int resId) {
|
||||
announceConfirmation(mLauncher.getResources().getString(resId));
|
||||
}
|
||||
|
||||
@Thunk void announceConfirmation(String confirmation) {
|
||||
mLauncher.getDragLayer().announceForAccessibility(confirmation);
|
||||
|
||||
}
|
||||
|
||||
public boolean isInAccessibleDrag() {
|
||||
return mDragInfo != null;
|
||||
}
|
||||
|
||||
public DragInfo getDragInfo() {
|
||||
return mDragInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param clickedTarget the actual view that was clicked
|
||||
* @param dropLocation relative to {@param clickedTarget}. If provided, its center is used
|
||||
* as the actual drop location otherwise the views center is used.
|
||||
*/
|
||||
public void handleAccessibleDrop(View clickedTarget, Rect dropLocation,
|
||||
String confirmation) {
|
||||
if (!isInAccessibleDrag()) return;
|
||||
|
||||
int[] loc = new int[2];
|
||||
if (dropLocation == null) {
|
||||
loc[0] = clickedTarget.getWidth() / 2;
|
||||
loc[1] = clickedTarget.getHeight() / 2;
|
||||
} else {
|
||||
loc[0] = dropLocation.centerX();
|
||||
loc[1] = dropLocation.centerY();
|
||||
}
|
||||
|
||||
mLauncher.getDragLayer().getDescendantCoordRelativeToSelf(clickedTarget, loc);
|
||||
mLauncher.getDragController().completeAccessibleDrag(loc);
|
||||
|
||||
if (!TextUtils.isEmpty(confirmation)) {
|
||||
announceConfirmation(confirmation);
|
||||
}
|
||||
}
|
||||
|
||||
public void beginAccessibleDrag(View item, ItemInfo info) {
|
||||
mDragInfo = new DragInfo();
|
||||
mDragInfo.info = info;
|
||||
mDragInfo.item = item;
|
||||
mDragInfo.dragType = DragType.ICON;
|
||||
if (info instanceof FolderInfo) {
|
||||
mDragInfo.dragType = DragType.FOLDER;
|
||||
} else if (info instanceof LauncherAppWidgetInfo) {
|
||||
mDragInfo.dragType = DragType.WIDGET;
|
||||
}
|
||||
|
||||
Rect pos = new Rect();
|
||||
mLauncher.getDragLayer().getDescendantRectRelativeToSelf(item, pos);
|
||||
mLauncher.getDragController().prepareAccessibleDrag(pos.centerX(), pos.centerY());
|
||||
mLauncher.getDragController().addDragListener(this);
|
||||
|
||||
DragOptions options = new DragOptions();
|
||||
options.isAccessibleDrag = true;
|
||||
ItemLongClickListener.beginDrag(item, mLauncher, info, options);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragStart(DragObject dragObject, DragOptions options) {
|
||||
// No-op
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDragEnd() {
|
||||
mLauncher.getDragController().removeDragListener(this);
|
||||
mDragInfo = null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find empty space on the workspace and returns the screenId.
|
||||
*/
|
||||
protected int findSpaceOnWorkspace(ItemInfo info, int[] outCoordinates) {
|
||||
Workspace workspace = mLauncher.getWorkspace();
|
||||
IntArray workspaceScreens = workspace.getScreenOrder();
|
||||
int screenId;
|
||||
|
||||
// First check if there is space on the current screen.
|
||||
int screenIndex = workspace.getCurrentPage();
|
||||
screenId = workspaceScreens.get(screenIndex);
|
||||
CellLayout layout = (CellLayout) workspace.getPageAt(screenIndex);
|
||||
|
||||
boolean found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
|
||||
screenIndex = 0;
|
||||
while (!found && screenIndex < workspaceScreens.size()) {
|
||||
screenId = workspaceScreens.get(screenIndex);
|
||||
layout = (CellLayout) workspace.getPageAt(screenIndex);
|
||||
found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
|
||||
screenIndex++;
|
||||
}
|
||||
|
||||
if (found) {
|
||||
return screenId;
|
||||
}
|
||||
|
||||
workspace.addExtraEmptyScreen();
|
||||
screenId = workspace.commitExtraEmptyScreen();
|
||||
layout = workspace.getScreenWithId(screenId);
|
||||
found = layout.findCellForSpan(outCoordinates, info.spanX, info.spanY);
|
||||
|
||||
if (!found) {
|
||||
Log.wtf(TAG, "Not enough space on an empty screen");
|
||||
}
|
||||
return screenId;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import static com.android.uiuios.LauncherState.NORMAL;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.accessibility.AccessibilityNodeInfo;
|
||||
import android.view.accessibility.AccessibilityNodeInfo.AccessibilityAction;
|
||||
|
||||
import com.android.uiuios.AbstractFloatingView;
|
||||
import com.android.uiuios.ItemInfo;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.LauncherSettings;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.WorkspaceItemInfo;
|
||||
import com.android.uiuios.notification.NotificationMainView;
|
||||
import com.android.uiuios.shortcuts.DeepShortcutView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Extension of {@link LauncherAccessibilityDelegate} with actions specific to shortcuts in
|
||||
* deep shortcuts menu.
|
||||
*/
|
||||
public class ShortcutMenuAccessibilityDelegate extends LauncherAccessibilityDelegate {
|
||||
|
||||
private static final int DISMISS_NOTIFICATION = R.id.action_dismiss_notification;
|
||||
|
||||
public ShortcutMenuAccessibilityDelegate(Launcher launcher) {
|
||||
super(launcher);
|
||||
mActions.put(DISMISS_NOTIFICATION, new AccessibilityAction(DISMISS_NOTIFICATION,
|
||||
launcher.getText(R.string.action_dismiss_notification)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSupportedActions(View host, AccessibilityNodeInfo info, boolean fromKeyboard) {
|
||||
if ((host.getParent() instanceof DeepShortcutView)) {
|
||||
info.addAction(mActions.get(ADD_TO_WORKSPACE));
|
||||
} else if (host instanceof NotificationMainView) {
|
||||
if (((NotificationMainView) host).canChildBeDismissed()) {
|
||||
info.addAction(mActions.get(DISMISS_NOTIFICATION));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean performAction(View host, ItemInfo item, int action) {
|
||||
if (action == ADD_TO_WORKSPACE) {
|
||||
if (!(host.getParent() instanceof DeepShortcutView)) {
|
||||
return false;
|
||||
}
|
||||
final WorkspaceItemInfo info = ((DeepShortcutView) host.getParent()).getFinalInfo();
|
||||
final int[] coordinates = new int[2];
|
||||
final int screenId = findSpaceOnWorkspace(item, coordinates);
|
||||
Runnable onComplete = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
mLauncher.getModelWriter().addItemToDatabase(info,
|
||||
LauncherSettings.Favorites.CONTAINER_DESKTOP,
|
||||
screenId, coordinates[0], coordinates[1]);
|
||||
ArrayList<ItemInfo> itemList = new ArrayList<>();
|
||||
itemList.add(info);
|
||||
mLauncher.bindItems(itemList, true);
|
||||
AbstractFloatingView.closeAllOpenViews(mLauncher);
|
||||
announceConfirmation(R.string.item_added_to_workspace);
|
||||
}
|
||||
};
|
||||
|
||||
mLauncher.getStateManager().goToState(NORMAL, true, onComplete);
|
||||
return true;
|
||||
} else if (action == DISMISS_NOTIFICATION) {
|
||||
if (!(host instanceof NotificationMainView)) {
|
||||
return false;
|
||||
}
|
||||
((NotificationMainView) host).onChildDismissed();
|
||||
announceConfirmation(R.string.notification_dismissed);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* 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.uiuios.accessibility;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
|
||||
import com.android.uiuios.AppInfo;
|
||||
import com.android.uiuios.CellLayout;
|
||||
import com.android.uiuios.FolderInfo;
|
||||
import com.android.uiuios.ItemInfo;
|
||||
import com.android.uiuios.Launcher;
|
||||
import com.android.uiuios.R;
|
||||
import com.android.uiuios.WorkspaceItemInfo;
|
||||
import com.android.uiuios.accessibility.LauncherAccessibilityDelegate.DragType;
|
||||
import com.android.uiuios.dragndrop.DragLayer;
|
||||
|
||||
import androidx.core.view.accessibility.AccessibilityNodeInfoCompat;
|
||||
|
||||
/**
|
||||
* Implementation of {@link DragAndDropAccessibilityDelegate} to support DnD on workspace.
|
||||
*/
|
||||
public class WorkspaceAccessibilityHelper extends DragAndDropAccessibilityDelegate {
|
||||
|
||||
private final Rect mTempRect = new Rect();
|
||||
private final int[] mTempCords = new int[2];
|
||||
|
||||
public WorkspaceAccessibilityHelper(CellLayout layout) {
|
||||
super(layout);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find the virtual view id corresponding to the top left corner of any drop region by which
|
||||
* the passed id is contained. For an icon, this is simply
|
||||
*/
|
||||
@Override
|
||||
protected int intersectsValidDropTarget(int id) {
|
||||
int mCountX = mView.getCountX();
|
||||
int mCountY = mView.getCountY();
|
||||
|
||||
int x = id % mCountX;
|
||||
int y = id / mCountX;
|
||||
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
|
||||
|
||||
if (dragInfo.dragType == DragType.WIDGET && !mView.acceptsWidget()) {
|
||||
return INVALID_POSITION;
|
||||
}
|
||||
|
||||
if (dragInfo.dragType == DragType.WIDGET) {
|
||||
// For a widget, every cell must be vacant. In addition, we will return any valid
|
||||
// drop target by which the passed id is contained.
|
||||
boolean fits = false;
|
||||
|
||||
// These represent the amount that we can back off if we hit a problem. They
|
||||
// get consumed as we move up and to the right, trying new regions.
|
||||
int spanX = dragInfo.info.spanX;
|
||||
int spanY = dragInfo.info.spanY;
|
||||
|
||||
for (int m = 0; m < spanX; m++) {
|
||||
for (int n = 0; n < spanY; n++) {
|
||||
|
||||
fits = true;
|
||||
int x0 = x - m;
|
||||
int y0 = y - n;
|
||||
|
||||
if (x0 < 0 || y0 < 0) continue;
|
||||
|
||||
for (int i = x0; i < x0 + spanX; i++) {
|
||||
if (!fits) break;
|
||||
for (int j = y0; j < y0 + spanY; j++) {
|
||||
if (i >= mCountX || j >= mCountY || mView.isOccupied(i, j)) {
|
||||
fits = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fits) {
|
||||
return x0 + mCountX * y0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return INVALID_POSITION;
|
||||
} else {
|
||||
// For an icon, we simply check the view directly below
|
||||
View child = mView.getChildAt(x, y);
|
||||
if (child == null || child == dragInfo.item) {
|
||||
// Empty cell. Good for an icon or folder.
|
||||
return id;
|
||||
} else if (dragInfo.dragType != DragType.FOLDER) {
|
||||
// For icons, we can consider cells that have another icon or a folder.
|
||||
ItemInfo info = (ItemInfo) child.getTag();
|
||||
if (info instanceof AppInfo || info instanceof FolderInfo ||
|
||||
info instanceof WorkspaceItemInfo) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
return INVALID_POSITION;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getConfirmationForIconDrop(int id) {
|
||||
int x = id % mView.getCountX();
|
||||
int y = id / mView.getCountX();
|
||||
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
|
||||
|
||||
View child = mView.getChildAt(x, y);
|
||||
if (child == null || child == dragInfo.item) {
|
||||
return mContext.getString(R.string.item_moved);
|
||||
} else {
|
||||
ItemInfo info = (ItemInfo) child.getTag();
|
||||
if (info instanceof AppInfo || info instanceof WorkspaceItemInfo) {
|
||||
return mContext.getString(R.string.folder_created);
|
||||
|
||||
} else if (info instanceof FolderInfo) {
|
||||
return mContext.getString(R.string.added_to_folder);
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPopulateNodeForVirtualView(int id, AccessibilityNodeInfoCompat node) {
|
||||
super.onPopulateNodeForVirtualView(id, node);
|
||||
|
||||
|
||||
// ExploreByTouchHelper does not currently handle view scale.
|
||||
// Update BoundsInScreen to appropriate value.
|
||||
DragLayer dragLayer = Launcher.getLauncher(mView.getContext()).getDragLayer();
|
||||
mTempCords[0] = mTempCords[1] = 0;
|
||||
float scale = dragLayer.getDescendantCoordRelativeToSelf(mView, mTempCords);
|
||||
|
||||
node.getBoundsInParent(mTempRect);
|
||||
mTempRect.left = mTempCords[0] + (int) (mTempRect.left * scale);
|
||||
mTempRect.right = mTempCords[0] + (int) (mTempRect.right * scale);
|
||||
mTempRect.top = mTempCords[1] + (int) (mTempRect.top * scale);
|
||||
mTempRect.bottom = mTempCords[1] + (int) (mTempRect.bottom * scale);
|
||||
node.setBoundsInScreen(mTempRect);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getLocationDescriptionForIconDrop(int id) {
|
||||
int x = id % mView.getCountX();
|
||||
int y = id / mView.getCountX();
|
||||
LauncherAccessibilityDelegate.DragInfo dragInfo = mDelegate.getDragInfo();
|
||||
|
||||
View child = mView.getChildAt(x, y);
|
||||
if (child == null || child == dragInfo.item) {
|
||||
return mView.getItemMoveDescription(x, y);
|
||||
} else {
|
||||
return getDescriptionForDropOver(child, mContext);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getDescriptionForDropOver(View overChild, Context context) {
|
||||
ItemInfo info = (ItemInfo) overChild.getTag();
|
||||
if (info instanceof WorkspaceItemInfo) {
|
||||
return context.getString(R.string.create_folder_with, info.title);
|
||||
} else if (info instanceof FolderInfo) {
|
||||
if (TextUtils.isEmpty(info.title)) {
|
||||
// Find the first item in the folder.
|
||||
FolderInfo folder = (FolderInfo) info;
|
||||
WorkspaceItemInfo firstItem = null;
|
||||
for (WorkspaceItemInfo shortcut : folder.contents) {
|
||||
if (firstItem == null || firstItem.rank > shortcut.rank) {
|
||||
firstItem = shortcut;
|
||||
}
|
||||
}
|
||||
|
||||
if (firstItem != null) {
|
||||
return context.getString(R.string.add_to_folder_with_app, firstItem.title);
|
||||
}
|
||||
}
|
||||
return context.getString(R.string.add_to_folder, info.title);
|
||||
}
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user