Search in sources :

Example 11 with PhotoInfo

use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.

the class PhotoEditActivity method onClick.

@Override
public void onClick(View v) {
    int id = v.getId();
    if (id == R.id.fab_crop) {
        if (mPhotoList.size() == 0) {
            return;
        }
        if (mCropState) {
            System.gc();
            PhotoInfo photoInfo = mPhotoList.get(mSelectIndex);
            try {
                String ext = FilenameUtils.getExtension(photoInfo.getPhotoPath());
                File toFile;
                if (GalleryFinal.getFunctionConfig().isCropReplaceSource()) {
                    toFile = new File(photoInfo.getPhotoPath());
                } else {
                    toFile = new File(mEditPhotoCacheFile, Utils.getFileName(photoInfo.getPhotoPath()) + "_crop." + ext);
                }
                FileUtils.mkdirs(toFile.getParentFile());
                //保存裁剪
                onSaveClicked(toFile);
            } catch (Exception e) {
                ILogger.e(e);
            }
        } else {
            //完成选择
            resultAction();
        }
    } else if (id == R.id.iv_crop) {
        if (mPhotoList.size() > 0) {
            PhotoInfo photoInfo = mPhotoList.get(mSelectIndex);
            String ext = FilenameUtils.getExtension(photoInfo.getPhotoPath());
            if (StringUtils.isEmpty(ext) || !(ext.equalsIgnoreCase("png") || ext.equalsIgnoreCase("jpg") || ext.equalsIgnoreCase("jpeg"))) {
                toast(getString(R.string.edit_letoff_photo_format));
            } else {
                if (mCropState) {
                    setCropEnabled(false);
                    corpPageState(false);
                    mTvTitle.setText(R.string.photo_edit);
                } else {
                    corpPageState(true);
                    setCropEnabled(true);
                    mTvTitle.setText(R.string.photo_crop);
                }
                mCropState = !mCropState;
            }
        }
    } else if (id == R.id.iv_rotate) {
        rotatePhoto();
    } else if (id == R.id.iv_take_photo) {
        if (GalleryFinal.getFunctionConfig().isMutiSelect() && GalleryFinal.getFunctionConfig().getMaxSize() == mSelectPhotoList.size()) {
            toast(getString(R.string.select_max_tips));
        } else {
            takePhotoAction();
        }
    } else if (id == R.id.iv_back) {
        if (mCropState && !(mCropPhotoAction && !GalleryFinal.getFunctionConfig().isRotate() && !GalleryFinal.getFunctionConfig().isCamera())) {
            if ((GalleryFinal.getFunctionConfig().isForceCrop() && GalleryFinal.getFunctionConfig().isForceCropEdit())) {
                mIvCrop.performClick();
                return;
            }
        }
        finish();
    } else if (id == R.id.iv_preview) {
        Intent intent = new Intent(this, PhotoPreviewActivity.class);
        intent.putExtra(PhotoPreviewActivity.PHOTO_LIST, mSelectPhotoList);
        startActivity(intent);
    }
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) Intent(android.content.Intent) File(java.io.File) IOException(java.io.IOException)

Example 12 with PhotoInfo

use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.

the class PhotoEditActivity method onItemClick.

@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
    mSelectIndex = i;
    PhotoInfo photoInfo = mPhotoList.get(i);
    loadImage(photoInfo);
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo)

Example 13 with PhotoInfo

use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.

the class GalleryFinal method openEdit.

/**
     * 打开编辑
     * @param requestCode
     * @param config
     * @param photoPath
     * @param callback
     */
public static void openEdit(int requestCode, FunctionConfig config, String photoPath, OnHanlderResultCallback callback) {
    if (mCoreConfig.getImageLoader() == null) {
        ILogger.e("Please init GalleryFinal.");
        if (callback != null) {
            callback.onHanlderFailure(requestCode, mCoreConfig.getContext().getString(R.string.open_gallery_fail));
        }
        return;
    }
    if (config == null && mGlobalFunctionConfig == null) {
        if (callback != null) {
            callback.onHanlderFailure(requestCode, mCoreConfig.getContext().getString(R.string.open_gallery_fail));
        }
        return;
    }
    if (!DeviceUtils.existSDCard()) {
        Toast.makeText(mCoreConfig.getContext(), R.string.empty_sdcard, Toast.LENGTH_SHORT).show();
        return;
    }
    if (config == null || StringUtils.isEmpty(photoPath) || !new File(photoPath).exists()) {
        ILogger.d("config为空或文件不存在");
        return;
    }
    mRequestCode = requestCode;
    mCallback = callback;
    //拍照为单选
    config.mutiSelect = false;
    mCurrentFunctionConfig = config;
    ArrayList<PhotoInfo> map = new ArrayList<>();
    PhotoInfo photoInfo = new PhotoInfo();
    photoInfo.setPhotoPath(photoPath);
    photoInfo.setPhotoId(Utils.getRandom(10000, 99999));
    map.add(photoInfo);
    Intent intent = new Intent(mCoreConfig.getContext(), PhotoEditActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(PhotoEditActivity.EDIT_PHOTO_ACTION, true);
    intent.putExtra(PhotoEditActivity.SELECT_MAP, map);
    mCoreConfig.getContext().startActivity(intent);
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) ArrayList(java.util.ArrayList) Intent(android.content.Intent) File(java.io.File)

Example 14 with PhotoInfo

use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.

the class PhotoBaseActivity method onActivityResult.

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == GalleryFinal.TAKE_REQUEST_CODE) {
        if (resultCode == RESULT_OK && mTakePhotoUri != null) {
            final String path = mTakePhotoUri.getPath();
            if (new File(path).exists()) {
                final PhotoInfo info = new PhotoInfo();
                info.setPhotoId(Utils.getRandom(10000, 99999));
                info.setPhotoPath(path);
                updateGallery(path);
                takeResult(info);
            } else {
                takePhotoFailure();
            }
        } else {
            takePhotoFailure();
        }
    }
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) File(java.io.File)

