Android Open Source - sony-camera-remote-java Get Available Self Timer Request






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.cameraremote.rpc;
/*from  w  w w  .  ja va 2 s  .  c om*/
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.JsonArray;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSyntaxException;

import java.lang.reflect.Type;

public class GetAvailableSelfTimerRequest extends BaseRequest<Void, GetAvailableSelfTimerResponse> {

    private static Gson customGson;

    public GetAvailableSelfTimerRequest() {
        super(GetAvailableSelfTimerResponse.class, RpcMethod.getAvailableSelfTimer);
    }

    @Override
    public GetAvailableSelfTimerResponse parseResponse(Gson gson, String data)
            throws JsonSyntaxException {
        synchronized (GetAvailableSelfTimerRequest.class) {
            if (customGson == null) {
                customGson = getGson();
            }
        }
        return super.parseResponse(customGson, data);
    }

    private Gson getGson() {
        return new GsonBuilder()
                .registerTypeAdapter(CustomizableEntity.class, new SelfTimerEntityDeserializer())
                .create();
    }

    private static class SelfTimerEntityDeserializer implements JsonDeserializer<CustomizableEntity> {

        @Override
        public CustomizableEntity deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
                throws JsonParseException {
            try {
                if (json.isJsonPrimitive()) {
                    JsonPrimitive primitive = (JsonPrimitive) json;
                    if (primitive.isNumber()) {
                        return new GetAvailableSelfTimerResponse.IntEntity(primitive.getAsNumber().intValue());
                    }
                } else if (json.isJsonArray()) {
                    JsonArray jsonArray = json.getAsJsonArray();
                    int[] array = new int[jsonArray.size()];
                    for (int i = 0; i < jsonArray.size(); i++) {
                        JsonElement item = jsonArray.get(i);
                        if (item.isJsonPrimitive()) {
                            array[i] = item.getAsNumber().intValue();
                        } else {
                            throw new JsonParseException("Illegal array item type: " + item);
                        }
                    }
                    return new GetAvailableSelfTimerResponse.IntArrayEntity(array);
                } else {
                    throw new JsonParseException("Illegal result type: " + json);
                }
            } catch (NumberFormatException e) {
                throw new JsonParseException(e);
            }
            return null;
        }

    }

}




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