Skip to content

Commit

Permalink
调整降低内存使用量
Browse files Browse the repository at this point in the history
  • Loading branch information
r17171709 committed Oct 10, 2017
1 parent 0473b78 commit 0829cc0
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 72 deletions.
2 changes: 1 addition & 1 deletion ImageLibrary/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<FragmentPagerAdapter> 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ImageInfo>() {
Expand Down
30 changes: 15 additions & 15 deletions app/src/main/java/com/renyu/androidimagelibrary/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,20 @@ protected void onCreate(Bundle savedInstanceState) {
com.blankj.utilcode.util.Utils.init(this);
Fresco.initialize(this);

// ArrayList<String> 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<String> 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());
}
}

0 comments on commit 0829cc0

Please sign in to comment.