Home | History | Annotate | Download | only in render
      1 /*
      2  * Copyright (C) 2011 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.example.android.render;
     18 
     19 import com.android.ide.common.rendering.api.AdapterBinding;
     20 import com.android.ide.common.rendering.api.ILayoutPullParser;
     21 import com.android.ide.common.rendering.api.IProjectCallback;
     22 import com.android.ide.common.rendering.api.ResourceReference;
     23 import com.android.ide.common.rendering.api.ResourceValue;
     24 import com.android.resources.ResourceType;
     25 import com.android.util.Pair;
     26 
     27 import java.util.HashMap;
     28 import java.util.Map;
     29 
     30 /**
     31  * Simple implementation of {@link IProjectCallback}. This is a very basic implementation that
     32  * cannot support custom classes. Look for the one in ADT for custom class support.
     33  *
     34  * Because there's no custom view support, the int to resource name is all dynamic instad of
     35  * looking up in the R.java class that was compiled.
     36  *
     37  */
     38 public class ProjectCallback implements IProjectCallback {
     39 
     40     private Map<ResourceType, Map<String, Integer>> mIdMap =
     41             new HashMap<ResourceType, Map<String, Integer>>();
     42     private Map<Integer, Pair<ResourceType, String>> mReverseIdMap =
     43             new HashMap<Integer, Pair<ResourceType,String>>();
     44 
     45     public ProjectCallback() {
     46 
     47     }
     48 
     49     public AdapterBinding getAdapterBinding(ResourceReference adapterViewRef, Object adapterCookie,
     50             Object viewObject) {
     51         // TODO Auto-generated method stub
     52         return null;
     53     }
     54 
     55     public Object getAdapterItemValue(ResourceReference adapterView, Object adapterCookie,
     56             ResourceReference itemRef, int fullPosition, int positionPerType,
     57             int fullParentPosition, int parentPositionPerType, ResourceReference viewRef,
     58             ViewAttribute viewAttribute, Object defaultValue) {
     59         // TODO Auto-generated method stub
     60         return null;
     61     }
     62 
     63     public String getNamespace() {
     64         // no custom class == no custom attribute, this is not needed.
     65         return null;
     66     }
     67 
     68     public ILayoutPullParser getParser(String layoutName) {
     69         // don't support custom parser for included files.
     70         return null;
     71     }
     72 
     73     public ILayoutPullParser getParser(ResourceValue layoutResource) {
     74         // don't support custom parser for included files.
     75         return null;
     76     }
     77 
     78     public Integer getResourceId(ResourceType type, String name) {
     79         // since we don't have access to compiled id, generate one on the fly.
     80         Map<String, Integer> typeMap = mIdMap.get(type);
     81         if (typeMap == null) {
     82             typeMap = new HashMap<String, Integer>();
     83             mIdMap.put(type, typeMap);
     84         }
     85 
     86         Integer value = typeMap.get(name);
     87         if (value == null) {
     88             value = typeMap.size() + 1;
     89             typeMap.put(name, value);
     90             mReverseIdMap.put(value, Pair.of(type, name));
     91         }
     92 
     93         return value;
     94     }
     95 
     96     @SuppressWarnings("unchecked")
     97     public Object loadView(String name, Class[] constructorSignature, Object[] constructorArgs)
     98             throws ClassNotFoundException, Exception {
     99         // don't support custom views.
    100         return null;
    101     }
    102 
    103     public Pair<ResourceType, String> resolveResourceId(int id) {
    104         return mReverseIdMap.get(id);
    105     }
    106 
    107     public String resolveResourceId(int[] id) {
    108         // this is needed only when custom views have custom styleable
    109         return null;
    110     }
    111 
    112 }
    113