1/* 2 * Copyright (C) 2017 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 17package android.support.wear.internal.widget.drawer; 18 19import android.support.annotation.MainThread; 20import android.support.annotation.RestrictTo; 21import android.support.annotation.RestrictTo.Scope; 22import android.support.wear.widget.drawer.WearableNavigationDrawerView.OnItemSelectedListener; 23import android.support.wear.widget.drawer.WearableNavigationDrawerView.WearableNavigationDrawerAdapter; 24 25import java.util.HashSet; 26import java.util.Set; 27 28/** 29 * Controls the behavior of this view where the behavior may differ between single and multi-page. 30 * 31 * @hide 32 */ 33@RestrictTo(Scope.LIBRARY_GROUP) 34public abstract class WearableNavigationDrawerPresenter { 35 36 private final Set<OnItemSelectedListener> mOnItemSelectedListeners = new HashSet<>(); 37 38 /** 39 * Indicates to the presenter that the underlying data has changed. 40 */ 41 @MainThread 42 public abstract void onDataSetChanged(); 43 44 /** 45 * Indicates to the presenter that the drawer has a new adapter. 46 */ 47 @MainThread 48 public abstract void onNewAdapter(WearableNavigationDrawerAdapter adapter); 49 50 /** 51 * Indicates to the presenter that the user has selected an item. 52 */ 53 @MainThread 54 public abstract void onSelected(int index); 55 56 /** 57 * Indicates to the presenter that the developer wishes to change which item is selected. 58 */ 59 @MainThread 60 public abstract void onSetCurrentItemRequested(int index, boolean smoothScrollTo); 61 62 /** 63 * Indicates to the presenter that the user has tapped on the drawer. 64 * 65 * @return {@code true} if the touch event has been handled and should not propagate further. 66 */ 67 @MainThread 68 public abstract boolean onDrawerTapped(); 69 70 /** 71 * Indicates to the presenter that a new {@link OnItemSelectedListener} has been added. 72 */ 73 @MainThread 74 public void onItemSelectedListenerAdded(OnItemSelectedListener listener) { 75 mOnItemSelectedListeners.add(listener); 76 } 77 78 /** 79 * Indicates to the presenter that an {@link OnItemSelectedListener} has been removed. 80 */ 81 @MainThread 82 public void onItemSelectedListenerRemoved(OnItemSelectedListener listener) { 83 mOnItemSelectedListeners.remove(listener); 84 } 85 86 /** 87 * Notifies all listeners that the item at {@code selectedPos} has been selected. 88 */ 89 @MainThread 90 void notifyItemSelectedListeners(int selectedPos) { 91 for (OnItemSelectedListener listener : mOnItemSelectedListeners) { 92 listener.onItemSelected(selectedPos); 93 } 94 } 95} 96