while (phiCursor.advance()) {
                    LocationIdentity key = phiCursor.getKey();
                    PhiNode phi = phiCursor.getValue();
                    phi.initializeValueAt(endIndex, ValueNodeUtil.asNode(endStateCursor.getValue().getLastLocationAccess(key)));
                }

package org.graalvm.compiler.phases.common;

import static org.graalvm.compiler.graph.Graph.NodeEvent.NODE_ADDED;
import static org.graalvm.compiler.graph.Graph.NodeEvent.ZERO_USAGES;
import static org.graalvm.word.LocationIdentity.any;
import java.util.EnumSet;
import java.util.Iterator;
import java.util.List;
import org.graalvm.collections.EconomicMap;
import org.graalvm.collections.EconomicSet;
import org.graalvm.collections.Equivalence;
import org.graalvm.collections.UnmodifiableMapCursor;
import org.graalvm.compiler.core.common.cfg.Loop;
import org.graalvm.compiler.debug.DebugCloseable;
import org.graalvm.compiler.graph.Graph.NodeEventScope;
import org.graalvm.compiler.graph.Node;
import org.graalvm.compiler.nodes.AbstractBeginNode;
import org.graalvm.compiler.nodes.AbstractMergeNode;
import org.graalvm.compiler.nodes.FixedNode;
import org.graalvm.compiler.nodes.LoopBeginNode;
import org.graalvm.compiler.nodes.LoopEndNode;
import org.graalvm.compiler.nodes.LoopExitNode;
import org.graalvm.compiler.nodes.PhiNode;
import org.graalvm.compiler.nodes.ProxyNode;
import org.graalvm.compiler.nodes.ReturnNode;
import org.graalvm.compiler.nodes.StartNode;
import org.graalvm.compiler.nodes.StructuredGraph;
import org.graalvm.compiler.nodes.ValueNodeUtil;
import org.graalvm.compiler.nodes.WithExceptionNode;
import org.graalvm.compiler.nodes.StructuredGraph.StageFlag;
import org.graalvm.compiler.nodes.calc.FloatingNode;
import org.graalvm.compiler.nodes.cfg.Block;
import org.graalvm.compiler.nodes.cfg.ControlFlowGraph;
import org.graalvm.compiler.nodes.cfg.HIRLoop;
import org.graalvm.compiler.nodes.memory.FloatableAccessNode;
import org.graalvm.compiler.nodes.memory.FloatingAccessNode;
import org.graalvm.compiler.nodes.memory.FloatingReadNode;
import org.graalvm.compiler.nodes.memory.MemoryAccess;
import org.graalvm.compiler.nodes.memory.MemoryAnchorNode;
import org.graalvm.compiler.nodes.memory.MemoryKill;
import org.graalvm.compiler.nodes.memory.MemoryMap;
import org.graalvm.compiler.nodes.memory.MemoryMapNode;
import org.graalvm.compiler.nodes.memory.MemoryPhiNode;
import org.graalvm.compiler.nodes.memory.MultiMemoryKill;
import org.graalvm.compiler.nodes.memory.ReadNode;
import org.graalvm.compiler.nodes.memory.SingleMemoryKill;
import org.graalvm.compiler.nodes.util.GraphUtil;
import org.graalvm.compiler.phases.Phase;
import org.graalvm.compiler.phases.common.util.EconomicSetNodeEventListener;
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator;
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.LoopInfo;
import org.graalvm.compiler.phases.graph.ReentrantNodeIterator.NodeIteratorClosure;
import org.graalvm.word.LocationIdentity;

public class FloatingReadPhase extends Phase {

    private boolean createFloatingReads;

    private boolean createMemoryMapNodes;

    public static class MemoryMapImpl implements MemoryMap {

        private final EconomicMap<LocationIdentity, MemoryKill> lastMemorySnapshot;

        public MemoryMapImpl(MemoryMapImpl memoryMap) {
            lastMemorySnapshot = EconomicMap.create(Equivalence.DEFAULT, memoryMap.lastMemorySnapshot);
        }

        public MemoryMapImpl(StartNode start) {
            this();
            lastMemorySnapshot.put(any(), start);
        }

        public MemoryMapImpl() {
            lastMemorySnapshot = EconomicMap.create(Equivalence.DEFAULT);
        }

        @Override
        public MemoryKill getLastLocationAccess(LocationIdentity locationIdentity) {
            MemoryKill lastLocationAccess;
            if (locationIdentity.isImmutable()) {
                return null;
            } else {
                lastLocationAccess = lastMemorySnapshot.get(locationIdentity);
                if (lastLocationAccess == null) {
                    lastLocationAccess = lastMemorySnapshot.get(any());
                    assert lastLocationAccess != null;
                }
                return lastLocationAccess;
            }
        }

        @Override
        public Iterable<LocationIdentity> getLocations() {
            return lastMemorySnapshot.getKeys();
        }

        public EconomicMap<LocationIdentity, MemoryKill> getMap() {
            return lastMemorySnapshot;
        }
    }

    public FloatingReadPhase() {
        this(true, false);
    }

