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


Java Promise类代码示例

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


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

示例1: share

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
/**
 * Open a chooser dialog to send text content to other apps.
 *
 * Refer http://developer.android.com/intl/ko/training/sharing/send.html
 *
 * @param content the data to send
 * @param dialogTitle the title of the chooser dialog
 */
@ReactMethod
public void share(ReadableMap content, String dialogTitle, Promise promise) {
  if (content == null) {
    promise.reject(ERROR_INVALID_CONTENT, "Content cannot be null");
    return;
  }

  try {
    Intent intent = new Intent(Intent.ACTION_SEND);
    intent.setTypeAndNormalize("text/plain");

    if (content.hasKey("title")) {
      intent.putExtra(Intent.EXTRA_SUBJECT, content.getString("title"));
    }

    if (content.hasKey("message")) {
      intent.putExtra(Intent.EXTRA_TEXT, content.getString("message"));
    }

    Intent chooser = Intent.createChooser(intent, dialogTitle);
    chooser.addCategory(Intent.CATEGORY_DEFAULT);

    Activity currentActivity = getCurrentActivity();
    if (currentActivity != null) {
      currentActivity.startActivity(chooser);
    } else {
      getReactApplicationContext().startActivity(chooser);
    }
    WritableMap result = Arguments.createMap();
    result.putString("action", ACTION_SHARED);
    promise.resolve(result);
  } catch (Exception e) {
    promise.reject(ERROR_UNABLE_TO_OPEN_DIALOG, "Failed to open share dialog");
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:44,代码来源:ShareModule.java

示例2: getAvailableVoices

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void getAvailableVoices(Promise promise) {
	if(notReady(promise)) return;

	try {
		WritableArray voicesList = Arguments.createArray();
		Voice[] array = tts.getVoices().toArray(new Voice[tts.getVoices().size()]);
		for(Voice voice: array) {
			WritableMap newVoice = returnMapForVoice(voice);
			voicesList.pushMap(newVoice);
		}

		promise.resolve(voicesList);
	} catch(Exception e) {
		promise.reject("not_found", "Unable to retrieve voices for getAvailableVoices()", e);
	}
}
 
开发者ID:echo8795,项目名称:react-native-android-text-to-speech,代码行数:18,代码来源:RNAndroidTextToSpeechModule.java

示例3: getImageIntentBase64

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void getImageIntentBase64(Promise promise) {
    if (getCurrentActivity() != null) {
        Intent intent = getCurrentActivity().getIntent();
        if (intent != null) {
            String action = intent.getAction();
            String type = intent.getType();

            if (Intent.ACTION_SEND.equals(action) && type != null) {
                if (type.startsWith("image/")) {
                    encodedImage = handleSendImage(intent); // Handle single image being sent
                }
            }
        }
    }

    if (encodedImage != null) {
        promise.resolve(encodedImage);
    } else {
        promise.reject("IMAGE_NOT_FOUND");
    }
}
 
开发者ID:sonnylazuardi,项目名称:react-native-image-intent,代码行数:23,代码来源:ImageIntentModule.java

示例4: getAppBrightness

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void getAppBrightness(Promise promise) {
    final Activity curActivity = getCurrentActivity();
    if(curActivity == null) {
        return;
    }
    try {
        float result = curActivity.getWindow().getAttributes().screenBrightness;
        if(result < 0){
            int val = Settings.System.getInt(getReactApplicationContext().getContentResolver(), Settings.System.SCREEN_BRIGHTNESS);
            promise.resolve(val * 1.0f / 255);
        }else{
            promise.resolve(result);
        }
    } catch (Exception e) {
        e.printStackTrace();
        promise.reject("-1", "get app's brightness fail", e);
    }
}
 
开发者ID:c19354837,项目名称:react-native-system-setting,代码行数:20,代码来源:SystemSetting.java

示例5: createAndSendTransaction

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
/**
 * Create and send transaction.
 *
 * @param passphrase Passphrase
 * @param nonce      Account nonce (use -1 to use last known nonce)
 * @param toAddress  Address destination
 * @param amount     Amount
 * @param gasLimit   Gas limit
 * @param gasPrice   Gas price
 * @param data
 * @param promise    Promise
 * @return Return String transaction
 */
@ReactMethod
public void createAndSendTransaction(String passphrase, double nonce, String toAddress,
                                     double amount, double gasLimit, double gasPrice,
                                     String data, Promise promise) {
    try {
        Account acc = GethHolder.getAccount();
        Address fromAddress = acc.getAddress();
        BigInt chain = new BigInt(GethHolder.getNodeConfig().getEthereumNetworkID());
        Context ctx = new Context();

        if (nonce == -1) {
          nonce = GethHolder.getNode().getEthereumClient().getPendingNonceAt(ctx, fromAddress);
        }

        Transaction tx = new Transaction(
                (long) nonce,
                new Address(toAddress),
                new BigInt((long) amount),
                new BigInt((long) gasLimit),
                new BigInt((long) gasPrice),
                data.getBytes("UTF8"));

        // Sign a transaction with a single authorization
        Transaction signed = GethHolder.getKeyStore().signTxPassphrase(acc, passphrase, tx, chain);
        // Send it out to the network.
        GethHolder.getNode().getEthereumClient().sendTransaction(ctx, signed);
        promise.resolve(tx.toString());
    } catch (Exception e) {
        promise.reject(NEW_TRANSACTION_ERROR, e);
    }
}
 
开发者ID:YsnKsy,项目名称:react-native-geth,代码行数:45,代码来源:RNGethModule.java

示例6: initFingerPrintIdentify

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void initFingerPrintIdentify(final Promise promise) {
  currentActivity = getCurrentActivity();
  if(currentActivity != null) {
    if(this.mFingerprintIdentify == null) {
      this.mFingerprintIdentify = new FingerprintIdentify(currentActivity, new BaseFingerprint.FingerprintIdentifyExceptionListener() {
        @Override
        public void onCatchException(Throwable exception) {
          Log.d("ReactNative", "ERROR FINGERPRINT: " + exception.getLocalizedMessage());
        }
      });
    }
    sendResponse("ok", null, promise);
  } else {
    sendResponse("failed", "ERROR_INITIALIZED", promise);
  }
}
 
开发者ID:williamtran29,项目名称:react-native-fingerprint-identify,代码行数:18,代码来源:RNFingerprintIdentifyModule.java

示例7: getSessionInfo

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void getSessionInfo(final Promise callback) {
    Taplytics.getSessionInfo(new SessionInfoRetrievedListener() {
        @Override
        public void sessionInfoRetrieved(HashMap hashMap) {
            WritableMap resultData = new WritableNativeMap();
            if(hashMap.containsKey("session_id")){
                resultData.putString("session_id", (String) hashMap.get("session_id"));
            }
            if(hashMap.containsKey("appUser_id")){
                resultData.putString("appUser_id", (String) hashMap.get("appUser_id"));
            }

            callback.resolve(resultData);
        }
    });
}
 
开发者ID:taplytics,项目名称:taplytics-react-native,代码行数:18,代码来源:TaplyticsReactModule.java

示例8: queryCache

import com.facebook.react.bridge.Promise; //导入依赖的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);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:22,代码来源:ImageLoaderModule.java

示例9: toGraphDef

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void toGraphDef(String id, Promise promise) {
    try {
        Graph graph = graphs.get(id);
        promise.resolve(Base64.encodeToString(graph.toGraphDef(), Base64.DEFAULT));
    } catch (Exception e) {
        promise.reject(e);
    }
}
 
开发者ID:reneweb,项目名称:react-native-tensorflow,代码行数:10,代码来源:RNTensorFlowGraphModule.java

示例10: close

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void close(String id, Promise promise) {
    try {
        Graph graph = graphs.get(id);
        graph.close();
        promise.resolve(true);
    } catch (Exception e) {
        promise.reject(e);
    }
}
 
开发者ID:reneweb,项目名称:react-native-tensorflow,代码行数:11,代码来源:RNTensorFlowGraphModule.java

示例11: signB64Data

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void signB64Data(final String privKeyData, final String password, final String b64Data, Promise promise) {
  try {
    // region Decode Base64
    byte[] data = Base64.decode(b64Data, Base64.DEFAULT);
    // endregion
    // region Decode Private Key
    PGPSecretKey secKey = PGPUtils.getSecretKey(privKeyData);
    PGPPrivateKey privKey = PGPUtils.decryptArmoredPrivateKey(secKey, password);
    // endregion
    // region Sign Data
    String signature = PGPUtils.signArmoredAscii(privKey, data, signatureAlgo);
    WritableMap resultMap = Arguments.createMap();
    resultMap.putString("asciiArmoredSignature", signature);
    resultMap.putString("hashingAlgo",  PGPUtils.hashAlgoToString(signatureAlgo));
    resultMap.putString("fingerPrint", Utils.bytesToHex(secKey.getPublicKey().getFingerprint()));
    promise.resolve(resultMap);
    // endregion
  } catch (Exception e) {
    promise.reject(e);
  }
}
 
开发者ID:quan-to,项目名称:react-native-pgp,代码行数:23,代码来源:Module.java

示例12: getEnginesInfo

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void getEnginesInfo(Promise promise) {
	if(notReady(promise)) return;

	try {
		WritableArray ttsInfo = Arguments.createArray();

		List<TextToSpeech.EngineInfo> engineList = tts.getEngines();
		Iterator iterator = engineList.iterator();
		while(iterator.hasNext()) {
			ttsInfo.pushString(iterator.next().toString());
		}

		promise.resolve(ttsInfo);
	} catch(Exception e) {
		promise.reject("error", "Unable to retrieve TTS Engine info for getEnginesInfo()", e);
	}
}
 
开发者ID:echo8795,项目名称:react-native-android-text-to-speech,代码行数:19,代码来源:RNAndroidTextToSpeechModule.java

示例13: createChannel

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
@ReactMethod
public void createChannel(ReadableMap options, final Promise promise) {
    final JSONObject attributes = RCTConvert.readableMapToJson(options.getMap("attributes"));
    final String uniqueName = options.getString("uniqueName");
    String friendlyName = options.getString("friendlyName");
    Channel.ChannelType type = (options.getString("type").compareTo("CHANNEL_TYPE_PRIVATE") == 0) ? Channel.ChannelType.PRIVATE : Channel.ChannelType.PUBLIC;

    channels().channelBuilder()
            .withUniqueName(uniqueName)
            .withFriendlyName(friendlyName)
            .withType(type)
            .withAttributes(attributes)
            .build(new CallbackListener<Channel>() {
                @Override
                public void onError(final ErrorInfo errorInfo) {
                    super.onError(errorInfo);
                    promise.reject("create-channel-error", "Error occurred while attempting to createChannel.");
                }

                @Override
                public void onSuccess(final Channel newChannel) {
                    promise.resolve(RCTConvert.Channel(newChannel));
                }
            });
}
 
开发者ID:ccm-innovation,项目名称:react-native-twilio-chat,代码行数:26,代码来源:RCTTwilioChatChannels.java

示例14: canOpenURL

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
/**
 * Determine whether or not an installed app can handle a given URL.
 *
 * @param url the URL to open
 * @param promise a promise that is always resolved with a boolean argument
 */
@ReactMethod
public void canOpenURL(String url, Promise promise) {
  if (url == null || url.isEmpty()) {
    promise.reject(new JSApplicationIllegalArgumentException("Invalid URL: " + url));
    return;
  }

  try {
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    // We need Intent.FLAG_ACTIVITY_NEW_TASK since getReactApplicationContext() returns
    // the ApplicationContext instead of the Activity context.
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    boolean canOpen =
        intent.resolveActivity(getReactApplicationContext().getPackageManager()) != null;
    promise.resolve(canOpen);
  } catch (Exception e) {
    promise.reject(new JSApplicationIllegalArgumentException(
        "Could not check if URL '" + url + "' can be opened: " + e.getMessage()));
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:27,代码来源:IntentModule.java

示例15: getInitialURL

import com.facebook.react.bridge.Promise; //导入依赖的package包/类
/**
 * Return the URL the activity was started with
 *
 * @param promise a promise which is resolved with the initial URL
 */
@ReactMethod
public void getInitialURL(Promise promise) {
  try {
    Activity currentActivity = getCurrentActivity();
    String initialURL = null;

    if (currentActivity != null) {
      Intent intent = currentActivity.getIntent();
      String action = intent.getAction();
      Uri uri = intent.getData();

      if (Intent.ACTION_VIEW.equals(action) && uri != null) {
        initialURL = uri.toString();
      }
    }

    promise.resolve(initialURL);
  } catch (Exception e) {
    promise.reject(new JSApplicationIllegalArgumentException(
        "Could not get the initial URL : " + e.getMessage()));
  }
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:28,代码来源:IntentModule.java


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