This question is answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 16 - Pages: 2 [ 1 2 | Next ] - Last Post: 3 Dec 23, 19:59 Last Post By: davidekholm
davidekholm

Posts: 3,451
Registered: 18-Oct-2002
New APIs in jAlbum 33.2
Posted: 1 Dec 23, 18:10
 
  Click to reply to this thread Reply
Attachment MinimalTest.jaskin (256.3 KB)
jAlbum 33.2 has a few new APIs tailored to help skin developers:
  • Skin developers can now add an "earlyinit" file that will be called at an earlier stage of album builds than "init". This allows skins to filter-out file types and categories that aren't supported.
  • New classes " CategoryFilter ", " RejectCounterFilter " to support rejecting/ignoring certain file types
  • The Paginator class now supports including/excluding distinct file types as well as categories

Examples speak louder than words. See the attached "MinimalTest" and its "earlyinit.bsh" and "init.bsh" files. This modifiation to Minimal is set to ignore PDF files, PNG files and any audio files, just to demonstrate this mechanism. If any such files are found within the project, they are ignored, and a warning notification pops up during the album build.

Let's focus on the most important parts of "earlyinit.bsh" and "init.bsh" here:

earylinit.bsh:
import se.datadosen.jalbum.*;
 
/**
 * Demo of how to exclude certain (supposedly not supported) file types from the gallery
 * In this demo we're excluding PDF, PNG and audio files
 * This also demos how to count the number of unsupported (rejected) files
 * In init.bsh, jAlbum has already done the counting, and the result is presented to the user
 * as a notification, in case files has been rejected.
 */
CategoryFilter categoryFilter = new CategoryFilter().exclude("pdf", "png").exclude(Category.audio);
rejectCounter = new RejectCounterFilter(categoryFilter);
 
/**
 * Install filter chain inside the engine's album object factory
 */
factory.setFilter(rejectCounter);

init.bsh:

/**
 * Before calling init.bsh here, jAlbum has counted the number of objects in the gallery
 * Prior to calling init.bsh, jAlbum has called earlyinit.bsh, where a filter
 * and counter for unsupported file types was set up (rejectCounter).
 * That counter can now be checked here, and user warned
 */
if (rejectCounter.getTotalCount() > 0) {
	System.out.println("Skipped types: " + rejectCounter);
	engine.fireWarning("PDF, PNG and audio files are not supported and have been skipped");
}


The CategoryFilter works in the same manner as the Paginator. Just chain calls to specify what files to include/exclude. To "simply" ignore PDF files and assuming that you don't care about informing the user about that, just put the following within earlyinit.bsh (or .js or .groovy):
factory.setFilter(new CategoryFilter().exclude("pdf"));


Let's assume that your skin only supports images, videos and the "PDF" "other" type but no folder support. Here's how to set that up:

factory.setFilter(new CategoryFilter().include(Category.image, Category.video).include("pdf"));


Here's a skin that supports everything but folders:
factory.setFilter(new CategoryFilter().exclude(Category.folder));

... or even shorter:
factory.setFilter(new CategoryFilter().nodirs();

The following variables ONLY are available in earlyinit:
engine, albumEngine, ctx, window, window, context, factory, root

JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 1 Dec 23, 19:25   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Worked like a champ on my very first attempt, in Atom. That's a "slide page" skin, which is where this really comes in handy, because of the reliance on core-provided things like "next page." :)

The warning mechanism is nice, too - not too obtrusive, but lets the user know that some of his precious objects have been kicked to the curb. ;)
RobM

Posts: 3,741
Registered: 4-Aug-2006
Re: New APIs in jAlbum 33.2
Posted: 1 Dec 23, 21:16   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Works well, tried changing skins and back, all ok.

It might be with updating the alert to say the objects are not supported by the 'skin name'. Just so some users don't think jAlbum doesn't support them.
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 1 Dec 23, 21:36   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Attachment ss012100.png (47.2 KB)
RobM wrote:
It might be with updating the alert to say the objects are not supported by the 'skin name'. Just so some users don't think jAlbum doesn't support them.

Easy enough - screenshot.

