/** * 启动Aviary图片编辑器 * * @param uri 图片的URI * @param outputFilePath 输出的图片的路径 */ private void startFeather(Uri uri, String outputFilePath) { // Create the intent needed to start feather Intent newIntent = new Intent(this, FeatherActivity.class); // set the source image uri newIntent.setData(uri); // pass the required api_key and secret newIntent.putExtra("API_KEY", API_KEY); // pass the uri of the destination image file (optional) // This will be the same uri you will receive in the onActivityResult newIntent.putExtra("output", Uri.parse("file://" + outputFilePath)); // 返回时data中保存的uri // format of the destination image (optional) newIntent.putExtra(Constants.EXTRA_OUTPUT_FORMAT, Bitmap.CompressFormat.JPEG.name()); // output format quality (optional) newIntent.putExtra(Constants.EXTRA_OUTPUT_QUALITY, 90); newIntent.putExtra(Constants.EXTRA_TOOLS_DISABLE_VIBRATION, true); final DisplayMetrics metrics = new DisplayMetrics(); getWindowManager().getDefaultDisplay().getMetrics(metrics); int max_size = Math.min(metrics.widthPixels, metrics.heightPixels); max_size = (int) (max_size / 0.8); newIntent.putExtra("max-image-size", max_size); // Enable/disable the default borders for the effects newIntent.putExtra("effect-enable-borders", true); // The session-id key must be 64 char length mSessionId = StringUtils.getSha256(System.currentTimeMillis() + API_KEY); newIntent.putExtra("output-hires-session-id", mSessionId); startActivityForResult(newIntent, ConstantUtil.REQUEST_AVIARY_FEATURE); }
@Override public boolean execute(String action, JSONArray args, final CallbackContext callbackContext) throws JSONException { mFolderName = args.isNull(10) ? mFolderName : args.getString(10); mGalleryFolder = createFolders(); if (action.equals("show")) { try { Log.i(LOG_TAG, action); this.callbackContext = callbackContext; // make sure an image URI has been provided if (args.isNull(0)) { callbackContext.error("Cannot start aviary, an image URI is required."); return true; } // parameters String source = args.getString(0); // 0 - image URI String outputFormat = args.isNull(1) ? Bitmap.CompressFormat.JPEG.name() : args.getString(1); // 1 - EXTRA_OUTPUT_FORMAT int quality = args.isNull(2) ? 95 : args.getInt(2); // 2 - EXTRA_OUTPUT_QUALITY String[] toolList = new String[] {}; // 3 - EXTRA_TOOLS_LIST if (!args.isNull(3)) { JSONArray toolArray = args.getJSONArray(3); toolList = new String[toolArray.length()]; for (int i = 0; i < toolArray.length(); i++) { toolList[i] = toolArray.getString(i); } } Boolean hideExitUnsaveConfirmation = args.isNull(4) ? false : args.getBoolean(4); // 4 - EXTRA_HIDE_EXIT_UNSAVE_CONFIRMATION Boolean enableEffectsPacks = args.isNull(5) ? false : args.getBoolean(5); // 5 - EXTRA_EFFECTS_ENABLE_EXTERNAL_PACKS Boolean enableFramesPacks = args.isNull(6) ? false : args.getBoolean(6); // 6 - EXTRA_FRAMES_ENABLE_EXTERNAL_PACKS Boolean enableStickersPacks = args.isNull(7) ? false : args.getBoolean(7); // 7 - EXTRA_STICKERS_ENABLE_EXTERNAL_PACKS Boolean disableVibration = args.isNull(8) ? false : args.getBoolean(8); // 8 - EXTRA_TOOLS_DISABLE_VIBRATION Boolean inSaveOnNoChanges = args.isNull(9) ? true : args.getBoolean(9); // 9 - EXTRA_IN_SAVE_ON_NO_CHANGES // get URI Uri uri = Uri.parse(source); // first check the external storage availability if (!isExternalStorageAvilable()) { callbackContext.error("Cannot start aviary, external storage unavailable."); return true; } String mOutputFilePath; // create a temporary file where to store the resulting image File file = getNextFileName(); if (null != file) { mOutputFilePath = file.getAbsolutePath(); } else { callbackContext.error("Cannot start aviary, failed to create a temp file."); return true; } // Create the intent needed to start feather Class<FeatherActivity> clsAviary = FeatherActivity.class; Intent newIntent = new Intent(this.cordova.getActivity(), clsAviary); // set the parameters newIntent.setData(uri); newIntent.putExtra(Constants.EXTRA_OUTPUT, Uri.parse("file://" + mOutputFilePath)); newIntent.putExtra(Constants.EXTRA_OUTPUT_FORMAT, outputFormat); newIntent.putExtra(Constants.EXTRA_OUTPUT_QUALITY, quality); if (toolList.length > 0) { newIntent.putExtra(Constants.EXTRA_TOOLS_LIST, toolList); } newIntent.putExtra( Constants.EXTRA_HIDE_EXIT_UNSAVE_CONFIRMATION, hideExitUnsaveConfirmation); newIntent.putExtra(Constants.EXTRA_EFFECTS_ENABLE_EXTERNAL_PACKS, enableEffectsPacks); newIntent.putExtra(Constants.EXTRA_FRAMES_ENABLE_EXTERNAL_PACKS, enableFramesPacks); newIntent.putExtra(Constants.EXTRA_STICKERS_ENABLE_EXTERNAL_PACKS, enableStickersPacks); // http://developers.aviary.com/docs/android/intent-parameters#EXTRA_MAX_IMAGE_SIZE // newIntent.putExtra(Constants.EXTRA_MAX_IMAGE_SIZE, 1000); // since a minor bug exists that when explicitly setting this to false disables vibration so // only set if true if (disableVibration) { newIntent.putExtra(Constants.EXTRA_TOOLS_DISABLE_VIBRATION, disableVibration); } newIntent.putExtra(Constants.EXTRA_IN_SAVE_ON_NO_CHANGES, inSaveOnNoChanges); cordova.getActivity().startActivityForResult(newIntent, ACTION_REQUEST_FEATHER); cordova.setActivityResultCallback(this); return true; } catch (Exception ex) { Log.e(LOG_TAG, ex.toString()); callbackContext.error("Unknown error occured showing aviary."); } } else if (action.equals("prepareForShow")) { // nothing to do on Android callbackContext.success(); } return false; }