List of usage examples for org.apache.cordova PluginResult setKeepCallback
public void setKeepCallback(boolean b)
From source file:com.samsung.richnotification.RichNotification.java
License:Apache License
@Override //On RichNotification Read in the gear public void onRead(UUID arg0) { if (mCallbackContext == null) return;//from w w w .j a va2s .co m try { JSONObject eventMsg = new JSONObject(); eventMsg.put("returnType", RichNotificationHelper.RETURN_TYPE_NOTIFICATION_READ); eventMsg.put("returnValue", arg0.toString()); PluginResult sentResult = new PluginResult(PluginResult.Status.OK, eventMsg); sentResult.setKeepCallback(true); mCallbackContext.sendPluginResult(sentResult); } catch (JSONException jse) { if (Log.isLoggable(RICHNOTI, Log.DEBUG)) Log.d(TAG, "Gear input invalid"); return; } }
From source file:com.samsung.richnotification.RichNotification.java
License:Apache License
@Override //On RichNotification Removed from the gear public void onRemoved(UUID arg0) { if (mCallbackContext == null) return;//from www. j av a 2 s . com try { JSONObject eventMsg = new JSONObject(); eventMsg.put("returnType", RichNotificationHelper.RETURN_TYPE_NOTIFICATION_REMOVED); eventMsg.put("returnValue", arg0.toString()); PluginResult sentResult = new PluginResult(PluginResult.Status.OK, eventMsg); sentResult.setKeepCallback(true); mCallbackContext.sendPluginResult(sentResult); } catch (JSONException jse) { if (Log.isLoggable(RICHNOTI, Log.DEBUG)) Log.d(TAG, "Gear input invalid"); return; } }
From source file:com.samsung.spen.SpenException.java
License:Apache License
/** * This method is used for sending the intermittent plugin results to the * application//w w w . j a v a 2 s. co m * * @param type * SpenExceptionType * @param callbackContext * Context of callback */ public static void sendPluginResult(SpenExceptionType type, CallbackContext callbackContext) { PluginResult pluginResult; switch (type) { case FAILED_RECOGNIZE_TEXT: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenException.SpenExceptionType.FAILED_RECOGNIZE_TEXT.toString()); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); break; case FAILED_RECOGNIZE_SHAPE: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenException.SpenExceptionType.FAILED_RECOGNIZE_SHAPE.toString()); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); break; case FAILED_SET_BACKGROUND_IMAGE: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenException.SpenExceptionType.FAILED_SET_BACKGROUND_IMAGE.toString()); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); break; case FAILED_CREATE_SURFACE: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenException.SpenExceptionType.FAILED_CREATE_SURFACE.toString()); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); break; case SURFACE_ID_NOT_EXISTS: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenExceptionType.SURFACE_ID_NOT_EXISTS.toString()); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); break; case FAILED_SAVING_IMAGE: pluginResult = new PluginResult(PluginResult.Status.ERROR, SpenExceptionType.FAILED_SAVING_IMAGE.toString()); pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); break; case INLINE_SURFACE_LIMIT_REACHED: case POPUP_SURFACE_LIMIT_REACHED: case MAX_HEAP_MEMORY_REACHED: case INVALID_SURFACE_ID: case INVALID_RETURN_TYPE: case INVALID_SURFACE_TYPE: case INVALID_FLAGS: case INVALID_INLINE_CORDINATES: case INVALID_DIMENSIONS: case MAX_SURFACE_LIMIT_REACHED: case SURFACE_ID_ALREADY_EXISTS: callbackContext.error(type.toString()); break; default: break; } }
From source file:com.samsung.spen.SPenInlineSurface.java
License:Apache License
/** * create SPen surface//from w w w . j a va2s .c o m */ boolean createSPenSurface() { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Inside createSPenSurface, creating SpenSurface"); } Activity activity = mContextParams.getSpenCustomDrawPlugin().cordova.getActivity(); boolean isSurface = false; SurfacePosition surfacePosition = mOptions.getSurfacePosition(); mRelativeLayout.setBackgroundColor(mOptions.getColor()); // Adding top traybar RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); int resId = activity.getResources().getIdentifier("spentraybar_top", "layout", activity.getPackageName()); RelativeLayout traybar_top = (RelativeLayout) View.inflate(activity, resId, null); lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); mRelativeLayout.addView(traybar_top, lp); Spen spenPackage = new Spen(); boolean isStatic = false; resId = activity.getResources().getIdentifier("spen_static", "bool", activity.getPackageName()); try { if (resId != 0) { isStatic = activity.getResources().getBoolean(resId); } } catch (Resources.NotFoundException re) { isStatic = false; } try { if (isStatic) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Initializing spen Statically"); } spenPackage.initialize(activity.getApplicationContext(), 5, Spen.SPEN_STATIC_LIB_MODE); } else { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Initializing spen Dynamically"); } spenPackage.initialize(activity.getApplicationContext()); } mSpenSurfaceView = new SpenSurfaceView(activity.getApplicationContext()); // create layout for the surface lp = new RelativeLayout.LayoutParams(surfacePosition.getWidth(), surfacePosition.getHeight()); lp.addRule(RelativeLayout.BELOW, traybar_top.getId()); ViewGroup viewGroup = (ViewGroup) mContextParams.getSpenCustomDrawPlugin().webView; if (viewGroup != null) { spenSurfaceViewContainer = new RelativeLayout(activity); spenSurfaceViewContainer.addView(mSpenSurfaceView); mRelativeLayout.addView(spenSurfaceViewContainer, lp); // Adding Basic colors resId = activity.getResources().getIdentifier("spentraybar_basic_colors", "layout", activity.getPackageName()); LinearLayout basic_colors = (LinearLayout) View.inflate(activity, resId, null); lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.BELOW, traybar_top.getId()); mRelativeLayout.addView(basic_colors, lp); mRelativeLayout.setTranslationX(surfacePosition.getxValue()); mRelativeLayout.setTranslationY(surfacePosition.getyValue()); viewGroup.addView(mRelativeLayout); int widthValue = surfacePosition.getWidth(); int heightValue = surfacePosition.getHeight() - (int) (((float) 24) * activity.getResources().getDisplayMetrics().density); mSpenNoteDoc = new SpenNoteDoc(activity.getApplicationContext(), widthValue, heightValue); mSpenPageDoc = mSpenNoteDoc.appendPage(); mSpenPageDoc.setBackgroundColor(mOptions.getColor()); mSpenPageDoc.clearHistory(); mSpenSurfaceView.setPageDoc(mSpenPageDoc, true); // set Pen Setting info mPenInfo = new SpenSettingPenInfo(); mPenInfo.size = PEN_SIZE; mPenInfo.color = Color.BLUE; mPenInfo.name = PEN_TYPE; Log.d(TAG, "mPenInfo:" + mPenInfo.name); mSpenSurfaceView.setPenSettingInfo(mPenInfo); setBgImage(mOptions); isSurface = true; } } catch (SsdkUnsupportedException e) { Log.d(TAG, "failed initializing the spen package " + e.getMessage()); e.printStackTrace(); PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, e.getType()); pluginResult.setKeepCallback(false); mContextParams.getCallbackContext().sendPluginResult(pluginResult); closeSurfaceControls(); } catch (IOException e) { Log.d(TAG, "cannot create new doc: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_CREATE_SURFACE, mContextParams.getCallbackContext()); closeSurfaceControls(); } catch (OutOfMemoryError e) { Runtime runtime = Runtime.getRuntime(); Log.d(TAG, "Memory Usage, Memory Used: " + runtime.totalMemory() + " , Max Memory: " + runtime.maxMemory()); e.printStackTrace(); closeSurfaceControls(); SpenException.sendPluginResult(SpenExceptionType.MAX_HEAP_MEMORY_REACHED, mContextParams.getCallbackContext()); } return isSurface; }
From source file:com.samsung.spen.SpenPlugin.java
License:Apache License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Inside execute"); }//from w ww . j a v a 2s . c o m // sometimes, init is not called from initialize init(); // Do not allow apis if metadata is missing if (!pluginMetadata) { callbackContext.error("METADATA_MISSING"); Log.e(TAG, "Metadata is missing"); return false; } initContextDetails(callbackContext); final CallbackContext finalCallbackContext = callbackContext; mSpenState = isSpenFeatureEnabled(mActivity.getApplicationContext(), callbackContext); if (action.equals("isSupported")) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Inside isSpenSupported"); } if (mSpenState == SPEN_AND_HAND_SUPPORTED) { callbackContext.success(SpenExceptionType.SPEN_AND_HAND_SUPPORTED.toString()); return true; } else if (mSpenState == ONLY_HAND_SUPPORTED) { callbackContext.success(SpenExceptionType.ONLY_HAND_SUPPORTED.toString()); // handled this in isSpenFeatureEnabled itself as it common // for many cases. } } else if (action.equals("launchSurfaceInline")) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "creating the spen surface inline"); } SpenTrayBarOptions options = createTrayBarOptions(args, Utils.SURFACE_INLINE, callbackContext); final SpenTrayBarOptions inlineOptions = options; if (inlineOptions != null && mSpenState != SPEN_INITILIZATION_ERROR) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { String id = inlineOptions.getId(); if (mSpenSurfaceViews.getSurfaceView(id) == null) { if (surfaceCount >= SpenSurfaceViews.MAX_SURFACE_COUNT) { SpenException.sendPluginResult(SpenExceptionType.MAX_SURFACE_LIMIT_REACHED, finalCallbackContext); } else { SPenSurfaceWithTrayBar mPaintViewTrayBar = null; mPaintViewTrayBar = new SPenSurfaceWithTrayBar(mContextParams, inlineOptions); mSpenSurfaceViews.addSurfaceView(id, mPaintViewTrayBar); surfaceCount++; if (!mSpenSurfaceViews.getSurfaceView(id).createSPenSurfaceWithTrayBar()) { mSpenSurfaceViews.removeSurfaceView(id); surfaceCount--; SpenException.sendPluginResult(SpenExceptionType.FAILED_CREATE_SURFACE, finalCallbackContext); } else { // finalCallbackContext.success(); PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, ""); pluginResult.setKeepCallback(true); finalCallbackContext.sendPluginResult(pluginResult); } } } else { SpenException.sendPluginResult(SpenExceptionType.SURFACE_ID_ALREADY_EXISTS, finalCallbackContext); } } }); } } else if (action.equals("launchSurfacePopup")) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "creating the spen surface popup"); } SpenTrayBarOptions options = createTrayBarOptions(args, Utils.SURFACE_POPUP, callbackContext); if (options != null && mSpenState != SPEN_INITILIZATION_ERROR) { String id = options.getId(); if (mSpenSurfaceViewsPopup.getSurfaceView(id) == null) { if (surfaceCount >= SpenSurfaceViews.MAX_SURFACE_COUNT) { SpenException.sendPluginResult(SpenExceptionType.MAX_SURFACE_LIMIT_REACHED, finalCallbackContext); } else { SPenSurfaceWithTrayBar mPaintViewTrayBar = null; mPaintViewTrayBar = new SPenSurfaceWithTrayBar(mContextParams, options); mSpenSurfaceViewsPopup.addSurfaceView(id, mPaintViewTrayBar); surfaceCount++; if (!mSpenSurfaceViewsPopup.getSurfaceView(id).createSPenSurfaceWithTrayBar()) { mSpenSurfaceViewsPopup.removeSurfaceView(id); surfaceCount--; SpenException.sendPluginResult(SpenExceptionType.FAILED_CREATE_SURFACE, finalCallbackContext); } else { PluginResult pluginResult = new PluginResult(PluginResult.Status.OK, ""); pluginResult.setKeepCallback(true); finalCallbackContext.sendPluginResult(pluginResult); } } } else { mSpenSurfaceViewsPopup.getSurfaceView(id).changeSPenTrayBarOptions(options, mContextParams); mSpenSurfaceViewsPopup.getSurfaceView(id).openSPenSurfaceWithTrayBar(); } } } else if (action.equals("removeSurfaceInline")) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "removing SpenSurface Inline"); } String tempId = args.getString(ID); if (tempId != null) { tempId = tempId.trim(); if (tempId.length() > MAX_ID_LENGTH) { tempId = tempId.substring(0, MAX_ID_LENGTH); } } final String id = tempId; if (id == null || id.equals("") || id.equals("null")) { SpenException.sendPluginResult(SpenExceptionType.INVALID_SURFACE_ID, callbackContext); return false; } if (mSpenState != SPEN_INITILIZATION_ERROR) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { if (mSpenSurfaceViews.getSurfaceView(id) != null) { surfaceCount--; mSpenSurfaceViews.getSurfaceView(id).removeSurface(); mSpenSurfaceViews.removeSurfaceView(id); finalCallbackContext.success(id); } else { SpenException.sendPluginResult(SpenExceptionType.SURFACE_ID_NOT_EXISTS, finalCallbackContext); } } }); } } else if (action.equals("removeSurfacePopup")) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "removing SpenSurface Popup"); } String tempId = args.getString(ID); if (tempId != null) { tempId = tempId.trim(); if (tempId.length() > MAX_ID_LENGTH) { tempId = tempId.substring(0, MAX_ID_LENGTH); } } final String id = tempId; if (id == null || id.equals("") || id.equals("null")) { SpenException.sendPluginResult(SpenExceptionType.INVALID_SURFACE_ID, callbackContext); return false; } if (mSpenSurfaceViewsPopup.getSurfaceView(id) != null) { surfaceCount--; mSpenSurfaceViewsPopup.getSurfaceView(id).removeSurface(); mSpenSurfaceViewsPopup.removeSurfaceView(id); finalCallbackContext.success(id); } else { SpenException.sendPluginResult(SpenExceptionType.SURFACE_ID_NOT_EXISTS, finalCallbackContext); } } else { callbackContext.error(SpenExceptionType.ACTION_INVALID.toString()); return false; } return true; }
From source file:com.samsung.spen.SpenPlugin.java
License:Apache License
/** * checks if the Spen feature is enabled or not. Send the result as * SPEN_SUPPORTED if the Spen is supported otherwise the corresponding error * message./* w w w .ja va 2 s. c o m*/ * * @param context * Context * @param callbackContext * CallbackContext * @return spenState */ private int isSpenFeatureEnabled(Context context, CallbackContext callbackContext) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "inside isSpenFeatureEnabled"); } int spenState = SPEN_INITILIZATION_ERROR; Spen spenPackage = new Spen(); try { if (isStatic) { spenPackage.initialize(context, 5, Spen.SPEN_STATIC_LIB_MODE); } else { spenPackage.initialize(context); } if (spenPackage.isFeatureEnabled(Spen.DEVICE_PEN)) { spenState = SPEN_AND_HAND_SUPPORTED; } else { spenState = ONLY_HAND_SUPPORTED; } } catch (SsdkUnsupportedException e) { Log.d(TAG, "failed initializing the spen package " + e.getMessage()); e.printStackTrace(); // if the spen sdk version name (dynamic sdk) is lesser than // the jar version name (which is inlcuded in the spen plugin // then LIBRARY_UPDATE_IS_REQUIRED should be thrown. // Current, Spen SDK not handled it properly. SpenExceptionType errorType = null; boolean isExceptionTypeFound = false; if (spenPackage != null && !isStatic) { String dynamicSDKPkgName = Spen.SPEN_NATIVE_PACKAGE_NAME; try { PackageInfo packageInfo = mActivity.getPackageManager().getPackageInfo(dynamicSDKPkgName, 0); if (packageInfo != null) { String dynamicSDKVersionName = packageInfo.versionName.replace(".", ""); String pluginJarVersionName = spenPackage.getVersionName().replace(".", ""); if (dynamicSDKVersionName.compareTo(pluginJarVersionName) < 0) { errorType = SpenExceptionType.LIBRARY_UPDATE_IS_REQUIRED; isExceptionTypeFound = true; } } } catch (NameNotFoundException e1) { e1.printStackTrace(); } } if (!isExceptionTypeFound) { errorType = SpenException.processUnsupportedException(e); } PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, errorType.toString()); pluginResult.setKeepCallback(false); callbackContext.sendPluginResult(pluginResult); } spenPackage = null; return spenState; }
From source file:com.samsung.spen.SPenPopupSurface.java
License:Apache License
/** * create SPen surface// w w w . jav a2 s. c o m * * @return true if surface created otherwise false */ boolean createSPenSurface() { Activity activity = mContextParams.getSpenCustomDrawPlugin().cordova.getActivity(); boolean isSurface = true; if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Inside createSPenSurface"); } if (mDialog == null) { mDialog = new Dialog(activity); mDialog.setCanceledOnTouchOutside(false); mDialog.setOnDismissListener(new OnDismissListener() { @Override public void onDismiss(DialogInterface dialog) { } }); mDialog.setOnCancelListener(new OnCancelListener() { @Override public void onCancel(DialogInterface dialog) { if (mSpenSettingPenLayout != null) { mSpenSettingPenLayout.setVisibility(View.GONE); } if (mSelectionSettingView != null) { mSelectionSettingView.setVisibility(View.GONE); } mSpenSurfaceView.closeControl(); } }); mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE); if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Dialog was null, creating new dialog. Dialog:" + mDialog.toString()); } } mRelativeLayout.setBackgroundColor(mOptions.getColor()); // Adding top traybar buttons RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); int resId = activity.getResources().getIdentifier("spentraybar_top", "layout", activity.getPackageName()); RelativeLayout traybar_top = (RelativeLayout) View.inflate(activity, resId, null); lp.addRule(RelativeLayout.ALIGN_PARENT_TOP); mRelativeLayout.addView(traybar_top, lp); // Adding bottom traybar RelativeLayout traybar_bottom = null; if ((mOptions.getsPenFlags() & Utils.FLAG_ADD_PAGE) == Utils.FLAG_ADD_PAGE) { resId = activity.getResources().getIdentifier("spentraybar_bottom", "layout", activity.getPackageName()); traybar_bottom = (RelativeLayout) View.inflate(activity, resId, null); lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); mRelativeLayout.addView(traybar_bottom, lp); } final Point point = getWidthAndHeightForPageDoc(); mPageDocSizes = point; try { Spen spenPackage = new Spen(); boolean isStatic = false; resId = activity.getResources().getIdentifier("spen_static", "bool", activity.getPackageName()); try { if (resId != 0) { isStatic = activity.getResources().getBoolean(resId); } } catch (Resources.NotFoundException re) { isStatic = false; } if (isStatic) { spenPackage.initialize(activity.getApplicationContext(), 5, Spen.SPEN_STATIC_LIB_MODE); } else { spenPackage.initialize(activity.getApplicationContext()); } mSpenSurfaceView = new SpenSurfaceView(activity.getApplicationContext()); lp = new RelativeLayout.LayoutParams(point.x, point.y); lp.addRule(RelativeLayout.BELOW, traybar_top.getId()); if (traybar_bottom != null) { lp.addRule(RelativeLayout.ABOVE, traybar_bottom.getId()); } spenSurfaceViewContainer = new RelativeLayout(activity); spenSurfaceViewContainer.addView(mSpenSurfaceView); mRelativeLayout.addView(spenSurfaceViewContainer, lp); int xValue = point.x; int yValue = point.y - (int) (((float) 24) * activity.getResources().getDisplayMetrics().density); mSpenNoteDoc = new SpenNoteDoc(activity.getApplicationContext(), xValue, yValue); mSpenPageDoc = mSpenNoteDoc.appendPage(); mCurrentPageindex = mSpenNoteDoc.getPageIndexById(mSpenPageDoc.getId()); mSpenPageDoc.setBackgroundColor(mOptions.getColor()); mSpenPageDoc.clearHistory(); mSpenSurfaceView.setPageDoc(mSpenPageDoc, true); mPenInfo = new SpenSettingPenInfo(); mPenInfo.size = PEN_SIZE; mPenInfo.color = Color.BLUE; mPenInfo.name = PEN_TYPE; if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "popup mPenInfo:" + mPenInfo.name); } mSpenSurfaceView.setPenSettingInfo(mPenInfo); LayoutParams p = new LayoutParams(point.x, point.y); // Adding Basic colors resId = activity.getResources().getIdentifier("spentraybar_basic_colors", "layout", activity.getPackageName()); LinearLayout basic_colors = (LinearLayout) View.inflate(activity, resId, null); lp = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT); lp.addRule(RelativeLayout.BELOW, traybar_top.getId()); mRelativeLayout.addView(basic_colors, lp); mDialog.setContentView(mRelativeLayout, p); setBgImage(mOptions); mDialog.show(); } catch (SsdkUnsupportedException e) { Log.d(TAG, "failed initializing the spen package " + e.getMessage()); e.printStackTrace(); PluginResult pluginResult = new PluginResult(PluginResult.Status.ERROR, e.getType()); pluginResult.setKeepCallback(false); mContextParams.getCallbackContext().sendPluginResult(pluginResult); closeSurfaceControls(); isSurface = false; } catch (IOException e) { Log.d(TAG, "cannot create new doc: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_CREATE_SURFACE, mContextParams.getCallbackContext()); closeSurfaceControls(); isSurface = false; } catch (OutOfMemoryError e) { Runtime runtime = Runtime.getRuntime(); Log.d(TAG, "Memory Usage, Memory Used: " + runtime.totalMemory() + " , Max Memory: " + runtime.maxMemory()); e.printStackTrace(); closeSurfaceControls(); SpenException.sendPluginResult(SpenExceptionType.MAX_HEAP_MEMORY_REACHED, mContextParams.getCallbackContext()); isSurface = false; } mOrientationListener = new OrientationEventListener(activity.getApplicationContext()) { int orntation = Configuration.ORIENTATION_PORTRAIT; @Override public void onOrientationChanged(int orientation) { Activity activity = mContextParams.getSpenCustomDrawPlugin().cordova.getActivity(); if (orntation != activity.getResources().getConfiguration().orientation) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "onOrientationChanged() called"); } orntation = activity.getResources().getConfiguration().orientation; Message msgObj = handler.obtainMessage(); Bundle b = new Bundle(); b.putInt("orientation", orntation); msgObj.setData(b); handler.sendMessage(msgObj); } } }; if (mOrientationListener.canDetectOrientation() == true) { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Can detect orientation"); } mOrientationListener.enable(); } return isSurface; }
From source file:com.samsung.spen.SpenTrayBar.java
License:Apache License
/** * Set Text Recognition//from ww w .j av a2 s. com */ private void setTextRecognition() { if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Inside setTextRecognition, intializing text recognition"); } Context context = mContextParams.getSpenCustomDrawPlugin().cordova.getActivity().getApplicationContext(); mSpenTextRecognitionManager = new SpenTextRecognitionManager(context); List<SpenRecognitionInfo> textRecognitionList = mSpenTextRecognitionManager .getInfoList(SpenObjectBase.TYPE_STROKE, SpenObjectBase.TYPE_CONTAINER); try { if (textRecognitionList.size() > 0) { for (SpenRecognitionInfo info : textRecognitionList) { if (info.name.equalsIgnoreCase("SpenText")) { if (mTextRecognition == null) { mTextRecognition = mSpenTextRecognitionManager.createRecognition(info); } break; } } } List<String> languageList = mTextRecognition.getSupportedLanguage(); if (textRecognitionList.size() > 0) { for (String language : languageList) { if (language.equalsIgnoreCase("eng")) { mTextRecognition.setLanguage(language); break; } } } mTextRecognition.setResultListener(new ResultListener() { @Override public void onResult(List<SpenObjectBase> input, List<SpenObjectBase> output) { mIsProcessingRecognition = false; if (isDone) { if (mSpenNoteDoc != null) { ArrayList<SpenObjectBase> selectedList = mSpenPageDoc.getObjectList(); int j = 0; for (int i = 0; i < selectedList.size(); i++) { if (selectedList.get(i).getType() == SpenObjectBase.TYPE_TEXT_BOX) { if (output == null) { output = new ArrayList<SpenObjectBase>(); } output.add(j, selectedList.get(i)); j++; } } } if (output == null) { return; } StringBuilder js_out = new StringBuilder(); for (SpenObjectBase obj : output) { if (obj instanceof SpenObjectTextBox) { SpenObjectTextBox mSpenObjectTextBox = (SpenObjectTextBox) obj; js_out.append(" " + mSpenObjectTextBox.getText()); } } String js_out2 = js_out.toString(); if (js_out2.contains("\n")) { js_out2 = js_out2.replace("\n", " "); } js_out2 = js_out2.trim(); if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "getting text form output, text:" + js_out); } PluginResult progressResult = new PluginResult(PluginResult.Status.OK, js_out2); progressResult.setKeepCallback(true); mContextParams.getCallbackContext().sendPluginResult(progressResult); if (Log.isLoggable(Utils.SPEN, Log.DEBUG)) { Log.d(TAG, "Returned Text for return type recognitzed text is: " + js_out2); } isDone = false; } else { if (output != null) { handleResult((SpenObjectTextBox) output.get(0)); } mSpenSurfaceView.closeControl(); mSpenSurfaceView.update(); } } }); } catch (ClassNotFoundException e) { Log.d(TAG, "SpenTextRecognitionManager class not found: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } catch (InstantiationException e) { Log.d(TAG, "Failed to access the SpenTextRecognitionManager constructor: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } catch (IllegalAccessException e) { Log.d(TAG, "Failed to access the SpenTextRecognitionManager field or method: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } catch (SpenCreationFailureException e) { Log.d(TAG, "exception while creating spen: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } catch (IllegalStateException e) { Log.d(TAG, "SpenTextRecognition is not loaded: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } catch (Exception e) { Log.d(TAG, "SpenTextRecognitionManager engine not loaded: " + e.getMessage()); e.printStackTrace(); SpenException.sendPluginResult(SpenExceptionType.FAILED_RECOGNIZE_TEXT, mContextParams.getCallbackContext()); } }
From source file:com.scala.cordova.plugin.expnginx.ExpNginx.java
License:MIT License
@Override public boolean execute(String action, final JSONArray args, CallbackContext callbackContext) throws JSONException { final Activity activity = cordova.getActivity(); final Nginx nginx = Nginx.create(); if (action.equals("start")) { Log.v(LOG_TAG, "Cordova Android ExpNginx.start() called."); this.callbackContext = callbackContext; final ExpNginx self = this; activity.runOnUiThread(new Runnable() { public void run() { try { nginx.start();/* w w w.java 2 s .co m*/ // send success result to cordova PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(false); self.callbackContext.sendPluginResult(result); } catch (Exception e) { String msg = "Error while starting ExpNginx."; Log.e(LOG_TAG, msg); // return error answer to cordova PluginResult result = new PluginResult(PluginResult.Status.ERROR, msg); result.setKeepCallback(false); self.callbackContext.sendPluginResult(result); } } }); return true; } if (action.equals("stop")) { Log.v(LOG_TAG, "Cordova Android ExpNginx.stop() called."); this.callbackContext = callbackContext; final ExpNginx self = this; activity.runOnUiThread(new Runnable() { public void run() { try { // stop nginx server Integer delay = (Integer) args.get(0); nginx.stop(delay); // send success result to cordova PluginResult result = new PluginResult(PluginResult.Status.OK); result.setKeepCallback(false); self.callbackContext.sendPluginResult(result); } catch (Exception e) { String msg = "Error while stoping ExpNginx."; Log.e(LOG_TAG, msg); // return error answer to cordova PluginResult result = new PluginResult(PluginResult.Status.ERROR, msg); result.setKeepCallback(false); self.callbackContext.sendPluginResult(result); } } }); return true; } return false; }
From source file:com.sesamtv.cordova.chromecast.ChromeCast.java
License:MIT License
private void startListener(String type, CallbackContext callbackContext) { Log.d(TAG, "startListener for " + type); PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT); if (type.equals("session")) { onSessionCreatedCallback = callbackContext; pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (type.equals("receivers")) { receiverCallback = callbackContext; onReceiverListChanged();// w w w .ja va 2 s .c o m } else if (type.equals("sessionEnded")) { onEndedCallback = callbackContext; pluginResult.setKeepCallback(true); callbackContext.sendPluginResult(pluginResult); } else if (type.equals("status")) { mediaStatusCallback = callbackContext; mediaStatusCallback.sendPluginResult(getMediaStatus()); } else { callbackContext.error("LISTENER_TYPE_NOT_FOUND"); } }