1960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam/* 2960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Copyright (C) 2015 The Android Open Source Project 3960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 4960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 5960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * you may not use this file except in compliance with the License. 6960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * You may obtain a copy of the License at 7960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 8960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * http://www.apache.org/licenses/LICENSE-2.0 9960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 10960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Unless required by applicable law or agreed to in writing, software 11960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 12960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * See the License for the specific language governing permissions and 14960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * limitations under the License. 15960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 16960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 17960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lampackage com.android.setupwizardlib.items; 18960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 19960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam/** 20960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Representation of zero or more items in a list. Each instance of ItemHierarchy should be capable 21960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * of being wrapped in ItemAdapter and be displayed. 22960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 23960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * For example, {@link com.android.setupwizardlib.items.Item} is a representation of a single item, 24960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * typically with data provided from XML. {@link com.android.setupwizardlib.items.ItemGroup} 25960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * represents a list of child item hierarchies it contains, but itself does not do any display. 26960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 27960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lampublic interface ItemHierarchy { 28960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 29960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 30960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Observer for any changes in this hierarchy. If anything updated that causes this hierarchy to 31960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * show different content, this observer should be called. 32960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 33960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam interface Observer { 34960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 35960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Called when an underlying data update that can cause this hierarchy to show different 36960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * content has occurred. 37960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 38960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam void onChanged(ItemHierarchy itemHierarchy); 39960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam } 40960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 41960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 42960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Register an observer to observe changes for this item hierarchy. 43960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 44960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam void registerObserver(Observer observer); 45960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 46960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 47960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Unregister a previously registered observer. 48960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 49960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam void unregisterObserver(Observer observer); 50960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 51960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 52960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * @return the number of items this item hierarchy represent. 53960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 54960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam int getCount(); 55960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 56960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 57960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Get the item at position. 58960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 59960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * @param position An integer from 0 to {@link #getCount()}}, which indicates the position in 60960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * this item hierarchy to get the child item. 61960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * @return A representation of the item at {@code position}. Must not be {@code null}. 62960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 63960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam IItem getItemAt(int position); 64960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam 65960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam /** 66960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * Find an item hierarchy within this hierarchy which has the given ID. Or null if no match is 67960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * found. This hierarchy will be returned if our ID matches. Same restrictions for Android 68960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * resource IDs apply to this ID. In fact, typically this ID is a resource ID generated from 69960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * XML. 70960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * 71960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * @param id An ID to search for in this item hierarchy. 72960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam * @return An ItemHierarchy which matches the given ID. 73960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam */ 74960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam ItemHierarchy findItemById(int id); 75960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam} 76