Search in sources :

Example 96 with XmlResourceParser

use of android.content.res.XmlResourceParser in project android_frameworks_base by AOSPA.

the class TtsEngines method settingsActivityFromServiceInfo.

private String settingsActivityFromServiceInfo(ServiceInfo si, PackageManager pm) {
    XmlResourceParser parser = null;
    try {
        parser = si.loadXmlMetaData(pm, TextToSpeech.Engine.SERVICE_META_DATA);
        if (parser == null) {
            Log.w(TAG, "No meta-data found for :" + si);
            return null;
        }
        final Resources res = pm.getResourcesForApplication(si.applicationInfo);
        int type;
        while ((type = parser.next()) != XmlResourceParser.END_DOCUMENT) {
            if (type == XmlResourceParser.START_TAG) {
                if (!XML_TAG_NAME.equals(parser.getName())) {
                    Log.w(TAG, "Package " + si + " uses unknown tag :" + parser.getName());
                    return null;
                }
                final AttributeSet attrs = Xml.asAttributeSet(parser);
                final TypedArray array = res.obtainAttributes(attrs, com.android.internal.R.styleable.TextToSpeechEngine);
                final String settings = array.getString(com.android.internal.R.styleable.TextToSpeechEngine_settingsActivity);
                array.recycle();
                return settings;
            }
        }
        return null;
    } catch (NameNotFoundException e) {
        Log.w(TAG, "Could not load resources for : " + si);
        return null;
    } catch (XmlPullParserException e) {
        Log.w(TAG, "Error parsing metadata for " + si + ":" + e);
        return null;
    } catch (IOException e) {
        Log.w(TAG, "Error parsing metadata for " + si + ":" + e);
        return null;
    } finally {
        if (parser != null) {
            parser.close();
        }
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) Secure.getString(android.provider.Settings.Secure.getString) IOException(java.io.IOException)

Example 97 with XmlResourceParser

use of android.content.res.XmlResourceParser in project android_frameworks_base by AOSPA.

the class AutoText method init.

private void init(Resources r) {
    XmlResourceParser parser = r.getXml(com.android.internal.R.xml.autotext);
    StringBuilder right = new StringBuilder(RIGHT);
    mTrie = new char[DEFAULT];
    mTrie[TRIE_ROOT] = TRIE_NULL;
    mTrieUsed = TRIE_ROOT + 1;
    try {
        XmlUtils.beginDocument(parser, "words");
        String odest = "";
        char ooff = 0;
        while (true) {
            XmlUtils.nextElement(parser);
            String element = parser.getName();
            if (element == null || !(element.equals("word"))) {
                break;
            }
            String src = parser.getAttributeValue(null, "src");
            if (parser.next() == XmlPullParser.TEXT) {
                String dest = parser.getText();
                char off;
                if (dest.equals(odest)) {
                    off = ooff;
                } else {
                    off = (char) right.length();
                    right.append((char) dest.length());
                    right.append(dest);
                }
                add(src, off);
            }
        }
        // Don't let Resources cache a copy of all these strings.
        r.flushLayoutCache();
    } catch (XmlPullParserException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new RuntimeException(e);
    } finally {
        parser.close();
    }
    mText = right.toString();
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 98 with XmlResourceParser

use of android.content.res.XmlResourceParser in project android_frameworks_base by AOSPA.

the class ZoneGetter method readTimezonesToDisplay.

private static List<String> readTimezonesToDisplay(Context context) {
    List<String> olsonIds = new ArrayList<String>();
    try (XmlResourceParser xrp = context.getResources().getXml(R.xml.timezones)) {
        while (xrp.next() != XmlResourceParser.START_TAG) {
            continue;
        }
        xrp.next();
        while (xrp.getEventType() != XmlResourceParser.END_TAG) {
            while (xrp.getEventType() != XmlResourceParser.START_TAG) {
                if (xrp.getEventType() == XmlResourceParser.END_DOCUMENT) {
                    return olsonIds;
                }
                xrp.next();
            }
            if (xrp.getName().equals(XMLTAG_TIMEZONE)) {
                String olsonId = xrp.getAttributeValue(0);
                olsonIds.add(olsonId);
            }
            while (xrp.getEventType() != XmlResourceParser.END_TAG) {
                xrp.next();
            }
            xrp.next();
        }
    } catch (XmlPullParserException xppe) {
        Log.e(TAG, "Ill-formatted timezones.xml file");
    } catch (java.io.IOException ioe) {
        Log.e(TAG, "Unable to read timezones.xml file");
    }
    return olsonIds;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) ArrayList(java.util.ArrayList) XmlPullParserException(org.xmlpull.v1.XmlPullParserException)

Example 99 with XmlResourceParser

use of android.content.res.XmlResourceParser in project android_frameworks_base by AOSPA.

the class PrintServiceInfo method create.

/**
     * Creates a new instance.
     *
     * @param resolveInfo The service resolve info.
     * @param context Context for accessing resources.
     * @return The created instance.
     */
public static PrintServiceInfo create(ResolveInfo resolveInfo, Context context) {
    String settingsActivityName = null;
    String addPrintersActivityName = null;
    String advancedPrintOptionsActivityName = null;
    XmlResourceParser parser = null;
    PackageManager packageManager = context.getPackageManager();
    parser = resolveInfo.serviceInfo.loadXmlMetaData(packageManager, PrintService.SERVICE_META_DATA);
    if (parser != null) {
        try {
            int type = 0;
            while (type != XmlPullParser.END_DOCUMENT && type != XmlPullParser.START_TAG) {
                type = parser.next();
            }
            String nodeName = parser.getName();
            if (!TAG_PRINT_SERVICE.equals(nodeName)) {
                Log.e(LOG_TAG, "Ignoring meta-data that does not start with " + TAG_PRINT_SERVICE + " tag");
            } else {
                Resources resources = packageManager.getResourcesForApplication(resolveInfo.serviceInfo.applicationInfo);
                AttributeSet allAttributes = Xml.asAttributeSet(parser);
                TypedArray attributes = resources.obtainAttributes(allAttributes, com.android.internal.R.styleable.PrintService);
                settingsActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_settingsActivity);
                addPrintersActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_addPrintersActivity);
                advancedPrintOptionsActivityName = attributes.getString(com.android.internal.R.styleable.PrintService_advancedPrintOptionsActivity);
                attributes.recycle();
            }
        } catch (IOException ioe) {
            Log.w(LOG_TAG, "Error reading meta-data:" + ioe);
        } catch (XmlPullParserException xppe) {
            Log.w(LOG_TAG, "Error reading meta-data:" + xppe);
        } catch (NameNotFoundException e) {
            Log.e(LOG_TAG, "Unable to load resources for: " + resolveInfo.serviceInfo.packageName);
        } finally {
            if (parser != null) {
                parser.close();
            }
        }
    }
    return new PrintServiceInfo(resolveInfo, settingsActivityName, addPrintersActivityName, advancedPrintOptionsActivityName);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) PackageManager(android.content.pm.PackageManager) AttributeSet(android.util.AttributeSet) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) TypedArray(android.content.res.TypedArray) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Example 100 with XmlResourceParser

