FileDocCategorySizeDatePackage
GraphEnvironment.javaAPI DocAndroid 5.1 API7229Thu Mar 12 22:22:30 GMT 2015android.filterfw

GraphEnvironment

public class GraphEnvironment extends MffEnvironment
A GraphEnvironment provides a simple front-end to filter graph setup and execution using the mobile filter framework. Typically, you use a GraphEnvironment in the following fashion: 1. Instantiate a new GraphEnvironment instance. 2. Perform any configuration, such as adding graph references and setting a GL environment. 3. Load a graph file using loadGraph() or add a graph using addGraph(). 4. Obtain a GraphRunner instance using getRunner(). 5. Execute the obtained runner. Note that it is possible to add multiple graphs and runners to a single GraphEnvironment.
hide

Fields Summary
public static final int
MODE_ASYNCHRONOUS
public static final int
MODE_SYNCHRONOUS
private android.filterfw.io.GraphReader
mGraphReader
private ArrayList
mGraphs
Constructors Summary
public GraphEnvironment()
Create a new GraphEnvironment with default components.

        super(null);
    
public GraphEnvironment(android.filterfw.core.FrameManager frameManager, android.filterfw.io.GraphReader reader)
Create a new GraphEnvironment with a custom FrameManager and GraphReader. Specifying null for either of these, will auto-create a default instance.

param
frameManager The FrameManager to use, or null to auto-create one.
param
reader The GraphReader to use for graph loading, or null to auto-create one. Note, that the reader will not be created until it is required. Pass null if you will not load any graph files.

        super(frameManager);
        mGraphReader = reader;
    
Methods Summary
public intaddGraph(android.filterfw.core.FilterGraph graph)
Add a graph to the environment. Consider using loadGraph() if you are loading a graph from a graph file.

param
graph The graph to add to the environment.
return
A unique ID for the added graph.

        GraphHandle graphHandle = new GraphHandle(graph);
        mGraphs.add(graphHandle);
        return mGraphs.size() - 1;
    
public voidaddReferences(java.lang.Object references)
Add graph references to resolve during graph reading. The references added here are shared among all graphs.

param
references An alternating argument list of keys (Strings) and values.

        getGraphReader().addReferencesByKeysAndValues(references);
    
public android.filterfw.core.FilterGraphgetGraph(int graphId)
Access a specific graph of this environment given a graph ID (previously returned from loadGraph() or addGraph()). Throws an InvalidArgumentException if no graph with the specified ID could be found.

param
graphId The ID of the graph to get.
return
The graph with the specified ID.

        if (graphId < 0 || graphId >= mGraphs.size()) {
            throw new IllegalArgumentException(
                "Invalid graph ID " + graphId + " specified in runGraph()!");
        }
        return mGraphs.get(graphId).getGraph();
    
public android.filterfw.io.GraphReadergetGraphReader()
Returns the used graph reader. This will create one, if a reader has not been set already.

        if (mGraphReader == null) {
            mGraphReader = new TextGraphReader();
        }
        return mGraphReader;
    
public android.filterfw.core.GraphRunnergetRunner(int graphId, int executionMode)
Get a GraphRunner instance for the graph with the specified ID. The GraphRunner instance can be used to execute the graph. Throws an InvalidArgumentException if no graph with the specified ID could be found.

param
graphId The ID of the graph to get.
param
executionMode The mode of graph execution. Currently this can be either MODE_SYNCHRONOUS or MODE_ASYNCHRONOUS.
return
A GraphRunner instance for this graph.

        switch (executionMode) {
            case MODE_ASYNCHRONOUS:
                return mGraphs.get(graphId).getAsyncRunner(getContext());

            case MODE_SYNCHRONOUS:
                return mGraphs.get(graphId).getSyncRunner(getContext());

            default:
                throw new RuntimeException(
                    "Invalid execution mode " + executionMode + " specified in getRunner()!");
        }
    
public intloadGraph(android.content.Context context, int resourceId)
Loads a graph file from the specified resource and adds it to this environment.

param
context The context in which to read the resource.
param
resourceId The ID of the graph resource to load.
return
A unique ID for the graph.

        // Read the file into a graph
        FilterGraph graph = null;
        try {
            graph = getGraphReader().readGraphResource(context, resourceId);
        } catch (GraphIOException e) {
            throw new RuntimeException("Could not read graph: " + e.getMessage());
        }

        // Add graph to our list of graphs
        return addGraph(graph);