Tempting to have a little fun with that. "You miserable pile of parrot droppings! You cloth-eared bint! Have you lost your mind?!!"
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 1 Dec 23, 21:37   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Now that we have earlyinit.groovy, when do we get latefinally.groovy? For symmetry. ;)
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 01:02   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
I haven't done any rigorous testing, but getting rid of the tree traversal that looked for unsupported AO's has noticeably reduced the "initializing" time during the album build.

Now, if I could just eliminate the routine that tags all GIF's as "use original," things would really snap, crackle, and pop. ;)
davidekholm

Posts: 3,451
Registered: 18-Oct-2002
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 13:11   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Great that you like it :-). I shall look into the GIF issue pretty soon now. You're basically saying that we can simply "use original" for GIF files. I think that's reasonable.
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 13:36   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Great that you like it :-).

I always like being able to hit the DEL key on chunks of clumsy, inefficient code. :)

I shall look into the GIF issue pretty soon now. You're basically saying that we can simply "use original" for GIF files. I think that's reasonable.

The argument for it is pretty basic. The only reason users add GIF's is for their animation. If there's a non-animated GIF, converting it to PNG sometimes actually produces a larger file, so that's pointless. There's never a penalty for using the original.

Still need JPG thumbnails, however. Animated GIF's tend to be on the large side - not a problem for a single slide image, but for a page full of thumbnails, that could be a real slow loader.
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 15:32   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
BTW, an interesting side-note. The WebP format allows for animation. I converted some of my animated GIF's to WebP (using an online converter), and the file sizes drop by about 50%, with no visible loss of image quality.

No way for the core or a skin to take care of that however. We can't do the conversion (AFAIK), and if the user adds an animated WebP to a project, we can't detect that it's animated, and should not be scaled. The user would still have to manually mark it as "use original."

ETA: There are ways to figure out if a WebP image is animated, but talk about adding a lot of overhead to the app! Yikes.
davidekholm

Posts: 3,451
Registered: 18-Oct-2002
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 16:05   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
Yes, I'll leave animated WebP images for now.
Now there's a service update: 33.2.1 which sets "Use original" for GIFs. Check it out by doing a core update. Let me know if I've broken anything ;-)

This service release also fixes an old bug with "Use original" and Variants. Variants should basically not be used for the closeups of images that have "Use originals" checked. This broke "Minimal" for instance.

(Tiger and Plain used different APIs and have never been affected by this bug.)
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 16:35   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Now there's a service update: 33.2.1 which sets "Use original" for GIFs. Check it out by doing a core update. Let me know if I've broken anything ;-)

Like this cat, I think you've nailed it.



This service release also fixes an old bug with "Use original" and Variants. Variants should basically not be used for the closeups of images that have "Use originals" checked. This broke "Minimal" for instance.

(Tiger and Plain used different APIs and have never been affected by this bug.)


Guess which other skins have never been affected by this bug. ;)

My only complaint about the new "exclusion" and "GIF" routines is that I'll have to specify the minimum jAlbum version for my skins as 33.2.1. Aesthetically unpleasing. Less objectionable would be 33.3. Even better, 34. :)
RobM

Posts: 3,741
Registered: 4-Aug-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 20:59   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
One place where gifs are not used is webLocations, the image is converted.
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 21:35   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
One place where gifs are not used is webLocations, the image is converted.

But that's just a representing thumbnail, right? Thumbnails need to be converted. This change is about only the slide images.
RobM

Posts: 3,741
Registered: 4-Aug-2006
Re: New APIs in jAlbum 33.2
Posted: 2 Dec 23, 23:42   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
RobM wrote:
One place where gifs are not used is webLocations, the image is converted.

But that's just a representing thumbnail, right? Thumbnails need to be converted. This change is about only the slide images.

I believe some skins, not mine, have webLocation objects show a slide page, which then links to the location. The slide image is converted as well as the thumbnail.
JeffTucker

Posts: 8,109
Registered: 31-Jan-2006
Re: New APIs in jAlbum 33.2
Posted: 3 Dec 23, 00:00   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
RobM wrote:
I believe some skins, not mine, have webLocation objects show a slide page, which then links to the location. The slide image is converted as well as the thumbnail.

None of mine, either. I don't think any of Laza's skins commit that sin.

I think it's probably safe to overlook this "gap" in the implementation. ;)
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums