/*
* Copyright (C) 2014 SCVNGR, Inc. d/b/a LevelUp
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.scvngr.levelup.core.test;
import android.content.res.AssetFileDescriptor;
import android.content.res.ColorStateList;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
import android.graphics.Movie;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.TypedValue;
import java.io.InputStream;
/**
* A wrapper for {@link Resources}. All methods call through to the wrapped {@link Resources} by
* default. Each method can be overridden to provide test-specific behavior.
*/
public class ResourcesWrapper extends Resources {
@NonNull
private final Resources mResources;
public ResourcesWrapper(@NonNull final Resources resources) {
super(resources.getAssets(), resources.getDisplayMetrics(), resources.getConfiguration());
mResources = resources;
}
@Override
public void updateConfiguration(Configuration config, DisplayMetrics metrics) {
// This method is called by the constructor, mResources may be null.
if (null != mResources) {
mResources.updateConfiguration(config, metrics);
}
}
@Override
public CharSequence getText(int id) throws NotFoundException {
return mResources.getText(id);
}
@Override
public CharSequence getQuantityText(int id, int quantity) throws NotFoundException {
return mResources.getQuantityText(id, quantity);
}
@Override
public String getString(int id) throws NotFoundException {
return mResources.getString(id);
}
@Override
public String getString(int id, Object... formatArgs) throws NotFoundException {
return mResources.getString(id, formatArgs);
}
@Override
public String getQuantityString(int id, int quantity, Object... formatArgs)
throws NotFoundException {
return mResources.getQuantityString(id, quantity, formatArgs);
}
@Override
public String getQuantityString(int id, int quantity) throws NotFoundException {
return mResources.getQuantityString(id, quantity);
}
@Override
public CharSequence getText(int id, CharSequence def) {
return mResources.getText(id, def);
}
@Override
public CharSequence[] getTextArray(int id) throws NotFoundException {
return mResources.getTextArray(id);
}
@Override
public String[] getStringArray(int id) throws NotFoundException {
return mResources.getStringArray(id);
}
@Override
public int[] getIntArray(int id) throws NotFoundException {
return mResources.getIntArray(id);
}
@Override
public TypedArray obtainTypedArray(int id) throws NotFoundException {
return mResources.obtainTypedArray(id);
}
@Override
public float getDimension(int id) throws NotFoundException {
return mResources.getDimension(id);
}
@Override
public int getDimensionPixelOffset(int id) throws NotFoundException {
return mResources.getDimensionPixelOffset(id);
}
@Override
public int getDimensionPixelSize(int id) throws NotFoundException {
return mResources.getDimensionPixelSize(id);
}
@Override
public Drawable getDrawable(int id) throws NotFoundException {
return mResources.getDrawable(id);
}
@Override
public Movie getMovie(int id) throws NotFoundException {
return mResources.getMovie(id);
}
@Override
public int getColor(int id) throws NotFoundException {
return mResources.getColor(id);
}
@Override
public ColorStateList getColorStateList(int id) throws NotFoundException {
return mResources.getColorStateList(id);
}
@Override
public int getInteger(int id) throws NotFoundException {
return mResources.getInteger(id);
}
@Override
public XmlResourceParser getLayout(int id) throws NotFoundException {
return mResources.getLayout(id);
}
@Override
public XmlResourceParser getAnimation(int id) throws NotFoundException {
return mResources.getAnimation(id);
}
@Override
public XmlResourceParser getXml(int id) throws NotFoundException {
return mResources.getXml(id);
}
@Override
public InputStream openRawResource(int id) throws NotFoundException {
return mResources.openRawResource(id);
}
@Override
public AssetFileDescriptor openRawResourceFd(int id) throws NotFoundException {
return mResources.openRawResourceFd(id);
}
@Override
public void getValue(int id, TypedValue outValue, boolean resolveRefs)
throws NotFoundException {
mResources.getValue(id, outValue, resolveRefs);
}
@Override
public void getValue(String name, TypedValue outValue, boolean resolveRefs)
throws NotFoundException {
mResources.getValue(name, outValue, resolveRefs);
}
@Override
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
return mResources.obtainAttributes(set, attrs);
}
@Override
public DisplayMetrics getDisplayMetrics() {
return mResources.getDisplayMetrics();
}
@Override
public Configuration getConfiguration() {
return mResources.getConfiguration();
}
@Override
public int getIdentifier(String name, String defType, String defPackage) {
return mResources.getIdentifier(name, defType, defPackage);
}
@Override
public String getResourceName(int resid) throws NotFoundException {
return mResources.getResourceName(resid);
}
@Override
public String getResourcePackageName(int resid) throws NotFoundException {
return mResources.getResourcePackageName(resid);
}
@Override
public String getResourceTypeName(int resid) throws NotFoundException {
return mResources.getResourceTypeName(resid);
}
@Override
public String getResourceEntryName(int resid) throws NotFoundException {
return mResources.getResourceEntryName(resid);
}
}