public class ResourceManager
extends java.lang.Object
init(Context)
before using it and
cleanup()
.
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ResourceManager.getInstance().init(this);
// Load the theme outside, if use the resource in APK, please comment the method following.
ResourceManager.getInstance().switchToResources(
Environment.getExternalStorageDirectory().getPath()
+ "/mapbar/example/obd/skin1.bin");
// All the layout resources should use the method following.
setContentView(ResourceManager.getInstance().inflate(this,
R.layout.activity_main, null));
// Initialize UI
mMainIconImageView = (ImageView) findViewById(R.id.iv_main_icon);
mStateTextView = (TextView) findViewById(R.id.tv_state);
mDeviceInfoTextView = (TextView) findViewById(R.id.tv_device);
mItemInfoListView = (ListView) findViewById(R.id.lv_item_info);
// Initialize Animations
mAnimation = ResourceManager.getInstance().loadAnimation(this, R.anim.from_buttom_fade_in);
mAnimation.setAnimationListener(this.animListener);
mMainIconImageView.setAnimation(mAnimation);
}
protected void onDestroy() {
// Cleanup ResourceManager
ResourceManager.getInstance().cleanup();
}
Limitation:限定符和类型 | 方法和说明 |
---|---|
static void |
cleanup()
释放占用的资源
|
static boolean |
dialogApplyTheme(android.app.Dialog dialog,
android.content.res.Resources.Theme newTheme)
设置给定对话框的主题
|
static int |
getColor(int resourceId)
The same as
android.content.res.Resources#getColor() |
static android.graphics.drawable.Drawable |
getDrawable(int resourceId)
The same as
android.content.res.Resources#getDrawable() |
static int |
getInnerRIdValue(java.lang.String r)
利用指代给定资源的字符串得到该资源被Android系统编译后的整数id
|
static android.content.res.Resources |
getResources()
The same as
Context.getResources() |
static java.lang.String |
getString(int resourceId)
The same as
android.content.res.Resources#getString() |
static android.view.View |
inflate(android.app.Activity activity,
int resource,
android.view.ViewGroup root)
Inflate a new view hierarchy from the specified xml resource.
|
static android.view.View |
inflate(android.content.Context context,
int resource,
android.view.ViewGroup root)
Inflate a new view hierarchy from the specified xml resource.
|
static void |
init(android.content.Context context)
初始化
|
static boolean |
isUsingDefault()
Use default resources or not.
|
static android.view.animation.Animation |
loadAnimation(android.content.Context context,
int id)
Loads an Animation object from a resource
|
static android.view.animation.Interpolator |
loadInterpolator(android.content.Context context,
int id)
Loads an Interpolator object from a resource
|
static android.view.animation.LayoutAnimationController |
loadLayoutAnimation(android.content.Context context,
int id)
Loads an LayoutAnimationController object from a resource
|
static boolean |
restoreDefaultResources(android.app.Activity activity)
Restore the default resources.
|
static boolean |
restoreDefaultResources(android.content.Context context)
Restore the default resources.
|
static void |
setViewBackgroud(android.view.View view,
int resourceId) |
static boolean |
switchToCustomResources(android.app.Activity activity)
Switch to the custom resources, must be paired invoked with
restoreDefaultResources(Activity) . |
static boolean |
switchToCustomResources(android.content.Context context)
Switch to the custom resources, must be paired invoked with
restoreDefaultResources(Context) . |
static boolean |
switchToResources(java.lang.String path)
Switch the source of resources
|
public static void init(android.content.Context context)
context
- 应用程序上下文public static void cleanup()
public static boolean switchToResources(java.lang.String path)
path
- The path of the resource JAR for custom resources or "default"
for default resourcespublic static boolean switchToCustomResources(android.app.Activity activity)
restoreDefaultResources(Activity)
.activity
- activity need to be setpublic static boolean restoreDefaultResources(android.app.Activity activity)
activity
- activity need to be restoredpublic static boolean switchToCustomResources(android.content.Context context)
restoreDefaultResources(Context)
.context
- context need to be setpublic static boolean restoreDefaultResources(android.content.Context context)
context
- context need to be restoredpublic static android.content.res.Resources getResources()
Context.getResources()
Resources
public static android.graphics.drawable.Drawable getDrawable(int resourceId)
android.content.res.Resources#getDrawable()
Drawable
public static java.lang.String getString(int resourceId)
android.content.res.Resources#getString()
String
public static int getColor(int resourceId)
android.content.res.Resources#getColor()
Color
public static void setViewBackgroud(android.view.View view, int resourceId)
public static android.view.View inflate(android.app.Activity activity, int resource, android.view.ViewGroup root)
activity
- Activity used for inflate a new viewresource
- resource ID for an XML layout resource to load (e.g.,
R.layout.main_page)root
- Optional view to be the parent of the generated hierarchy.public static android.view.View inflate(android.content.Context context, int resource, android.view.ViewGroup root)
context
- Context used for inflate a new viewresource
- resource ID for an XML layout resource to load (e.g.,
R.layout.main_page)root
- Optional view to be the parent of the generated hierarchy.public static android.view.animation.Animation loadAnimation(android.content.Context context, int id) throws android.content.res.Resources.NotFoundException
context
- Application context used to access resourcesid
- The resource id of the animation to loadResources.NotFoundException
public static android.view.animation.LayoutAnimationController loadLayoutAnimation(android.content.Context context, int id) throws android.content.res.Resources.NotFoundException
context
- Application context used to access resourcesid
- The resource id of the animation to loadResources.NotFoundException
public static android.view.animation.Interpolator loadInterpolator(android.content.Context context, int id) throws android.content.res.Resources.NotFoundException
context
- Application context used to access resourcesid
- The resource id of the animation to loadResources.NotFoundException
public static boolean isUsingDefault()
public static int getInnerRIdValue(java.lang.String r)
r
- 指代给定资源的字符串public static boolean dialogApplyTheme(android.app.Dialog dialog, android.content.res.Resources.Theme newTheme)
dialog
- 待更改的对话框newTheme
- 待使用的主题©Mapbar Engine Team;All Rights Reserved