Search in sources :

Example 21 with XmlResourceParser

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

the class UsbSettingsManager method handlePackageUpdateLocked.

private boolean handlePackageUpdateLocked(String packageName, ActivityInfo aInfo, String metaDataName) {
    XmlResourceParser parser = null;
    boolean changed = false;
    try {
        parser = aInfo.loadXmlMetaData(mPackageManager, metaDataName);
        if (parser == null)
            return false;
        XmlUtils.nextElement(parser);
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            String tagName = parser.getName();
            if ("usb-device".equals(tagName)) {
                DeviceFilter filter = DeviceFilter.read(parser);
                if (clearCompatibleMatchesLocked(packageName, filter)) {
                    changed = true;
                }
            } else if ("usb-accessory".equals(tagName)) {
                AccessoryFilter filter = AccessoryFilter.read(parser);
                if (clearCompatibleMatchesLocked(packageName, filter)) {
                    changed = true;
                }
            }
            XmlUtils.nextElement(parser);
        }
    } catch (Exception e) {
        Slog.w(TAG, "Unable to load component info " + aInfo.toString(), e);
    } finally {
        if (parser != null)
            parser.close();
    }
    return changed;
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 22 with XmlResourceParser

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

the class UsbSettingsManager method packageMatchesLocked.

// Checks to see if a package matches a device or accessory.
// Only one of device and accessory should be non-null.
private boolean packageMatchesLocked(ResolveInfo info, String metaDataName, UsbDevice device, UsbAccessory accessory) {
    ActivityInfo ai = info.activityInfo;
    XmlResourceParser parser = null;
    try {
        parser = ai.loadXmlMetaData(mPackageManager, metaDataName);
        if (parser == null) {
            Slog.w(TAG, "no meta-data for " + info);
            return false;
        }
        XmlUtils.nextElement(parser);
        while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
            String tagName = parser.getName();
            if (device != null && "usb-device".equals(tagName)) {
                DeviceFilter filter = DeviceFilter.read(parser);
                if (filter.matches(device)) {
                    return true;
                }
            } else if (accessory != null && "usb-accessory".equals(tagName)) {
                AccessoryFilter filter = AccessoryFilter.read(parser);
                if (filter.matches(accessory)) {
                    return true;
                }
            }
            XmlUtils.nextElement(parser);
        }
    } catch (Exception e) {
        Slog.w(TAG, "Unable to load component info " + info.toString(), e);
    } finally {
        if (parser != null)
            parser.close();
    }
    return false;
}
Also used : ActivityInfo(android.content.pm.ActivityInfo) XmlResourceParser(android.content.res.XmlResourceParser) NameNotFoundException(android.content.pm.PackageManager.NameNotFoundException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) ActivityNotFoundException(android.content.ActivityNotFoundException)

Example 23 with XmlResourceParser

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

the class SimpleInflater method inflate.

public void inflate(int menuRes) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException e) {
        throw new InflateException("Error inflating menu XML", e);
    } catch (IOException e) {
        throw new InflateException("Error inflating menu XML", e);
    } finally {
        if (parser != null)
            parser.close();
    }
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) InflateException(android.view.InflateException) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 24 with XmlResourceParser

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

the class LayoutInflater_Delegate method parseInclude.