    /**
     * @param createFloatingReads specifies whether {@link FloatableAccessNode}s like
     *            {@link ReadNode} should be converted into floating nodes (e.g.,
     *            {@link FloatingReadNode}s) where possible
     * @param createMemoryMapNodes a {@link MemoryMapNode} will be created for each return if this
     *            is true
     */
    public FloatingReadPhase(boolean createFloatingReads, boolean createMemoryMapNodes) {
        this.createFloatingReads = createFloatingReads;
        this.createMemoryMapNodes = createMemoryMapNodes;
    }

    @Override
    public float codeSizeIncrease() {
        return 1.50f;
    }

    /**
     * Removes nodes from a given set that (transitively) have a usage outside the set.
     */
    private static EconomicSet<Node> removeExternallyUsedNodes(EconomicSet<Node> set) {
        boolean change;
        do {
            change = false;
            for (Iterator<Node> iter = set.iterator(); iter.hasNext(); ) {
                Node node = iter.next();
                for (Node usage : node.usages()) {
                    if (!set.contains(usage)) {
                        change = true;
                        iter.remove();
                        break;
                    }
                }
            }
        } while (change);
        return set;
    }

    protected void processNode(FixedNode node, EconomicSet<LocationIdentity> currentState) {
        if (node instanceof SingleMemoryKill) {
            processIdentity(currentState, ((SingleMemoryKill) node).getKilledLocationIdentity());
        } else if (node instanceof MultiMemoryKill) {
            for (LocationIdentity identity : ((MultiMemoryKill) node).getKilledLocationIdentities()) {
                processIdentity(currentState, identity);
            }
        }
    }

    private static void processIdentity(EconomicSet<LocationIdentity> currentState, LocationIdentity identity) {
        if (identity.isMutable()) {
            currentState.add(identity);
        }
    }

    protected void processBlock(Block b, EconomicSet<LocationIdentity> currentState) {
        for (FixedNode n : b.getNodes()) {
            processNode(n, currentState);
        }
    }

    private EconomicSet<LocationIdentity> processLoop(HIRLoop loop, EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops) {
        LoopBeginNode loopBegin = (LoopBeginNode) loop.getHeader().getBeginNode();
        EconomicSet<LocationIdentity> result = modifiedInLoops.get(loopBegin);
        if (result != null) {
            return result;
        }
        result = EconomicSet.create(Equivalence.DEFAULT);
        for (Loop<Block> inner : loop.getChildren()) {
            result.addAll(processLoop((HIRLoop) inner, modifiedInLoops));
        }
        for (Block b : loop.getBlocks()) {
            if (b.getLoop() == loop) {
                processBlock(b, result);
            }
        }
        modifiedInLoops.put(loopBegin, result);
        return result;
    }

    @Override
    @SuppressWarnings("try")
    protected void run(StructuredGraph graph) {
        EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops = null;
        if (graph.hasLoops()) {
            modifiedInLoops = EconomicMap.create(Equivalence.IDENTITY);
            ControlFlowGraph cfg = ControlFlowGraph.compute(graph, true, true, false, false);
            for (Loop<?> l : cfg.getLoops()) {
                HIRLoop loop = (HIRLoop) l;
                processLoop(loop, modifiedInLoops);
            }
        }
        EconomicSetNodeEventListener listener = new EconomicSetNodeEventListener(EnumSet.of(NODE_ADDED, ZERO_USAGES));
        try (NodeEventScope nes = graph.trackNodeEvents(listener)) {
            ReentrantNodeIterator.apply(new FloatingReadClosure(modifiedInLoops, createFloatingReads, createMemoryMapNodes), graph.start(), new MemoryMapImpl(graph.start()));
        }
        for (Node n : removeExternallyUsedNodes(listener.getNodes())) {
            if (n.isAlive() && n instanceof FloatingNode) {
                n.replaceAtUsages(null);
                GraphUtil.killWithUnusedFloatingInputs(n);
            }
        }
        if (createFloatingReads) {
            assert graph.isBeforeStage(StageFlag.FLOATING_READS);
            graph.setAfterStage(StageFlag.FLOATING_READS);
        }
    }

    public static MemoryMapImpl mergeMemoryMaps(AbstractMergeNode merge, List<? extends MemoryMap> states) {
        MemoryMapImpl newState = new MemoryMapImpl();
        EconomicSet<LocationIdentity> keys = EconomicSet.create(Equivalence.DEFAULT);
        for (MemoryMap other : states) {
            keys.addAll(other.getLocations());
        }
        assert checkNoImmutableLocations(keys);
        for (LocationIdentity key : keys) {
            int mergedStatesCount = 0;
            boolean isPhi = false;
            MemoryKill merged = null;
            for (MemoryMap state : states) {
                MemoryKill last = state.getLastLocationAccess(key);
                if (isPhi) {
                    // Fortify: Suppress Null Deference false positive (`isPhi == true` implies
                    ((MemoryPhiNode) merged).addInput(ValueNodeUtil.asNode(last));
                } else {
                    if (merged == last) {
                        // nothing to do
                    } else if (merged == null) {
                        merged = last;
                    } else {
                        MemoryPhiNode phi = merge.graph().addWithoutUnique(new MemoryPhiNode(merge, key));
                        for (int j = 0; j < mergedStatesCount; j++) {
                            phi.addInput(ValueNodeUtil.asNode(merged));
                        }
                        phi.addInput(ValueNodeUtil.asNode(last));
                        merged = phi;
                        isPhi = true;
                    }
                }
                mergedStatesCount++;
            }
            newState.getMap().put(key, merged);
        }
        return newState;
    }

