1 /** 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14 package com.android.healthconnect.controller.datasources.appsources 15 16 import android.content.Context 17 import android.os.Bundle 18 import android.view.View 19 import androidx.core.view.accessibility.AccessibilityNodeInfoCompat 20 import androidx.recyclerview.widget.LinearLayoutManager 21 import androidx.recyclerview.widget.RecyclerView 22 import com.android.healthconnect.controller.R 23 24 class AppSourcesLinearLayoutManager(context: Context?, private val adapter: AppSourcesAdapter) : 25 LinearLayoutManager(context) { onInitializeAccessibilityNodeInfoForItemnull26 override fun onInitializeAccessibilityNodeInfoForItem( 27 recycler: RecyclerView.Recycler, 28 state: RecyclerView.State, 29 host: View, 30 info: AccessibilityNodeInfoCompat 31 ) { 32 super.onInitializeAccessibilityNodeInfoForItem(recycler, state, host, info) 33 val position = getPosition(host) 34 if (position > 0) { 35 info.addAction( 36 AccessibilityNodeInfoCompat.AccessibilityActionCompat( 37 R.id.action_drag_move_up, 38 host.context.getString(R.string.action_drag_label_move_up))) 39 } 40 if (position < itemCount - 1) { 41 info.addAction( 42 AccessibilityNodeInfoCompat.AccessibilityActionCompat( 43 R.id.action_drag_move_down, 44 host.context.getString(R.string.action_drag_label_move_down))) 45 } 46 } 47 performAccessibilityActionForItemnull48 override fun performAccessibilityActionForItem( 49 recycler: RecyclerView.Recycler, 50 state: RecyclerView.State, 51 host: View, 52 action: Int, 53 args: Bundle? 54 ): Boolean { 55 val position = getPosition(host) 56 if (action == R.id.action_drag_move_up) { 57 adapter.onItemMove(position, position - 1) 58 return true 59 } 60 if (action == R.id.action_drag_move_down) { 61 adapter.onItemMove(position, position + 1) 62 return true 63 } 64 return false 65 } 66 } 67