@LayoutlibDelegate
public static void parseInclude(LayoutInflater thisInflater, XmlPullParser parser, Context context, View parent, AttributeSet attrs) throws XmlPullParserException, IOException {
    int type;
    if (parent instanceof ViewGroup) {
        // Apply a theme wrapper, if requested. This is sort of a weird
        // edge case, since developers think the <include> overwrites
        // values in the AttributeSet of the included View. So, if the
        // included View has a theme attribute, we'll need to ignore it.
        final TypedArray ta = context.obtainStyledAttributes(attrs, ATTRS_THEME);
        final int themeResId = ta.getResourceId(0, 0);
        final boolean hasThemeOverride = themeResId != 0;
        if (hasThemeOverride) {
            context = new ContextThemeWrapper(context, themeResId);
        }
        ta.recycle();
        // If the layout is pointing to a theme attribute, we have to
        // massage the value to get a resource identifier out of it.
        int layout = attrs.getAttributeResourceValue(null, ATTR_LAYOUT, 0);
        if (layout == 0) {
            final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
            if (value == null || value.length() <= 0) {
                throw new InflateException("You must specify a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
            }
            // Attempt to resolve the "?attr/name" string to an identifier.
            layout = context.getResources().getIdentifier(value.substring(1), null, null);
        }
        // ---- START CHANGES
        if (layout != 0) {
            final TypedValue tempValue = new TypedValue();
            if (context.getTheme().resolveAttribute(layout, tempValue, true)) {
                layout = tempValue.resourceId;
            }
        }
        if (layout == 0) {
            final String value = attrs.getAttributeValue(null, ATTR_LAYOUT);
            if (value == null) {
                throw new InflateException("You must specifiy a layout in the" + " include tag: <include layout=\"@layout/layoutID\" />");
            } else {
                throw new InflateException("You must specifiy a valid layout " + "reference. The layout ID " + value + " is not valid.");
            }
        } else {
            final XmlResourceParser childParser = thisInflater.getContext().getResources().getLayout(layout);
            try {
                final AttributeSet childAttrs = Xml.asAttributeSet(childParser);
                while ((type = childParser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) {
                // Empty.
                }
                if (type != XmlPullParser.START_TAG) {
                    throw new InflateException(childParser.getPositionDescription() + ": No start tag found!");
                }
                final String childName = childParser.getName();
                if (TAG_MERGE.equals(childName)) {
                    // Inflate all children.
                    thisInflater.rInflate(childParser, parent, context, childAttrs, false);
                } else {
                    final View view = thisInflater.createViewFromTag(parent, childName, context, childAttrs, hasThemeOverride);
                    final ViewGroup group = (ViewGroup) parent;
                    final TypedArray a = context.obtainStyledAttributes(attrs, com.android.internal.R.styleable.Include);
                    final int id = a.getResourceId(com.android.internal.R.styleable.Include_id, View.NO_ID);
                    final int visibility = a.getInt(com.android.internal.R.styleable.Include_visibility, -1);
                    a.recycle();
                    // We try to load the layout params set in the <include /> tag. If
                    // they don't exist, we will rely on the layout params set in the
                    // included XML file.
                    // During a layoutparams generation, a runtime exception is thrown
                    // if either layout_width or layout_height is missing. We catch
                    // this exception and set localParams accordingly: true means we
                    // successfully loaded layout params from the <include /> tag,
                    // false means we need to rely on the included layout params.
                    ViewGroup.LayoutParams params = null;
                    try {
                        // ---- START CHANGES
                        sIsInInclude = true;
                        // ---- END CHANGES
                        params = group.generateLayoutParams(attrs);
                    } catch (RuntimeException ignored) {
                    // Ignore, just fail over to child attrs.
                    } finally {
                        // ---- START CHANGES
                        sIsInInclude = false;
                    // ---- END CHANGES
                    }
                    if (params == null) {
                        params = group.generateLayoutParams(childAttrs);
                    }
                    view.setLayoutParams(params);
                    // Inflate all children.
                    thisInflater.rInflateChildren(childParser, view, childAttrs, true);
                    if (id != View.NO_ID) {
                        view.setId(id);
                    }
                    switch(visibility) {
                        case 0:
                            view.setVisibility(View.VISIBLE);
                            break;
                        case 1:
                            view.setVisibility(View.INVISIBLE);
                            break;
                        case 2:
                            view.setVisibility(View.GONE);
                            break;
                    }
                    group.addView(view);
                }
            } finally {
                childParser.close();
            }
        }
    } else {
        throw new InflateException("<include /> can only be used inside of a ViewGroup");
    }
    LayoutInflater.consumeChildElements(parser);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) TypedValue(android.util.TypedValue) LayoutlibDelegate(com.android.tools.layoutlib.annotations.LayoutlibDelegate)

Example 25 with XmlResourceParser

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

the class TextView method setInputExtras.

/**
     * Set the extra input data of the text, which is the
     * {@link EditorInfo#extras TextBoxAttribute.extras}
     * Bundle that will be filled in when creating an input connection.  The
     * given integer is the resource ID of an XML resource holding an
     * {@link android.R.styleable#InputExtras &lt;input-extras&gt;} XML tree.
     *
     * @see #getInputExtras(boolean)
     * @see EditorInfo#extras
     * @attr ref android.R.styleable#TextView_editorExtras
     */
public void setInputExtras(@XmlRes int xmlResId) throws XmlPullParserException, IOException {
    createEditorIfNeeded();
    XmlResourceParser parser = getResources().getXml(xmlResId);
    mEditor.createInputContentTypeIfNeeded();
    mEditor.mInputContentType.extras = new Bundle();
    getResources().parseBundleExtras(parser, mEditor.mInputContentType.extras);
}
Also used : XmlResourceParser(android.content.res.XmlResourceParser) Bundle(android.os.Bundle)

Aggregations

XmlResourceParser (android.content.res.XmlResourceParser)508 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)267 IOException (java.io.IOException)247 AttributeSet (android.util.AttributeSet)241 Resources (android.content.res.Resources)146 TypedArray (android.content.res.TypedArray)97 Test (org.junit.Test)82 PackageManager (android.content.pm.PackageManager)68 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)68 ArrayList (java.util.ArrayList)52 ComponentName (android.content.ComponentName)49 Bundle (android.os.Bundle)44 ActivityInfo (android.content.pm.ActivityInfo)43 AssetManager (android.content.res.AssetManager)32 RemoteException (android.os.RemoteException)31 TypedValue (android.util.TypedValue)29 ResolveInfo (android.content.pm.ResolveInfo)27 Intent (android.content.Intent)25 ApplicationInfo (android.content.pm.ApplicationInfo)25 Context (android.content.Context)22