Search in sources :

Example 1 with RequestHandle

use of com.shizhefei.mvc.RequestHandle in project MVCHelper by LuckyJayce.

the class TestCaseFragment method getTestCaseDatas.

@Override
protected List<TestCaseData> getTestCaseDatas() {
    List<TestCaseData> datas = new ArrayList<TestCaseData>();
    TestCaseData caseData = new TestCaseData("测试登录", new LoginAsyncTask("LuckyJayce", "111"));
    caseData.addParamGet(new String[] { "name", "password" }, new IAsyncTask<Map<String, String>>() {

        @Override
        public RequestHandle execute(ResponseSender<Map<String, String>> sender) throws Exception {
            Map<String, String> map = new ArrayListMap<String, String>();
            map.put("name", "nnnnn");
            map.put("password", "ppppp");
            sender.sendData(map);
            return new RequestHandle() {

                @Override
                public boolean isRunning() {
                    return false;
                }

                @Override
                public void cancle() {
                }
            };
        }
    });
    datas.add(caseData);
    datas.add(new TestCaseData("测试详情页", new BookDetailDataSource()));
    datas.add(new TestCaseData("测试搜索文章", new SearchBookDataSource("Java")));
    datas.add(new TestCaseData("测试文章列表", new BooksOkHttpNormal_DataSource()));
    return datas;
}
Also used : RequestHandle(com.shizhefei.mvc.RequestHandle) ArrayList(java.util.ArrayList) BooksOkHttpNormal_DataSource(com.shizhefei.test.models.datasource.okhttp.BooksOkHttpNormal_DataSource) BookDetailDataSource(com.shizhefei.test.models.datasource.BookDetailDataSource) TestCaseData(com.shizhefei.mvchelper.testcase.TestCaseData) SearchBookDataSource(com.shizhefei.test.models.datasource.SearchBookDataSource) ArrayListMap(com.shizhefei.utils.ArrayListMap) Map(java.util.Map) LoginAsyncTask(com.shizhefei.test.models.task.LoginAsyncTask)

Example 2 with RequestHandle

use of com.shizhefei.mvc.RequestHandle in project MVCHelper by LuckyJayce.

the class MovieAmountTask2 method execute.

@Override
public RequestHandle execute(final ResponseSender<MovieAmount> sender) throws Exception {
    final AsyncTask<Void, Void, Void> asyncTask = new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            try {
                Thread.sleep(2000);
                Random random = new Random();
                int commentCount = random.nextInt(100);
                int playCount = random.nextInt(1000) + 10;
                long updateTime = System.currentTimeMillis();
                sender.sendData(new MovieAmount(name, commentCount, playCount, name + " " + DateFormat.format("dd kk:mm:ss", updateTime)));
            } catch (Exception e) {
                e.printStackTrace();
                sender.sendError(e);
            }
            return null;
        }
    };
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        asyncTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
    } else {
        asyncTask.execute();
    }
    return new RequestHandle() {

        @Override
        public void cancle() {
            asyncTask.cancel(true);
        }

        @Override
        public boolean isRunning() {
            return false;
        }
    };
}
Also used : Random(java.util.Random) MovieAmount(com.shizhefei.test.models.enties.MovieAmount) RequestHandle(com.shizhefei.mvc.RequestHandle) AsyncTask(android.os.AsyncTask) IAsyncTask(com.shizhefei.task.IAsyncTask)

Aggregations

RequestHandle (com.shizhefei.mvc.RequestHandle)2 AsyncTask (android.os.AsyncTask)1 TestCaseData (com.shizhefei.mvchelper.testcase.TestCaseData)1 IAsyncTask (com.shizhefei.task.IAsyncTask)1 BookDetailDataSource (com.shizhefei.test.models.datasource.BookDetailDataSource)1 SearchBookDataSource (com.shizhefei.test.models.datasource.SearchBookDataSource)1 BooksOkHttpNormal_DataSource (com.shizhefei.test.models.datasource.okhttp.BooksOkHttpNormal_DataSource)1 MovieAmount (com.shizhefei.test.models.enties.MovieAmount)1 LoginAsyncTask (com.shizhefei.test.models.task.LoginAsyncTask)1 ArrayListMap (com.shizhefei.utils.ArrayListMap)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1 Random (java.util.Random)1