Slideshow Applet
From Pointui
This example applet allows the user to configure a folder to fetch images from and will show a slideshow that can be automatically or manually navigated through.
Code (Slideshow.cs)
//Pointui C Script/*COPYRIGHTCopyright (c) 2008-2009 Pointui Pty Ltd, All Rights Reserved.ABN: 80 129 073 678This software is provided under license by Pointui Pty Ltd, and use thereofis subject to the licensing terms. Distribution of this software is on an"AS IS" basis, WITHOUT WARRANTY OF ANY KIND.This software is protected by Australian and international law.This software program may not be reproduced, transmitted, or disclosed tothird parties, in whole or in part, in any form or by any manner, electronicor mechanical, without the express written consent of Pointui Pty Ltd, exceptto the extent provided for by applicable license*/#region Appletclass SlideshowApplet : Applet
{//data table to store the list of files in the folder being displayedDataTable tblFiles;//timer that is used to swap to the next imageTimer ssUpdateTimer;//images for the slideshow bordersImage imgTop, imgLeft, imgRight, imgBottom, imgBottomFade;//current image being displayedImage imgScreenshot;//buttons for navigatingButton btnPlayPause, btnSettings, btnNext, btnPrev;int x, y, r, w, h;
int displayX, displayY, displayHeight, displayWidth;
String PictureFolderPath;
int PictureCount;
int CurrentPicture;
int ssInterval;
bool ControlsAreBright;
void ShowNextPicture(int offsetFromCurrent)
{//increment the picture indexCurrentPicture += offsetFromCurrent;
//is this after the last one?if (CurrentPicture >= PictureCount)
{//go back to startCurrentPicture = 0;
}//is this before the first oneif (CurrentPicture < 0)
{//wrap around to endCurrentPicture = PictureCount - 1;
}//try move to next image in list of filesbool anyMore;
anyMore = tblFiles.MoveTo(CurrentPicture);
if (anyMore)
{//was another image, so get the filenameString s;
tblFiles.GetValue("Filename", s);
//show this pictureShowPicture(s);
} else {
//no pictures in this folder, so show default imageShowPicture("Default.Image.jpg");
}}//event handler to swap to the next picturevoid ssUpdateTimer_OnTimer()
{ShowNextPicture(1);
}//click handler for when picture being shown is clickedvoid imgScreenshot_OnClick()
{//stop cycling through picturesssUpdateTimer.Stop();
//fade back in the navigation controlsControlsFade(false);
}//click handler for the settings buttonvoid btnSettings_OnClick()
{//show the screen to select a different folderScreenSelectFolder s;s.OnSelectFolder = ScreenSelectFolder_OnSelectFolder;
FlowStack.Branch(s);
}//handler for when folder selected on the ScreenSelectFoldervoid ScreenSelectFolder_OnSelectFolder(String FolderPath)
{String path;
//save the path in the Attributes collection of this appletAttributes.Add("FolderPath", FolderPath);
//save the folder path to file so if the user restarts their device it will still be the sameFile.Write("Settings.txt", Attributes);
//get files in the folderPath.GetFiles(FolderPath, tblFiles);
//make sure list doesn't include any directoriesPath.RemoveDirectories(tblFiles);
//how many pictures?PictureCount = tblFiles.GetCount();
CurrentPicture = -1;
ShowNextPicture(1);
}//click handler for the play buttonvoid btnPlayPause_OnClick()
{//start the picture cycle timerssUpdateTimer.StartSecondsTimer(ssInterval);
//hide the controlsControlsFade(true);
}//handler for the next picture buttonvoid btnNext_OnClick()
{//ensure auto cycling is stoppedssUpdateTimer.Stop();
//show next pictureShowNextPicture(1);
}//click handler for previous buttonvoid btnPrev_OnClick()
{//ensure auto cycling is stoppedssUpdateTimer.Stop();
//show previous pictureShowNextPicture(-1);
}//shows the picture specified in pathvoid ShowPicture(String path)
{//load the image and force it to the required dimensionsimgScreenshot.Surface.LoadFromFile(path, displayWidth, displayHeight);
//did it load?if (imgScreenshot.Surface.GetWidth() <= 0)
{//no, so use the default imageimgScreenshot.Surface.LoadFromFile("Default.Image.jpg");
}//make sure the image control is positioned correctlyimgScreenshot.SetBounds(displayX, displayY);
//and make sure screen is forced to updateFlagScreenChanged();
}//show or hide the navigation buttonsvoid ControlsFade(bool DirectionUp)
{int Start, Finish;
if (DirectionUp)
{if (ControlsAreBright == false)
{return;}ControlsAreBright = false;
Start = 100;
Finish = 10;
}else{if (ControlsAreBright == true)
{return;}ControlsAreBright = true;
Start = 10;
Finish = 100;
}//clear any previous animations that had been applied to these controls//because don't want parallel animations running and fighting each otherbtnPrev.AnimateClear();
btnPlayPause.AnimateClear();
btnSettings.AnimateClear();
btnNext.AnimateClear();
//fade the controls either in or out based on the Start/Finish valuesbtnPrev.AnimateFade(Start, Finish, 5);
btnPlayPause.AnimateFade(Start, Finish, 5, 1);
btnSettings.AnimateFade(Start, Finish, 5, 2);
btnNext.AnimateFade(Start, Finish, 5, 3);
}//this method is called once for the Applet when it is being initially loaded//and is where the controls for the applet are initialised, settings fetched from file etcvoid Load()
{x = 0;
y = 0;
w = GetWidth();
r = x + w;
//frame controls that will be displayed around the picturey = 0;
imgTop.Surface.LoadFromFile("Frame.Top.jif");
Controls.Add(imgTop);
imgTop.SetBounds(x, y);
y += imgTop.GetHeight();
imgLeft.Surface.LoadFromFile("Frame.Left.jif");
Controls.Add(imgLeft);
imgLeft.SetBounds(x, y);
imgRight.Surface.LoadFromFile("Frame.Right.jif");
Controls.Add(imgRight);
r -= imgRight.GetWidth();
imgRight.SetBounds(r, y);
y += imgLeft.GetHeight();
imgBottom.Surface.LoadFromFile("Frame.Bottom.jif");
Controls.Add(imgBottom);
imgBottom.SetBounds(x, y);
//determine the display area limits - how much space is there to show the slideshow pictures?displayHeight = GetHeight();
displayHeight -= ((imgTop.GetHeight() + imgBottom.GetHeight()) / 2);
displayWidth = GetWidth();
displayWidth -= ((imgLeft.GetWidth() + imgRight.GetWidth()) / 2);
displayX = imgLeft.GetWidth() / 2;
displayY = imgTop.GetHeight() / 2;
//load the default pictureimgScreenshot.Surface.LoadFromFile("Default.Image.jpg", displayWidth, displayHeight);
Controls.Add(imgScreenshot);
imgScreenshot.SendToBack();
imgScreenshot.SetBounds(displayX, displayY);
imgScreenshot.SetTabStop(true);
imgScreenshot.OnClick = imgScreenshot_OnClick;
x = 0;
//init the buttons//load the images for normal and selected statesbtnPrev.ImageSelected.LoadFromFile("Button.Previous.Selected.jif");
btnPrev.Image.LoadFromFile("Button.Previous.jif");
//add this button to be a direct child of the appletControls.Add(btnPrev);
//position ity = GetHeight() - btnPrev.GetHeight();
btnPrev.SetBounds(x, y);
//provide an OnClick event handler so can respond to when the user clicks the buttonbtnPrev.OnClick = btnPrev_OnClick;
x += btnPrev.GetWidth();
btnPlayPause.ImageSelected.LoadFromFile("Button.Right.Arrow.Selected.jif");
btnPlayPause.Image.LoadFromFile("Button.Right.Arrow.jif");
Controls.Add(btnPlayPause);
btnPlayPause.SetBounds(x, y);
x += btnPlayPause.GetWidth();
btnPlayPause.OnClick = btnPlayPause_OnClick;
btnSettings.ImageSelected.LoadFromFile("Button.Settings.Selected.jif");
btnSettings.Image.LoadFromFile("Button.Settings.jif");
Controls.Add(btnSettings);
btnSettings.SetBounds(x, y);
x += btnSettings.GetWidth();
btnSettings.OnClick = btnSettings_OnClick;
btnNext.ImageSelected.LoadFromFile("Button.Next.Selected.jif");
btnNext.Image.LoadFromFile("Button.Next.jif");
Controls.Add(btnNext);
btnNext.SetBounds(x, y);
x += btnNext.GetWidth();
btnNext.OnClick = btnNext_OnClick;
//when playing go to next picture every 3 secondsssInterval = 3;
//set the event handler for OnTimerssUpdateTimer.OnTimer = ssUpdateTimer_OnTimer;
ControlsAreBright = true;
PictureCount = 0;
//load the settings into the Attributes collectionFile.Read("Settings.txt", Attributes);
//read the last folder that was being viewedPictureFolderPath = Attributes.Item("FolderPath");
//is there are path previously saved?if (PictureFolderPath.GetLength() > 0)
{//yes, so make it load right nowScreenSelectFolder_OnSelectFolder(PictureFolderPath);
}}//this method is called when the applet loses focus for some reason such as the user//sliding to another applet, or going off to another screen after having this applet visiblevoid Deactivated()
{//stop the update timer - no point loading more images if the user can't see themssUpdateTimer.Stop();
//show controls againControlsFade(false);
}}#endregion#region Screens//screen that allows browsing through file system to select a folderclass ScreenSelectFolder : FileExplorerScreen
{//title of the screenLabel lblTitle;//initialize the screenvoid Load()
{//init the title labelControls.Add(lblTitle);
SetTitlePosition(lblTitle);
//set the properties for this FileExplorerScreenSetBasePath("\\");
SetDisplayFileExt(true);
SetMode("SelectFolder");
}//event to raise when the user selects a folderEvent OnSelectFolder;
//this method is called by the FileExplorerScreen when the user selects a foldervoid FolderSelected(String filename)
{//raise the eventOnSelectFolder(filename);
//return from the current screenFlowStack.Return();
}//this method is called by the FileExplorerScreen when the user navigates to each folder//while trying to select onevoid FolderChanged(String folder)
{//get just the current folder name from the full pathString s;
s = Path.GetFilename(folder);
//are we at root?if (s.GetLength() <= 0)
{s = "Choose Slideshow Folder";
}//set the screen titlelblTitle.SetText(s);
}}#endregion
Remarks
Line 20: This slideshow applet inherits from the Applet class. Notice the name of the class "SlideshowApplet". All applet classes must be named with the word "Applet" at the end. Because this applet is called "Slideshow" there needs to be a corresponding folder in the file system (ApplcationDirectory)\AppletRibbon\Slideshow. All files including the Slideshow.cs script file, images, and any other configuration files like xml files must sit in this folder.
