当前位置: 首页>>代码示例>>Java>>正文


Java Util.runInBackground方法代码示例

本文整理汇总了Java中com.connectsdk.core.Util.runInBackground方法的典型用法代码示例。如果您正苦于以下问题:Java Util.runInBackground方法的具体用法?Java Util.runInBackground怎么用?Java Util.runInBackground使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.connectsdk.core.Util的用法示例。


在下文中一共展示了Util.runInBackground方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: start

import com.connectsdk.core.Util; //导入方法依赖的package包/类
public synchronized void start() {
    if (running) {
        return;
    }

    running = true;

    try {
        welcomeSocket = new ServerSocket(this.port);
    } catch (IOException ex) {
        ex.printStackTrace();
        return;
    }

    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            processRequests();
        }
    }, true);
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:22,代码来源:DLNAHttpServer.java

示例2: disconnect

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void disconnect() {
    connected = false;

    if (mServiceReachability != null)
        mServiceReachability.stop();

    Util.runOnUI(new Runnable() {

        @Override
        public void run() {
            if (listener != null) {
                listener.onDisconnect(DLNAService.this, null);
            }
        }
    });

    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            httpServer.stop();
        }
    }, true);

}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:26,代码来源:DLNAService.java

示例3: disconnect

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void disconnect() {
    connected = false;

    if (mServiceReachability != null)
        mServiceReachability.stop();

    Util.runOnUI(new Runnable() {

        @Override
        public void run() {
            if (listener != null) {
                listener.onDisconnect(DLNAService.this, null);
            }
        }
    });

    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            httpServer.stop();
        }
    });

}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:26,代码来源:DLNAService.java

示例4: writeStoreToDisk

