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