Android Open Source - sony-camera-remote-java Radial Free Space






From Project

Back to project page sony-camera-remote-java.

License

The source code is released under:

Apache License

If you think the Android project sony-camera-remote-java listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.praetoriandroid.widget;
//  w w w.j  a v  a  2 s  . c  o  m
import java.util.HashMap;
import java.util.Map;

/**
 * There are 16 possible cases of free space in the parent:
 * <pre>
 *      |    ---    |
 *  O   |O    O    O|
 * ---  |           |
 *
 * |    +--  --+    |
 * |O   |O    O|   O|
 * +--  |      |  --+
 *
 * | |  +--  +-+  --+
 * |O|  |O   |O|   O|
 * +-+  +--  | |  --+
 *
 * ---  | |  +-+
 *  O   |O|  |O|   O
 * ---  | |  +-+
 * </pre>
 * Assuming the free space is at least as much as selector size multiplied by 1.5, proposed
 * that selector and selection items are approximately the same size.
 */
@SuppressWarnings("UnusedDeclaration")
public enum RadialFreeSpace {
    LEFT_TOP_RIGHT {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * 1.5);
        }

        @Override
        public float sectorSize() {
            return (float) Math.PI;
        }
    },
    TOP_RIGHT_BOTTOM {
        @Override
        public float mainAxis() {
            return 0;
        }

        @Override
        public float sectorSize() {
            return (float) Math.PI;
        }
    },
    RIGHT_BOTTOM_LEFT {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * .5);
        }

        @Override
        public float sectorSize() {
            return (float) Math.PI;
        }
    },
    BOTTOM_LEFT_TOP {
        @Override
        public float mainAxis() {
            return (float) Math.PI;
        }

        @Override
        public float sectorSize() {
            return (float) Math.PI;
        }
    },

    TOP_RIGHT {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * 1.75);
        }

        @Override
        public float sectorSize() {
            return (float) (Math.PI / 2);
        }
    },
    RIGHT_BOTTOM {
        @Override
        public float mainAxis() {
            return (float) (Math.PI / 4);
        }

        @Override
        public float sectorSize() {
            return (float) (Math.PI / 2);
        }
    },
    BOTTOM_LEFT {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * .75);
        }

        @Override
        public float sectorSize() {
            return (float) (Math.PI / 2);
        }
    },
    LEFT_TOP {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * 1.25);
        }

        @Override
        public float sectorSize() {
            return (float) (Math.PI / 2);
        }
    },

    TOP {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * 1.5);
        }

        @Override
        public float sectorSize() {
            return 0;
        }
    },
    RIGHT {
        @Override
        public float mainAxis() {
            return 0;
        }

        @Override
        public float sectorSize() {
            return 0;
        }
    },
    BOTTOM {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * .5);
        }

        @Override
        public float sectorSize() {
            return 0;
        }
    },
    LEFT {
        @Override
        public float mainAxis() {
            return (float) Math.PI;
        }

        @Override
        public float sectorSize() {
            return 0;
        }
    },

    LEFT_RIGHT {
        @Override
        public float mainAxis() {
            throw new NotImplementedException(); // TODO here and below: need something more acceptable...
        }

        @Override
        public float sectorSize() {
            throw new NotImplementedException();
        }
    },
    TOP_BOTTOM {
        @Override
        public float mainAxis() {
            throw new NotImplementedException();
        }

        @Override
        public float sectorSize() {
            throw new NotImplementedException();
        }
    },
    ZERO {
        @Override
        public float mainAxis() {
            throw new NotImplementedException();
        }

        @Override
        public float sectorSize() {
            throw new NotImplementedException();
        }
    },
    ALL {
        @Override
        public float mainAxis() {
            return (float) (Math.PI * 1.5);
        }

        @Override
        public float sectorSize() {
            return (float) (Math.PI * 2);
        }
    };

    public static final int FREE_TOP = 0x01;
    public static final int FREE_RIGHT = 0x02;
    public static final int FREE_BOTTOM = 0x04;
    public static final int FREE_LEFT = 0x08;
    public static final float MAX_RAYS_ANGLE = (float) (Math.PI / 3.);

    private static Map<Integer, RadialFreeSpace> flagMap = new HashMap<Integer, RadialFreeSpace>(16);

    static {
        flagMap.put(FREE_LEFT | FREE_TOP | FREE_RIGHT, LEFT_TOP_RIGHT);
        flagMap.put(FREE_TOP | FREE_RIGHT | FREE_BOTTOM, TOP_RIGHT_BOTTOM);
        flagMap.put(FREE_RIGHT | FREE_BOTTOM | FREE_LEFT, RIGHT_BOTTOM_LEFT);
        flagMap.put(FREE_BOTTOM | FREE_LEFT | FREE_TOP, BOTTOM_LEFT_TOP);
        flagMap.put(FREE_TOP, TOP);
        flagMap.put(FREE_RIGHT, RIGHT);
        flagMap.put(FREE_BOTTOM, BOTTOM);
        flagMap.put(FREE_LEFT, LEFT);
        flagMap.put(FREE_TOP | FREE_RIGHT, TOP_RIGHT);
        flagMap.put(FREE_RIGHT | FREE_BOTTOM, RIGHT_BOTTOM);
        flagMap.put(FREE_BOTTOM | FREE_LEFT, BOTTOM_LEFT);
        flagMap.put(FREE_LEFT | FREE_TOP, LEFT_TOP);
        flagMap.put(FREE_LEFT | FREE_RIGHT, LEFT_RIGHT);
        flagMap.put(FREE_TOP | FREE_BOTTOM, TOP_BOTTOM);
        flagMap.put(0, ZERO);
        flagMap.put(FREE_TOP | FREE_RIGHT | FREE_BOTTOM | FREE_LEFT, ALL);
    }

    public abstract float mainAxis();

    public abstract float sectorSize();

    public static RadialFreeSpace fromFlags(int flags) {
        RadialFreeSpace result = flagMap.get(flags);
        if (result == null) {
            throw new IllegalArgumentException();
        }
        return result;
    }

    public static RadialFreeSpace fromCoordinates(int parentWidth, int parentHeight, int cx, int cy, int size) {
        int flags = 0;
        if (cy > size * 2) {
            flags |= FREE_TOP;
        }
        if (cy + size * 2 < parentHeight) {
            flags |= FREE_BOTTOM;
        }
        if (cx > size * 2) {
            flags |= FREE_LEFT;
        }
        if (cx + size * 2 < parentWidth) {
            flags |= FREE_RIGHT;
        }
        return fromFlags(flags);
    }

    public static class NotImplementedException extends RuntimeException {
    }
}




