Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Context;

import android.text.TextUtils;

import java.lang.reflect.Method;

public class Main {
    private static Object rp;

    public static int getStyleRes(Context context, String resName) {
        return getResId(context, "style", resName);
    }

    public static int getResId(Context context, String resType, String resName) {
        int resId = 0;
        if (context != null && !TextUtils.isEmpty(resType) && !TextUtils.isEmpty(resName)) {
            if (rp != null) {
                try {
                    Method pck = rp.getClass().getMethod("getResId", Context.class, String.class, String.class);
                    pck.setAccessible(true);
                    resId = ((Integer) pck.invoke(rp, context, resType, resName)).intValue();
                } catch (Throwable var5) {

                }
            }

            if (resId <= 0) {
                String pck1 = context.getPackageName();
                if (TextUtils.isEmpty(pck1)) {
                    return resId;
                }

                if (resId <= 0) {
                    resId = context.getResources().getIdentifier(resName, resType, pck1);
                    if (resId <= 0) {
                        resId = context.getResources().getIdentifier(resName.toLowerCase(), resType, pck1);
                    }
                }

                if (resId <= 0) {
                    System.err.println("failed to parse " + resType + " resource \"" + resName + "\"");
                }
            }

            return resId;
        } else {
            return resId;
        }
    }
}