/** * Creates a new WebViewer component. * * @param container container the component will be placed in */ public WebViewer(ComponentContainer container) { super(container); webview = new WebView(container.$context()); webview.setWebViewClient(new WebViewerClient()); webview.getSettings().setJavaScriptEnabled(true); webview.setFocusable(true); // enable pinch zooming and zoom controls webview.getSettings().setBuiltInZoomControls(true); container.$add(this); webview.setOnTouchListener( new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: case MotionEvent.ACTION_UP: if (!v.hasFocus()) { v.requestFocus(); } break; } return false; } }); // set the initial default properties. Height and Width // will be fill-parent, which will be the default for the web viewer. followLinks = true; HomeUrl(""); Width(LENGTH_FILL_PARENT); Height(LENGTH_FILL_PARENT); }
@Test public void test_add_collection() { ComponentContainer container = new ComponentContainer(); container.add(Arrays.asList(ComponentWithProperty.class, SimpleComponent.class)); assertThat(container.getComponentByType(ComponentWithProperty.class)).isNotNull(); assertThat(container.getComponentByType(SimpleComponent.class)).isNotNull(); }
public SensorDB(ComponentContainer container) { super(container.$form()); // TODO Auto-generated constructor stub // Set up listeners form.registerForOnDestroy(this); mainUIThreadActivity = container.$context(); handler = new Handler(); // we use dbName as pipelineName, each app (package) has their unique dbName, which is // packagename + "__SENSOR_DB__" pipelineName = SensorDbUtil.getPipelineName(mainUIThreadActivity); exportPath = new File(Environment.getExternalStorageDirectory(), form.getPackageName()) + File.separator + "export"; exportFormat = NameValueDatabaseService.EXPORT_CSV; // set the exporting format as csv by default // Intent i = new Intent(mainUIThreadActivity, FunfManager.class); // mainUIThreadActivity.startService(i); if (!Launcher.isLaunched()) { Log.i(TAG, "firstTime launching...."); Launcher.launch(mainUIThreadActivity); } // bind to FunfManger (in case the user wants to set up the schedule) doBindService(); // now we get(bind) to the Pipleline class that exists // we can set upload and archive periods using the pipeline form.registerForOnDestroy(this); }
/** * Creates a new TextMessage component. * * @param container ignored (because this is a non-visible component) */ public Texting(ComponentContainer container) { super(container.$form()); Log.d(TAG, "Texting constructor"); Texting.component = (Texting) this; activity = container.$context(); SharedPreferences prefs = activity.getSharedPreferences(PREF_FILE, Activity.MODE_PRIVATE); if (prefs != null) { receivingEnabled = prefs.getBoolean(PREF_RCVENABLED, true); googleVoiceEnabled = prefs.getBoolean(PREF_GVENABLED, false); Log.i( TAG, "Starting with receiving Enabled=" + receivingEnabled + " GV enabled=" + googleVoiceEnabled); } else { receivingEnabled = true; googleVoiceEnabled = false; } smsManager = SmsManager.getDefault(); PhoneNumber(""); isInitialized = false; // Set true when the form is initialized and can dispatch isRunning = false; // This will be set true in onResume and false in onPause // Register this component for lifecycle callbacks container.$form().registerForOnInitialize(this); container.$form().registerForOnResume(this); container.$form().registerForOnPause(this); container.$form().registerForOnStop(this); }
/** * Creates a new ButtonBase component. * * @param container container, component will be placed in */ public ButtonBase(ComponentContainer container) { super(container); view = new android.widget.Button(container.$context()); // Save the default values in case the user wants them back later. defaultButtonDrawable = view.getBackground(); defaultColorStateList = view.getTextColors(); // Adds the component to its designated container container.$add(this); // Listen to clicks and focus changes view.setOnClickListener(this); view.setOnFocusChangeListener(this); view.setOnLongClickListener(this); view.setOnTouchListener(this); // Default property values TextAlignment(Component.ALIGNMENT_CENTER); // BackgroundColor and Image are dangerous properties: // Once either of them is set, the 3D bevel effect for the button is // irretrievable, except by reloading defaultButtonDrawable, defined above. BackgroundColor(Component.COLOR_DEFAULT); Image(""); Enabled(true); fontTypeface = Component.TYPEFACE_DEFAULT; TextViewUtil.setFontTypeface(view, fontTypeface, bold, italic); FontSize(Component.FONT_DEFAULT_SIZE); Text(""); TextColor(Component.COLOR_DEFAULT); Shape(Component.BUTTON_SHAPE_DEFAULT); }
@Test public void should_stop_hierarchy_of_containers_on_failure() { StartableComponent parentComponent = new StartableComponent(); final StartableComponent childComponent1 = new StartableComponent(); final UnstartableComponent childComponent2 = new UnstartableComponent(); ComponentContainer parentContainer = new ComponentContainer() { @Override public void doAfterStart() { ComponentContainer childContainer = new ComponentContainer(this); childContainer.add(childComponent1); childContainer.add(childComponent2); childContainer.execute(); } }; parentContainer.add(parentComponent); try { parentContainer.execute(); fail(); } catch (Exception e) { assertThat(parentComponent.started).isTrue(); assertThat(parentComponent.stopped).isTrue(); assertThat(childComponent1.started).isTrue(); assertThat(childComponent1.stopped).isTrue(); } }
@Override public void reorder(int[] perm) { if (component instanceof ComponentContainer) { ComponentContainer cont = (ComponentContainer) component; cont.reorderSubComponents(perm); component.getFormModel().fireComponentsReordered(cont, perm); } }
public void replaceContainer(ComponentContainer newContainer, ComponentContainer newPosition) { ComponentContainer containerParent = (ComponentContainer) tabContainer.getParent(); if (containerParent != null) { containerParent.removeComponent(tabContainer); } if (newPosition == null) newPosition = newContainer; newPosition.addComponent(tabContainer); contentWrapper.addComponent(newContainer); }
protected void activateLoadedView(Component lazyLoad) { if (getParent() instanceof ComponentContainer) { final ComponentContainer parent = (ComponentContainer) getParent(); parent.replaceComponent(this, lazyLoad); } else { removeAllComponents(); addComponent(lazyLoad); } }
@Test public void should_sanitize_pico_exception_on_start_failure() { ComponentContainer container = new ComponentContainer(); container.add(UnstartableComponent.class); // do not expect a PicoException thrown.expect(IllegalStateException.class); container.startComponents(); }
@Test public void stop_exception_should_not_hide_start_exception() { ComponentContainer container = new ComponentContainer(); container.add(UnstartableComponent.class, UnstoppableComponent.class); thrown.expect(IllegalStateException.class); thrown.expectMessage("Fail to start"); container.execute(); }
/** Method close() must be called even if the methods start() or stop() are not defined. */ @Test public void should_close_components_without_lifecycle() { ComponentContainer container = new ComponentContainer(); CloseableComponent component = new CloseableComponent(); container.add(component); container.execute(); assertThat(component.isClosed).isTrue(); }
@Test public void shouldDeclareComponentProperties() { ComponentContainer container = new ComponentContainer(); container.addSingleton(ComponentWithProperty.class); PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class); assertThat(propertyDefinitions.get("foo")).isNotNull(); assertThat(propertyDefinitions.get("foo").defaultValue()).isEqualTo("bar"); }
public ImageGallery(ComponentContainer container, String[] picnames, int[] basestyle) { super(container); view = new Gallery(container.$context()); adapter = new ImageAdapter(container.$context(), basestyle); adapter.setFiles(picnames); view.setAdapter(adapter); view.setOnItemClickListener(this); container.$add(this); view.requestLayout(); }
@Test public void should_execute_components() { ComponentContainer container = new ComponentContainer(); StartableComponent component = new StartableComponent(); container.add(component); container.execute(); assertThat(component.started).isTrue(); assertThat(component.stopped).isTrue(); }
public ImageGallery( ComponentContainer container, String[] picnames, int[] basestyle, int resourceId) { super(container, resourceId); view = null; Gallery view = (Gallery) container.$form().findViewById(resourceId); adapter = new ImageAdapter(container.$context(), basestyle); adapter.setFiles(picnames); view.setAdapter(adapter); view.setOnItemClickListener(this); view.requestLayout(); }
@Test public void shouldDeclareExtensionWithoutAddingIt() { ComponentContainer container = new ComponentContainer(); PluginInfo plugin = mock(PluginInfo.class); container.declareExtension(plugin, ComponentWithProperty.class); PropertyDefinitions propertyDefinitions = container.getComponentByType(PropertyDefinitions.class); assertThat(propertyDefinitions.get("foo")).isNotNull(); assertThat(container.getComponentByType(ComponentWithProperty.class)).isNull(); }
/** Sets the items of the ListView through an adapter */ public void setAdapterData() { adapter = new ArrayAdapter<Spannable>( container.$context(), android.R.layout.simple_list_item_1, itemsToColoredText()); view.setAdapter(adapter); adapterCopy = new ArrayAdapter<Spannable>(container.$context(), android.R.layout.simple_list_item_1); for (int i = 0; i < adapter.getCount(); ++i) { adapterCopy.insert(adapter.getItem(i), i); } }
/** Method close() must be executed after stop() */ @Test public void should_close_components_with_lifecycle() { ComponentContainer container = new ComponentContainer(); StartableCloseableComponent component = new StartableCloseableComponent(); container.add(component); container.execute(); assertThat(component.isStopped).isTrue(); assertThat(component.isClosed).isTrue(); assertThat(component.isClosedAfterStop).isTrue(); }
@Test public void display_plugin_name_when_failing_to_add_extension() { ComponentContainer container = new ComponentContainer(); PluginInfo plugin = mock(PluginInfo.class); container.startComponents(); thrown.expect(IllegalStateException.class); thrown.expectMessage( "Unable to register extension org.sonar.core.platform.ComponentContainerTest$UnstartableComponent"); container.addExtension(plugin, UnstartableComponent.class); }
/** * Creates a new HVArrangement component. * * @param container container, component will be placed in * @param orientation one of {@link ComponentConstants#LAYOUT_ORIENTATION_HORIZONTAL}. {@link * ComponentConstants#LAYOUT_ORIENTATION_VERTICAL} */ public HVArrangement(ComponentContainer container, int orientation) { super(container); context = container.$context(); this.orientation = orientation; viewLayout = new LinearLayout( context, orientation, ComponentConstants.EMPTY_HV_ARRANGEMENT_WIDTH, ComponentConstants.EMPTY_HV_ARRANGEMENT_HEIGHT); container.$add(this); }
@Test public void test_stop_failure() { ComponentContainer container = new ComponentContainer(); StartableComponent startable = new StartableComponent(); container.add(startable, UnstoppableComponent.class); try { container.execute(); fail(); } catch (Exception e) { assertThat(startable.started).isTrue(); // container should stop the components that have already been started // ... but that's not the case } }
// FormNodeChildren implementation @Override protected void updateKeys() { RADComponent[] subComps = container.getSubBeans(); List<Object> keys = new ArrayList<Object>(subComps.length + 2); if (container instanceof RADVisualContainer) { RADVisualContainer visualCont = (RADVisualContainer) container; RADComponent menuComp = visualCont.getContainerMenu(); if (menuComp != null) keys.add(menuComp); if (visualCont.shouldHaveLayoutNode()) { keyLayout = visualCont .getLayoutSupport() .getLayoutDelegate(); // new Object(); // [need not be recreated every time] keys.add(keyLayout); } for (int i = 0; i < subComps.length; i++) if (subComps[i] != menuComp) keys.add(subComps[i]); } else { for (int i = 0; i < subComps.length; i++) keys.add(subComps[i]); } setKeys(keys); }
/** * Creates a new TextMessage component. * * @param container ignored (because this is a non-visible component) */ public Texting(ComponentContainer container) { super(container.$form()); Log.d(TAG, "Texting constructor"); this.container = container; Texting.component = (Texting) this; activity = container.$context(); SharedPreferences prefs = activity.getSharedPreferences(PREF_FILE, Activity.MODE_PRIVATE); if (prefs != null) { receivingEnabled = prefs.getInt(PREF_RCVENABLED, -1); if (receivingEnabled == -1) { if (prefs.getBoolean(PREF_RCVENABLED_LEGACY, true)) { receivingEnabled = ComponentConstants.TEXT_RECEIVING_FOREGROUND; } else { receivingEnabled = ComponentConstants.TEXT_RECEIVING_OFF; } } googleVoiceEnabled = prefs.getBoolean(PREF_GVENABLED, false); Log.i( TAG, "Starting with receiving Enabled=" + receivingEnabled + " GV enabled=" + googleVoiceEnabled); } else { receivingEnabled = ComponentConstants.TEXT_RECEIVING_FOREGROUND; googleVoiceEnabled = false; } // Handles authenticating for GV feature. This sets the authToken. if (googleVoiceEnabled) new AsyncAuthenticate().execute(); smsManager = SmsManager.getDefault(); PhoneNumber(""); isInitialized = false; // Set true when the form is initialized and can dispatch isRunning = false; // This will be set true in onResume and false in onPause // Register this component for lifecycle callbacks container.$form().registerForOnInitialize(this); container.$form().registerForOnResume(this); container.$form().registerForOnPause(this); container.$form().registerForOnStop(this); }
/** * Constructor for Toggle Button component when using the GLE. * * @param container * @param resourceId */ public Toggle(ComponentContainer container, int resourceId) { super(container, resourceId); view = (ToggleButton) container.$context().findViewById(resourceId); if (view == null) { throw new IllegalArgumentException( "View with resource Id " + resourceId + " is coming up null!"); } view.setOnCheckedChangeListener(this); }
/** * Creates a new LocationSensor component. * * @param container ignored (because this is a non-visible component) */ public LocationSensor(ComponentContainer container) { super(container.$form()); handler = new Handler(); // Set up listener form.registerForOnResume(this); form.registerForOnStop(this); // Initialize sensor properties (60 seconds; 5 meters) timeInterval = 60000; distanceInterval = 5; // Initialize location-related fields Context context = container.$context(); geocoder = new Geocoder(context); locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE); locationCriteria = new Criteria(); myLocationListener = new MyLocationListener(); }
@Test public void shouldForwardStartAndStopToDescendants() { ComponentContainer grandParent = new ComponentContainer(); ComponentContainer parent = grandParent.createChild(); ComponentContainer child = parent.createChild(); child.addSingleton(StartableComponent.class); grandParent.startComponents(); StartableComponent component = child.getComponentByType(StartableComponent.class); assertTrue(component.started); parent.stopComponents(); assertTrue(component.stopped); }
public Texting(ComponentContainer paramComponentContainer) { super(paramComponentContainer.$form()); Log.d("Texting Component", "Texting constructor"); this.container = paramComponentContainer; component = this; activity = paramComponentContainer.$context(); SharedPreferences localSharedPreferences = activity.getSharedPreferences("TextingState", 0); if (localSharedPreferences != null) { receivingEnabled = localSharedPreferences.getInt("receiving2", -1); if (receivingEnabled == -1) { if (localSharedPreferences.getBoolean("receiving", true)) { receivingEnabled = 2; } } else { this.googleVoiceEnabled = localSharedPreferences.getBoolean("gvenabled", false); Log.i("Texting Component", "Starting with receiving Enabled=" + receivingEnabled + " GV enabled=" + this.googleVoiceEnabled); } } for (;;) { if (this.googleVoiceEnabled) { new AsyncAuthenticate().execute(new Void[0]); } this.smsManager = SmsManager.getDefault(); PhoneNumber(""); this.isInitialized = false; isRunning = false; paramComponentContainer.$form().registerForOnInitialize(this); paramComponentContainer.$form().registerForOnResume(this); paramComponentContainer.$form().registerForOnPause(this); paramComponentContainer.$form().registerForOnStop(this); return; receivingEnabled = 1; break; receivingEnabled = 2; this.googleVoiceEnabled = false; } }
/** * Creates a new TextBoxBase component * * @param container container that the component will be placed in * @param textview the underlying EditText object that maintains the text */ public TextBoxBase(ComponentContainer container, EditText textview) { super(container); view = textview; // Listen to focus changes view.setOnFocusChangeListener(this); defaultTextBoxDrawable = view.getBackground(); // Add a transformation method to provide input validation /* * TODO(user): see comment above) setTransformationMethod(new * ValidationTransformationMethod()); */ // Adds the component to its designated container container.$add(this); container.setChildWidth(this, ComponentConstants.TEXTBOX_PREFERRED_WIDTH); TextAlignment(Component.ALIGNMENT_NORMAL); // Leave the nice default background color. Users can change it to // "none" if they like // // TODO(user): if we make a change here we also need to change the // default property value. // Eventually I hope to simplify this so it has to be changed in one // location // only). Maybe we need another color value which would be // 'SYSTEM_DEFAULT' which // will not attempt to explicitly initialize with any of the properties // with any // particular value. // BackgroundColor(Component.COLOR_NONE); Enabled(true); fontTypeface = Component.TYPEFACE_DEFAULT; TextViewUtil.setFontTypeface(view, fontTypeface, bold, italic); FontSize(Component.FONT_DEFAULT_SIZE); Hint(""); Text(""); TextColor(Component.COLOR_BLACK); }
@Test public void should_start_and_stop_hierarchy_of_containers() { StartableComponent parentComponent = new StartableComponent(); final StartableComponent childComponent = new StartableComponent(); ComponentContainer parentContainer = new ComponentContainer() { @Override public void doAfterStart() { ComponentContainer childContainer = new ComponentContainer(this); childContainer.add(childComponent); childContainer.execute(); } }; parentContainer.add(parentComponent); parentContainer.execute(); assertThat(parentComponent.started).isTrue(); assertThat(parentComponent.stopped).isTrue(); assertThat(childComponent.started).isTrue(); assertThat(childComponent.stopped).isTrue(); }