Example usage for android.os Debug isDebuggerConnected

List of usage examples for android.os Debug isDebuggerConnected

Introduction

In this page you can find the example usage for android.os Debug isDebuggerConnected.

Prototype

public static boolean isDebuggerConnected() 

Source Link

Document

Determine if a debugger is currently attached.

Usage

From source file:com.intel.xdk.cache.Cache.java

public void removeFromMediaCache(String url) {
    //        if(webView.config!=null && !webView.config.hasCaching) return;
    String path = mediaCache.getString(url, "");
    String js;//ww w  . j  a v  a  2s  . c  o  m
    boolean success = false;

    //try to delete the file
    if (!"".equals(path)) {
        boolean removed = new File(cachedMediaDirectory, path).delete();
        if (removed) {
            //update the prefs
            SharedPreferences.Editor editor = mediaCache.edit();
            editor.remove(url);
            editor.commit();

            success = true;
        }
    }

    //update js object and fire private and public events
    if (success) {
        js = "javascript:var _e = document.createEvent('Events');_e.initEvent('intel.xdk.cache.internal.media.remove',true,true);_e.success=true;_e.url=\""
                + url + "\";document.dispatchEvent(_e);"
                + "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.remove',true,true);e.success=true;e.url=e.url=\""
                + url + "\";document.dispatchEvent(e);";
    } else {
        js = "javascript:var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.remove',true,true);e.success=false;e.url=e.url=\""
                + url + "\";document.dispatchEvent(e);";
    }

    //update js object and fire an event
    if (Debug.isDebuggerConnected())
        Log.i(tag, js);
    injectJS(js);
}

From source file:com.intel.xdk.cache.Cache.java

private void downloadToMediaCache(String url, final String id) {

    //get the filename
    String filename = getFilenameWithURL(url);

    //create the file to write data into
    // File mediaPath = new File(cachedMediaDirectory, getFilenameWithURL(url));
    // CacheHandler will create the file for us

    //*//from www  . j  a v a2 s  .com
    //download the file: allow for up to 3 retries

    int retries = 3;
    boolean success = false;
    while (!success && retries > 0) {
        //check if the request succeeded, if so, write out data and increment offset
        success = (id != null && id.length() > 0) ? CacheHandler.get(url, activity.getApplicationContext(),
                filename, cachedMediaDirectory, new DownloadProgressEmitter() {
                    public void emit(long current, long length) {
                        String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.update',true,true);e.success=true;e.id='"
                                + id + "';e.current=" + current + ";e.total=" + length
                                + ";document.dispatchEvent(e);";
                        if (Debug.isDebuggerConnected())
                            Log.i(tag, js);
                        injectJS(js);
                    }
                }) : CacheHandler.get(url, activity.getApplicationContext(), filename, cachedMediaDirectory);
        if (success) {
        } else {
            //handle error
            //NSLog(@"error -- code: %d, localizedDescription: %@", [error code], [error localizedDescription]);
            //[self finishedDownloadToMediaCache:url toPath:nil withFlag:NO];
        }
        retries--;
    }

    //finishedDownloadToMediaCache(url, mediaPath.getAbsolutePath(), success, id);
    finishedDownloadToMediaCache(url, filename, success, id);
}

From source file:com.intel.xdk.cache.Cache.java

private void finishedDownloadToMediaCache(String url, String path, boolean didSucceed, String id) {
    String js;//from   www  .  j  ava2s .  com
    if (didSucceed) {
        //update the prefs
        SharedPreferences.Editor editor = mediaCache.edit();
        editor.putString(url, path);
        editor.commit();

        //update js object and fire private and public events
        js = "javascript:var _e = document.createEvent('Events');_e.initEvent('intel.xdk.cache.internal.media.add',true,true);_e.success=true;_e.url=\""
                + url + "\",_e.filename=\"" + path + "\";document.dispatchEvent(_e);";
        if (id != null && id.length() > 0) {
            js += "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.add',true,true);e.success=true;e.url=\""
                    + url + "\";e.id='" + id + "';document.dispatchEvent(e);";
        } else {
            js += "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.add',true,true);e.success=true;e.url=\""
                    + url + "\";document.dispatchEvent(e);";
        }
    } else {
        //update js object and fire public event (private not needed for failure case)
        js = "javascript:";
        if (id != null && id.length() > 0) {
            js += "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.add',true,true);e.success=false;e.url=\""
                    + url + "\";e.id='" + id + "';document.dispatchEvent(e);";
        } else {
            js += "var e = document.createEvent('Events');e.initEvent('intel.xdk.cache.media.add',true,true);e.success=false;e.url=\""
                    + url + "\";document.dispatchEvent(e);";
        }
    }
    if (Debug.isDebuggerConnected())
        Log.i(tag, js);
    injectJS(js);
}