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