package org.cnodejs.android.md.util; import android.content.Context; import android.content.res.TypedArray; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.RawRes; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; public final class ResUtils { private ResUtils() {} public static int getStatusBarHeight(@NonNull Context context) { int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android"); return resourceId > 0 ? context.getResources().getDimensionPixelSize(resourceId) : 0; } @ColorInt public static int getThemeAttrColor(@NonNull Context context, @AttrRes int attr) { TypedArray a = context.obtainStyledAttributes(null, new int[]{attr}); try { return a.getColor(0, 0); } finally { a.recycle(); } } public static String getRawString(@NonNull Context context, @RawRes int rawId) throws IOException { InputStream is = context.getResources().openRawResource(rawId); BufferedReader reader = new BufferedReader(new InputStreamReader(is, "UTF-8")); StringBuilder sb = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { sb.append(line).append("\n"); } sb.deleteCharAt(sb.length() - 1); reader.close(); return sb.toString(); } }