當前位置: 首頁>>代碼示例>>Java>>正文


Java Resources.getResourceTypeName方法代碼示例

本文整理匯總了Java中android.content.res.Resources.getResourceTypeName方法的典型用法代碼示例。如果您正苦於以下問題:Java Resources.getResourceTypeName方法的具體用法?Java Resources.getResourceTypeName怎麽用?Java Resources.getResourceTypeName使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在android.content.res.Resources的用法示例。


在下文中一共展示了Resources.getResourceTypeName方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getViewSign

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 獲取View的簽名
 *
 * @param view
 * @return
 */
public static String getViewSign(View view) {
    StringBuilder sign = new StringBuilder(128);
    sign.append(view.getClass().getName());
    sign.append('{');
    sign.append(Integer.toHexString(System.identityHashCode(view)));
    sign.append(' ');
    sign.append(view.getLeft());
    sign.append(',');
    sign.append(view.getTop());
    sign.append('-');
    sign.append(view.getRight());
    sign.append(',');
    sign.append(view.getBottom());
    final int id = view.getId();
    if (id != View.NO_ID) {
        sign.append(" #");
        sign.append(Integer.toHexString(id));
        final Resources r = view.getResources();
        if (id > 0 && resourceHasPackage(id) && r != null) {
            try {
                String pkgname;
                switch (id & 0xff000000) {
                    case 0x7f000000:
                        pkgname = "app";
                        break;
                    case 0x01000000:
                        pkgname = "android";
                        break;
                    default:
                        pkgname = r.getResourcePackageName(id);
                        break;
                }
                String typename = r.getResourceTypeName(id);
                String entryname = r.getResourceEntryName(id);
                sign.append(" ");
                sign.append(pkgname);
                sign.append(":");
                sign.append(typename);
                sign.append("/");
                sign.append(entryname);
                if ("android".equals(pkgname) && "id".equals(typename) && "content".equals(entryname)) {
                    //找到android:id/content的父View,認為是根View了,不再查找
                    isRootParent = true;
                }
            } catch (Resources.NotFoundException e) {
            }
        }
    }
    sign.append('}');
    return sign.toString();
}
 
開發者ID:zkwlx,項目名稱:DroidTelescope,代碼行數:58,代碼來源:ViewUtils.java

示例2: generateResourceNameFromId

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * Generates a Resource name from resourceId located in res/ folder.
 *
 * @param resourceId id of the resource, must be greater then 0.
 * @return resourceName in format folder/file.extension.
 */
public static String generateResourceNameFromId(int resourceId) {
  try {
    if (resourceId <= 0) {
      Log.w("Provided resource id is invalid.");
      return null;
    }
    Resources resources = Leanplum.getContext().getResources();
    // Get entryName from resourceId, which represents a file name in res/ directory.
    String entryName = resources.getResourceEntryName(resourceId);
    // Get typeName from resourceId, which represents a folder where file is located in
    // res/ directory.
    String typeName = resources.getResourceTypeName(resourceId);

    // By using TypedValue we can get full path of a file with extension.
    TypedValue value = new TypedValue();
    resources.getValue(resourceId, value, true);

    // Regex matching to find real file extension, "image.img.png" will produce "png".
    String[] fullFileName = value.string.toString().split("\\.(?=[^\\.]+$)");
    String extension = "";
    // If extension is found, we will append dot before it.
    if (fullFileName.length == 2) {
      extension = "." + fullFileName[1];
    }

    // Return full resource name in format: drawable/image.png
    return typeName + "/" + entryName + extension;
  } catch (Exception e) {
    Log.w("Failed to generate resource name from provided resource id: ", e);
    Util.handleException(e);
  }
  return null;
}
 
開發者ID:Leanplum,項目名稱:Leanplum-Android-SDK,代碼行數:40,代碼來源:Util.java

示例3: getUriFromDrawableRes

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * 得到資源文件中圖片的Uri
 * @param context 上下文對象
 * @param id 資源id
 * @return Uri
 */
public static Uri getUriFromDrawableRes(Context context, int id) {
	Resources resources = context.getResources();
	String path = ContentResolver.SCHEME_ANDROID_RESOURCE + "://"
			+ resources.getResourcePackageName(id) + "/"
			+ resources.getResourceTypeName(id) + "/"
			+ resources.getResourceEntryName(id);
	return Uri.parse(path);
}
 
開發者ID:ebridfighter,項目名稱:GongXianSheng,代碼行數:15,代碼來源:CommonUtils.java

示例4: activityTheme

import android.content.res.Resources; //導入方法依賴的package包/類
@Override
public Config activityTheme(@StyleRes int theme) {
    final Resources r = mContext.getResources();
    final String name = r.getResourceName(theme);
    final String defType = r.getResourceTypeName(theme);
    mEditor.putString(KEY_ACTIVITY_THEME, name);
    mEditor.putString(KEY_ACTIVITY_THEME_DEFTYPE, defType);
    return this;
}
 
開發者ID:RajneeshSingh007,項目名稱:MusicX-music-player,代碼行數:10,代碼來源:Config.java

示例5: getResourceEntry

import android.content.res.Resources; //導入方法依賴的package包/類
/**
 * Find an entry of resource in the overlay package provided by partners. It will first look for
 * the resource in the overlay package, and if not available, will return the one in the
 * original context.
 *
 * @return a ResourceEntry in the partner overlay's resources, if one is defined. Otherwise the
 * resources from the original context is returned. Clients can then get the resource by
 * {@code entry.resources.getString(entry.id)}, or other methods available in
 * {@link android.content.res.Resources}.
 */
public static ResourceEntry getResourceEntry(Context context, int id) {
    final Partner partner = Partner.get(context);
    if (partner != null) {
        final Resources ourResources = context.getResources();
        final String name = ourResources.getResourceEntryName(id);
        final String type = ourResources.getResourceTypeName(id);
        final int partnerId = partner.getIdentifier(name, type);
        if (partnerId != 0) {
            return new ResourceEntry(partner.mResources, partnerId, true);
        }
    }
    return new ResourceEntry(context.getResources(), id, false);
}
 
開發者ID:Trumeet,項目名稱:SetupWizardLibCompat,代碼行數:24,代碼來源:Partner.java

示例6: getPluginResourceId

import android.content.res.Resources; //導入方法依賴的package包/類
public static int getPluginResourceId(Context context, String apkPath, int oldResourceId) {

        Resources resources = context.getResources();
        String colorName = resources.getResourceName(oldResourceId);
        String entryName = resources.getResourceEntryName(oldResourceId);
        String typeName = resources.getResourceTypeName(oldResourceId);

        Log.e("MyLog", colorName + "," + entryName + "," + typeName);

        Resources pluginResources = resourcesMap.get(apkPath);
        if (pluginResources == null) {

            pluginResources = RecourcesUtil.getResources(context, apkPath);

            resourcesMap.put(apkPath, pluginResources);

        }

        String packageName = SPluginUtil.getPackageInfo(context, apkPath).packageName;
        int colorId = pluginResources.getIdentifier(entryName, typeName, packageName);
        Log.e("MyLog", colorId + "");


        return colorId;

    }
 
開發者ID:XaskYSab,項目名稱:CSkin,代碼行數:27,代碼來源:RecourcesUtil.java


注:本文中的android.content.res.Resources.getResourceTypeName方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。