import com.connectsdk.core.Util; //导入方法依赖的package包/类
private synchronized void writeStoreToDisk(final JSONObject deviceStore) {
    final long lastUpdate = updated;
    waitToWrite = true;

    Util.runInBackground(new Runnable() {

        @Override
        public void run() {
            FileWriter out;
            try {
                File output = new File(fileFullPath);

                if (!output.exists())
                    output.getParentFile().mkdirs();

                out = new FileWriter(output);
                out.write(deviceStore.toString());
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                waitToWrite = false;
            }

            if (lastUpdate < updated)
                writeStoreToDisk(deviceStore);
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:30,代码来源:DefaultConnectableDeviceStore.java

示例5: addSubscription

import com.connectsdk.core.Util; //导入方法依赖的package包/类
private void addSubscription(URLServiceSubscription<?> subscription) {
    if (!httpServer.isRunning()) {
        Util.runInBackground(new Runnable() {

            @Override
            public void run() {
                httpServer.start();
            }
        });
        subscribeServices();
    }

    httpServer.getSubscriptions().add(subscription);
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:15,代码来源:DLNAService.java

示例6: unsubscribeServices

import com.connectsdk.core.Util; //导入方法依赖的package包/类
public void unsubscribeServices() {
    if (resubscriptionTimer != null) {
        resubscriptionTimer.cancel();
    }

    Util.runInBackground(new Runnable() {

        @Override
        public void run() {
            final List<Service> serviceList = serviceDescription.getServiceList();

            if (serviceList != null) {
                for (int i = 0; i < serviceList.size(); i++) {
                    String eventSubURL = makeControlURL("/", serviceList.get(i).eventSubURL);
                    if (eventSubURL == null) {
                        continue;
                    }

                    String sid = SIDList.get(serviceList.get(i).serviceType);
                    try {
                        HttpConnection connection = HttpConnection.newSubscriptionInstance(
                                new URI("http", "", serviceDescription.getIpAddress(), serviceDescription.getPort(), eventSubURL, "", ""));
                        connection.setMethod(HttpConnection.Method.UNSUBSCRIBE);
                        connection.setHeader("SID", sid);
                        connection.execute();
                        if (connection.getResponseCode() == 200) {
                            SIDList.remove(serviceList.get(i).serviceType);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:37,代码来源:DLNAService.java

示例7: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            final ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
                connection.setHeader(HttpMessage.USER_AGENT, HttpMessage.UDAP_USER_AGENT);
                connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_TEXT_XML);
                if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    connection.setPayload(payload.toString());
                }
                connection.execute();
                int code = connection.getResponseCode();
                Log.d("", "RESP " + code);
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:34,代码来源:NetcastTVService.java

示例8: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = createHttpConnection(mCommand.getTarget());
                if (payload != null || command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    if (payload != null) {
                        connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, "text/plain; " +
                                "charset=\"utf-8\"");
                        connection.setPayload(payload.toString());
                    }
                } else if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_DEL)) {
                    connection.setMethod(HttpConnection.Method.DELETE);
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else if (code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseHeader("Location"));
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (Exception e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:38,代码来源:DIALService.java

示例9: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                Log.d("", "RESP " + command.getTarget());
                HttpConnection connection = HttpConnection.newInstance(URI.create(command.getTarget()));
                if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                    if (payload != null) {
                        connection.setPayload(payload.toString());
                    }
                }
                connection.execute();
                int code = connection.getResponseCode();
                Log.d("", "RESP " + code);
                if (code == 200 || code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }

        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:36,代码来源:RokuService.java

示例10: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;
            Object payload = command.getPayload();

            try {
                HttpConnection connection = createHttpConnection(mCommand.getTarget());
                if (payload != null && command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, "text/plain; charset=\"utf-8\"");
                    connection.setMethod(HttpConnection.Method.POST);
                    connection.setPayload(payload.toString());
                } else if (command.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_DEL)) {
                    connection.setMethod(HttpConnection.Method.DELETE);
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else if (code == 201) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseHeader("Location"));
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (Exception e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:35,代码来源:DIALService.java

示例11: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> mCommand) {
    Util.runInBackground(new Runnable() {

        @SuppressWarnings("unchecked")
        @Override
        public void run() {
            ServiceCommand<ResponseListener<Object>> command = (ServiceCommand<ResponseListener<Object>>) mCommand;

            String method = command.getTarget();
            String payload = (String) command.getPayload();

            String targetURL = null;
            String serviceURN = null;

            if (payload == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"payload\" is missed", null));
                return;
            }

            if (payload.contains(AV_TRANSPORT_URN)) {
                targetURL = avTransportURL;
                serviceURN = AV_TRANSPORT_URN;
            } else if (payload.contains(RENDERING_CONTROL_URN)) {
                targetURL = renderingControlURL;
                serviceURN = RENDERING_CONTROL_URN;
            } else if (payload.contains(CONNECTION_MANAGER_URN)) {
                targetURL = connectionControlURL;
                serviceURN = CONNECTION_MANAGER_URN;
            }

            if (serviceURN == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"serviceURN\" is missed", null));
                return;
            }

            if (targetURL == null) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, "Cannot process the command, \"targetURL\" is missed", null));
                return;
            }

            try {
                HttpConnection connection = createHttpConnection(targetURL);
                connection.setHeader("Content-Type", "text/xml; charset=utf-8");
                connection.setHeader("SOAPAction", String.format("\"%s#%s\"", serviceURN, method));
                connection.setMethod(HttpConnection.Method.POST);
                connection.setPayload(payload);
                connection.execute();
                int code = connection.getResponseCode();
                if (code == 200) {
                    Util.postSuccess(command.getResponseListener(), connection.getResponseString());
                } else {
                    Util.postError(command.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                Util.postError(command.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:61,代码来源:DLNAService.java

示例12: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> serviceCommand) {
    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            try {
                StringBuilder sb = new StringBuilder();
                sb.append("http://").append(serviceDescription.getIpAddress()).append(":").append(serviceDescription.getPort());
                sb.append(serviceCommand.getTarget());

                HttpConnection connection = HttpConnection.newInstance(URI.create(sb.toString()));
                connection.setHeader(HTTP.USER_AGENT, "ConnectSDK MediaControl/1.0");
                connection.setHeader(X_APPLE_SESSION_ID, mSessionId);
                if (password != null) {
                    String authorization = getAuthenticate(serviceCommand.getHttpMethod(), serviceCommand.getTarget(), authenticate);
                    connection.setHeader("Authorization", authorization);
                }
                Object payload = serviceCommand.getPayload();
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)
                        || serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    if (payload != null) {
                        if (payload instanceof String) {
                            connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_APPLICATION_PLIST);
                            connection.setPayload(payload.toString());
                        } else if (payload instanceof byte[]) {
                            connection.setPayload((byte[])payload);
                        }
                    }
                }
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                } else if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    connection.setMethod(HttpConnection.Method.PUT);
                } else {
                    connection.setHeader("Content-Length", "0");
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == HttpURLConnection.HTTP_OK) {
                    Util.postSuccess(serviceCommand.getResponseListener(), connection.getResponseString());
                } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    authenticate = connection.getResponseHeader("WWW-Authenticate");
                    pendingCommand = serviceCommand;
                    Util.runOnUI(new Runnable() {
                        @Override
                        public void run() {
                            if (listener != null) {
                                listener.onPairingRequired(AirPlayService.this, pairingType, null);
                            }
                        }
                    });
                } else {
                    Util.postError(serviceCommand.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(serviceCommand.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:david-fenton,项目名称:Connect-SDK-Cordova-Plugin,代码行数:62,代码来源:AirPlayService.java

示例13: sendCommand

import com.connectsdk.core.Util; //导入方法依赖的package包/类
@Override
public void sendCommand(final ServiceCommand<?> serviceCommand) {
    Util.runInBackground(new Runnable() {
        @Override
        public void run() {
            try {
                StringBuilder sb = new StringBuilder();
                sb.append("http://").append(serviceDescription.getIpAddress()).append(":").append(serviceDescription.getPort());
                sb.append(serviceCommand.getTarget());

                HttpConnection connection = HttpConnection.newInstance(URI.create(sb.toString()));
                connection.setHeader(HTTP.USER_AGENT, "ConnectSDK MediaControl/1.0");
                connection.setHeader(X_APPLE_SESSION_ID, mSessionId);
                if (password != null) {
                    String authorization = getAuthenticate(serviceCommand.getHttpMethod(), serviceCommand.getTarget(), authenticate);
                    connection.setHeader("Authorization", authorization);
                }
                Object payload = serviceCommand.getPayload();
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)
                        || serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    if (payload != null) {
                        if (payload instanceof String) {
                            connection.setHeader(HttpMessage.CONTENT_TYPE_HEADER, HttpMessage.CONTENT_TYPE_APPLICATION_PLIST);
                            connection.setPayload(payload.toString());
                        } else if (payload instanceof byte[]) {
                            connection.setPayload((byte[]) payload);
                        }
                    }
                }
                if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_POST)) {
                    connection.setMethod(HttpConnection.Method.POST);
                } else if (serviceCommand.getHttpMethod().equalsIgnoreCase(ServiceCommand.TYPE_PUT)) {
                    connection.setMethod(HttpConnection.Method.PUT);
                } else {
                    connection.setHeader("Content-Length", "0");
                }
                connection.execute();
                int code = connection.getResponseCode();
                if (code == HttpURLConnection.HTTP_OK) {
                    Util.postSuccess(serviceCommand.getResponseListener(), connection.getResponseString());
                } else if (code == HttpURLConnection.HTTP_UNAUTHORIZED) {
                    authenticate = connection.getResponseHeader("WWW-Authenticate");
                    pendingCommand = serviceCommand;
                    Util.runOnUI(new Runnable() {
                        @Override
                        public void run() {
                            if (listener != null) {
                                listener.onPairingRequired(AirPlayService.this, pairingType, null);
                            }
                        }
                    });
                } else {
                    Util.postError(serviceCommand.getResponseListener(), ServiceCommandError.getError(code));
                }
            } catch (IOException e) {
                e.printStackTrace();
                Util.postError(serviceCommand.getResponseListener(), new ServiceCommandError(0, e.getMessage(), null));
            }
        }
    });
}
 
开发者ID:PTCE,项目名称:popcorn-android,代码行数:62,代码来源:AirPlayService.java


注:本文中的com.connectsdk.core.Util.runInBackground方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。