Search in sources :

Example 31 with AttributeSet

use of android.util.AttributeSet in project platform_frameworks_base by android.

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 32 with AttributeSet

use of android.util.AttributeSet in project platform_frameworks_base by android.

the class SearchableInfo method getActivityMetaData.

/**
     * Get the metadata for a given activity
     * 
     * @param context runtime context
     * @param xml XML parser for reading attributes
     * @param cName The component name of the searchable activity
     * 
     * @result A completely constructed SearchableInfo, or null if insufficient XML data for it
     */
private static SearchableInfo getActivityMetaData(Context context, XmlPullParser xml, final ComponentName cName) {
    SearchableInfo result = null;
    Context activityContext = createActivityContext(context, cName);
    if (activityContext == null)
        return null;
    // forward through the file until it's reading the tag of interest.
    try {
        int tagType = xml.next();
        while (tagType != XmlPullParser.END_DOCUMENT) {
            if (tagType == XmlPullParser.START_TAG) {
                if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE)) {
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result = new SearchableInfo(activityContext, attr, cName);
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid searchable metadata for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                } else if (xml.getName().equals(MD_XML_ELEMENT_SEARCHABLE_ACTION_KEY)) {
                    if (result == null) {
                        // Can't process an embedded element if we haven't seen the enclosing
                        return null;
                    }
                    AttributeSet attr = Xml.asAttributeSet(xml);
                    if (attr != null) {
                        try {
                            result.addActionKey(new ActionKeyInfo(activityContext, attr));
                        } catch (IllegalArgumentException ex) {
                            Log.w(LOG_TAG, "Invalid action key for " + cName.flattenToShortString() + ": " + ex.getMessage());
                            return null;
                        }
                    }
                }
            }
            tagType = xml.next();
        }
    } catch (XmlPullParserException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    } catch (IOException e) {
        Log.w(LOG_TAG, "Reading searchable metadata for " + cName.flattenToShortString(), e);
        return null;
    }
    return result;
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) XmlPullParserException(org.xmlpull.v1.XmlPullParserException) IOException(java.io.IOException)

Example 33 with AttributeSet

use of android.util.AttributeSet in project robolectric by robolectric.

the class ShadowMapView method __constructor__.

public void __constructor__(Context context, AttributeSet attributeSet) {
    setContextOnRealView(context);
    this.attributeSet = attributeSet;
    zoomButtonsController = new ZoomButtonsController(realMapView);
    invokeConstructor(View.class, realView, ClassParameter.from(Context.class, context), ClassParameter.from(AttributeSet.class, attributeSet), ClassParameter.from(int.class, 0));
    invokeConstructor(ViewGroup.class, realView, ClassParameter.from(Context.class, context), ClassParameter.from(AttributeSet.class, attributeSet), ClassParameter.from(int.class, 0));
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) ZoomButtonsController(android.widget.ZoomButtonsController)

Example 34 with AttributeSet

use of android.util.AttributeSet in project robolectric by robolectric.

the class ShadowMapView method __constructor__.

@Override
public void __constructor__(Context context, AttributeSet attributeSet, int defStyle) {
    setContextOnRealView(context);
    this.attributeSet = attributeSet;
    zoomButtonsController = new ZoomButtonsController(realMapView);
    invokeConstructor(View.class, realView, ClassParameter.from(Context.class, context), ClassParameter.from(AttributeSet.class, attributeSet), ClassParameter.from(int.class, defStyle));
    invokeConstructor(ViewGroup.class, realView, ClassParameter.from(Context.class, context), ClassParameter.from(AttributeSet.class, attributeSet), ClassParameter.from(int.class, defStyle));
    super.__constructor__(context, attributeSet, defStyle);
}
Also used : Context(android.content.Context) AttributeSet(android.util.AttributeSet) ZoomButtonsController(android.widget.ZoomButtonsController)

Example 35 with AttributeSet

use of android.util.AttributeSet in project robolectric by robolectric.

the class ShadowThemeTest method dimenRef.

@Test
public void dimenRef() throws Exception {
    AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(android.R.attr.layout_height, "@dimen/test_px_dimen").build();
    TypedArray typedArray = resources.newTheme().obtainStyledAttributes(attributeSet, new int[] { android.R.attr.layout_height }, 0, 0);
    assertThat(typedArray.getDimensionPixelSize(0, -1)).isEqualTo(15);
}
Also used : AttributeSet(android.util.AttributeSet) TypedArray(android.content.res.TypedArray) Test(org.junit.Test)

Aggregations

AttributeSet (android.util.AttributeSet)262 XmlPullParserException (org.xmlpull.v1.XmlPullParserException)160 IOException (java.io.IOException)125 XmlResourceParser (android.content.res.XmlResourceParser)113 TypedArray (android.content.res.TypedArray)78 Resources (android.content.res.Resources)46 Test (org.junit.Test)42 TypedValue (android.util.TypedValue)34 InflateException (android.view.InflateException)28 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)24 PackageManager (android.content.pm.PackageManager)22 Context (android.content.Context)20 ComponentName (android.content.ComponentName)18 XmlPullParser (org.xmlpull.v1.XmlPullParser)17 Intent (android.content.Intent)11 RemoteException (android.os.RemoteException)11 Bundle (android.os.Bundle)9 ArrayList (java.util.ArrayList)9 ActivityInfo (android.content.pm.ActivityInfo)7 ApplicationInfo (android.content.pm.ApplicationInfo)7