Home | History | Annotate | Download | only in legacy
      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     public final Integer getResourceValue(String type, String name) {
     39         return getResourceId(ResourceType.getEnum(type), name);
     40     }
     41 
     42     public final String[] resolveResourceValue(int id) {
     43         Pair<ResourceType, String> info = resolveResourceId(id);
     44         if (info != null) {
     45             return new String[] { info.getSecond(), info.getFirst().getName() };
     46         }
     47 
     48         return null;
     49     }
     50 
     51     public final String resolveResourceValue(int[] id) {
     52         return resolveResourceId(id);
     53     }
     54 
     55     // ------
     56 }
     57