public void actionPerformed (final @Nonnull ActionEvent event) { log.info("SelectTaxonAction.actionPerformed(): {}", taxonPM); flowController.toNextStep(taxonPM.as(Taxon.class)); } }
public void propertyChange (final @Nonnull PropertyChangeEvent event) { if (PROP_DOWNLOAD_PROGRESS.equals(event.getPropertyName())) // FIXME: drop this, use a property-specific listener { final float progress = (Float)event.getNewValue(); log.debug("download progress for {}: {}", image.as(Identifiable).getId(), progress); } } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ Observation getObservation (final @Nonnegative int index) { return getPresentationModel(index).as(Observation); }
public void actionPerformed (final @Nonnull ActionEvent event) { log.info("SelectTaxonomyAction.actionPerformed(): {}", taxonomyPM); taxonomyPreferences.get().setTaxonomy(taxonomyPM.as(Taxonomy.class)); flowController.finish(); } }
@Override public boolean matches (final Object item) { if (!(item instanceof PresentationModel)) { return false; } final PresentationModel pm = (PresentationModel)item; for (final Class<?> roleType : expectedRoleTypes) { try { pm.as(roleType); } catch (AsException e) { return false; } } return true; }
@Override public void populate (final @Nonnull PresentationModel pm) { taReport.setText(pm.as(PlainTextRenderable).render()); } }
public void renderTo (View view, Object... extra) { final Document message = newsItemPM.as(Document.class); try { final String date = preferences.get().formatDateAndTime(message.get(PUB_DATE)); final TextView tvDate = (TextView)view.findViewById(R.id.tvDate); final TextView tvTitle = (TextView)view.findViewById(R.id.tvTitle); tvDate.setText(date); tvTitle.setText(message.get(TITLE)); final int icon = newsItemPM.as(Readable).isRead() ? android.R.drawable.star_off : android.R.drawable.star_on; ((ImageView)view.findViewById(R.id.ivRead)).setImageResource(icon); } catch (NotFoundException e) { } } };
public void onItemClick (final @Nonnull AdapterView<?> adapterView, final @Nonnull View view, final int index, final long id) { try { final ActionEvent actionEvent = new ActionEvent(view, ActionEvent.ACTION_PERFORMED, "actionPerformed"); getItem(index).as(ActionProvider).getDefaultAction().actionPerformed(actionEvent); } catch (AsException e) { // ok, no ActionProvider } catch (NotFoundException e) { // ok, no default Action } } };
public void showCommonNameInFullScreen (final @Nonnull PresentationModel commonNamesPM) { log.info("showCommonNameInFullScreen({})", commonNamesPM); final Intent intent = commonNamesPM.as(IntentProvider).createIntent(getBaseContext(), TaxonLargeCommonNameFactSheetActivity.class); startActivity(intent); } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ public PresentationModelAdapter (final @Nonnull Context context, final @Nonnull PresentationModel presentationModel) { log.debug("PresentationModelAdapter()"); this.context = context; this.presentationModels = new ArrayList<PresentationModel>(); try { // FIXME: why SimpleComposite? final SimpleComposite<PresentationModel> composite = presentationModel.as(SimpleComposite.class); presentationModels.addAll(composite.findChildren().results()); } catch (AsException e) { log.debug(">>>> presentationModel is not a Composite"); // ok, no Composite } // log.debug(">>>> created from {}, {} items", presentationModel, presentationModels.size()); log.debug("PresentationModelAdapter - created from {}@{}, {} items", new Object[] { presentationModel.getClass().getSimpleName(), Integer.toHexString(System.identityHashCode(presentationModel)), presentationModels.size() }); }
public void propertyChange (final @Nonnull PropertyChangeEvent event) { if (PROP_STATUS.equals(event.getPropertyName())) // FIXME: drop this, use a property-specific listener { final Status status = (Status)event.getNewValue(); log.info("download change status for {}: {}", image.as(Identifiable).getId(), status); if (status.isFinal()) { image.removePropertyChangeListener(downloadProgressListener); } switch (status) { case DOWNLOADED: doRender(); break; case BROKEN: log.warn("broken image: {}", image.as(Identifiable).getId()); // FIXME: show broken } } } };
public boolean apply (final @Nonnull Object object) { if (!(object instanceof PresentationModel)) { return false; } final PresentationModel presentationModel = (PresentationModel)object; try { return TYPE_STILL_IMAGE.stringValue().equals(presentationModel.as(Media).get(TYPE)); } catch (NotFoundException e) { return false; } catch (AsException e) { return false; } } };
/******************************************************************************************************************* * * ******************************************************************************************************************/ private void doRender() { final Uri uri = Uri.parse(image.as(Downloadable).getFile().getAbsolutePath()); // Uri.fromFile(file) doesn't work here log.debug(">>>> loading image from {}...", uri); AndroidUtilities.runOnUIThread(new Runnable() { public void run() { try { setImageURI(uri); // FIXME: is this blocking? } catch (OutOfMemoryError e) { log.error("Cannot display image because OutOfMemoryError: {}", uri); // FIXME: user notification } } }); } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public boolean onContextItemSelected (final @Nonnull MenuItem item) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo)item.getMenuInfo(); try { final ActionProvider actionProvider = getItem(info.position).as(ActionProvider); final Action[] actions = actionProvider.getActions().toArray(new Action[0]); final int menuIndex = item.getItemId(); actions[menuIndex].actionPerformed(new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "actionPerformed")); } catch (AsException e) { return false; // no ActionProvider } return true; } }
/******************************************************************************************************************* * * ******************************************************************************************************************/ public void onCreateContextMenu (final @Nonnull ContextMenu menu, final @Nonnull View view, final @Nonnull ContextMenuInfo menuInfo) { final AdapterContextMenuInfo info = (AdapterContextMenuInfo)menuInfo; try { final ActionProvider actionProvider = getItem(info.position).as(ActionProvider); int id = 0; for (final Action action : actionProvider.getActions()) { final MenuItem menuItem = menu.add(0, id++, 0, (String)action.getValue(Action.NAME)); menuItem.setEnabled(action.isEnabled()); } } catch (AsException e) { // ok, no ActionProvider } }
public void populate (final @Nonnull PresentationModel newsItemPM) { try { final Document message = newsItemPM.as(Document.class); final String date = preferences.get().formatDateAndTime((Date)message.get(PUB_DATE)); ((TextView)findViewById(R.id.tvDate)).setText(date); ((TextView)findViewById(R.id.tvTitle)).setText(message.get(TITLE)); final String text = "<html><body>" + UriEncoder.uriEncoded(message.get(CONTENT)) + "</body></html>"; final WebView webView = (WebView)findViewById(R.id.wvContent); webView.setNetworkAvailable(false); webView.loadData(text, "text/html", "utf-8"); } catch (NotFoundException e) { throw new RuntimeException(e); } } }
/******************************************************************************************************************* * ******************************************************************************************************************/ @Nonnull private void assertProperPresentationModel (final @Nonnull String indent, final @Nonnull PresentationModel pm, final @Nonnull MockDatum datum) { log.debug("assertProperPresentationModel() - {} {}, {}", new Object[] { indent, pm, datum }); pm.as(MockRole1.class); // must not throw AsException final MockRole2 role = pm.as(MockRole2.class); // must not throw AsException assertThat(role.getDatum(), is(sameInstance(datum))); final SimpleComposite<PresentationModel> composite = pm.as(SimpleComposite.class); final List<? extends PresentationModel> childrenPm = composite.findChildren().results(); final List<MockDatum> childrenData = datum.getChildren(); assertThat(childrenPm.size(), is(childrenData.size())); for (int i = 0; i < childrenPm.size(); i++) { assertProperPresentationModel(indent + " ", childrenPm.get(i), childrenData.get(i)); } } }
public void run() { log.info("renderImage({})", image); ivFullImage.setImage(image); // FIXME: can't use TextViewRenderable since ts* are TextSwitchers - enhance TextViewRenderable or create TextSwitcherRenderable final PlainTextRenderable stringRenderable = image.as(PlainTextRenderable); tsCaption.setText(stringRenderable.render("%s", DC_TITLE)); tsSource.setText(stringRenderable.render("Author: %s (publisher: %s)", Media.AUTHOR, DC_PUBLISHER)); tsLicense.setText(stringRenderable.render("%s", Media.RIGHTS)); } });
final TextView tvLanguages = (TextView)view.findViewById(R.id.tvLanguages); final Taxonomy taxonomy = taxonomyPM.as(Taxonomy.class); // FIXME: should work without this intermediate passage tvName.setText(taxonomy.as(Displayable.class).getDisplayName());