List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:com.aoeng.degu.utils.net.asyncthhpclient.AsyncHttpClient.java
/** * Puts a new request in queue as a new thread in pool to be executed * * @param client HttpClient to be used for request, can differ in single requests * @param contentType MIME body type, for POST and PUT requests, may be null * @param context Context of Android application, to hold the reference of request * @param httpContext HttpContext in which the request will be executed * @param responseHandler ResponseHandler or its subclass to put the response into * @param uriRequest instance of HttpUriRequest, which means it must be of HttpDelete, * HttpPost, HttpGet, HttpPut, etc. * @return RequestHandle of future request process *//*from w w w . j ava2 s . c o m*/ protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) { if (contentType != null) { uriRequest.setHeader("Content-Type", contentType); } responseHandler.setRequestHeaders(uriRequest.getAllHeaders()); responseHandler.setRequestURI(uriRequest.getURI()); Future<?> request = threadPool .submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler)); if (context != null) { // Add request to request map List<WeakReference<Future<?>>> requestList = requestMap.get(context); if (requestList == null) { requestList = new LinkedList<WeakReference<Future<?>>>(); requestMap.put(context, requestList); } requestList.add(new WeakReference<Future<?>>(request)); // TODO: Remove dead weakrefs from requestLists? } return new RequestHandle(request); }
From source file:cn.rongcloud.im.server.network.http.AsyncHttpClient.java
/** * Puts a new request in queue as a new thread in pool to be executed * * @param client HttpClient to be used for request, can differ in single requests * @param contentType MIME body type, for POST and PUT requests, may be null * @param context Context of Android application, to hold the reference of request * @param httpContext HttpContext in which the request will be executed * @param responseHandler ResponseHandler or its subclass to put the response into * @param uriRequest instance of HttpUriRequest, which means it must be of HttpDelete, * HttpPost, HttpGet, HttpPut, etc. * @return RequestHandle of future request process *//*w w w .j a v a 2 s . co m*/ protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) { if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); } responseHandler.setRequestHeaders(uriRequest.getAllHeaders()); responseHandler.setRequestURI(uriRequest.getURI()); Future<?> request = threadPool .submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler)); if (context != null) { // Add request to request map List<WeakReference<Future<?>>> requestList = requestMap.get(context); if (requestList == null) { requestList = new LinkedList<WeakReference<Future<?>>>(); requestMap.put(context, requestList); } requestList.add(new WeakReference<Future<?>>(request)); // TODO: Remove dead weakrefs from requestLists? } return new RequestHandle(request); }
From source file:com.lewa.crazychapter11.MainActivity.java
private void showTost(String content, int tostLength) { Toast mToast;/* w ww.ja va 2 s . com*/ if (mToastReference != null) { mToast = mToastReference.get(); if (mToast != null) { mToast.cancel(); mToastReference = null; } } mToast = Toast.makeText(MainActivity.this, content, tostLength); mToastReference = new WeakReference<Toast>(mToast); mToast.show(); }
From source file:com.android.gallery3d.v5.filtershow.FilterShowActivity.java
private void showSavingProgress(String albumName) { ProgressDialog progress;//from www . j a v a 2 s .c o m if (mSavingProgressDialog != null) { progress = mSavingProgressDialog.get(); if (progress != null) { progress.show(); return; } } // TODO: Allow cancellation of the saving process String progressText; progressText = getString(R.string.saving_image); if (albumName == null) { } else { progressText = getString(R.string.filtershow_saving_image, albumName); } progress = ProgressDialog.show(this, "", progressText, true, false); mSavingProgressDialog = new WeakReference<ProgressDialog>(progress); }
From source file:net.java.sip.communicator.plugin.notificationwiring.NotificationManager.java
/** * Fired when peer's state is changed// ww w. jav a 2s . co m * * @param ev fired CallPeerEvent */ public void peerStateChanged(CallPeerChangeEvent ev) { try { CallPeer peer = ev.getSourceCallPeer(); Call call = peer.getCall(); CallPeerState newState = (CallPeerState) ev.getNewValue(); CallPeerState oldState = (CallPeerState) ev.getOldValue(); // Play the dialing audio when in connecting and initiating call state. // Stop the dialing audio when we enter any other state. if ((newState == CallPeerState.INITIATING_CALL) || (newState == CallPeerState.CONNECTING)) { /* * The loopCondition will stay with the notification sound until * the latter is stopped. If by any chance the sound fails to * stop by the time the peer is no longer referenced, do try to * stop it then. That's why the loopCondition will weakly * reference the peer. */ final WeakReference<CallPeer> weakPeer = new WeakReference<CallPeer>(peer); /* We want to play the dialing once for multiple CallPeers. */ if (shouldPlayDialingSound(weakPeer)) { NotificationData notification = fireNotification(DIALING, new Callable<Boolean>() { public Boolean call() { return shouldPlayDialingSound(weakPeer); } }); if (notification != null) callNotifications.put(call, notification); } } else { NotificationData notification = callNotifications.get(call); if (notification != null) stopSound(notification); } if (newState == CallPeerState.ALERTING_REMOTE_SIDE //if we were already in state CONNECTING_WITH_EARLY_MEDIA the server //is already taking care of playing the notifications so we don't //need to fire a notification here. && oldState != CallPeerState.CONNECTING_WITH_EARLY_MEDIA) { final WeakReference<CallPeer> weakPeer = new WeakReference<CallPeer>(peer); NotificationData notification = fireNotification(OUTGOING_CALL, new Callable<Boolean>() { public Boolean call() { CallPeer peer = weakPeer.get(); return (peer != null) && CallPeerState.ALERTING_REMOTE_SIDE.equals(peer.getState()); } }); if (notification != null) callNotifications.put(call, notification); } else if (newState == CallPeerState.BUSY) { // We start the busy sound only if we're in a simple call. if (!isConference(call)) { final WeakReference<CallPeer> weakPeer = new WeakReference<CallPeer>(peer); NotificationData notification = fireNotification(BUSY_CALL, new Callable<Boolean>() { public Boolean call() { CallPeer peer = weakPeer.get(); return (peer != null) && CallPeerState.BUSY.equals(peer.getState()); } }); if (notification != null) callNotifications.put(call, notification); } } else if ((newState == CallPeerState.DISCONNECTED) || (newState == CallPeerState.FAILED)) { fireNotification(HANG_UP); } } catch (Throwable t) { if (t instanceof ThreadDeath) throw (ThreadDeath) t; else { logger.error( "An error occurred while trying to notify" + " about a change in the state of a call peer.", t); } } }
From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java
protected void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, CacheParams cacheParams, AsyncHttpResponseHandler responseHandler, Context context) {/*from w w w .j a va 2s .c om*/ if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); } Future<?> request = threadPool.submit( new AsyncHttpRequest(client, httpContext, uriRequest, cacheParams, responseHandler, context)); if (context != null) { // Add request to request map List<WeakReference<Future<?>>> requestList = requestMap.get(context); if (requestList == null) { requestList = new LinkedList<WeakReference<Future<?>>>(); requestMap.put(context, requestList); } requestList.add(new WeakReference<Future<?>>(request)); // TODO: Remove dead weakrefs from requestLists? } }
From source file:com.enjoy.nerd.http.AsyncHttpClient.java
/** * Puts a new request in queue as a new thread in pool to be executed * * @param client HttpClient to be used for request, can differ in single requests * @param contentType MIME body type, for POST and PUT requests, may be null * @param context Context of Android application, to hold the reference of request * @param httpContext HttpContext in which the request will be executed * @param responseHandler ResponseHandler or its subclass to put the response into * @param uriRequest instance of HttpUriRequest, which means it must be of HttpDelete, * HttpPost, HttpGet, HttpPut, etc. * @return RequestHandle of future request process *///from w w w . j ava 2 s. co m protected RequestHandle sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, ResponseHandlerInterface responseHandler, Context context) { if (contentType != null) { uriRequest.setHeader("Content-Type", contentType); } responseHandler.setRequestHeaders(uriRequest.getAllHeaders()); responseHandler.setRequestURI(uriRequest.getURI()); //tangwh add, ?????cookie?cookie?setCookieStore?uriRequestHeader? //??http2Cookie???cookieStore client.setCookieStore(null); Future<?> request = threadPool .submit(new AsyncHttpRequest(client, httpContext, uriRequest, responseHandler)); if (context != null) { // Add request to request map List<WeakReference<Future<?>>> requestList = requestMap.get(context); if (requestList == null) { requestList = new LinkedList<WeakReference<Future<?>>>(); requestMap.put(context, requestList); } requestList.add(new WeakReference<Future<?>>(request)); // TODO: Remove dead weakrefs from requestLists? } return new RequestHandle(request); }
From source file:com.android.mail.utils.NotificationUtils.java
private static Bitmap getDefaultWearableBg(Context context) { Bitmap bg = sDefaultWearableBg.get(); if (bg == null) { bg = BitmapFactory.decodeResource(context.getResources(), R.drawable.bg_email); sDefaultWearableBg = new WeakReference<>(bg); }// w ww .ja v a 2s . c o m return bg; }
From source file:com.gargoylesoftware.htmlunit.WebClient.java
/** * <span style="color:red">INTERNAL API - SUBJECT TO CHANGE AT ANY TIME - USE AT YOUR OWN RISK.</span><br> * * Adds a new window to the list of available windows. * * @param webWindow the new WebWindow//from w ww . j a va2s.co m */ public void registerWebWindow(final WebWindow webWindow) { WebAssert.notNull("webWindow", webWindow); windows_.add(webWindow); // register JobManager here but don't deregister in deregisterWebWindow as it can live longer jobManagers_.add(new WeakReference<>(webWindow.getJobManager())); }
From source file:com.corebase.android.framework.http.client.AsyncHttpClient.java
/** * post// w w w. j av a 2 s . c o m * * @param client * @param httpContext * @param uriRequest * @param contentType * @param cacheParams * @param responseHandler * @param context * @param requestParam */ protected void sendRequestPost(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, CacheParams cacheParams, AsyncHttpResponseHandler responseHandler, Context context, String requestParam) { if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); } Future<?> request = threadPool.submit(new AsyncHttpRequest(client, httpContext, uriRequest, cacheParams, responseHandler, context, requestParam)); if (context != null) { // Add request to request map List<WeakReference<Future<?>>> requestList = requestMap.get(context); if (requestList == null) { requestList = new LinkedList<WeakReference<Future<?>>>(); requestMap.put(context, requestList); } requestList.add(new WeakReference<Future<?>>(request)); // TODO: Remove dead weakrefs from requestLists? } }