Search in sources :

Example 1 with ChannelInfo

use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.

the class NetcastTVService method getChannelList.

@Override
public void getChannelList(final ChannelListListener listener) {
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CHANNEL_LIST);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strObj = (String) response;
            try {
                SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
                SAXParser saxParser = saxParserFactory.newSAXParser();
                NetcastChannelParser parser = new NetcastChannelParser();
                saxParser.parse(stream, parser);
                JSONArray channelArray = parser.getJSONChannelArray();
                ArrayList<ChannelInfo> channelList = new ArrayList<ChannelInfo>();
                for (int i = 0; i < channelArray.length(); i++) {
                    JSONObject rawData;
                    try {
                        rawData = (JSONObject) channelArray.get(i);
                        ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
                        channelList.add(channel);
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
                Util.postSuccess(listener, channelList);
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    request.setHttpMethod(ServiceCommand.TYPE_GET);
    request.send();
}
Also used : NetcastChannelParser(com.connectsdk.service.netcast.NetcastChannelParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) JSONObject(org.json.JSONObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ServiceCommand(com.connectsdk.service.command.ServiceCommand) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 2 with ChannelInfo

use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.

the class WebOSTVService method getChannelList.

private ServiceCommand<ResponseListener<Object>> getChannelList(boolean isSubscription, final ChannelListListener listener) {
    ServiceCommand<ResponseListener<Object>> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                ArrayList<ChannelInfo> list = new ArrayList<ChannelInfo>();
                JSONArray array = (JSONArray) jsonObj.get("channelList");
                for (int i = 0; i < array.length(); i++) {
                    JSONObject object = (JSONObject) array.get(i);
                    ChannelInfo channel = parseRawChannelData(object);
                    list.add(channel);
                }
                Util.postSuccess(listener, list);
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, CHANNEL_LIST, null, true, responseListener);
    request.send();
    return request;
}
Also used : ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) SuppressLint(android.annotation.SuppressLint) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONObject(org.json.JSONObject) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 3 with ChannelInfo

use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.

the class WebOSTVService method getProgramList.

private ServiceCommand<ResponseListener<Object>> getProgramList(boolean isSubscription, final ProgramListListener listener) {
    ServiceCommand<ResponseListener<Object>> request;
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            try {
                JSONObject jsonObj = (JSONObject) response;
                JSONObject jsonChannel = (JSONObject) jsonObj.get("channel");
                ChannelInfo channel = parseRawChannelData(jsonChannel);
                JSONArray programList = (JSONArray) jsonObj.get("programList");
                Util.postSuccess(listener, new ProgramList(channel, programList));
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    if (isSubscription)
        request = new URLServiceSubscription<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
    else
        request = new ServiceCommand<ResponseListener<Object>>(this, PROGRAM, null, true, responseListener);
    request.send();
    return request;
}
Also used : ProgramList(com.connectsdk.core.ProgramList) JSONObject(org.json.JSONObject) URLServiceSubscription(com.connectsdk.service.command.URLServiceSubscription) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) ServiceCommand(com.connectsdk.service.command.ServiceCommand)

Example 4 with ChannelInfo

use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.

the class NetcastChannelParser method parseRawChannelData.

public static ChannelInfo parseRawChannelData(JSONObject channelRawData) {
    String channelName = null;
    String channelId = null;
    String channelNumber = null;
    int minorNumber = 0;
    int majorNumber = 0;
    ChannelInfo channelInfo = new ChannelInfo();
    channelInfo.setRawData(channelRawData);
    try {
        if (!channelRawData.isNull("channelName"))
            channelName = (String) channelRawData.get("channelName");
        if (!channelRawData.isNull("channelId"))
            channelId = (String) channelRawData.get("channelId");
        if (!channelRawData.isNull("majorNumber"))
            majorNumber = (Integer) channelRawData.get("majorNumber");
        if (!channelRawData.isNull("minorNumber"))
            minorNumber = (Integer) channelRawData.get("minorNumber");
        if (!channelRawData.isNull("channelNumber"))
            channelNumber = (String) channelRawData.get("channelNumber");
        else {
            channelNumber = String.format(String.valueOf(majorNumber) + "-" + String.valueOf(minorNumber));
        }
        channelInfo.setName(channelName);
        channelInfo.setId(channelId);
        channelInfo.setNumber(channelNumber);
        channelInfo.setMajorNumber(majorNumber);
        channelInfo.setMinorNumber(minorNumber);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return channelInfo;
}
Also used : JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo)

Example 5 with ChannelInfo

use of com.connectsdk.core.ChannelInfo in project butter-android by butterproject.

the class NetcastTVService method getCurrentChannel.

@Override
public void getCurrentChannel(final ChannelListener listener) {
    String requestURL = getUDAPRequestURL(UDAP_PATH_DATA, TARGET_CURRENT_CHANNEL);
    ResponseListener<Object> responseListener = new ResponseListener<Object>() {

        @Override
        public void onSuccess(Object response) {
            String strObj = (String) response;
            try {
                SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
                InputStream stream = new ByteArrayInputStream(strObj.getBytes("UTF-8"));
                SAXParser saxParser = saxParserFactory.newSAXParser();
                NetcastChannelParser parser = new NetcastChannelParser();
                saxParser.parse(stream, parser);
                JSONArray channelArray = parser.getJSONChannelArray();
                if (channelArray.length() > 0) {
                    JSONObject rawData = (JSONObject) channelArray.get(0);
                    ChannelInfo channel = NetcastChannelParser.parseRawChannelData(rawData);
                    Util.postSuccess(listener, channel);
                }
            } catch (ParserConfigurationException e) {
                e.printStackTrace();
            } catch (SAXException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }

        @Override
        public void onError(ServiceCommandError error) {
            Util.postError(listener, error);
        }
    };
    ServiceCommand<ResponseListener<Object>> request = new ServiceCommand<ResponseListener<Object>>(this, requestURL, null, responseListener);
    request.send();
}
Also used : NetcastChannelParser(com.connectsdk.service.netcast.NetcastChannelParser) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) ChannelInfo(com.connectsdk.core.ChannelInfo) ServiceCommandError(com.connectsdk.service.command.ServiceCommandError) ResponseListener(com.connectsdk.service.capability.listeners.ResponseListener) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) JSONObject(org.json.JSONObject) ByteArrayInputStream(java.io.ByteArrayInputStream) SAXParser(javax.xml.parsers.SAXParser) JSONObject(org.json.JSONObject) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) ServiceCommand(com.connectsdk.service.command.ServiceCommand) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Aggregations

ChannelInfo (com.connectsdk.core.ChannelInfo)9 JSONException (org.json.JSONException)7 ResponseListener (com.connectsdk.service.capability.listeners.ResponseListener)6 JSONObject (org.json.JSONObject)6 ServiceCommand (com.connectsdk.service.command.ServiceCommand)5 ServiceCommandError (com.connectsdk.service.command.ServiceCommandError)5 JSONArray (org.json.JSONArray)4 URLServiceSubscription (com.connectsdk.service.command.URLServiceSubscription)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 IOException (java.io.IOException)3 InputStream (java.io.InputStream)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 SAXParser (javax.xml.parsers.SAXParser)3 SAXParserFactory (javax.xml.parsers.SAXParserFactory)3 SAXException (org.xml.sax.SAXException)3 SuppressLint (android.annotation.SuppressLint)2 NetcastChannelParser (com.connectsdk.service.netcast.NetcastChannelParser)2 ArrayList (java.util.ArrayList)2 ProgramInfo (com.connectsdk.core.ProgramInfo)1 ProgramList (com.connectsdk.core.ProgramList)1