Java Code Examples for com.lidroid.xutils.util.LogUtils#e()

The following examples show how to use com.lidroid.xutils.util.LogUtils#e() . 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: 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 2
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 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: 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 5
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 6
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 7
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 8
Source File: test.java    From ALLGO with Apache License 2.0 5 votes vote down vote up
public void test3(){

        RequestParams params = new RequestParams();
        params.addQueryStringParameter("uname", "中文");
        //params.addHeader("appkey" , "0000001");
        HttpUtils http = new HttpUtils();
        try {
            ResponseStream responseStream = http.sendSync(HttpRequest.HttpMethod.POST,
            		"http://10.0.2.2:8080/ALLGO_SERVER/login", params);
            Log.i("Http" , responseStream.readString() ) ;
        } catch (Exception e) {
            LogUtils.e(e.getMessage(), e);
        }
    
	}
 
Example 9
Source File: DownloadManager.java    From AndroidAppCodeFramework with Apache License 2.0 5 votes vote down vote up
@Override
public void onFailure(HttpException error, String msg) {
    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.onFailure(error, msg);
    }
}
 
Example 10
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 11
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 12
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 13
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 14
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 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: BitmapDecoder.java    From android-open-project-demo with Apache License 2.0 5 votes vote down vote up
public static Bitmap decodeFileDescriptor(FileDescriptor fileDescriptor) {
    synchronized (lock) {
        final BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPurgeable = true;
        options.inInputShareable = true;
        try {
            return BitmapFactory.decodeFileDescriptor(fileDescriptor, null, options);
        } catch (Throwable e) {
            LogUtils.e(e.getMessage(), e);
            return null;
        }
    }
}
 
Example 17
Source File: EventListenerManager.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
public static void addEventMethod(
        ViewFinder finder,
        ViewInjectInfo info,
        Annotation eventAnnotation,
        Object handler,
        Method method) {
    try {
        View view = finder.findViewByInfo(info);
        if (view != null) {
            EventBase eventBase = eventAnnotation.annotationType().getAnnotation(EventBase.class);
            Class<?> listenerType = eventBase.listenerType();
            String listenerSetter = eventBase.listenerSetter();
            String methodName = eventBase.methodName();

            boolean addNewMethod = false;
            Object listener = listenerCache.get(info, listenerType);
            DynamicHandler dynamicHandler = null;
            if (listener != null) {
                dynamicHandler = (DynamicHandler) Proxy.getInvocationHandler(listener);
                addNewMethod = handler.equals(dynamicHandler.getHandler());
                if (addNewMethod) {
                    dynamicHandler.addMethod(methodName, method);
                }
            }
            if (!addNewMethod) {
                dynamicHandler = new DynamicHandler(handler);
                dynamicHandler.addMethod(methodName, method);
                listener = Proxy.newProxyInstance(
                        listenerType.getClassLoader(),
                        new Class<?>[]{listenerType},
                        dynamicHandler);

                listenerCache.put(info, listenerType, listener);
            }

            Method setEventListenerMethod = view.getClass().getMethod(listenerSetter, listenerType);
            setEventListenerMethod.invoke(view, listener);
        }
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }
}
 
Example 18
Source File: LruDiskCache.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
/**
 * Opens the cache in {@code directory}, creating a cache if none exists
 * there.
 *
 * @param directory  a writable directory
 * @param valueCount the number of values per cache entry. Must be positive.
 * @param maxSize    the maximum number of bytes this cache should use to store
 * @throws IOException if reading or writing the cache directory fails
 */
public static LruDiskCache open(File directory, int appVersion, int valueCount, long maxSize)
        throws IOException {
    if (maxSize <= 0) {
        throw new IllegalArgumentException("maxSize <= 0");
    }
    if (valueCount <= 0) {
        throw new IllegalArgumentException("valueCount <= 0");
    }

    // If a bkp file exists, use it instead.
    File backupFile = new File(directory, JOURNAL_FILE_BACKUP);
    if (backupFile.exists()) {
        File journalFile = new File(directory, JOURNAL_FILE);
        // If journal file also exists just delete backup file.
        if (journalFile.exists()) {
            backupFile.delete();
        } else {
            renameTo(backupFile, journalFile, false);
        }
    }

    // Prefer to pick up where we left off.
    LruDiskCache cache = new LruDiskCache(directory, appVersion, valueCount, maxSize);
    if (cache.journalFile.exists()) {
        try {
            cache.readJournal();
            cache.processJournal();
            cache.journalWriter = new BufferedWriter(
                    new OutputStreamWriter(new FileOutputStream(cache.journalFile, true), HTTP.US_ASCII));
            return cache;
        } catch (Throwable journalIsCorrupt) {
            LogUtils.e("DiskLruCache "
                    + directory
                    + " is corrupt: "
                    + journalIsCorrupt.getMessage()
                    + ", removing", journalIsCorrupt);
            cache.delete();
        }
    }

    // Create a new empty cache.
    if (directory.exists() || directory.mkdirs()) {
        cache = new LruDiskCache(directory, appVersion, valueCount, maxSize);
        cache.rebuildJournal();
    }
    return cache;
}
 
