Java Code Examples for io.reactivex.ObservableEmitter#onNext()

The following examples show how to use io.reactivex.ObservableEmitter#onNext() . 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: ReadTadPagePresenter.java    From GankGirl with GNU Lesser General Public License v2.1 6 votes vote down vote up
@Override
public void subscribe(ObservableEmitter<List<ReadTypeBean>> subscriber) throws Exception {
    List<ReadTypeBean> datas = new ArrayList<>();
    try {
        Document doc = Jsoup.connect(Constants.API_URL_READ).get();
        Elements tads = doc.select("div#xiandu_cat").select("a");
        for (Element tad : tads) {
            ReadTypeBean bean = new ReadTypeBean();
            bean.setTitle(tad.text());//获取标题
            bean.setUrl(tad.absUrl("href"));//absUrl可以获取地址的绝对路径
            datas.add(bean);
            Log.v("Jsoup","title= "+bean.getTitle()+"   url= "+bean.getUrl());
        }
    } catch (IOException e) {
        subscriber.onError(e);
    }

    subscriber.onNext(datas);
    subscriber.onComplete();
}
 
Example 2
Source File: AesEncryptionObservable.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintEncryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] encryptedBytes = cipher.doFinal(ConversionUtils.toBytes(toEncrypt));
		byte[] ivBytes = cipher.getParameters().getParameterSpec(IvParameterSpec.class).getIV();

		String encryptedString = CryptoData.fromBytes(encodingProvider, encryptedBytes, ivBytes).toString();
		CryptoData.verifyCryptoDataString(encryptedString);

		emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.AUTHENTICATED, null, encryptedString));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}
}
 
Example 3
Source File: RsaEncryptionObservable.java    From RxFingerprint with Apache License 2.0 6 votes vote down vote up
@Override
public void subscribe(ObservableEmitter<FingerprintEncryptionResult> emitter) throws Exception {
	if (fingerprintApiWrapper.isUnavailable()) {
		emitter.onError(new FingerprintUnavailableException("Fingerprint authentication is not available on this device! Ensure that the device has a Fingerprint sensor and enrolled Fingerprints by calling RxFingerprint#isAvailable(Context) first"));
		return;
	}

	try {
		Cipher cipher = cipherProvider.getCipherForEncryption();
		byte[] encryptedBytes = cipher.doFinal(ConversionUtils.toBytes(toEncrypt));

		String encryptedString = encodingProvider.encode(encryptedBytes);
		emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.AUTHENTICATED, null, encryptedString));
		emitter.onComplete();
	} catch (Exception e) {
		Logger.error(String.format("Error writing value for key: %s", cipherProvider.keyName), e);
		emitter.onError(e);
	}
}
 
Example 4
Source File: LegacyScanOperation.java    From RxAndroidBle with Apache License 2.0 6 votes vote down vote up
@Override
BluetoothAdapter.LeScanCallback createScanCallback(final ObservableEmitter<RxBleInternalScanResultLegacy> emitter) {
    return new BluetoothAdapter.LeScanCallback() {
        @Override
        public void onLeScan(BluetoothDevice device, int rssi, byte[] scanRecord) {
            if (filterUuids != null && RxBleLog.isAtLeast(LogConstants.DEBUG)) {
                RxBleLog.d("%s, name=%s, rssi=%d, data=%s",
                        LoggerUtil.commonMacMessage(device.getAddress()),
                        device.getName(),
                        rssi,
                        LoggerUtil.bytesToHex(scanRecord)
                );
            }
            if (filterUuids == null || uuidUtil.extractUUIDs(scanRecord).containsAll(filterUuids)) {
                emitter.onNext(new RxBleInternalScanResultLegacy(device, rssi, scanRecord));
            }
        }
    };
}
 
Example 5
Source File: Fetcher.java    From fetch with Apache License 2.0 6 votes vote down vote up
<ResultT> void subscribe(Converter<ResultT> converter, ObservableEmitter<? super ResultT> emitter) {
    try {
        if (isEmpty(cursor)) {
            return;
        }

        while (this.cursor.moveToNext()) {
            ResultT event = converter.convert(this.cursor);
            if (event != null) {
                emitter.onNext(event);
            }
        }
    } finally {
        close();
        emitter.onComplete();
    }
}
 
Example 6
Source File: FileTailer.java    From websockets-log-tail with Apache License 2.0 6 votes vote down vote up
private TailerListenerAdapter createListener(final ObservableEmitter<String> emitter) {
    return new TailerListenerAdapter() {

        @Override
        public void fileRotated() {
            // ignore, just keep tailing
        }

        @Override
        public void handle(String line) {
            emitter.onNext(line);
        }

        @Override
        public void fileNotFound() {
            emitter.onError(new FileNotFoundException(file.toString()));
        }

        @Override
        public void handle(Exception ex) {
            emitter.onError(ex);
        }
    };
}
 
