MAFLogViewer

The MAFLogViewer component provides a standard UI to show log entries in an application. MAFLogViewer uses SDMLogger or MAFLogger as a source, and shows the entries from these loggers. It can also send the log entries to a predefined recipient. MAFLogViewer is built from skinnable components.

Dependencies and Project Setup

MAFLogViewer is a complex reusable control, which means that it is built on top of simple controls, such as MAFActionBar and MAFListView. MAFLogViewer depends on the MAFUIControls library and the MAFLogger.

These MAF libraries are required:
  • com.sap.mobile.maf.ui.android/MAFUIComponents
  • com.sap.mobile.maf.tools.android/MAFLogger
Required android libraries containing the resources for MAFUIcomponents: mafuicomponents-res.

Presenting a View

MAFLogViewer is an extension of a simple LinearLayout. This layout contains MAFActionBar and a ListView that shows the log entries. To show this layout in an activity, use:
MAFLogViewer logViewer = new MAFLogViewer( this, logger );
        setContentView(logViewer); 
To initialize the MAFLogViewer from a layout XML, use:
<com.sap.maf.uicontrols.logviewer.MAFLogViewer 
xmlns:x="http://schemas.sap.com/maf/2011/ux"           
           android:id="@+id/logviewer"
           android:layout_width="match_parent"         
          android:layout_height="match_parent"         
          x:email = "sap@sap.com"         
          x:subject = "Test LogViewer"
          x:title = "Log Test title"> 

Setting the Source for MAFLogViewer

MAFLogViewer can show log entries from SDMLogger, which is the standard SAP Mobile Platform logger. To set the source for MAFLogViewer, use:
  • The constructor where you can set an SDMLogger instance – public MAFLogViewer(Context context, SDMLogger logger)
  • The setter API – public void setLogger(SDMLogger logger)
  • SDMLogger  – to show (??) log entries from MAFLogger:
If you initialize the logger from a layout XML, set SDMLogger as a source logger explicitly in code after the inflation:
setContentView(R.layout.logviewer); MAFLogViewer logViewer = (MAFLogViewer)
        findViewById(R.id.logviewer); logViewer.setLogger(logger) 

If there is a source set, but you call the setLogger() API with a new SDMLogger instance, the new instance is used, and the old entries are dropped.

If you present the MAFLogViewer without an SDMLogger instance, it creates an instance and enters one log entry with error severity: No logger was set.

Customization of the MAFLogViewer

Customization options for MAFLogViewer include skinning, setting the title and the navigation icon, and defining the email recipient and subject for sending log entries.
  • MAFLogViewer uses skinning from the ActionBar and ListView TargetTypes, which you can use to create new flavors with.
  • You can set a predefined e-mail recipient for log entries in two ways:
    • Programmatically, using the public void setEmail(String email) API.
    • If MAFLogViewer is inflated from a layout XML, set the e-mail recipient with the x:email = sap@sap.com attribute, where x is the following SAP namespace: xmlns:x=http://schemas.sap.com/maf/2011/ux
  • You can set a predefined e-mail subject for log entries in two ways:
    • Programmatically, using the public void setSubject(String subject) API.
    • If MAFLogViewer is inflated from a layout XML, set the e-mail subject with the x:subject = "Test LogViewer" attribute, where x is the following SAP namespace: xmlns:x=http://schemas.sap.com/maf/2011/ux

      The default subject is Log Entries, which is localized for supported languages.

  • You can set a title for MAFLogViewer that appears on the ActionBar in two ways:
    • Programmatically, using the public void setTitle(String title) API
    • If MAFLogViewer is inflated from a layout XML, set the title with the x:title = "Log Test title" attribute, where x is the following SAP namespace: xmlns:x=http://schemas.sap.com/maf/2011/ux

      The default title for the log viewer is Log Viewer, which is localized for supported languages.

  • The default navigation icon on MAFLogViewer is the application icon. To change the icon, use the public MAFLogViewer(Context context, SDMLogger logger, String flavor, Bitmap bitmap) constructor.

Sending Logs

MAFLogViewer supports sending log entries to a predefined e-mail address. If there is no e-mail set, the user must use an e-mail application.

To send the logs, tap the action button on the right side of the action bar. This triggers a sending intent, where the content’s MIME type is message/rfc822. A list of apps that can handle these messages, such as Gmail or Exchange, is presented.

After an app is selected, MAFLogViewer passes the predefined e-mail address, subject, and content to the application, which, if configured properly, opens a new e-mail message that contains the sent content.