当前位置: 首页>>代码示例>>Java>>正文


Java DeferredAsyncTask类代码示例

本文整理汇总了Java中org.jdeferred.android.DeferredAsyncTask的典型用法代码示例。如果您正苦于以下问题:Java DeferredAsyncTask类的具体用法?Java DeferredAsyncTask怎么用?Java DeferredAsyncTask使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


DeferredAsyncTask类属于org.jdeferred.android包,在下文中一共展示了DeferredAsyncTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createProfile

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void createProfile() {
    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager.when(new DeferredAsyncTask<Void, Object, CreateProfileResponse>() {

        @Override
        protected CreateProfileResponse doInBackgroundSafe(Void... voids) throws Exception {
            // Support en-us or zh-CN.
            return client.createProfile("en-US");
        }
    }).done(response -> {
        Log.d(TAG, "Succeeded to create profile. IdentificationProfileId:" + response.verificationProfileId);
        fetchProfiles();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable throwable) {
            Log.e(TAG, "Failed to fetch user profiles.", throwable);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:27,代码来源:ProfileListFragment.java

示例2: createProfile

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void createProfile() {
    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager.when(new DeferredAsyncTask<Void, Object, CreateProfileResponse>() {

        @Override
        protected CreateProfileResponse doInBackgroundSafe(Void... voids) throws Exception {
            // Support en-us or zh-CN.
            return client.createProfile("en-us");
        }
    }).done(response -> {
        Log.d(TAG, "Succeeded to create profile. IdentificationProfileId:" + response.identificationProfileId);
        fetchProfiles();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable throwable) {
            Log.e(TAG, "Failed to fetch user profiles.", throwable);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:27,代码来源:ProfileListFragment.java

示例3: onActivityCreated

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    getActivity().setTitle(getString(R.string.title_register_audio));

    remainingEnrollmentsTextView.setText("Remaining enrollments count: " + String.valueOf(remainingEnrollmentsCount));

    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager.when(new DeferredAsyncTask<Void, Object, List<VerificationPhrase>>() {

        @Override
        protected List<VerificationPhrase> doInBackgroundSafe(Void... voids) throws Exception {
            return client.getPhrases("en-US");
        }
    }).done(results -> {
        StringBuilder builder = new StringBuilder();
        builder.append("Phrases is below. You must speech one of the phrases.");
        builder.append("\n\n");
        for (VerificationPhrase result : results) {
            builder.append(result.phrase);
            builder.append("\n\n");
        }
        phraseTextView.setText(builder.toString());

        Log.d(TAG, builder.toString());
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed to fetch phrase.", e);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:40,代码来源:AudioRegisterFragment.java

示例4: registerAudio

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void registerAudio() {
    String filePath = FileHelper.getFilename(verificationProfileId);

    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager
            .when(new DeferredAsyncTask<Void, Object, Enrollment>() {

                @Override
                protected Enrollment doInBackgroundSafe(Void... voids) throws Exception {
                    InputStream inputStream = new FileInputStream(filePath);
                    return client.enroll(inputStream, UUID.fromString(verificationProfileId));
                }
            })
            .done(enrollment -> {
                Log.d(TAG, "remainingEnrollments: " + enrollment.remainingEnrollments);
                Log.d(TAG, "phrase: " + enrollment.phrase);

                if (enrollment.remainingEnrollments <= 0) {
                    Toast.makeText(getContext(), "Success.", Toast.LENGTH_SHORT).show();
                } else {
                    Toast.makeText(getContext(), "Remaining enrollments are " + enrollment.remainingEnrollments, Toast.LENGTH_SHORT).show();
                }
            })
            .fail(new AndroidFailCallback<Throwable>() {

                @Override
                public void onFail(Throwable throwable) {
                    Log.e(TAG, "Failed to register audio.", throwable);
                    Toast.makeText(getContext(), "Failed", Toast.LENGTH_SHORT).show();
                }

                @Override
                public AndroidExecutionScope getExecutionScope() {
                    return null;
                }
            });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:38,代码来源:AudioRegisterFragment.java

示例5: removeProfile

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void removeProfile() {
    AndroidDeferredManager deferredManager = new AndroidDeferredManager();
    deferredManager.when(new DeferredAsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackgroundSafe(Void... voids) throws Exception {
            client.deleteProfile(UUID.fromString(verificationProfileId));
            return null;
        }
    }).done(result -> {
        Log.d(TAG, "Success");
        Toast.makeText(getContext(), "Success", Toast.LENGTH_SHORT).show();
        getActivity().getSupportFragmentManager().popBackStack();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed to remove user profile.", e);
            Toast.makeText(getContext(), "Failed", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:28,代码来源:AudioRegisterFragment.java

示例6: fetchProfiles

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void fetchProfiles() {
    // jdeferred
    // See https://github.com/jdeferred/jdeferred
    new AndroidDeferredManager().when(new DeferredAsyncTask<Void, Object, List<Profile>>() {

        @Override
        protected List<Profile> doInBackgroundSafe(Void... voids) throws Exception {
            List<Profile> profiles = client.getProfiles();
            // Sort by createdDateTime.
            Collections.sort(profiles, (p1, p2) -> p2.createdDateTime.compareTo(p1.createdDateTime));
            return profiles;
        }
    }).done(profiles -> {
        for (Profile profile : profiles) {
            Log.d(TAG, "verificationProfileId: " + profile.verificationProfileId);
            Log.d(TAG, "remainingEnrollmentsCount: " + profile.remainingEnrollmentsCount);
            Log.d(TAG, "enrollmentsCount: " + profile.enrollmentsCount);
            Log.d(TAG, "locale: " + profile.locale);
            Log.d(TAG, "createdDateTime: " + profile.createdDateTime);
            Log.d(TAG, "lastActionDateTime: " + profile.lastActionDateTime);
            Log.d(TAG, "enrollmentStatus: " + profile.enrollmentStatus);
        }

        viewModels.clear();
        viewModels.addAll(profiles);

        recyclerView.getAdapter().notifyDataSetChanged();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable throwable) {
            Log.e(TAG, "Failed to fetch user profiles.", throwable);
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:41,代码来源:ProfileListFragment.java

示例7: fetchPhases

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void fetchPhases() {
    new AndroidDeferredManager().when(new DeferredAsyncTask<Void, Object, List<VerificationPhrase>>() {

        @Override
        protected List<VerificationPhrase> doInBackgroundSafe(Void... voids) throws Exception {
            return client.getPhrases("en-US");
        }
    }).done(results -> {
        StringBuilder builder = new StringBuilder();
        builder.append("Phrases is below. You must speech one of the phrases.");
        builder.append("\n\n");
        for (VerificationPhrase result : results) {
            builder.append(result.phrase);
            builder.append("\n\n");
        }
        phraseTextView.setText(builder.toString());
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed to fetch phrase.", e);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:31,代码来源:VerificationFragment.java

示例8: identification

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void identification(List<UUID> identificationProfileIds) {
    String path = FileHelper.getFilename("xxx");
    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager.when(new DeferredAsyncTask<Void, Object, OperationLocation>() {

        @Override
        protected OperationLocation doInBackgroundSafe(Void... voids) throws Exception {
            InputStream inputStream = new FileInputStream(path);
            return client.identify(inputStream, identificationProfileIds, true);
        }
    }).done(location -> {
        // Recognition processing does not end immediately, so keep operation location here.
        Log.d(TAG, "OperationLocation: " + location.Url);
        operationLocation = location;
        checkResultButton.setEnabled(true);
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed to identify.", e);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:30,代码来源:IdentificationFragment.java

示例9: checkResult

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void checkResult() {
    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager.when(new DeferredAsyncTask<Void, Object, IdentificationOperation>() {

        @Override
        protected IdentificationOperation doInBackgroundSafe(Void... voids) throws Exception {
            return client.checkIdentificationStatus(operationLocation);
        }
    }).done(operation -> {
        Log.d(TAG, "Status: " + operation.status);

        if (Status.SUCCEEDED == operation.status) {
            Identification identification = operation.processingResult;
            Log.d(TAG, "identifiedProfileId: " + identification.identifiedProfileId);
            Log.d(TAG, "confidence: " + identification.confidence);
            Toast.makeText(getContext(), "You are " + identification.identifiedProfileId, Toast.LENGTH_SHORT).show();
        } else {
            Log.d(TAG, "Not enrolled yet. Message: " + operation.message);
            Toast.makeText(getContext(), operation.message, Toast.LENGTH_SHORT).show();
        }
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed.", e);
            Toast.makeText(getContext(), "Failed.", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:35,代码来源:IdentificationFragment.java

示例10: registerAudio

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void registerAudio(String filePath) {
    AndroidDeferredManager manager = new AndroidDeferredManager();
    manager
            .when(new DeferredAsyncTask<Void, Object, OperationLocation>() {

                @Override
                protected OperationLocation doInBackgroundSafe(Void... voids) throws Exception {
                    InputStream inputStream = new FileInputStream(filePath);
                    return client.enroll(inputStream, UUID.fromString(identificationProfileId), true);
                }
            })
            .done(location -> {
                Log.d(TAG, "EnrollmentStatus: " + location.Url);
                Toast.makeText(getContext(), "Success.", Toast.LENGTH_SHORT).show();
            })
            .fail(new AndroidFailCallback<Throwable>() {

                @Override
                public void onFail(Throwable throwable) {
                    Log.e(TAG, "Failed to register audio.", throwable);
                    Toast.makeText(getContext(), "Failed", Toast.LENGTH_SHORT).show();
                }

                @Override
                public AndroidExecutionScope getExecutionScope() {
                    return null;
                }
            });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:30,代码来源:AudioRegisterFragment.java

示例11: removeProfile

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void removeProfile() {
    AndroidDeferredManager deferredManager = new AndroidDeferredManager();
    deferredManager.when(new DeferredAsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackgroundSafe(Void... voids) throws Exception {
            client.deleteProfile(UUID.fromString(identificationProfileId));
            return null;
        }
    }).done(result -> {
        Log.d(TAG, "Success");
        Toast.makeText(getContext(), "Success", Toast.LENGTH_SHORT).show();
        getActivity().getSupportFragmentManager().popBackStack();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable e) {
            Log.e(TAG, "Failed to remove user profile.", e);
            Toast.makeText(getContext(), "Failed", Toast.LENGTH_SHORT).show();
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:28,代码来源:AudioRegisterFragment.java

示例12: fetchProfiles

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
private void fetchProfiles() {
    // jdeferred
    // See https://github.com/jdeferred/jdeferred
    new AndroidDeferredManager().when(new DeferredAsyncTask<Void, Object, List<Profile>>() {
        @Override
        protected List<Profile> doInBackgroundSafe(Void... voids) throws Exception {
            List<Profile> profiles = client.getProfiles();
            // Sort by createdDateTime.
            Collections.sort(profiles, (p1, p2) -> p2.createdDateTime.compareTo(p1.createdDateTime));
            return profiles;
        }
    }).done(profiles -> {
        for (Profile profile : profiles) {
            Log.d(TAG, "identificationProfileId: " + profile.identificationProfileId);
            Log.d(TAG, "enrollmentSpeechTime: " + profile.enrollmentSpeechTime);
            Log.d(TAG, "remainingEnrollmentSpeechTime: " + profile.remainingEnrollmentSpeechTime);
            Log.d(TAG, "locale: " + profile.locale);
            Log.d(TAG, "createdDateTime: " + profile.createdDateTime);
            Log.d(TAG, "lastActionDateTime: " + profile.lastActionDateTime);
            Log.d(TAG, "enrollmentStatus: " + profile.enrollmentStatus);
        }

        viewModels.clear();
        viewModels.addAll(profiles);

        recyclerView.getAdapter().notifyDataSetChanged();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable throwable) {
            Log.e(TAG, "Failed to fetch user profiles.", throwable);
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:40,代码来源:ProfileListFragment.java

示例13: getEntriesAsync

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
@Override
final Promise<Object, Throwable, Void> getEntriesAsync(final Context context) {
    DeferredAsyncTask<Void, Void, Object> deferredAsyncTask = new DeferredAsyncTask<Void, Void, Object>() {
        @Override
        protected Object doInBackgroundSafe(Void... objects) throws Exception {
            return getEntries(context);
        }
    };
    deferredAsyncTask.execute();
    return deferredAsyncTask.promise();
}
 
开发者ID:michalbednarski,项目名称:IntentsLab,代码行数:12,代码来源:AsyncTaskFetcher.java

示例14: testDeferredAsyncTask

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
public void testDeferredAsyncTask() {
	final ValueHolder<String> backgroundThreadGroupName = new ValueHolder<String>();
	final ValueHolder<String> doneThreadGroupName = new ValueHolder<String>();

	try {
		dm.when(new DeferredAsyncTask<Void, Integer, String>() {
			@Override
			protected String doInBackgroundSafe(Void... nil)
					throws Exception {
				backgroundThreadGroupName.set(Thread.currentThread()
						.getThreadGroup().getName());
				return "Done";
			}
		}).done(new DoneCallback<String>() {

			@Override
			public void onDone(String result) {
				doneThreadGroupName.set(Thread.currentThread()
						.getThreadGroup().getName());
			}

		}).waitSafely();
	} catch (InterruptedException e) {
		// Do nothing
	}

	doneThreadGroupName.assertEquals("main");
	Assert.assertFalse(
			String.format(
					"Background Thread Group [%s] shouldn't be the same as Thread Group in Done [%s]",
					backgroundThreadGroupName.get(),
					doneThreadGroupName.get()), backgroundThreadGroupName
					.equals(doneThreadGroupName));
}
 
开发者ID:jdeferred,项目名称:jdeferred,代码行数:35,代码来源:AndroidDeferredManagerTest.java

示例15: onActivityCreated

import org.jdeferred.android.DeferredAsyncTask; //导入依赖的package包/类
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    getActivity().setTitle(getString(R.string.title_verification));

    new AndroidDeferredManager().when(new DeferredAsyncTask<Void, Object, List<Profile>>() {

        @Override
        protected List<Profile> doInBackgroundSafe(Void... voids) throws Exception {
            List<Profile> profiles = client.getProfiles();
            // Sort by createdDateTime.
            Collections.sort(profiles, (p1, p2) -> p2.createdDateTime.compareTo(p1.createdDateTime));
            return profiles;
        }
    }).done(profiles -> {
        if (profiles == null || profiles.size() == 0) {
            Toast.makeText(getContext(), "Please register audio first.", Toast.LENGTH_SHORT).show();
            return;
        }
        List<UUID> ids = new ArrayList<>(profiles.size());
        for (Profile profile : profiles) {
            ids.add(profile.verificationProfileId);
        }

        new MaterialDialog.Builder(getContext())
                .title("Select speaker")
                .content("Select speaker id for verification.")
                .items(ids)
                .cancelable(false)
                .itemsCallbackSingleChoice(-1, (dialog1, itemView, which, text) -> {
                    verificationProfileId = (String) text;
                    return true;
                })
                .show();

        fetchPhases();
    }).fail(new AndroidFailCallback<Throwable>() {

        @Override
        public void onFail(Throwable throwable) {
            Log.e(TAG, "Failed to fetch user profiles.", throwable);
        }

        @Override
        public AndroidExecutionScope getExecutionScope() {
            return null;
        }
    });
}
 
开发者ID:lakeel-altla,项目名称:samples-cognitive-services-android,代码行数:50,代码来源:VerificationFragment.java


注:本文中的org.jdeferred.android.DeferredAsyncTask类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。