Curl page from left to right

So, I use the harl page curl, https://github.com/harism/android_page_curl and successfully implemented it to upload images via web streams. But I can't get it to work when I go back to previous images or pages, since the images are not coming with the correct index. that is, they do not refresh properly. I can’t figure it out.

This is my implementation when I upload images to PageProvider

 private class PageProvider implements CurlView.PageProvider { @Override public int getPageCount() { return data1.size()-1; } private Bitmap loadBitmap(int width, int height, final int index) throws MalformedURLException, IOException { Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888); b.eraseColor(0xFFFFFFFF); Canvas c = new Canvas(b); System.out.println("value of current page index "+mCurlView.getCurrentIndex()+" and index is "+index); System.out.println("url forward"); aq.ajax(data1.get(index+1), Bitmap.class,0, new AjaxCallback<Bitmap>() { @Override public void callback(String url, Bitmap object, AjaxStatus status) { if(object!=null) try { System.out.println("url image downloaded "+url); y=object; aq.ajax(data1.get(index).replace(".png", ".mp3"), File.class,0,new AjaxCallback<File>() { @Override public void callback(String url, File object, AjaxStatus status) { System.out.println("url sound downloaded "+url); try { if(object!=null) { FileInputStream inputStream = new FileInputStream(object); if(index>0) { mPlayer.stop(); mPlayer.reset(); } prepareMediaPlayer(inputStream.getFD()); inputStream.close(); } } catch (Exception e) {} } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); d = new BitmapDrawable(getResources(),y); if(y!=null) { int margin = 7; int border = 3; Rect r = new Rect(margin, margin, width - margin, height - margin); int imageWidth = r.width() - (border * 2); int imageHeight = imageWidth * d.getIntrinsicHeight() / d.getIntrinsicWidth(); if (imageHeight > r.height() - (border * 2)) { imageHeight = r.height() - (border * 2); imageWidth = imageHeight * d.getIntrinsicWidth() / d.getIntrinsicHeight(); } r.left += ((r.width() - imageWidth) / 2) - border; r.right = r.left + imageWidth + border + border; r.top += ((r.height() - imageHeight) / 2) - border; r.bottom = r.top + imageHeight + border + border; Paint p = new Paint(); p.setColor(0xFFC0C0C0); c.drawRect(r, p); r.left += border; r.right -= border; r.top += border; r.bottom -= border; d.setBounds(r); d.draw(c); } //} if(y==null) return null; else return b; } @Override public void updatePage(CurlPage page, final int width, final int height, final int index) { Bitmap front = null; System.out.println("motion / index value /countIteration / size of map "+motionDirection+"/"+index+"/"+countIteration+"/"+imageFilexxSm.size()); try { front=loadBitmap(width, height,index); if(front!=null) { page.setTexture(front, CurlPage.SIDE_FRONT); page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}} 

I also tried to set the index using the getCurrentIndex method, which is provided inside the CurlView class, but it does not even work. Found that the index is transmitted correctly, but the bitmap images are not updated.

More clearly the problem:

When I move forward, i.e. 1st, 2nd, 3rd, 4th, 5th ... images and sounds work correctly, but when I do the reverse of the 5th, 4th, 3rd, 2nd, 1 1st is correct, but 3rd, 2nd and 1st are invalid. Why is this happening?

+7
android android-layout page-curl android-query
May 27 '13 at 11:58
source share
2 answers

I hope this saves time if you use the imageloading library with page curl.

So, after a lot of research, I found that the imageloading library I used with (aquery) received methods ie getCachedImage(String url) , getCachedFile(String url) that do not work with streams and return null if the file is not cached in any storage (sdcard, cache cache) .

The piece of code that was valid did this for me,

 private class PageProvider implements CurlView.PageProvider { @Override public int getPageCount() { return data1.size()-1; } private Bitmap loadBitmap(int width, int height, final int index) throws MalformedURLException, IOException { Bitmap b = Bitmap.createBitmap(width, height,Bitmap.Config.ARGB_8888); b.eraseColor(0xFFFFFFFF); Canvas c = new Canvas(b); System.out.println(" Index is : "+index+" Curl state : "+CurlActivity.motionDirection); if(index==data1.size()) { lastPage=false; } else { lastPage=true; } if(CurlActivity.motionDirection==11) { y=aq.getCachedImage(data1.get(index)); f=aq.getCachedFile(data1.get(index+1).replace(".png", ".mp3")); if(f!=null) { FileInputStream inputStream = new FileInputStream(f); if(index>0) { mPlayer.stop(); mPlayer.reset(); } prepareMediaPlayer(inputStream.getFD()); inputStream.close(); } } else { y=aq.getCachedImage(data1.get(index)); if(jump==0) { f=aq.getCachedFile(data1.get(index).replace(".png", ".mp3")); } else { f=aq.getCachedFile(data1.get(index+1).replace(".png", ".mp3")); } if(y!=null&&f!=null) { FileInputStream inputStream = new FileInputStream(f); if(index>0) { mPlayer.stop(); mPlayer.reset(); } prepareMediaPlayer(inputStream.getFD()); inputStream.close(); } else if(y!=null && f == null) { duration=1000; } else { aq.progress(R.id.progress).ajax(data1.get(index+1), Bitmap.class,0, new AjaxCallback<Bitmap>() { @Override public void callback(final String urlimg, final Bitmap object1, AjaxStatus status) { if(object1!=null) try { y=object1; aq.ajax(data1.get(index).replace(".png", ".mp3"), File.class,0,new AjaxCallback<File>() { @Override public void callback(String url, File object, AjaxStatus status) { System.out.println("url sound downloaded "+url+status.getCode()); try { if(object!=null||status.getCode()==404) { FileInputStream inputStream = new FileInputStream(object); if(index>0) { mPlayer.stop(); mPlayer.reset(); } prepareMediaPlayer(inputStream.getFD()); inputStream.close(); } } catch (Exception e) {} } }); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }); } } d = new BitmapDrawable(getResources(),y); if(y!=null) { int margin = 7; int border = 3; Rect r = new Rect(margin, margin, width - margin, height - margin); int imageWidth = r.width() - (border * 2); int imageHeight = imageWidth * d.getIntrinsicHeight() / d.getIntrinsicWidth(); if (imageHeight > r.height() - (border * 2)) { imageHeight = r.height() - (border * 2); imageWidth = imageHeight * d.getIntrinsicWidth() / d.getIntrinsicHeight(); } r.left += ((r.width() - imageWidth) / 2) - border; r.right = r.left + imageWidth + border + border; r.top += ((r.height() - imageHeight) / 2) - border; r.bottom = r.top + imageHeight + border + border; Paint p = new Paint(); p.setColor(0xFFC0C0C0); c.drawRect(r, p); r.left += border; r.right -= border; r.top += border; r.bottom -= border; d.setBounds(r); d.draw(c); } return b; } @Override public void updatePage(CurlPage page, final int width, final int height, final int index) { mPlayer.stop(); mPlayer.reset(); Bitmap front = null; try { front=loadBitmap(width, height,index); if(front!=null) { page.setTexture(front, CurlPage.SIDE_FRONT); page.setColor(Color.rgb(180, 180, 180), CurlPage.SIDE_BACK); } } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } 
+2
Jun 05 '13 at 7:47
source share

hm ... curlpage by harism has a behavior for loading more than one image when turning the page, for example, if you redirect the page from 0 to 1, curlpage will load the image for page 1 and page 2, and if you flip to page 5 curlpage will load the image for pages 5 and 6, but if you go back to page 4, curlpage will load the image for pages 4, page 3, and page 2.

loadImage() triggered when onTouch ACTION.MOVE , so you must prepare the image before you move / turn the page or your page gets zero, you need to load it manually by calling the updatePage() method in the CurlView class.

for getCurrentIndex() you can check it in the startCurl() method and updatePage() in the CurlView class.

+2
May 30 '13 at 10:21
source share



All Articles