本文整理汇总了Java中com.facebook.react.bridge.GuardedAsyncTask类的典型用法代码示例。如果您正苦于以下问题:Java GuardedAsyncTask类的具体用法?Java GuardedAsyncTask怎么用?Java GuardedAsyncTask使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
GuardedAsyncTask类属于com.facebook.react.bridge包,在下文中一共展示了GuardedAsyncTask类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onCatalystInstanceDestroy
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@Override
public void onCatalystInstanceDestroy() {
try {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
if (client != null) {
client.disconnect(false);
}
if (server != null) {
server.close();
}
}
}.execute().get();
} catch (InterruptedException ioe) {
Log.e(eTag, "onCatalystInstanceDestroy", ioe);
} catch (ExecutionException ee) {
Log.e(eTag, "onCatalystInstanceDestroy", ee);
}
}
示例2: clear
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
/**
* Clears the database.
*/
@ReactMethod
public void clear(final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
if (!mReactDatabaseSupplier.ensureDatabase()) {
callback.invoke(AsyncStorageErrorUtil.getDBError(null));
return;
}
try {
mReactDatabaseSupplier.clear();
callback.invoke();
} catch (Exception e) {
FLog.w(ReactConstants.TAG, e.getMessage(), e);
callback.invoke(AsyncStorageErrorUtil.getError(null, e.getMessage()));
}
}
}.execute();
}
示例3: queryCache
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void queryCache(final ReadableArray uris, final Promise promise) {
// perform cache interrogation in async task as disk cache checks are expensive
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
WritableMap result = Arguments.createMap();
ImagePipeline imagePipeline = Fresco.getImagePipeline();
for (int i = 0; i < uris.size(); i++) {
String uriString = uris.getString(i);
final Uri uri = Uri.parse(uriString);
if (imagePipeline.isInBitmapMemoryCache(uri)) {
result.putString(uriString, "memory");
} else if (imagePipeline.isInDiskCacheSync(uri)) {
result.putString(uriString, "disk");
}
}
promise.resolve(result);
}
}.executeOnExecutor(GuardedAsyncTask.THREAD_POOL_EXECUTOR);
}
示例4: getLocale
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
/***
* This method will expose all the available languages in TTS engine
*
* @param callback
*/
@ReactMethod
public void getLocale(final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
try {
if (tts == null) {
init();
}
Locale[] locales = Locale.getAvailableLocales();
WritableArray data = Arguments.createArray();
for (Locale locale : locales) {
int res = tts.isLanguageAvailable(locale);
if (res == TextToSpeech.LANG_COUNTRY_AVAILABLE) {
data.pushString(locale.getLanguage());
}
}
callback.invoke(null, data);
} catch (Exception e) {
callback.invoke(e.getMessage());
}
}
}.execute();
}
示例5: isSpeaking
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void isSpeaking(final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
try {
if (tts.isSpeaking()) {
callback.invoke(null, true);
} else {
callback.invoke(null, false);
}
} catch (Exception e) {
callback.invoke(e.getMessage());
}
}
}.execute();
}
示例6: shutDown
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void shutDown(final Callback callBack) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void... params) {
if (tts == null) {
callBack.invoke(true);
}
try {
tts.shutdown();
callBack.invoke(null, true);
} catch (Exception e) {
callBack.invoke(e.getMessage());
}
}
}.execute();
}
示例7: query
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void query(final String sql, final ReadableArray values, final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void ...params) {
WritableArray data = Arguments.createArray();
// FLog.w(ReactConstants.TAG, "dbmanager.query.sql=%s", sql);
// FLog.w(ReactConstants.TAG, "dbmanager.query.values.size()=%d", values.size());
try {
data = mDb.query(sql, values);
} catch(Exception e) {
FLog.w(ReactConstants.TAG, "Exception in database query: ", e);
callback.invoke(ErrorUtil.getError(null, e.getMessage()), null);
}
callback.invoke(null, data);
}
}.execute();
}
示例8: exec
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void exec(final String sql, final ReadableArray values, final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void ...params) {
try {
mDb.exec(sql, values);
} catch(Exception e) {
FLog.w(ReactConstants.TAG, "Exception in database exec: ", e);
callback.invoke(ErrorUtil.getError(null, e.getMessage()), null);
}
callback.invoke();
}
}.execute();
}
示例9: close
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
@ReactMethod
public void close(final Callback callback) {
new GuardedAsyncTask<Void, Void>(getReactApplicationContext()) {
@Override
protected void doInBackgroundGuarded(Void ...params) {
try {
mDb.close();
} catch(Exception e) {
FLog.w(ReactConstants.TAG, "Exception in database close: ", e);
callback.invoke(ErrorUtil.getError(null, e.getMessage()), null);
}
callback.invoke();
}
}.execute();
}
示例10: executeDbCallsAsync
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void executeDbCallsAsync(final String tableName, final Promise promise, final String createQuery, final ContentValues contentValues) {
new GuardedAsyncTask(reactContext) {
@Override
protected void doInBackgroundGuarded(Object[] params) {
SQLiteDatabase db = rnRecordSQLiteHelper.getWritableDatabase();
db.execSQL(createQuery);
promise.resolve((double)db.insert(tableName, null, contentValues));
}
}.execute();
}
示例11: executeDbCallsAsync
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void executeDbCallsAsync(final String tableName, final Promise promise) {
new GuardedAsyncTask(reactContext) {
@Override
protected void doInBackgroundGuarded(Object[] params) {
SQLiteDatabase db = rnRecordSQLiteHelper.getWritableDatabase();
promise.resolve(transformQueryResults(db.rawQuery("select * from " + tableName, null)));
}
}.execute();
}
示例12: executeDbCallsAsync
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void executeDbCallsAsync(final String queryString, final ArrayList<String> queryArguments, final Promise promise) {
new GuardedAsyncTask(reactContext) {
@Override
protected void doInBackgroundGuarded(Object[] params) {
SQLiteDatabase db = rnRecordSQLiteHelper.getWritableDatabase();
promise.resolve(transformQueryResults(db.rawQuery(queryString, queryArguments.toArray(new String[queryArguments.size()]) )));
}
}.execute();
}
示例13: executeDbCallsAsync
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void executeDbCallsAsync(final String tableName, final Promise promise, final int id) {
new GuardedAsyncTask(reactContext) {
@Override
protected void doInBackgroundGuarded(Object[] params) {
SQLiteDatabase db = rnRecordSQLiteHelper.getWritableDatabase();
promise.resolve(db.delete(tableName, "id = ?", new String[] {String.valueOf(id)} ));
}
}.execute();
}
示例14: executeDbCallsAsync
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void executeDbCallsAsync(final String tableName, final Promise promise, final ContentValues contentValues) {
new GuardedAsyncTask(reactContext) {
@Override
protected void doInBackgroundGuarded(Object[] params) {
SQLiteDatabase db = rnRecordSQLiteHelper.getWritableDatabase();
promise.resolve(db.update(tableName, contentValues, "id = ?", new String[] {contentValues.getAsString("id")} ));
}
}.execute();
}
示例15: runInBackground
import com.facebook.react.bridge.GuardedAsyncTask; //导入依赖的package包/类
private void runInBackground(final Runnable runnable) {
new GuardedAsyncTask<Void, Void>(mContext) {
@Override
protected void doInBackgroundGuarded(Void... params) {
runnable.run();
}
}.execute();
}