List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:com.hippoapp.asyncmvp.http.AsyncHttpClient.java
private void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, IAsyncHttpResponseHandler responseHandler, Context context, int protocol, int cacheProtocol, String cacheId) { if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); }//from w w w .j a v a 2 s. co m Future request = threadPool.submit(new AsyncCachedHttpRequest(client, httpContext, uriRequest, responseHandler, protocol, cacheProtocol, cacheId)); // TODO if use application context there is no need to check 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.android.leanlauncher.LauncherModel.java
/** * Set this as the current Launcher activity object for the loader. */// w ww. j a v a 2 s . c om public void initialize(Callbacks callbacks) { synchronized (mLock) { mCallbacks = new WeakReference<Callbacks>(callbacks); } }
From source file:com.baidu.asynchttpclient.AsyncHttpClient.java
private Future<?> sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, Context context) { if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); }/* w w w. j a v a2s .c om*/ /* * ------------------ http header ----------------- uriRequest.addHeader("Platform", "8"); // ? 1=IOS * 8=Android uriRequest.addHeader("SDKVersion", NdCommplatformExtends.getInstance().getVersion()); // SDK?? * uriRequest.addHeader("FWVersion", Utils.getDeviceSDKVersion()); // ? String model = * android.os.Build.MODEL; if(!TextUtils.isEmpty(model)) { if(model.length() > 10) { model = * model.substring(model.length() - 10); } uriRequest.addHeader("PhoneType", model); // ?(N97, Touch * HD10??10) } uriRequest.addHeader("Resolution", ScreenUtil.screen_width(context) + "x" + * ScreenUtil.screen_height(context)); // x640x960 uriRequest.addHeader("Network", * Utils.isWifi(context)? "1" : "0"); // 0=?WIFI 1=WIFI /* ------------------ http header * ----------------- */ 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 request; }
From source file:com.folioreader.ui.folio.activity.FolioActivity.java
@Override public WeakReference<FolioActivity> getActivity() { return new WeakReference<>(this); }
From source file:org.sakaiproject.iclicker.logic.IClickerLogic.java
/** * Executes the add or remove tool workspace operation * @param type the type of runner to make, from BigRunner.RUNNER_TYPE_* * @return the runner object indicating progress * @throws IllegalArgumentException if the runner type is unknown * @throws IllegalStateException if there is a runner in progress of a different type * @throws ClickerLockException if a lock cannot be obtained */// ww w . j ava 2s . c o m public BigRunner startRunnerOperation(String type) { BigRunner runner = getRunnerStatus(); if (runner != null) { // allow the runner to be cleared if done if (runner.isComplete()) { runner = null; } else { if (!type.equals(runner.getType())) { throw new IllegalStateException( "Already running a big runner of a different type: " + runner.getType()); } } } if (runner == null) { // try to obtain a lock Boolean gotLock = dao.obtainLock(BigRunner.RUNNER_LOCK, serverId, 600000); // expire 10 mins if (gotLock != null && gotLock) { if (BigRunner.RUNNER_TYPE_ADD.equalsIgnoreCase(type)) { runner = getExternalLogic().makeAddToolToWorkspacesRunner(ICLICKER_TOOL_ID, workspacePageTitle, null); } else if (BigRunner.RUNNER_TYPE_REMOVE.equalsIgnoreCase(type)) { runner = getExternalLogic().makeRemoveToolFromWorkspacesRunner(ICLICKER_TOOL_ID); } else { throw new IllegalArgumentException("Unknown type of runner operation: " + type); } final BigRunner bigRunner = runner; Runnable runnable = new Runnable() { public void run() { try { bigRunner.run(); } catch (Exception e) { String msg = "long running process (" + bigRunner + ") failure: " + e; sendNotification(msg, e); log.warn(msg, e); // sleep for 5 secs to hold the error state so it can be checked try { Thread.sleep(5000); } catch (InterruptedException e1) { // nothing to do here } } finally { clearRunner(); // when done dao.releaseLock(BigRunner.RUNNER_LOCK, serverId); } } }; new Thread(runnable).start(); // start up a thread to run this log.info("Starting new long running process (" + runner + ")"); this.runnerHolder = new WeakReference<BigRunner>(runner); } else { // failed to obtain the lock String msg = "Could not obtain a lock (" + BigRunner.RUNNER_LOCK + ") on server (" + serverId + "): " + gotLock; log.info(msg); throw new ClickerLockException(msg, BigRunner.RUNNER_LOCK, serverId); } } return runner; }
From source file:biz.laenger.android.vpbs.ViewPagerBottomSheetBehavior.java
private View findAllScrollableChild(View view) { if (view instanceof NestedScrollingChild) { return view; }/* w w w. j av a 2s. c o m*/ if (view instanceof ViewPager) { ViewPager viewPager = ((ViewPager) view); for (int c = 0; c < viewPager.getChildCount(); c++) { View currentViewPagerChild = viewPager.getChildAt(c); if (currentViewPagerChild != null) { View scrollingChild = findAllScrollableChild(currentViewPagerChild); if (scrollingChild != null) { scrollableViews.add(new WeakReference<View>(scrollingChild)); } } } } else if (view instanceof ViewGroup) { ViewGroup group = (ViewGroup) view; for (int i = 0, count = group.getChildCount(); i < count; i++) { View scrollingChild = findAllScrollableChild(group.getChildAt(i)); if (scrollingChild != null) { scrollableViews.add(new WeakReference<>(scrollingChild)); } } } return null; }
From source file:com.heyzap.http.AsyncHttpClient.java
private void sendRequest(DefaultHttpClient client, HttpContext httpContext, HttpUriRequest uriRequest, String contentType, AsyncHttpResponseHandler responseHandler, Context context) { if (contentType != null) { uriRequest.addHeader("Content-Type", contentType); }/*from w w w . j av a 2 s. c o m*/ 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)); } }
From source file:com.benefit.buy.library.http.query.callback.AbstractAjaxCallback.java
/** * Starts the async process. If activity is passed, the callback method will not be invoked if the activity is no * longer in use. Specifically, isFinishing() is called to determine if the activity is active. * @param act activity/*from ww w . ja v a2 s.c o m*/ */ public void async(Activity act) { if (act.isFinishing()) { AQUtility.warn("Warning", "Possible memory leak. Calling ajax with a terminated activity."); } if (type == null) { AQUtility.warn("Warning", "type() is not called with response type."); return; } this.act = new WeakReference<Activity>(act); async((Context) act); }
From source file:uk.ac.horizon.ug.exploding.client.BackgroundThread.java
/** check */ private static synchronized void checkThread(Context context) { if (currentClientState == null) currentClientState = new ClientState(ClientStatus.CONFIGURING, GameStatus.UNKNOWN); // if (singleton==null || !singleton.isAlive()) { // Log.i(TAG, (singleton!=null ? "(Re)": "")+"starting background thread"); // singleton = new Thread(new BackgroundThread()); // singleton.start(); // }/*from w w w . j a va 2s . c o m*/ if (contextRef == null || contextRef.get() == null) { contextRef = new WeakReference<Context>(context); // PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(new SharedPreferenceChangeListener()); } // TODO }
From source file:com.appbase.androidquery.callback.AbstractAjaxCallback.java
/** * Starts the async process. /*from w ww. j av a 2 s .c om*/ * * If activity is passed, the callback method will not be invoked if the activity is no longer in use. * Specifically, isFinishing() is called to determine if the activity is active. * * @param act activity */ public void async(Activity act) { if (act.isFinishing()) { AQUtility.warn("Warning", "Possible memory leak. Calling ajax with a terminated activity."); } if (type == null) { AQUtility.warn("Warning", "type() is not called with response type."); return; } this.act = new WeakReference<Activity>(act); async((Context) act); }