    public static boolean nodeOfMemoryType(Node node) {
        return !(node instanceof MemoryKill) || (node instanceof SingleMemoryKill ^ node instanceof MultiMemoryKill);
    }

    private static boolean checkNoImmutableLocations(EconomicSet<LocationIdentity> keys) {
        keys.forEach(t -> {
            assert t.isMutable();
        });
        return true;
    }

    public static class FloatingReadClosure extends NodeIteratorClosure<MemoryMapImpl> {

        private final EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops;

        private boolean createFloatingReads;

        private boolean createMemoryMapNodes;

        public FloatingReadClosure(EconomicMap<LoopBeginNode, EconomicSet<LocationIdentity>> modifiedInLoops, boolean createFloatingReads, boolean createMemoryMapNodes) {
            this.modifiedInLoops = modifiedInLoops;
            this.createFloatingReads = createFloatingReads;
            this.createMemoryMapNodes = createMemoryMapNodes;
        }

        @Override
        protected MemoryMapImpl processNode(FixedNode node, MemoryMapImpl state) {
            if (node instanceof LoopExitNode) {
                final LoopExitNode loopExitNode = (LoopExitNode) node;
                final EconomicSet<LocationIdentity> modifiedInLoop = modifiedInLoops.get(loopExitNode.loopBegin());
                final boolean anyModified = modifiedInLoop.contains(LocationIdentity.any());
                state.getMap().replaceAll((locationIdentity, memoryNode) -> (anyModified || modifiedInLoop.contains(locationIdentity)) ? ProxyNode.forMemory(memoryNode, loopExitNode, locationIdentity) : memoryNode);
            }
            if (node instanceof MemoryAnchorNode) {
                processAnchor((MemoryAnchorNode) node, state);
                return state;
            }
            if (node instanceof MemoryAccess) {
                processAccess((MemoryAccess) node, state);
            }
            if (createFloatingReads && node instanceof FloatableAccessNode) {
                processFloatable((FloatableAccessNode) node, state);
            }
            if (node instanceof SingleMemoryKill) {
                processCheckpoint((SingleMemoryKill) node, state);
            } else if (node instanceof MultiMemoryKill) {
                processCheckpoint((MultiMemoryKill) node, state);
            }
            assert nodeOfMemoryType(node) : node;
            if (createMemoryMapNodes && node instanceof ReturnNode) {
                ((ReturnNode) node).setMemoryMap(node.graph().unique(new MemoryMapNode(state.getMap())));
            }
            return state;
        }

        /**
         * Improve the memory graph by re-wiring all usages of a {@link MemoryAnchorNode} to the
         * real last access location.
         */
        private static void processAnchor(MemoryAnchorNode anchor, MemoryMapImpl state) {
            for (Node node : anchor.usages().snapshot()) {
                if (node instanceof MemoryAccess) {
                    MemoryAccess access = (MemoryAccess) node;
                    if (access.getLastLocationAccess() == anchor) {
                        MemoryKill lastLocationAccess = state.getLastLocationAccess(access.getLocationIdentity());
                        assert lastLocationAccess != null;
                        access.setLastLocationAccess(lastLocationAccess);
                    }
                }
            }
            if (anchor.hasNoUsages()) {
                anchor.graph().removeFixed(anchor);
            }
        }

        private static void processAccess(MemoryAccess access, MemoryMapImpl state) {
            LocationIdentity locationIdentity = access.getLocationIdentity();
            if (!locationIdentity.equals(LocationIdentity.any())) {
                MemoryKill lastLocationAccess = state.getLastLocationAccess(locationIdentity);
                access.setLastLocationAccess(lastLocationAccess);
            }
        }

        private static void processCheckpoint(SingleMemoryKill checkpoint, MemoryMapImpl state) {
            processIdentity(checkpoint.getKilledLocationIdentity(), checkpoint, state);
        }

        private static void processCheckpoint(MultiMemoryKill checkpoint, MemoryMapImpl state) {
            for (LocationIdentity identity : checkpoint.getKilledLocationIdentities()) {
                processIdentity(identity, checkpoint, state);
            }
        }

        private static void processIdentity(LocationIdentity identity, MemoryKill checkpoint, MemoryMapImpl state) {
            if (identity.isAny()) {
                state.getMap().clear();
            }
            if (identity.isMutable()) {
                state.getMap().put(identity, checkpoint);
            }
        }

        @SuppressWarnings("try")
        private static void processFloatable(FloatableAccessNode accessNode, MemoryMapImpl state) {
            StructuredGraph graph = accessNode.graph();
            LocationIdentity locationIdentity = accessNode.getLocationIdentity();
            if (accessNode.canFloat()) {
                assert accessNode.getNullCheck() == false;
                MemoryKill lastLocationAccess = state.getLastLocationAccess(locationIdentity);
                try (DebugCloseable position = accessNode.withNodeSourcePosition()) {
                    FloatingAccessNode floatingNode = accessNode.asFloatingNode();
                    assert floatingNode.getLastLocationAccess() == lastLocationAccess;
                    graph.replaceFixedWithFloating(accessNode, floatingNode);
                }
            }
        }

