當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。