Example 7
Source File: AppStateObservableOnSubscribe.java    From RxAppState with MIT License 6 votes vote down vote up
@Override
public void subscribe(@NonNull final ObservableEmitter<AppState> appStateEmitter) throws Exception {
  final AppStateListener appStateListener = new AppStateListener() {
    @Override
    public void onAppDidEnterForeground() {
      appStateEmitter.onNext(FOREGROUND);
    }

    @Override
    public void onAppDidEnterBackground() {
      appStateEmitter.onNext(BACKGROUND);
    }
  };

  appStateEmitter.setCancellable(new Cancellable() {
    @Override public void cancel() throws Exception {
      recognizer.removeListener(appStateListener);
      recognizer.stop();
    }
  });

  recognizer.addListener(appStateListener);
  recognizer.start();
}
 
Example 8
Source File: FeatureControllerOnSubscribe.java    From FeatureAdapter with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(final ObservableEmitter<FeatureEvent> subscriber) {
  verifyMainThread();

  FeatureEventListener listener =
      event -> {
        if (!subscriber.isDisposed()) {
          subscriber.onNext(event);
        }
      };

  subscriber.setCancellable(() -> featureController.removeFeatureEventListener(listener));

  featureController.addFeatureEventListener(listener);
}
 
Example 9
Source File: NewArticleActivity.java    From YCCustomText with Apache License 2.0 5 votes vote down vote up
/**
 * 显示数据
 */
private void showEditData(ObservableEmitter<String> emitter, String html) {
    try {
        List<String> textList = HyperLibUtils.cutStringByImgTag(html);
        for (int i = 0; i < textList.size(); i++) {
            String text = textList.get(i);
            emitter.onNext(text);
        }
        emitter.onComplete();
    } catch (Exception e){
        e.printStackTrace();
        emitter.onError(e);
    }
}
 
Example 10
Source File: RsaDecryptionObservable.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] bytes = cipher.doFinal(encodingProvider.decode(encryptedString));

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, ConversionUtils.toChars(bytes)));
		emitter.onComplete();
	} catch (Exception e) {
		Logger.error("Unable to decrypt given value. RxFingerprint is only able to decrypt values previously encrypted by RxFingerprint with the same encryption mode.", e);
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 11
Source File: DefaultContentDelegate.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
private void doOnChapterListFinish(List<ChapterBean> chapterList, ObservableEmitter<List<ChapterBean>> emitter) {
    if (!getBookSource().chapterListReverse()) {
        Collections.reverse(chapterList);
    }
    LinkedHashSet<ChapterBean> lh = new LinkedHashSet<>(chapterList);
    chapterList = new ArrayList<>(lh);
    Collections.reverse(chapterList);
    emitter.onNext(chapterList);
    emitter.onComplete();
}
 
Example 12
Source File: AesDecryptionObservable.java    From RxFingerprint with Apache License 2.0 5 votes vote down vote up
@Override
protected void onAuthenticationSucceeded(ObservableEmitter<FingerprintDecryptionResult> emitter, AuthenticationResult result) {
	try {
		CryptoData cryptoData = CryptoData.fromString(encodingProvider, encryptedString);
		Cipher cipher = result.getCryptoObject().getCipher();
		byte[] bytes = cipher.doFinal(cryptoData.getMessage());

		emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.AUTHENTICATED, null, ConversionUtils.toChars(bytes)));
		emitter.onComplete();
	} catch (Exception e) {
		emitter.onError(cipherProvider.mapCipherFinalOperationException(e));
	}

}
 
Example 13
Source File: RxScheduler.java    From MvpRoute with Apache License 2.0 5 votes vote down vote up
@Override
public void subscribe(final ObservableEmitter<View> emitter) throws Exception {
	View.OnClickListener listener = new View.OnClickListener() {
		@Override
		public void onClick(View v) {
			if (!emitter.isDisposed()) {
				emitter.onNext(view);
			}
		}
	};
	view.setOnClickListener(listener);
}
 
Example 14
Source File: RpcRx.java    From api with Apache License 2.0 5 votes vote down vote up
private IRpcFunction.SubscribeCallback createReplayCallBack(ObservableEmitter<Object> emitter) {
    return new IRpcFunction.SubscribeCallback() {
        @Override
        public void callback(Object o) {
            emitter.onNext(o);
        }
    };
}
 
Example 15
Source File: DisposableUtil.java    From RxAndroidBle with Apache License 2.0 5 votes vote down vote up
public static <T> DisposableSingleObserver<T> disposableSingleObserverFromEmitter(final ObservableEmitter<T> emitter) {
    return new DisposableSingleObserver<T>() {

        @Override
        public void onSuccess(T t) {
            emitter.onNext(t);
            emitter.onComplete();
        }

        @Override
        public void onError(Throwable e) {
            emitter.tryOnError(e);
        }
    };
}
 