        @Override
        protected MemoryMapImpl merge(AbstractMergeNode merge, List<MemoryMapImpl> states) {
            return mergeMemoryMaps(merge, states);
        }

        @Override
        protected MemoryMapImpl afterSplit(AbstractBeginNode node, MemoryMapImpl oldState) {
            MemoryMapImpl result = new MemoryMapImpl(oldState);
            if (node.predecessor() instanceof WithExceptionNode && node.predecessor() instanceof MemoryKill) {
                /*
                 * This WithExceptionNode cannot be the lastLocationAccess for a FloatingReadNode.
                 * Since it is both a memory kill and a control flow split, the scheduler cannot
                 * schedule anything immediately after the kill. It can only schedule in the normal
                 * or exceptional successor - and we have to tell the scheduler here which side it
                 * needs to choose by putting in the location identity on both successors.
                 */
                LocationIdentity killedLocationIdentity = node.predecessor() instanceof SingleMemoryKill ? ((SingleMemoryKill) node.predecessor()).getKilledLocationIdentity() : LocationIdentity.any();
                result.getMap().put(killedLocationIdentity, (MemoryKill) node);
            }
            return result;
        }

        @Override
        protected EconomicMap<LoopExitNode, MemoryMapImpl> processLoop(LoopBeginNode loop, MemoryMapImpl initialState) {
            EconomicSet<LocationIdentity> modifiedLocations = modifiedInLoops.get(loop);
            EconomicMap<LocationIdentity, MemoryPhiNode> phis = EconomicMap.create(Equivalence.DEFAULT);
            if (modifiedLocations.contains(LocationIdentity.any())) {
                // create phis for all locations if ANY is modified in the loop
                modifiedLocations = EconomicSet.create(Equivalence.DEFAULT, modifiedLocations);
                modifiedLocations.addAll(initialState.getMap().getKeys());
            }
            for (LocationIdentity location : modifiedLocations) {
                createMemoryPhi(loop, initialState, phis, location);
            }
            initialState.getMap().putAll(phis);
            LoopInfo<MemoryMapImpl> loopInfo = ReentrantNodeIterator.processLoop(this, loop, initialState);
            UnmodifiableMapCursor<LoopEndNode, MemoryMapImpl> endStateCursor = loopInfo.endStates.getEntries();
            while (endStateCursor.advance()) {
                int endIndex = loop.phiPredecessorIndex(endStateCursor.getKey());
                UnmodifiableMapCursor<LocationIdentity, MemoryPhiNode> phiCursor = phis.getEntries();

            }
            return loopInfo.exitStates;
        }

        private static void createMemoryPhi(LoopBeginNode loop, MemoryMapImpl initialState, EconomicMap<LocationIdentity, MemoryPhiNode> phis, LocationIdentity location) {
            MemoryPhiNode phi = loop.graph().addWithoutUnique(new MemoryPhiNode(loop, location));
            phi.addInput(ValueNodeUtil.asNode(initialState.getLastLocationAccess(location)));
            phis.put(location, phi);
        }
    }
}


@Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition)

package com.schneewittchen.rosandroid.utility;

import androidx.recyclerview.widget.DiffUtil;
import com.schneewittchen.rosandroid.model.entities.widgets.BaseEntity;
import java.util.List;

/**
 * TODO: Description
 *
 * @author Nico Studt
 * @version 1.0.1
 * @created on 05.02.20
 * @updated on 24.09.20
 * @modified by Nico Studt
 */
public class WidgetDiffCallback extends DiffUtil.Callback {

    public static String TAG = WidgetDiffCallback.class.getSimpleName();

    List<BaseEntity> oldWidgets;

    List<BaseEntity> newWidgets;

    public WidgetDiffCallback(List<BaseEntity> newWidgets, List<BaseEntity> oldWidgets) {
        this.newWidgets = newWidgets;
        this.oldWidgets = oldWidgets;
    }

    @Override
    public int getOldListSize() {
        return oldWidgets.size();
    }

    @Override
    public int getNewListSize() {
        return newWidgets.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEntity newWidget = newWidgets.get(newItemPosition);
        return oldWidget.id == newWidget.id;
    }

{
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEntity newWidget = newWidgets.get(newItemPosition);
        return oldWidget.equals(newWidget);
    }
}


{
        return newWidgets.size();
    }

package com.schneewittchen.rosandroid.utility;

import androidx.recyclerview.widget.DiffUtil;
import com.schneewittchen.rosandroid.model.entities.widgets.BaseEntity;
import java.util.List;

/**
 * TODO: Description
 *
 * @author Nico Studt
 * @version 1.0.1
 * @created on 05.02.20
 * @updated on 24.09.20
 * @modified by Nico Studt
 */
public class WidgetDiffCallback extends DiffUtil.Callback {

    public static String TAG = WidgetDiffCallback.class.getSimpleName();

    List<BaseEntity> oldWidgets;

    List<BaseEntity> newWidgets;

    public WidgetDiffCallback(List<BaseEntity> newWidgets, List<BaseEntity> oldWidgets) {
        this.newWidgets = newWidgets;
        this.oldWidgets = oldWidgets;
    }

    @Override
    public int getOldListSize() {
        return oldWidgets.size();
    }

