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 * 245bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Modified from android.support.v7.preference.PreferenceInflater 255bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam */ 26960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lampublic class ItemInflater extends GenericInflater<ItemHierarchy> { 275bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 285bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam private static final String TAG = "ItemInflater"; 295bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 3000358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam public interface ItemParent { 3100358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam void addChild(ItemHierarchy child); 3200358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam } 3300358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam 345bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam private final Context mContext; 355bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 365bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam public ItemInflater(Context context) { 375bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam super(context); 385bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam mContext = context; 395bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam setDefaultPackage(Item.class.getPackage().getName() + "."); 405bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 415bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 425bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam @Override 435bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam public ItemInflater cloneInContext(Context newContext) { 445bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam return new ItemInflater(newContext); 455bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 465bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 475bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam /** 485bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * Return the context we are running in, for access to resources, class 495bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam * loader, etc. 505bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam */ 51de9f081976b6121f93b6debca4554226c125e12fMaurice Lam @Override 525bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam public Context getContext() { 535bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam return mContext; 545bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 555bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam 565bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam @Override 57960c0ea0b1d36904beef0f01715dd43a211e88caMaurice Lam protected void onAddChildItem(ItemHierarchy parent, ItemHierarchy child) { 5800358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam if (parent instanceof ItemParent) { 5900358e4d12e6c7ba0f1da1fa9ad57f87da9b3b1aMaurice Lam ((ItemParent) parent).addChild(child); 605bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } else { 615bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam throw new IllegalArgumentException("Cannot add child item to " + parent); 625bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 635bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam } 645bf291fde3dfd64f264d525534730514a279c8fcMaurice Lam} 65