當前位置: 首頁>>代碼示例>>Java>>正文


Java Action1類代碼示例

本文整理匯總了Java中rx.functions.Action1的典型用法代碼示例。如果您正苦於以下問題:Java Action1類的具體用法?Java Action1怎麽用?Java Action1使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Action1類屬於rx.functions包,在下文中一共展示了Action1類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onLocationPermissionGranted

import rx.functions.Action1; //導入依賴的package包/類
@Override
protected void onLocationPermissionGranted() {
    compositeSubscription = new CompositeSubscription();
    compositeSubscription.add(reactiveLocationProvider.getPlaceById(placeId)
            .subscribe(new Action1<PlaceBuffer>() {
                @Override
                public void call(PlaceBuffer buffer) {
                    Place place = buffer.get(0);
                    if (place != null) {
                        placeNameView.setText(place.getName());
                        placeLocationView.setText(place.getLatLng().latitude + ", " + place.getLatLng().longitude);
                        placeAddressView.setText(place.getAddress());
                    }
                    buffer.release();
                }
            }));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:PlacesResultActivity.java

示例2: loadData

import rx.functions.Action1; //導入依賴的package包/類
private void loadData(final boolean refresh) {
    Observable.timer(5, TimeUnit.SECONDS).compose(new Observable.Transformer<Long, List<String>>() {
        @Override
        public Observable<List<String>> call(Observable<Long> longObservable) {
            return Observable.create(new Observable.OnSubscribe<List<String>>() {
                @Override
                public void call(Subscriber<? super List<String>> subscriber) {
                    subscriber.onNext(pageNo == 0 ? new ArrayList<String>() : AnalogData.analogString(pageNo));
                    subscriber.onCompleted();
                }
            });
        }
    }).compose(RxSchedulers.<List<String>>io2main())
            .subscribe(new Action1<List<String>>() {
                @Override
                public void call(List<String> section2Models) {
                    mBaseAdapter.addItems(section2Models, refresh);
                    stopRefresh(refresh);
                }
            });
}
 
開發者ID:lvtanxi,項目名稱:BaseVLayoutAdapterHelper,代碼行數:22,代碼來源:EmptyActivity.java

示例3: getData

import rx.functions.Action1; //導入依賴的package包/類
@Override
public void getData(boolean isRefresh) {
    mDbDao.queryBuilder()
            .where(VideoInfoDao.Properties.DownloadStatus.eq(DownloadStatus.COMPLETE))
            .rx()
            .list()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<VideoInfo>>() {
                @Override
                public void call(List<VideoInfo> videoList) {
                    if (ListUtils.isEmpty(videoList)) {
                        mView.noData();
                    } else {
                        mView.loadData(videoList);
                    }
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:19,代碼來源:VideoCompletePresenter.java

示例4: asyncTask

import rx.functions.Action1; //導入依賴的package包/類
/**
 * Start an async task which can do things beforehand, in background and callback when the job is done on the main thread, and handle the exception with the given action.
 *
 * @param preExecute     action to do beforehand.
 * @param doInBackground action to do in the background.
 * @param doOnFinish     action to do when the job is done.(this is called on main thread)
 * @param onError        action to do when exceptions are thrown.
 * @return the subscription of the task.
 */
public static Subscription asyncTask(final Action0 preExecute, @NonNull final Action0 doInBackground, final Action0 doOnFinish, Action1<Throwable> onError) {
    return Observable.just("Hey nerd! This is an async task.")
            .subscribeOn(Schedulers.io())
            .doOnSubscribe(new Action0() {
                @Override
                public void call() {
                    if (preExecute != null) preExecute.call();
                }
            })
            .observeOn(Schedulers.io())
            .doOnNext(Actions.toAction1(doInBackground))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<String>() {
                @Override
                public void call(String s) {
                    if (doOnFinish != null) doOnFinish.call();
                }
            }, onError == null ? RxActions.onError() : onError);
}
 
開發者ID:Mindjet,項目名稱:LiteReader,代碼行數:29,代碼來源:RxTask.java

示例5: getData

import rx.functions.Action1; //導入依賴的package包/類
@Override
public void getData(boolean isRefresh) {
    mDbDao.queryBuilder().where(VideoInfoDao.Properties.IsCollect.eq(true))
            .rx()
            .list()
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<List<VideoInfo>>() {
                @Override
                public void call(List<VideoInfo> videoList) {
                    if (ListUtils.isEmpty(videoList)) {
                        mView.noData();
                    } else {
                        mView.loadData(videoList);
                    }
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:LoveVideoPresenter.java

示例6: onTouchEvent

import rx.functions.Action1; //導入依賴的package包/類
/**
 * 重寫onTouchEvent, 當用戶的手在MyScrollView上麵的時候,
 * 直接將MyScrollView滑動的Y方向距離回調給onScroll方法中,當用戶抬起手的時候,
 * MyScrollView可能還在滑動,所以當用戶抬起手我們隔5毫秒給handler發送消息,在handler處理
 * MyScrollView滑動的距離
 */
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if(onScrollListener != null){
        lastScrollX = this.getScrollX();
        onScrollListener.onScroll(this.getScrollX());
    }
    switch(ev.getAction()){
        case MotionEvent.ACTION_UP:
            Observable.timer(500, TimeUnit.MILLISECONDS, AndroidSchedulers.mainThread())
                    .subscribe(new Action1<Long>() {
                        @Override
                        public void call(Long aLong) {
                            if(onScrollListener != null){
                                onScrollListener.onScrollStop();
                            }
                        }
                    });
            break;
    }
    return super.onTouchEvent(ev);
}
 
開發者ID:WeiMei-Tian,項目名稱:editor-sql,代碼行數:28,代碼來源:MyHorizontalScrollView.java

示例7: initRxBus

import rx.functions.Action1; //導入依賴的package包/類
private void initRxBus(){
    addSubscription(RemoveItemEvent.class, new Action1<RemoveItemEvent>() {
        @Override
        public void call(RemoveItemEvent removeItemEvent) {
            ProductEntity removeEntity = removeItemEvent.getRemoveEntity();
            if(DataLayer.getInstance().getDataPool().getSelectedProductEntityList().contains(removeEntity)){
                DataLayer.getInstance().getDataPool().getSelectedProductEntityList().remove(removeEntity);
            }
            mCategoryProductAdapter.updateData(removeEntity);
        }
    }, new Action1<Throwable>() {
        @Override
        public void call(Throwable throwable) {
            throwable.printStackTrace();
        }
    });
}
 
開發者ID:Sugarya,項目名稱:Closet,代碼行數:18,代碼來源:ClosetFragment.java

示例8: checkRandCodeAndNext

import rx.functions.Action1; //導入依賴的package包/類
private void checkRandCodeAndNext() {
    final HttpService service = RetrofitManager.getInstance().getService();
    service.checkRandCode2(randCode, "randp", "", orderParam.getREPEAT_SUBMIT_TOKEN())
            .subscribeOn(Schedulers.io())
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(new Action1<CheckRandCodeResponse>() {
                @Override
                public void call(CheckRandCodeResponse checkRandCodeResponse) {
                    if (checkRandCodeResponse.getData().getResult().equals("1")) {
                        RxBus.getDefault().post("pass");
                        submitOrderNext(service, orderParam.getREPEAT_SUBMIT_TOKEN());
                    }
                    else {
                        RxBus.getDefault().post("驗證碼錯誤");
                        RxBus.getDefault().post("clear");
                        refreshPassCode();
                    }
                }
            });
}
 
開發者ID:Akari10032,項目名稱:12306_Android,代碼行數:21,代碼來源:LoopService.java

示例9: getNewsData

import rx.functions.Action1; //導入依賴的package包/類
@Override
public void getNewsData(int channelId, final boolean refresh) {
    if (refresh) pageNum = 0;
    mModel.getNewsData(channelId, pageNum, new Action1<NewsList>() {
        @Override
        public void call(NewsList newsList) {
            mView.onNewsData(newsList.getList(), refresh);
            mView.stopLoading();
            if ("True".equals(newsList.getNext())) {
                pageNum = Integer.parseInt(newsList.getNextpage());
            }
            if (refresh) {
                SharedPreManager.getInstance().putNewsList(mContext, newsList);
            }
        }
    });
}
 
開發者ID:Yuanhongliang,項目名稱:HLOLI,代碼行數:18,代碼來源:HomePresenterImpl.java

示例10: rxCacheBeanHelper

import rx.functions.Action1; //導入依賴的package包/類
public static <T> Observable.Transformer<T, T> rxCacheBeanHelper(final String key) {
    return new Observable.Transformer<T, T>() {
        @Override
        public Observable<T> call(Observable<T> observable) {
            return observable
                    .subscribeOn(Schedulers.io())//指定doOnNext執行線程是新線程
                    .doOnNext(new Action1<T>() {
                        @Override
                        public void call(final T data) {
                            Schedulers.io().createWorker().schedule(new Action0() {
                                @Override
                                public void call() {
                                    LogUtils.d("get data from network finish ,start cache...");
                                    ACache.get(ReaderApplication.getsInstance())
                                            .put(key, new Gson().toJson(data, data.getClass()));
                                    LogUtils.d("cache finish");
                                }
                            });
                        }
                    })
                    .observeOn(AndroidSchedulers.mainThread());
        }
    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:25,代碼來源:RxUtil.java

示例11: throttleFirst

import rx.functions.Action1; //導入依賴的package包/類
private void throttleFirst() {
   Observable.create(new Observable.OnSubscribe<Integer>() {
        @Override
        public void call(Subscriber<? super Integer> subscriber) {
              for(int i=0;i<10;i++){
                  subscriber.onNext(i);
                  try {
                      Thread.sleep(100);
                  } catch (InterruptedException e) {
                      e.printStackTrace();
                  }
              }
            subscriber.onCompleted();
        }
    }).throttleFirst(200, TimeUnit.MILLISECONDS).subscribe(new Action1<Integer>() {
       @Override
       public void call(Integer integer) {
           Log.d(TAG, "throttleFirst:"+integer);
       }
   });
}
 
開發者ID:henrymorgen,項目名稱:android-advanced-light,代碼行數:22,代碼來源:FilterActivity.java

示例12: addGeofence

import rx.functions.Action1; //導入依賴的package包/類
private void addGeofence() {
    final GeofencingRequest geofencingRequest = createGeofencingRequest();
    if (geofencingRequest == null) return;

    final PendingIntent pendingIntent = createNotificationBroadcastPendingIntent();
    reactiveLocationProvider
            .removeGeofences(pendingIntent)
            .flatMap(new Func1<Status, Observable<Status>>() {
                @Override
                public Observable<Status> call(Status pendingIntentRemoveGeofenceResult) {
                    return reactiveLocationProvider.addGeofences(pendingIntent, geofencingRequest);
                }
            })
            .subscribe(new Action1<Status>() {
                @Override
                public void call(Status addGeofenceResult) {
                    toast("Geofence added, success: " + addGeofenceResult.isSuccess());
                }
            }, new Action1<Throwable>() {
                @Override
                public void call(Throwable throwable) {
                    toast("Error adding geofence.");
                    Log.d(TAG, "Error adding geofence.", throwable);
                }
            });
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:27,代碼來源:GeofenceActivity.java

示例13: configurationImp

import rx.functions.Action1; //導入依賴的package包/類
protected void configurationImp(@NonNull Action1<byte[]> action) {
    mConn.flatMap(rxBleConnection -> rxBleConnection
            .writeCharacteristic(uuidConf, baConf))
            .observeOn(AndroidSchedulers.mainThread())
            .subscribe(action, this::onConnectionFailure);

    // Speed up period for compass calibration
    // For some reason temperature sensor does not work at this speed
    if (!uuidConf.equals(UUID.fromString(TempertureProfile.GattConf))) {
        // Period 0x14 = 200ms
        byte[] periodConf = new byte[]{(byte) 0x14};
        mConn.flatMap(rxBleConnection -> rxBleConnection
                .writeCharacteristic(uuidPeri, periodConf))
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(action, this::onConnectionFailure);
    }
}
 
開發者ID:KunYi,項目名稱:SensorTag2Testing,代碼行數:18,代碼來源:GenericProfile.java

示例14: testPagingCapabilities

import rx.functions.Action1; //導入依賴的package包/類
@Test
public void testPagingCapabilities() {
    PublishSubject<Object> view = PublishSubject.create();
    BehaviorSubject<Integer> nextPageRequests = BehaviorSubject.create();
    final TestObserver<Delivery<Object, String>> testObserver = new TestObserver<>();

    nextPageRequests
        .concatMap(new Func1<Integer, Observable<Integer>>() {
            @Override
            public Observable<Integer> call(Integer targetPage) {
                return targetPage <= requestedPageCount ?
                    Observable.<Integer>never() :
                    Observable.range(requestedPageCount, targetPage - requestedPageCount);
            }
        })
        .doOnNext(new Action1<Integer>() {
            @Override
            public void call(Integer it) {
                requestedPageCount = it + 1;
            }
        })
        .startWith(Observable.range(0, requestedPageCount))
        .concatMap(new Func1<Integer, Observable<String>>() {
            @Override
            public Observable<String> call(final Integer page) {
                return requestPage(page, PAGE_SIZE);
            }
        })
        .compose(new DeliverReplay<Object, String>(view))
        .subscribe(testObserver);

    ArrayList<Delivery<Object, String>> onNext = new ArrayList<>();

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(999);
    addOnNext(onNext, 999, 0, 1, 2);

    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(2);
    addOnNext(onNext, 999, 3, 4, 5);

    testObserver.assertReceivedOnNext(onNext);

    view.onNext(null);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    nextPageRequests.onNext(3);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);

    view.onNext(9999);
    addOnNext(onNext, 9999, 0, 1, 2, 3, 4, 5, 6, 7, 8);

    assertEquals(0, testObserver.getOnCompletedEvents().size());
    testObserver.assertReceivedOnNext(onNext);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:62,代碼來源:DeliverReplayTest.java

示例15: onViewAttached

import rx.functions.Action1; //導入依賴的package包/類
@Override
public void onViewAttached(View view) {
    if (!hasAttach) {
        hasAttach = true;
        RxTask.asyncMap(new Func1<String, String>() {
            @Override
            public String call(String s) {
                return extractContent(prefix + id);
            }
        }, new Action1<String>() {
            @Override
            public void call(String summary) {
                if (summary.length() == 2) {
                    getSelfView().getBinding().tvSummary.setText(getString(R.string.douban_staff_no_introduce));
                    getSelfView().getBinding().ivToggle.setVisibility(View.GONE);
                } else {
                    initText(summary);
                }
                RxBus.getInstance().send(true, Constant.LOADING_COMPLETE_SIGNAL);       //通知已經加載完畢
            }
        });
    }
}
 
開發者ID:Mindjet,項目名稱:LiteReader,代碼行數:24,代碼來源:StaffDetailSummaryViewModel.java


注:本文中的rx.functions.Action1類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。