Example 15 with PhotoInfo

use of cn.finalteam.galleryfinal.model.PhotoInfo in project GalleryFinal by pengjianbo.

the class PhotoEditActivity method onCreate.

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if (GalleryFinal.getFunctionConfig() == null || GalleryFinal.getGalleryTheme() == null) {
        resultFailureDelayed(getString(R.string.please_reopen_gf), true);
    } else {
        setContentView(R.layout.gf_activity_photo_edit);
        mDefaultDrawable = getResources().getDrawable(R.drawable.ic_gf_default_photo);
        mSelectPhotoList = (ArrayList<PhotoInfo>) getIntent().getSerializableExtra(SELECT_MAP);
        mTakePhotoAction = this.getIntent().getBooleanExtra(TAKE_PHOTO_ACTION, false);
        mCropPhotoAction = this.getIntent().getBooleanExtra(CROP_PHOTO_ACTION, false);
        mEditPhotoAction = this.getIntent().getBooleanExtra(EDIT_PHOTO_ACTION, false);
        if (mSelectPhotoList == null) {
            mSelectPhotoList = new ArrayList<>();
        }
        mPhotoTempMap = new LinkedHashMap<>();
        mPhotoList = new ArrayList<>(mSelectPhotoList);
        mEditPhotoCacheFile = GalleryFinal.getCoreConfig().getEditPhotoCacheFolder();
        if (mPhotoList == null) {
            mPhotoList = new ArrayList<>();
        }
        for (PhotoInfo info : mPhotoList) {
            mPhotoTempMap.put(info.getPhotoId(), new PhotoTempModel(info.getPhotoPath()));
        }
        findViews();
        setListener();
        setTheme();
        mPhotoEditListAdapter = new PhotoEditListAdapter(this, mPhotoList, mScreenWidth);
        mLvGallery.setAdapter(mPhotoEditListAdapter);
        try {
            File nomediaFile = new File(mEditPhotoCacheFile, ".nomedia");
            if (!nomediaFile.exists()) {
                nomediaFile.createNewFile();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        if (GalleryFinal.getFunctionConfig().isCamera()) {
            mIvTakePhoto.setVisibility(View.VISIBLE);
        }
        if (GalleryFinal.getFunctionConfig().isCrop()) {
            mIvCrop.setVisibility(View.VISIBLE);
        }
        if (GalleryFinal.getFunctionConfig().isRotate()) {
            mIvRotate.setVisibility(View.VISIBLE);
        }
        if (!GalleryFinal.getFunctionConfig().isMutiSelect()) {
            mLlGallery.setVisibility(View.GONE);
        }
        initCrop(mIvCropPhoto, GalleryFinal.getFunctionConfig().isCropSquare(), GalleryFinal.getFunctionConfig().getCropWidth(), GalleryFinal.getFunctionConfig().getCropHeight());
        if (mPhotoList.size() > 0 && !mTakePhotoAction) {
            loadImage(mPhotoList.get(0));
        }
        if (mTakePhotoAction) {
            //打开相机
            takePhotoAction();
        }
        if (mCropPhotoAction) {
            mIvCrop.performClick();
            if (!GalleryFinal.getFunctionConfig().isRotate() && !GalleryFinal.getFunctionConfig().isCamera()) {
                mIvCrop.setVisibility(View.GONE);
            }
        } else {
            //判断是否强制裁剪
            hasForceCrop();
        }
        if (GalleryFinal.getFunctionConfig().isEnablePreview()) {
            mIvPreView.setVisibility(View.VISIBLE);
        }
    }
}
Also used : PhotoInfo(cn.finalteam.galleryfinal.model.PhotoInfo) PhotoEditListAdapter(cn.finalteam.galleryfinal.adapter.PhotoEditListAdapter) PhotoTempModel(cn.finalteam.galleryfinal.model.PhotoTempModel) IOException(java.io.IOException) File(java.io.File)

Aggregations

PhotoInfo (cn.finalteam.galleryfinal.model.PhotoInfo)19 File (java.io.File)9 ArrayList (java.util.ArrayList)5 Drawable (android.graphics.drawable.Drawable)4 PhotoFolderInfo (cn.finalteam.galleryfinal.model.PhotoFolderInfo)4 Intent (android.content.Intent)3 IOException (java.io.IOException)3 Message (android.os.Message)2 PhotoTempModel (cn.finalteam.galleryfinal.model.PhotoTempModel)2 Cursor (android.database.Cursor)1 Bitmap (android.graphics.Bitmap)1 ImageView (android.widget.ImageView)1 PhotoEditListAdapter (cn.finalteam.galleryfinal.adapter.PhotoEditListAdapter)1 PhotoListAdapter (cn.finalteam.galleryfinal.adapter.PhotoListAdapter)1 PhotoPreviewAdapter (cn.finalteam.galleryfinal.adapter.PhotoPreviewAdapter)1 DisplayImageOptions (com.nostra13.universalimageloader.core.DisplayImageOptions)1 HashMap (java.util.HashMap)1