本文整理匯總了Java中io.reactivex.FlowableEmitter.onNext方法的典型用法代碼示例。如果您正苦於以下問題:Java FlowableEmitter.onNext方法的具體用法?Java FlowableEmitter.onNext怎麽用?Java FlowableEmitter.onNext使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.reactivex.FlowableEmitter
的用法示例。
在下文中一共展示了FlowableEmitter.onNext方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: SimpleRemoteSourceMapper
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
public SimpleRemoteSourceMapper(FlowableEmitter<Resource<T>> emitter) {
emitter.onNext(Resource.loading(null));
// since realm instance was created on Main Thread, so if we need to touch on realm database after calling
// api (such as save response data to local database, we must make request on main thread
// by setting shouldUpdateUi params = true
Disposable disposable = RestHelper.makeRequest(getRemote(), true, response -> {
Log.d(TAG, "SimpleRemoteSourceMapper: call API success!");
saveCallResult(response);
emitter.onNext(Resource.success(response));
}, errorEntity -> {
Log.d(TAG, "SimpleRemoteSourceMapper: call API error: " + errorEntity.getMessage());
emitter.onNext(Resource.error(errorEntity.getMessage(), null));
});
// set emitter disposable to ensure that when it is going to be disposed, our api request should be disposed as well
emitter.setDisposable(disposable);
}
示例2: ListDataNetworkBounceResource
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
public ListDataNetworkBounceResource(FlowableEmitter<Resource<LocalType>> emitter) {
emitter.onNext(Resource.success(getLocal()));
emitter.onNext(Resource.loading(null));
// since realm instance was created on Main Thread, so if we need to touch on realm database after calling
// api (such as save response data to local database, we must make request on main thread
// by setting shouldUpdateUi params = true
Disposable disposable = RestHelper.makeRequest(getRemote(), true, response -> {
Single.just(response)
.map(mapper())
.subscribe(localData -> {
Log.d(TAG, "SimpleRemoteSourceMapper: call API success!");
saveCallResult(localData);
emitter.onNext(Resource.success(localData));
});
}, errorEntity -> {
Log.d(TAG, "SimpleRemoteSourceMapper: call API error: " + errorEntity.getMessage());
emitter.onNext(Resource.error(errorEntity.getMessage(), null));
});
// set emitter disposable to ensure that when it is going to be disposed, our api request should be disposed as well
emitter.setDisposable(disposable);
}
示例3: initializeSensorEventListenerFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
private SensorEventListener initializeSensorEventListenerFor(final FlowableEmitter<SensorRecord> subscriber) {
return new SensorEventListener() {
@Override
public void onSensorChanged(SensorEvent event) {
subscriber.onNext(createSensorRecordFrom(event));
}
@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {}
};
}
示例4: defineBroadcastReceiverFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
private BroadcastReceiver defineBroadcastReceiverFor(final FlowableEmitter<SensorRecord> subscriber){
return new BroadcastReceiver() {
Timer timer = new Timer();
long prevCallTime = new Date().getTime();
@Override
public void onReceive(Context context, Intent intent) {
long actualTime = new Date().getTime();
long delay = calculateDiffDelay(prevCallTime, actualTime);
prevCallTime = actualTime;
subscriber.onNext(new WifiMeasurementsRecord(wifiManager.getScanResults()));
if (delay > 0)
timer.schedule(createScanTask(), delay);
else
createScanTask().run();
}
};
}
示例5: subscribe
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@Override
public void subscribe(FlowableEmitter<T> e) throws Exception {
try {
Response response = call.execute();
if (!e.isCancelled()) {
if (response.isSuccessful()) {
e.onNext(rxEasyConverter.convert(response.body().string()));
} else {
e.onError(new Throwable("response is unsuccessful"));
}
}
} catch (Throwable t) {
if (!e.isCancelled()) {
e.onError(t);
}
} finally {
e.onComplete();
}
}
示例6: recvFile
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
/**
* 下載文件
*
* @param emitter
* @param response
* @param file
* @throws Exception
*/
private void recvFile(FlowableEmitter emitter, Response response, File file) throws Exception {
long fileSize = response.body().contentLength();
InputStream is =
response.body().byteStream();
float preProgress = 0;
float progress = 0;
FileOutputStream fos = new FileOutputStream(file);
int pullLength = 0;
byte[] b = new byte[1024];
int len;
while ((len = is.read(b)) != -1) {
fos.write(b, 0, len);
pullLength += len;
progress = (float) (pullLength * 100 / fileSize);
if (preProgress != progress) {
emitter.onNext(progress);
}
preProgress = progress;
}
fos.flush();
fos.close();
is.close();
}
示例7: onGoogleApiClientReady
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, final FlowableEmitter<Location> emitter) {
locationListener = new LocationListener() {
@Override
public void onLocationChanged(Location value) {
emitter.onNext(value);
}
};
//noinspection MissingPermission
setupLocationPendingResult(
LocationServices.FusedLocationApi.requestLocationUpdates(apiClient, locationRequest, locationListener, looper),
new StatusErrorResultCallBack(emitter)
);
}
示例8: initializeScanCallbackFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
private ScanCallback initializeScanCallbackFor(final FlowableEmitter<SensorRecord> subscriber){
return new ScanCallback() {
@Override
public void onBatchScanResults(List<ScanResult> results) {
subscriber.onNext(new BLEMeasurementsRecord(results));
}
};
}
示例9: initializeGnssMeasurementsCallbackFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@RequiresApi(Build.VERSION_CODES.N)
private GnssMeasurementsEvent.Callback initializeGnssMeasurementsCallbackFor(final FlowableEmitter<SensorRecord> subscriber) {
return new GnssMeasurementsEvent.Callback() {
@Override
public void onGnssMeasurementsReceived(GnssMeasurementsEvent event) {
subscriber.onNext(new RawGPSMeasurementsRecord(event));
}
};
}
示例10: initializeGnssStatusCallbackFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@RequiresApi(Build.VERSION_CODES.N)
private GnssStatus.Callback initializeGnssStatusCallbackFor(final FlowableEmitter<SensorRecord> subscriber) {
return new GnssStatus.Callback() {
@Override
public void onSatelliteStatusChanged(GnssStatus status) {
subscriber.onNext(new RawGPSStatusRecord(status));
}
};
}
示例11: initializeGnssNavigationCallbackFor
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@RequiresApi(Build.VERSION_CODES.N)
private GnssNavigationMessage.Callback initializeGnssNavigationCallbackFor(final FlowableEmitter<SensorRecord> subscriber) {
return new GnssNavigationMessage.Callback() {
@Override
public void onGnssNavigationMessageReceived(GnssNavigationMessage event) {
subscriber.onNext(new RawGPSNavigationRecord(event));
}
};
}
示例12: onGoogleApiClientReady
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
@Override
protected void onGoogleApiClientReady(GoogleApiClient apiClient, FlowableEmitter<GoogleApiClient> emitter) {
emitter.onNext(apiClient);
}
示例13: walk
import io.reactivex.FlowableEmitter; //導入方法依賴的package包/類
/**
* Walk the directory tree.
*
* @param path the starting path
* @param depth offset, where 1 == data directory, 2 == zoom directory, 3 == row, 4 == column
* @param subscriber to provide feedback and terminate according to
*/
private static void walk(String path, int depth, FlowableEmitter<File> subscriber) {
final File root = new File(path);
File[] list;
switch (depth) {
case 1:
case 2:
list = root.listFiles(File::isDirectory);
break;
case 3:
list = root.listFiles(file -> file.isFile() && PATTERN.matcher(file.toString()).matches());
break;
case 4:
// consider removing out of walk
list = getSingleMatchOrEmpty(root);
break;
default:
throw new IllegalArgumentException("unsupported depth");
}
if (list == null) {
return;
}
for (final File f : list) {
if (subscriber.isCancelled()) {
return;
}
if (f.isDirectory()) {
walk(f.getAbsolutePath(), depth + 1, subscriber);
} else {
// move close as possible - but no guarantee!
final boolean isSubscribed = !subscriber.isCancelled();
if (isSubscribed) {
subscriber.onNext(f);
}
}
}
}