андроид getText (int resId) реализация - PullRequest
1 голос
/ 13 марта 2012

Мне нужно увидеть реализацию метода getText(int resId).Этот метод определен как final в абстрактном классе Context.java, и я искал реализацию в ContextWrapper.java и ContextThemeWrapper.java, но я не смог найти какую-либо реализацию.Может кто-нибудь опубликовать ссылку на реализацию этого метода?Я посмотрел на netmite.com для реализации классов.Спасибо

Ответы [ 2 ]

3 голосов
/ 13 марта 2012

Это реализация getText() в Context.java. Класс абстрактный, но у него есть реализация этого метода.

public final CharSequence getText(int resId) {
    return getResources().getText(resId);
}

Реализация Resources.getText():

public CharSequence getText(int id) throws NotFoundException {
    CharSequence res = mAssets.getResourceText(id);
    if (res != null) {
        return res;
    }
    throw new NotFoundException("String resource ID #0x"
                                + Integer.toHexString(id));
}

Реализация AssetManager.getResourceText():

final CharSequence getResourceText(int ident) {
    synchronized (this) {
        TypedValue tmpValue = mValue;
        int block = loadResourceValue(ident, (short) 0, tmpValue, true);
        if (block >= 0) {
            if (tmpValue.type == TypedValue.TYPE_STRING) {
                return mStringBlocks[block].get(tmpValue.data);
            }
            return tmpValue.coerceToString();
        }
    }
    return null;
}

Upd: Как упоминается @zapl loadResourceValue() является нативным и может быть найдено в android_util_AssetManager.cpp.

0 голосов
/ 13 марта 2012

ICS - фреймворки / base / core / java / android / content / res / AssetManager.java

/**
 * Retrieve the string value associated with a particular resource
 * identifier for the current configuration / skin.
 */
/*package*/ final CharSequence getResourceText(int ident) {
    synchronized (this) {
        TypedValue tmpValue = mValue;
        int block = loadResourceValue(ident, (short) 0, tmpValue, true);
        if (block >= 0) {
            if (tmpValue.type == TypedValue.TYPE_STRING) {
                return mStringBlocks[block].get(tmpValue.data);
            }
            return tmpValue.coerceToString();
        }
    }
    return null;
}

loadResourceValue() является нативным и определено в frameworks / base / core / jni / android_util_AssetManager.cpp

...