1 /* 2 * Copyright (C) 2010 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 17 package com.android.ide.common.rendering.legacy; 18 19 import com.android.ide.common.rendering.api.IProjectCallback; 20 import com.android.resources.ResourceType; 21 import com.android.util.Pair; 22 23 /** 24 * Intermediary class implementing parts of both the old and new project call back from the 25 * layout lib API. 26 * 27 * Clients should use this instead of {@link IProjectCallback} to target both old and new 28 * Layout Libraries. 29 * 30 */ 31 @SuppressWarnings("deprecation") 32 public abstract class LegacyCallback implements 33 com.android.ide.common.rendering.api.IProjectCallback, 34 com.android.layoutlib.api.IProjectCallback { 35 36 // ------ implementation of the old interface using the new interface. 37 38 @Override getResourceValue(String type, String name)39 public final Integer getResourceValue(String type, String name) { 40 return getResourceId(ResourceType.getEnum(type), name); 41 } 42 43 @Override resolveResourceValue(int id)44 public final String[] resolveResourceValue(int id) { 45 Pair<ResourceType, String> info = resolveResourceId(id); 46 if (info != null) { 47 return new String[] { info.getSecond(), info.getFirst().getName() }; 48 } 49 50 return null; 51 } 52 53 @Override resolveResourceValue(int[] id)54 public final String resolveResourceValue(int[] id) { 55 return resolveResourceId(id); 56 } 57 58 // ------ 59 } 60