当前位置: 首页>>代码示例>>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;未经允许,请勿转载。