Example 16
Source File: AesEncryptionObservable.java    From RxFingerprint with Apache License 2.0 4 votes vote down vote up
@Override
protected void onAuthenticationFailed(ObservableEmitter<FingerprintEncryptionResult> emitter) {
	emitter.onNext(new FingerprintEncryptionResult(FingerprintResult.FAILED, null, null));
}
 
Example 17
Source File: DecompressionModel.java    From Dainty with Apache License 2.0 4 votes vote down vote up
private void unRar(File mInput, File mOutput, final ObservableEmitter<Long> emitter) throws IOException, RarException {
    Archive rarFile = null;
    try {
        rarFile = new Archive(mInput, new UnrarCallback() {
            @Override
            public boolean isNextVolumeReady(File file) {
                return false;
            }

            @Override
            public void volumeProgressChanged(long l, long l1) {
                emitter.onNext(l);
            }
        });
        long uncompressedSize = getOriginalSize(rarFile);
        //publishProgress(0L, uncompressedSize);
        emitter.onNext(uncompressedSize);

        for (int i = 0; i < rarFile.getFileHeaders().size(); i++) {
            if (emitter.isDisposed())
                break;
            FileHeader fh = rarFile.getFileHeaders().get(i);
            String entryPath;
            if (fh.isUnicode()) {
                entryPath = fh.getFileNameW().trim();
            } else {
                entryPath = fh.getFileNameString().trim();
            }
            entryPath = entryPath.replaceAll("\\\\", "/");
            File file = new File(mOutput, entryPath);
            if (fh.isDirectory()) {
                //noinspection ResultOfMethodCallIgnored
                file.mkdirs();
            } else {
                File parent = file.getParentFile();
                if (parent != null && !parent.exists()) {
                    //noinspection ResultOfMethodCallIgnored
                    parent.mkdirs();
                }
                FileOutputStream fileOut = new FileOutputStream(file);
                rarFile.extractFile(fh, fileOut);
                fileOut.close();
            }
        }
        emitter.onComplete();
    } finally {
        if (rarFile != null) {
            try {
                rarFile.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 18
Source File: IflySynthesizer.java    From AssistantBySDK with Apache License 2.0 4 votes vote down vote up
private void checkValid(ObservableEmitter<SpeechMsg> e, SpeechMsg msg, SpeechMsg.State nextState) {
    if (msg.invalid())
        return;
    e.onNext(msg.setState(nextState));
}
 
Example 19
Source File: RxContacts.java    From MultiContactPicker with Apache License 2.0 4 votes vote down vote up
private void fetch (LimitColumn columnLimitChoice, ObservableEmitter emitter) {
    LongSparseArray<Contact> contacts = new LongSparseArray<>();
    Cursor cursor = createCursor(getFilter(columnLimitChoice));
    cursor.moveToFirst();
    int idColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts._ID);
    int inVisibleGroupColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.IN_VISIBLE_GROUP);
    int displayNamePrimaryColumnIndex = cursor.getColumnIndex(DISPLAY_NAME);
    int starredColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.STARRED);
    int photoColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_URI);
    int thumbnailColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI);
    int hasPhoneNumberColumnIndex = cursor.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER);


    while (!cursor.isAfterLast()) {
        long id = cursor.getLong(idColumnIndex);
        Contact contact = contacts.get(id, null);
        if (contact == null) {
            contact = new Contact(id);
        }
        ColumnMapper.mapInVisibleGroup(cursor, contact, inVisibleGroupColumnIndex);
        ColumnMapper.mapDisplayName(cursor, contact, displayNamePrimaryColumnIndex);
        ColumnMapper.mapStarred(cursor, contact, starredColumnIndex);
        ColumnMapper.mapPhoto(cursor, contact, photoColumnIndex);
        ColumnMapper.mapThumbnail(cursor, contact, thumbnailColumnIndex);

        switch (columnLimitChoice){
            case EMAIL:
                getEmail(id, contact);
                break;
            case PHONE:
                getPhoneNumber(id, cursor, contact, hasPhoneNumberColumnIndex);
                break;
            case NONE:
                getEmail(id, contact);
                getPhoneNumber(id, cursor, contact, hasPhoneNumberColumnIndex);
                break;
        }

        if(columnLimitChoice == LimitColumn.EMAIL){
            if(contact.getEmails().size() > 0){
                contacts.put(id, contact);
                //noinspection unchecked
                emitter.onNext(contact);
            }
        }else{
            contacts.put(id, contact);
            //noinspection unchecked
            emitter.onNext(contact);
        }
        cursor.moveToNext();
    }
    cursor.close();
    emitter.onComplete();
}
 
Example 20
Source File: RsaDecryptionObservable.java    From RxFingerprint with Apache License 2.0 4 votes vote down vote up
@Override
protected void onAuthenticationFailed(ObservableEmitter<FingerprintDecryptionResult> emitter) {
	emitter.onNext(new FingerprintDecryptionResult(FingerprintResult.FAILED, null, null));
}