com.lidroid.xutils.util.LogUtils Java Examples

The following examples show how to use com.lidroid.xutils.util.LogUtils. 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: BitmapCache.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
/**
 * Initializes the disk cache.  Note that this includes disk access so this should not be
 * executed on the main/UI thread. By default an ImageCache does not initialize the disk
 * cache when it is created, instead you should call initDiskCache() to initialize it on a
 * background thread.
 */
public void initDiskCache() {
    // Set up disk cache
    synchronized (mDiskCacheLock) {
        if (globalConfig.isDiskCacheEnabled() && (mDiskLruCache == null || mDiskLruCache.isClosed())) {
            File diskCacheDir = new File(globalConfig.getDiskCachePath());
            if (diskCacheDir.exists() || diskCacheDir.mkdirs()) {
                long availableSpace = OtherUtils.getAvailableSpace(diskCacheDir);
                long diskCacheSize = globalConfig.getDiskCacheSize();
                diskCacheSize = availableSpace > diskCacheSize ? diskCacheSize : availableSpace;
                try {
                    mDiskLruCache = LruDiskCache.open(diskCacheDir, 1, 1, diskCacheSize);
                    mDiskLruCache.setFileNameGenerator(globalConfig.getFileNameGenerator());
                    LogUtils.d("create disk cache success");
                } catch (Throwable e) {
                    mDiskLruCache = null;
                    LogUtils.e("create disk cache error", e);
                }
            }
        }
    }
}
 
