use of io.reactivex.SingleSource in project gh4a by slapperwan.
the class RxUtils method wrapWithProgressDialog.
public static <T> SingleTransformer<T, T> wrapWithProgressDialog(final FragmentActivity activity, @StringRes final int messageResId) {
return new SingleTransformer<T, T>() {
private ProgressDialogFragment mFragment;
@Override
public SingleSource<T> apply(Single<T> upstream) {
return upstream.doOnSubscribe(disposable -> showDialog()).doOnError(throwable -> hideDialog()).doOnSuccess(result -> hideDialog());
}
private void showDialog() {
Bundle args = new Bundle();
args.putInt("message_res", messageResId);
mFragment = new ProgressDialogFragment();
mFragment.setArguments(args);
mFragment.show(activity.getSupportFragmentManager(), "progressdialog");
}
private void hideDialog() {
if (mFragment.getActivity() != null) {
mFragment.dismissAllowingStateLoss();
}
mFragment = null;
}
};
}
use of io.reactivex.SingleSource in project developmentDependencyLibrary by MatchlessBrother.
the class BasePhotoActivity method onActivityResult.
/**
***********************************获取图片以及裁剪图片的处理过程**********************************
*/
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_IMAGE_CAMERA) {
final String imgPath = compressImagePixel_AllAcion(mImgFilePath);
if (!StringTools.isEmpty(imgPath)) {
Intent intent = new Intent(this, PhotoCropperActivity.class);
intent.putExtra(PhotoCropperActivity.TITLECOLOR, mTitleBgColor);
intent.putExtra(PhotoCropperActivity.BITMAPPATH, imgPath);
intent.putExtra(PhotoCropperActivity.ROUNDCROPPER, mIsRoundCropper);
intent.putExtra(PhotoCropperActivity.TITLETEXTCOLOR, mTitleTextColor);
startActivityForResult(intent, REQUEST_CODE_IMAGE_CROPPER);
} else
PromptBoxTools.showToast(this, "亲,获取拍照的图片失败了!\n因为在指定路径无法查找到图片哟!");
} else if (resultCode == RESULT_OK && requestCode == REQUEST_CODE_IMAGE_GALLERY && data != null) {
final ArrayList<String> imgList = data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
if (imgList.size() == 1) {
String imgPath = imgList.get(0);
if (!StringTools.isEmpty(imgPath)) {
File bitmapFile = new File(imgPath);
/**
******超过120KB的图片需要进行像素压缩处理*******
*/
if (bitmapFile.length() >= 120 * 1024)
imgPath = compressImagePixel_AllAcion(imgPath);
else /**
***不超过120的图片则不需要进行像素压缩处理****
*/
{
try {
mResultBitmapQualitySize = 100d;
FileInputStream fileInputStream = new FileInputStream(bitmapFile);
byte[] fileInputStreamSz = new byte[(int) bitmapFile.length()];
fileInputStream.read(fileInputStreamSz);
File newBitmapFile = new File(mImgFilePath);
BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(newBitmapFile));
outputStream.write(fileInputStreamSz);
outputStream.flush();
outputStream.close();
imgPath = mImgFilePath;
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (Exception e) {
e.printStackTrace();
}
}
Intent intent = new Intent(this, PhotoCropperActivity.class);
intent.putExtra(PhotoCropperActivity.TITLECOLOR, mTitleBgColor);
intent.putExtra(PhotoCropperActivity.BITMAPPATH, imgPath);
intent.putExtra(PhotoCropperActivity.ROUNDCROPPER, mIsRoundCropper);
intent.putExtra(PhotoCropperActivity.TITLETEXTCOLOR, mTitleTextColor);
startActivityForResult(intent, REQUEST_CODE_IMAGE_CROPPER);
} else
PromptBoxTools.showToast(this, "亲,获取选定的图片失败了!\n因为在指定路径无法查找到图片哟!");
} else {
Single.just("only").flatMap(new Function<String, SingleSource<LinkedList<String>>>() {
public SingleSource<LinkedList<String>> apply(@io.reactivex.annotations.NonNull String s) throws Exception {
for (int index = 0; index < imgList.size(); index++) {
String imgPath = imgList.get(index);
File bitmapFile = new File(imgPath);
/**
*******为了不破坏原有图片,我们尽量生成新图片来进行操作*******
*/
/**
******超过120KB的图片需要进行像素压缩以及质量压缩的处理******
*/
mImgFilePath = mCachePath + File.separator + new SimpleDateFormat("yyyy_MM_dd_HH_mm").format(new Date()) + "_" + index + ".jpg";
if (bitmapFile.length() >= 120 * 1024)
imgPath = compressImageQuality_Complete(compressImagePixel_AllAcion(imgPath), (int) mResultBitmapQualitySize.doubleValue());
else
/**
*不超过120KB的图片我们则直接使用原图片,避免消耗多余的空间**
*/
imgPath = imgPath;
/**
*至此对于图片必须的像素压缩完成
*/
imgList.set(index, imgPath);
}
LinkedList<String> dataList = new LinkedList<>();
dataList.addAll(imgList);
return Single.just(dataList);
}
}).observeOn(AndroidSchedulers.mainThread()).subscribeOn(Schedulers.io()).subscribe(new Consumer<LinkedList<String>>() {
public void accept(@io.reactivex.annotations.NonNull LinkedList<String> dataList) throws Exception {
setOnNewImgPathListener(dataList);
}
});
}
} else if (requestCode == REQUEST_CODE_IMAGE_CROPPER && data != null) {
String cropperBitmapPath = data.getStringExtra(PhotoCropperActivity.BITMAPPATH);
File bitmapFile = new File(cropperBitmapPath);
if (!StringTools.isEmpty(cropperBitmapPath) && bitmapFile.exists()) {
/**
**************************************超过120KB的图片需要进行质量压缩处理***************************************
*/
if (bitmapFile.length() >= 120 * 1024)
cropperBitmapPath = compressImageQuality_Complete(cropperBitmapPath, (int) mResultBitmapQualitySize.doubleValue());
LinkedList<String> dataList = new LinkedList<>();
dataList.add(cropperBitmapPath);
setOnNewImgPathListener(dataList);
} else
PromptBoxTools.showToast(this, "亲,手机发生异常情况导致裁剪\n图片失败了哟!请您稍后重试!");
}
super.onActivityResult(requestCode, resultCode, data);
}
use of io.reactivex.SingleSource in project ForPDA by RadiationX.
the class NotificationsService method sendNotification.
public void sendNotification(NotificationEvent event) {
Log.e("kulolo", "sendNotification " + event.notifyId());
if (notificationPreferencesHolder.getMainAvatarsEnabled()) {
SchedulersProvider schedulers = App.get().Di().getSchedulers();
Disposable disposable = avatarRepository.getAvatar(event.getUserId(), event.getUserNick()).flatMap((Function<String, SingleSource<Bitmap>>) s -> {
return Single.fromCallable(() -> ImageLoader.getInstance().loadImageSync(s)).subscribeOn(schedulers.io()).observeOn(schedulers.ui());
}).onErrorReturn(throwable -> ImageLoader.getInstance().loadImageSync("assets://av.png")).map(bitmap -> {
if (bitmap != null) {
Resources res = App.getContext().getResources();
int height = (int) res.getDimension(android.R.dimen.notification_large_icon_height);
int width = (int) res.getDimension(android.R.dimen.notification_large_icon_width);
boolean isCircle = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP;
bitmap = BitmapUtils.centerCrop(bitmap, width, height, 1.0f);
bitmap = BitmapUtils.createAvatar(bitmap, width, height, isCircle);
}
return bitmap;
}).subscribe(avatar -> sendNotification(event, avatar), Throwable::printStackTrace);
addToDisposable(disposable);
} else {
sendNotification(event, null);
}
}
Aggregations