List of usage examples for android.os Message obtain
public static Message obtain(Handler h, int what, int arg1, int arg2, Object obj)
From source file:com.kakao.rest.APIHttpRequestTask.java
private static void failedToRefreshAccessToken(final APIHttpRequestTask requestTask, final HttpResponseHandler responseHandler, final String errorMsg) { String requestUrl = null;//from w ww . ja va 2 s .c o m if (requestTask != null && requestTask.request != null) requestUrl = requestTask.request.getUrl(); final APIErrorResult clientError = new APIErrorResult(requestUrl, errorMsg); responseHandler.sendMessage(Message.obtain(responseHandler, NEED_TO_LOGIN, 0, 0, clientError)); }
From source file:com.kakao.UserManagement.java
private static void request(final HttpResponseHandler<Map> responseHandler, final String url, final Map properties) { final HttpRequestBuilder requestBuilder = HttpRequestBuilder.get(url); APIHttpRequestTask.addCommon(requestBuilder); try {/*from ww w . j a v a 2 s.co m*/ APIHttpRequestTask.addQueryParam(requestBuilder, ServerProtocol.PROPERTIES_KEY, properties); APIHttpRequestTask.checkSessionAndExecute( new APIHttpRequestTask<Map>(requestBuilder.build(), responseHandler, Map.class), responseHandler); } catch (JSONException e) { responseHandler.sendMessage(Message.obtain(responseHandler, HttpRequestTask.ERROR, 0, 0, new APIErrorResult(requestBuilder.build().getUrl(), e.getMessage()))); } }
From source file:com.kakao.http.KakaoAsyncHandler.java
public void onThrowable(final Throwable t) { httpResponseHandler.sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.ERROR, 0, 0, new APIErrorResult(request.getUrl(), "error occurred during http request. t= " + t.toString()))); }
From source file:de.climbingguide.erzgebirsgrenzgebiet.downloader.DownloaderThread.java
/** * Connects to the URL of the file, begins the download, and notifies the * MainActivity activity of changes in state. Writes the file to * the root of the SD card./*ww w . j a v a 2 s . c o m*/ */ @Override public void run() { Message msg; //Delay, um auf eventuelle Verzgerung des Handlers zu warten try { Thread.sleep(500); } catch (InterruptedException e) { e.printStackTrace(); } // we're going to connect now msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_CONNECTING_STARTED, 0, 0, ""); activityHandler.sendMessage(msg); if (whichMap == OPENANDROMAPS) { if (ftpDownload(KleFuEntry.DOWNLOAD_FTP_SERVER_OA, KleFuEntry.DOWNLOAD_MAP_FTP_FILE_OA, "sachsen.zip")) { if (httpDownload(KleFuEntry.DOWNLOAD_THEME_URL, "Elevate.zip")) { // notify unzipping // msg = Message.obtain(activityHandler, // KleFuEntry.MESSAGE_UNZIP, 0, 0, ""); // activityHandler.sendMessage(msg); //unzip der Datei if (unpackZip(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY, "sachsen.zip")) { if (unpackZip(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY, "Elevate.zip")) { // notify completion (new File(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY + "Sachsen.zip")).delete(); (new File(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY + "Elevate.zip")).delete(); (new File(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY + "themes_locus.zip")).delete(); (new File(KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY + "themes_orux_new.zip")).delete(); msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_DOWNLOAD_COMPLETE); activityHandler.sendMessage(msg); } } } } // boolean status = ftpDownload("/pub/misc/openstreetmap/openandromaps/maps/Germany/sachsen.zip", fileName); } else if (whichMap == MAPSFORGE) { if (ftpDownload("ftp-stud.hs-esslingen.de", "/pub/Mirrors/download.mapsforge.org/maps/europe/germany/sachsen.map", "sachsen.map")) { // if (httpDownload(KleFuEntry.DOWNLOAD_HTTP_URL_SACHSEN, "sachsen.map")) { // notify completion msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_DOWNLOAD_COMPLETE); activityHandler.sendMessage(msg); } // boolean status = ftpDownload("/maps/europe/germany/sachsen.map", fileName); } }
From source file:com.google.android.apps.chrometophone.ShareLinkActivity.java
private void sendLink() { new Thread(new Runnable() { public void run() { sendToast(getString(R.string.sending_link_toast)); try { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("url", mPendingLink)); params.add(new BasicNameValuePair("deviceName", "Chrome")); SharedPreferences settings = Prefs.get(ShareLinkActivity.this); final String accountName = settings.getString("accountName", null); if (accountName == null) { sendToast(getString(R.string.link_not_sent_auth_toast)); finish();/*from w w w .j av a 2s .co m*/ return; } AppEngineClient client = new AppEngineClient(ShareLinkActivity.this, accountName); HttpResponse res = client.makeRequest(SEND_PATH, params); if (res.getStatusLine().getStatusCode() == 200) { sendToast(getString(R.string.link_sent_toast)); } else { sendToast(getString(R.string.link_not_sent_toast)); } finish(); } catch (AppEngineClient.PendingAuthException pae) { Intent authIntent = (Intent) pae.getAccountManagerBundle().get(AccountManager.KEY_INTENT); if (authIntent != null && !mPendingAuth) { mPendingAuth = true; mHandler.sendMessage(Message.obtain(mHandler, START_ACTIVITY_MSG, 0, 0, authIntent)); } else { sendToast(getString(R.string.link_not_sent_auth_toast)); finish(); } } catch (Exception e) { sendToast(getString(R.string.link_not_sent_toast)); finish(); } } }).start(); }
From source file:com.kakao.http.KakaoAsyncHandler.java
protected void sendError(final Response response, final String msg) { httpResponseHandler//w ww . ja va2 s.c o m .sendMessage(Message.obtain(httpResponseHandler, HttpRequestTask.ERROR, 0, 0, new APIErrorResult( request.getUrl(), "http status = " + response.getStatusText() + " msg = " + msg))); }
From source file:com.google.android.apps.chrometophone.ShareLinkActivity.java
private void sendToast(String toastMessage) { mHandler.sendMessage(Message.obtain(mHandler, TOAST_MSG, 0, 0, toastMessage)); }
From source file:com.kakao.rest.APIHttpRequestTask.java
protected void failedRequest(Exception e) { HttpResponseHandler.sendMessage(Message.obtain(HttpResponseHandler, ERROR, 0, 0, e)); }
From source file:de.climbingguide.erzgebirsgrenzgebiet.downloader.DownloaderThread.java
private Boolean ftpDownload(String ftpServer, String ftpPathName, String dateiname) { String fileName;/*from w w w . ja v a2 s .c o m*/ Message msg; try { ftpConnect(ftpServer, "anonymous", "", 21); fileName = KleFuEntry.DOWNLOAD_LOCAL_DIRECTORY; File file = new File(fileName); file.mkdirs(); fileName = fileName + dateiname; FTPFile[] ftpfile = mFTPClient.listFiles(ftpPathName); long fileSize = ftpfile[0].getSize(); // notify download start int fileSizeInKB = (int) (fileSize / 1024); msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_DOWNLOAD_STARTED, fileSizeInKB, 0, fileName); activityHandler.sendMessage(msg); BufferedInputStream inStream = new BufferedInputStream(mFTPClient.retrieveFileStream(ftpPathName)); File outFile = new File(fileName); FileOutputStream fileStream = new FileOutputStream(outFile); BufferedOutputStream outStream = new BufferedOutputStream(fileStream, KleFuEntry.DOWNLOAD_BUFFER_SIZE); byte[] data = new byte[KleFuEntry.DOWNLOAD_BUFFER_SIZE]; int bytesRead = 0, totalRead = 0; while (!isInterrupted() && (bytesRead = inStream.read(data, 0, data.length)) >= 0) { outStream.write(data, 0, bytesRead); // update progress bar totalRead += bytesRead; int totalReadInKB = totalRead / 1024; msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_UPDATE_PROGRESS_BAR, totalReadInKB, 0); activityHandler.sendMessage(msg); } outStream.close(); fileStream.close(); inStream.close(); if (isInterrupted()) { // the download was canceled, so let's delete the partially downloaded file outFile.delete(); ftpDisconnect(); return false; } else { ftpDisconnect(); return true; } } catch (Exception e) { String errMsg = parentActivity.getString(R.string.error_message_general); msg = Message.obtain(activityHandler, KleFuEntry.MESSAGE_ENCOUNTERED_ERROR, 0, 0, errMsg); activityHandler.sendMessage(msg); return false; } }