use of android.content.res.XmlResourceParser in project android_frameworks_base by AOSPA.

the class AnimatorInflater method loadAnimator.

/** @hide */
public static Animator loadAnimator(Resources resources, Theme theme, int id, float pathErrorScale) throws NotFoundException {
    final ConfigurationBoundResourceCache<Animator> animatorCache = resources.getAnimatorCache();
    Animator animator = animatorCache.getInstance(id, resources, theme);
    if (animator != null) {
        if (DBG_ANIMATOR_INFLATER) {
            Log.d(TAG, "loaded animator from cache, " + resources.getResourceName(id));
        }
        return animator;
    } else if (DBG_ANIMATOR_INFLATER) {
        Log.d(TAG, "cache miss for animator " + resources.getResourceName(id));
    }
    XmlResourceParser parser = null;
    try {
        parser = resources.getAnimation(id);
        animator = createAnimatorFromXml(resources, theme, parser, pathErrorScale);
        if (animator != null) {
            animator.appendChangingConfigurations(getChangingConfigs(resources, id));
            final ConstantState<Animator> constantState = animator.createConstantState();
            if (constantState != null) {
                if (DBG_ANIMATOR_INFLATER) {
                    Log.d(TAG, "caching animator for res " + resources.getResourceName(id));
                }
                animatorCache.put(id, theme, constantState);
                // create a new animator so that cached version is never used by the user
                animator = constantState.newInstance(resources, theme);
            }
        }
        return animator;
    } catch (XmlPullParserException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } catch (IOException ex) {
        Resources.NotFoundException rnf = new Resources.NotFoundException("Can't load animation resource ID #0x" + Integer.toHexString(id));
        rnf.initCause(ex);
        throw rnf;
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : NotFoundException(android.content.res.Resources.NotFoundException) XmlResourceParser(android.content.res.XmlResourceParser) NotFoundException(android.content.res.Resources.NotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) Resources(android.content.res.Resources) IOException(java.io.IOException)

Aggregations

XmlResourceParser (android.content.res.XmlResourceParser)331 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)210 IOException (java.io.IOException)202 Resources (android.content.res.Resources)114 AttributeSet (android.util.AttributeSet)113 TypedArray (android.content.res.TypedArray)80 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)64 PackageManager (android.content.pm.PackageManager)45 ActivityInfo (android.content.pm.ActivityInfo)43 Bundle (android.os.Bundle)42 ComponentName (android.content.ComponentName)41 ArrayList (java.util.ArrayList)30 TypedValue (android.util.TypedValue)29 AssetManager (android.content.res.AssetManager)28 RemoteException (android.os.RemoteException)28 Intent (android.content.Intent)22 ApplicationInfo (android.content.pm.ApplicationInfo)18 InflateException (android.view.InflateException)18 FileNotFoundException (java.io.FileNotFoundException)18 NotFoundException (android.content.res.Resources.NotFoundException)17