android - Reset TouchImageView zoom in ViewPager -



android - Reset TouchImageView zoom in ViewPager -

i have activity fullscreen browsing of images (something gallery). in activity have viewpager offscreen limit 6. utilize touchimageview images. problem is, when first zoom image , swipe photo, want see not zoomed photo when homecoming it. touchimageview has resetzoom() function, how can offscreen page view fragmentstatepageadapter or viewpager? here's code of activity:

public class imageslidesactivity extends fragmentactivity implements viewpager.onpagechangelistener { final int page_limit = 6; final int page_margin = 8; long userid; long deviceid; string key; string[] mattachments; imageslidesadapter madaper; viewpager mpager; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); requestwindowfeature(window.feature_action_bar_overlay); setcontentview(r.layout.activity_image_slides); actionbar actionbar = getactionbar(); actionbar.setdisplayhomeasupenabled(true); //actionbar.setbackgrounddrawable(new colordrawable(color.parsecolor("#33ffffff"))); intent intent = getintent(); mattachments = intent.getstringarrayextra("attachments"); int position = intent.getintextra("position", 0); sharedpreferences pref = getapplicationcontext().getsharedpreferences("authdata", 0); key = pref.getstring("key", null); userid = pref.getlong("userid", 0); deviceid = pref.getlong("deviceid", 0); setpageindicator(position); madaper = new imageslidesadapter(getsupportfragmentmanager(), mattachments); final view container = findviewbyid(r.id.container); container.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { getactionbar().hide(); container.setsystemuivisibility(view.system_ui_flag_hide_navigation); } }); mpager = (viewpager) findviewbyid(r.id.pager); mpager.setadapter(madaper); mpager.setonpagechangelistener(this); mpager.setoffscreenpagelimit(page_limit); mpager.setcurrentitem(position-1); /* cause bug white strip final float density = getresources().getdisplaymetrics().density; mpager.setpagemargin((int) (page_margin * density + 0.5f)); mpager.setpagemargindrawable(android.r.color.black); */ } @override public boolean oncreateoptionsmenu(menu menu) { // inflate menu; adds items action bar if present. //getmenuinflater().inflate(r.menu.image_slides, menu); homecoming true; } @override public boolean onoptionsitemselected(menuitem item) { // handle action bar item clicks here. action bar // automatically handle clicks on home/up button, long // specify parent activity in androidmanifest.xml. int id = item.getitemid(); if (id == android.r.id.home) { onbackpressed(); } if (id == r.id.action_settings) { homecoming true; } homecoming super.onoptionsitemselected(item); } @override public void onpagescrolled(int position, float positionoffset, int positionoffsetpixels) { } @override public void onpageselected(int position) { setpageindicator(position+1); } @override public void onpagescrollstatechanged(int state) { } private void setpageindicator(int page) { settitle(integer.tostring(page) + "/" + integer.tostring(mattachments.length)); } /** * fragment containing zoomable image. */ public static class showimagefragment extends fragment { string malias; long muserid; long mdeviceid; string mkey; touchimageview mimage; static showimagefragment newinstance(string alias, long userid, long deviceid, string key) { showimagefragment f = new showimagefragment(); bundle args = new bundle(); args.putstring("alias", alias); args.putlong("userid", userid); args.putlong("deviceid", deviceid); args.putstring("key", key); f.setarguments(args); homecoming f; } @override public void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); bundle bundle = getarguments(); malias = bundle.getstring("alias"); muserid = bundle.getlong("userid"); mdeviceid = bundle.getlong("deviceid"); mkey = bundle.getstring("key"); } @override public view oncreateview(layoutinflater inflater, viewgroup container, bundle savedinstancestate) { view rootview = inflater.inflate(r.layout.fragment_image_slides, container, false); mimage = (touchimageview) rootview.findviewbyid(r.id.imageview); final progressbar prbar = (progressbar) rootview.findviewbyid(r.id.progressbar); new asynctask<void, void, bitmap>() { @override protected bitmap doinbackground(void... voids) { seek { string[] links = api.getimagelinkbyalias(malias, muserid, mdeviceid, mkey); homecoming imageloader.getinstance().loadimagesync(links[1]); } grab (exception e) { // todo: handle exceptions e.printstacktrace(); cancel(true); homecoming null; } } @override protected void onpostexecute(bitmap bitmap) { prbar.setvisibility(view.gone); if (bitmap == null) { return; } mimage.setimagebitmap(bitmap); mimage.setvisibility(view.visible); mimage.setonclicklistener(new view.onclicklistener() { @override public void onclick(view view) { if (getactivity().getactionbar().isshowing()) { getactivity().getactionbar().hide(); } else { getactivity().getactionbar().show(); } } }); } }.execute(); homecoming rootview; } } public class imageslidesadapter extends fragmentstatepageradapter { private string[] maliases; public imageslidesadapter(android.support.v4.app.fragmentmanager fm, string[] aliases) { super(fm); maliases = aliases; } @override public android.support.v4.app.fragment getitem(int position) { homecoming showimagefragment.newinstance(maliases[position], userid, deviceid, key); } @override public int getcount() { homecoming maliases.length; } }

}

i overrided onpageselected method , views calling getchildat().

@override public void onpageselected(int position) { setpageindicator(position+1); if (position > 0) { view view = mpager.getchildat(position -1); if (view != null) { touchimageview img = (touchimageview) view.findviewbyid(r.id.image); img.resetzoom(); } } if (position < mpager.getchildcount() - 1) { view view = mpager.getchildat(position + 1); if (view != null) { touchimageview img = (touchimageview) view.findviewbyid(r.id.image); img.resetzoom(); } } }

android android-viewpager fragmentstatepageradapter touchimageview

Comments

Popular posts from this blog

xslt - DocBook 5 to PDF transform failing with error: "fo:flow" is missing child elements. Required content model: marker* -

mediawiki - How do I insert tables inside infoboxes on Wikia pages? -

SQL Server : need assitance parsing delimted data and returning a long concatenated string -