Example usage for org.apache.cordova LOG d

List of usage examples for org.apache.cordova LOG d

Introduction

In this page you can find the example usage for org.apache.cordova LOG d.

Prototype

public static void d(String tag, String s) 

Source Link

Document

Debug log message.

Usage

From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java

License:Apache License

/**
 * Called when the camera view exits.//ww w  .j  a  v  a  2s .c o m
 * 
 * @param requestCode
 *            The request code originally supplied to
 *            startActivityForResult(), allowing you to identify who this
 *            result came from.
 * @param resultCode
 *            The integer result code returned by the child activity through
 *            its setResult().
 * @param intent
 *            An Intent, which can return result data to the caller (various
 *            data can be attached to Intent "extras").
 */
public void onActivityResult(int requestCode, int resultCode, Intent intent) {

    // If image available
    if (resultCode == Activity.RESULT_OK) {
        try {
            // Create an ExifHelper to save the exif data that is lost
            // during compression
            ExifHelper exif = new ExifHelper();
            exif.createInFile(
                    getTempDirectoryPath(this.cordova.getActivity().getApplicationContext()) + "/Pic.jpg");
            exif.readExifData();

            // Read in bitmap of captured image
            Bitmap bitmap;
            try {
                bitmap = android.provider.MediaStore.Images.Media
                        .getBitmap(this.cordova.getActivity().getContentResolver(), imageUri);
            } catch (FileNotFoundException e) {
                Uri uri = intent.getData();
                android.content.ContentResolver resolver = this.cordova.getActivity().getContentResolver();
                bitmap = android.graphics.BitmapFactory.decodeStream(resolver.openInputStream(uri));
            }

            bitmap = scaleBitmap(bitmap);

            // Create entry in media store for image
            // (Don't use insertImage() because it uses default compression
            // setting of 50 - no way to change it)
            ContentValues values = new ContentValues();
            values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, "image/jpeg");
            Uri uri = null;
            try {
                uri = this.cordova.getActivity().getContentResolver()
                        .insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
            } catch (UnsupportedOperationException e) {
                LOG.d(LOG_TAG, "Can't write to external media storage.");
                try {
                    uri = this.cordova.getActivity().getContentResolver()
                            .insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
                } catch (UnsupportedOperationException ex) {
                    LOG.d(LOG_TAG, "Can't write to internal media storage.");
                    this.failPicture("Error capturing image - no media storage found.");
                    return;
                }
            }

            // Add compressed version of captured image to returned media
            // store Uri
            OutputStream os = this.cordova.getActivity().getContentResolver().openOutputStream(uri);
            bitmap.compress(Bitmap.CompressFormat.JPEG, this.mQuality, os);
            os.close();

            // Restore exif data to file
            exif.createOutFile(getRealPathFromURI(uri, this.cordova));
            exif.writeExifData();

            android.util.Log.i("CameraPlugin", "destinationType: " + this.destinationType);

            if (this.destinationType == 1) { //File URI
                // Send Uri back to JavaScript for viewing image
                this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, uri.toString()));
            } else if (this.destinationType == 0) { //DATA URL
                String base64Data = ForegroundCameraLauncher.encodeTobase64(bitmap, this.mQuality);
                this.callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, base64Data));
            } else {
                this.failPicture("Unsupported destination");
            }

            bitmap.recycle();
            bitmap = null;
            System.gc();

            checkForDuplicateImage();
        } catch (IOException e) {
            e.printStackTrace();
            this.failPicture("Error capturing image.");
        }
    }

    // If cancelled
    else if (resultCode == Activity.RESULT_CANCELED) {
        this.failPicture("Camera cancelled.");
    }

    // If something else
    else {
        this.failPicture("Did not complete!");
    }
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

/**
 * Called when the activity is first created.
 *
 * @param savedInstanceState/*from  w  w  w  .  ja  va  2s .co m*/
 */
@SuppressWarnings("deprecation")
@Override
public void onCreate(Bundle savedInstanceState) {
    checkIntents();
    Config.init(this);
    LOG.d(TAG, "CordovaActivity.onCreate()");
    super.onCreate(savedInstanceState);

    if (savedInstanceState != null) {
        initCallbackClass = savedInstanceState.getString("callbackClass");
    }

    if (!this.getBooleanProperty("ShowTitle", false)) {
        getWindow().requestFeature(Window.FEATURE_NO_TITLE);
    }

    if (this.getBooleanProperty("SetFullscreen", false)) {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
    } else {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
    }
    // This builds the view.  We could probably get away with NOT having a LinearLayout, but I like having a bucket!
    Display display = getWindowManager().getDefaultDisplay();
    int width = display.getWidth();
    int height = display.getHeight();

    root = new LinearLayoutSoftKeyboardDetect(this, width, height);
    root.setOrientation(LinearLayout.VERTICAL);
    root.setBackgroundColor(this.backgroundColor);
    root.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 0.0F));

    // Setup the hardware volume controls to handle volume control
    setVolumeControlStream(AudioManager.STREAM_MUSIC);
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

