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