15bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam/* 25bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Copyright (C) 2015 The Android Open Source Project 35bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * 45bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Licensed under the Apache License, Version 2.0 (the "License"); 55bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * you may not use this file except in compliance with the License. 65bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * You may obtain a copy of the License at 75bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * 85bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * http://www.apache.org/licenses/LICENSE-2.0 95bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * 105bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Unless required by applicable law or agreed to in writing, software 115bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * distributed under the License is distributed on an "AS IS" BASIS, 125bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 135bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * See the License for the specific language governing permissions and 145bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * limitations under the License 155bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam */ 165bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 175bf291fde3dfd64f264d525534730514a279c8fcMaurice Lampackage com.android.setupwizardlib.items; 185bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 195bf291fde3dfd64f264d525534730514a279c8fcMaurice Lamimport android.content.Context; 205bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 215bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam/** 225bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Inflate {@link Item} hierarchies from XML files. 235bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam */ 24c64c94744da6d3d139c24be7dd62cbb3ceae0eb5Maurice Lampublic class ItemInflater extends ReflectionInflater<ItemHierarchy> { 255bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 2600358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam public interface ItemParent { 2700358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam void addChild(ItemHierarchy child); 2800358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam } 2900358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam 305bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam public ItemInflater(Context context) { 315bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam super(context); 325bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam setDefaultPackage(Item.class.getPackage().getName() + "."); 335bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 345bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 355bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam @Override 36960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam protected void onAddChildItem(ItemHierarchy parent, ItemHierarchy child) { 3700358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam if (parent instanceof ItemParent) { 3800358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam ((ItemParent) parent).addChild(child); 395bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } else { 405bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam throw new IllegalArgumentException("Cannot add child item to " + parent); 415bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 425bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 435bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam} 44