Search in sources :

Example 6 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TImageFiles method inputStreamToFile.

/**
     * InputStream 转File
     * */
public static void inputStreamToFile(InputStream is, File file) throws TException {
    if (file == null) {
        Log.i(TAG, "inputStreamToFile:file not be null");
        throw new TException(TExceptionType.TYPE_WRITE_FAIL);
    }
    FileOutputStream fos = null;
    try {
        fos = new FileOutputStream(file);
        byte[] buffer = new byte[1024 * 10];
        int i;
        while ((i = is.read(buffer)) != -1) {
            fos.write(buffer, 0, i);
        }
    } catch (IOException e) {
        Log.e(TAG, "InputStream 写入文件出错:" + e.toString());
        throw new TException(TExceptionType.TYPE_WRITE_FAIL);
    } finally {
        try {
            fos.flush();
            fos.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : TException(com.jph.takephoto.model.TException) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException)

Example 7 with TException

use of com.jph.takephoto.model.TException in project TakePhoto by crazycodeboy.

the class TUtils method sendIntentBySafely.

/**
     * 安全地发送Intent
     * @param contextWrap
     * @param intentWapList 要发送的Intent以及候选Intent
     * @param defaultIndex 默认发送的Intent
     * @param isCrop 是否为裁切照片的Intent
     * @throws TException
     */
public static void sendIntentBySafely(TContextWrap contextWrap, List<TIntentWap> intentWapList, int defaultIndex, boolean isCrop) throws TException {
    if (defaultIndex + 1 > intentWapList.size())
        throw new TException(isCrop ? TExceptionType.TYPE_NO_MATCH_PICK_INTENT : TExceptionType.TYPE_NO_MATCH_CROP_INTENT);
    TIntentWap intentWap = intentWapList.get(defaultIndex);
    List result = contextWrap.getActivity().getPackageManager().queryIntentActivities(intentWap.getIntent(), PackageManager.MATCH_ALL);
    if (result.isEmpty()) {
        sendIntentBySafely(contextWrap, intentWapList, ++defaultIndex, isCrop);
    } else {
        startActivityForResult(contextWrap, intentWap);
    }
}
Also used : TException(com.jph.takephoto.model.TException) TIntentWap(com.jph.takephoto.model.TIntentWap) ArrayList(java.util.ArrayList) List(java.util.List)

Aggregations

TException (com.jph.takephoto.model.TException)7 TIntentWap (com.jph.takephoto.model.TIntentWap)3 File (java.io.File)3 ArrayList (java.util.ArrayList)2 Bitmap (android.graphics.Bitmap)1 Image (com.darsh.multipleimageselect.models.Image)1 CompressImage (com.jph.takephoto.compress.CompressImage)1 TImage (com.jph.takephoto.model.TImage)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 List (java.util.List)1