/**
 * Initialize web container with web view objects.
 *
 * @param webView//from   www  .  j a va 2  s  .c  o  m
 * @param webViewClient
 * @param webChromeClient
 */
@SuppressLint("NewApi")
public void init(CordovaWebView webView, CordovaWebViewClient webViewClient,
        CordovaChromeClient webChromeClient) {
    LOG.d(TAG, "CordovaActivity.init()");

    // Set up web container
    this.appView = webView;
    this.appView.setId(100);

    this.appView.setWebViewClient(webViewClient);
    this.appView.setWebChromeClient(webChromeClient);
    webViewClient.setWebView(this.appView);
    webChromeClient.setWebView(this.appView);

    this.appView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT, 1.0F));

    if (this.getBooleanProperty("DisallowOverscroll", false)) {
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.GINGERBREAD) {
            this.appView.setOverScrollMode(CordovaWebView.OVER_SCROLL_NEVER);
        }
    }

    // Add web view but make it invisible while loading URL
    this.appView.setVisibility(View.INVISIBLE);
    this.root.addView(this.appView);
    setContentView(this.root);

    // Clear cancel flag
    this.cancelLoadUrl = false;

}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

@Override
/**/*  w ww.  j  a v  a2  s  . c  o  m*/
 * Called when the system is about to start resuming a previous activity.
 */
