Working with Dashboard

Operating system requirements: iOS 5.0 or later.

Mobile device: iPad.

Description

This example describes some methods of working with a dashboard. After starting the example the following operations are executed:

Source Code

Executing the example requires to place the following code instead of the executeExample method of the ViewController class (see the Displaying of Dashboard section):

// Executes custom example placed in the body of this method
-(void) executeExample {
    // Get dashboard controller
    MADashboardReportViewController *dashboard = (MADashboardReportViewController *)m_controller;
    // Get dashboard controller delegate
    MADashboardReportDelegateImpl *delegate = (MADashboardReportDelegateImpl*)[dashboard delegate];
    // Determine path to resources
    NSArray *resourcesPaths = [delegate dashboardResourcesPath];
    // Determine MIME types of resources
    NSArray *resourcesMimesTypes = [delegate dashboardResourcesMimeTypes];
    // Determine path to XML file
    NSString *xmlPath;
    for (int i = 0; i < [resourcesMimesTypes count]; i++) {
        if ([(NSString *)[resourcesMimesTypes objectAtIndex:i] isEqualToString:@"application/xml"]) {
            xmlPath = (NSString *)[resourcesPaths objectAtIndex:i];
        }
    }
    // Get XML file data
    NSData *xmlData = [NSData dataWithContentsOfFile:xmlPath];
    APXMLParserObject *structure = [APXMLParser parseXML:xmlData];
    
    // Create a dashboard
    APKap *kap = [APKap alloc];
    [kap initWithParserObject:structure delegate: dashboard];
    
    if ([[kap compositeBlocks] count] == 0) {
        kap = [dashboard report];
        [kap setDelegate: dashboard];
    }
    
    // Get dashboard delegate
    MADashboardReportViewController *kapDelegate = (MADashboardReportViewController *)[kap delegate];
    [kapDelegate setValue:kap forKey:@"m_report"];
    // Get composite block dictionary
    NSMutableDictionary *compositeBlocks = [kap compositeBlocks];
    if ([[compositeBlocks allKeys] count] > 0) {
        // Get last composite block key
        NSString *blockKey = [[compositeBlocks allKeys]
                              objectAtIndex:([compositeBlocks count] - 1)];
        // Set key for the block in full-screen mode
        [kap setFullScreenBlockKey:blockKey];
        // Get last composite block title
        NSString *title = [kap titleForCompositeBlock:blockKey];
        if (title != nil) {
            // Add title to dictionary of composite block titles
            [[kap dataViewsTitles] setObject:title forKey:blockKey];
            NSLog(@"Last composite block title: %@", title);
        }
        // Enable use of full-screen mode
        [kap setIsfullScreenEnabled:YES];
        // Enable switching of dashboard to slideshow mode
        [kap setSlideMode:YES];
        // Refresh dashboard
        [self refreshKap:kap];
    }
}
// Refresh dashboard
-(void)refreshKap: (APKap*) kap {
    // Get object for working with container split into two data views
    SplitViewController *split = (SplitViewController*)[m_controller splitViewController];
    if([kap isfullScreenEnabled]) {
        // Display controls for full-screen mode
        [kap showFullscreenCompositeBlockWithKey: [kap fullScreenBlockKey]];
        // Display dimension panel
        [split setFirstViewVisible:YES];
        
        // Get last composite block
        APCompositeBlock *compositeBlock = [[kap dataViews] objectForKey:[kap fullScreenBlockKey]];
        // Display this block in full-screen mode
        [split setSecondView:[compositeBlock view]];
    }
    if ([kap slideMode]) {
        // Create a screenshot of the current window with 1 second delay
        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1.0 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
            // Create a screenshot
            UIImage *image = [m_controller screenshot];
            MADashboardReportDelegateImpl *delegate = (MADashboardReportDelegateImpl*)[m_controller delegate];
            // Set screenshot
            [delegate setScreenshot:UIImagePNGRepresentation(image)];
            UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
            // Display screenshot in the right part of the window
            [split setSecondView: imageView];
        });
    }
}

After executing the example the dashboard is displayed in full-screen mode and slideshow mode. The left part of the report displays the dimension panel, the right part displays the previously created dashboard report screenshot.

The development environment console displays the last composite block title:

Last composite block title: GDP per capita, PPP (constant 2005 international $)

The result is not changed after replacing the code string:

[kap showFullscreenCompositeBlockWithKey: [kap fullScreenBlockKey]];

with the following string:

[(MADashboardReportViewController *)[kap delegate] showControlsForFullscreenBlock:[kap fullScreenBlockKey]];

Then delete the dimension panel located to the left. To do this, add the following code string to the executeExample method contents:

[kap dismissFullscreenCompositeBlock];

After repeated starting the example the side panel is hidden. The identical result is obtained after executing any of the given code strings:

// Inform about exit from full-screen mode of composite block display
[kap fullscreenViewDismissed];
[kapDelegate dismissControlsForFullscreenBlock];
[kapDelegate hideControlsForFullscreenBlock:blockKey];

After executing any of the given code strings the dimension panel is hidden.

See also:

Example of Component Use