Curl página de izquierda a derecha android

Por lo tanto, estoy utilizando página curl por harism, https://github.com/harism/android_page_curl y han implementado con éxito para cargar imágenes a través de streaming web. Pero no puedo conseguir que funcione cuando vuelvo a las imágenes o páginas anteriores, ya que las imágenes no vienen con el índice correcto. Es decir, no están refrescando correctamente. No puedo entender esto.

Esta es mi implementación donde cargar imágenes en el 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(); }}} 

También he intentado fijar el índice usando el método de getCurrentIndex que se proporciona dentro de la clase de CurlView, pero incluso no trabaja. Han encontrado que el índice se pasa correctamente, pero los mapas de bits no se están actualizando.

Más claramente el problema es:

Cuando me muevo hacia delante, es decir, 1, 2, 3, 4, 5 … las imágenes y los sonidos funcionan correctamente, pero cuando hago lo contrario 5, 4, 3, 2, 3º, 2º y 1º están fuera de servicio. ¿Por qué está pasando esto?

Hm … curlpage por harism tiene un comportamiento para cargar la imagen más de uno al mover la página, por ejemplo, si mueve la página de 0 a 1 curlpage cargará la imagen para la página 1 y la página 2 y si pasa a la página 5 curlpage cargará la imagen Para las páginas 5 y 6, pero si vuelve a la página 4, curlpage cargará la imagen para la página 4, la página 3 y la página 2.

loadImage() activa cuando onTouch ACTION.MOVE , por lo que tiene que preparar la imagen antes de mover / voltear la página o su página se obtendrá nulo, tiene que cargar manualmente llamando al método updatePage() en la clase CurlView.

Para getCurrentIndex() puede comprobarlo en el método startCurl() y updatePage() en la clase CurlView.

Espero que esto ahorraría el tiempo de alguien si está usando una biblioteca de imageloading con el enrollamiento de la página del harism.

Por lo tanto, después de mucha investigación encontré que la biblioteca de creación de imágenes que estaba usando (aquery) tiene métodos, es decir getCachedImage(String url) , getCachedFile(String url) que no funciona en los hilos y devolver null si el archivo no es Ya en caché en cualquier almacenamiento (sdcard, directorio de caché) .

El pedazo de código que era real lo hizo para mí es,

 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(); } } } 
FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.