1 /*
2  * Copyright (C) 2015 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.launcher3.accessibility;
18 
19 import com.android.launcher3.CellLayout;
20 import com.android.launcher3.R;
21 import com.android.launcher3.folder.FolderPagedView;
22 
23 /**
24  * Implementation of {@link DragAndDropAccessibilityDelegate} to support DnD in a folder.
25  */
26 public class FolderAccessibilityHelper extends DragAndDropAccessibilityDelegate {
27 
28     /**
29      * 0-index position for the first cell in {@link #mView} in {@link #mParent}.
30      */
31     private final int mStartPosition;
32 
33     private final FolderPagedView mParent;
34 
FolderAccessibilityHelper(CellLayout layout)35     public FolderAccessibilityHelper(CellLayout layout) {
36         super(layout);
37         mParent = (FolderPagedView) layout.getParent();
38 
39         int index = mParent.indexOfChild(layout);
40         mStartPosition = index * layout.getCountX() * layout.getCountY();
41     }
42     @Override
intersectsValidDropTarget(int id)43     protected int intersectsValidDropTarget(int id) {
44         return Math.min(id, mParent.getAllocatedContentSize() - mStartPosition - 1);
45     }
46 
47     @Override
getLocationDescriptionForIconDrop(int id)48     protected String getLocationDescriptionForIconDrop(int id) {
49         return mContext.getString(R.string.move_to_position, id + mStartPosition + 1);
50     }
51 
52     @Override
getConfirmationForIconDrop(int id)53     protected String getConfirmationForIconDrop(int id) {
54         return mContext.getString(R.string.item_moved);
55     }
56 }
57