diff --git a/ImageLibrary/build.gradle b/ImageLibrary/build.gradle index 5a07c87..99e1c59 100644 --- a/ImageLibrary/build.gradle +++ b/ImageLibrary/build.gradle @@ -35,7 +35,7 @@ dependencies { exclude group: 'com.android.support', module: 'support-annotations' }) testCompile 'junit:junit:4.12' - compile 'com.github.r17171709:AndroidCommonLibrary:v1.5.2' + compile 'com.github.r17171709:AndroidCommonLibrary:v1.6.7' // CircleIndicator A lightweight viewpager indicator like in nexus 5 launcher compile 'me.relex:circleindicator:1.2.2@aar' // PhotoDraweeView PhotoView For Fresco diff --git a/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewActivity.java b/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewActivity.java index 14f9b82..96330ec 100644 --- a/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewActivity.java +++ b/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewActivity.java @@ -18,6 +18,7 @@ import android.widget.Toast; import com.facebook.imagepipeline.image.ImageInfo; +import com.renyu.commonlibrary.adapter.ViewPagerFragmentAdapter; import com.renyu.commonlibrary.baseact.BaseActivity; import com.renyu.imagelibrary.R; import com.renyu.imagelibrary.commonutils.Utils; @@ -41,7 +42,7 @@ public class ImagePreviewActivity extends BaseActivity { MultiTouchViewPager imagepreview_viewpager; - MyPagerAdapter adapter; + ViewPagerFragmentAdapter adapter; CircleIndicator imagepreview_indicator; RelativeLayout layout_imagepreview_edit; TextView imagepreview_edit; @@ -139,7 +140,7 @@ public void picChanged(int position, ImageInfo imageInfo) { }); fragments.add(fragment); } - adapter=new MyPagerAdapter(getSupportFragmentManager()); + adapter=new ViewPagerFragmentAdapter(fragments, getSupportFragmentManager()); imagepreview_viewpager.setAdapter(adapter); imagepreview_viewpager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override @@ -185,59 +186,6 @@ public void onClick(View v) { tv_nav_title.setText((position+1)+"/"+urls.size()); } - private class MyPagerAdapter extends FragmentPagerAdapter { - public MyPagerAdapter(FragmentManager fm) { - super(fm); - } - - @Override - public Fragment getItem(int position) { - return fragments.get(position); - } - - @Override - public int getCount() { - return fragments.size(); - } - - @Override - public int getItemPosition(Object object) { - return POSITION_NONE; - } - - @Override - public Object instantiateItem(ViewGroup container, int position) { - removeFragment(container,position); - return super.instantiateItem(container, position); - } - } - - private void removeFragment(ViewGroup container,int index) { - String tag = getFragmentTag(container.getId(), index); - Fragment fragment = getSupportFragmentManager().findFragmentByTag(tag); - if (fragment == null) - return; - FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); - ft.remove(fragment); - ft.commitAllowingStateLoss(); - getSupportFragmentManager().executePendingTransactions(); - } - - private String getFragmentTag(int viewId, int index) { - try { - Class cls = FragmentPagerAdapter.class; - Class[] parameterTypes = { int.class, long.class }; - Method method = cls.getDeclaredMethod("makeFragmentName", - parameterTypes); - method.setAccessible(true); - String tag = (String) method.invoke(this, viewId, index); - return tag; - } catch (Exception e) { - e.printStackTrace(); - return ""; - } - } - @Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); diff --git a/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewFragment.java b/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewFragment.java index ba5c74c..24ad372 100644 --- a/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewFragment.java +++ b/ImageLibrary/src/main/java/com/renyu/imagelibrary/preview/ImagePreviewFragment.java @@ -56,7 +56,7 @@ public void initParams() { String url=getArguments().getString("url"); PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder(); ImageRequest request = ImageRequestBuilder.newBuilderWithSource(Uri.parse(url.indexOf("http")!=-1?url:"file://"+url)) - .setResizeOptions(new ResizeOptions(SizeUtils.dp2px(360), SizeUtils.dp2px(640))).build(); + .setResizeOptions(new ResizeOptions(SizeUtils.dp2px(180), SizeUtils.dp2px(320))).build(); controller.setImageRequest(request); controller.setOldController(photoDraweeView.getController()); controller.setControllerListener(new BaseControllerListener() { diff --git a/app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java b/app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java index 8ba3365..fda1827 100644 --- a/app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java +++ b/app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java @@ -21,20 +21,20 @@ protected void onCreate(Bundle savedInstanceState) { com.blankj.utilcode.util.Utils.init(this); Fresco.initialize(this); -// ArrayList strings=new ArrayList<>(); -// strings.add("http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg"); -// strings.add("http://img.sj33.cn/uploads/allimg/201302/1-130201105055.jpg"); -// Intent intent=new Intent(this, ImagePreviewActivity.class); -// Bundle bundle=new Bundle(); -// bundle.putBoolean("canDownload", false); -// bundle.putInt("position", 0); -// bundle.putBoolean("canEdit", false); -// bundle.putStringArrayList("urls", strings); -// bundle.putString("rightNav", "查看"); -// bundle.putParcelable("rightNavClick", new RightNavClick()); -// intent.putExtras(bundle); -// startActivity(intent); - - Utils.showLongPreview(this, "http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg", Environment.getExternalStorageDirectory().getPath()); + ArrayList strings=new ArrayList<>(); + strings.add("http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg"); + strings.add("http://img.sj33.cn/uploads/allimg/201302/1-130201105055.jpg"); + Intent intent=new Intent(this, ImagePreviewActivity.class); + Bundle bundle=new Bundle(); + bundle.putBoolean("canDownload", false); + bundle.putInt("position", 0); + bundle.putBoolean("canEdit", false); + bundle.putStringArrayList("urls", strings); + bundle.putString("rightNav", "查看"); + bundle.putParcelable("rightNavClick", new RightNavClick()); + intent.putExtras(bundle); + startActivity(intent); + +// Utils.showLongPreview(this, "http://7b1g8u.com1.z0.glb.clouddn.com/ccc.jpg", Environment.getExternalStorageDirectory().getPath()); } }