|
@@ -0,0 +1,132 @@
|
|
|
+package com.xugame.gameconsole.util;
|
|
|
+
|
|
|
+import android.content.Context;
|
|
|
+import android.graphics.drawable.Drawable;
|
|
|
+import android.graphics.drawable.StateListDrawable;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by Frank on 2016/11/23.
|
|
|
+ */
|
|
|
+
|
|
|
+public class ResUtil {
|
|
|
+ public static final String sPackageName = null;
|
|
|
+
|
|
|
+ public static int getStringID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "string", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "string", sPackageName);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getStringGameID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "string", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "string", sPackageName);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getDrawableID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "drawable", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "drawable", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getColorID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "color", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "color", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getLayoutID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "layout", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "layout", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getAnimID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "anim", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "anim", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "id", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "id", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getXmlID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "xml", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "xml", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getDimID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "dimen", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "dimen", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getStyleID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "style", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "style", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getArrayID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "array", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "array", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static int getRawID(Context context, String name) {
|
|
|
+ if (sPackageName == null)
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "raw", context.getPackageName());
|
|
|
+ else
|
|
|
+ return context.getResources().
|
|
|
+ getIdentifier(name, "raw", sPackageName);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static StateListDrawable createSelector(Drawable normal, Drawable focused) {
|
|
|
+ StateListDrawable stateList = new StateListDrawable();
|
|
|
+ int stateFocused = android.R.attr.state_focused;
|
|
|
+
|
|
|
+ stateList.addState(new int[]{-stateFocused}, normal);
|
|
|
+ stateList.addState(new int[]{stateFocused}, focused);
|
|
|
+ return stateList;
|
|
|
+ }
|
|
|
+}
|