use of cn.finalteam.galleryfinal.sample.loader.FrescoImageLoader in project GalleryFinal by pengjianbo.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.bind(this);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
mLvPhoto = (HorizontalListView) findViewById(R.id.lv_photo);
mPhotoList = new ArrayList<>();
mChoosePhotoListAdapter = new ChoosePhotoListAdapter(this, mPhotoList);
mLvPhoto.setAdapter(mChoosePhotoListAdapter);
mOpenGallery = (Button) findViewById(R.id.btn_open_gallery);
mRbMutiSelect.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mLlMaxSize.setVisibility(View.VISIBLE);
mLlForceCrop.setVisibility(View.GONE);
} else {
if (mCbEdit.isChecked()) {
mLlForceCrop.setVisibility(View.VISIBLE);
}
mLlMaxSize.setVisibility(View.GONE);
}
}
});
mCbEdit.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mLlEdit.setVisibility(View.VISIBLE);
} else {
mLlEdit.setVisibility(View.GONE);
}
}
});
mCbCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mLlCropSize.setVisibility(View.VISIBLE);
mCbCropReplaceSource.setVisibility(View.VISIBLE);
if (mRbSingleSelect.isChecked()) {
mLlForceCrop.setVisibility(View.VISIBLE);
}
} else {
mLlCropSize.setVisibility(View.GONE);
mCbCropReplaceSource.setVisibility(View.INVISIBLE);
mLlForceCrop.setVisibility(View.GONE);
}
}
});
mCbRotate.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mCbRotateReplaceSource.setVisibility(View.VISIBLE);
} else {
mCbRotateReplaceSource.setVisibility(View.INVISIBLE);
}
}
});
mCbOpenForceCrop.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (isChecked) {
mCbOpenForceCropEdit.setVisibility(View.VISIBLE);
} else {
mCbOpenForceCropEdit.setVisibility(View.INVISIBLE);
}
}
});
mOpenGallery.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// 公共配置都可以在application中配置,这里只是为了代码演示而写在此处
ThemeConfig themeConfig = null;
if (mRbThemeDefault.isChecked()) {
themeConfig = ThemeConfig.DEFAULT;
} else if (mRbThemeDark.isChecked()) {
themeConfig = ThemeConfig.DARK;
} else if (mRbThemeCyan.isChecked()) {
themeConfig = ThemeConfig.CYAN;
} else if (mRbThemeOrange.isChecked()) {
themeConfig = ThemeConfig.ORANGE;
} else if (mRbThemeGreen.isChecked()) {
themeConfig = ThemeConfig.GREEN;
} else if (mRbThemeTeal.isChecked()) {
themeConfig = ThemeConfig.TEAL;
} else if (mRbThemeCustom.isChecked()) {
ThemeConfig theme = new ThemeConfig.Builder().setTitleBarBgColor(Color.rgb(0xFF, 0x57, 0x22)).setTitleBarTextColor(Color.BLACK).setTitleBarIconColor(Color.BLACK).setFabNornalColor(Color.RED).setFabPressedColor(Color.BLUE).setCheckNornalColor(Color.WHITE).setCheckSelectedColor(Color.BLACK).setIconBack(R.mipmap.ic_action_previous_item).setIconRotate(R.mipmap.ic_action_repeat).setIconCrop(R.mipmap.ic_action_crop).setIconCamera(R.mipmap.ic_action_camera).build();
themeConfig = theme;
}
FunctionConfig.Builder functionConfigBuilder = new FunctionConfig.Builder();
cn.finalteam.galleryfinal.ImageLoader imageLoader;
PauseOnScrollListener pauseOnScrollListener = null;
if (mRbUil.isChecked()) {
imageLoader = new UILImageLoader();
pauseOnScrollListener = new UILPauseOnScrollListener(false, true);
} else if (mRbXutils.isChecked()) {
imageLoader = new XUtils2ImageLoader(MainActivity.this);
} else if (mRbXutils3.isChecked()) {
imageLoader = new XUtilsImageLoader();
} else if (mRbGlide.isChecked()) {
imageLoader = new GlideImageLoader();
pauseOnScrollListener = new GlidePauseOnScrollListener(false, true);
} else if (mRbFresco.isChecked()) {
imageLoader = new FrescoImageLoader(MainActivity.this);
} else {
imageLoader = new PicassoImageLoader();
pauseOnScrollListener = new PicassoPauseOnScrollListener(false, true);
}
boolean muti = false;
if (mRbSingleSelect.isChecked()) {
muti = false;
} else {
muti = true;
if (TextUtils.isEmpty(mEtMaxSize.getText().toString())) {
Toast.makeText(getApplicationContext(), "请输入MaxSize", Toast.LENGTH_SHORT).show();
return;
}
int maxSize = Integer.parseInt(mEtMaxSize.getText().toString());
functionConfigBuilder.setMutiSelectMaxSize(maxSize);
}
final boolean mutiSelect = muti;
if (mCbEdit.isChecked()) {
functionConfigBuilder.setEnableEdit(true);
}
if (mCbRotate.isChecked()) {
functionConfigBuilder.setEnableRotate(true);
if (mCbRotateReplaceSource.isChecked()) {
functionConfigBuilder.setRotateReplaceSource(true);
}
}
if (mCbCrop.isChecked()) {
functionConfigBuilder.setEnableCrop(true);
if (!TextUtils.isEmpty(mEtCropWidth.getText().toString())) {
int width = Integer.parseInt(mEtCropWidth.getText().toString());
functionConfigBuilder.setCropWidth(width);
}
if (!TextUtils.isEmpty(mEtCropHeight.getText().toString())) {
int height = Integer.parseInt(mEtCropHeight.getText().toString());
functionConfigBuilder.setCropHeight(height);
}
if (mCbCropSquare.isChecked()) {
functionConfigBuilder.setCropSquare(true);
}
if (mCbCropReplaceSource.isChecked()) {
functionConfigBuilder.setCropReplaceSource(true);
}
if (mCbOpenForceCrop.isChecked() && mRbSingleSelect.isChecked()) {
functionConfigBuilder.setForceCrop(true);
if (mCbOpenForceCropEdit.isChecked()) {
functionConfigBuilder.setForceCropEdit(true);
}
}
}
if (mCbShowCamera.isChecked()) {
functionConfigBuilder.setEnableCamera(true);
}
if (mCbPreview.isChecked()) {
functionConfigBuilder.setEnablePreview(true);
}
// 添加过滤集合
functionConfigBuilder.setSelected(mPhotoList);
final FunctionConfig functionConfig = functionConfigBuilder.build();
CoreConfig coreConfig = new CoreConfig.Builder(MainActivity.this, imageLoader, themeConfig).setFunctionConfig(functionConfig).setPauseOnScrollListener(pauseOnScrollListener).setNoAnimcation(mCbNoAnimation.isChecked()).build();
GalleryFinal.init(coreConfig);
ActionSheet.createBuilder(MainActivity.this, getSupportFragmentManager()).setCancelButtonTitle("取消(Cancel)").setOtherButtonTitles("打开相册(Open Gallery)", "拍照(Camera)", "裁剪(Crop)", "编辑(Edit)").setCancelableOnTouchOutside(true).setListener(new ActionSheet.ActionSheetListener() {
@Override
public void onDismiss(ActionSheet actionSheet, boolean isCancel) {
}
@Override
public void onOtherButtonClick(ActionSheet actionSheet, int index) {
String path = "/sdcard/pk1-2.jpg";
switch(index) {
case 0:
if (mutiSelect) {
GalleryFinal.openGalleryMuti(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
} else {
GalleryFinal.openGallerySingle(REQUEST_CODE_GALLERY, functionConfig, mOnHanlderResultCallback);
}
break;
case 1:
GalleryFinal.openCamera(REQUEST_CODE_CAMERA, functionConfig, mOnHanlderResultCallback);
break;
case 2:
if (new File(path).exists()) {
GalleryFinal.openCrop(REQUEST_CODE_CROP, functionConfig, path, mOnHanlderResultCallback);
} else {
Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
}
break;
case 3:
if (new File(path).exists()) {
GalleryFinal.openEdit(REQUEST_CODE_EDIT, functionConfig, path, mOnHanlderResultCallback);
} else {
Toast.makeText(MainActivity.this, "图片不存在", Toast.LENGTH_SHORT).show();
}
break;
default:
break;
}
}
}).show();
}
});
initImageLoader(this);
initFresco();
x.Ext.init(getApplication());
}
Aggregations