    @Override
    public int getNewListSize()

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEntity newWidget = newWidgets.get(newItemPosition);
        return oldWidget.id == newWidget.id;
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEntity newWidget = newWidgets.get(newItemPosition);
        return oldWidget.equals(newWidget);
    }
}


package com.schneewittchen.rosandroid.utility;

import androidx.recyclerview.widget.DiffUtil;
import com.schneewittchen.rosandroid.model.entities.widgets.BaseEntity;
import java.util.List;

/**
 * TODO: Description
 *
 * @author Nico Studt
 * @version 1.0.1
 * @created on 05.02.20
 * @updated on 24.09.20
 * @modified by Nico Studt
 */
public class WidgetDiffCallback extends DiffUtil.Callback {

    public static String TAG = WidgetDiffCallback.class.getSimpleName();

    List<BaseEntity> oldWidgets;

    List<BaseEntity> newWidgets;

    public WidgetDiffCallback(List<BaseEntity> newWidgets, List<BaseEntity> oldWidgets) {
        this.newWidgets = newWidgets;
        this.oldWidgets = oldWidgets;
    }

    @Override
    public int getOldListSize() {
        return oldWidgets.size();
    }

    @Override
    public int getNewListSize() {
        return newWidgets.size();
    }

    @Override
    public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) {
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEnti

        return oldWidget.id == newWidget.id;
    }

    @Override
    public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) {
        BaseEntity oldWidget = oldWidgets.get(oldItemPosition);
        BaseEntity newWidget = newWidgets.get(newItemPosition);
        return oldWidget.equals(newWidget);
    }
}


@Deprecated
    @Property(selector = "completionHandler")
    @Block
    public native VoidBlock2<String, Boolean> getCompletionHandler();

package com.bugvm.apple.uikit;

import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.coreanimation.*;
import com.bugvm.apple.coregraphics.*;
import com.bugvm.apple.coredata.*;
import com.bugvm.apple.coreimage.*;
import com.bugvm.apple.coretext.*;
import com.bugvm.apple.corelocation.*;

/**
 * @since Available in iOS 6.0 and later.
 */
@Library("UIKit")
@NativeClass
public class UIActivityViewController extends UIViewController {

    public static class UIActivityViewControllerPtr extends Ptr<UIActivityViewController, UIActivityViewControllerPtr> {
    }

    static {
        ObjCRuntime.bind(UIActivityViewController.class);
    }

    public UIActivityViewController() {
    }

    protected UIActivityViewController(SkipInit skipInit) {
        super(skipInit);
    }

    public UIActivityViewController(String nibNameOrNil, NSBundle nibBundleOrNil) {
        super((SkipInit) null);
        initObject(init(nibNameOrNil, nibBundleOrNil));
    }

    public UIActivityViewController(NSCoder aDecoder) {
        super((SkipInit) null);
        initObject(init(aDecoder));
    }

    public UIActivityViewController(NSArray<?> activityItems, NSArray<UIActivity> applicationActivities) {
        super((SkipInit) null);
        initObject(init(activityItems, applicationActivities));
    }

    public UIActivityViewController(List<?> activityItems, NSArray<UIActivity> applicationActivities) {
        super((SkipInit) null);
        NSArray<NSObject> items = new NSMutableArray<>();
        for (Object item : activityItems) {
            if (!(item instanceof NSObject)) {
                if (item instanceof String) {
                    items.add(new NSString((String) item));
                } else if (item instanceof Number) {
                    items.add(NSNumber.valueOf((Number) item));
                } else {
                    throw new IllegalArgumentException("Unsupported activity item type: " + item);
                }
            } else {
                items.add((NSObject) item);
            }
        }
        initObject(init(items, applicationActivities));
    }

    /**
     * @since Available in iOS 6.0 and later.
     * @deprecated Deprecated in iOS 8.0.
     */

    /**
     * @since Available in iOS 6.0 and later.
     * @deprecated Deprecated in iOS 8.0.
     */
    @Deprecated
    @Property(selector = "setCompletionHandler:")
    public native void setCompletionHandler(@Block VoidBlock2<String, Boolean> v);

    /**
     * @since Available in iOS 8.0 and later.
     */
    @Property(selector = "completionWithItemsHandler")
    @Block
    public native VoidBlock4<String, Boolean, NSArray<NSObject>, NSError> getCompletionWithItemsHandler();

    /**
     * @since Available in iOS 8.0 and later.
     */
    @Property(selector = "setCompletionWithItemsHandler:")
    public native void setCompletionWithItemsHandler(@Block VoidBlock4<String, Boolean, NSArray<NSObject>, NSError> v);

    @Property(selector = "excludedActivityTypes")
    @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class)
    public native List<String> getExcludedActivityTypes();

    @Property(selector = "setExcludedActivityTypes:")
    public native void setExcludedActivityTypes(@com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List<String> v);

    @Method(selector = "initWithNibName:bundle:")
    @Pointer
    protected native long init(String nibNameOrNil, NSBundle nibBundleOrNil);

    @Method(selector = "initWithCoder:")
    @Pointer
    protected native long init(NSCoder aDecoder);

    @Method(selector = "initWithActivityItems:applicationActivities:")
    @Pointer
    protected native long init(NSArray<?> activityItems, NSArray<UIActivity> applicationActivities);
}


