@Test public void testInflateSimple() { Context context = InstrumentationRegistry.getTargetContext(); NavInflater navInflater = new NavInflater(context, new TestNavigatorProvider(context)); NavGraph graph = navInflater.inflate(R.navigation.nav_simple); assertThat(graph, is(notNullValue(NavGraph.class))); assertThat(graph.getStartDestination(), is(R.id.start_test)); }
@SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } }
NavInflater { @SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } } }
NavInflater { @SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } } NavInflater(@NonNull Context context, @NonNull NavigatorProvider navigatorProvider); }
NavInflater { @SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } } NavInflater(@NonNull Context context, @NonNull NavigatorProvider navigatorProvider); @Nullable NavGraph inflateMetadataGraph(); @SuppressLint("ResourceType") @NonNull NavGraph inflate(@NavigationRes int graphResId); }
NavInflater { @SuppressLint("ResourceType") @NonNull public NavGraph inflate(@NavigationRes int graphResId) { Resources res = mContext.getResources(); XmlResourceParser parser = res.getXml(graphResId); final AttributeSet attrs = Xml.asAttributeSet(parser); try { int type; while ((type = parser.next()) != XmlPullParser.START_TAG && type != XmlPullParser.END_DOCUMENT) { } if (type != XmlPullParser.START_TAG) { throw new XmlPullParserException("No start tag found"); } String rootElement = parser.getName(); NavDestination destination = inflate(res, parser, attrs); if (!(destination instanceof NavGraph)) { throw new IllegalArgumentException("Root element <" + rootElement + ">" + " did not inflate into a NavGraph"); } return (NavGraph) destination; } catch (Exception e) { throw new RuntimeException("Exception inflating " + res.getResourceName(graphResId) + " line " + parser.getLineNumber(), e); } finally { parser.close(); } } NavInflater(@NonNull Context context, @NonNull NavigatorProvider navigatorProvider); @Nullable NavGraph inflateMetadataGraph(); @SuppressLint("ResourceType") @NonNull NavGraph inflate(@NavigationRes int graphResId); @SuppressWarnings("WeakerAccess")
    static final String METADATA_KEY_GRAPH; }