@Test public void should_check_resource_language() { ViewProxy proxy = mock(ViewProxy.class); assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(true); when(proxy.getResourceLanguages()).thenReturn(new String[] {"foo"}); assertThat(Views.acceptResourceLanguage(proxy, Java.KEY)).isEqualTo(false); assertThat(Views.acceptResourceLanguage(proxy, "foo")).isEqualTo(true); }
@Test public void should_check_resource_scope() { ViewProxy proxy = mock(ViewProxy.class); assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true); when(proxy.getResourceScopes()).thenReturn(new String[] {Scopes.PROJECT, Scopes.FILE}); assertThat(Views.acceptResourceScope(proxy, Scopes.FILE)).isEqualTo(true); assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY)).isEqualTo(false); }
@Test public void checkResourceLanguage() { ViewProxy proxy = mock(ViewProxy.class); assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(true)); when(proxy.getResourceLanguages()).thenReturn(new String[] {"foo"}); assertThat(Views.acceptResourceLanguage(proxy, Java.KEY), is(false)); assertThat(Views.acceptResourceLanguage(proxy, "foo"), is(true)); }
@Test public void checkResourceScope() { ViewProxy proxy = mock(ViewProxy.class); assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true)); when(proxy.getResourceScopes()).thenReturn(new String[] {Scopes.PROJECT, Scopes.FILE}); assertThat(Views.acceptResourceScope(proxy, Scopes.FILE), is(true)); assertThat(Views.acceptResourceScope(proxy, Scopes.DIRECTORY), is(false)); }
@Test public void doNotCheckNavigationSectionOnWidgets() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.isWidget()).thenReturn(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true)); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(true)); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(true)); assertThat(Views.acceptNavigationSection(proxy, null), is(true)); }
@Test public void should_check_resource_qualifier() { ViewProxy proxy = mock(ViewProxy.class); assertThat(Views.acceptResourceQualifier(proxy, Scopes.FILE)).isEqualTo(true); when(proxy.getResourceQualifiers()) .thenReturn(new String[] {Qualifiers.CLASS, Qualifiers.FILE}); assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.FILE)).isEqualTo(true); assertThat(Views.acceptResourceQualifier(proxy, Qualifiers.PACKAGE)).isEqualTo(false); }
@Test public void acceptNavigationSection() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.getSections()).thenReturn(new String[] {NavigationSection.RESOURCE}); when(proxy.isWidget()).thenReturn(false); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE), is(true)); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME), is(false)); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION), is(false)); assertThat(Views.acceptNavigationSection(proxy, null), is(true)); }
private void register(View view) { if (view instanceof Widget) { ViewProxy<Widget> proxy = new ViewProxy<>((Widget) view, userSession); widgets.add(proxy); widgetsPerId.put(proxy.getId(), proxy); } else if (view instanceof Page) { ViewProxy<Page> proxy = new ViewProxy<>((Page) view, userSession); pagesPerId.put(proxy.getId(), proxy); pages.add(proxy); } }
@Test public void should_not_check_navigation_section_on_widgets() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.isWidget()).thenReturn(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)) .isEqualTo(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE_CONFIGURATION)) .isEqualTo(true); assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true); }
@Test public void should_accept_navigation_section() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.getSections()).thenReturn(new String[] {NavigationSection.RESOURCE}); when(proxy.isWidget()).thenReturn(false); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE)).isEqualTo(true); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.HOME)).isEqualTo(false); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.CONFIGURATION)) .isEqualTo(false); assertThat(Views.acceptNavigationSection(proxy, NavigationSection.RESOURCE_CONFIGURATION)) .isEqualTo(false); assertThat(Views.acceptNavigationSection(proxy, null)).isEqualTo(true); }
@Test public void should_accept_available_measures() { ViewProxy proxy = mock(ViewProxy.class); when(proxy.acceptsAvailableMeasures(new String[] {"lines"})).thenReturn(true); when(proxy.acceptsAvailableMeasures(new String[] {"ncloc"})).thenReturn(false); assertThat(Views.acceptAvailableMeasures(proxy, null)).isEqualTo(true); assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"lines"})).isEqualTo(true); assertThat(Views.acceptAvailableMeasures(proxy, new String[] {"ncloc"})).isEqualTo(false); assertThat(Views.accept(proxy, null, null, null, null, null)).isEqualTo(true); assertThat(Views.accept(proxy, null, null, null, null, new String[] {"lines"})).isEqualTo(true); assertThat(Views.accept(proxy, null, null, null, null, new String[] {"ncloc"})) .isEqualTo(false); }
@Kroll.method public void release() { if (TiApplication.isUIThread()) { super.releaseViews(); } else { getMainHandler().sendEmptyMessage(MSG_RELEASE); } }
public List<ViewProxy<Page>> getPagesForMetric( String section, String resourceScope, String resourceQualifier, String resourceLanguage, String[] availableMeasures, String metric) { List<ViewProxy<Page>> result = Lists.newArrayList(); for (ViewProxy<Page> proxy : pages) { if (accept( proxy, section, resourceScope, resourceQualifier, resourceLanguage, availableMeasures) && proxy.supportsMetric(metric)) { result.add(proxy); } } return result; }
@Override public void setActivity(Activity activity) { super.setActivity(activity); if (rows != null) { for (TableViewRowProxy row : rows) { row.setActivity(activity); } } }
@Override public void releaseViews(boolean activityFinishing) { super.releaseViews(activityFinishing); if (rows != null) { for (TableViewRowProxy row : rows) { row.releaseViews(activityFinishing); } } }
@Override protected void handleShow(KrollDict options) { super.handleShow(options); TiUINotification n = (TiUINotification) getOrCreateView(); if (n != null) { n.show(options); } }
@Override public boolean handleMessage(Message msg) { if (peekView() != null) { switch (msg.what) { case MSG_GO_BACK: getWebView().goBack(); return true; case MSG_GO_FORWARD: getWebView().goForward(); return true; case MSG_RELOAD: getWebView().reload(); return true; case MSG_STOP_LOADING: getWebView().stopLoading(); return true; case MSG_SET_USER_AGENT: getWebView().setUserAgentString(msg.obj.toString()); return true; case MSG_GET_USER_AGENT: { AsyncResult result = (AsyncResult) msg.obj; result.setResult(getWebView().getUserAgentString()); return true; } case MSG_CAN_GO_BACK: { AsyncResult result = (AsyncResult) msg.obj; result.setResult(getWebView().canGoBack()); return true; } case MSG_CAN_GO_FORWARD: { AsyncResult result = (AsyncResult) msg.obj; result.setResult(getWebView().canGoForward()); return true; } case MSG_RELEASE: super.releaseViews(); return true; case MSG_PAUSE: getWebView().pauseWebView(); return true; case MSG_RESUME: getWebView().resumeWebView(); return true; case MSG_SET_HTML: String html = TiConvert.toString(getProperty(TiC.PROPERTY_HTML)); HashMap<String, Object> d = (HashMap<String, Object>) getProperty(OPTIONS_IN_SETHTML); getWebView().setHtml(html, d); return true; } } return super.handleMessage(msg); }
@Override public void onDestroy(Activity activity) { TiUIWebView webView = (TiUIWebView) peekView(); if (webView == null) { return; } // We allow JS polling to continue until we exit the app. If we want to stop the polling when // the app is // backgrounded, we would need to move this to onStop(), and add the appropriate logic in // onResume() to restart // the polling. webView.destroyWebViewBinding(); WebView nativeWebView = webView.getWebView(); if (nativeWebView == null) { return; } nativeWebView.stopLoading(); super.releaseViews(); }
protected static boolean acceptResourceScope(ViewProxy<?> proxy, @Nullable String resourceScope) { return resourceScope == null || ArrayUtils.isEmpty(proxy.getResourceScopes()) || ArrayUtils.contains(proxy.getResourceScopes(), resourceScope); }
protected static boolean acceptNavigationSection(ViewProxy<?> proxy, @Nullable String section) { return proxy.isWidget() || section == null || ArrayUtils.contains(proxy.getSections(), section); }
protected static boolean acceptAvailableMeasures( ViewProxy<?> proxy, @Nullable String[] availableMeasures) { return availableMeasures == null || proxy.acceptsAvailableMeasures(availableMeasures); }
protected static boolean acceptResourceQualifier( ViewProxy<?> proxy, @Nullable String resourceQualifier) { return resourceQualifier == null || ArrayUtils.isEmpty(proxy.getResourceQualifiers()) || ArrayUtils.contains(proxy.getResourceQualifiers(), resourceQualifier); }