Java Source Code List

com.praetoriandroid.cameraremote.BadHttpStatusException.java
com.praetoriandroid.cameraremote.DeviceDescription.java
com.praetoriandroid.cameraremote.HttpClient.java
com.praetoriandroid.cameraremote.InvalidDataFormatException.java
com.praetoriandroid.cameraremote.LiveViewDisconnectedException.java
com.praetoriandroid.cameraremote.LiveViewFetcher.java
com.praetoriandroid.cameraremote.Logger.java
com.praetoriandroid.cameraremote.ParseException.java
com.praetoriandroid.cameraremote.RpcClient.java
com.praetoriandroid.cameraremote.RpcException.java
com.praetoriandroid.cameraremote.ServiceNotSupportedException.java
com.praetoriandroid.cameraremote.SsdpClient.java
com.praetoriandroid.cameraremote.SsdpException.java
com.praetoriandroid.cameraremote.app.LiveView.java
com.praetoriandroid.cameraremote.app.MainActivity.java
com.praetoriandroid.cameraremote.app.Rpc.java
com.praetoriandroid.cameraremote.app.SelfTimerSelector.java
com.praetoriandroid.cameraremote.app.ThisApp.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.ActTakePictureResponse.java
com.praetoriandroid.cameraremote.rpc.AwaitTakePictureRequest.java
com.praetoriandroid.cameraremote.rpc.BaseRequest.java
com.praetoriandroid.cameraremote.rpc.BaseResponse.java
com.praetoriandroid.cameraremote.rpc.CustomizableEntity.java
com.praetoriandroid.cameraremote.rpc.EventEntity.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoRequest.java
com.praetoriandroid.cameraremote.rpc.GetApplicationInfoResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableApiListResponse.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetAvailableSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetEventRequest.java
com.praetoriandroid.cameraremote.rpc.GetEventResponse.java
com.praetoriandroid.cameraremote.rpc.GetExposureModeRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesRequest.java
com.praetoriandroid.cameraremote.rpc.GetMethodTypesResponse.java
com.praetoriandroid.cameraremote.rpc.GetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.GetSupportedSelfTimerResponse.java
com.praetoriandroid.cameraremote.rpc.GetVersionsRequest.java
com.praetoriandroid.cameraremote.rpc.GetVersionsResponse.java
com.praetoriandroid.cameraremote.rpc.IllegalResultSizeException.java
com.praetoriandroid.cameraremote.rpc.MethodTypesEntity.java
com.praetoriandroid.cameraremote.rpc.RpcMethod.java
com.praetoriandroid.cameraremote.rpc.SetSelfTimerRequest.java
com.praetoriandroid.cameraremote.rpc.SimpleResponse.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewRequest.java
com.praetoriandroid.cameraremote.rpc.StartLiveViewResponse.java
com.praetoriandroid.cameraremote.rpc.StartMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StartRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.StopLiveviewRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecRequest.java
com.praetoriandroid.cameraremote.rpc.StopMovieRecResponse.java
com.praetoriandroid.cameraremote.rpc.StopRecModeRequest.java
com.praetoriandroid.cameraremote.rpc.ValidationException.java
com.praetoriandroid.cameraremote.rpc._DummyResponse.java
com.praetoriandroid.cameraremote.tool.Cache.java
com.praetoriandroid.cameraremote.tool.RemoteControl.java
com.praetoriandroid.widget.ItemViewCreator.java
com.praetoriandroid.widget.RadialFreeSpace.java
com.praetoriandroid.widget.RadialSelector.java