List of usage examples for java.lang.ref WeakReference WeakReference
public WeakReference(T referent)
From source file:ch.entwine.weblounge.common.impl.request.WebloungeResponseImpl.java
/** * {@inheritDoc}/*w ww . j a v a 2 s .c o m*/ * * @see ch.entwine.weblounge.common.request.WebloungeResponse#startResponse(ch.entwine.weblounge.common.request.CacheTag[], * long, long) */ public boolean startResponse(CacheTag[] tags, long expirationTime, long revalidationTime) throws IllegalStateException { if (!isValid || cache == null) return false; ResponseCache cache = this.cache.get(); if (cache == null) return false; if (cacheHandle != null) throw new IllegalStateException("The response is already being cached"); // Is the response in the cache? CacheHandle hdl = cache.startResponse(tags, request.get(), this, expirationTime, revalidationTime); if (hdl == null) return true; // It's not, meaning we need to do the processing ourselves cacheHandle = new WeakReference<CacheHandle>(hdl); return false; }
From source file:ti.modules.titanium.geolocation.GeolocationModule.java
private TiGeoHelper getHelperForContext(TiContext context, GeoFeature feature, boolean createIfMissing) { ArrayList<TiGeoHelper> helpers = null; if (contextGeoHelpers.containsKey(context)) { helpers = contextGeoHelpers.get(context); if (helpers == null) { contextGeoHelpers.remove(context); }//from ww w . ja v a 2s . com } if (helpers == null && !createIfMissing) { return null; } if (helpers == null) { helpers = new ArrayList<TiGeoHelper>(2); contextGeoHelpers.put(new WeakReference<TiContext>(context), helpers); } TiGeoHelper result = null; for (TiGeoHelper helper : helpers) { if (helper.getFeature() == feature) { result = helper; break; } } if (result == null && createIfMissing) { result = TiGeoHelper.getInstance(context, this, feature); helpers.add(result); } return result; }
From source file:com.baidu.asynchttpclient.AsyncHttpClient.java
public WeakReference<Future<?>> get(Context context, String url, RequestParams params, Map<String, String> headers, AsyncHttpResponseHandler responseHandler) { HttpGet getMethod = new HttpGet(getUrlWithQueryString(url, params)); if (headers != null) { Set<Entry<String, String>> entrys = headers.entrySet(); Iterator<Entry<String, String>> itertor = entrys.iterator(); while (itertor.hasNext()) { Entry<String, String> entry = itertor.next(); getMethod.addHeader(entry.getKey(), entry.getValue()); }//from w ww . ja v a2 s . co m } return new WeakReference<Future<?>>( sendRequest(httpClient, httpContext, getMethod, null, responseHandler, context)); }
From source file:com.sworddance.taskcontrol.TaskGroup.java
/** * @return true if there is a task in this TaskGroup that is ready to run *//*from ww w. j av a2s. com*/ @SuppressWarnings("unchecked") public boolean isTaskReady() { if (isShutdown()) { return false; } synchronized (tasksToBeRun) { List<PrioritizedTask> eligibleTasks = resourceManager.getUnblockedTasks(); eligibleTasks.addAll(locklessTasks); boolean newDeadTasks; // go through this loop until there are no more deadTasks found. // this also makes sure that tasks that have 'always' run dependency // on a task will be in the correct state. // unless we repeat on finding a dead task we may not be if the // dependent // task occurs later in tasksToBeRun list do { newDeadTasks = false; for (PrioritizedTask task : eligibleTasks) { if (task == null) { // should never happen tasksToBeRun.remove(null); } // skip tasks that may be running (and thus have not release // their locks) else if (!tasksToBeRun.contains(task)) { continue; } else if (task.isReadyToRun()) { this.lastEligibleTask = new WeakReference<PrioritizedTask>(task); // exiting here may mean that tasks that are now "neverEligible" to // be run don't get a chance to set their "neverEligible" state. .. but // that should be o.k. return true; } else if (task.isNeverEligibleToRun()) { deadTasks.add(task); warning(task.getName() + ": Declaring itself never eligible to run. Moved to dead pool"); newDeadTasks = true; tasksToBeRun.remove(task); } else if (task.isDone()) { // has a result without being run. // most such cases should be caught by above code. deadTasks.add(task); newDeadTasks = true; warning(task.getName() + ": has result but has never run. Moved to dead pile."); tasksToBeRun.remove(task); } } } while (newDeadTasks); return false; } }
From source file:net.sf.maltcms.common.charts.api.overlay.AbstractChartOverlay.java
/** * * @return//from ww w . j a v a 2s. c o m */ @Override public Node createNodeDelegate() { Node node = null; if (nodeReference == null) { node = overlayNode(this, Children.LEAF, lookup); nodeReference = new WeakReference<>(node); } else { node = nodeReference.get(); if (node == null) { node = overlayNode(this, Children.LEAF, lookup); nodeReference = new WeakReference<>(node); } } return node; }
From source file:com.vk.sdk.api.VKRequest.java
/** * Method used for response processing/*from w ww.j a va 2 s . com*/ * * @param jsonResponse response from API * @param parsedModel model parsed from json */ private void provideResponse(final JSONObject jsonResponse, Object parsedModel) { final VKResponse response = new VKResponse(); response.request = this; response.json = jsonResponse; response.parsedModel = parsedModel; this.response = new WeakReference<VKResponse>(response); if (mLoadingOperation instanceof VKHttpOperation) { response.responseString = ((VKHttpOperation) mLoadingOperation).getResponseString(); } runOnLooper(new Runnable() { @Override public void run() { if (mPostRequestsQueue != null && mPostRequestsQueue.size() > 0) { for (final VKRequest request : mPostRequestsQueue) { request.start(); } } if (requestListener != null) { requestListener.onComplete(response); } } }); }
From source file:com.appbase.androidquery.callback.AbstractAjaxCallback.java
public K progress(Object progress) { if (progress != null) { this.progress = new WeakReference<Object>(progress); }//from ww w . j a v a 2s.com return self(); }
From source file:com.creativtrendz.folio.ui.FolioWebViewScroll.java
@SuppressLint({ "SetJavaScriptEnabled" }) protected void init(Context context) { if (context instanceof Activity) { mActivity = new WeakReference<>((Activity) context); }//from w w w. j a v a 2s . c o m mLanguageIso3 = getLanguageIso3(); setFocusable(true); setFocusableInTouchMode(true); setSaveEnabled(true); final String filesDir = context.getFilesDir().getPath(); final String databaseDir = filesDir.substring(0, filesDir.lastIndexOf("/")) + DATABASES_SUB_FOLDER; final WebSettings webSettings = getSettings(); webSettings.setAllowFileAccess(false); setAllowAccessFromFileUrls(webSettings, false); webSettings.setBuiltInZoomControls(false); webSettings.setJavaScriptEnabled(true); webSettings.setDomStorageEnabled(true); if (Build.VERSION.SDK_INT < 18) { webSettings.setRenderPriority(WebSettings.RenderPriority.HIGH); } webSettings.setDatabaseEnabled(true); if (Build.VERSION.SDK_INT < 19) { webSettings.setDatabasePath(databaseDir); } setMixedContentAllowed(webSettings, true); setThirdPartyCookiesEnabled(true); super.setWebViewClient(new WebViewClient() { @Override public void onPageStarted(WebView view, String url, Bitmap favicon) { if (!hasError()) { if (mListener != null) { mListener.onPageStarted(url, favicon); } } if (mCustomWebViewClient != null) { mCustomWebViewClient.onPageStarted(view, url, favicon); } } @Override public void onPageFinished(WebView view, String url) { if (!hasError()) { if (mListener != null) { mListener.onPageFinished(url); } } if (mCustomWebViewClient != null) { mCustomWebViewClient.onPageFinished(view, url); } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { setLastError(); if (mListener != null) { mListener.onPageError(errorCode, description, failingUrl); } if (mCustomWebViewClient != null) { mCustomWebViewClient.onReceivedError(view, errorCode, description, failingUrl); } } @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { if (isHostnameAllowed(url)) { return mCustomWebViewClient != null && mCustomWebViewClient.shouldOverrideUrlLoading(view, url); } else { if (mListener != null) { mListener.onExternalPageRequest(url); } return true; } } @Override public void onLoadResource(WebView view, String url) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onLoadResource(view, url); } else { super.onLoadResource(view, url); } } @SuppressLint("NewApi") @SuppressWarnings("all") public WebResourceResponse shouldInterceptRequest(WebView view, String url) { if (Build.VERSION.SDK_INT >= 11) { if (mCustomWebViewClient != null) { return mCustomWebViewClient.shouldInterceptRequest(view, url); } else { return super.shouldInterceptRequest(view, url); } } else { return null; } } @SuppressLint("NewApi") @SuppressWarnings("all") public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) { if (Build.VERSION.SDK_INT >= 21) { if (mCustomWebViewClient != null) { return mCustomWebViewClient.shouldInterceptRequest(view, request); } else { return super.shouldInterceptRequest(view, request); } } else { return null; } } @Override public void onFormResubmission(WebView view, Message dontResend, Message resend) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onFormResubmission(view, dontResend, resend); } else { super.onFormResubmission(view, dontResend, resend); } } @Override public void doUpdateVisitedHistory(WebView view, String url, boolean isReload) { if (mCustomWebViewClient != null) { mCustomWebViewClient.doUpdateVisitedHistory(view, url, isReload); } else { super.doUpdateVisitedHistory(view, url, isReload); } } @Override public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onReceivedSslError(view, handler, error); } else { super.onReceivedSslError(view, handler, error); } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onReceivedClientCertRequest(WebView view, ClientCertRequest request) { if (Build.VERSION.SDK_INT >= 21) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onReceivedClientCertRequest(view, request); } else { super.onReceivedClientCertRequest(view, request); } } } @Override public void onReceivedHttpAuthRequest(WebView view, HttpAuthHandler handler, String host, String realm) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onReceivedHttpAuthRequest(view, handler, host, realm); } else { super.onReceivedHttpAuthRequest(view, handler, host, realm); } } @Override public boolean shouldOverrideKeyEvent(WebView view, KeyEvent event) { if (mCustomWebViewClient != null) { return mCustomWebViewClient.shouldOverrideKeyEvent(view, event); } else { return super.shouldOverrideKeyEvent(view, event); } } @Override public void onUnhandledKeyEvent(WebView view, KeyEvent event) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onUnhandledKeyEvent(view, event); } else { super.onUnhandledKeyEvent(view, event); } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onUnhandledInputEvent(WebView view, InputEvent event) { if (Build.VERSION.SDK_INT >= 21) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onUnhandledInputEvent(view, event); } else { super.onUnhandledInputEvent(view, event); } } } @Override public void onScaleChanged(WebView view, float oldScale, float newScale) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onScaleChanged(view, oldScale, newScale); } else { super.onScaleChanged(view, oldScale, newScale); } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onReceivedLoginRequest(WebView view, String realm, String account, String args) { if (Build.VERSION.SDK_INT >= 12) { if (mCustomWebViewClient != null) { mCustomWebViewClient.onReceivedLoginRequest(view, realm, account, args); } else { super.onReceivedLoginRequest(view, realm, account, args); } } } }); super.setWebChromeClient(new WebChromeClient() { // file upload callback (Android 2.2 (API level 8) -- Android 2.3 (API level 10)) (hidden method) @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg) { openFileChooser(uploadMsg, null); } // file upload callback (Android 3.0 (API level 11) -- Android 4.0 (API level 15)) (hidden method) public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType) { openFileChooser(uploadMsg, acceptType, null); } // file upload callback (Android 4.1 (API level 16) -- Android 4.3 (API level 18)) (hidden method) @SuppressWarnings("unused") public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) { openFileInput(uploadMsg, null); } // file upload callback (Android 5.0 (API level 21) -- current) (public method) @SuppressWarnings("all") public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback, WebChromeClient.FileChooserParams fileChooserParams) { openFileInput(null, filePathCallback); return true; } @Override public void onProgressChanged(WebView view, int newProgress) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onProgressChanged(view, newProgress); } else { super.onProgressChanged(view, newProgress); } } @Override public void onReceivedTitle(WebView view, String title) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onReceivedTitle(view, title); } else { super.onReceivedTitle(view, title); } } @Override public void onReceivedIcon(WebView view, Bitmap icon) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onReceivedIcon(view, icon); } else { super.onReceivedIcon(view, icon); } } @Override public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onReceivedTouchIconUrl(view, url, precomposed); } else { super.onReceivedTouchIconUrl(view, url, precomposed); } } @Override public void onShowCustomView(View view, CustomViewCallback callback) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onShowCustomView(view, callback); } else { super.onShowCustomView(view, callback); } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onShowCustomView(View view, int requestedOrientation, CustomViewCallback callback) { if (Build.VERSION.SDK_INT >= 14) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onShowCustomView(view, requestedOrientation, callback); } else { super.onShowCustomView(view, requestedOrientation, callback); } } } @Override public void onHideCustomView() { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onHideCustomView(); } else { super.onHideCustomView(); } } @Override public boolean onCreateWindow(WebView view, boolean isDialog, boolean isUserGesture, Message resultMsg) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onCreateWindow(view, isDialog, isUserGesture, resultMsg); } else { return super.onCreateWindow(view, isDialog, isUserGesture, resultMsg); } } @Override public void onRequestFocus(WebView view) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onRequestFocus(view); } else { super.onRequestFocus(view); } } @Override public void onCloseWindow(WebView window) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onCloseWindow(window); } else { super.onCloseWindow(window); } } @Override public boolean onJsAlert(WebView view, String url, String message, JsResult result) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onJsAlert(view, url, message, result); } else { return super.onJsAlert(view, url, message, result); } } @Override public boolean onJsConfirm(WebView view, String url, String message, JsResult result) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onJsConfirm(view, url, message, result); } else { return super.onJsConfirm(view, url, message, result); } } @Override public boolean onJsPrompt(WebView view, String url, String message, String defaultValue, JsPromptResult result) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onJsPrompt(view, url, message, defaultValue, result); } else { return super.onJsPrompt(view, url, message, defaultValue, result); } } @Override public boolean onJsBeforeUnload(WebView view, String url, String message, JsResult result) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onJsBeforeUnload(view, url, message, result); } else { return super.onJsBeforeUnload(view, url, message, result); } } @Override public void onGeolocationPermissionsShowPrompt(String origin, Callback callback) { if (mGeolocationEnabled) { callback.invoke(origin, true, false); } else { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onGeolocationPermissionsShowPrompt(origin, callback); } else { super.onGeolocationPermissionsShowPrompt(origin, callback); } } } @Override public void onGeolocationPermissionsHidePrompt() { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onGeolocationPermissionsHidePrompt(); } else { super.onGeolocationPermissionsHidePrompt(); } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onPermissionRequest(PermissionRequest request) { if (Build.VERSION.SDK_INT >= 21) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onPermissionRequest(request); } else { super.onPermissionRequest(request); } } } @SuppressLint("NewApi") @SuppressWarnings("all") public void onPermissionRequestCanceled(PermissionRequest request) { if (Build.VERSION.SDK_INT >= 21) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onPermissionRequestCanceled(request); } else { super.onPermissionRequestCanceled(request); } } } @Override public boolean onJsTimeout() { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onJsTimeout(); } else { return super.onJsTimeout(); } } @Override public void onConsoleMessage(String message, int lineNumber, String sourceID) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onConsoleMessage(message, lineNumber, sourceID); } else { super.onConsoleMessage(message, lineNumber, sourceID); } } @Override public boolean onConsoleMessage(ConsoleMessage consoleMessage) { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.onConsoleMessage(consoleMessage); } else { return super.onConsoleMessage(consoleMessage); } } @Override public Bitmap getDefaultVideoPoster() { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.getDefaultVideoPoster(); } else { return super.getDefaultVideoPoster(); } } @Override public View getVideoLoadingProgressView() { if (mCustomWebChromeClient != null) { return mCustomWebChromeClient.getVideoLoadingProgressView(); } else { return super.getVideoLoadingProgressView(); } } @Override public void getVisitedHistory(ValueCallback<String[]> callback) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.getVisitedHistory(callback); } else { super.getVisitedHistory(callback); } } @Override public void onExceededDatabaseQuota(String url, String databaseIdentifier, long quota, long estimatedDatabaseSize, long totalQuota, QuotaUpdater quotaUpdater) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onExceededDatabaseQuota(url, databaseIdentifier, quota, estimatedDatabaseSize, totalQuota, quotaUpdater); } else { super.onExceededDatabaseQuota(url, databaseIdentifier, quota, estimatedDatabaseSize, totalQuota, quotaUpdater); } } @Override public void onReachedMaxAppCacheSize(long requiredStorage, long quota, QuotaUpdater quotaUpdater) { if (mCustomWebChromeClient != null) { mCustomWebChromeClient.onReachedMaxAppCacheSize(requiredStorage, quota, quotaUpdater); } else { super.onReachedMaxAppCacheSize(requiredStorage, quota, quotaUpdater); } } }); setDownloadListener(new DownloadListener() { @Override public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) { if (mListener != null) { mListener.onDownloadRequested(url, userAgent, contentDisposition, mimetype, contentLength); } } }); }
From source file:it.openutils.mgnlaws.magnolia.datastore.S3DataStore.java
/** * Add WeakReference to inUse Map/*from ww w.java 2 s. c o m*/ * @param identifier The DataIdentifier */ private void usesIdentifier(DataIdentifier identifier) { inUse.put(identifier, new WeakReference<DataIdentifier>(identifier)); }
From source file:com.baseproject.image.ImageWorker.java
/** * Called when the processing is complete and the final bitmap should be set * on the ImageView.// w w w .j a va2 s . c o m * * @param imageView * @param bitmap */ @SuppressWarnings("deprecation") @SuppressLint("NewApi") private void setImageBitmap(ImageView imageView, Bitmap bitmap) { if (mFadeInBitmap) { if (imageView.getTag() instanceof String && "no_animation".equals(String.valueOf(imageView.getTag()))) { imageView.setImageBitmap(bitmap); } else { // Transition drawable with a transparent drwabale and the final // bitmap TransitionDrawable td = new TransitionDrawable( new Drawable[] { new ColorDrawable(android.R.color.transparent), new BitmapDrawable(mContext.getResources(), bitmap) }); final WeakReference<TransitionDrawable> tdReference = new WeakReference<TransitionDrawable>(td); td = null; // Set background to loading bitmap final BitmapDrawable bd = new BitmapDrawable(mContext.getResources(), mLoadingBitmap); if (Build.VERSION.SDK_INT >= 16) { imageView.setBackground(bd); } else { imageView.setBackgroundDrawable(bd); } if (null != tdReference.get()) { imageView.setImageDrawable(tdReference.get()); tdReference.get().startTransition(FADE_IN_TIME); } } } else { imageView.setImageBitmap(bitmap); } }