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