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);
}
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;
}
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));
}
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);
}
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);
}
Aggregations