List of usage examples for org.apache.cordova PluginResult PluginResult
public PluginResult(Status status, List<PluginResult> multipartMessages)
From source file:com.phonegap.customcamera.NativeCameraLauncher.java
License:Apache License
void cancelPicture() { callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, "")); }
From source file:com.phonegap.customcamera.NativeCameraLauncher.java
License:Apache License
@Override public void run() { WindowManager windowManager = (WindowManager) this.cordova.getActivity().getApplicationContext() .getSystemService(this.cordova.getActivity().getApplicationContext().WINDOW_SERVICE); int rotation = windowManager.getDefaultDisplay().getRotation(); // Read in bitmap of captured image Bitmap bitmap;// w w w . j av a 2s. c om ExifHelper exif = new ExifHelper(); //Log.i("orientation", rotation+" rotation"); int rotate = rotation; try { // Create an ExifHelper to save the exif data that is lost // during compression exif.createInFile(getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic-" + this.date + ".jpg"); exif.readExifData(); /*Auskommentiert weil es immer auf Querformat gedreht hat*/ // rotate = exif.getOrientation(); Log.i("orientation", rotate + " "); // rotate = 90; try { bitmap = android.provider.MediaStore.Images.Media .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri); Log.i("orientation", bitmap.getWidth() + " " + bitmap.getHeight()); if (bitmap.getWidth() > bitmap.getHeight()) { rotate = rotate + 90; } } catch (FileNotFoundException e) { Uri uri = resultIntent.getData(); android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver(); bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri)); } // If bitmap cannot be decoded, this may return null if (bitmap == null) { this.failPicture("Error decoding image."); return; } bitmap = scaleBitmap(bitmap); // Add compressed version of captured image to returned media // store Uri bitmap = getRotatedBitmap(rotate, bitmap, exif); //Log.i(LOG_TAG, "URI: " + this.imageUri.toString()); OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(this.imageUri); // ByteArrayOutputStream outStream = new ByteArrayOutputStream(); // bitmap.compress(CompressFormat.JPEG, this.mQuality, outStream); bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os); // String imgString = Base64.encodeToString(outStream.toByteArray(), Base64.NO_WRAP); os.close(); // Restore exif data to file exif.createOutFile(this.imageUri.getPath()); exif.writeExifData(); // Send Uri back to JavaScript for viewing image this.callbackContext .sendPluginResult(new PluginResult(PluginResult.Status.OK, this.imageUri.getPath())); // this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, imgString)); bitmap.recycle(); bitmap = null; System.gc(); } catch (IOException e) { e.printStackTrace(); this.failPicture("Error capturing image."); } }
From source file:com.phonegap.plugins.datesettings.DateSettings.java
License:BSD License
@Override public boolean execute(String action, JSONArray args, CallbackContext callbackContext) { PluginResult.Status status = PluginResult.Status.OK; String result = ""; if (action.equals("open")) { this.cordova.getActivity().startActivity(new Intent(android.provider.Settings.ACTION_DATE_SETTINGS)); } else {//ww w . ja va2 s . co m status = PluginResult.Status.INVALID_ACTION; } callbackContext.sendPluginResult(new PluginResult(status, result)); return true; }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void init(JSONArray data) { if (data.length() >= 1) { try {/*w w w .ja v a 2s .co m*/ appName = data.getString(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "init : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } PluginResult pluginResult = new PluginResult(Status.OK); mCallbackContext.sendPluginResult(pluginResult); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void setPersistenceEnabled(JSONArray data) { if (isUsed == true) { PluginResult pluginResult = new PluginResult(Status.ERROR, "Can't modify config objects after they are in use for Firebase references."); mCallbackContext.sendPluginResult(pluginResult); return;//from ww w.j a v a 2s . c o m } boolean persistenceEnabled = true; if (data.length() >= 1) { try { persistenceEnabled = data.getBoolean(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "setPersistenceEnabled : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } //Firebase.setAndroidContext(this); Firebase.getDefaultConfig().setPersistenceEnabled(persistenceEnabled); PluginResult pluginResult = new PluginResult(Status.OK); mCallbackContext.sendPluginResult(pluginResult); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void readData(JSONArray data) { ////w ww .j a v a 2 s. com String strURL = String.format("https://%s.firebaseio.com", appName); String path, child, value; final Firebase myRootRef = new Firebase(strURL); if (data.length() >= 1) { try { path = data.getString(0); child = data.getString(1); value = data.getString(2); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "readDataOnceWithURL : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } Firebase myChildRef = myRootRef.child(path); Query query = myChildRef.orderByChild(child).equalTo(value); query.keepSynced(true); if (isUsed != true) isUsed = true; // Read data and react to changes query.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { JSONObject resultObj; try { HashMap result = snapshot.getValue(HashMap.class); if (result == null) resultObj = new JSONObject(); else resultObj = new JSONObject(result); myRootRef.keepSynced(true); PluginResult pluginResult = new PluginResult(Status.OK, resultObj); pluginResult.setKeepCallback(true); mCallbackContext.sendPluginResult(pluginResult); } catch (Exception e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); } } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The readData(addValueEventListener) failed: " + firebaseError.getMessage()); PluginResult pluginResult = new PluginResult(Status.ERROR, firebaseError.getMessage()); mCallbackContext.sendPluginResult(pluginResult); } }); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void readDataOnceWithURL(JSONArray data) { String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName; String path;/*from w w w.j av a 2s. c om*/ if (data.length() >= 1) { try { path = data.getString(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "readDataOnceWithURL : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } Firebase myRootRef = new Firebase(strURL); if (isUsed != true) isUsed = true; // Read data and react to changes myRootRef.child(path).addListenerForSingleValueEvent(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { JSONObject resultObj; try { HashMap result = snapshot.getValue(HashMap.class); if (result == null) resultObj = new JSONObject(); else resultObj = new JSONObject(result); PluginResult pluginResult = new PluginResult(Status.OK, resultObj); //pluginResult.setKeepCallback(true); mCallbackContext.sendPluginResult(pluginResult); } catch (Exception e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); } } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The readDataOnceWithURL(addListenerForSingleValueEvent) failed: " + firebaseError.getMessage()); PluginResult pluginResult = new PluginResult(Status.ERROR, "The readDataOnceWithURL failded: " + firebaseError.getMessage()); mCallbackContext.sendPluginResult(pluginResult); } }); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void removeAllCallbacksWithURL(JSONArray data) { String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName; if (data.length() >= 1) { try {/*from ww w .j a v a2 s .c o m*/ strURL = data.getString(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "removeAllCallbacksWithURL : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } Firebase myChildRef = new Firebase(strURL); //myChildRef.removeEventListener(listener); //myChildRef.removeEventListener(listener);//.removeEventListener(myChildRef.); PluginResult pluginResult = new PluginResult(Status.OK); mCallbackContext.sendPluginResult(pluginResult); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void readValueTypeEventWithURL(JSONArray data) { ///* w ww . java 2 s. c o m*/ String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName; if (data.length() >= 1) { try { strURL = data.getString(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "readValueTypeEventWithURL : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } Firebase myChildRef = new Firebase(strURL); if (isUsed != true) isUsed = true; myChildRef.addValueEventListener(new ValueEventListener() { @Override public void onDataChange(DataSnapshot snapshot) { JSONObject resultObj; try { HashMap result = snapshot.getValue(HashMap.class); if (result == null) resultObj = new JSONObject(); else resultObj = new JSONObject(result); PluginResult pluginResult = new PluginResult(Status.OK, resultObj); //pluginResult.setKeepCallback(true); mCallbackContext.sendPluginResult(pluginResult); } catch (Exception e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); } } @Override public void onCancelled(FirebaseError firebaseError) { System.out.println("The readValueTypeEventWithURL(addValueEventListener) failed: " + firebaseError.getMessage()); PluginResult pluginResult = new PluginResult(Status.ERROR, "The readValueTypeEventWithURL failded: " + firebaseError.getMessage()); mCallbackContext.sendPluginResult(pluginResult); } }); }
From source file:com.phonegap.plugins.Firebase.CDVFirebase.java
License:Apache License
private void RetrieveChildAddedEventWithURL(JSONArray data) { ////www. j a va 2 s . c o m String strURL = String.format("https://%s.firebaseio.com", appName); // = "https://%@.firebaseio.com" + appName; if (data.length() >= 1) { try { strURL = data.getString(0); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); return; } } else { PluginResult pluginResult = new PluginResult(Status.ERROR, "RetrieveChildAddedEventWithURL : Parameter Error"); mCallbackContext.sendPluginResult(pluginResult); return; } Firebase myChildRef = new Firebase(strURL); if (isUsed != true) isUsed = true; // Retrieve new posts as they are added to the database myChildRef.addChildEventListener(new ChildEventListener() { @Override public void onChildAdded(DataSnapshot arg0, String arg1) { //[result setKeepCallback:[NSNumber numberWithBool:YES]]; System.out.println(arg0.getValue()); JSONObject resultObj; try { resultObj = new JSONObject(arg0.getValue().toString()); PluginResult pluginResult = new PluginResult(Status.OK, resultObj); //pluginResult.setKeepCallback(true); mCallbackContext.sendPluginResult(pluginResult); } catch (JSONException e) { PluginResult pluginResult = new PluginResult(Status.ERROR, e.getMessage()); mCallbackContext.sendPluginResult(pluginResult); e.printStackTrace(); } } @Override public void onCancelled(FirebaseError arg0) { // TODO Auto-generated method stub } @Override public void onChildMoved(DataSnapshot arg0, String arg1) { // TODO Auto-generated method stub } @Override public void onChildRemoved(DataSnapshot arg0) { // TODO Auto-generated method stub } @Override public void onChildChanged(DataSnapshot arg0, String arg1) { // TODO Auto-generated method stub } }); }