protected void onPause() {
    super.onPause();

    LOG.d(TAG, "Paused the application!");

    // Don't process pause if shutting down, since onDestroy() will be called
    if (this.activityState == ACTIVITY_EXITING) {
        return;
    }

    if (this.appView == null) {
        return;
    } else {
        this.appView.handlePause(this.keepRunning);
    }

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

@Override
/**//w  w w .j av a2 s  .  c o m
 * Called when the activity will start interacting with the user.
 */
protected void onResume() {
    super.onResume();
    //Reload the configuration
    Config.init(this);

    LOG.d(TAG, "Resuming the App");

    //Code to test CB-3064
    String errorUrl = this.getStringProperty("ErrorUrl", null);
    LOG.d(TAG, "CB-3064: The errorUrl is " + errorUrl);

    if (this.activityState == ACTIVITY_STARTING) {
        this.activityState = ACTIVITY_RUNNING;
        return;
    }

    if (this.appView == null) {
        return;
    }

    this.appView.handleResume(this.keepRunning, this.activityResultKeepRunning);

    // If app doesn't want to run in background
    if (!this.keepRunning || this.activityResultKeepRunning) {

        // Restore multitasking state
        if (this.activityResultKeepRunning) {
            this.keepRunning = this.activityResultKeepRunning;
            this.activityResultKeepRunning = false;
        }
    }
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

@Override
/**//  ww w . j  a v  a 2 s  . co m
 * The final call you receive before your activity is destroyed.
 */
public void onDestroy() {
    LOG.d(TAG, "CordovaActivity.onDestroy()");
    super.onDestroy();

    // hide the splash screen to avoid leaking a window
    this.removeSplashScreen();

    if (this.appView != null) {
        appView.handleDestroy();
    } else {
        this.activityState = ACTIVITY_EXITING;
    }
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

@Override
/**/*from   w  ww.j a v  a2s.  co  m*/
 * Called when an activity you launched exits, giving you the requestCode you started it with,
 * the resultCode it returned, and any additional data from it.
 *
 * @param requestCode       The request code originally supplied to startActivityForResult(),
 *                          allowing you to identify who this result came from.
 * @param resultCode        The integer result code returned by the child activity through its setResult().
 * @param data              An Intent, which can return result data to the caller (various data can be attached to Intent "extras").
 */
protected void onActivityResult(int requestCode, int resultCode, Intent intent) {
    LOG.d(TAG, "Incoming Result");
    super.onActivityResult(requestCode, resultCode, intent);
    Log.d(TAG, "Request code = " + requestCode);
    if (appView != null && requestCode == CordovaChromeClient.FILECHOOSER_RESULTCODE) {
        ValueCallback<Uri> mUploadMessage = this.appView.getWebChromeClient().getValueCallback();
        Log.d(TAG, "did we get here?");
        if (null == mUploadMessage)
            return;
        Uri result = intent == null || resultCode != Activity.RESULT_OK ? null : intent.getData();
        Log.d(TAG, "result = " + result);
        //            Uri filepath = Uri.parse("file://" + FileUtils.getRealPathFromURI(result, this));
        //            Log.d(TAG, "result = " + filepath);
        mUploadMessage.onReceiveValue(result);
        mUploadMessage = null;
    }
    CordovaPlugin callback = this.activityResultCallback;
    if (callback == null && initCallbackClass != null) {
        // The application was restarted, but had defined an initial callback
        // before being shut down.
        this.activityResultCallback = appView.pluginManager.getPlugin(initCallbackClass);
        callback = this.activityResultCallback;
    }
    if (callback != null) {
        LOG.d(TAG, "We have a callback to send this result to");
        callback.onActivityResult(requestCode, resultCode, intent);
    }
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

/**
 * Get Activity context./* ww w.  j  a  v a2s.  co  m*/
 *
 * @return
 */
public Context getContext() {
    LOG.d(TAG, "This will be deprecated December 2012");
    return this;
}

From source file:com.AlcaldiaSucre.App.CordovaActivity.java

License:Apache License

/**
 * Called when a message is sent to plugin.
 *
 * @param id            The message id/*from ww  w  .j  a  va2 s.com*/
 * @param data          The message data
 * @return              Object or null
 */
public Object onMessage(String id, Object data) {
    LOG.d(TAG, "onMessage(" + id + "," + data + ")");
    if ("splashscreen".equals(id)) {
        if ("hide".equals(data.toString())) {
            this.removeSplashScreen();
        } else {
            // If the splash dialog is showing don't try to show it again
            if (this.splashDialog == null || !this.splashDialog.isShowing()) {
                this.splashscreen = this.getIntegerProperty("SplashScreen", 0);
                this.showSplashScreen(this.splashscreenTime);
            }
        }
    } else if ("spinner".equals(id)) {
        if ("stop".equals(data.toString())) {
            this.spinnerStop();
            this.appView.setVisibility(View.VISIBLE);
        }
    } else if ("onReceivedError".equals(id)) {
        JSONObject d = (JSONObject) data;
        try {
            this.onReceivedError(d.getInt("errorCode"), d.getString("description"), d.getString("url"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
    } else if ("exit".equals(id)) {
        this.endActivity();
    }
    return null;
}

From source file:com.amazon.cordova.plugin.PushPlugin.java

License:Open Source License

/**
 * @see Plugin#execute(String, JSONArray, String)
 *//*from  w  ww  .  j  av a 2 s . co  m*/
@Override
public boolean execute(final String request, final JSONArray args, CallbackContext callbackContext)
        throws JSONException {
    try {
        // check ADM readiness
        ADMReadiness ready = isPushPluginReady();
        if (ready == ADMReadiness.NON_AMAZON_DEVICE) {
            callbackContext.error(NON_AMAZON_DEVICE_ERROR);
            return false;
        } else if (ready == ADMReadiness.ADM_NOT_SUPPORTED) {
            callbackContext.error(ADM_NOT_SUPPORTED_ERROR);
            return false;
        } else if (callbackContext == null) {
            LOG.e(TAG, "CallbackConext is null. Notification to WebView is not possible. Can not proceed.");
            return false;
        }

        // Process the request here
        if (REGISTER.equals(request)) {

            if (args == null) {
                LOG.e(TAG, REGISTER_OPTIONS_NULL);
                callbackContext.error(REGISTER_OPTIONS_NULL);
                return false;
            }

            // parse args to get eventcallback name
            if (args.isNull(0)) {
                LOG.e(TAG, ECB_NOT_SPECIFIED);
                callbackContext.error(ECB_NOT_SPECIFIED);
                return false;
            }

            JSONObject jo = args.getJSONObject(0);
            if (jo.getString("ecb").isEmpty()) {
                LOG.e(TAG, ECB_NAME_NOT_SPECIFIED);
                callbackContext.error(ECB_NAME_NOT_SPECIFIED);
                return false;
            }
            callbackContext.success(REGISTRATION_SUCCESS_RESPONSE);
            notificationHandlerCallBack = jo.getString(ECB);
            String regId = adm.getRegistrationId();
            LOG.d(TAG, "regId = " + regId);
            if (regId == null) {
                adm.startRegister();
            } else {
                sendRegistrationIdWithEvent(REGISTER_EVENT, regId);
            }

            // see if there are any messages while app was in background and
            // launched via app icon
            LOG.d(TAG, "checking for offline message..");
            deliverPendingMessageAndCancelNotifiation();
            return true;

        } else if (UNREGISTER.equals(request)) {
            adm.startUnregister();
            callbackContext.success(UNREGISTRATION_SUCCESS_RESPONSE);
            return true;
        } else {
            LOG.e(TAG, "Invalid action : " + request);
            callbackContext.error("Invalid action : " + request);
            return false;
        }
    } catch (final Exception e) {
        callbackContext.error(e.getMessage());
    }

    return false;
}