Example #2
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Bitmap decodeSampledBitmapFromByteArray(byte[] data, BitmapSize maxSize, Bitmap.Config config) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inPurgeable = true;
        options.inInputShareable = true;
        BitmapFactory.decodeByteArray(data, 0, data.length, options);
        options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
        options.inJustDecodeBounds = false;
        if (config != null) {
            options.inPreferredConfig = config;
        }
        try {
            return BitmapFactory.decodeByteArray(data, 0, data.length, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #3
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example #4
Source File: ColumnUtils.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Method getColumnSetMethod(Class<?> entityType, Field field) {
    String fieldName = field.getName();
    Method setMethod = null;
    if (field.getType() == boolean.class) {
        setMethod = getBooleanColumnSetMethod(entityType, field);
    }
    if (setMethod == null) {
        String methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
        try {
            setMethod = entityType.getDeclaredMethod(methodName, field.getType());
        } catch (NoSuchMethodException e) {
            LogUtils.d(methodName + " not exist");
        }
    }

    if (setMethod == null && !Object.class.equals(entityType.getSuperclass())) {
        return getColumnSetMethod(entityType.getSuperclass(), field);
    }
    return setMethod;
}
 
Example #5
Source File: ColumnUtils.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Method getColumnGetMethod(Class<?> entityType, Field field) {
    String fieldName = field.getName();
    Method getMethod = null;
    if (field.getType() == boolean.class) {
        getMethod = getBooleanColumnGetMethod(entityType, fieldName);
    }
    if (getMethod == null) {
        String methodName = "get" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
        try {
            getMethod = entityType.getDeclaredMethod(methodName);
        } catch (NoSuchMethodException e) {
            LogUtils.d(methodName + " not exist");
        }
    }

    if (getMethod == null && !Object.class.equals(entityType.getSuperclass())) {
        return getColumnGetMethod(entityType.getSuperclass(), field);
    }
    return getMethod;
}
 
Example #6
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Bitmap decodeSampledBitmapFromDescriptor(FileDescriptor fileDescriptor, BitmapSize maxSize, Bitmap.Config config) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true; // 只读头信息
        options.inPurgeable = true;
        options.inInputShareable = true;
        BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
        //这个就是图片压缩倍数的参数
        options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
        options.inJustDecodeBounds = false;
        if (config != null) {
            options.inPreferredConfig = config;
        }
        try {
            return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #7
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Bitmap decodeSampledBitmapFromFile(String filename, BitmapSize maxSize, Bitmap.Config config) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inPurgeable = true;
        options.inInputShareable = true;
        BitmapFactory.decodeFile(filename, options);
        options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
        options.inJustDecodeBounds = false;
        if (config != null) {
            options.inPreferredConfig = config;
        }
        try {
            return BitmapFactory.decodeFile(filename, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #8
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 6 votes vote down vote up
public static Bitmap decodeSampledBitmapFromResource(Resources res, int resId, BitmapSize maxSize, Bitmap.Config config) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inJustDecodeBounds = true;
        options.inPurgeable = true;
        options.inInputShareable = true;
        BitmapFactory.decodeResource(res, resId, options);
        options.inSampleSize = calculateInSampleSize(options, maxSize.getWidth(), maxSize.getHeight());
        options.inJustDecodeBounds = false;
        if (config != null) {
            options.inPreferredConfig = config;
        }
        try {
            return BitmapFactory.decodeResource(res, resId, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #9
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 6 votes vote down vote up
@Override
public void onLoading(long total, long current, boolean isUploading) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    downloadInfo.setFileLength(total);
    downloadInfo.setProgress(current);
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onLoading(total, current, isUploading);
    }
}
 
Example #10
Source File: BodyParamsEntity.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private void refreshContent() {
    if (dirty) {
        try {
            this.content = URLEncodedUtils.format(params, charset).getBytes(charset);
        } catch (UnsupportedEncodingException e) {
            LogUtils.e(e.getMessage(), e);
        }
        dirty = false;
    }
}
 
Example #11
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static Bitmap decodeByteArray(byte[] data) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        options.inInputShareable = true;
        try {
            return BitmapFactory.decodeByteArray(data, 0, data.length, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #12
Source File: BitmapCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Get the bitmap from disk cache.
 *
 * @param uri
 * @param config
 * @return
 */
public Bitmap getBitmapFromDiskCache(String uri, BitmapDisplayConfig config) {
    if (uri == null || !globalConfig.isDiskCacheEnabled()) return null;
    if (mDiskLruCache == null) {
        initDiskCache();
    }
    if (mDiskLruCache != null) {
        LruDiskCache.Snapshot snapshot = null;
        try {
            snapshot = mDiskLruCache.get(uri);
            if (snapshot != null) {
                Bitmap bitmap = null;
                if (config == null || config.isShowOriginal()) {
                    bitmap = BitmapDecoder.decodeFileDescriptor(
                            snapshot.getInputStream(DISK_CACHE_INDEX).getFD());
                } else {
                    bitmap = BitmapDecoder.decodeSampledBitmapFromDescriptor(
                            snapshot.getInputStream(DISK_CACHE_INDEX).getFD(),
                            config.getBitmapMaxSize(),
                            config.getBitmapConfig());
                }

                bitmap = rotateBitmapIfNeeded(uri, config, bitmap);
                bitmap = addBitmapToMemoryCache(uri, config, bitmap, mDiskLruCache.getExpiryTimestamp(uri));
                return bitmap;
            }
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
        } finally {
            IOUtils.closeQuietly(snapshot);
        }
    }
    return null;
}
 
Example #13
Source File: BitmapCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public void clearDiskCache() {
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
            try {
                mDiskLruCache.delete();
                mDiskLruCache.close();
            } catch (Throwable e) {
                LogUtils.e(e.getMessage(), e);
            }
            mDiskLruCache = null;
        }
    }
    initDiskCache();
}
 
Example #14
Source File: BitmapCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public void clearDiskCache(String uri) {
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache != null && !mDiskLruCache.isClosed()) {
            try {
                mDiskLruCache.remove(uri);
            } catch (Throwable e) {
                LogUtils.e(e.getMessage(), e);
            }
        }
    }
}
 
Example #15
Source File: BitmapCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Flushes the disk cache associated with this ImageCache object. Note that this includes
 * disk access so this should not be executed on the main/UI thread.
 */
public void flush() {
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache != null) {
            try {
                mDiskLruCache.flush();
            } catch (Throwable e) {
                LogUtils.e(e.getMessage(), e);
            }
        }
    }
}
 
Example #16
Source File: BitmapCache.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Closes the disk cache associated with this ImageCache object. Note that this includes
 * disk access so this should not be executed on the main/UI thread.
 */
public void close() {
    synchronized (mDiskCacheLock) {
        if (mDiskLruCache != null) {
            try {
                if (!mDiskLruCache.isClosed()) {
                    mDiskLruCache.close();
                }
            } catch (Throwable e) {
                LogUtils.e(e.getMessage(), e);
            }
            mDiskLruCache = null;
        }
    }
}
 
Example #17
Source File: DbUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private synchronized static DbUtils getInstance(DaoConfig daoConfig) {
    DbUtils dao = daoMap.get(daoConfig.getDbName());
    if (dao == null) {
        dao = new DbUtils(daoConfig);
        daoMap.put(daoConfig.getDbName(), dao);
    } else {
        dao.daoConfig = daoConfig;
    }

    // update the database if needed
    SQLiteDatabase database = dao.database;
    int oldVersion = database.getVersion();
    int newVersion = daoConfig.getDbVersion();
    if (oldVersion != newVersion) { //数据库升级
        if (oldVersion != 0) {
            DbUpgradeListener upgradeListener = daoConfig.getDbUpgradeListener();
            if (upgradeListener != null) {
                upgradeListener.onUpgrade(dao, oldVersion, newVersion);
            } else {
                try {
                    dao.dropDb();
                } catch (DbException e) {
                    LogUtils.e(e.getMessage(), e);
                }
            }
        }
        database.setVersion(newVersion);
    }

    return dao;
}
 
Example #18
Source File: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static Bitmap decodeFile(String filename) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        options.inInputShareable = true;
        try {
            return BitmapFactory.decodeFile(filename, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example #19
Source File: HttpRequest.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
@Override
public URI getURI() {
    try {
        if (uriCharset == null) {
            uriCharset = OtherUtils.getCharsetFromHttpRequest(this);
        }
        if (uriCharset == null) {
            uriCharset = Charset.forName(HTTP.UTF_8);
        }
        return uriBuilder.build(uriCharset);
    } catch (URISyntaxException e) {
        LogUtils.e(e.getMessage(), e);
        return null;
    }
}
 
Example #20
Source File: DefaultSSLSocketFactory.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static DefaultSSLSocketFactory getSocketFactory() {
    if (instance == null) {
        try {
            instance = new DefaultSSLSocketFactory();
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
        }
    }
    return instance;
}
 
Example #21
Source File: URIBuilder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public URIBuilder(final String uri) {
    try {
        digestURI(new URI(uri));
    } catch (URISyntaxException e) {
        LogUtils.e(e.getMessage(), e);
    }
}
 
Example #22
Source File: RequestParams.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Returns an HttpEntity containing all request parameters
 */
public HttpEntity getEntity() {

    if (bodyEntity != null) {
        return bodyEntity;
    }

    HttpEntity result = null;

    if (fileParams != null && !fileParams.isEmpty()) {

        MultipartEntity multipartEntity = new MultipartEntity(HttpMultipartMode.STRICT, null, Charset.forName(charset));

        if (bodyParams != null && !bodyParams.isEmpty()) {
            for (NameValuePair param : bodyParams) {
                try {
                    multipartEntity.addPart(param.getName(), new StringBody(param.getValue()));
                } catch (UnsupportedEncodingException e) {
                    LogUtils.e(e.getMessage(), e);
                }
            }
        }

        for (ConcurrentHashMap.Entry<String, ContentBody> entry : fileParams.entrySet()) {
            multipartEntity.addPart(entry.getKey(), entry.getValue());
        }

        result = multipartEntity;
    } else if (bodyParams != null && !bodyParams.isEmpty()) {
        result = new BodyParamsEntity(bodyParams, charset);
    }

    return result;
}
 
Example #23
Source File: ColumnUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private static Method getBooleanColumnGetMethod(Class<?> entityType, final String fieldName) {
    String methodName = "is" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    if (isStartWithIs(fieldName)) {
        methodName = fieldName;
    }
    try {
        return entityType.getDeclaredMethod(methodName);
    } catch (NoSuchMethodException e) {
        LogUtils.d(methodName + " not exist");
    }
    return null;
}
 
Example #24
Source File: ColumnUtils.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
private static Method getBooleanColumnSetMethod(Class<?> entityType, Field field) {
    String fieldName = field.getName();
    String methodName = null;
    if (isStartWithIs(field.getName())) {
        methodName = "set" + fieldName.substring(2, 3).toUpperCase() + fieldName.substring(3);
    } else {
        methodName = "set" + fieldName.substring(0, 1).toUpperCase() + fieldName.substring(1);
    }
    try {
        return entityType.getDeclaredMethod(methodName, field.getType());
    } catch (NoSuchMethodException e) {
        LogUtils.d(methodName + " not exist");
    }
    return null;
}
 
Example #25
Source File: PriorityAsyncTask.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new asynchronous task. This constructor must be invoked on the UI thread.
 */
public PriorityAsyncTask() {
	//这一块为什么不直接使用Runnable, 我的见解是这种使用能获取返回值
    mWorker = new WorkerRunnable<Params, Result>() {  
        public Result call() throws Exception { //在子线程中运行
            mTaskInvoked.set(true);

            android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_BACKGROUND);
            //noinspection unchecked
            return postResult(doInBackground(mParams));
        }
    };

    mFuture = new FutureTask<Result>(mWorker) { //
        @Override
        protected void done() {  
            try {
                postResultIfNotInvoked(get());
            } catch (InterruptedException e) {
                LogUtils.d(e.getMessage());
            } catch (ExecutionException e) {
                throw new RuntimeException("An error occured while executing doInBackground()",
                        e.getCause());
            } catch (CancellationException e) {
                postResultIfNotInvoked(null);
            }
        }
    };
}
 
Example #26
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onSuccess(responseInfo);
    }
}
 
Example #27
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
DownloadManager(Context appContext) {
    ColumnConverterFactory.registerColumnConverter(HttpHandler.State.class, new HttpHandlerStateConverter());
    mContext = appContext;
    db = DbUtils.create(mContext);
    try {
        downloadInfoList = db.findAll(Selector.from(DownloadInfo.class));
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (downloadInfoList == null) {
        downloadInfoList = new ArrayList<DownloadInfo>();
    }
}
 
Example #28
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStart();
    }
}
 
Example #29
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onStopped() {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onStopped();
    }
}
 
Example #30
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onSuccess(ResponseInfo<File> responseInfo) {
    HttpHandler<File> handler = downloadInfo.getHandler();
    if (handler != null) {
        downloadInfo.setState(handler.getState());
    }
    try {
        db.saveOrUpdate(downloadInfo);
    } catch (DbException e) {
        LogUtils.e(e.getMessage(), e);
    }
    if (baseCallBack != null) {
        baseCallBack.onSuccess(responseInfo);
    }
}