Search in sources :

Example 36 with AttributeSet

use of android.util.AttributeSet in project FloatingSearchView by renaudcerrato.

the class FloatingSearchView method inflateMenu.

public void inflateMenu(@MenuRes int menuRes) {
    if (menuRes == 0)
        return;
    if (isInEditMode())
        return;
    getActivity().getMenuInflater().inflate(menuRes, mActionMenu.getMenu());
    XmlResourceParser parser = null;
    try {
        //noinspection ResourceType
        parser = getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs);
    } catch (XmlPullParserException | IOException e) {
        // should not happens
        throw new InflateException("Error parsing 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 37 with AttributeSet

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

the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength.

@Test
public void givenInitializingWithAttributeSet_whenMaxLengthDefined_thenRestrictTextLengthToMaxLength() {
    int maxLength = anyInteger();
    AttributeSet attrs = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, maxLength + "").build();
    EditText editText = new EditText(RuntimeEnvironment.application, attrs);
    String excessiveInput = stringOfLength(maxLength * 2);
    editText.setText(excessiveInput);
    assertThat((CharSequence) editText.getText().toString()).isEqualTo(excessiveInput.subSequence(0, maxLength));
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Example 38 with AttributeSet

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

the class ShadowEditTextTest method givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions.

@Test
public void givenInitializingWithAttributeSet_whenMaxLengthNotDefined_thenTextLengthShouldHaveNoRestrictions() {
    AttributeSet attrs = Robolectric.buildAttributeSet().build();
    EditText editText = new EditText(RuntimeEnvironment.application, attrs);
    String input = anyString();
    editText.setText(input);
    assertThat(editText.getText().toString()).isEqualTo(input);
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Test(org.junit.Test)

Example 39 with AttributeSet

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

the class ShadowEditTextTest method setup.

@Before
public void setup() {
    AttributeSet attributeSet = Robolectric.buildAttributeSet().addAttribute(android.R.attr.maxLength, "5").build();
    editText = new EditText(application, attributeSet);
}
Also used : EditText(android.widget.EditText) AttributeSet(android.util.AttributeSet) Before(org.junit.Before)

Example 40 with AttributeSet

use of android.util.AttributeSet in project cw-omnibus by commonsguy.

the class MenuInflater method inflate.

/**
     * Inflate a menu hierarchy from the specified XML resource. Throws
     * {@link InflateException} if there is an error.
     *
     * @param menuRes Resource ID for an XML layout resource to load (e.g.,
     *            <code>R.menu.main_activity</code>)
     * @param menu The Menu to inflate into. The items and submenus will be
     *            added to this Menu.
     */
public void inflate(int menuRes, Menu menu) {
    XmlResourceParser parser = null;
    try {
        parser = mContext.getResources().getLayout(menuRes);
        AttributeSet attrs = Xml.asAttributeSet(parser);
        parseMenu(parser, attrs, menu);
    } 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)

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