if (item instanceof Number) {
                    items.add(NSNumber.valueOf((Number) item));
                } else {
                    throw new IllegalArgumentException("Unsupported activity item type: " + item);
                }

package com.bugvm.apple.uikit;

import java.io.*;
import java.nio.*;
import java.util.*;
import com.bugvm.objc.*;
import com.bugvm.objc.annotation.*;
import com.bugvm.objc.block.*;
import com.bugvm.rt.*;
import com.bugvm.rt.annotation.*;
import com.bugvm.rt.bro.*;
import com.bugvm.rt.bro.annotation.*;
import com.bugvm.rt.bro.ptr.*;
import com.bugvm.apple.foundation.*;
import com.bugvm.apple.coreanimation.*;
import com.bugvm.apple.coregraphics.*;
import com.bugvm.apple.coredata.*;
import com.bugvm.apple.coreimage.*;
import com.bugvm.apple.coretext.*;
import com.bugvm.apple.corelocation.*;

/**
 * @since Available in iOS 6.0 and later.
 */
@Library("UIKit")
@NativeClass
public class UIActivityViewController extends UIViewController {

    public static class UIActivityViewControllerPtr extends Ptr<UIActivityViewController, UIActivityViewControllerPtr> {
    }

    static {
        ObjCRuntime.bind(UIActivityViewController.class);
    }

    public UIActivityViewController() {
    }

    protected UIActivityViewController(SkipInit skipInit) {
        super(skipInit);
    }

    public UIActivityViewController(String nibNameOrNil, NSBundle nibBundleOrNil) {
        super((SkipInit) null);
        initObject(init(nibNameOrNil, nibBundleOrNil));
    }

    public UIActivityViewController(NSCoder aDecoder) {
        super((SkipInit) null);
        initObject(init(aDecoder));
    }

    public UIActivityViewController(NSArray<?> activityItems, NSArray<UIActivity> applicationActivities) {
        super((SkipInit) null);
        initObject(init(activityItems, applicationActivities));
    }

    public UIActivityViewController(List<?> activityItems, NSArray<UIActivity> applicationActivities) {
        super((SkipInit) null);
        NSArray<NSObject> items = new NSMutableArray<>();
        for (Object item : activityItems) {
            if (!(item instanceof NSObject)) {
                if (item instanceof String) {
                    items.add(new NSString((String) item));
                } else

            } else {
                items.add((NSObject) item);
            }
        }
        initObject(init(items, applicationActivities));
    }

    /**
     * @since Available in iOS 6.0 and later.
     * @deprecated Deprecated in iOS 8.0.
     */
    @Deprecated
    @Property(selector = "completionHandler")
    @Block
    public native VoidBlock2<String, Boolean> getCompletionHandler();

    /**
     * @since Available in iOS 6.0 and later.
     * @deprecated Deprecated in iOS 8.0.
     */
    @Deprecated
    @Property(selector = "setCompletionHandler:")
    public native void setCompletionHandler(@Block VoidBlock2<String, Boolean> v);

    /**
     * @since Available in iOS 8.0 and later.
     */
    @Property(selector = "completionWithItemsHandler")
    @Block
    public native VoidBlock4<String, Boolean, NSArray<NSObject>, NSError> getCompletionWithItemsHandler();

    /**
     * @since Available in iOS 8.0 and later.
     */
    @Property(selector = "setCompletionWithItemsHandler:")
    public native void setCompletionWithItemsHandler(@Block VoidBlock4<String, Boolean, NSArray<NSObject>, NSError> v);

    @Property(selector = "excludedActivityTypes")
    @com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class)
    public native List<String> getExcludedActivityTypes();

    @Property(selector = "setExcludedActivityTypes:")
    public native void setExcludedActivityTypes(@com.bugvm.rt.bro.annotation.Marshaler(NSArray.AsStringListMarshaler.class) List<String> v);

    @Method(selector = "initWithNibName:bundle:")
    @Pointer
    protected native long init(String nibNameOrNil, NSBundle nibBundleOrNil);

    @Method(selector = "initWithCoder:")
    @Pointer
    protected native long init(NSCoder aDecoder);

    @Method(selector = "initWithActivityItems:applicationActivities:")
    @Pointer
    protected native long init(NSArray<?> activityItems, NSArray<UIActivity> applicationActivities);
}


public String getSavedString(String name, final String DEFAULT)

/**
 * BobEngine - 2D game engine for Android
 */
package com.bobbyloujo.bobengine.extra;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

/**
 * This helper class contains some useful functionality for your app.
 *
 * Created by Benjamin on 2/13/2015.
 */
public class BobHelper {

    // Constants
    final // The flags for immersive mode
    int // The flags for immersive mode
    VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // Data
    // Real width of the screen in pixels
    private int screenWidth;

    // Real height of the screen in pixels
    private int screenHeight;

    // Flag that determines if Immersive Mode is in use
    private boolean useImmersive = false;

    // Name of shared preferences file for saving data
    private String save = "save";

    // Objects
    private Activity activity;

    private WindowManager wm;

    private Point size;

