Home | History | Annotate | Download | only in android
      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.layoutlib.bridge.android;
     18 
     19 import com.android.layoutlib.bridge.BridgeConstants;
     20 
     21 import android.util.AttributeSet;
     22 
     23 import java.util.Map;
     24 
     25 /**
     26  * An implementation of the {@link AttributeSet} interface on top of a map of attribute in the form
     27  * of (name, value).
     28  *
     29  * This is meant to be called only from {@link BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)}
     30  * in the case of LayoutParams and therefore isn't a full implementation.
     31  */
     32 public class BridgeLayoutParamsMapAttributes implements AttributeSet {
     33 
     34     private final Map<String, String> mAttributes;
     35 
     36     public BridgeLayoutParamsMapAttributes(Map<String, String> attributes) {
     37         mAttributes = attributes;
     38     }
     39 
     40     @Override
     41     public String getAttributeValue(String namespace, String name) {
     42         if (BridgeConstants.NS_RESOURCES.equals(namespace)) {
     43             return mAttributes.get(name);
     44         }
     45 
     46         return null;
     47     }
     48 
     49     // ---- the following methods are not called from
     50     // BridgeContext#obtainStyledAttributes(AttributeSet, int[], int, int)
     51     // Should they ever be called, we'll just implement them on a need basis.
     52 
     53     @Override
     54     public int getAttributeCount() {
     55         throw new UnsupportedOperationException();
     56     }
     57 
     58     @Override
     59     public String getAttributeNamespace(int index) {
     60         throw new UnsupportedOperationException();
     61     }
     62 
     63     @Override
     64     public String getAttributeName(int index) {
     65         throw new UnsupportedOperationException();
     66     }
     67 
     68     @Override
     69     public String getAttributeValue(int index) {
     70         throw new UnsupportedOperationException();
     71     }
     72 
     73     @Override
     74     public String getPositionDescription() {
     75         throw new UnsupportedOperationException();
     76     }
     77 
     78     @Override
     79     public int getAttributeNameResource(int index) {
     80         throw new UnsupportedOperationException();
     81     }
     82 
     83     @Override
     84     public int getAttributeListValue(String namespace, String attribute,
     85             String[] options, int defaultValue) {
     86         throw new UnsupportedOperationException();
     87     }
     88 
     89     @Override
     90     public boolean getAttributeBooleanValue(String namespace, String attribute,
     91             boolean defaultValue) {
     92         throw new UnsupportedOperationException();
     93     }
     94 
     95     @Override
     96     public int getAttributeResourceValue(String namespace, String attribute,
     97             int defaultValue) {
     98         throw new UnsupportedOperationException();
     99     }
    100 
    101     @Override
    102     public int getAttributeIntValue(String namespace, String attribute,
    103             int defaultValue) {
    104         throw new UnsupportedOperationException();
    105     }
    106 
    107     @Override
    108     public int getAttributeUnsignedIntValue(String namespace, String attribute,
    109             int defaultValue) {
    110         throw new UnsupportedOperationException();
    111     }
    112 
    113     @Override
    114     public float getAttributeFloatValue(String namespace, String attribute,
    115             float defaultValue) {
    116         throw new UnsupportedOperationException();
    117     }
    118 
    119     @Override
    120     public int getAttributeListValue(int index,
    121             String[] options, int defaultValue) {
    122         throw new UnsupportedOperationException();
    123     }
    124 
    125     @Override
    126     public boolean getAttributeBooleanValue(int index, boolean defaultValue) {
    127         throw new UnsupportedOperationException();
    128     }
    129 
    130     @Override
    131     public int getAttributeResourceValue(int index, int defaultValue) {
    132         throw new UnsupportedOperationException();
    133     }
    134 
    135     @Override
    136     public int getAttributeIntValue(int index, int defaultValue) {
    137         throw new UnsupportedOperationException();
    138     }
    139 
    140     @Override
    141     public int getAttributeUnsignedIntValue(int index, int defaultValue) {
    142         throw new UnsupportedOperationException();
    143     }
    144 
    145     @Override
    146     public float getAttributeFloatValue(int index, float defaultValue) {
    147         throw new UnsupportedOperationException();
    148     }
    149 
    150     @Override
    151     public String getIdAttribute() {
    152         throw new UnsupportedOperationException();
    153     }
    154 
    155     @Override
    156     public String getClassAttribute() {
    157         throw new UnsupportedOperationException();
    158     }
    159 
    160     @Override
    161     public int getIdAttributeResourceValue(int defaultValue) {
    162         throw new UnsupportedOperationException();
    163     }
    164 
    165     @Override
    166     public int getStyleAttribute() {
    167         throw new UnsupportedOperationException();
    168     }
    169 }
    170