1/* 2 * Copyright (C) 2015 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 17package android.support.v7.internal.widget; 18 19import org.xmlpull.v1.XmlPullParserException; 20 21import android.content.res.AssetFileDescriptor; 22import android.content.res.AssetManager; 23import android.content.res.ColorStateList; 24import android.content.res.Configuration; 25import android.content.res.Resources; 26import android.content.res.TypedArray; 27import android.content.res.XmlResourceParser; 28import android.graphics.Movie; 29import android.graphics.drawable.Drawable; 30import android.graphics.drawable.Drawable.ConstantState; 31import android.os.Bundle; 32import android.util.AttributeSet; 33import android.util.DisplayMetrics; 34import android.util.LongSparseArray; 35import android.util.TypedValue; 36 37import java.io.IOException; 38import java.io.InputStream; 39 40/** 41 * This extends Resources but delegates the calls to another Resources object. This enables 42 * any customization done by some subclass of Resources to be also picked up. 43 */ 44class ResourcesWrapper extends Resources { 45 46 private final Resources mResources; 47 48 public ResourcesWrapper(Resources resources) { 49 super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration()); 50 mResources = resources; 51 } 52 53 @Override 54 public CharSequence getText(int id) throws NotFoundException { 55 return mResources.getText(id); 56 } 57 58 @Override 59 public CharSequence getQuantityText(int id, int quantity) throws NotFoundException { 60 return mResources.getQuantityText(id, quantity); 61 } 62 63 @Override 64 public String getString(int id) throws NotFoundException { 65 return mResources.getString(id); 66 } 67 68 @Override 69 public String getString(int id, Object... formatArgs) throws NotFoundException { 70 return mResources.getString(id, formatArgs); 71 } 72 73 @Override 74 public String getQuantityString(int id, int quantity, Object... formatArgs) 75 throws NotFoundException { 76 return mResources.getQuantityString(id, quantity, formatArgs); 77 } 78 79 @Override 80 public String getQuantityString(int id, int quantity) throws NotFoundException { 81 return mResources.getQuantityString(id, quantity); 82 } 83 84 @Override 85 public CharSequence getText(int id, CharSequence def) { 86 return mResources.getText(id, def); 87 } 88 89 @Override 90 public CharSequence[] getTextArray(int id) throws NotFoundException { 91 return mResources.getTextArray(id); 92 } 93 94 @Override 95 public String[] getStringArray(int id) throws NotFoundException { 96 return mResources.getStringArray(id); 97 } 98 99 @Override 100 public int[] getIntArray(int id) throws NotFoundException { 101 return mResources.getIntArray(id); 102 } 103 104 @Override 105 public TypedArray obtainTypedArray(int id) throws NotFoundException { 106 return mResources.obtainTypedArray(id); 107 } 108 109 @Override 110 public float getDimension(int id) throws NotFoundException { 111 return mResources.getDimension(id); 112 } 113 114 @Override 115 public int getDimensionPixelOffset(int id) throws NotFoundException { 116 return mResources.getDimensionPixelOffset(id); 117 } 118 119 @Override 120 public int getDimensionPixelSize(int id) throws NotFoundException { 121 return mResources.getDimensionPixelSize(id); 122 } 123 124 @Override 125 public float getFraction(int id, int base, int pbase) { 126 return mResources.getFraction(id, base, pbase); 127 } 128 129 @Override 130 public Drawable getDrawable(int id) throws NotFoundException { 131 return mResources.getDrawable(id); 132 } 133 134 @Override 135 public Drawable getDrawable(int id, Theme theme) throws NotFoundException { 136 return mResources.getDrawable(id, theme); 137 } 138 139 @Override 140 public Drawable getDrawableForDensity(int id, int density) throws NotFoundException { 141 return mResources.getDrawableForDensity(id, density); 142 } 143 144 @Override 145 public Drawable getDrawableForDensity(int id, int density, Theme theme) { 146 return mResources.getDrawableForDensity(id, density, theme); 147 } 148 149 @Override 150 public Movie getMovie(int id) throws NotFoundException { 151 return mResources.getMovie(id); 152 } 153 154 @Override 155 public int getColor(int id) throws NotFoundException { 156 return mResources.getColor(id); 157 } 158 159 @Override 160 public ColorStateList getColorStateList(int id) throws NotFoundException { 161 return mResources.getColorStateList(id); 162 } 163 164 @Override 165 public boolean getBoolean(int id) throws NotFoundException { 166 return mResources.getBoolean(id); 167 } 168 169 @Override 170 public int getInteger(int id) throws NotFoundException { 171 return mResources.getInteger(id); 172 } 173 174 @Override 175 public XmlResourceParser getLayout(int id) throws NotFoundException { 176 return mResources.getLayout(id); 177 } 178 179 @Override 180 public XmlResourceParser getAnimation(int id) throws NotFoundException { 181 return mResources.getAnimation(id); 182 } 183 184 @Override 185 public XmlResourceParser getXml(int id) throws NotFoundException { 186 return mResources.getXml(id); 187 } 188 189 @Override 190 public InputStream openRawResource(int id) throws NotFoundException { 191 return mResources.openRawResource(id); 192 } 193 194 @Override 195 public InputStream openRawResource(int id, TypedValue value) throws NotFoundException { 196 return mResources.openRawResource(id, value); 197 } 198 199 @Override 200 public AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException { 201 return mResources.openRawResourceFd(id); 202 } 203 204 @Override 205 public void getValue(int id, TypedValue outValue, boolean resolveRefs) 206 throws NotFoundException { 207 mResources.getValue(id, outValue, resolveRefs); 208 } 209 210 @Override 211 public void getValueForDensity(int id, int density, TypedValue outValue, boolean resolveRefs) 212 throws NotFoundException { 213 mResources.getValueForDensity(id, density, outValue, resolveRefs); 214 } 215 216 @Override 217 public void getValue(String name, TypedValue outValue, boolean resolveRefs) 218 throws NotFoundException { 219 mResources.getValue(name, outValue, resolveRefs); 220 } 221 222 @Override 223 public TypedArray obtainAttributes(AttributeSet set, int[] attrs) { 224 return mResources.obtainAttributes(set, attrs); 225 } 226 227 @Override 228 public void updateConfiguration(Configuration config, DisplayMetrics metrics) { 229 super.updateConfiguration(config, metrics); 230 if (mResources != null) { // called from super's constructor. So, need to check. 231 mResources.updateConfiguration(config, metrics); 232 } 233 } 234 235 @Override 236 public DisplayMetrics getDisplayMetrics() { 237 return mResources.getDisplayMetrics(); 238 } 239 240 @Override 241 public Configuration getConfiguration() { 242 return mResources.getConfiguration(); 243 } 244 245 @Override 246 public int getIdentifier(String name, String defType, String defPackage) { 247 return mResources.getIdentifier(name, defType, defPackage); 248 } 249 250 @Override 251 public String getResourceName(int resid) throws NotFoundException { 252 return mResources.getResourceName(resid); 253 } 254 255 @Override 256 public String getResourcePackageName(int resid) throws NotFoundException { 257 return mResources.getResourcePackageName(resid); 258 } 259 260 @Override 261 public String getResourceTypeName(int resid) throws NotFoundException { 262 return mResources.getResourceTypeName(resid); 263 } 264 265 @Override 266 public String getResourceEntryName(int resid) throws NotFoundException { 267 return mResources.getResourceEntryName(resid); 268 } 269 270 @Override 271 public void parseBundleExtras(XmlResourceParser parser, Bundle outBundle) 272 throws XmlPullParserException, IOException { 273 mResources.parseBundleExtras(parser, outBundle); 274 } 275 276 @Override 277 public void parseBundleExtra(String tagName, AttributeSet attrs, Bundle outBundle) 278 throws XmlPullParserException { 279 mResources.parseBundleExtra(tagName, attrs, outBundle); 280 } 281} 282 283