The helper for slice of carrier and non-Carrier, used by ProviderModelSlice.
create a helper file. create a res/drawable/ic_signal_strength_zero_bar_no_internet.xml create string at res/values/strings.xml Bug: 173971144 Test: atest ProviderModelSliceHelperTest Change-Id: I7f63a6b04784325989e776cb140017314ebde4ce
This commit is contained in:
@@ -17,15 +17,43 @@ package com.android.settings.testutils;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
/**
|
||||
* Test util to provide the correct resources.
|
||||
*/
|
||||
public final class ResourcesUtils {
|
||||
/**
|
||||
* Return a resource identifier for the given resource name.
|
||||
* @param context Context to use.
|
||||
* @param type Optional default resource type to find, if "type/" is not included in the name.
|
||||
* Can be null to require an explicit type.
|
||||
* @param name The name of the desired resource.
|
||||
* @return The associated resource identifier. Returns 0 if no such resource was found.
|
||||
* (0 is not a valid resource ID.)
|
||||
*/
|
||||
public static int getResourcesId(Context context, String type, String name) {
|
||||
return context.getResources().getIdentifier(name, type, context.getPackageName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a localized string from the application's package's default string table.
|
||||
* @param context Context to use.
|
||||
* @param name The name of the desired resource.
|
||||
* @return The string data associated with the resource, stripped of styled text information.
|
||||
*/
|
||||
public static String getResourcesString(Context context, String name) {
|
||||
return context.getResources().getString(getResourcesId(context, "string", name));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the string value associated with a particular neame of resource,
|
||||
* substituting the format arguments as defined in {@link java.util.Formatter}
|
||||
* and {@link java.lang.String#format}. It will be stripped of any styled text
|
||||
* information.
|
||||
* @param context Context to use.
|
||||
* @param name The name of the desired resource.
|
||||
* @param value The format arguments that will be used for substitution.
|
||||
* @return The string data associated with the resource, stripped of styled text information.
|
||||
*/
|
||||
public static String getResourcesString(Context context, String name, Object... value) {
|
||||
return context.getResources().getString(getResourcesId(context, "string", name), value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user