android.support.v4.os.AsyncTaskCompat Java Examples
The following examples show how to use
android.support.v4.os.AsyncTaskCompat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ScreenCaptureSocket.java From pc-android-controller-android with Apache License 2.0 | 6 votes |
/** * 开始截图. 获取 image 面板上的图片. */ private void startCapture() { Image image = null; try { try { finalize(); } catch (Throwable throwable) { throwable.printStackTrace(); } image = mImageReader.acquireLatestImage(); } catch (Exception e) { e.printStackTrace(); } if (image == null) { L.e(" 获取 image 为空 结束.."); return; } else { SaveTask mSaveTask = new SaveTask(); AsyncTaskCompat.executeParallel(mSaveTask, image); } }
Example #2
Source File: ExifViewerFragment.java From support with Apache License 2.0 | 6 votes |
private void decodeWith(ExifDecoder decoder) { AsyncTaskCompat.executeParallel(new AsyncTask<ExifDecoder, Void, ExifBean>() { @Override protected ExifBean doInBackground(ExifDecoder... params) { return new ExifBean(params[0].decodeBitmap(), params[0].extractExif()); } @Override protected void onPostExecute(ExifBean exifBean) { if (exifBean.bitmap != null) { mImageView.setImageBitmap(exifBean.bitmap); } if (exifBean.value != null) { mTextView.setText(exifBean.value); } } }, decoder); }
Example #3
Source File: ZhifubaoHelper.java From android-common-utils with Apache License 2.0 | 6 votes |
public void pay(Activity activity,final String orderId, final String productName ,final String productDesc, final String price, final String notifyUrl ,IZhifubaoPayCallback callback){ if(mProcessing.get()){ callback.onError("zhifubao pay is processing."); return ; } mProcessing.set(true); this.mWeakActivity = new WeakReference<>(activity); this.mCallback = callback; CheckTask task = new CheckTask(mTaskManager) { @Override protected void onZhifubaoExist() { doPay(orderId, productName, productDesc, price, notifyUrl); } }; AsyncTaskCompat.executeParallel(task,activity); }
Example #4
Source File: ScreenShotActivity.java From TVRemoteIME with GNU General Public License v2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.KITKAT) public void startScreenShot() { virtualDisplay(); Handler handler = new Handler(); handler.postDelayed(new Runnable() { @Override public void run() { Image image = mImageReader.acquireLatestImage(); AsyncTaskCompat.executeParallel(new ScreenShotSaveTask(), image); } }, 300); }
Example #5
Source File: FloatWindowsService.java From ScreenCapture with Apache License 2.0 | 5 votes |
private void startCapture() { Image image = mImageReader.acquireLatestImage(); if (image == null) { startScreenShot(); } else { SaveTask mSaveTask = new SaveTask(); AsyncTaskCompat.executeParallel(mSaveTask, image); } }
Example #6
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 5 votes |
public void shareWebUrl(final String imgUrl,final String shareUrl, final String title,final String desc, final boolean shareToFriendCircle,final IWXShareCallback callback){ AsyncTask2<Void,Void,Bitmap> task = new AsyncTask2<Void, Void, Bitmap>(mTaskManager) { @Override protected Bitmap doInBackground(Void... params) { try { return new ImageParser(THUMB_SIZE,THUMB_SIZE).parseToBitmap( IoUtil.getBytesFromStreamAndClose(new URL(imgUrl).openStream())); } catch (IOException e) { System.out.println("share_img: url = " + imgUrl); e.printStackTrace(); } return null; } @Override protected void onPostExecute(Bitmap bitmap) { if(bitmap == null){ if(callback != null){ callback.onShareFailed("get image bitmap from url failed !"); } }else{ shareWebUrlWithIcon(bitmap, shareUrl, title, desc, shareToFriendCircle, callback); } super.onPostExecute(bitmap); } }; AsyncTaskCompat.executeParallel(task); }
Example #7
Source File: ZhifubaoHelper.java From android-common-utils with Apache License 2.0 | 5 votes |
private void doPay(String orderId,String productName, String productDesc, String price,String notifyUrl) { String orderInfo = getOrderInfo(orderId,productName,productDesc,price,notifyUrl); // 对订单做RSA 签名 String sign = SignUtil.sign(orderInfo, SdkFactory.PayConfig.sZhifubao_rsa_key); sign = Util.urlEncode(sign); if(sign == null){ onPayFailed("sign urlencode failed"); return; } // 完整的符合支付宝参数规范的订单信息 final String payInfo = orderInfo + "&sign=\"" + sign + "\"&" + getSignType(); AsyncTaskCompat.executeParallel(new InternalPayTask(mTaskManager), payInfo); }
Example #8
Source File: IconFactory.java From HeadsUp with GNU General Public License v2.0 | 5 votes |
@NonNull public static AsyncTask<Void, Void, Bitmap> generateAsync(final @NonNull Context context, final @NonNull OpenNotification notification, final @NonNull IconAsyncListener listener) { return (AsyncTask<Void, Void, Bitmap>) AsyncTaskCompat.executeParallel( new AsyncTask<Void, Void, Bitmap>() { @Override protected Bitmap doInBackground(Void... params) { final long start = SystemClock.elapsedRealtime(); Bitmap output = generate(context, notification); if (DEBUG) { long delta = SystemClock.elapsedRealtime() - start; Log.d(TAG, "Notification icon created in " + delta + " millis:" + " width=" + output.getWidth() + " height=" + output.getHeight()); } return output; } @Override protected void onPostExecute(Bitmap bitmap) { super.onPostExecute(bitmap); listener.onGenerated(bitmap); } }); }
Example #9
Source File: ReCaptcha.java From Android-Lib-reCAPTCHA with Apache License 2.0 | 5 votes |
/** * Checks asynchronously whether the answer entered by the user is correct after your application * is successfully displaying <a href="https://developers.google.com/recaptcha/">reCAPTCHA</a>. * @param privateKey The private key that is unique to your domain and sub-domains (unless it is a global key). * @param answer The string the user entered to solve the <a href="http://captcha.net/">CAPTCHA</a> displayed. * @param listener The callback to call when an answer entered by the user is verified. */ @UiThread public final void verifyAnswerAsync(@NonNull final String privateKey, @NonNull final String answer, @Nullable final ReCaptcha.OnVerifyAnswerListener listener) { if (TextUtils.isEmpty(privateKey)) { throw new IllegalArgumentException("privateKey cannot be null or empty"); } if (TextUtils.isEmpty(answer)) { throw new IllegalArgumentException("answer cannot be null or empty"); } AsyncTaskCompat.executeParallel(new AsyncTask<String, Void, Boolean>() { @Override protected Boolean doInBackground(final String... params) { try { return ReCaptcha.this.submitAnswer(params[0], params[1]); } catch (final IOException e) { Log.e(TAG, e.getMessage(), e); } return Boolean.FALSE; } @Override protected void onPostExecute(final Boolean result) { if (listener != null) { listener.onAnswerVerified(result); } } }, privateKey, answer); }
Example #10
Source File: XAsyncTask.java From Alibaba-Android-Certification with MIT License | 4 votes |
public static <Result,Params> void execute(Context context, XAsyncTaskListener<Result,Params> asyncTask, Params...params){ AsyncTaskCompat.executeParallel(new Task(context,asyncTask),params); }
Example #11
Source File: LargeHeightImageDisplayFragment.java From support with Apache License 2.0 | 4 votes |
@Override public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { mDecodeTask = new AsyncTask<Context, Bitmap, Object>() { @Override protected Object doInBackground(Context... params) { Log.d(TAG, "Start decode image..."); BitmapRegionDecoder decoder = null; try { //TODO According to api document both jpeg and png are supported, however jpeg image just failed to be decoded on this case decoder = BitmapRegionDecoder.newInstance(params[0].getAssets().open("image.png", AssetManager.ACCESS_RANDOM), false); final int screenWidth = params[0].getResources().getDisplayMetrics().widthPixels; final int imageWidth = decoder.getWidth(); final int imageHeight = decoder.getHeight(); final int eachHeight = (int) (screenWidth * ((imageWidth + 0.5f) / screenWidth)); int heightRemained = imageHeight; Rect corpRect = new Rect(0, 0, imageWidth, 0); //TODO the while case is only for test, should only load specific bitmap data when scrolled to be visible while (heightRemained > 0 && !isCancelled()) { Log.d(TAG, "clip image"); if (heightRemained >= eachHeight) { corpRect.set(corpRect.left, corpRect.bottom, corpRect.right, corpRect.bottom + eachHeight); heightRemained -= eachHeight; } else { corpRect.set(corpRect.left, corpRect.bottom, corpRect.right, corpRect.bottom + heightRemained); heightRemained = 0; } Log.d(TAG, "corptBitmap, " + corpRect.toString()); Bitmap corptBitmap = decoder.decodeRegion(corpRect, null); publishProgress(corptBitmap); } Log.d(TAG, "Image decode finished"); } catch (IOException e) { Log.d(TAG, "Image decode failed"); e.printStackTrace(); } finally { if (decoder != null) { decoder.recycle(); } } return null; } @Override protected void onProgressUpdate(Bitmap... values) { if (getActivity() != null && !isRemoving() && values[0] != null) { ImageView imageView = new ImageView(getActivity()); imageView.setScaleType(ImageView.ScaleType.FIT_CENTER); imageView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT)); imageView.setImageBitmap(values[0]); mContainer.addView(imageView); } } }; AsyncTaskCompat.executeParallel(mDecodeTask, getActivity()); }
Example #12
Source File: WeixinHelper.java From android-common-utils with Apache License 2.0 | 4 votes |
/** * title 和 desc 在分享图片时无效 */ public void shareImageByUrl(String url,String title,String desc ,boolean shareToFriendCircle, IWXShareCallback callback){ AsyncTaskCompat.executeParallel(new ShareImageTask(mTaskManager), url, title, desc, shareToFriendCircle, callback); }