Java Code Examples for com.vk.sdk.VKSdk#DEBUG

The following examples show how to use com.vk.sdk.VKSdk#DEBUG . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: VKModelOperation.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
@Override
protected boolean postExecution() {
    if (!super.postExecution())
        return false;

    if (mParser != null) {
        try {
            JSONObject response = getResponseJson();
            parsedModel = mParser.createModel(response);
            return true;
        } catch (Exception e) {
            if (VKSdk.DEBUG) {
                e.printStackTrace();
            }
        }
    }
    return false;
}
 
Example 2
Source File: VKList.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
/**
 * Fills list according with data in {@code from}.
 * @param from an array of items in the list. You can use null.
 * @param creator interface implementation to parse objects.
 */
public void fill(JSONArray from, Parser<? extends T> creator) {
    if(from != null) {
        for(int i = 0; i < from.length(); i++) {
            try {
                T object = creator.parseObject(from.getJSONObject(i));
                if(object != null) {
                    items.add(object);
                }
            } catch (Exception e) {
                if (VKSdk.DEBUG)
                    e.printStackTrace();
            }
        }
    }
}
 
Example 3
Source File: VKUploadImage.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
public File getTmpFile() {
    Context ctx = VKUIHelper.getApplicationContext();
    File outputDir = null;
    if (ctx != null) {
        outputDir = ctx.getExternalCacheDir();
        if (outputDir == null || !outputDir.canWrite())
            outputDir = ctx.getCacheDir();
    }
    File tmpFile = null;
    try {
        tmpFile = File.createTempFile("tmpImg", String.format(".%s", mParameters.fileExtension()), outputDir);
        FileOutputStream fos = new FileOutputStream(tmpFile);
        if (mParameters.mImageType == VKImageParameters.VKImageType.Png)
            mImageData.compress(Bitmap.CompressFormat.PNG, 100, fos);
        else
            mImageData.compress(Bitmap.CompressFormat.JPEG, (int) (mParameters.mJpegQuality * 100), fos);
        fos.close();
    } catch (IOException ignored) {
        if (VKSdk.DEBUG)
            ignored.printStackTrace();
    }
    return tmpFile;
}
 
Example 4
Source File: VKUtil.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
/**
 * Returns md5 hash of string
 *
 * @param s string to hash
 * @return md5 hash
 */
public static String md5(final String s) {
    try {
        // Create MD5 Hash
        MessageDigest digest = MessageDigest.getInstance("MD5");
        digest.update(s.getBytes());
        byte messageDigest[] = digest.digest();

        // Create Hex String
        StringBuilder hexString = new StringBuilder();
        for (byte aMessageDigest : messageDigest) {
            String h = Integer.toHexString(0xFF & aMessageDigest);
            while (h.length() < 2)
                h = "0" + h;
            hexString.append(h);
        }
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
        if (VKSdk.DEBUG)
            e.printStackTrace();
    }
    return "";
}
 
Example 5
Source File: VKUtil.java    From cordova-social-vk with Apache License 2.0 6 votes vote down vote up
/**
 * Builds map from list of strings
 *
 * @param args key-value pairs for build a map. Must be a multiple of 2
 * @return Result map. If args not multiple of 2, last argument will be ignored
 */
public static Map<String, Object> mapFrom(Object... args) {
    if (args.length % 2 != 0) {
        if (VKSdk.DEBUG)
            Log.w("VKUtil", "Params must be paired. Last one is ignored");
    }
    LinkedHashMap<String, Object> result = new LinkedHashMap<>(args.length / 2);
    for (int i = 0; i + 1 < args.length; i += 2) {
        if (args[i] == null || args[i + 1] == null || !(args[i] instanceof String)) {
            if (VKSdk.DEBUG)
                Log.e("VK SDK", "Error while using mapFrom", new InvalidParameterSpecException("Key and value must be specified. Key must be string"));
            continue;
        }
        result.put((String) args[i], args[i + 1]);
    }
    return result;
}
 
Example 6
Source File: VKHttpClient.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
public VKHTTPRequest(@Nullable String url) {
    if (url != null) {
        try {
            this.methodUrl = new URL(url);
        } catch (MalformedURLException e) {
            if (VKSdk.DEBUG) {
                e.printStackTrace();
            }
        }
    }
}
 
Example 7
Source File: VKDefaultParser.java    From cordova-social-vk with Apache License 2.0 5 votes vote down vote up
@Override
public Object createModel(JSONObject object) {
    try {
        VKApiModel model = mModelClass.newInstance();
        model.parse(object);
        return model;
    } catch (Exception e) {
        if (VKSdk.DEBUG)
            e.printStackTrace();
    }
    return null;
}