    /**
     * You should initialize your BobHelper in or after onCreate() of activity.
     * @param activity - The activity that this BobHelper is tied to.
     */
    @SuppressLint("NewApi")
    public BobHelper(Activity activity) {
        this.activity = activity;
        wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        size = new Point();
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available.");
    }

    public void onResume() {
        if (useImmersive) {
            useImmersiveMode();
        }
    }

    /**
     * Uses KitKat's immersive mode. Immersive mode only works on Android 4.4.2
     * and up. There is no need to check for version number when using this
     * method. This method will handle older versions for you.
     */
    @SuppressLint("NewApi")
    public void useImmersiveMode() {
        try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }
    }

    /**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, 0);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */

{
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}


{
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

/**
 * BobEngine - 2D game engine for Android
 */
package com.bobbyloujo.bobengine.extra;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

/**
 * This helper class contains some useful functionality for your app.
 *
 * Created by Benjamin on 2/13/2015.
 */
public class BobHelper {

    // Constants
    final // The flags for immersive mode
    int // The flags for immersive mode
    VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // Data
    // Real width of the screen in pixels
    private int screenWidth;

    // Real height of the screen in pixels
    private int screenHeight;

    // Flag that determines if Immersive Mode is in use
    private boolean useImmersive = false;

    // Name of shared preferences file for saving data
    private String save = "save";

    // Objects
    private Activity activity;

    private WindowManager wm;

    private Point size;

    /**
     * You should initialize your BobHelper in or after onCreate() of activity.
     * @param activity - The activity that this BobHelper is tied to.
     */
    @SuppressLint("NewApi")
    public BobHelper(Activity activity) {
        this.activity = activity;
        wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        size = new Point();
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available.");
    }

    public void onResume() {
        if (useImmersive) {
            useImmersiveMode();
        }
    }

    /**
     * Uses KitKat's immersive mode. Immersive mode only works on Android 4.4.2
     * and up. There is no need to check for version number when using this
     * method. This method will handle older versions for you.
     */
    @SuppressLint("NewApi")
    public void useImmersiveMode() {
        try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }
    }

    /**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value)

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, 0);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name, final String DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}


/**
 * BobEngine - 2D game engine for Android
 */
package com.bobbyloujo.bobengine.extra;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

/**
 * This helper class contains some useful functionality for your app.
 *
 * Created by Benjamin on 2/13/2015.
 */
public class BobHelper {

    // Constants
    final // The flags for immersive mode
    int // The flags for immersive mode
    VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // Data
    // Real width of the screen in pixels
    private int screenWidth;

    // Real height of the screen in pixels
    private int screenHeight;

    // Flag that determines if Immersive Mode is in use
    private boolean useImmersive = false;

    // Name of shared preferences file for saving data
    private String save = "save";

    // Objects
    private Activity activity;

    private WindowManager wm;

    private Point size;

    /**
     * You should initialize your BobHelper in or after onCreate() of activity.
     * @param activity - The activity that this BobHelper is tied to.
     */
    @SuppressLint("NewApi")
    public BobHelper(Activity activity) {
        this.activity = activity;
        wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        size = new Point();
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available.");
    }

    public void onResume() {
        if (useImmersive) {
            useImmersiveMode();
        }
    }

    /**
     * Uses KitKat's immersive mode. Immersive mode only works on Android 4.4.2
     * and up. There is no need to check for version number when using this
     * method. This method will handle older versions for you.
     */
    @SuppressLint("NewApi")
    public void useImmersiveMode() {

try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }
    }

    /**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, 0);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name, final String DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}


try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }

}

    /**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, 0);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name, final String DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}


/**
 * BobEngine - 2D game engine for Android
 */
package com.bobbyloujo.bobengine.extra;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

/**
 * This helper class contains some useful functionality for your app.
 *
 * Created by Benjamin on 2/13/2015.
 */
public class BobHelper {

    // Constants
    final // The flags for immersive mode
    int // The flags for immersive mode
    VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // Data
    // Real width of the screen in pixels
    private int screenWidth;

    // Real height of the screen in pixels
    private int screenHeight;

    // Flag that determines if Immersive Mode is in use
    private boolean useImmersive = false;

    // Name of shared preferences file for saving data
    private String save = "save";

    // Objects
    private Activity activity;

    private WindowManager wm;

    private Point size;

    /**
     * You should initialize your BobHelper in or after onCreate() of activity.
     * @param activity - The activity that this BobHelper is tied to.
     */
    @SuppressLint("NewApi")
    public BobHelper(Activity activity) {
        this.activity = activity;
        wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        size = new Point();
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available.");
    }

    public void onResume() {
        if (useImmersive) {
            useImmersiveMode();
        }
    }

    /**
     * Uses KitKat's immersive mode. Immersive mode only works on Android 4.4.2
     * and up. There is no need to check for version number when using this
     * method. This method will handle older versions for you.
     */
    @SuppressLint("NewApi")
    public void useImmersiveMode() {
        try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }

/**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, 0);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name, final String DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}


/**
 * BobEngine - 2D game engine for Android
 */
package com.bobbyloujo.bobengine.extra;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Point;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;

/**
 * This helper class contains some useful functionality for your app.
 *
 * Created by Benjamin on 2/13/2015.
 */
public class BobHelper {

    // Constants
    final // The flags for immersive mode
    int // The flags for immersive mode
    VISIBILITY = View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    // Data
    // Real width of the screen in pixels
    private int screenWidth;

    // Real height of the screen in pixels
    private int screenHeight;

    // Flag that determines if Immersive Mode is in use
    private boolean useImmersive = false;

    // Name of shared preferences file for saving data
    private String save = "save";

    // Objects
    private Activity activity;

    private WindowManager wm;

    private Point size;

    /**
     * You should initialize your BobHelper in or after onCreate() of activity.
     * @param activity - The activity that this BobHelper is tied to.
     */
    @SuppressLint("NewApi")
    public BobHelper(Activity activity) {
        this.activity = activity;
        wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
        size = new Point();
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        ActivityManager am = (ActivityManager) activity.getSystemService(Context.ACTIVITY_SERVICE);
        Log.i("info", Integer.toString(am.getMemoryClass()) + "MB ram available.");
    }

    public void onResume() {
        if (useImmersive) {
            useImmersiveMode();
        }
    }

    /**
     * Uses KitKat's immersive mode. Immersive mode only works on Android 4.4.2
     * and up. There is no need to check for version number when using this
     * method. This method will handle older versions for you.
     */
    @SuppressLint("NewApi")
    public void useImmersiveMode() {
        try {
            // Immersive mode (Will not work on versions prior to 4.4.2)
            // Set the flags for immersive mode
            activity.getWindow().getDecorView().setSystemUiVisibility(VISIBILITY);
            // Add a listener to detect if we have lost immersive mode
            UIChangeListener();
            wm = (WindowManager) activity.getSystemService(Context.WINDOW_SERVICE);
            size = new Point();
            // Get -REAL- screen size. This excludes the navbar, which isn't visible
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
            screenHeight = size.y;
            useImmersive = true;
        } catch (NoSuchMethodError e) {
            // Immersive mode not supported (Android version < 4.4.2)
            // Get KitKat!
            Log.d("BobEngine", "Immersive mode not supported. (Android version < 4.4.2)");
        }
    }

    /**
     * This method creates a listener that will detect when immersive mode is
     * lost and get it back. Needs to be called again in onResume.
     */
    @SuppressLint("NewApi")
    private void UIChangeListener() {
        final View decorView = activity.getWindow().getDecorView();
        decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {

            @Override
            public void onSystemUiVisibilityChange(int visibility) {
                if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                    decorView.setSystemUiVisibility(VISIBILITY);
                }
            }
        });
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real width of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the width of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenWidth() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenWidth = size.x;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenWidth = wm.getDefaultDisplay().getWidth();
        }
        return screenWidth;
    }

    /**
     * Returns the width of the screen.

     *

     * On devices using API level 13 and higher, this function will return the
     * real height of the screen including things like the navigation bar and
     * title bar.

     *

     * BobView includes a function to get just the height of the view.
     *
     * @return - Width of the screen, in pixels.
     */
    @SuppressLint("NewApi")
    @SuppressWarnings("deprecation")
    public int getScreenHeight() {
        try {
            // Get screen dimensions
            // New method, might not work on old devices
            wm.getDefaultDisplay().getRealSize(size);
            screenHeight = size.y;
        } catch (NoSuchMethodError er) {
            // If new method didn't work, use depreciated methods
            screenHeight = wm.getDefaultDisplay().getHeight();
        }
        return screenHeight;
    }

    /**
     * Set the save file to use with saveInt()... getSavedInt()... etc.
     * @param fileName
     */
    public void setSaveFile(String fileName) {
        save = fileName;
    }

    /**
     * Save an integer value. It can be retrieved even after the application has quit
     * by calling getSavedInt();
     *
     * @param name  - name of the saved integer. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveInt(String name, int value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putInt(name, value);
        edit.commit();
    }

    /**
     * Save an boolean value. It can be retrieved even after the application has quit
     * by calling getSavedBool();
     *
     * @param name  - name of the saved boolean. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveBool(String name, boolean value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putBoolean(name, value);
        edit.commit();
    }

    /**
     * Save an float value. It can be retrieved even after the application has quit
     * by calling getSavedFloat();
     *
     * @param name  - name of the saved float. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveFloat(String name, float value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putFloat(name, value);
        edit.commit();
    }

    /**
     * Save an string value. It can be retrieved even after the application has quit
     * by calling getSavedString();
     *
     * @param name  - name of the saved string. Will be used for retrieval.
     * @param value - value to save.
     */
    public void saveString(String name, String value) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        SharedPreferences.Editor edit = prefs.edit();
        edit.putString(name, value);
        edit.commit();
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        retu

    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, 0f);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, false);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, "");
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0 if name doesn't exist.
     */
    public int getSavedInt(String name, final int DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getInt(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. 0f if name doesn't exist.
     */
    public float getSavedFloat(String name, final float DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getFloat(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. false if name doesn't exist.
     */
    public boolean getSavedBool(String name, final boolean DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getBoolean(name, DEFAULT);
    }

    /**
     * Get a saved value.
     *
     * @param name - name of the saved value.
     * @return saved value of name. "" if name doesn't exist.
     */
    public String getSavedString(String name, final String DEFAULT) {
        SharedPreferences prefs = activity.getSharedPreferences(save, activity.MODE_PRIVATE);
        return prefs.getString(name, DEFAULT);
    }
}