Example 19
Source File: DefaultDownloader.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
/**
 * Download bitmap to outputStream by uri.
 *
 * @param uri          file path, assets path(assets/xxx) or http url.
 * @param outputStream
 * @param task
 * @return The expiry time stamp or -1 if failed to download.
 */
@Override
public long downloadToStream(String uri, OutputStream outputStream, final BitmapUtils.BitmapLoadTask<?> task) {

    if (task == null || task.isCancelled() || task.getTargetContainer() == null) return -1;

    URLConnection urlConnection = null;
    BufferedInputStream bis = null;

    OtherUtils.trustAllHttpsURLConnection();

    long result = -1;
    long fileLen = 0;
    long currCount = 0;  
    try {
    	//分三种方式获取图片
        if (uri.startsWith("/")) { 
        	//sd卡获取
            FileInputStream fileInputStream = new FileInputStream(uri);
            fileLen = fileInputStream.available();
            bis = new BufferedInputStream(fileInputStream);
            result = System.currentTimeMillis() + this.getDefaultExpiry();
        } else if (uri.startsWith("assets/")) { 
        	//资产文件夹
            InputStream inputStream = this.getContext().getAssets().open(uri.substring(7, uri.length()));
            fileLen = inputStream.available();
            bis = new BufferedInputStream(inputStream);
            result = Long.MAX_VALUE;
        } else {  
        	//网络
            final URL url = new URL(uri);
            urlConnection = url.openConnection();
            urlConnection.setConnectTimeout(this.getDefaultConnectTimeout());
            urlConnection.setReadTimeout(this.getDefaultReadTimeout());
            bis = new BufferedInputStream(urlConnection.getInputStream());
            result = urlConnection.getExpiration();
            result = result < System.currentTimeMillis() ? System.currentTimeMillis() + this.getDefaultExpiry() : result;
            fileLen = urlConnection.getContentLength();
        }

        if (task.isCancelled() || task.getTargetContainer() == null) return -1;

        byte[] buffer = new byte[4096];
        int len = 0;
        BufferedOutputStream out = new BufferedOutputStream(outputStream);
        while ((len = bis.read(buffer)) != -1) {
            out.write(buffer, 0, len);
            currCount += len;
            if (task.isCancelled() || task.getTargetContainer() == null) return -1;
            task.updateProgress(fileLen, currCount);     //回调
        }
        out.flush();
    } catch (Throwable e) {
        result = -1;
        LogUtils.e(e.getMessage(), e);
    } finally {
        IOUtils.closeQuietly(bis);
    }
    return result;
}
 
Example 20
Source File: BitmapGlobalConfig.java    From android-open-project-demo with Apache License 2.0 4 votes vote down vote up
@Override
protected Object[] doInBackground(Object... params) {
    if (params == null || params.length == 0) return params;
    BitmapCache cache = getBitmapCache();
    if (cache == null) return params;
    try {
        switch ((Integer) params[0]) {
            case MESSAGE_INIT_MEMORY_CACHE:
                cache.initMemoryCache();
                break;
            case MESSAGE_INIT_DISK_CACHE:
                cache.initDiskCache();
                break;
            case MESSAGE_FLUSH:
                cache.flush();
                break;
            case MESSAGE_CLOSE:
                cache.clearMemoryCache();
                cache.close();
                break;
            case MESSAGE_CLEAR:
                cache.clearCache();
                break;
            case MESSAGE_CLEAR_MEMORY:
                cache.clearMemoryCache();
                break;
            case MESSAGE_CLEAR_DISK:
                cache.clearDiskCache();
                break;
            case MESSAGE_CLEAR_BY_KEY:
                if (params.length != 2) return params;
                cache.clearCache(String.valueOf(params[1]));
                break;
            case MESSAGE_CLEAR_MEMORY_BY_KEY:
                if (params.length != 2) return params;
                cache.clearMemoryCache(String.valueOf(params[1]));
                break;
            case MESSAGE_CLEAR_DISK_BY_KEY:
                if (params.length != 2) return params;
                cache.clearDiskCache(String.valueOf(params[1]));
                break;
            default:
                break;
        }
    } catch (Throwable e) {
        LogUtils.e(e.getMessage(), e);
    }
    return params;
}